Close

Relief for ODA Team in Ukraine

Learn more
ODA BimRv SDK
Work with Curve Elements

The OdBmCurveElem class represents a curve element in ODA BimRv SDK. It has a set of geometries that can be a line, arc, ellipse, Hermit or nurb spline.

To create a curve element, use the createObject() method of the OdBmCurveElem class. Next, add it to the database. Each curve must be attached to a plane, so next, set the ID of the sketch plane. For example:


// Create Curve Element
OdBmCurveElemPtr pCurveElemLine = OdBmCurveElem::createObject();
// Add it to the database
OdBmObjectId curveElemLineId = pDb->addElement(pCurveElemLine);
OdBmObjectId pSketchId = pDb->getObjectId(OdDbHandle(OdUInt64(iHandle)));
// Set Sketch Plane
pCurveElemLine->setSketchPlane(pSketchId);
    

Next, the geometry can be applied to the curve element.

Creating a Line

To create a straight line, use the createLine() method, which requires two OdGePoint3d objects to specify the start and end points. For example:


// Define the line parameters
OdGePoint3d start = OdGePoint3d(1, 2, 0);
OdGePoint3d end = OdGePoint3d(10, 4, 0);
// Create a line
OdResult res = pCurveElemLine->createLine(start, end);
if (res != eOk)
  curveElemLineId.erase();
    

Creating an Arc

To create an arc, use the createArc() method. There are two ways to use it. The first way requires one OdGePoint3d object to specify the center of an arc, two OdGeVector3d objects to specify the X- and Y-directions of an arc, and three double values to specify the radius, start and end angles. The second way requires three OdGePoint3d objects to specify the start, middle and end points. For example:


// Define the arc parameters
OdGePoint3d center = OdGePoint3d(3, 3, 0);
OdGeVector3d xDirection = OdGeVector3d(1, 0, 0);
OdGeVector3d yDirection = OdGeVector3d(0, -1, 0);
double radius = 5;
double startAng = 0.7;
double endAng = 2.2;
// Create an arc
res = pCurveElemArc1->createArc(center, xDirection, yDirection, radius, startAng, endAng);
if (res != eOk)
  curveElemArc1Id.erase();
    

// Define the arc parameters
OdGePoint3d startPoint = OdGePoint3d(-3, -8, 0);
OdGePoint3d middlePoint = OdGePoint3d(-6, -6, 0);
OdGePoint3d endPoint = OdGePoint3d(-2, -5, 0);
// Create an arc
res = pCurveElemArc2->createArc(startPoint, middlePoint, endPoint);
if (res != eOk)
  curveElemArc2Id.erase();
    

Creating an Ellipse

To create an ellipse, use the createEllipse() method, which requires one OdGePoint3d object to specify the center of an ellipse, two OdGeVector3d objects to specify the X- and Y-directions of an ellipse, and four double values to specify the X- and Y- radiuses, start and end angles. For example:


// Define the ellipse parameters
center = OdGePoint3d(9.8, 18.0, 0);
xDirection = OdGeVector3d(-0.258819045102522, -0.965925826289068, 0);
yDirection = OdGeVector3d(-0.965925826289068, 0.258819045102522, 0);
double radiusX = 2;
double radiusY = 5;
startAng = 0.;
endAng = 6;
// Create an Ellipse
res = pCurveElemEllipse->createEllipse(center, xDirection, yDirection, radiusX, radiusY, startAng, endAng);
if (res != eOk)
  curveElemEllipseId.erase();
    

Creating a Hermite Spline

To create a hermite spline, use the createHermiteSpline() method. It requires an array of OdGePoint3d objects to specify the array of spline points, two OdGeVector3d objects to specify the start and end tangent vector values, and one bool value to specify the "periodic" flag. For example:


// Define the hermite spline parameters
OdGePoint3dArray arrPoints;
arrPoints.append(OdGePoint3d(1, -12, 0));
arrPoints.append(OdGePoint3d(-2., -7, 0));
arrPoints.append(OdGePoint3d(7, -11, 0));
arrPoints.append(OdGePoint3d(11, -6, 0));
// Create the hermite spline
res = pCurveElemHermite->createHermiteSpline(arrPoints, OdGeVector3d(-1.53, 1.895, 0), OdGeVector3d(-0.017, 2.0, 0), false);
if (res != eOk)
  curveElemHermiteId.erase();
    

Creating a NURB Spline

To create a nurb spline, use the createNurbSpline() method. It requires an integer value to specify the spline degree, an OdGeKnotVector object to specify the knot vector, an OdGePoint3dArray object to specify the array of control points and OdGeDoubleArray object to specify the control points weights. For example:


// Define the nurbs spline parameters
OdGePoint3dArray arrPointsNurbs;
arrPointsNurbs.append(OdGePoint3d(23, 7, 0));
arrPointsNurbs.append(OdGePoint3d(17, 8, 0));
arrPointsNurbs.append(OdGePoint3d(26, 4, 0));
arrPointsNurbs.append(OdGePoint3d(16, 1, 0));
OdGeDoubleArray weigths;
weigths.append(1);
weigths.append(2);
weigths.append(2);
weigths.append(1);
OdGeKnotVector knVec;
OdDoubleArray knots;
knots.insert(knots.begin(), 4, 0.0);
knots.insert(knots.end(), 4, 187.19137982292);
knVec = knots;
// Create nurbs spline
res = pCurveElemNurbs->createNurbSpline(3, knVec, arrPointsNurbs, weigths);
if (res != eOk)
  curveElemNurbsId.erase();
    

To see the full sample find Examples/TB_DevGuideCommands/BmCurveElemCmd sample command inside your ODA BimRv SDK installation folder.

See Also

Work with Simple Geometric Elements

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.