1 #include <SketchSolver_Constraint.h>
2 #include <SketchSolver_Group.h>
3 #include <SketchSolver_Error.h>
4 #include <SketchSolver_Manager.h>
6 #include <SketchPlugin_Arc.h>
7 #include <SketchPlugin_Circle.h>
8 #include <SketchPlugin_Line.h>
9 #include <SketchPlugin_Point.h>
11 #include <SketchPlugin_ConstraintAngle.h>
12 #include <SketchPlugin_ConstraintCoincidence.h>
13 #include <SketchPlugin_ConstraintDistance.h>
14 #include <SketchPlugin_ConstraintEqual.h>
15 #include <SketchPlugin_ConstraintHorizontal.h>
16 #include <SketchPlugin_ConstraintLength.h>
17 #include <SketchPlugin_ConstraintMirror.h>
18 #include <SketchPlugin_ConstraintParallel.h>
19 #include <SketchPlugin_ConstraintPerpendicular.h>
20 #include <SketchPlugin_ConstraintRadius.h>
21 #include <SketchPlugin_ConstraintRigid.h>
22 #include <SketchPlugin_ConstraintTangent.h>
23 #include <SketchPlugin_ConstraintVertical.h>
25 #include <GeomAPI_Dir2d.h>
26 #include <GeomDataAPI_Point.h>
27 #include <GeomDataAPI_Point2D.h>
28 #include <ModelAPI_AttributeDouble.h>
29 #include <ModelAPI_ResultConstruction.h>
33 SketchSolver_Constraint::SketchSolver_Constraint(
34 ConstraintPtr theConstraint)
35 : myBaseConstraint(theConstraint),
36 myGroupID(GID_UNKNOWN),
37 myType(CONSTRAINT_UNKNOWN)
41 void SketchSolver_Constraint::process(StoragePtr theStorage,
42 const GroupID& theGroupID,
43 const EntityID& theSketchID)
45 myStorage = theStorage;
46 myGroupID = theGroupID;
47 mySketchID = theSketchID;
48 // Process constraint according to its type
53 SketchSolver_ConstraintType SketchSolver_Constraint::TYPE(ConstraintPtr theConstraint)
55 const std::string& aType = theConstraint->getKind();
56 if (aType == SketchPlugin_ConstraintCoincidence::ID())
57 return CONSTRAINT_COINCIDENCE;
58 else if (aType == SketchPlugin_ConstraintRigid::ID())
59 return CONSTRAINT_FIXED;
60 else if (aType == SketchPlugin_ConstraintHorizontal::ID())
61 return CONSTRAINT_HORIZONTAL;
62 else if (aType == SketchPlugin_ConstraintVertical::ID())
63 return CONSTRAINT_VERTICAL;
64 else if (aType == SketchPlugin_ConstraintAngle::ID())
65 return CONSTRAINT_ANGLE;
66 else if (aType == SketchPlugin_ConstraintDistance::ID())
67 return CONSTRAINT_DISTANCE;
68 else if (aType == SketchPlugin_ConstraintEqual::ID())
69 return CONSTRAINT_EQUAL;
70 else if (aType == SketchPlugin_ConstraintLength::ID())
71 return CONSTRAINT_PT_PT_DISTANCE;
72 else if (aType == SketchPlugin_ConstraintMirror::ID())
73 return CONSTRAINT_SYMMETRIC;
74 else if (aType == SketchPlugin_ConstraintParallel::ID())
75 return CONSTRAINT_PARALLEL;
76 else if (aType == SketchPlugin_ConstraintPerpendicular::ID())
77 return CONSTRAINT_PERPENDICULAR;
78 else if (aType == SketchPlugin_ConstraintRadius::ID())
79 return CONSTRAINT_RADIUS;
80 else if (aType == SketchPlugin_ConstraintTangent::ID())
81 return CONSTRAINT_TANGENT;
82 return CONSTRAINT_UNKNOWN;
85 void SketchSolver_Constraint::process()
88 if (!myBaseConstraint || !myStorage || myGroupID == GID_UNKNOWN) {
89 // Not enough parameters are assigned
92 //// if (!myConstraints.empty()) // some data is changed, update constraint
95 SketchSolver_ConstraintType aConstrType = getType();
97 std::vector<EntityWrapperPtr> anAttributes;
98 getAttributes(aValue, anAttributes);
99 if (!myErrorMsg.empty())
101 if (anAttributes.empty()) {
102 myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
105 if (aConstrType == CONSTRAINT_UNKNOWN)
106 aConstrType = getType();
108 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
109 std::list<ConstraintWrapperPtr> aNewConstraints = aBuilder->createConstraint(
110 myBaseConstraint, myGroupID, mySketchID, aConstrType,
111 aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
112 myStorage->addConstraint(myBaseConstraint, aNewConstraints);
117 ////bool SketchSolver_Constraint::checkAttributesChanged(ConstraintPtr theConstraint)
119 //// std::set<Slvs_hEntity> aCurAttrs; // list of currently used attributes
120 //// std::vector<Slvs_hConstraint>::const_iterator aConstrIter = mySlvsConstraints.begin();
121 //// for (; aConstrIter != mySlvsConstraints.end(); aConstrIter++) {
122 //// Slvs_Constraint aConstr = myStorage->getConstraint(*aConstrIter);
123 //// if (aConstr.ptA != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.ptA);
124 //// if (aConstr.ptB != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.ptB);
125 //// if (aConstr.entityA != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityA);
126 //// if (aConstr.entityB != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityB);
127 //// if (aConstr.entityC != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityC);
128 //// if (aConstr.entityD != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityD);
130 //// // Check the attrbutes of constraint are changed
131 //// ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
132 //// std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
133 //// std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
134 //// for (; anAttrIter != anAttrList.end(); anAttrIter++) {
135 //// AttributeRefAttrPtr aRefAttr =
136 //// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
138 //// if (aRefAttr->isObject()) {
139 //// FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
140 //// std::map<FeaturePtr, Slvs_hEntity>::iterator aFIt = myFeatureMap.find(aFeature);
142 //// if (aFIt == myFeatureMap.end())
144 //// // Additional check the points of entity
145 //// if (aCurAttrs.find(aFIt->second) == aCurAttrs.end()) {
146 //// Slvs_Entity anEntity = myStorage->getEntity(aFIt->second);
147 //// bool isFound = false;
148 //// for (int i = 0; i < 4 && !isFound; i++)
149 //// if (anEntity.point[i] != SLVS_E_UNKNOWN &&
150 //// aCurAttrs.find(anEntity.point[i]) != aCurAttrs.end())
156 //// } else if (aRefAttr->attr()) {
157 //// std::map<AttributePtr, Slvs_hEntity>::iterator anAIt = myAttributeMap.find(aRefAttr->attr());
158 //// if (anAIt == myAttributeMap.end() || aCurAttrs.find(anAIt->second) == aCurAttrs.end())
162 //// AttributeRefListPtr aRefList =
163 //// std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
165 //// std::list<ObjectPtr> anItems = aRefList->list();
166 //// std::list<ObjectPtr>::iterator anIt = anItems.begin();
167 //// for (; anIt != anItems.end(); anIt++) {
168 //// FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
169 //// if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end())
177 void SketchSolver_Constraint::update()
181 std::list<ConstraintWrapperPtr> aWrapper = myStorage->constraint(myBaseConstraint);
182 AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
183 myBaseConstraint->attribute(SketchPlugin_Constraint::VALUE()));
185 std::list<ConstraintWrapperPtr>::iterator aWIt = aWrapper.begin();
186 for (; aWIt != aWrapper.end(); ++aWIt)
187 (*aWIt)->setValue(aValueAttr->value());
189 myStorage->addConstraint(myBaseConstraint, aWrapper);
194 bool SketchSolver_Constraint::remove()
197 return myStorage->removeConstraint(myBaseConstraint);
200 void SketchSolver_Constraint::getAttributes(
202 std::vector<EntityWrapperPtr>& theAttributes)
204 static const int anInitNbOfAttr = 4;
205 theAttributes.assign(anInitNbOfAttr, EntityWrapperPtr());
207 DataPtr aData = myBaseConstraint->data();
208 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
210 myType = TYPE(myBaseConstraint);
212 AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
213 aData->attribute(SketchPlugin_Constraint::VALUE()));
214 theValue = aValueAttr ? aValueAttr->value() : 0.0;
216 int aPtInd = 0; // index of first point in the list of attributes
217 int aEntInd = 2; // index of first entity in the list of attributes
218 std::list<AttributePtr> aConstrAttrs = aData->attributes(ModelAPI_AttributeRefAttr::typeId());
219 std::list<AttributePtr>::iterator anIter = aConstrAttrs.begin();
220 for (; anIter != aConstrAttrs.end(); anIter++) {
221 AttributeRefAttrPtr aRefAttr =
222 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
223 if (!aRefAttr || !aRefAttr->isInitialized()) {
224 myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
228 myStorage->update(aRefAttr, myGroupID);
229 EntityWrapperPtr anEntity = myStorage->entity(aRefAttr);
231 SketchSolver_EntityType aType = anEntity->type();
232 if (aType == ENTITY_UNKNOWN)
234 else if (aType == ENTITY_POINT)
235 theAttributes[aPtInd++] = anEntity; // the point is created
236 else { // another entity (not a point) is created
237 if (aEntInd < anInitNbOfAttr)
238 theAttributes[aEntInd] = anEntity;
240 theAttributes.push_back(anEntity);
246 bool SketchSolver_Constraint::isUsed(FeaturePtr theFeature) const
248 const std::list<ConstraintWrapperPtr>& aCList = myStorage->constraint(myBaseConstraint);
249 std::list<ConstraintWrapperPtr>::const_iterator aCIt = aCList.begin();
250 for (; aCIt != aCList.end(); ++aCIt)
251 if ((*aCIt)->isUsed(theFeature))
254 std::list<AttributePtr> anAttrList = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
255 std::list<AttributePtr>::const_iterator anAttrIt = anAttrList.begin();
256 for (; anAttrIt != anAttrList.end(); ++ anAttrIt)
257 if (isUsed(*anAttrIt))
263 bool SketchSolver_Constraint::isUsed(AttributePtr theAttribute) const
265 AttributePtr anAttribute = theAttribute;
266 AttributeRefAttrPtr aRefAttr =
267 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
269 if (aRefAttr->isObject())
270 return isUsed(ModelAPI_Feature::feature(aRefAttr->object()));
272 anAttribute = aRefAttr->attr();
275 const std::list<ConstraintWrapperPtr>& aCList = myStorage->constraint(myBaseConstraint);
276 std::list<ConstraintWrapperPtr>::const_iterator aCIt = aCList.begin();
277 for (; aCIt != aCList.end(); ++aCIt)
278 if ((*aCIt)->isUsed(theAttribute))
283 ////Slvs_hEntity SketchSolver_Constraint::changeEntity(AttributeRefAttrPtr theAttribute, int& theType)
285 //// // Convert the object of the attribute to the feature
286 //// FeaturePtr aFeature;
287 //// if (theAttribute->isObject() && theAttribute->object()) {
288 //// ResultConstructionPtr aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
289 //// theAttribute->object());
291 //// myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
292 //// return SLVS_E_UNKNOWN;
294 //// std::shared_ptr<ModelAPI_Document> aDoc = aRC->document();
295 //// aFeature = aDoc->feature(aRC);
297 //// return changeEntity(aFeature, theType);
300 //// return changeEntity(theAttribute->attr(), theType);
303 ////Slvs_hEntity SketchSolver_Constraint::changeEntity(AttributePtr theEntity, int& theType)
305 //// Slvs_hEntity aResult = SLVS_E_UNKNOWN;
306 //// if (!theEntity || !isInitialized(theEntity)) {
307 //// myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
308 //// return SLVS_E_UNKNOWN;
311 //// // If the entity is already in the group, try to find it
312 //// std::map<std::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator anEntIter =
313 //// myAttributeMap.find(theEntity);
314 //// Slvs_Entity aCurrentEntity;
315 //// aCurrentEntity.h = SLVS_E_UNKNOWN;
316 //// if (anEntIter != myAttributeMap.end())
317 //// aCurrentEntity = myStorage->getEntity(anEntIter->second);
319 //// aResult = myGroup->getAttributeId(theEntity);
320 //// if (aResult != SLVS_E_UNKNOWN) {
321 //// Slvs_Entity anEnt = myStorage->getEntity(aResult);
322 //// theType = anEnt.type;
323 //// myAttributeMap[theEntity] = aResult;
328 //// Slvs_hGroup aGroupID = myGroup->getId();
329 //// // do not update entity from another group
330 //// if (aCurrentEntity.h != SLVS_E_UNKNOWN && aGroupID != aCurrentEntity.group)
331 //// return aCurrentEntity.h;
334 //// std::shared_ptr<GeomDataAPI_Point> aPoint =
335 //// std::dynamic_pointer_cast<GeomDataAPI_Point>(theEntity);
337 //// double aXYZ[3] = {aPoint->x(), aPoint->y(), aPoint->z()};
338 //// Slvs_hParam aParams[3];
339 //// for (int i = 0; i < 3; i++) {
340 //// Slvs_Param aPar = aCurrentEntity.h != SLVS_E_UNKNOWN ?
341 //// myStorage->getParameter(aCurrentEntity.param[i]) :
342 //// Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0);
343 //// aPar.val = aXYZ[i];
344 //// aParams[i] = myStorage->addParameter(aPar);
347 //// if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
348 //// aCurrentEntity = Slvs_MakePoint3d(SLVS_E_UNKNOWN, aGroupID, aParams[0], aParams[1], aParams[2]);
349 //// else { // update entity data
350 //// for (int i = 0; i < 3; i++)
351 //// aCurrentEntity.param[i] = aParams[i];
353 //// aResult = myStorage->addEntity(aCurrentEntity);
355 //// // All entities except 3D points are created on workplane. So, if there is no workplane yet, then error
356 //// Slvs_hEntity aWorkplaneID = myGroup->getWorkplaneId();
357 //// if (aWorkplaneID == SLVS_E_UNKNOWN)
358 //// return SLVS_E_UNKNOWN;
361 //// std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
362 //// std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theEntity);
364 //// double aXY[2] = {aPoint2D->x(), aPoint2D->y()};
365 //// Slvs_hParam aParams[2];
366 //// for (int i = 0; i < 2; i++) {
367 //// Slvs_Param aPar = aCurrentEntity.h != SLVS_E_UNKNOWN ?
368 //// myStorage->getParameter(aCurrentEntity.param[i]) :
369 //// Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0);
370 //// aPar.val = aXY[i];
371 //// aParams[i] = myStorage->addParameter(aPar);
374 //// if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
375 //// aCurrentEntity = Slvs_MakePoint2d(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aParams[0], aParams[1]);
376 //// else { // update entity data
377 //// for (int i = 0; i < 2; i++)
378 //// aCurrentEntity.param[i] = aParams[i];
380 //// aResult = myStorage->addEntity(aCurrentEntity);
382 //// // Scalar value (used for the distance entities)
383 //// AttributeDoublePtr aScalar = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theEntity);
385 //// Slvs_Param aParam = aCurrentEntity.h != SLVS_E_UNKNOWN ?
386 //// myStorage->getParameter(aCurrentEntity.param[0]) :
387 //// Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0);
388 //// aParam.val = aScalar->value();
389 //// Slvs_hParam aValue = myStorage->addParameter(aParam);
391 //// if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
392 //// aCurrentEntity = Slvs_MakeDistance(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aValue);
394 //// aCurrentEntity.param[0] = aValue;
395 //// aResult = myStorage->addEntity(aCurrentEntity);
400 //// myAttributeMap[theEntity] = aResult;
401 //// theType = aCurrentEntity.type;
405 ////Slvs_hEntity SketchSolver_Constraint::changeEntity(FeaturePtr theEntity, int& theType)
407 //// Slvs_hEntity aResult = SLVS_E_UNKNOWN;
408 //// if (!theEntity || !theEntity->data() || !theEntity->data()->isValid())
409 //// return SLVS_E_UNKNOWN;
410 //// // If the entity is already in the group, try to find it
411 //// std::map<FeaturePtr, Slvs_hEntity>::const_iterator anEntIter = myFeatureMap.find(theEntity);
412 //// Slvs_Entity aCurrentEntity;
413 //// aCurrentEntity.h = SLVS_E_UNKNOWN;
414 //// if (anEntIter != myFeatureMap.end())
415 //// aCurrentEntity = myStorage->getEntity(anEntIter->second);
417 //// aResult = myGroup->getFeatureId(theEntity);
418 //// if (aResult != SLVS_E_UNKNOWN) {
419 //// Slvs_Entity anEnt = myStorage->getEntity(aResult);
420 //// theType = anEnt.type;
421 //// myFeatureMap[theEntity] = aResult;
426 //// Slvs_hGroup aGroupID = myGroup->getId();
427 //// // do not update entity from another group
428 //// if (aCurrentEntity.h != SLVS_E_UNKNOWN && aGroupID != aCurrentEntity.group)
429 //// return aCurrentEntity.h;
431 //// Slvs_hEntity aWorkplaneID = myGroup->getWorkplaneId();
432 //// DataPtr aData = theEntity->data();
434 //// // SketchPlugin features
435 //// const std::string& aFeatureKind = theEntity->getKind();
436 //// AttributePtr anAttribute;
439 //// if (aFeatureKind == SketchPlugin_Line::ID()) {
440 //// anAttribute = aData->attribute(SketchPlugin_Line::START_ID());
441 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
442 //// Slvs_hEntity aStart = changeEntity(anAttribute, anAttrType);
444 //// anAttribute = aData->attribute(SketchPlugin_Line::END_ID());
445 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
446 //// Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType);
448 //// if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity
449 //// aCurrentEntity = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aStart, aEnd);
451 //// aCurrentEntity.point[0] = aStart;
452 //// aCurrentEntity.point[1] = aEnd;
454 //// aResult = myStorage->addEntity(aCurrentEntity);
457 //// else if (aFeatureKind == SketchPlugin_Circle::ID()) {
458 //// anAttribute = aData->attribute(SketchPlugin_Circle::CENTER_ID());
459 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
460 //// Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType);
462 //// anAttribute = aData->attribute(SketchPlugin_Circle::RADIUS_ID());
463 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
464 //// Slvs_hEntity aRadius = changeEntity(anAttribute, anAttrType);
466 //// if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity
467 //// Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID);
468 //// aCurrentEntity = Slvs_MakeCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID,
469 //// aCenter, aWorkplane.normal, aRadius);
471 //// aCurrentEntity.point[0] = aCenter;
472 //// aCurrentEntity.distance = aRadius;
474 //// aResult = myStorage->addEntity(aCurrentEntity);
477 //// else if (aFeatureKind == SketchPlugin_Arc::ID()) {
478 //// anAttribute = aData->attribute(SketchPlugin_Arc::CENTER_ID());
479 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
480 //// Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType);
482 //// anAttribute = aData->attribute(SketchPlugin_Arc::START_ID());
483 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
484 //// Slvs_hEntity aStart = changeEntity(anAttribute, anAttrType);
486 //// anAttribute = aData->attribute(SketchPlugin_Arc::END_ID());
487 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
488 //// Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType);
490 //// if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity
491 //// Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID);
492 //// aCurrentEntity = Slvs_MakeArcOfCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID,
493 //// aWorkplane.normal, aCenter, aStart, aEnd);
495 //// aCurrentEntity.point[0] = aCenter;
496 //// aCurrentEntity.point[1] = aStart;
497 //// aCurrentEntity.point[2] = aEnd;
499 //// aResult = myStorage->addEntity(aCurrentEntity);
501 //// // Point (it has low probability to be an attribute of constraint, so it is checked at the end)
502 //// else if (aFeatureKind == SketchPlugin_Point::ID()) {
503 //// anAttribute = aData->attribute(SketchPlugin_Point::COORD_ID());
504 //// if (!isInitialized(anAttribute)) return SLVS_E_UNKNOWN;
505 //// // Both the sketch point and its attribute (coordinates) link to the same SolveSpace point identifier
506 //// aResult = changeEntity(anAttribute, anAttrType);
507 //// aCurrentEntity.type = SLVS_E_POINT_IN_3D;
510 //// if (aResult != SLVS_E_UNKNOWN) {
511 //// myFeatureMap[theEntity] = aResult;
512 //// theType = aCurrentEntity.type;
517 ////bool SketchSolver_Constraint::hasConstraint(ConstraintPtr theConstraint) const
519 //// std::list<ConstraintPtr>::const_iterator anIt = myConstraints.begin();
520 //// for (; anIt != myConstraints.end(); ++anIt)
521 //// if (*anIt == theConstraint)
526 ////void SketchSolver_Constraint::refresh()
528 //// cleanErrorMsg();
529 //// std::map<AttributePtr, Slvs_hEntity>::iterator anAttrIter = myAttributeMap.begin();
530 //// while (anAttrIter != myAttributeMap.end()) {
531 //// std::shared_ptr<GeomDataAPI_Point> aPoint =
532 //// std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttrIter->first);
533 //// Slvs_Entity anEntity = myStorage->getEntity(anAttrIter->second);
534 //// if (anEntity.h == SLVS_E_UNKNOWN) {
535 //// std::map<AttributePtr, Slvs_hEntity>::iterator aTmpIter = anAttrIter++;
536 //// myAttributeMap.erase(aTmpIter);
541 //// for (int i = 0; i < 3; i++) {
542 //// Slvs_Param aPar = myStorage->getParameter(anEntity.param[i]);
543 //// aXYZ[i] = aPar.val;
545 //// if (fabs(aPoint->x() - aXYZ[0]) > tolerance ||
546 //// fabs(aPoint->y() - aXYZ[1]) > tolerance ||
547 //// fabs(aPoint->z() - aXYZ[2]) > tolerance)
548 //// aPoint->setValue(aXYZ[0], aXYZ[1], aXYZ[2]);
551 //// std::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
552 //// std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttrIter->first);
555 //// for (int i = 0; i < 2; i++) {
556 //// Slvs_Param aPar = myStorage->getParameter(anEntity.param[i]);
557 //// aXY[i] = aPar.val;
559 //// if (fabs(aPoint2D->x() - aXY[0]) > tolerance ||
560 //// fabs(aPoint2D->y() - aXY[1]) > tolerance)
561 //// aPoint2D->setValue(aXY[0], aXY[1]);
563 //// // Scalar value (used for the distance entities)
564 //// AttributeDoublePtr aScalar =
565 //// std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttrIter->first);
567 //// Slvs_Param aPar = myStorage->getParameter(anEntity.param[0]);
568 //// if (fabs(aScalar->value() - aPar.val) > tolerance)
569 //// aScalar->setValue(aPar.val);
576 //// std::map<AttributePtr, Slvs_hParam>::iterator aValIter = myValueMap.begin();
577 //// for (; aValIter != myValueMap.end(); aValIter++) {
578 //// AttributeDoublePtr aScalar =
579 //// std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttrIter->first);
581 //// Slvs_Param aPar = myStorage->getParameter(anAttrIter->second);
582 //// aScalar->setValue(aPar.val);
587 ////bool SketchSolver_Constraint::isInitialized(AttributePtr theAttribute)
589 //// if (theAttribute->isInitialized())
591 //// myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
596 ////void SketchSolver_Constraint::calculateMiddlePoint(
597 //// const Slvs_Entity& theEntity, double theCoeff, double& theX, double& theY) const
599 //// if (theEntity.type == SLVS_E_LINE_SEGMENT) {
600 //// double aStartEndXY[2][2];
601 //// Slvs_Entity aPoint;
602 //// for (int i = 0; i < 2; i++) {
603 //// aPoint = myStorage->getEntity(theEntity.point[i]);
604 //// for (int j = 0; j < 2; j++)
605 //// aStartEndXY[i][j] = myStorage->getParameter(aPoint.param[j]).val;
607 //// theX = (1.0 - theCoeff) * aStartEndXY[0][0] + theCoeff * aStartEndXY[1][0];
608 //// theY = (1.0 - theCoeff) * aStartEndXY[0][1] + theCoeff * aStartEndXY[1][1];
609 //// } else if (theEntity.type == SLVS_E_ARC_OF_CIRCLE) {
610 //// double anArcPoint[3][2];
611 //// Slvs_Entity aPoint;
612 //// for (int i = 0; i < 3; i++) {
613 //// aPoint = myStorage->getEntity(theEntity.point[i]);
614 //// for (int j = 0; j < 2; j++)
615 //// anArcPoint[i][j] = myStorage->getParameter(aPoint.param[j]).val;
617 //// // project last point of arc on the arc
618 //// double x = anArcPoint[1][0] - anArcPoint[0][0];
619 //// double y = anArcPoint[1][1] - anArcPoint[0][1];
620 //// double aRad = sqrt(x*x + y*y);
621 //// x = anArcPoint[2][0] - anArcPoint[0][0];
622 //// y = anArcPoint[2][1] - anArcPoint[0][1];
623 //// double aNorm = sqrt(x*x + y*y);
624 //// if (aNorm >= tolerance) {
625 //// anArcPoint[2][0] = x * aRad / aNorm;
626 //// anArcPoint[2][1] = y * aRad / aNorm;
628 //// anArcPoint[1][0] -= anArcPoint[0][0];
629 //// anArcPoint[1][1] -= anArcPoint[0][1];
630 //// if (theCoeff < tolerance) {
631 //// theX = anArcPoint[0][0] + anArcPoint[1][0];
632 //// theY = anArcPoint[0][1] + anArcPoint[1][1];
634 //// } else if (1 - theCoeff < tolerance) {
635 //// theX = anArcPoint[0][0] + anArcPoint[2][0];
636 //// theY = anArcPoint[0][1] + anArcPoint[2][1];
640 //// std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(anArcPoint[1][0], anArcPoint[1][1]));
641 //// std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(anArcPoint[2][0], anArcPoint[2][1]));
642 //// double anAngle = aStartDir->angle(aEndDir);
643 //// if (anAngle < 0)
644 //// anAngle += 2.0 * PI;
645 //// anAngle *= theCoeff;
646 //// double aCos = cos(anAngle);
647 //// double aSin = sin(anAngle);
648 //// theX = anArcPoint[0][0] + anArcPoint[1][0] * aCos - anArcPoint[1][1] * aSin;
649 //// theY = anArcPoint[0][1] + anArcPoint[1][0] * aSin + anArcPoint[1][1] * aCos;
653 void SketchSolver_Constraint::makeTemporary() const
655 myStorage->setTemporary(myBaseConstraint);