Salome HOME
Optimize performance while editing sketch (case for issue #1692)
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMirror.cpp
index 0bccf4f0495ae3547c4d0c4d7dac714ec3d7d940..63867f1c3bd7c6c7eaf3171d301a650745dbaf81 100644 (file)
@@ -45,12 +45,12 @@ void SketchSolver_ConstraintMirror::getAttributes(
       if (!aFeature)
         continue;
 
-      myStorage->update(aFeature/*, myGroupID*/);
+      myStorage->update(aFeature, GID_UNKNOWN, true);
       aList->push_back(myStorage->entity(aFeature));
     }
   }
 
-  if (theBaseEntities.size() > theMirrorEntities.size())
+  if (theBaseEntities.size() > theMirrorEntities.size() || aMirroredList.empty())
     myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
 }
 
@@ -79,50 +79,29 @@ void SketchSolver_ConstraintMirror::process()
   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
   std::list<ConstraintWrapperPtr> aMirConstrList;
 
-  std::vector<EntityWrapperPtr>::iterator aBIt = aBaseList.begin();
+  // update mirrored features to be in the current group
   std::vector<EntityWrapperPtr>::iterator aMIt = aMirrorList.begin();
-  for (; aBIt != aBaseList.end(); ++aBIt, ++aMIt) {
-    if ((*aBIt)->type() == ENTITY_ARC) {
-      // add new points on arcs and mirror them
-      EntityWrapperPtr aBasePnt = myStorage->calculateMiddlePoint(*aBIt, 0.5);
-      EntityWrapperPtr aMirrPnt = myStorage->calculateMiddlePoint(*aMIt, 0.5);
-      // point on base arc
-      aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID,
-          CONSTRAINT_PT_ON_CIRCLE, 0.0, aBasePnt, EntityWrapperPtr(), *aBIt);
-      aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());
-      // point on mirrored arc
-      aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID,
-          CONSTRAINT_PT_ON_CIRCLE, 0.0, aMirrPnt, EntityWrapperPtr(), *aMIt);
-      aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());
-      // mirror these points
-      aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID,
-          aConstrType, 0.0, aBasePnt, aMirrPnt, aMirrorLine);
-      aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());
-    }
+  for (; aMIt != aMirrorList.end(); ++aMIt)
+    myStorage->update((*aMIt)->baseFeature(), myGroupID);
+
+  std::vector<EntityWrapperPtr>::iterator aBIt = aBaseList.begin();
+  for (aMIt = aMirrorList.begin(); aBIt != aBaseList.end(); ++aBIt, ++aMIt) {
     aNewConstraints = aBuilder->createConstraint(
         myBaseConstraint, myGroupID, mySketchID, aConstrType,
         0.0, *aBIt, *aMIt, aMirrorLine);
     aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());
   }
-
   myStorage->addConstraint(myBaseConstraint, aMirConstrList);
-  // update mirrored features to be in the current group
-  for (aMIt = aMirrorList.begin(); aMIt != aMirrorList.end(); ++aMIt)
-    myStorage->update((*aMIt)->baseFeature(), myGroupID);
+
+  adjustConstraint();
 }
 
 
 void SketchSolver_ConstraintMirror::update()
 {
   cleanErrorMsg();
-  AttributeRefListPtr aMirroredRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
-    myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_C()));
-  if (aMirroredRefList->size() != myNumberOfObjects) {
-    remove();
-    process();
-    return;
-  }
-  adjustConstraint();
+  remove();
+  process();
 }
 
 void SketchSolver_ConstraintMirror::adjustConstraint()