]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3135: Implement creation of sketch entities by mouse drag
authorvsv <vsv@opencascade.com>
Thu, 30 Jan 2020 12:52:54 +0000 (15:52 +0300)
committervsv <vsv@opencascade.com>
Thu, 30 Jan 2020 13:23:22 +0000 (16:23 +0300)
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_SketcherReentrantMgr.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp

index 7e8ff1db5d49ba611905bf13954ccf76479a6507..bc369e6edd538353d587569c0625a2d57ade8664 100644 (file)
@@ -66,6 +66,8 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
     "Rotate to plane when selected", Config_Prop::Boolean, "false");
   Config_PropManager::registerProp(SKETCH_TAB_NAME, "operation_cursor",
     "Cursor for Sketch operation", Config_Prop::Cursor, "0");
+  Config_PropManager::registerProp(SKETCH_TAB_NAME, "create_by_dragging",
+    "Create sketch enities by dragging", Config_Prop::Boolean, "false");
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index c57929240857943f38c965c34d622b7ffe75466f..eceebc0c0942166f3feb60f98ee987ada0f37c0e 100644 (file)
@@ -349,8 +349,13 @@ void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
 }
 */
 
+static bool MyModeByDrag = false;
+static bool MyMultiselectionState = true;
+
 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  MyModeByDrag = Config_PropManager::boolean(SKETCH_TAB_NAME, "create_by_dragging");
+
   // Clear dragging mode
   myIsDragging = false;
 
@@ -399,9 +404,26 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
       return;
 
     // Ignore creation sketch operation
-    if ((!isSketcher) && (!isEditing))
+    if ((!isSketcher) && (!isEditing)) {
+      if (MyModeByDrag) {
+        myMousePoint.setX(theEvent->x());
+        myMousePoint.setX(theEvent->y());
+        ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
+        PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
+        if (aProcessor) {
+          MyMultiselectionState = aViewer->isMultiSelectionEnabled();
+          aViewer->enableMultiselection(false);
+          myIsDragging = true;
+          ModuleBase_ISelection* aSelection = aWorkshop->selection();
+          QList<ModuleBase_ViewerPrsPtr> aPreSelected = aSelection->getHighlighted();
+          if (!aPreSelected.empty())
+            aProcessor->setPreSelection(aPreSelected.first(), theWnd, theEvent);
+          else
+            aProcessor->mouseReleased(theWnd, theEvent);
+        }
+      }
       return;
-
+    }
     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
     storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
 
@@ -506,12 +528,13 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
   if (!myIsMouseOverViewProcessed) {
     return;
   }
-  //if (!aViewer->canDragByMouse())
-  //  return;
+
   ModuleBase_OperationFeature* aOp =
     dynamic_cast<ModuleBase_OperationFeature*>(getCurrentOperation());
+  bool isEditing = false;
   if (aOp) {
-    bool aStartNoDragOperation = !aViewer->canDragByMouse() && aOp->isEditOperation();
+    isEditing = aOp->isEditOperation();
+    bool aStartNoDragOperation = !aViewer->canDragByMouse() && isEditing;
     if (aStartNoDragOperation || myNoDragMoving) {
       // Process edit operation without dragging
       if (myCurrentSelection.size() > 0)
@@ -541,11 +564,29 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
     }
   }
 
-
   ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
   PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
-  if (aProcessor)
-    aProcessor->mouseReleased(theWnd, theEvent);
+  if (aProcessor) {
+    ModuleBase_ISelection* aSelection = aWorkshop->selection();
+    QList<ModuleBase_ViewerPrsPtr> aPreSelected = aSelection->getHighlighted();
+    if (MyModeByDrag && !aPreSelected.empty() && !isEditing)
+      aProcessor->setPreSelection(aPreSelected.first(), theWnd, theEvent);
+    else
+      aProcessor->mouseReleased(theWnd, theEvent);
+  }
+  if (MyModeByDrag && aOp) {
+    QString aOpId = aOp->id();
+    if (aOpId == "Sketch")
+      return;
+    QPoint aPnt(theEvent->x(), theEvent->y());
+    if (aPnt == myMousePoint) {
+      aOp->abort();
+      return;
+    }
+    if ((aOpId != "SketchMacroArc") && (!isEditing)) {
+      module()->launchOperation(aOpId, true);
+    }
+  }
 }
 
 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
@@ -563,6 +604,9 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
   }
 #endif
+  if (MyModeByDrag && !myIsDragging)
+    return;
+
   if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
     return;
 
index 97fb2c720cf77533f3e58e33f6975d1e4f957e38..ab56be3a8b01df0a739fb81aac082f4a67c885ae 100644 (file)
@@ -55,6 +55,7 @@
 #include <QObject>
 #include <QList>
 #include <QMap>
+#include <QPoint>
 
 #include <set>
 
@@ -510,6 +511,8 @@ private:
   QMap<ResultPtr, Handle(AIS_Shape)> myPointsHighlight;
 
   bool myNoDragMoving;
+
+  QPoint myMousePoint;
 };
 
 
index d46c5d30dddae5eb37e7604f55e779e7877358f3..73ec80ebfb1bfab200f4fbc1f51807200790879b 100644 (file)
@@ -359,6 +359,9 @@ void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviou
     return;
   }
 
+  if (Config_PropManager::boolean(SKETCH_TAB_NAME, "create_by_dragging"))
+    return;
+
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                        (myWorkshop->currentOperation());
   if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
index b01f5fecddd6dfd17c5180c4a86f1b5088766f5e..0574f2e0003c37ab6bdbb81eff764a6af4d1bb77 100644 (file)
@@ -657,6 +657,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
         if (!anOrphanPoint)
           emit vertexSelected(); // it stops the reentrant operation
 
+        myPreSelected.reset();
         emit focusOutWidget(this);
       }
     }
@@ -701,6 +702,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
         updateObject(feature());
         if (!anOrphanPoint && !anExternal && !isAuxiliaryFeature)
           emit vertexSelected();
+        myPreSelected.reset();
         emit focusOutWidget(this);
       }
     }
@@ -735,6 +737,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
         setPoint(aPnt->x(), aPnt->y());
       }
       emit vertexSelected(); // it stops the reentrant operation
+      myPreSelected.reset();
       emit focusOutWidget(this);
     }
   }
@@ -748,6 +751,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
     if (!setPoint(aX, aY) || isFeatureContainsPoint(myFeature, aX, aY))
       return;
 
+    myPreSelected.reset();
     emit focusOutWidget(this);
   }
 }
@@ -759,7 +763,6 @@ void PartSet_WidgetPoint2D::setPreSelection(
 {
   myPreSelected = thePreSelected;
   mouseReleased(theWnd, theEvent);
-  myPreSelected = ModuleBase_ViewerPrsPtr();
 }
 
 void PartSet_WidgetPoint2D::getGeomSelection_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,