Close

Relief for ODA Team in Ukraine

Learn more
ODA PRC SDK
Work with Representation Entities
This topic describes how representation entities are implemented in ODA PRC SDK and how to use them in client applications.

Representation Entities Implementation in ODA PRC SDK

There are two classes in ODA PRC SDK which can be considered as base classes for representation entities:
  • OdPrcRepresentationItemContent — Implements storage of common data for all representation entities. Formally this class is the root of the representation classes tree.
  • OdPrcRepresentationItem — Base class for all derived representation item classes. It is derived from OdPrcRepresentationItemContent because of the need to store common data. This is the super class in the representation entities class group; all other classes inherit it.

Brief information about all classes derived from the OdPrcRepresentationItem class is found in the table below.

Class name Description
OdPrcBrepModel This class implements a boundary representation model. In the case where the body of the Brep model is allocated in the exact geometry section of the .prc file structure, it is identified with a topological context index and a body's index in this context. To indicate whether the body is closed, a special boolean flag is used. Even if there is no body in the exact geometry section, tessellation data may represent a closed body.
OdPrcCoordinateSystem A coordinate system can be included into a part definition tree as a representing item. Or it can play a role of an entity used to position other representation entities. In the second case, the coordinate system is allocated in the global section of the .prc file structure.
OdPrcConstructionPlane Implements a construction plane instead of a specified planar surface. In the case where a plane body is allocated in the exact geometry section of the .prc file structure, the plane's body can be determined with an index of a topological context and a body's index within the context.
OdPrcDirection Represents a direction vector with an optional origin. It is possible to determine infinite construction lines through the direction vector.
OdPrcPointSet Implements a set of 3D points.
OdPrcPolyBrepModel A poly Brep model is defined by the tessellation data (encapsulated in an OdPrcRepresentationItemContent object). A special boolean flag indicates whether the tessellation is closed or open.
OdPrcPolyWire A poly wire is determined with the tessellation data of an OdPrcRepresentationItemContent object.
OdPrcSet Implements a logical grouping of an arbitrary number of representation items.
OdPrcWireCurve Implements a curve entity. In the case where a wire body is allocated in the exact geometry section of the .prc file structure, the wire body is determined with the index of the topological context and the body's index within the context.

Creating a Simple Brep Entity and Saving it to a .prc File

To create a simple Brep entity (for example, a sphere) and export it into a .prc file, use the following order:
  1. Create an instance of the OdDbHostAppServices class to get access to platform-dependent functionality of ODA Kernel SDK (See Create Client Applications for details about getting access to platform-dependent functionality of ODA Software and ODA PRC SDK):
    
            MyServices svcs;
            
  2. Create a stream for the .prc file:
    
            OdStreamBufPtr pPrcStream = odrxSystemServices()->createFile(prcName, (Oda::FileAccessMode)(Oda::kFileWrite), Oda::kShareDenyNo, Oda::kCreateAlways);
            
  3. Create an OdDb3dSolid object:
    
            OdDb3dSolidPtr p3dSolid = OdDb3dSolid::createObject();
            
  4. Create a sphere with specified radius:
    
            p3dSolid->createSphere(10);
            
  5. Create a new database instance using OdDbHostAppServices object created in Step 1 and add the sphere into it (for example, to model space):
    
            OdDbDatabasePtr pDb = svcs.hostTD().createDatabase();
            OdDbBlockTableRecordPtr pRec = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
            pRec->appendOdDbEntity(p3dSolid);
            
  6. Create a boundary representation of the sphere:
    
            OdBrBrep brep;
            p3dSolid->brep(brep);
            
  7. Get geometry extents of the sphere:
    
            OdGeExtents3d extents;
            p3dSolid->getGeomExtents(extents);
            
  8. Export the created boundary representation into the .prc file:
    
            PrcExportModulePtr pModule = odrxDynamicLinker()->loadModule(OdDwg2PrcExportModuleName);
            OdResult res = pModule->exportPrc(pDb, *p3dSolid, brep, pPrcStream, extents, OdRxDictionaryPtr());
            if (res != eOk)
            {
              throw OdError(res);
            }
            
    For details about exporting to a .prc file, see Export a Drawing to a .prc File.

Working with Boundary Representation Model Entities

To create a boundary representation model (for example, a sphere) follow the steps below:
  1. Create boundary representation model entity topology in an OdPrcFile object (see Creation of a .prc File for additional information about creating an OdPrcFile object and its content).
  2. Get the last file structure from the previously created OdPrcFile object and create a new part definition (pFile is a smart pointer to an OdPrcFile object):
    
              OdPrcFileStructurePtr newStructure = pFile->fileStructures().last();
              OdPrcPartDefinitionPtr newDefinition = newStructure->fileStructureTree().partDefinition().last().safeOpenObject(kForWrite);
            
  3. Create a closed boundary representation model and associate it with the new part definition:
    
            OdPrcBrepModelPtr newBrep = OdPrcBrepModel::createObject();
            newStructure->addObject(newBrep);
            newBrep->setIsClosed(true);
            newDefinition->representationItem().push_back(newBrep->objectId());
            
  4. Create a bounding box and add it to the part definition (extents represents extents passed from the calling subroutine):
        
            OdGePoint3d min = extents.minPoint(),
                        max = extents.maxPoint();
            OdPrcBoundingBox box;
            box.minPoint().set(min.x,min.y,min.z);
            box.maxPoint().set(max.x,max.y,max.z);
            newDefinition->boundingBox() = box;
            
  5. Create boundary representation entity body:
    
            OdPrcContextAndBodies &newContextAndBodies = newStructure->fileStructureGeometry().fileStructureExactGeometry().topologicalContext().last();
            OdPrcBrepDataPtr brepData = OdPrcBrepData::createObject();
            newStructure->addObject(brepData);
            box.minPoint().set(min.x,min.y,min.z);
            box.maxPoint().set(max.x,max.y,max.z);
            brepData->boundingBox() = box;
            brepData->contentBody().setBoundingBoxBehaviour(2);
            
  6. Set a reference to the created body in the representation item.
    
            newBrep->setReferenceToBody(brepData);
            
  7. Add boundary representation entity data identifier to the context:
    
            newContextAndBodies.bodies().push_back(brepData->objectId());
            
  8. Get the last file structure from OdPrcFile object:
    
            OdPrcFileStructure &newStructure = *(pFile->fileStructures().last());
            
  9. Add a line style for global data of the newly created file structure with the Brep model:
        
            OdPrcFileStructureGlobals &globalData = newStructure.fileStructureGlobals();
    
            OdPrcRgbColorArray &colorArr = globalData.colors();
            colorArr.append()->set(r, g, b);
    
            OdPrcObjectIdArray &lineStyleArr = globalData.category1LineStyles();
            OdPrcCategory1LineStylePtr lineStyle = OdPrcCategory1LineStyle::createObject();
            newStructure.addObject(lineStyle);
            lineStyle->setLineWidth(1.0f);
            lineStyle->setColorIdx(1); 
            lineStyleArr.push_back(lineStyle->objectId());
            addLineStyleForBrep(newStructure, 1.0f, 0.0f, 0.0f);
            
  10. Add graphic data to the boundary representation model:
        
            OdPrcFileStructureTree &tree = newStructure.fileStructureTree();
            OdPrcObjectIdArray &partArr = tree.partDefinition();
            OdPrcPartDefinitionPtr part = partArr.last().safeOpenObject(kForWrite);
            OdPrcObjectIdArray &itemArr = part->representationItem();
            OdPrcRepresentationItemPtr item = itemArr.last().safeOpenObject(kForWrite);
    
            OdPrcGraphics &graphics = item->graphics();
            graphics.lineAttr().setLineStyleID(newStructure.fileStructureGlobals().category1LineStyles()[0]);
            graphics.setBehaviourBitField(PRC_GRAPHICS_Show);
            
  11. Open boundary representation data object for writing:
    
            OdPrcContextAndBodies &newContextAndBodies = newStructure.fileStructureGeometry().fileStructureExactGeometry().topologicalContext().last();
            OdPrcBrepDataPtr brepData = newContextAndBodies.bodies().last().safeOpenObject(kForWrite);
            
  12. Create a new instance of the OdPrcRepresentationItem class, and set a name value for the entity:
        
            OdPrcRepresentationItemPtr newRepItem = ((OdPrcPartDefinitionPtr)(newStructure.fileStructureTree().partDefinition().last().safeOpenObject(kForWrite)))->representationItem().last().safeOpenObject(kForWrite);  
            newRepItem->name().setName("Sphere");
            
  13. Create a sphere with a specified radius:
    
            OdPrcSpherePtr pPrcSphere = OdPrcSphere::createObject();
            {
              OdPrcContentSurface &srfContent  = pPrcSphere->contentSurface();
    
              srfContent.baseGeometry().name().setName("named sphere in srfContent");
              pPrcSphere->setUVParameterization(OdPrcUVParameterization(-OdaPI, OdaPI, -OdaPI/2, OdaPI/2));
    
              pPrcSphere->setRadius(1);
            }
            
  14. Fill the previously created boundary representation model with a surface (brepData is a smart pointer to the Brep data object, pSurface is a smart pointer to the created sphere):
    
            OdPrcConnexPtr pCurConnex = OdPrcConnex::createObject();
            brepData->addConnex(pCurConnex);
    
            {
              OdPrcShellPtr pCurShell = OdPrcShell::createObject();
              pCurConnex->addShell(pCurShell);
    
              {
                OdPrcFacePtr pCurFace = OdPrcFace::createObject();
    
                pCurFace->baseSurface() = pSurface;
                pCurFace->orientationSurfaceWithShell() = kSame;
                pCurFace->setSurfaceTrimDomain(0);
                pCurFace->setHaveTolerance(false);
    
                pCurShell->addFace(pCurFace);
              }
    
              pCurShell->setShellIsClosed(false);
            }
            
  15. Open the part definition and Brep model object for writing:
    
            OdPrcPartDefinitionPtr newDefinition = newStructure.fileStructureTree().partDefinition().last().safeOpenObject(kForWrite);
            OdPrcBrepModelPtr pBrepModel = newDefinition->representationItem().last().openObject(kForWrite);
            
  16. Check whether the created Brep model is still closed:
    
            ODA_VERIFY(pBrepModel->updateIsClosedFlag() == eOk);
            
  17. Export the created boundary representation model to a specified .prc file (pPrcStream is an input parameter containing a smart pointer to the stream buffer associated with a .prc file):
    
            pFile->writeFile(pPrcStream);
            

Sample Application

ODA PRC SDK contains a set of examples which illustrate base programming practices of using PRC entities in custom applications. Sample applications source code is located in Prc\Examples folder, binary executables can be launched from \exe folder.

Working with representation entities are illustrated in the OdPrcCreate sample application. Created by the OdPrcCreate application, .prc files can be opened with specialized viewers, such as the following Brep model sphere and Brep model cylinder.

PRC entities created with OdPrcCreate sample application: a sphere (left) and a cylinder (right)

See Also

Work with PRC Entities
Create a Markup Tessellation
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.