- if (aConstraintKind.compare(SketchPlugin_ConstraintEqual::ID()) == 0) {
- static const int aConstrType[3] = {
- SLVS_C_EQUAL_RADIUS,
- SLVS_C_EQUAL_LINE_ARC_LEN,
- SLVS_C_EQUAL_LENGTH_LINES
- };
- int aNbLines = 0;
- int aNbEntities = 2; // lines and circles in SolveSpace constraints should start from SketchPlugin_Constraint::ENTITY_C() attribute
- for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
- std::shared_ptr<ModelAPI_Attribute> anAttr =
- aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
- AttrType aType = typeOfAttribute(anAttr);
- if (aType == LINE) {
- myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- aNbLines++;
+ Slvs_hGroup aGroupID = myGroup->getId();
+ // Point in 3D
+ std::shared_ptr<GeomDataAPI_Point> aPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point>(theEntity);
+ if (aPoint) {
+ double aXYZ[3] = {aPoint->x(), aPoint->y(), aPoint->z()};
+ Slvs_hParam aParams[3];
+ for (int i = 0; i < 3; i++) {
+ Slvs_Param aPar = aCurrentEntity.h != SLVS_E_UNKNOWN ?
+ myStorage->getParameter(aCurrentEntity.param[i]) :
+ Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0);
+ aPar.val = aXYZ[i];
+ aParams[i] = myStorage->addParameter(aPar);
+ }
+
+ if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
+ aCurrentEntity = Slvs_MakePoint3d(SLVS_E_UNKNOWN, aGroupID, aParams[0], aParams[1], aParams[2]);
+ else { // update entity data
+ for (int i = 0; i < 3; i++)
+ aCurrentEntity.param[i] = aParams[i];
+ }
+ aResult = myStorage->addEntity(aCurrentEntity);
+ } else {
+ // All entities except 3D points are created on workplane. So, if there is no workplane yet, then error
+ Slvs_hEntity aWorkplaneID = myGroup->getWorkplaneId();
+ if (aWorkplaneID == SLVS_E_UNKNOWN)
+ return SLVS_E_UNKNOWN;
+
+ // Point in 2D
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theEntity);
+ if (aPoint2D) {
+ double aXY[2] = {aPoint2D->x(), aPoint2D->y()};
+ Slvs_hParam aParams[2];
+ for (int i = 0; i < 2; i++) {
+ Slvs_Param aPar = aCurrentEntity.h != SLVS_E_UNKNOWN ?
+ myStorage->getParameter(aCurrentEntity.param[i]) :
+ Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0);
+ aPar.val = aXY[i];
+ aParams[i] = myStorage->addParameter(aPar);
+ }
+
+ if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
+ aCurrentEntity = Slvs_MakePoint2d(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aParams[0], aParams[1]);
+ else { // update entity data
+ for (int i = 0; i < 2; i++)
+ aCurrentEntity.param[i] = aParams[i];