From: nds Date: Mon, 26 Jan 2015 08:28:11 +0000 (+0300) Subject: Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1 X-Git-Tag: V_1.0.0~22^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d499ef7358a4dc4ce020054fc94ef04c22e9e444;hp=c47decf94380d5c06fd22a03634e464f8ed33de6;p=modules%2Fshaper.git Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1 Conflicts: src/ModuleBase/ModuleBase_ModelWidget.h src/PartSet/PartSet_SketcherMgr.cpp --- diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index 5061f8193..314a0ab79 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -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); diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index ddd3fc7d2..224691890 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -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); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 79b00dfe2..6a5421549 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -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() : ""; } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 35bd16320..c4b2ec614 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -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; }; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 0da5482f9..bd8b15dd3 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; @@ -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(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(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/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 21f885c64..c008d9d71 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -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()); 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 0f056a94f..77acb88d5 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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(); } } 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();