Add and Delete Geometric Objects

The geometric solver mainly works with geometric objects, so to start to create constraint system, the application declares the geometric objects that will become constraint arguments in the constraint system.

Every geometric object declared in the constraint system will have its unique identifier, namely, geom_item descriptor. Its geometric type (geom_type) is not changed during the entire object life. API C3D Solver calls that add geometric objects to the system are described below.

A point is added using

geom_item GCE_AddPoint(GCE_system gSys, GCE_point pVal).

The function returns a descriptor of the geometric point that belongs to the gSys geometric constraint system. The pVal parameter sets the start values of <X,Y> point coordinates.

A line is added using

geom_item GCE_AddLine(GCE_system gSys, GCE_line lVal).  

The function returns a descriptor of the line on a plane that belongs to the gSys geometric constraint system. The lVal sets the starting values of position lVal.p and a normal to the line lVal.norm.

A circle is added using

geom_item GCE_AddCircle(GCE_system gSys, GCE_circle cVal).  

The function returns a descriptor of the circle that belongs to the gSys geometric constraint system. The cVal parameter defines the starting values of the circle center cVal.centre and its radius cVal.radius.

An ellipse is added using

geom_item GCE_AddEllipse(GCE_system gSys, GCE_ellipse eVal).    

The function returns a descriptor of the ellipse that belongs to the gSys geometric constraint system. The eVal parameter sets the ellipse start parameters:

<eVal.centre, eVal.direct, eVal.majorR, eVal.minorR>, that define correspondingly the center, direction vector, and radii along the main and the minor semi-axes.

A spline is added using

geom_item GCE_AddSpline(GCE_system gSys, GCE_spline spl).   

The function returns a descriptor of the spline that belongs to the gSys constraint system. The spl data structure determines the original state of the spline. Parts of spline curves and methods used to define them are reviewed in Item Spline Curves.

A parametric curve of general form is added using

geom_item GCE_AddParametricCurve(GCE_system gSys, const MbCurve & crv). 

The function returns a descriptor of the parametric curve added to the gSys constraint system. The crv object completely determines abstract mathematical description of the curve in parametric form. 2D curve class is described in more detail in Item MbCurve_Two-Dimensional_Curve_ MbCurve Two-Dimensional Curve. It should be noted that the MbCurve data type is included in the C3D geometric core class hierarchy, so its lifetime is determined by the reference counter. In other words, the constraint system guarantees the validity of MbCurve instance until the parametric curve is deleted from the system. Work with parametric curve is described in more detail in Item General Parametric Curves.

A bounded curve is added using

geom_item GCE_AddBoundedCurve(GCE_system gSys, geom_item curve, geom_item p[2]).    

The function returns a descriptor of the bounded curve that belongs to the gSys constraint system. The created curve is based on the curve with p[0] and p[1] end points as boundaries. In fact, this method links three objects (a base curve and two points) into a single object, and automatically creates two “point on curve” constraints for the end points. A code fragment given below shows an example how to create a circular arc.

GCE_system gSys = GCE_CreateSystem();
GCE_circle circPars; // Circle values
GCE_point endP1, endP2; // Coordinates of the end points.
// ...
// It is required to insert the code that assigns start values of the circle and its endpoints.
// ...
geom_item p[2] = { GCE_AddPoint(gSys, endP1), GCE_AddPoint(gSys, endP2) };
geom_item circItem = GCE_AddCircle(gSys, circPars); // Create a circle. It's a base curve of the arc.
geom_item arc = GCE_AddBoundedCurve(gSys, circItem, p); // Create the circular arc.
// ...
GCE_RemoveSystem(gSys);

Likewise, you can call GCE_AddBoundedCurve() method to create elliptical arcs, parametric curve portions, line segments, etc. A bounded curve created based on a straight line is called a segment, and all the constraints applicable to a straight line are also applicable to a segment.

A geometric object added to the constraint system by any of the above methods and free of any constraints, can be removed by calling

bool GCE_RemoveGeom(GCE_system gSys, geom_item g).  

This method deletes the geometric object from the system and makes its descriptor g invalid. The function will return true if successful. The function will return false and the deletion will not be performed if the geometric object at the moment of the call is an argument of one of the constraints. To find out if a geometric object is available for deletion by GCE_RemoveGeom, you can use the GCE_IsConstrainedGeom function. Also, it is allowed to delete the geometric object on which other objects are based before others. For example, one of endpoints or base curve may be removed before the bounded curve based on them, but it will be inevitably deleted after the deletion of bounded curve or the last of the geometric objects associated with it.