Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom.git into Dev_0.7.1
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
index 434d98c9086693dc70031db173af59ceacfbb016..7937a60c337249dc43e58308367d78e723b3951f 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "PartSet_SketcherMgr.h"
 #include "PartSet_Module.h"
-#include "PartSet_WidgetPoint2D.h"
+#include "PartSet_WidgetPoint2d.h"
 #include "PartSet_Tools.h"
 
 #include <XGUI_ModuleConnector.h>
@@ -184,7 +184,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
 
       get2dPoint(theWnd, theEvent, myCurX, myCurY);
       myDragDone = false;
-      aWorkshop->viewer()->enableMultiselection(false);
       launchEditing();
 
     } else if (isSketchOpe && isEditing) {
@@ -194,7 +193,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
       myIsDragging = true;
       get2dPoint(theWnd, theEvent, myCurX, myCurY);
       myDragDone = false;
-      aWorkshop->viewer()->enableMultiselection(false);
 
       // This is necessary in order to finalize previous operation
       QApplication::processEvents();
@@ -218,7 +216,6 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
     aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
     myIsDragging = false;
     if (myDragDone) {
-      aViewer->enableMultiselection(true);
       //aOp->commit();
       myFeature2AttributeMap.clear();
 
@@ -232,9 +229,6 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
       return;
     }
   }
-  if (!aViewer->isMultiSelectionEnabled()) {
-    aViewer->enableMultiselection(true);
-  }
 }
 
 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
@@ -277,24 +271,26 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     // 4. the features and attributes modification(move)
     for (; anIt != aLast; anIt++) {
       FeaturePtr aFeature = anIt.key();
-      AttributePtr anAttr;
 
       AttributeList anAttributes = anIt.value();
-      if (!anAttributes.empty()) {
-        anAttr = anAttributes.first();
-      }
       // Process selection by attribute: the priority to the attribute
-      if (anAttr.get() != NULL) {
-        std::string aAttrId = anAttr->id();
-        DataPtr aData = aFeature->data();
-        if (aData.get() != NULL) {
-          std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
-            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
-          if (aPoint.get() != NULL) {
-            bool isImmutable = aPoint->setImmutable(true);
-            aPoint->move(dX, dY);
-            ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
-            aPoint->setImmutable(isImmutable);
+      if (!anAttributes.empty()) {
+        AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
+        for (; anAttIt != anAttLast; anAttIt++) {
+          AttributePtr anAttr = *anAttIt;
+          if (anAttr.get() == NULL)
+            continue;
+          std::string aAttrId = anAttr->id();
+          DataPtr aData = aFeature->data();
+          if (aData.get() != NULL) {
+            std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
+              std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
+            if (aPoint.get() != NULL) {
+              bool isImmutable = aPoint->setImmutable(true);
+              aPoint->move(dX, dY);
+              ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
+              aPoint->setImmutable(isImmutable);
+            }
           }
         }
       } else {
@@ -440,16 +436,26 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
 
 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
 {
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
   DataPtr aData = myCurrentSketch->data();
   if ((!aData) || (!aData->isValid())) {
     // The sketch was aborted
     myCurrentSketch = CompositeFeaturePtr();
     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
+
+    // Erase all sketcher objects
+    QStringList aSketchIds = sketchOperationIdList();
+    QObjectPtrList aObjects = aDisplayer->displayedObjects();
+    foreach (ObjectPtr aObj, aObjects) {
+      DataPtr aObjData = aObj->data();
+      if ((!aObjData) || (!aObjData->isValid()))
+        aDisplayer->erase(aObj);
+    }
     return; 
   }
   // Hide all sketcher sub-Objects
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
-  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
     FeaturePtr aFeature = myCurrentSketch->subFeature(i);
     std::list<ResultPtr> aResults = aFeature->results();
@@ -524,6 +530,9 @@ void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
         continue;
       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
                                                                         aBRepOwner->Selectable());
+      if (anIO != anAISIO)
+        continue;
+
       if (aBRepOwner->HasShape()) {
         const TopoDS_Shape& aShape = aBRepOwner->Shape();
         TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
@@ -546,8 +555,6 @@ void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
                                              const FeaturePtr& theSketch,
                                              ModuleBase_IWorkshop* theWorkshop,
-                                             //const std::set<AttributePtr>& theSelectedAttributes,
-                                             //const std::set<ResultPtr>& theSelectedResults,
                                              const FeatureToSelectionMap& theSelection,
                                              SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
 {