This section describes how to create sweep elements. Sweep representation is based on the idea of moving a contour along some path. A relatively constrained geometry of a sweep shape means that only a small dataset is needed to specify it. An example of a sweep element is presented below.
The functionality for working with sweep elements is implemented within the OdBmSweepElem
class.
To create a sweep element, you need to use the
set()
method.
The workflow of creating a sweep element looks something like this:
Below, you can find an example with code fragments.
First of all, you need to initialize a command context object, and then access database through it.
OdBmCommandContextPtr pDbCmdCtx(pCmdCtx);
OdBmDatabase* pDb = pDbCmdCtx->database();
In this example, an active sketch plane is used.
OdSmartPtr<OdBmUserIO> pIO = pDbCmdCtx->userIO();
OdBmObjectId idSketchPlane = pDb->getActiveSketchPlaneId();
if (idSketchPlane == (OdBmObjectId)NULL) {
pIO->putString(OD_T("Invalid sketch plane"));
return;
}
OdBmObjectPtr pObj = idSketchPlane.safeOpenObject();
if (pObj->isA() != OdBmSketchPlane::desc()) {
pIO->putString(OD_T("The object is not SketchPlane"));
return;
}
A simple path with just two GLine
elements is used here.
You need to pay attention about these things: sweep path consists of contiguous curves, this set of curves may be closed or open, but must not have any intersections.
OdBmGCurvePtrArray path;
OdBmGLinePtr pGLine = OdBmGLine::createObject();
OdBmGLinePtr pGLine2 = OdBmGLine::createObject();
pGLine->set(OdGePoint3d(-36, 0, 0), OdGePoint3d(27, 10, 0));
pGLine2->set(OdGePoint3d(27, 10, 0), OdGePoint3d(29, 30, 0));
path.append(pGLine);
path.append(pGLine2);
Just as for paths, there are some restrictions for profiles:
There is a specific case, when profile loops are so big you may have an error in sweep creation. This error can be easily explained: on the step of moving a profile along a path there will occur an intersection of profiles, the one that was previously moved and the one that is being moved.
Below you can find an example that should not cause any errors:
OdArray<OdBmGCurvePtrArray> profile;
//points
OdGePoint3d pnt1(0, 0, 0);
OdGePoint3d pnt2(0, 5, 0);
OdGePoint3d pnt3(5, 5, 0);
OdGePoint3d pnt4(5, 0, 0);
OdBmGCurvePtrArray arrCurvesOfLoop;
//profile loop
OdBmGLinePtr pProfileGLine1 = OdBmGLine::createObject();
pProfileGLine1->set(pnt1, pnt2);
OdBmGLinePtr pProfileGLine2 = OdBmGLine::createObject();
pProfileGLine2->set(pnt2, pnt3);
OdBmGLinePtr pProfileGLine3 = OdBmGLine::createObject();
pProfileGLine3->set(pnt3, pnt4);
OdBmGLinePtr pProfileGLine4 = OdBmGLine::createObject();
pProfileGLine4->set(pnt4, pnt1);
arrCurvesOfLoop.append(pProfileGLine1);
arrCurvesOfLoop.append(pProfileGLine2);
arrCurvesOfLoop.append(pProfileGLine3);
arrCurvesOfLoop.append(pProfileGLine4);
profile.append(arrCurvesOfLoop);
The last step of the sweep element creation is to create a new OdBmSweepElem
object, add it to a database, and pass all the data created in previous steps to the
set()
method.
OdBmSweepElemPtr pSweep = OdBmSweepElem::createObject();
ODBM_TRANSACTION_BEGIN(t, pDb);
t.start();
pDb->addElement(pSweep);
OdResult err = pSweep->set(true, path, idSketchPlane, profile, 0, OdBm::ProfilePlaneLocation::Start);
if (eOk == err)
t.commit();
else
t.rollback();
ODBM_TRANSACTION_END();
Don't forget to include all necessary header files. You can find the full source code in BimRv/Examples/TB_DevGuideCommands/BmDocCreateSweepCmd.cpp in the function _BmCreateSweepCmd_func
.
The resulting object should look like the following object:
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|