From 1c2db2a9ea5f192e2bde3c81e19a9915e2f89d53 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 26 Jan 2015 11:22:48 +0300 Subject: [PATCH] Issue #348 Validate sketch is disabled when point coordinates are set manually It saves the clicked point, connects to the the activated signal of a widget and try initialize the widget with the point value. There are some limitations: Firstly, for the constraints distane we should not perform it because the fly out point is moved to the mouse, there is a blinking between calculated value and the clicked. It can be corrected if do not update the viewer during this. But, the lightes workaround is to do not apply clicked point to such type of operation. Secondly, the mouse release point should be also saved in the clicked point for the mouse moving with Left button swithed. Without this, the actuvatedwidget value is moved to the previuosly clicked mouse but not the current one. --- src/ModuleBase/ModuleBase_IPropertyPanel.h | 4 ++ src/PartSet/PartSet_SketcherMgr.cpp | 77 ++++++++++++++++++---- src/PartSet/PartSet_SketcherMgr.h | 44 ++++++++++++- src/XGUI/XGUI_PropertyPanel.cpp | 2 + src/XGUI/XGUI_Workshop.cpp | 2 + src/XGUI/XGUI_Workshop.h | 3 + 6 files changed, 116 insertions(+), 16 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index 77b65f2d6..1419a715e 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -50,6 +50,10 @@ signals: /// \param theEvent key release event void keyReleased(QKeyEvent* theEvent); + /// The signal about the widget activation + /// \param theWidget the activated widget + void beforeWidgetActivated(ModuleBase_ModelWidget* theWidget); + /// The signal about the widget activation /// \param theWidget the activated widget void widgetActivated(ModuleBase_ModelWidget* theWidget); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 7937a60c3..cce44aaa8 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #include #include @@ -102,8 +105,8 @@ void fillFeature2Attribute(const QList& theList, PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false) { - ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); - ModuleBase_IViewer* aViewer = aWorkshop->viewer(); + ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); + ModuleBase_IViewer* aViewer = anIWorkshop->viewer(); myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled(); @@ -118,6 +121,10 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*))); + + XGUI_ModuleConnector* aConnector = dynamic_cast(anIWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted())); } PartSet_SketcherMgr::~PartSet_SketcherMgr() @@ -128,6 +135,8 @@ PartSet_SketcherMgr::~PartSet_SketcherMgr() void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + get2dPoint(theWnd, theEvent, myClickedPoint); + // if (!(theEvent->buttons() & Qt::LeftButton)) return; @@ -182,7 +191,7 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE if (isSketcher) { myIsDragging = true; - get2dPoint(theWnd, theEvent, myCurX, myCurY); + get2dPoint(theWnd, theEvent, myCurrentPoint); myDragDone = false; launchEditing(); @@ -191,7 +200,7 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE aOperation->commit(); myIsDragging = true; - get2dPoint(theWnd, theEvent, myCurX, myCurY); + get2dPoint(theWnd, theEvent, myCurrentPoint); myDragDone = false; // This is necessary in order to finalize previous operation @@ -210,6 +219,8 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse if (!sketchOperationIdList().contains(aOp->id())) return; + get2dPoint(theWnd, theEvent, myClickedPoint); + // Only for sketcher operations ModuleBase_IViewer* aViewer = aWorkshop->viewer(); if (myIsDragging) { @@ -233,6 +244,8 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + myClickedPoint.clear(); + if (myIsDragging) { ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); // 1. it is necessary to save current selection in order to restore it after the features moving @@ -253,8 +266,8 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); double aX, aY; PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY); - double dX = aX - myCurX; - double dY = aY - myCurY; + double dX = aX - myCurrentPoint.myCurX; + double dY = aY - myCurrentPoint.myCurY; XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); @@ -321,8 +334,7 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve aDisplayer->enableUpdateViewer(isEnableUpdateViewer); aDisplayer->updateViewer(); myDragDone = true; - myCurX = aX; - myCurY = aY; + myCurrentPoint.setValue(aX, aY); } } @@ -331,9 +343,7 @@ void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMo ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation(); if (aOperation && aOperation->isEditOperation()) { std::string aId = aOperation->id().toStdString(); - if ((aId == SketchPlugin_ConstraintLength::ID()) || - (aId == SketchPlugin_ConstraintDistance::ID()) || - (aId == SketchPlugin_ConstraintRadius::ID())) + if (isDistanceOperation(aOperation)) { // Activate dimension value editing on double click ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); @@ -349,12 +359,53 @@ void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMo } } +void PartSet_SketcherMgr::onApplicationStarted() +{ + ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(anIWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel(); + if (aPropertyPanel) { + connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)), + this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*))); + } +} + +void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget) +{ + if (!myClickedPoint.myIsInitialized) + return; + + ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation(); + // the distance constraint feature should not use the clickedd point + // this is workaround in order to don't throw down the flyout point value, + // set by execute() method of these type of features + if (isDistanceOperation(aOperation)) + return; + + PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast(theWidget); + if (aPnt2dWgt) { + aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY); + } +} + +bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) const +{ + std::string aId = theOperation ? theOperation->id().toStdString() : ""; + + return (aId == SketchPlugin_ConstraintLength::ID()) || + (aId == SketchPlugin_ConstraintDistance::ID()) || + (aId == SketchPlugin_ConstraintRadius::ID()); +} + void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, - double& theX, double& theY) + Point& thePoint) { Handle(V3d_View) aView = theWnd->v3dView(); gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY); + double aX, anY; + PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY); + thePoint.setValue(aX, anY); } void PartSet_SketcherMgr::launchEditing() diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index bc976ded3..0b79b084e 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -26,6 +26,7 @@ class PartSet_Module; class ModuleBase_IViewWindow; +class ModuleBase_ModelWidget; class ModuleBase_Operation; class QMouseEvent; @@ -35,6 +36,36 @@ class QMouseEvent; class PARTSET_EXPORT PartSet_SketcherMgr : public QObject { Q_OBJECT + /// Struct to define gp point, with the state is the point is initialized + struct Point + { + /// Constructor + Point() + { + myIsInitialized = false; + } + /// Destructor + ~Point() + { + } + + /// clear the initialized flag. + void clear() + { + myIsInitialized = false; + } + /// set the point and switch on the initialized flag + /// \param thePoint the point + void setValue(const double theX, const double theY) + { + myIsInitialized = true; + myCurX = theX; + myCurY = theY; + } + + bool myIsInitialized; /// the state whether the point is set + double myCurX, myCurY; /// the point coordinates + }; public: PartSet_SketcherMgr(PartSet_Module* theModule); @@ -63,13 +94,19 @@ private slots: void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*); void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*); void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*); + void onApplicationStarted(); + void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget); private: + /// Returns whethe the current operation is a sketch distance - lenght, distance or radius + /// \param the operation + /// \return a boolean value + bool isDistanceOperation(ModuleBase_Operation* theOperation) const; + /// Converts mouse position to 2d coordinates. /// Member myCurrentSketch has to be correctly defined void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, - double& theX, double& theY); - + Point& thePoint); typedef QList AttributeList; typedef QMap FeatureToAttributesMap; @@ -124,7 +161,8 @@ private: bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer bool myIsDragging; bool myDragDone; - double myCurX, myCurY; + Point myCurrentPoint; + Point myClickedPoint; CompositeFeaturePtr myCurrentSketch; diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index d0b270536..fc337bc63 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -214,6 +214,8 @@ void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) myActiveWidget->setHighlighted(false); } if(theWidget) { + if (theWidget) + emit beforeWidgetActivated(theWidget); theWidget->activate(); theWidget->setHighlighted(true); } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 18942d3a2..9cc011bef 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -206,6 +206,8 @@ void XGUI_Workshop::startApplication() } onNew(); + + emit applicationStarted(); } //****************************************************** diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index d2423262c..13fa9039e 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -195,6 +195,9 @@ signals: //! the signal about the workshop actions states are updated. void commandStatusUpdated(); + //! the application is started + void applicationStarted(); + public slots: void updateCommandStatus(); -- 2.39.2