]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
It replaces two lists of features and attributes to a map of feature to a list of...
authornds <natalia.donis@opencascade.com>
Mon, 29 Dec 2014 10:10:01 +0000 (13:10 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 29 Dec 2014 10:10:01 +0000 (13:10 +0300)
It fixes a multi-selection bug, in the new version it is possible to move a countour of four lines in another place, the countour figure is not changed.

src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h

index 6937e5181730d59595021f1861ea5f1258e35ce5..7c4d9ffebb14b6c94055aca8115c6d9526454f7b 100644 (file)
 #include <QApplication>
 
 
-
-
 /// Returns list of unique objects by sum of objects from List1 and List2
-QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
+/*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
                                        const QList<ModuleBase_ViewerPrs>& theList2)
 {
   QList<ModuleBase_ViewerPrs> aRes;
@@ -64,6 +62,38 @@ QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theLis
       aRes.append(aPrs);
   }
   return aRes;
+}*/
+
+void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
+                           QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
+                           const FeaturePtr theSketch)
+{
+  QList<ModuleBase_ViewerPrs> aRes;
+
+  QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
+                                              aLast = theList.end();
+  for (; anIt != aLast; anIt++)
+  {
+    ModuleBase_ViewerPrs aPrs = *anIt;
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
+    if (aFeature.get() == NULL)
+      continue;
+
+    QList<AttributePtr> anAttributes;
+    if (theFeature2AttributeMap.contains(aFeature)) {
+      anAttributes = theFeature2AttributeMap[aFeature];
+    }
+    AttributePtr anAttr;
+    TopoDS_Shape aShape = aPrs.shape();
+    if (!aShape.IsNull()) {
+      if (aShape.ShapeType() == TopAbs_VERTEX) {
+        anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
+        if (anAttr.get() != NULL && !anAttributes.contains(anAttr))
+          anAttributes.push_back(anAttr);
+      }
+    }
+    theFeature2AttributeMap[aFeature] = anAttributes;
+  }
 }
 
 
@@ -128,19 +158,18 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
     ModuleBase_ISelection* aSelect = aWorkshop->selection();
     QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
-    myEditingFeatures.clear();
-    myEditingAttr.clear();
+    myFeature2AttributeMap.clear();
 
     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-    QList<ModuleBase_ViewerPrs> aSelObjects;
-    if (aHasShift)
-      aSelObjects = getSumList(aHighlighted, aSelected);
+    if (aHasShift) {
+      fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
+      fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
+    }
     else {
-      foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
-        aSelObjects.append(aPrs);
-      }
+      fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
     }
-    if ((aSelObjects.size() == 0)) {
+
+    if (myFeature2AttributeMap.empty()) {
       if (isSketchOpe && (!isSketcher))
         // commit previous operation
         if (!aOperation->commit())
@@ -148,25 +177,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
       return;
     }
 
-    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);
-      }
-    }
-
-    // If nothing highlighted - return
-    if (myEditingFeatures.size() == 0)
-      return;
-
     if (isSketcher) {
       myIsDragging = true;
       get2dPoint(theWnd, theEvent, myCurX, myCurY);
@@ -206,8 +216,7 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
     if (myDragDone) {
       aViewer->enableMultiselection(true);
       //aOp->commit();
-      myEditingFeatures.clear();
-      myEditingAttr.clear();
+      myFeature2AttributeMap.clear();
 
       // Reselect edited object
       aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
@@ -245,9 +254,17 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
     static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
 
-    for (int i = 0; i < myEditingFeatures.size(); i++) {
-      AttributePtr aAttr = myEditingAttr.at(i);
-      FeaturePtr aFeature = myEditingFeatures.at(i);
+    FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
+                                           aLast = myFeature2AttributeMap.end();
+    for (; anIt != aLast; anIt++) {
+      FeaturePtr aFeature = anIt.key();
+      AttributePtr anAttr;
+
+      AttributeList anAttributes = anIt.value();
+      if (!anAttributes.empty()) {
+        anAttr = anAttributes.first();
+      }
+
       // save the previous selection
       std::set<AttributePtr> aSelectedAttributes;
       std::set<ResultPtr> aSelectedResults;
@@ -256,8 +273,8 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
       // save the previous selection: end
 
       // Process selection by attribute
-      if (aAttr.get() != NULL) {
-        std::string aAttrId = aAttr->id();
+      if (anAttr.get() != NULL) {
+        std::string aAttrId = anAttr->id();
         DataPtr aData = aFeature->data();
         if (aData.get() != NULL) {
           std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
@@ -279,17 +296,22 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
           // TODO: the selection restore should be after the AIS presentation is rebuilt
         }
       }
-      Events_Loop::loop()->flush(aMoveEvent);
-      Events_Loop::loop()->flush(aUpdateEvent);
+      //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);
+      //TODO: after the last flush
+      //SelectMgr_IndexedMapOfOwner anOwnersToSelect;
+      //getSelectionOwners(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
+      //                   aSelectedResults, anOwnersToSelect);
+      //TODO: after the last flush
+      //aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
       // restore the previous selection
       ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent, true);
+      Events_Loop::loop()->flush(aUpdateEvent);
     }
+    Events_Loop::loop()->flush(aMoveEvent);
     Events_Loop::loop()->flush(aUpdateEvent);
+
     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
     aDisplayer->updateViewer();
     myDragDone = true;
@@ -395,14 +417,15 @@ void PartSet_SketcherMgr::launchEditing()
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
   aConnector->activateSubShapesSelection(aModes);
 
-  if (myEditingFeatures.size() > 0) {
-    FeaturePtr aFeature = myEditingFeatures.first();
+  if (!myFeature2AttributeMap.empty()) {
+    FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
     if (aSPFeature) {
       myModule->editFeature(aSPFeature);
     }
   }
 }
 
 
index 083e918b580851bbf2b27651af9f0e99e70d6bfa..c2f55bf79219f9b4656d7d03c11eecc110aaa530 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QObject>
 #include <QList>
+#include <QMap>
 
 class PartSet_Module;
 class ModuleBase_IViewWindow;
@@ -114,8 +115,10 @@ private:
   double myCurX, myCurY;
 
   CompositeFeaturePtr myCurrentSketch;
-  QList<FeaturePtr> myEditingFeatures;
-  QList<AttributePtr> myEditingAttr;
+
+  typedef QList<AttributePtr> AttributeList;
+  typedef QMap<FeaturePtr, AttributeList> FeatureToAttributesMap;
+  FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes
 
   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
 };