From 19bc85698899d6bee8704e7b0953ee045b0eb66f Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 3 Oct 2014 16:03:41 +0400 Subject: [PATCH] Make property panel as a GUI of an operation --- src/ModuleBase/CMakeLists.txt | 1 + src/ModuleBase/ModuleBase_IModule.h | 2 +- src/ModuleBase/ModuleBase_IPropertyPanel.h | 44 +++++++++ src/ModuleBase/ModuleBase_Operation.cpp | 89 ++++++++++++++++--- src/ModuleBase/ModuleBase_Operation.h | 41 ++++++--- .../ModuleBase_WidgetShapeSelector.cpp | 56 ++++++++---- .../ModuleBase_WidgetShapeSelector.h | 10 ++- src/PartSet/PartSet_Module.cpp | 26 ++++-- src/PartSet/PartSet_OperationFeatureBase.cpp | 61 +++---------- src/PartSet/PartSet_OperationFeatureBase.h | 23 +---- .../PartSet_OperationFeatureCreate.cpp | 30 ++++--- src/PartSet/PartSet_OperationFeatureCreate.h | 13 ++- src/PartSet/PartSet_OperationFeatureEdit.cpp | 14 +-- src/PartSet/PartSet_OperationFeatureEdit.h | 3 - .../PartSet_OperationFeatureEditMulti.cpp | 11 +-- .../PartSet_OperationFeatureEditMulti.h | 3 - src/PartSet/PartSet_OperationSketch.cpp | 7 -- src/PartSet/PartSet_OperationSketch.h | 3 - src/PartSet/PartSet_OperationSketchBase.cpp | 4 +- src/PartSet/PartSet_OperationSketchBase.h | 5 -- src/XGUI/XGUI_OperationMgr.cpp | 8 -- src/XGUI/XGUI_OperationMgr.h | 7 -- src/XGUI/XGUI_PropertyPanel.cpp | 17 +++- src/XGUI/XGUI_PropertyPanel.h | 25 +++--- src/XGUI/XGUI_Workshop.cpp | 11 +-- 25 files changed, 304 insertions(+), 210 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_IPropertyPanel.h diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 92a73fce8..ba568428e 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -27,6 +27,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetChoice.h ModuleBase_WidgetFileSelector.h ModuleBase_DoubleSpinBox.h + ModuleBase_IPropertyPanel.h ) SET(PROJECT_SOURCES diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 640484927..df599f416 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -49,4 +49,4 @@ typedef ModuleBase_IModule* (*CREATE_FUNC)(XGUI_Workshop*); #define CREATE_MODULE "createModule" -#endif //ModuleBase_IModule \ No newline at end of file +#endif //ModuleBase_IModule diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h new file mode 100644 index 000000000..b43a3d42c --- /dev/null +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -0,0 +1,44 @@ +/* + * ModuleBase_IPropertyPanel.h + * + * Created on: Oct 01, 2014 + * Author: vsv + */ + +#ifndef ModuleBase_PROPERTYPANEL_H_ +#define ModuleBase_PROPERTYPANEL_H_ + +#include "ModuleBase.h" + +#include +#include + +class ModuleBase_ModelWidget; + +class MODULEBASE_EXPORT ModuleBase_IPropertyPanel : public QDockWidget +{ +Q_OBJECT +public: + ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent) {} + + /// Returns currently active widget + virtual ModuleBase_ModelWidget* activeWidget() const = 0; + +signals: + /// The signal about key release on the control, that corresponds to the attribute + /// \param theEvent key release event + void keyReleased(QKeyEvent* theEvent); + /// The signal about the widget activation + /// \param theWidget the activated widget + void widgetActivated(ModuleBase_ModelWidget* theWidget); + +public slots: + /// Activate the next widget in the property panel + /// \param theWidget a widget. The next widget should be activated + virtual void activateNextWidget(ModuleBase_ModelWidget* theWidget) = 0; + + /// Activate the next from current widget in the property panel + virtual void activateNextWidget() = 0; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index ec6c0e1e6..718ded61a 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -9,6 +9,9 @@ #include "ModuleBase_OperationDescription.h" #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_WidgetValueFeature.h" +#include "ModuleBase_ViewerPrs.h" +#include "ModuleBase_IPropertyPanel.h" #include #include @@ -19,6 +22,8 @@ #include #include +#include + #include #ifdef _DEBUG @@ -28,7 +33,8 @@ ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent) : QObject(theParent), myIsEditing(false), - myIsModified(false) + myIsModified(false), + myPropertyPanel(NULL) { myDescription = new ModuleBase_OperationDescription(theId); } @@ -78,16 +84,10 @@ void ModuleBase_Operation::storeCustomValue() aCustom->storeValue(); } -void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) -{ -} - void ModuleBase_Operation::startOperation() { if (!myIsEditing) createFeature(); - //emit callSlot(); - //commit(); } void ModuleBase_Operation::stopOperation() @@ -145,11 +145,6 @@ FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage) void ModuleBase_Operation::setFeature(FeaturePtr theFeature) { myFeature = theFeature; -} - -void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature) -{ - setFeature(theFeature); myIsEditing = true; } @@ -186,6 +181,9 @@ void ModuleBase_Operation::start() void ModuleBase_Operation::resume() { + if (myPropertyPanel) + connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, + SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); emit resumed(); } @@ -193,6 +191,8 @@ void ModuleBase_Operation::abort() { abortOperation(); emit aborted(); + if (myPropertyPanel) + disconnect(myPropertyPanel, 0, this, 0); stopOperation(); @@ -206,6 +206,9 @@ bool ModuleBase_Operation::commit() commitOperation(); emit committed(); + if (myPropertyPanel) + disconnect(myPropertyPanel, 0, this, 0); + stopOperation(); ModelAPI_Session::get()->finishOperation(); @@ -223,3 +226,65 @@ void ModuleBase_Operation::setRunning(bool theState) abort(); } } + +void ModuleBase_Operation::activateByPreselection() +{ + if (!myPropertyPanel) + return; + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + if ((myPreSelection.size() > 0) && aActiveWgt) { + const ModuleBase_ViewerPrs& aPrs = myPreSelection.front(); + ModuleBase_WidgetValueFeature aValue; + aValue.setObject(aPrs.object()); + if (aActiveWgt->setValue(&aValue)) { + myPreSelection.remove(aPrs); + if(isValid()) { + //myActiveWidget = NULL; + commit(); + } else { + myPropertyPanel->activateNextWidget(); + //emit activateNextWidget(myActiveWidget); + } + } + // If preselection is enough to make a valid feature - apply it immediately + } +} + +void ModuleBase_Operation::initSelection( + const std::list& theSelected, + const std::list& /*theHighlighted*/) +{ + myPreSelection = theSelected; +} + +void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) +{ + activateByPreselection(); + //if (theWidget && myPropertyPanel) { + // myPropertyPanel->activateNextWidget(); + //// //emit activateNextWidget(myActiveWidget); + //} +} + +bool ModuleBase_Operation::setWidgetValue(ObjectPtr theFeature, double theX, double theY) +{ + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + if (!aActiveWgt) + return false; + ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature(); + aValue->setObject(theFeature); + aValue->setPoint(boost::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); + bool isApplyed = aActiveWgt->setValue(aValue); + + delete aValue; + myIsModified = (myIsModified || isApplyed); + return isApplyed; +} + + +void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) +{ + myPropertyPanel = theProp; + connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, + SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); +} diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index b73ba4726..910bd6eae 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -9,18 +9,18 @@ #define ModuleBase_Operation_H #include +#include #include +#include #include #include #include -#include - -class ModelAPI_Document; class ModuleBase_ModelWidget; class ModuleBase_OperationDescription; +class ModuleBase_IPropertyPanel; class QKeyEvent; @@ -102,19 +102,27 @@ Q_OBJECT virtual bool isNestedOperationsEnabled() const; /// Sets the operation feature - void setEditingFeature(FeaturePtr theFeature); + void setFeature(FeaturePtr theFeature); /// Returns True if the current operation works with the given object (feature or result) virtual bool hasObject(ObjectPtr theObj) const; virtual void keyReleased(const int theKey) {}; - virtual void activateNextToCurrentWidget() {}; - /// If operation needs to redisplay its result during operation /// then this method has to return True virtual bool hasPreview() const { return false; } + /// Initialisation of operation with preliminary selection + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void initSelection(const std::list& theSelected, + const std::list& theHighlighted); + + virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp); + + ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; } + signals: void started(); /// the operation is started void aborted(); /// the operation is aborted @@ -122,10 +130,6 @@ signals: void stopped(); /// the operation is aborted or committed void resumed(); /// the operation is resumed - /// Signals about the activating of the next widget - /// \param theWidget the previous active widget - void activateNextWidget(ModuleBase_ModelWidget* theWidget); - public slots: /// Starts operation /// Public slot. Verifies whether operation can be started and starts operation. @@ -191,9 +195,6 @@ signals: /// \returns the created feature virtual FeaturePtr createFeature(const bool theFlushMessage = true); - /// Sets the operation feature - void setFeature(FeaturePtr theFeature); - /// Verifies whether this operator can be commited. /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled virtual bool canBeCommitted() const; @@ -201,6 +202,15 @@ signals: /// Returns pointer to the root document. boost::shared_ptr document() const; + /// + virtual void activateByPreselection(); + + /// Set value to the active widget + /// \param theFeature the feature + /// \param theX the horizontal coordinate + /// \param theY the vertical coordinate + /// \return true if the point is set + virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY); protected: FeaturePtr myFeature; /// the operation feature to be handled @@ -217,6 +227,11 @@ signals: /// List of nested operations IDs QStringList myNestedFeatures; + /// List of pre-selected object + std::list myPreSelection; + + /// Access to property panel + ModuleBase_IPropertyPanel* myPropertyPanel; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index fcd287c55..36c1efd1a 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -4,6 +4,8 @@ #include "ModuleBase_WidgetShapeSelector.h" #include "ModuleBase_IWorkshop.h" +#include "ModuleBase_WidgetValue.h" +#include "ModuleBase_WidgetValueFeature.h" #include #include @@ -72,6 +74,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen myTextLine = new QLineEdit(myContainer); myTextLine->setReadOnly(true); myTextLine->setToolTip(aToolTip); + myTextLine->installEventFilter(this); myBasePalet = myTextLine->palette(); myInactivePalet = myBasePalet; @@ -146,22 +149,28 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() if (!isAccepted(aObject)) return; - mySelectedObject = aObject; - if (mySelectedObject) { - updateSelectionName(); - raisePanel(); - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE); - ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent); - Events_Loop::loop()->flush(anEvent); - } else { - myTextLine->setText(""); - } - activateSelection(false); - emit valuesChanged(); - emit focusOutWidget(this); + setObject(aObject); } } +//******************************************************************** +void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj) +{ + if (mySelectedObject == theObj) + return; + mySelectedObject = theObj; + if (mySelectedObject) { + raisePanel(); + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE); + ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent); + Events_Loop::loop()->flush(anEvent); + } + updateSelectionName(); + activateSelection(false); + emit valuesChanged(); + emit focusOutWidget(this); +} + //******************************************************************** bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const { @@ -235,9 +244,6 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate) connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); else disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - -// if (myWorkshop->selectedObjects().size() > 0) -// onSelectionChanged(); } //******************************************************************** @@ -273,3 +279,21 @@ bool ModuleBase_WidgetShapeSelector::eventFilter(QObject* theObj, QEvent* theEve } return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); } + +//******************************************************************** +bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue) +{ + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue && aFeatureValue->object()) { + ObjectPtr aObject = aFeatureValue->object(); + if (isAccepted(aObject)) { + setObject(aObject); + return true; + } + } + } + return false; +} + diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 5defe3a2e..c1decfa56 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -55,7 +55,12 @@ Q_OBJECT return mySelectedObject; } - public slots: + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValue the wrapped widget value + virtual bool setValue(ModuleBase_WidgetValue* theValue); + +public slots: /// Activate or deactivate selection void activateSelection(bool toActivate); @@ -71,6 +76,9 @@ private: void raisePanel() const; bool isAccepted(const ObjectPtr theObject) const; + // Set the given object as a value of the widget + void setObject(ObjectPtr theObj); + static TopAbs_ShapeEnum shapeType(const QString& theType); QWidget* myContainer; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index b2387c238..bc23a468b 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -152,25 +152,27 @@ void PartSet_Module::onFeatureTriggered() void PartSet_Module::launchOperation(const QString& theCmdId) { ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString()); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { + //PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + //if (aPreviewOp) { XGUI_Selection* aSelection = myWorkshop->selector()->selection(); // Initialise operation with preliminary selection std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); - aPreviewOp->initSelection(aSelected, aHighlighted); - } + anOperation->initSelection(aSelected, aHighlighted); + //} sendOperation(anOperation); } void PartSet_Module::onOperationStarted() { - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(myWorkshop - ->operationMgr()->currentOperation()); + ModuleBase_Operation* aOperation = myWorkshop->operationMgr()->currentOperation(); + + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(aOperation); if (aPreviewOp) { XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel(); connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this, SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); aDisplayer->openLocalContext(); aDisplayer->deactivateObjectsOutOfContext(); @@ -210,6 +212,7 @@ void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked) void PartSet_Module::onMousePressed(QMouseEvent* theEvent) { + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(myWorkshop ->operationMgr()->currentOperation()); Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); @@ -296,10 +299,17 @@ void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject // Initialise operation with preliminary selection std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); - aSketchOp->initFeature(aFeature); aSketchOp->initSelection(aSelected, aHighlighted); + PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast(anOperation); + if (aCreateOp) + aCreateOp->initFeature(aFeature); + else { + PartSet_OperationFeatureEdit* aEditOp = dynamic_cast(anOperation); + if (aEditOp) + anOperation->setFeature(aFeature); + } } else if (aFeature) { - anOperation->setEditingFeature(aFeature); + anOperation->setFeature(aFeature); //Deactivate result of current feature in order to avoid its selection XGUI_Displayer* aDisplayer = myWorkshop->displayer(); std::list aResults = aFeature->results(); diff --git a/src/PartSet/PartSet_OperationFeatureBase.cpp b/src/PartSet/PartSet_OperationFeatureBase.cpp index c1da278fa..a3eacd024 100644 --- a/src/PartSet/PartSet_OperationFeatureBase.cpp +++ b/src/PartSet/PartSet_OperationFeatureBase.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include "ModuleBase_IPropertyPanel.h" #include @@ -46,8 +46,7 @@ PartSet_OperationFeatureBase::PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, FeaturePtr theFeature) : PartSet_OperationSketchBase(theId, theParent), - mySketch(theFeature), - myActiveWidget(NULL) + mySketch(theFeature) { } @@ -55,18 +54,6 @@ PartSet_OperationFeatureBase::~PartSet_OperationFeatureBase() { } -void PartSet_OperationFeatureBase::initSelection( - const std::list& theSelected, - const std::list& /*theHighlighted*/) -{ - myPreSelection = theSelected; -} - -void PartSet_OperationFeatureBase::initFeature(FeaturePtr theFeature) -{ - myInitFeature = theFeature; -} - FeaturePtr PartSet_OperationFeatureBase::sketch() const { return mySketch; @@ -90,7 +77,8 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V if (!aVertex.IsNull()) { aPoint = BRep_Tool::Pnt(aVertex); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY); + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); } } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); @@ -108,53 +96,24 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V bool isApplyed = setWidgetValue(aFeature, aX, anY); if (isApplyed) { flushUpdated(); - emit activateNextWidget(myActiveWidget); + myPropertyPanel->activateNextWidget(); } commit(); } -void PartSet_OperationFeatureBase::onWidgetActivated(ModuleBase_ModelWidget* theWidget) -{ - myActiveWidget = theWidget; - activateByPreselection(); - if (myInitFeature && myActiveWidget) { - ModuleBase_WidgetPoint2D* aWgt = dynamic_cast(myActiveWidget); - if (aWgt && aWgt->initFromPrevious(myInitFeature)) { - myInitFeature = FeaturePtr(); - emit activateNextWidget(myActiveWidget); - } - } -} -void PartSet_OperationFeatureBase::activateByPreselection() -{ - if ((myPreSelection.size() > 0) && myActiveWidget) { - const ModuleBase_ViewerPrs& aPrs = myPreSelection.front(); - ModuleBase_WidgetValueFeature aValue; - aValue.setObject(aPrs.object()); - if (myActiveWidget->setValue(&aValue)) { - myPreSelection.remove(aPrs); - if(isValid()) { - myActiveWidget = NULL; - commit(); - } else { - emit activateNextWidget(myActiveWidget); - } - } - // If preselection is enough to make a valid feature - apply it immediately - } -} -bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY) +/*bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY) { - if (!myActiveWidget) + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + if (!aActiveWgt) return false; ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature(); aValue->setObject(theFeature); aValue->setPoint(boost::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); - bool isApplyed = myActiveWidget->setValue(aValue); + bool isApplyed = aActiveWgt->setValue(aValue); delete aValue; myIsModified = (myIsModified || isApplyed); return isApplyed; -} +}*/ diff --git a/src/PartSet/PartSet_OperationFeatureBase.h b/src/PartSet/PartSet_OperationFeatureBase.h index 5a0c66bf0..baef75f9f 100644 --- a/src/PartSet/PartSet_OperationFeatureBase.h +++ b/src/PartSet/PartSet_OperationFeatureBase.h @@ -33,15 +33,6 @@ Q_OBJECT /// Destructor virtual ~PartSet_OperationFeatureBase(); - /// Initialisation of operation with preliminary selection - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void initSelection(const std::list& theSelected, - const std::list& theHighlighted); - - /// Initializes the operation with previously created feature. It is used in sequental operations - virtual void initFeature(FeaturePtr theFeature); - /// Returns the operation sketch feature /// \returns the sketch instance virtual FeaturePtr sketch() const; @@ -56,28 +47,16 @@ Q_OBJECT const std::list& theHighlighted); - public slots: - /// Slots which listen the mode widget activation - /// \param theWidget the model widget - virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget); - protected: - /// - void activateByPreselection(); /// Set value to the active widget /// \param theFeature the feature /// \param theX the horizontal coordinate /// \param theY the vertical coordinate /// \return true if the point is set - bool setWidgetValue(ObjectPtr theFeature, double theX, double theY); + //bool setWidgetValue(ObjectPtr theFeature, double theX, double theY); protected: - FeaturePtr myInitFeature; ///< the initial feature FeaturePtr mySketch; ///< the sketch of the feature - - ModuleBase_ModelWidget* myActiveWidget; ///< the active widget - - std::list myPreSelection; }; #endif diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index b9c2326ee..2be41c483 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -125,7 +126,8 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle if (!aVertex.IsNull()) { aPoint = BRep_Tool::Pnt(aVertex); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY); + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); isClosedContour = true; } } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected @@ -144,10 +146,10 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle bool isApplyed = setWidgetValue(aFeature, aX, anY); if (isApplyed) { flushUpdated(); - emit activateNextWidget(myActiveWidget); + myPropertyPanel->activateNextWidget(); } - if (myActiveWidget == NULL) { + if (!myPropertyPanel->activeWidget()) { if(commit() && !isClosedContour) { // if the point creation is finished, the next mouse release should commit the modification // the next release can happens by double click in the viewer @@ -156,11 +158,6 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle } } -void PartSet_OperationFeatureCreate::activateNextToCurrentWidget() -{ - emit activateNextWidget(myActiveWidget); -} - void PartSet_OperationFeatureCreate::startOperation() { PartSet_OperationSketchBase::startOperation(); @@ -194,11 +191,22 @@ FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMess aFeature->addSub(aNewFeature); } - //myFeaturePrs->init(aNewFeature); - //myFeaturePrs->setFeature(myInitFeature, SM_FirstPoint); -//TODO emit featureConstructed(aNewFeature, FM_Activation); if (theFlushMessage) flushCreated(); return aNewFeature; } + + +void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget) +{ + PartSet_OperationFeatureBase::onWidgetActivated(theWidget); + if (myInitFeature && theWidget) { + ModuleBase_WidgetPoint2D* aWgt = dynamic_cast(theWidget); + if (aWgt && aWgt->initFromPrevious(myInitFeature)) { + myInitFeature = FeaturePtr(); + if (myPropertyPanel) + myPropertyPanel->activateNextWidget(); + } + } +} diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index f254b713a..fcd92be95 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -60,8 +60,13 @@ Q_OBJECT /// \param theKey a key value virtual void keyReleased(const int theKey); - /// alias for activateNextWidget(myActiveWidget); - virtual void activateNextToCurrentWidget(); + /// Initializes the operation with previously created feature. It is used in sequental operations + void initFeature(FeaturePtr theFeature) { myInitFeature = theFeature; } + + public slots: + /// Slots which listen the mode widget activation + /// \param theWidget the model widget + virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget); protected: /// \brief Virtual method called when operation is started @@ -90,6 +95,10 @@ Q_OBJECT /// Verifies whether this operator can be commited. /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled virtual bool canBeCommitted() const; + +protected: + /// Feature of previous operation (for sequintal operations) + FeaturePtr myInitFeature; }; #endif diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index 2036d5576..1e0932280 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -43,22 +44,20 @@ PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId, : PartSet_OperationFeatureBase(theId, theParent, theFeature), myIsBlockedSelection(false) { + myIsEditing = true; } PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit() { } -void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature) -{ - setEditingFeature(theFeature); -} void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView, const std::list& theSelected, const std::list& theHighlighted) { - if(myActiveWidget && myActiveWidget->isViewerSelector()) { + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + if(aActiveWgt && aActiveWgt->isViewerSelector()) { // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased PartSet_OperationFeatureBase::mousePressed(theEvent, theView, theSelected, theHighlighted); return; @@ -128,7 +127,10 @@ void PartSet_OperationFeatureEdit::mouseReleased( const std::list& theSelected, const std::list& theHighlighted) { - if(myActiveWidget && myActiveWidget->isViewerSelector()) { + ModuleBase_ModelWidget* aActiveWgt = 0; + if (myPropertyPanel) + aActiveWgt = myPropertyPanel->activeWidget(); + if(aActiveWgt && aActiveWgt->isViewerSelector()) { // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased PartSet_OperationFeatureBase::mouseReleased(theEvent, theView, theSelected, theHighlighted); } else { diff --git a/src/PartSet/PartSet_OperationFeatureEdit.h b/src/PartSet/PartSet_OperationFeatureEdit.h index 2082258b0..67223fce6 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.h +++ b/src/PartSet/PartSet_OperationFeatureEdit.h @@ -70,9 +70,6 @@ Q_OBJECT /// Destructor virtual ~PartSet_OperationFeatureEdit(); - /// Initializes the operation with previously created feature. It is used in sequental operations - virtual void initFeature(FeaturePtr theFeature); - /// Processes the mouse pressed in the point /// \param theEvent the mouse event /// \param theView a viewer to have the viewer the eye position diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp index cd0de8925..ceef096f9 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp @@ -39,6 +39,7 @@ PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QStri mySketch(theFeature), myIsBlockedSelection(false) { + myIsEditing = true; } PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti() @@ -69,11 +70,6 @@ void PartSet_OperationFeatureEditMulti::initSelection( myFeatures = theSelected; } -void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature) -{ - setEditingFeature(theFeature); -} - FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const { return mySketch; @@ -93,7 +89,7 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); - blockSelection(true); +/* blockSelection(true); if (myCurPoint.myIsInitialized) { double aCurX, aCurY; PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY); @@ -105,7 +101,7 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle double aDeltaY = anY - aCurY; boost::shared_ptr aSketchFeature = boost::dynamic_pointer_cast< - SketchPlugin_Feature>(feature()); + SketchPlugin_Feature>(sketch()); aSketchFeature->move(aDeltaX, aDeltaY); std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures @@ -125,6 +121,7 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle sendFeatures(); myCurPoint.setPoint(aPoint); + */ } void PartSet_OperationFeatureEditMulti::mouseReleased( diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.h b/src/PartSet/PartSet_OperationFeatureEditMulti.h index 0f21f34ab..b34b638ad 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.h +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.h @@ -70,9 +70,6 @@ Q_OBJECT /// Destructor virtual ~PartSet_OperationFeatureEditMulti(); - /// Initializes the operation with previously created feature. It is used in sequental operations - virtual void initFeature(FeaturePtr theFeature); - /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 2a320bc69..fdb56312b 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -59,13 +59,6 @@ std::list PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) return aModes; } -/// Initializes the operation with previously created feature. It is used in sequental operations -void PartSet_OperationSketch::initFeature(FeaturePtr theFeature) -{ - if (theFeature) - setEditingFeature(theFeature); -} - FeaturePtr PartSet_OperationSketch::sketch() const { return feature(); diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 3e99e86fa..94ddf02d9 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -46,9 +46,6 @@ Q_OBJECT /// \return the selection mode virtual std::list getSelectionModes(ObjectPtr theFeature) const; - /// Initializes the operation with previously created feature. It is used in sequental operations - virtual void initFeature(FeaturePtr theFeature); - /// Returns the operation sketch feature /// \returns the sketch instance virtual FeaturePtr sketch() const; diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 9dd3141eb..e8f081e4d 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -98,9 +98,7 @@ void PartSet_OperationSketchBase::restartOperation(const std::string& theType, O if (aFeature) { QStringList aNested = this->nestedFeatures(); if (!aNested.isEmpty()) { - if (aNested.contains(QString(aFeature->getKind().c_str()))) - emit restartRequired(theType, theFeature); - else + if (!aNested.contains(QString(aFeature->getKind().c_str()))) return; } } diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 9b43039ea..c92be1da3 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -65,11 +65,6 @@ Q_OBJECT /// \return the selection mode virtual std::list getSelectionModes(ObjectPtr theFeature) const; - /// Initializes the operation with previously created feature. It is used in sequental operations - virtual void initFeature(FeaturePtr theFeature) - { - } - /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 88d5f89de..6f014ad8a 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -85,8 +85,6 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation) connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped())); connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted())); connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed())); - connect(theOperation, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), this, - SIGNAL(activateNextWidget(ModuleBase_ModelWidget*))); theOperation->start(); onValidateOperation(); @@ -241,9 +239,3 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent) return isAccepted; } -void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget) -{ - ModuleBase_Operation* anOperation = currentOperation(); - if (anOperation) - anOperation->onWidgetActivated(theWidget); -} diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index ee8ff1f93..95d5affb1 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -78,9 +78,6 @@ signals: void operationResumed(); /// Signal is emitted after the validate methods calls. void operationValidated(bool); - /// Signal about the necessety of the next widget activating - /// \param theWidget the model widget - void activateNextWidget(ModuleBase_ModelWidget* theWidget); protected: @@ -108,10 +105,6 @@ signals: /// \param theEvent the mouse event bool onKeyReleased(QKeyEvent* theEvent); - /// SLOT, that reacts to the widget activation - /// \param theWidget an activated widget - void onWidgetActivated(ModuleBase_ModelWidget* theWidget); - protected slots: /// Slot that is called by an operation stop. Removes the stopped operation form the stack. /// If there is a suspended operation, restart it. diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 14ae5b6d9..93a35bdc9 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -23,7 +23,7 @@ #endif XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) - : QDockWidget(theParent) + : ModuleBase_IPropertyPanel(theParent), myActiveWidget(0) { this->setWindowTitle(tr("Property Panel")); QAction* aViewAct = this->toggleViewAction(); @@ -76,6 +76,7 @@ void XGUI_PropertyPanel::cleanContent() void XGUI_PropertyPanel::setModelWidgets(const QList& theWidgets) { myWidgets = theWidgets; + int aS = myWidgets.size(); if (theWidgets.empty()) return; QList::const_iterator anIt = theWidgets.begin(), aLast = @@ -84,7 +85,7 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& t connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*))); connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this, - SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); + SLOT(activateNextWidget(ModuleBase_ModelWidget*))); connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)), this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*))); @@ -120,6 +121,7 @@ QWidget* XGUI_PropertyPanel::contentWidget() void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) { + int aS = myWidgets.size(); foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) { eachWidget->setFeature(theFeature); @@ -129,7 +131,8 @@ void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) repaint(); } -void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget) + +void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) { QObject* aSender = sender(); ModuleBase_ModelWidget* aNextWidget = 0; @@ -143,7 +146,13 @@ void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget) } isFoundWidget = (*anIt) == theWidget; } - emit widgetActivated(aNextWidget); + myActiveWidget = aNextWidget; + emit widgetActivated(myActiveWidget); +} + +void XGUI_PropertyPanel::activateNextWidget() +{ + activateNextWidget(myActiveWidget); } void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled) diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index a660b5484..b29d51579 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -11,14 +11,14 @@ #include "XGUI.h" #include +#include -#include #include class QKeyEvent; class QVBoxLayout; -class XGUI_EXPORT XGUI_PropertyPanel : public QDockWidget +class XGUI_EXPORT XGUI_PropertyPanel : public ModuleBase_IPropertyPanel { Q_OBJECT public: @@ -36,22 +36,22 @@ Q_OBJECT /// Removes all widgets in the widget area of the property panel void cleanContent(); + /// Returns currently active widget + virtual ModuleBase_ModelWidget* activeWidget() const { return myActiveWidget; } + + /// Activate the next widget in the property panel + /// \param theWidget a widget. The next widget should be activated + virtual void activateNextWidget(ModuleBase_ModelWidget* theWidget); + + /// Activate the next from current widget in the property panel + virtual void activateNextWidget(); + public slots: void updateContentWidget(FeaturePtr theFeature); - /// slot to activate the next widget in the property panel - /// \param theWidget a widget. The next widget should be activated - void onActivateNextWidget(ModuleBase_ModelWidget* theWidget); // Enables / disables "ok" ("accept") button void setAcceptEnabled(bool); signals: - /// The signal about key release on the control, that corresponds to the attribute - /// \param theEvent key release event - void keyReleased(QKeyEvent* theEvent); - /// The signal about the widget activation - /// \param theWidget the activated widget - void widgetActivated(ModuleBase_ModelWidget* theWidget); - /// Signal about the point 2d set to the feature /// \param the feature /// \param the attribute of the feature @@ -61,6 +61,7 @@ signals: QWidget* myCustomWidget; QList myWidgets; QVBoxLayout* myMainLayout; + ModuleBase_ModelWidget* myActiveWidget; }; #endif /* XGUI_PROPERTYPANEL_H_ */ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8c76c2fd1..9ee12eea2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -513,8 +513,9 @@ void XGUI_Workshop::onOperationStarted() } } + aOperation->setPropertyPanel(myPropertyPanel); myPropertyPanel->setModelWidgets(aWidgets); - myPropertyPanel->onActivateNextWidget(NULL); + myPropertyPanel->activateNextWidget(NULL); // Widget activation (from the previous method) may commit the current operation // if pre-selection is enougth for it. So we shouldn't update prop panel's title if(myOperationMgr->isCurrentOperation(aOperation)) { @@ -1001,10 +1002,10 @@ void XGUI_Workshop::createDockWidgets() connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation())); connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr, SLOT(onKeyReleased(QKeyEvent*))); - connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr, - SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); - connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel, - SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); + //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr, + // SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + //connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel, + // SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel, SLOT(setAcceptEnabled(bool))); -- 2.39.2