]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Debug the multi-edit operation. The restore of the selection after all features are...
authornds <natalia.donis@opencascade.com>
Mon, 29 Dec 2014 12:27:10 +0000 (15:27 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 29 Dec 2014 12:27:10 +0000 (15:27 +0300)
Edge activation mode in the context for the edit operation(in order to the selection of the edge is not lost during moving)
do not flush for the Update signal, because it is automatically called by the solver after pocessing(flush) the move signal.

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

index 7c4d9ffebb14b6c94055aca8115c6d9526454f7b..f2094b5712d1b16a4a0043393e41b6e8c102f720 100644 (file)
@@ -252,10 +252,11 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
 
     static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
-    static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+    //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
 
     FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
                                            aLast = myFeature2AttributeMap.end();
+    FeatureToSelectionMap aCurrentSelection;
     for (; anIt != aLast; anIt++) {
       FeaturePtr aFeature = anIt.key();
       AttributePtr anAttr;
@@ -266,13 +267,10 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
       }
 
       // save the previous selection
-      std::set<AttributePtr> aSelectedAttributes;
-      std::set<ResultPtr> aSelectedResults;
-      getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes,
-                          aSelectedResults);
+      getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, aCurrentSelection);
       // save the previous selection: end
 
-      // Process selection by attribute
+      // Process selection by attribute: the priority to the attribute
       if (anAttr.get() != NULL) {
         std::string aAttrId = anAttr->id();
         DataPtr aData = aFeature->data();
@@ -293,24 +291,23 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
         if (aSketchFeature) {
           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(aMoveEvent);
-      //Events_Loop::loop()->flush(aUpdateEvent);
-      // restore the previous selection
-      //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);
+    Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
+    //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
+
+    // restore the previous selection
+    FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
+                                          aSLast = aCurrentSelection.end();
+    SelectMgr_IndexedMapOfOwner anOwnersToSelect;
+    for (; aSIt != aSLast; aSIt++) {
+      anOwnersToSelect.Clear();
+      getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
+                         anOwnersToSelect);
+      aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
+    }
+    // restore the previous selection: end
 
     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
     aDisplayer->updateViewer();
@@ -319,63 +316,6 @@ 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)
 {
@@ -413,7 +353,7 @@ void PartSet_SketcherMgr::launchEditing()
   // there should be activate the vertex selection mode because the edit can happens by the selected
   // point
   QIntList aModes;
-  aModes << TopAbs_VERTEX;
+  aModes << TopAbs_VERTEX << TopAbs_EDGE;
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
   aConnector->activateSubShapesSelection(aModes);
 
@@ -525,22 +465,25 @@ void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& th
   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
 }
 
-void PartSet_SketcherMgr::getCurrentSelection(const ObjectPtr& theObject,
+void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
                                               const FeaturePtr& theSketch,
                                               ModuleBase_IWorkshop* theWorkshop,
-                                              std::set<AttributePtr>& theSelectedAttributes,
-                                              std::set<ResultPtr>& theSelectedResults)
+                                              FeatureToSelectionMap& theSelection)
+                                              //std::set<AttributePtr>& theSelectedAttributes,
+                                              //std::set<ResultPtr>& theSelectedResults)
 {
-  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-  if (aFeature.get() == NULL)
+  if (theFeature.get() == NULL)
     return;
 
+  std::set<AttributePtr> aSelectedAttributes;
+  std::set<ResultPtr> aSelectedResults;
+
   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
-  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr> aResults = theFeature->results();
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
   {
@@ -561,37 +504,42 @@ void PartSet_SketcherMgr::getCurrentSelection(const ObjectPtr& theObject,
         const TopoDS_Shape& aShape = aBRepOwner->Shape();
         TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
         if (aShapeType == TopAbs_VERTEX) {
-          AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObject,
+          AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
                                                                         aShape, theSketch);
           if (aPntAttr.get() != NULL)
-            theSelectedAttributes.insert(aPntAttr);
+            aSelectedAttributes.insert(aPntAttr);
         }
         else if (aShapeType == TopAbs_EDGE &&
-                 theSelectedResults.find(aResult) == theSelectedResults.end()) {
-          theSelectedResults.insert(aResult);
+                 aSelectedResults.find(aResult) == aSelectedResults.end()) {
+          aSelectedResults.insert(aResult);
         }
       }
     }
   }
+  theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
 }
 
-void PartSet_SketcherMgr::getSelectionOwners(const ObjectPtr& theObject,
+void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
                                              const FeaturePtr& theSketch,
                                              ModuleBase_IWorkshop* theWorkshop,
-                                             const std::set<AttributePtr>& theSelectedAttributes,
-                                             const std::set<ResultPtr>& theSelectedResults,
+                                             //const std::set<AttributePtr>& theSelectedAttributes,
+                                             //const std::set<ResultPtr>& theSelectedResults,
+                                             const FeatureToSelectionMap& theSelection,
                                              SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
 {
-  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-  if (aFeature.get() == NULL)
+  if (theFeature.get() == NULL)
     return;
 
+  FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
+  std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
+  std::set<ResultPtr> aSelectedResults = anIt->second.second;
+
   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
-  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr> aResults = theFeature->results();
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
   {
@@ -610,17 +558,16 @@ void PartSet_SketcherMgr::getSelectionOwners(const ObjectPtr& theObject,
       const TopoDS_Shape& aShape = anOwner->Shape();
       TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
       if (aShapeType == TopAbs_VERTEX) {
-        AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
+        AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
         if (aPntAttr.get() != NULL &&
-            theSelectedAttributes.find(aPntAttr) != theSelectedAttributes.end()) {
+            aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
           anOwnersToSelect.Add(anOwner);
         }
       }
       else if (aShapeType == TopAbs_EDGE) {
-        bool aFound = theSelectedResults.find(aResult) != theSelectedResults.end();
-        int anIndex = anOwnersToSelect.FindIndex(anOwner);
-        if (theSelectedResults.find(aResult) != theSelectedResults.end()/* &&
-            anOwnersToSelect.FindIndex(anOwner) < 0*/)
+        bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
+        if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
+            anOwnersToSelect.FindIndex(anOwner) <= 0)
           anOwnersToSelect.Add(anOwner);
       }
     }
index c2f55bf79219f9b4656d7d03c11eecc110aaa530..2f51af93129a8dc27eab0c6987e6cb71598db7e3 100644 (file)
@@ -29,7 +29,6 @@ class ModuleBase_IViewWindow;
 class ModuleBase_Operation;
 class QMouseEvent;
 
-
 /**
 * A class for management of sketch operations
 */
@@ -71,21 +70,22 @@ private:
   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
                   double& theX, double& theY);
 
+
+  typedef std::map<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
+                                                                       FeatureToSelectionMap;
   /// Obtains the current selection of the object in the workshop viewer 
   /// It includes the selection in all modes of activation, even local context - vertices, edges
   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
   /// the feature, if the owner is edge, the current result is added to the container of results.
-  /// \param theObject a feature or result object
+  /// \param theFeature a feature or result object
   /// \param theSketch a current sketch feature
   /// \param theWorkshop a workshop to have an access to AIS context and displayer
-  /// \param theSelectedAttributes an out list of selected attributes
-  /// \param theSelectedResults an out list of selected results
-  static void getCurrentSelection(const ObjectPtr& theObject,
+  /// \param theSelection a container for the selection, to save results and attributres for a feature
+  static void getCurrentSelection(const FeaturePtr& theFeature,
                                   const FeaturePtr& theSketch,
                                   ModuleBase_IWorkshop* theWorkshop,
-                                  std::set<AttributePtr>& theSelectedAttributes,
-                                  std::set<ResultPtr>& theSelectedResults);
+                                  FeatureToSelectionMap& theSelection);
 
   /// Applyes the current selection to the object in the workshop viewer 
   /// It includes the selection in all modes of activation, even local context - vertexes, edges
@@ -94,17 +94,15 @@ private:
   /// the feature and if it is in the container of selected attributes, the owner is put in the
   /// out container. If the owner is edge and the current result is in the container of selected
   /// results, the owner is put in the out container.
-  /// \param theObject a feature or result object
+  /// \param theFeature a feature or result object
   /// \param theSketch a current sketch feature
   /// \param theWorkshop a workshop to have an access to AIS context and displayer
-  /// \param theSelectedAttributes an list of selected attributes
-  /// \param theSelectedResults an list of selected results
+  /// \param theSelection a container of the selection, it has results and attributres for a feature
   /// \param theOwnersToSelect an out container of found owners
-  static void getSelectionOwners(const ObjectPtr& theObject,
+  static void 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);
 
 private: