- anAttribute = aData->attribute(SketchPlugin_Line::END_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType);
-
- if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
- aCurrentEntity = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aStart, aEnd);
- else {
- aCurrentEntity.point[0] = aStart;
- aCurrentEntity.point[1] = aEnd;
- }
- aResult = myStorage->addEntity(aCurrentEntity);
- }
- // Circle
- else if (aFeatureKind == SketchPlugin_Circle::ID()) {
- anAttribute = aData->attribute(SketchPlugin_Circle::CENTER_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType);
-
- anAttribute = aData->attribute(SketchPlugin_Circle::RADIUS_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aRadius = changeEntity(anAttribute, anAttrType);
-
- if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity
- Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID);
- aCurrentEntity = Slvs_MakeCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID,
- aCenter, aWorkplane.normal, aRadius);
- } else {
- aCurrentEntity.point[0] = aCenter;
- aCurrentEntity.distance = aRadius;
- }
- aResult = myStorage->addEntity(aCurrentEntity);
- }
- // Arc
- else if (aFeatureKind == SketchPlugin_Arc::ID()) {
- anAttribute = aData->attribute(SketchPlugin_Arc::CENTER_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType);
-
- anAttribute = aData->attribute(SketchPlugin_Arc::START_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aStart = changeEntity(anAttribute, anAttrType);
-
- anAttribute = aData->attribute(SketchPlugin_Arc::END_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType);
-
- if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity
- Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID);
- aCurrentEntity = Slvs_MakeArcOfCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID,
- aWorkplane.normal, aCenter, aStart, aEnd);
- } else {
- aCurrentEntity.point[0] = aCenter;
- aCurrentEntity.point[1] = aStart;
- aCurrentEntity.point[2] = aEnd;
- }
- aResult = myStorage->addEntity(aCurrentEntity);
- }
- // Point (it has low probability to be an attribute of constraint, so it is checked at the end)
- else if (aFeatureKind == SketchPlugin_Point::ID()) {
- anAttribute = aData->attribute(SketchPlugin_Point::COORD_ID());
- if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
- // Both the sketch point and its attribute (coordinates) link to the same SolveSpace point identifier
- aResult = changeEntity(anAttribute, anAttrType);
- aCurrentEntity.type = SLVS_E_POINT_IN_3D;
- }
-
- if (aResult != SLVS_E_UNKNOWN) {
- myFeatureMap[theEntity] = aResult;
- theType = aCurrentEntity.type;
- }
- return aResult;
-}
-
-std::list<ConstraintPtr> SketchSolver_Constraint::constraints() const
-{
- std::list<ConstraintPtr> aConstraints;
- aConstraints.push_back(myBaseConstraint);
- return aConstraints;
-}
-
-void SketchSolver_Constraint::refresh()
-{
- cleanErrorMsg();
- std::map<AttributePtr, Slvs_hEntity>::iterator anAttrIter = myAttributeMap.begin();
- while (anAttrIter != myAttributeMap.end()) {
- std::shared_ptr<GeomDataAPI_Point> aPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttrIter->first);
- Slvs_Entity anEntity = myStorage->getEntity(anAttrIter->second);
- if (anEntity.h == SLVS_E_UNKNOWN) {
- std::map<AttributePtr, Slvs_hEntity>::iterator aTmpIter = anAttrIter++;
- myAttributeMap.erase(aTmpIter);
- continue;
- }
- if (aPoint) {
- double aXYZ[3];
- for (int i = 0; i < 3; i++) {
- Slvs_Param aPar = myStorage->getParameter(anEntity.param[i]);
- aXYZ[i] = aPar.val;
- }
- if (fabs(aPoint->x() - aXYZ[0]) > tolerance ||
- fabs(aPoint->y() - aXYZ[1]) > tolerance ||
- fabs(aPoint->z() - aXYZ[2]) > tolerance)
- aPoint->setValue(aXYZ[0], aXYZ[1], aXYZ[2]);
- } else {
- // Point in 2D
- std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttrIter->first);
- if (aPoint2D) {
- double aXY[2];
- for (int i = 0; i < 2; i++) {
- Slvs_Param aPar = myStorage->getParameter(anEntity.param[i]);
- aXY[i] = aPar.val;
- }
- if (fabs(aPoint2D->x() - aXY[0]) > tolerance ||
- fabs(aPoint2D->y() - aXY[1]) > tolerance)
- aPoint2D->setValue(aXY[0], aXY[1]);
- } else {
- // Scalar value (used for the distance entities)
- AttributeDoublePtr aScalar =
- std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttrIter->first);
- if (aScalar) {
- Slvs_Param aPar = myStorage->getParameter(anEntity.param[0]);
- if (fabs(aScalar->value() - aPar.val) > tolerance)
- aScalar->setValue(aPar.val);
- }
- }
- }
- anAttrIter++;
- }
-
- std::map<AttributePtr, Slvs_hParam>::iterator aValIter = myValueMap.begin();
- for (; aValIter != myValueMap.end(); aValIter++) {
- AttributeDoublePtr aScalar =
- std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttrIter->first);
- if (aScalar) {
- Slvs_Param aPar = myStorage->getParameter(anAttrIter->second);
- aScalar->setValue(aPar.val);
- }
- }