]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
authorvsv <vitaly.smetannikov@opencascade.com>
Sat, 27 Dec 2014 13:58:32 +0000 (16:58 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Sat, 27 Dec 2014 13:58:32 +0000 (16:58 +0300)
Conflicts:
src/PartSet/PartSet_SketcherMgr.cpp

src/PartSet/PartSet_SketcherMgr.cpp

index 0bfbaa816f885b1c68fa16fa9ae1bb0cb1852b43..466cb64294fb598cc0eb6681dfb7e8bb5c4c75cf 100644 (file)
@@ -23,6 +23,8 @@
 #include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_Operation.h>
 
+#include <GeomDataAPI_Point2D.h>
+
 #include <Events_Loop.h>
 
 #include <SketchPlugin_Line.h>
 
 
 /// Returns list of unique objects by sum of objects from List1 and List2
-QList<ObjectPtr> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
+QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
                                        const QList<ModuleBase_ViewerPrs>& theList2)
 {
-  QList<ObjectPtr> aRes;
+  QList<ModuleBase_ViewerPrs> aRes;
   foreach (ModuleBase_ViewerPrs aPrs, theList1) {
-    if (!aRes.contains(aPrs.object()))
-      aRes.append(aPrs.object());
+    if (!aRes.contains(aPrs))
+      aRes.append(aPrs);
   }
   foreach (ModuleBase_ViewerPrs aPrs, theList2) {
-    if (!aRes.contains(aPrs.object()))
-      aRes.append(aPrs.object());
+    if (!aRes.contains(aPrs))
+      aRes.append(aPrs);
   }
   return aRes;
 }
@@ -118,14 +120,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
     if ((!isSketcher) && (!isEditing))
       return;
 
-    if (theEvent->modifiers()) {
-      // If user performs multiselection
-      if (isSketchOpe /* && (!isSketcher)*/)
-        if (!aOperation->commit())
-          aOperation->abort();
-      return;
-    }
-
     // MoveTo in order to highlight current object
     ModuleBase_IViewer* aViewer = aWorkshop->viewer();
     aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
@@ -138,12 +132,12 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
     myEditingAttr.clear();
 
     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-    QObjectPtrList aSelObjects;
+    QList<ModuleBase_ViewerPrs> aSelObjects;
     if (aHasShift)
       aSelObjects = getSumList(aHighlighted, aSelected);
     else {
       foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
-        aSelObjects.append(aPrs.object());
+        aSelObjects.append(aPrs);
       }
     }
     if ((aSelObjects.size() == 0)) {
@@ -153,32 +147,22 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
           aOperation->abort();
       return;
     }
-    if (aSelObjects.size() == 1) {
-      // Move by selected shape (vertex). Can be used only for single selection
-      foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(aHighlighted.first().object());
-        if (aFeature) {
-          myEditingFeatures.append(aFeature);
-          TopoDS_Shape aShape = aPrs.shape();
-          if (!aShape.IsNull()) {
-            if (aShape.ShapeType() == TopAbs_VERTEX) {
-              AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(), 
-                                                                         aShape, myCurrentSketch);
-              if (aAttr)
-                myEditingAttr.append(aAttr);
-            }
+
+    foreach(ModuleBase_ViewerPrs aPrs, aSelObjects) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
+      if (aFeature) {
+        myEditingFeatures.append(aFeature);
+        AttributePtr aAttr;
+        TopoDS_Shape aShape = aPrs.shape();
+        if (!aShape.IsNull()) {
+          if (aShape.ShapeType() == TopAbs_VERTEX) {
+            aAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, myCurrentSketch);
           }
         }
+        myEditingAttr.append(aAttr);
       }
-    } else {
-      // Provide multi-selection. Can be used only for features
-      foreach (ObjectPtr aObj, aSelObjects) {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
-        if (aFeature && (!myEditingFeatures.contains(aFeature)))
-          myEditingFeatures.append(aFeature);
-      }
-
     }
+
     // If nothing highlighted - return
     if (myEditingFeatures.size() == 0)
       return;
@@ -246,8 +230,6 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
       return; // No edit operation activated
 
-    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
-
     Handle(V3d_View) aView = theWnd->v3dView();
     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
     double aX, aY;
@@ -260,66 +242,54 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
     bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
 
-    if ((myEditingAttr.size() == 1) && myEditingAttr.first()) {
-      FeaturePtr aSketchFeature = myEditingFeatures.first();
+    static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
+    static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
 
-      // probably we have prehighlighted point
-      AttributePtr aAttr = myEditingAttr.first();
-      std::string aAttrId = aAttr->id();
-      ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
-      QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
-      // Find corresponded widget to provide dragging
-      foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
-        if (aWgt->attributeID() == aAttrId) {
-          PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
-          if (aWgt2d) {
-            aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
-            break;
+    for (int i = 0; i < myEditingFeatures.size(); i++) {
+      AttributePtr aAttr = myEditingAttr.at(i);
+      FeaturePtr aFeature = myEditingFeatures.at(i);
+      // save the previous selection
+      std::set<AttributePtr> aSelectedAttributes;
+      std::set<ResultPtr> aSelectedResults;
+      getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
+                          aSelectedResults);
+      // save the previous selection: end
+
+      // Process selection by attribute
+      if (aAttr.get() != NULL) {
+        std::string aAttrId = aAttr->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);
           }
         }
-      }
-      // restore the previous selection
-      SelectMgr_IndexedMapOfOwner anOwnersToSelect;
-      std::set<AttributePtr> aSelectedAttributes;
-      aSelectedAttributes.insert(aAttr);
-      getSelectionOwners(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
-                         std::set<ResultPtr>(), anOwnersToSelect);
-      aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
-      // restore the previous selection
-    } else {
-      foreach(FeaturePtr aFeature, myEditingFeatures) {
+      } else {
+        // Process selection by feature
         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
         if (aSketchFeature) {
-          // save the previous selection
-          std::set<AttributePtr> aSelectedAttributes;
-          std::set<ResultPtr> aSelectedResults;
-          getCurrentSelection(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
-                              aSelectedResults);
-          // save the previous selection: end
-
           aSketchFeature->move(dX, dY);
+          ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
           // TODO: the selection restore should be after the AIS presentation is rebuilt
-          Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
-          Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-
-          // restore the previous selection
-          SelectMgr_IndexedMapOfOwner anOwnersToSelect;
-          getSelectionOwners(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
-                             aSelectedResults, anOwnersToSelect);
-          aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
-          // restore the previous selection
         }
-        ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
-        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
       }
-      // TODO: set here
-      //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
-      //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-
-      //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+      Events_Loop::loop()->flush(aMoveEvent);
+      Events_Loop::loop()->flush(aUpdateEvent);
+      // restore the previous selection
+      SelectMgr_IndexedMapOfOwner anOwnersToSelect;
+      getSelectionOwners(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
+                         aSelectedResults, anOwnersToSelect);
+      aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
+      // restore the previous selection
+      ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent, true);
     }
-
+    Events_Loop::loop()->flush(aUpdateEvent);
     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
     aDisplayer->updateViewer();
     myDragDone = true;
@@ -327,6 +297,63 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     myCurY = aY;
   }
 }
+    //if ((myEditingAttr.size() == 1) && myEditingAttr.first()) {
+    //  // probably we have prehighlighted point
+    //  AttributePtr aAttr = myEditingAttr.first();
+    //  std::string aAttrId = aAttr->id();
+    //  ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+    //  QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
+    //  // Find corresponded widget to provide dragging
+    //  foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
+    //    if (aWgt->attributeID() == aAttrId) {
+    //      PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
+    //      if (aWgt2d) {
+    //        aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
+    //        break;
+    //      }
+    //    }
+    //  }
+    //} else {
+    //  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+    //  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+    //  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+    //  bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
+
+    //  foreach(FeaturePtr aFeature, myEditingFeatures) {
+    //    std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+    //      std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+    //    if (aSketchFeature) {
+    //      // save the previous selection
+
+    //      std::set<AttributePtr> aSelectedAttributes;
+    //      std::set<ResultPtr> aSelectedResults;
+    //      getCurrentSelection(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
+    //                          aSelectedResults);
+    //      // save the previous selection: end
+
+    //      aSketchFeature->move(dX, dY);
+    //      // TODO: the selection restore should be after the AIS presentation is rebuilt
+    //      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
+    //      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+
+    //      // restore the previous selection
+    //      SelectMgr_IndexedMapOfOwner anOwnersToSelect;
+    //      getSelectionOwners(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
+    //                         aSelectedResults, anOwnersToSelect);
+    //      aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
+    //      // restore the previous selection
+    //    }
+    //    ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent, true);
+    //    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    //  }
+    //  // TODO: set here
+    //  //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
+    //  //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+
+    //  //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+    //  aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
+    //  aDisplayer->updateViewer();
+    //}
 
 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
@@ -560,8 +587,10 @@ void PartSet_SketcherMgr::getSelectionOwners(const ObjectPtr& theObject,
         }
       }
       else if (aShapeType == TopAbs_EDGE) {
-        if (theSelectedResults.find(aResult) != theSelectedResults.end() &&
-            anOwnersToSelect.FindIndex(anOwner) <= 0)
+        bool aFound = theSelectedResults.find(aResult) != theSelectedResults.end();
+        int anIndex = anOwnersToSelect.FindIndex(anOwner);
+        if (theSelectedResults.find(aResult) != theSelectedResults.end()/* &&
+            anOwnersToSelect.FindIndex(anOwner) < 0*/)
           anOwnersToSelect.Add(anOwner);
       }
     }