Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
authornds <natalia.donis@opencascade.com>
Mon, 26 Jan 2015 08:28:11 +0000 (11:28 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 26 Jan 2015 08:28:11 +0000 (11:28 +0300)
Conflicts:
src/ModuleBase/ModuleBase_ModelWidget.h
src/PartSet/PartSet_SketcherMgr.cpp

src/GeomData/GeomData_Point2D.cpp
src/ModuleBase/ModuleBase_IPropertyPanel.h
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 5061f8193ec6c8eb495116a788fb2395fb5239bb..314a0ab79468c6d545e651dcdfa2a70b963b3ac2 100644 (file)
@@ -13,7 +13,7 @@ using namespace std;
 
 void GeomData_Point2D::setValue(const double theX, const double theY)
 {
-  if (myCoords->Value(0) != theX || myCoords->Value(1) != theY) {
+  if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY) {
     myCoords->SetValue(0, theX);
     myCoords->SetValue(1, theY);
     owner()->data()->sendAttributeUpdated(this);
index ddd3fc7d2938f9204d6bc89c093fd03aaf72c90a..224691890ed8d4eae59f5a69f6e87e5c72337053 100644 (file)
@@ -60,6 +60,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 79b00dfe2071fb892d6c3d3799377ad17f3ac438..6a5421549ff74845da9a60dca29fd6257a54761d 100644 (file)
@@ -27,6 +27,7 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_
     : QObject(theParent),
       myParentId(theParentId)
 {
+  myIsValueDefault = !theData->getProperty(ATTR_DEFAULT).empty();
   myIsComputedDefault = false;
   myAttributeID = theData ? theData->widgetId() : "";
 }
index 35bd1632026d91a530505880b3f41c2c47746121..c4b2ec614f3a6db38f57c9ab4ac66b024247c8e1 100644 (file)
@@ -51,6 +51,11 @@ Q_OBJECT
   /// on operation's execute, like radius for circle's constraint (can not be zero)
   bool isComputedDefault() { return myIsComputedDefault; }
 
+  /// Returns true, if default value of the widget is defined in the XML and it is not the
+  /// computed value
+  /// \return the boolean result
+  bool isValueDefault() { return myIsValueDefault; }
+
   /// Defines if it is supposed that the widget should interact with the viewer.
   virtual bool isViewerSelector() { return false; }
 
@@ -177,7 +182,9 @@ signals:
 
   /// Value should be computed on execute, like radius for circle's constraint (can not be zero)
   bool myIsComputedDefault; 
-                            
+                        
+  /// the default value is defined in the XML for this attribute    
+  bool myIsValueDefault;
   /// Flag which shows that current operation is in editing mode
   bool myIsEditing; 
 };
index 0da5482f9a72bfeb51b4f133c175f3ef6e9b85a6..bd8b15dd374cf64f4a89baa5f06a3df0c1edfb83 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;
@@ -184,7 +193,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();
 
@@ -193,7 +202,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
@@ -209,6 +218,8 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse
   ModuleBase_Operation* aOp = aWorkshop->currentOperation();
   if (aOp) {
     if (sketchOperationIdList().contains(aOp->id())) {
+  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
@@ -255,8 +268,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();
@@ -323,8 +336,7 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
     aDisplayer->updateViewer();
     myDragDone = true;
-    myCurX = aX;
-    myCurY = aY;
+    myCurrentPoint.setValue(aX, aY);
   }
 }
 
@@ -333,9 +345,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();
@@ -351,12 +361,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 21f885c64ee4dadac4f2aefc45fca1368230f1a2..c008d9d71650c08a3e881e3ff8a0632d81e9d503 100644 (file)
@@ -194,6 +194,9 @@ void PartSet_WidgetPoint2D::activate()
   QIntList aModes;
   aModes << TopAbs_VERTEX;
   myWorkshop->moduleConnector()->activateSubShapesSelection(aModes);
+  // the control value is stored to the mode by the focus in on the widget
+  // we need the value is initialized in order to enable the apply button in the property panel
+  storeValue();
 }
 
 void PartSet_WidgetPoint2D::deactivate()
@@ -276,6 +279,9 @@ void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEv
   if (isEditingMode())
     return;
   myWorkshop->operationMgr()->setLockValidating(true);
+  // the Ok button should be disabled in the property panel by moving the mouse point in the viewer
+  // this leads that the user does not try to click Ok and it avoids an incorrect situation that the 
+  // line is moved to the cursor to the Ok button
   myWorkshop->propertyPanel()->setOkEnabled(false);
 
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
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 0f056a94f63ac057c2f3a324551af85c1b159096..77acb88d5fb0d6fc6937e72a2d42e3204e38f948 100644 (file)
@@ -206,6 +206,8 @@ void XGUI_Workshop::startApplication()
   }
   
   onNew();
+
+  emit applicationStarted();
 }
 
 //******************************************************
@@ -632,7 +634,7 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
     aWidget->enableFocusProcessing();
     QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
     // Init default values
-    if (!theOperation->isEditOperation() && !aWidget->isComputedDefault()) {
+    if (!theOperation->isEditOperation() && aWidget->isValueDefault() && !aWidget->isComputedDefault()) {
       aWidget->storeValue();
     }
   }
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();