From: vsv Date: Thu, 30 Jan 2020 12:52:54 +0000 (+0300) Subject: Issue #3135: Implement creation of sketch entities by mouse drag X-Git-Tag: V9_5_0a1~51 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a4d7bd33d764bf6c6d893763b4b9a9c712d75f2d;p=modules%2Fshaper.git Issue #3135: Implement creation of sketch entities by mouse drag --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 7e8ff1db5..bc369e6ed 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -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); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index c57929240..eceebc0c0 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -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(anActiveWidget); + if (aProcessor) { + MyMultiselectionState = aViewer->isMultiSelectionEnabled(); + aViewer->enableMultiselection(false); + myIsDragging = true; + ModuleBase_ISelection* aSelection = aWorkshop->selection(); + QList 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(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(anActiveWidget); - if (aProcessor) - aProcessor->mouseReleased(theWnd, theEvent); + if (aProcessor) { + ModuleBase_ISelection* aSelection = aWorkshop->selection(); + QList 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; diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 97fb2c720..ab56be3a8 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -510,6 +511,8 @@ private: QMap myPointsHighlight; bool myNoDragMoving; + + QPoint myMousePoint; }; diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.cpp b/src/PartSet/PartSet_SketcherReentrantMgr.cpp index d46c5d30d..73ec80ebf 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReentrantMgr.cpp @@ -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 (myWorkshop->currentOperation()); if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index b01f5fecd..0574f2e00 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -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& theValue,