/////////////////////////////////////////////////////////////////////////////// // 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 #include #include #include #include #include #include #include #include void fillDatabase(OdDbDatabase* pDb) { /**********************************************************************/ /* Set default font */ /**********************************************************************/ { OdDbTextStyleTableRecordPtr txtsty = pDb->getTextStyleStandardId().safeOpenObject(OdDb::kForWrite); txtsty->setFont("Arial", false, false, 0, 0); } /**********************************************************************/ /* Open the model space block */ /**********************************************************************/ OdDbBlockTableRecordPtr ms = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite); /**********************************************************************/ /* Create box, frustum, sphere and torus and collect their Object IDs */ /**********************************************************************/ OdDbObjectIdArray sourceEntityIds; { OdDb3dSolidPtr pBox = OdDb3dSolid::createObject(); pBox->setDatabaseDefaults(pDb); ms->appendOdDbEntity(pBox); pBox->createBox(15., 17.5, 14.); sourceEntityIds.append(pBox->objectId()); } { OdDb3dSolidPtr pFrustum = OdDb3dSolid::createObject(); pFrustum->setDatabaseDefaults(pDb); ms->appendOdDbEntity(pFrustum); pFrustum->createFrustum(20., 10., 7.5, 3.); pFrustum->transformBy(OdGeMatrix3d::translation(OdGeVector3d(15.,0.,0.))); sourceEntityIds.append(pFrustum->objectId()); } { OdDb3dSolidPtr pSphere = OdDb3dSolid::createObject(); pSphere->setDatabaseDefaults(pDb); ms->appendOdDbEntity(pSphere); pSphere->createSphere(8.); pSphere->transformBy(OdGeMatrix3d::translation(OdGeVector3d(25., 0., 0.))); sourceEntityIds.append(pSphere->objectId()); } { OdDb3dSolidPtr pTorus = OdDb3dSolid::createObject(); pTorus->setDatabaseDefaults(pDb); ms->appendOdDbEntity(pTorus); pTorus->createTorus(7.5, 3.); pTorus->transformBy(OdGeMatrix3d::translation(OdGeVector3d(40, 0., 0.))); sourceEntityIds.append(pTorus->objectId()); } ms.release(); /********************************************************************/ /* Make sure ModelDoc's implementation module is loaded */ /********************************************************************/ OdRxModulePtr pModelDocModule = ::odrxSafeLoadApp(OdModelDocObjModuleName); /********************************************************************/ /* Create a new Layout and make it current */ /********************************************************************/ pDb->setCurrentLayout(pDb->createLayout(OD_T("Model Documentation"))); /********************************************************************/ /* Prepare extents of source bodies (WCS) */ /********************************************************************/ OdGeExtents3d wrldExt; for (OdDbObjectId entid : sourceEntityIds) { OdDbEntityPtr ent = entid.safeOpenObject(); OdGeExtents3d entExt; ent->getGeomExtents(entExt); wrldExt.addExt(entExt); } /********************************************************************/ /* Lookup standard scale from scale list */ /********************************************************************/ double dScale = .05; OdDbObjectId idScale; OdSyScaleList scaleList; scaleList.init(pDb); scaleList.getScale(scaleList.findClosestScaleIdx(dScale), idScale, dScale); /********************************************************************/ /* Create base view from model space entities */ /********************************************************************/ OdDbObjectId baseViewRepId; { OdDbViewInitParams params; params.setViewType(OdDbViewRep::kBase); params.setSelSetEntities(sourceEntityIds); // ids collected during 3d solid creation /********************************************************************/ /* Init mapping between model space CS and paper space CS */ /********************************************************************/ params.setCenter(OdGePoint3d(2.1, 6.5, 0.0)); // viewport center in paper space params.setTarget(wrldExt.center()); // view target in WCS (center of source bodies' extents) params.setEye(wrldExt.center() + OdGeVector3d::kZAxis); // view dir from target in WCS params.setUpVec(OdGeVector3d::kYAxis); // view camera up vector in WCS params.setScaleId(idScale); // standard scale (same as base view) params.setScale(dScale); // custom scale (same as base view) params.setShowTangentEdges(true); params.setShowInterferenceEdges(true); OdDbViewRepPtr newViewRep = OdDbViewRep::createViewRep(pDb, params); baseViewRepId = newViewRep->objectId(); } OdDbAssocManager::evaluateTopLevelNetwork(pDb); /********************************************************************/ /* Create projected view from base view */ /********************************************************************/ { OdDbViewInitParams params; params.setViewType(OdDbViewRep::kProjected); params.setParentViewRepId(baseViewRepId); params.setInheritStyle(false); params.setIsShaded(true); params.setViewStyleType(OdDbViewRep::kVisibleLinesOnly); params.setInheritScale(true); params.setCenter(OdGePoint3d(8.0, 2.0, 0.0)); // viewport center in paper space params.setTarget(wrldExt.center()); // view target in WCS (center of source bodies' extents) params.setEye(wrldExt.center() + OdGeVector3d(1.0, -1.0, 1.0)); // view dir from target in WCS params.setUpVec(OdGeVector3d(-1.0, 1.0, 1.0)); // view camera up vector in WCS params.setViewOrientType(OdDbViewRep::kNEIsometric); OdDbViewRepPtr newViewRep = OdDbViewRep::createViewRep(pDb, params); } OdDbAssocManager::evaluateTopLevelNetwork(pDb); /********************************************************************/ /* Create section view from base view */ /********************************************************************/ { OdDbViewInitParams params; params.setViewType(OdDbViewRep::kSection); params.setParentViewRepId(baseViewRepId); params.setInheritStyle(false); params.setViewStyleType(OdDbViewRep::kVisibleLinesOnly); params.setInheritScale(true); params.setScaleId(idScale); // standard scale (same as base view) params.setScale(dScale); // custom scale (same as base view) params.setCenter(OdGePoint3d(2.0, 2.2, 0.0)); // viewport center in paper space OdDbSectionSymbolPtr symb = OdDbSectionSymbol::createObject(); symb->setDatabaseDefaults(pDb); OdDbSectionViewStylePtr style = symb->symbolStyleId().safeOpenObject(OdDb::kForWrite); style->setArrowSymbolSize(0.2); style->setIdentifierHeight(0.2); style->setViewLabelTextHeight(0.16); style->setViewLabelOffset(0.12); symb->addSectionPoint(OdGePoint3d(0.5, 6.5, 0.0)); symb->addSectionPoint(OdGePoint3d(3.6, 6.5, 0.0)); symb->setIdentifier("A"); symb->resetLabelOffsets(); // label positioning according section style settings OdDbViewRepPtr newViewRep = OdDbViewRep::createViewRep(pDb, params, symb); } OdDbAssocManager::evaluateTopLevelNetwork(pDb); /********************************************************************/ /* Create detail view from base view */ /********************************************************************/ { OdDbViewInitParams params; params.setParentViewRepId(baseViewRepId); params.setViewType(OdDbViewRep::kDetail); params.setViewStyleType(OdDbViewRep::kVisibleLinesOnly); params.setInheritScale(false); params.setLabelIdentifier("B"); dScale *= 2.; /********************************************************************/ /* Lookup standard scale from scale list */ /********************************************************************/ scaleList.getScale(scaleList.findClosestScaleIdx(dScale), idScale, dScale); params.setScale(dScale); params.setScaleId(idScale); params.setCenter(OdGePoint3d(8.0, 6.0, 0.0)); // viewport center in paper space OdDbDetailSymbolPtr symb = OdDbDetailSymbol::createObject(); symb->setDatabaseDefaults(pDb); OdDbDetailViewStylePtr style = symb->symbolStyleId().safeOpenObject(OdDb::kForWrite); style->setArrowSymbolSize(0.2); style->setIdentifierHeight(0.2); style->setViewLabelTextHeight(0.16); style->setViewLabelOffset(0.12); symb->setModelEdgeType(OdDbDetailViewStyle::kSmoothWithBorder); symb->setBoundaryType(OdDbDetailSymbol::kRectangularBoundary); symb->setOrigin(OdGePoint3d(2.0, 6.5, 0.0)); symb->setBoundarySize(OdGeVector2d(.8, 1.0)); symb->setIdentifierPosition(OdGePoint3d(2.6, 7.5, 0.0)); OdDbViewRepPtr newViewRep = OdDbViewRep::createViewRep(pDb, params, symb); } OdDbAssocManager::evaluateTopLevelNetwork(pDb); pDb->setLWDISPLAY(true); }