/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include "Ed/EdUserIO.h" #include "Ed/EdCommandStack.h" #include "DbCommandContext.h" #include "DbSSet.h" #include "DbDatabase.h" #include "ExSelectionUtils.h" #include "DbViewport.h" #include "RxObject.h" #include "AssocLineExampleActionBody.h" #include "AssocWireExampleActionBody.h" #include "COdPowerTowerEntity.h" #include "COdPowerTowerSolidEntity.h" #include "DbAssocManager.h" #define STL_USING_LIMITS #define STL_USING_ALGORITHM #define STL_USING_MAP #include "OdaSTL.h" void _assoc_network_test_func(OdEdCommandContext* pCmdCtx) { OdDbCommandContextPtr pDbCmdCtx(pCmdCtx); OdDbUserIO* pIO = pDbCmdCtx->dbUserIO(); OdDbDatabasePtr pDb = pDbCmdCtx->database(); if (pDb.isNull()) return; OdGePoint3dArray ptsSelected; OdDbFullSubentPathArray entPathArray; OdString strInvitation[2] = { L"Select first point for example line association:", L"Select second point for example line association:" }; OdDbSelectionSetPtr pSSet; OdArray snapModeArr; for (int n = 0; n < 2; n++) { OdDbFullSubentPath path = selectedFullSubentPathWithSnapInfo(pIO, pDb, strInvitation[n], ptsSelected, pSSet, *snapModeArr.append()); entPathArray.append(path); } pDb->startTransaction(); OdDbObjectId blockRefId, actionBodyId; OdResult res = OdAssocLineExampleActionBody::createInstance(entPathArray, ptsSelected, snapModeArr, blockRefId, actionBodyId); pDb->endTransaction(); if (res != eOk) return; OdDbAssocManager::evaluateTopLevelNetwork(pDb); } void _assoc_add_wire_func(OdEdCommandContext* pCmdCtx) { OdDbCommandContextPtr pDbCmdCtx(pCmdCtx); OdDbUserIO* pIO = pDbCmdCtx->dbUserIO(); OdDbDatabasePtr pDb = pDbCmdCtx->database(); if (pDb.isNull()) return; OdGePoint3dArray ptsSelected; OdDbFullSubentPathArray entPathArray; OdString strInvitation[2] = { L"Select first point for example line association:", L"Select second point for example line association:" }; OdDbSelectionSetPtr pSSet; OdArray snapModeArr; for (int n = 0; n < 2; n++) { OdDbFullSubentPath path = selectedFullSubentPathWithSnapInfo(pIO, pDb, strInvitation[n], ptsSelected, pSSet, *snapModeArr.append()); entPathArray.append(path); } pDb->startTransaction(); OdDbObjectId blockRefId, actionBodyId; OdResult res = OdAssocWireExampleActionBody::createInstance(entPathArray, ptsSelected, snapModeArr, blockRefId, actionBodyId); pDb->endTransaction(); if (res != eOk) return; OdDbAssocManager::evaluateTopLevelNetwork(pDb); } void _add_power_tower_func(OdEdCommandContext* pCmdCtx) { OdDbCommandContextPtr pDbCmdCtx(pCmdCtx); OdDbUserIO* pIO = pDbCmdCtx->dbUserIO(); OdDbDatabasePtr pDb = pDbCmdCtx->database(); if (pDb.isNull()) return; OdGePoint3d basePnt = pIO->getPoint(L"Select insert point for power tower"); COdPowerTowerEntityPtr pTower = COdPowerTowerEntity::createObject(); pTower->createTowerGeometry(); pTower->setBasePnt(basePnt); OdDbBlockTableRecordPtr pMS = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite); pMS->appendOdDbEntity(pTower); pTower->subSetDatabaseDefaults(pDb, true); } void _add_power_tower_solid_func(OdEdCommandContext* pCmdCtx) { OdDbCommandContextPtr pDbCmdCtx(pCmdCtx); OdDbUserIO* pIO = pDbCmdCtx->dbUserIO(); OdDbDatabasePtr pDb = pDbCmdCtx->database(); if (pDb.isNull()) return; OdGePoint3d basePnt = pIO->getPoint(L"Select insert point for solid power tower"); COdPowerTowerSolidEntityPtr pSolidTower = COdPowerTowerSolidEntity::createObject(); pSolidTower->createTowerGeometry(basePnt); OdDbBlockTableRecordPtr pMS = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite); pMS->appendOdDbEntity(pSolidTower); } void _change_action_param_func(OdEdCommandContext* pCmdCtx) { OdDbCommandContextPtr pDbCmdCtx(pCmdCtx); OdDbUserIO* pIO = pDbCmdCtx->dbUserIO(); OdDbSelectionSetPtr pSSet = pIO->select(OD_T("Select assoc object to change param:")); for (OdDbSelectionSetIteratorPtr it = pSSet->newIterator(); !it->done(); it->next()) { OdDbEntityPtr pEnt = it->objectId().safeOpenObject(); const OdDbObjectIdArray aReactors = pEnt->getPersistentReactors(); for (OdDbObjectIdArray::const_iterator reacIt = aReactors.begin(); reacIt != aReactors.end(); reacIt++) { OdDbAssocDependencyPtr pDep = OdDbAssocDependency::cast(reacIt->openObject()); if (pDep.isNull()) continue; OdDbAssocActionPtr pAction = OdDbAssocAction::cast(pDep->owningAction().openObject(OdDb::kForWrite)); if (pAction.isNull()) continue; OdString paramName = pIO->getString(OD_T("Param name:")); OdStringArray paramNames; pAction->ownedValueParamNames(paramNames); if (!paramNames.contains(paramName)) { pIO->putString(OD_T("The action does not contain this parameter")); continue; } double paramValue = pIO->getReal(OD_T("Param value(double):")); const OdDbEvalVariantPtr value = OdDbEvalVariant::init(paramValue); OdString errorMessage; if (pAction->setValueParam(paramName, *value.get(), OD_T(""), OD_T(""), errorMessage, false, 0) != eOk) pIO->putString(errorMessage); } } }