Salome HOME
ViewerFilters transferred from XGUI to ModuleBase
[modules/shaper.git] / src / PartSet / PartSet_OperationFeatureEditMulti.cpp
index 0c4a71697d6aca7e5234d1a919a76a8d563e668f..b36e16ca201c7c71418bcf4261ab577522116abb 100644 (file)
@@ -39,44 +39,61 @@ PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QStri
       mySketch(theFeature),
       myIsBlockedSelection(false)
 {
+  myIsEditing = true;
 }
 
 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
 {
 }
 
-bool PartSet_OperationFeatureEditMulti::isGranted(ModuleBase_IOperation* theOperation) const
+
+bool isContains(const std::list<ModuleBase_ViewerPrs>& theSelected, const ModuleBase_ViewerPrs& thePrs)
 {
-  return theOperation->getDescription()->operationId().toStdString()
-      == PartSet_OperationSketch::Type();
+  std::list<ModuleBase_ViewerPrs>::const_iterator anIt;
+  for (anIt = theSelected.cbegin(); anIt != theSelected.cend(); ++anIt) {
+    if ((*anIt).object() == thePrs.object())
+      return true;
+  }
+  return false;
 }
 
+
 void PartSet_OperationFeatureEditMulti::initSelection(
     const std::list<ModuleBase_ViewerPrs>& theSelected,
     const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
-  if (!theHighlighted.empty()) {
-    // if there is highlighted object, we check whether it is in the list of selected objects
-    // in that case this object is a handle of the moved lines. If there no such object in the selection,
-    // the hightlighted object should moved and the selection is skipped. The skipped selection will be
-    // deselected in the viewer by blockSelection signal in the startOperation method.
-    bool isSelected = false;
-    std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected
-        .end();
-    for (; anIt != aLast && !isSelected; anIt++) {
-      isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
+  //if (!theHighlighted.empty()) {
+  //  // if there is highlighted object, we check whether it is in the list of selected objects
+  //  // in that case this object is a handle of the moved lines. If there no such object in the selection,
+  //  // the hightlighted object should moved and the selection is skipped. The skipped selection will be
+  //  // deselected in the viewer by blockSelection signal in the startOperation method.
+  //  bool isSelected = false;
+  //  std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), 
+  //    aLast = theSelected.end();
+  //  for (; anIt != aLast && !isSelected; anIt++) {
+  //    isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
+  //  }
+  //  if (!isSelected)
+  //    myFeatures = theHighlighted;
+  //  else
+  //    myFeatures = theSelected;
+  //} else
+  myFeatures = theSelected;
+  // add highlighted elements if they are not selected
+  std::list<ModuleBase_ViewerPrs>::const_iterator anIt;
+  for (anIt = theHighlighted.cbegin(); anIt != theHighlighted.cend(); ++anIt) {
+    if (!isContains(myFeatures, (*anIt)))
+      myFeatures.push_back(*anIt);
+  }
+  // Remove current feature if it is in the list (it will be moved as main feature)
+  FeaturePtr aFea = feature();
+  for (anIt = myFeatures.cbegin(); anIt != myFeatures.cend(); ++anIt) {
+    FeaturePtr aF = ModelAPI_Feature::feature((*anIt).object());
+    if (ModelAPI_Feature::feature((*anIt).object()) == feature()) {
+      myFeatures.erase(anIt);
+      break;
     }
-    if (!isSelected)
-      myFeatures = theHighlighted;
-    else
-      myFeatures = theSelected;
-  } else
-    myFeatures = theSelected;
-}
-
-void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature)
-{
-  setEditingFeature(theFeature);
+  }
 }
 
 FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
@@ -113,8 +130,8 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle
         SketchPlugin_Feature>(feature());
     aSketchFeature->move(aDeltaX, aDeltaY);
 
-    std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures
-        .end();
+    std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), 
+      aLast = myFeatures.end();
     for (; anIt != aLast; anIt++) {
       ObjectPtr aObject = (*anIt).object();
       if (!aObject || aObject == feature())