From: nds Date: Thu, 12 Feb 2015 07:45:21 +0000 (+0300) Subject: Issue #394 Undo-ing a Sketch element X-Git-Tag: V_1.1.0~199 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7e85caf42f4f1b8f04444afc76a039036f27de9f;p=modules%2Fshaper.git Issue #394 Undo-ing a Sketch element --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 44b43e462..87fcd1db7 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -142,6 +142,9 @@ signals: /// The signal about widget values changed void valuesChanged(); + /// The signal about widget values changed + void controlValuesChanged(); + /// The signal about key release on the control, that corresponds to the attribute /// \param theEvent key release event void keyReleased(QKeyEvent* theEvent); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 6b1f52ed3..6d17b4153 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -94,6 +94,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, aControlLay->setStretch(1, 1); connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(controlValuesChanged())); } ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 8c0eff955..280c107f6 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -74,6 +74,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${CMAKE_SOURCE_DIR}/src/SketchPlugin ${CMAKE_SOURCE_DIR}/src/FeaturesPlugin ${CMAKE_SOURCE_DIR}/src/GeomAPI + ${CMAKE_SOURCE_DIR}/src/AppElements ${CAS_INCLUDE_DIRS} ${SUIT_INCLUDE} ) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c3b595796..e1e18df38 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -186,9 +186,13 @@ void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation) void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation) { - if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) { + if (PartSet_SketcherMgr::isSketchOperation(theOperation)) { mySketchMgr->startSketch(theOperation); } + else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) { + mySketchMgr->startNestedSketch(theOperation); + } + if (myDocumentShapeFilter.IsNull()) myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop); myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter); @@ -196,15 +200,21 @@ void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation) void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation) { - if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) { + if (PartSet_SketcherMgr::isSketchOperation(theOperation) || + PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) { mySketchMgr->stopSketch(theOperation); } + else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) { + mySketchMgr->stopNestedSketch(theOperation); + } myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter); } bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const { bool aCanDisplay = false; + if (!mySketchMgr->canDisplayObject(theObject)) + return aCanDisplay; CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch(); if (aSketchFeature.get() != NULL) { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); @@ -238,7 +248,8 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const void PartSet_Module::addViewerItems(QMenu* theMenu) const { - if (!isSketchOperationActive() && !isSketchFeatureOperationActive()) + if (!PartSet_SketcherMgr::isSketchOperation(myWorkshop->currentOperation()) && + !isSketchFeatureOperationActive()) return; ModuleBase_ISelection* aSelection = myWorkshop->selection(); QObjectPtrList aObjects = aSelection->selectedPresentations(); @@ -259,8 +270,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) { ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel(); - if ((theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) && - (theOperation->isEditOperation())) { + if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) { // we have to manually activate the sketch label in edit mode aPanel->activateWidget(aPanel->modelWidgets().first()); return; @@ -289,20 +299,17 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) if (theOperation->isEditOperation()) { // TODO: #391 - to be removed std::string aId = theOperation->id().toStdString(); - if (PartSet_SketcherMgr::sketchOperationIdList().contains(QString(aId.c_str()))) { - if ((aId == SketchPlugin_ConstraintRadius::ID()) || - (aId == SketchPlugin_ConstraintLength::ID()) || - (aId == SketchPlugin_ConstraintDistance::ID())) { - // Find and activate widget for management of point for dimension line position - QList aWidgets = aPanel->modelWidgets(); - foreach (ModuleBase_ModelWidget* aWgt, aWidgets) { - PartSet_WidgetPoint2D* aPntWgt = dynamic_cast(aWgt); - if (aPntWgt) { - aPanel->activateWidget(aPntWgt); - return; - } + if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) && + PartSet_SketcherMgr::isDistanceOperation(theOperation)) { + // Find and activate widget for management of point for dimension line position + QList aWidgets = aPanel->modelWidgets(); + foreach (ModuleBase_ModelWidget* aWgt, aWidgets) { + PartSet_WidgetPoint2D* aPntWgt = dynamic_cast(aWgt); + if (aPntWgt) { + aPanel->activateWidget(aPntWgt); + return; } - } + } } } } @@ -319,7 +326,7 @@ void PartSet_Module::onSelectionChanged() // An edit operation is enable only if the current opeation is the sketch operation if (mySketchMgr->activeSketch()) { if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch())) - isSketcherOp = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()); + isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation); } if (isSketcherOp) { // Editing of constraints can be done on selection @@ -442,14 +449,6 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* return 0; } -bool PartSet_Module::isSketchOperationActive() const -{ - ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); - - bool isSketchOp = aOperation && aOperation->id().toStdString() == SketchPlugin_Sketch::ID(); - return isSketchOp; -} - bool PartSet_Module::isSketchFeatureOperationActive() const { bool isCurrentSketchOp = false; @@ -497,7 +496,7 @@ void PartSet_Module::onAction(bool isChecked) void PartSet_Module::deleteObjects() { - bool isSketchOp = isSketchOperationActive(); + bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(myWorkshop->currentOperation()); if (!isSketchOp && !isSketchFeatureOperationActive()) return; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 80fd683fe..70db7acc3 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -18,6 +18,8 @@ #include #include +#include + #include #include #include @@ -106,7 +108,8 @@ void fillFeature2Attribute(const QList& theList, PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) - : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false) + : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false), + myIsMouseOverWindow(false), myIsPropertyPanelValueChanged(false) { ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); ModuleBase_IViewer* aViewer = anIWorkshop->viewer(); @@ -136,6 +139,22 @@ PartSet_SketcherMgr::~PartSet_SketcherMgr() myPlaneFilter.Nullify(); } +void PartSet_SketcherMgr::onMouseMoveOverWindow(bool theOverWindow) +{ + myIsMouseOverWindow = theOverWindow; + if (theOverWindow) + myIsPropertyPanelValueChanged = false; + + updateVisibilityOfCreatedFeature(); +} + +void PartSet_SketcherMgr::onValuesChangedInPropertyPanel() +{ + myIsPropertyPanelValueChanged = true; + + updateVisibilityOfCreatedFeature(); +} + void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { get2dPoint(theWnd, theEvent, myClickedPoint); @@ -166,8 +185,8 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE if (!PartSet_Tools::sketchPlane(myCurrentSketch)) return; - bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()); - bool isSketchOpe = sketchOperationIdList().contains(aOperation->id()); + bool isSketcher = isSketchOperation(aOperation); + bool isSketchOpe = isNestedSketchOperation(aOperation); // Avoid non-sketch operations if ((!isSketchOpe) && (!isSketcher)) @@ -234,8 +253,8 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse return; ModuleBase_Operation* aOp = aWorkshop->currentOperation(); if (aOp) { - if (sketchOperationIdList().contains(aOp->id())) { - get2dPoint(theWnd, theEvent, myClickedPoint); + if (isNestedSketchOperation(aOp)) { + get2dPoint(theWnd, theEvent, myClickedPoint); // Only for sketcher operations if (myIsDragging) { @@ -277,7 +296,7 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation(); if (!aOperation) return; - if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()) + if (isSketchOperation(aOperation)) return; // No edit operation activated Handle(V3d_View) aView = theWnd->v3dView(); @@ -387,6 +406,9 @@ void PartSet_SketcherMgr::onApplicationStarted() connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)), this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*))); } + + AppElements_MainWindow* aMainWindow = aWorkshop->mainWindow(); + connect(aMainWindow, SIGNAL(mouseMoveOverWindow(bool)), this, SLOT(onMouseMoveOverWindow(bool))); } void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget) @@ -407,15 +429,6 @@ void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWid } } -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, Point& thePoint) { @@ -471,6 +484,26 @@ QStringList PartSet_SketcherMgr::sketchOperationIdList() return aIds; } +bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation) +{ + return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID(); +} + +bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) +{ + return theOperation && + PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id()); +} + +bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) +{ + std::string aId = theOperation ? theOperation->id().toStdString() : ""; + + return (aId == SketchPlugin_ConstraintLength::ID()) || + (aId == SketchPlugin_ConstraintDistance::ID()) || + (aId == SketchPlugin_ConstraintRadius::ID()); +} + void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) { // Display all sketcher sub-Objects @@ -553,6 +586,20 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) aDisplayer->updateViewer(); } +void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* ) +{ + connectToPropertyPanel(true); +} + +void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* ) +{ + connectToPropertyPanel(false); +} + +bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const +{ + return myIsMouseOverWindow || myIsPropertyPanelValueChanged; +} void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr& thePln) { @@ -679,3 +726,43 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, } } } + +void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect) +{ + ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(anIWorkshop); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel(); + if (aPropertyPanel) { + const QList& aWidgets = aPropertyPanel->modelWidgets(); + foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { + if (isToConnect) + connect(aWidget, SIGNAL(controlValuesChanged()), this, SLOT(onValuesChangedInPropertyPanel())); + else + disconnect(aWidget, SIGNAL(controlValuesChanged()), this, SLOT(onValuesChangedInPropertyPanel())); + } + } +} + +void PartSet_SketcherMgr::updateVisibilityOfCreatedFeature() +{ + ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); + ModuleBase_Operation* aOperation = aWorkshop->currentOperation(); + if (!aOperation || aOperation->isEditOperation()) + return; + XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + FeaturePtr aFeature = aOperation->feature(); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + if (canDisplayObject(aFeature)) { + aDisplayer->display(*aIt, false); + } + else { + aDisplayer->erase(*aIt, false); + } + } + aDisplayer->updateViewer(); +} \ No newline at end of file diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 1507f92e9..a08cf3941 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -77,8 +77,20 @@ public: virtual ~PartSet_SketcherMgr(); - /// Returns list of strings which contains id's of sketch operations - static QStringList sketchOperationIdList(); + /// Returns true if the operation is the sketch + /// \param theOperation an operation + /// \return the boolean result + static bool isSketchOperation(ModuleBase_Operation* theOperation); + + /// Returns true if the operation id is in the sketch operation id list + /// \param theOperation an operation + /// \return the boolean result + static bool isNestedSketchOperation(ModuleBase_Operation* theOperation); + + /// Returns whethe the current operation is a sketch distance - lenght, distance or radius + /// \param the operation + /// \return a boolean value + static bool isDistanceOperation(ModuleBase_Operation* theOperation); /// Launches the operation from current highlighting void launchEditing(); @@ -92,12 +104,28 @@ public: /// Stops sketch operation void stopSketch(ModuleBase_Operation* ); + /// Starts sketch operation + void startNestedSketch(ModuleBase_Operation* ); + + /// Stops sketch operation + void stopNestedSketch(ModuleBase_Operation* ); + + /// Returns whether the object can be displayed at the bounds of the active operation. + /// Display only current operation results for usual operation and ask the sketcher manager + /// if it is a sketch operation + /// \param theObject a model object + bool canDisplayObject(const ObjectPtr& theObject) const; + public slots: /// Process sketch plane selected event void onPlaneSelected(const std::shared_ptr& thePln); private slots: + /// Process the signal about mouse moving into or out of the window + /// \param heOverWindow true, if the moving happens to window + void onMouseMoveOverWindow(bool theOverWindow); + void onValuesChangedInPropertyPanel(); void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*); void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*); void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*); @@ -106,10 +134,8 @@ private slots: 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; + /// Returns list of strings which contains id's of sketch operations + static QStringList sketchOperationIdList(); /// Converts mouse position to 2d coordinates. /// Member myCurrentSketch has to be correctly defined @@ -163,12 +189,20 @@ private: const FeatureToSelectionMap& theSelection, SelectMgr_IndexedMapOfOwner& anOwnersToSelect); + /// Connects or disconnects to the value changed signal of the property panel widgets + /// \param isToConnect a boolean value whether connect or disconnect + void connectToPropertyPanel(const bool isToConnect); + + void updateVisibilityOfCreatedFeature(); + private: PartSet_Module* myModule; bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer bool myIsDragging; bool myDragDone; + bool myIsMouseOverWindow; /// the state that mouse is over view + bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed Point myCurrentPoint; Point myClickedPoint; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 4bab36441..e32410baf 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -425,14 +425,6 @@ std::shared_ptr PartSet_Tools::point3D(std::shared_ptrto3D(aC->pnt(), aX->dir(), aY->dir()); } -bool PartSet_Tools::isConstraintFeature(const std::string& theKind) -{ - return theKind == SketchPlugin_ConstraintDistance::ID() - || theKind == SketchPlugin_ConstraintLength::ID() - || theKind == SketchPlugin_ConstraintRadius::ID() - || theKind == SketchPlugin_ConstraintRigid::ID(); -} - ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, const ObjectPtr& theObject, CompositeFeaturePtr theSketch) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 4ff7da471..854dd3b0e 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -144,10 +144,6 @@ class PARTSET_EXPORT PartSet_Tools /// \return API object of point 3D static std::shared_ptr point3D(std::shared_ptr thePoint2D, CompositeFeaturePtr theSketch); - /// Check whether there is a constraint with the feature kind given - /// \param theKind a feature kind - /// \return the boolean value - static bool isConstraintFeature(const std::string& theKind); /// Creates a line (arc or circle) by given edge /// Created line will have fixed constraint diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index d61d8d748..34560cdc4 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -75,6 +75,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, aGroupLay->addWidget(myXSpin, 0, 1); connect(myXSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); + connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(controlValuesChanged())); } { QLabel* aLabel = new QLabel(myGroupBox); @@ -89,6 +90,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, aGroupLay->addWidget(myYSpin, 1, 1); connect(myYSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); + connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(controlValuesChanged())); } } diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index be1081034..b32ba1443 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -34,6 +34,7 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, // Reconnect to local slot disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); + connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(controlValuesChanged())); } PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()