]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #348 Validate sketch is disabled when point coordinates are set manually
authornds <natalia.donis@opencascade.com>
Mon, 26 Jan 2015 08:22:48 +0000 (11:22 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 26 Jan 2015 08:22:48 +0000 (11:22 +0300)
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
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 77b65f2d6b0aeab6537ac9b6aef5126dc57efe80..1419a715e6c8ef4418ee948b0a87695939fe0230 100644 (file)
@@ -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);
index 7937a60c337249dc43e58308367d78e723b3951f..cce44aaa856d8a3a04c7f7fcfc1849eec8214c32 100644 (file)
@@ -14,6 +14,9 @@
 #include <XGUI_Workshop.h>
 #include <XGUI_Selection.h>
 #include <XGUI_SelectionMgr.h>
+#include <ModuleBase_ModelWidget.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_PropertyPanel.h>
 
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_IWorkshop.h>
@@ -102,8 +105,8 @@ void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& 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<XGUI_ModuleConnector*>(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<XGUI_ModuleConnector*>(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<XGUI_ModuleConnector*>(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<PartSet_WidgetPoint2D*>(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()
index bc976ded351740487be91d8b47afc34c153a08c5..0b79b084e0b18dd31deab0e8e67835c622e0b9a4 100644 (file)
@@ -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<AttributePtr> AttributeList;
   typedef QMap<FeaturePtr, AttributeList> 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;
 
index d0b270536e7d21f4b6816381ec31294410057c50..fc337bc6305a1a2e9cd2753613db5b6a427ef3f4 100644 (file)
@@ -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);
   }
index 18942d3a2577e3fe9454134f1328d66bb9644c92..9cc011bef1ebe1483c3d13ff4e8dceb26ca1d459 100644 (file)
@@ -206,6 +206,8 @@ void XGUI_Workshop::startApplication()
   }
   
   onNew();
+
+  emit applicationStarted();
 }
 
 //******************************************************
index d2423262c0d08803c5a1fe2d56e54363706bffda..13fa9039e7678785499ee88cc36efd7260f9558a 100644 (file)
@@ -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();