From 976244bad37e04fcebaf8866d7d7a02efd2b7d35 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 26 Nov 2014 19:01:51 +0300 Subject: [PATCH] Redesign of operations architecture --- src/Config/Config_Keywords.h | 9 +- src/ModuleBase/CMakeLists.txt | 13 +- src/ModuleBase/ModuleBase_Definitions.h | 4 +- src/ModuleBase/ModuleBase_IModule.cpp | 109 +- src/ModuleBase/ModuleBase_IModule.h | 55 +- src/ModuleBase/ModuleBase_IPropertyPanel.h | 4 + src/ModuleBase/ModuleBase_ISelection.h | 6 +- src/ModuleBase/ModuleBase_IViewWindow.h | 20 + src/ModuleBase/ModuleBase_IViewer.h | 23 +- src/ModuleBase/ModuleBase_IWorkshop.h | 26 +- src/ModuleBase/ModuleBase_Operation.cpp | 154 +-- src/ModuleBase/ModuleBase_Operation.h | 50 +- src/ModuleBase/ModuleBase_Tools.cpp | 9 +- src/ModuleBase/ModuleBase_Tools.h | 7 +- src/ModuleBase/ModuleBase_WidgetEditor.cpp | 13 +- src/ModuleBase/ModuleBase_WidgetEditor.h | 4 + src/ModuleBase/ModuleBase_WidgetFactory.cpp | 69 +- src/ModuleBase/ModuleBase_WidgetFactory.h | 6 +- src/ModuleBase/ModuleBase_WidgetFeature.cpp | 160 --- src/ModuleBase/ModuleBase_WidgetFeature.h | 96 -- .../ModuleBase_WidgetFeatureOrAttribute.cpp | 179 --- .../ModuleBase_WidgetFeatureOrAttribute.h | 62 - .../ModuleBase_WidgetMultiSelector.cpp | 2 +- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 177 --- src/ModuleBase/ModuleBase_WidgetPoint2D.h | 77 -- .../ModuleBase_WidgetPoint2dDistance.cpp | 63 - .../ModuleBase_WidgetPoint2dDistance.h | 39 - .../ModuleBase_WidgetShapeSelector.cpp | 72 +- .../ModuleBase_WidgetShapeSelector.h | 4 - src/NewGeom/NewGeom_SalomeViewer.cpp | 120 +- src/NewGeom/NewGeom_SalomeViewer.h | 13 +- src/PartSet/CMakeLists.txt | 30 +- src/PartSet/PartSet_Listener.cpp | 107 -- src/PartSet/PartSet_Listener.h | 35 - src/PartSet/PartSet_Module.cpp | 1228 +++++++++++------ src/PartSet/PartSet_Module.h | 128 +- src/PartSet/PartSet_Operation.cpp | 17 + src/PartSet/PartSet_Operation.h | 30 + src/PartSet/PartSet_OperationFeatureBase.cpp | 126 -- src/PartSet/PartSet_OperationFeatureBase.h | 63 - .../PartSet_OperationFeatureCreate.cpp | 195 --- src/PartSet/PartSet_OperationFeatureCreate.h | 96 -- src/PartSet/PartSet_OperationFeatureEdit.cpp | 521 ------- src/PartSet/PartSet_OperationFeatureEdit.h | 156 --- src/PartSet/PartSet_OperationSketch.cpp | 292 ---- src/PartSet/PartSet_OperationSketch.h | 126 -- src/PartSet/PartSet_OperationSketchBase.cpp | 98 -- src/PartSet/PartSet_OperationSketchBase.h | 148 -- src/PartSet/PartSet_Tools.cpp | 22 +- src/PartSet/PartSet_Tools.h | 3 +- src/PartSet/PartSet_WidgetPoint2d.cpp | 268 ++++ src/PartSet/PartSet_WidgetPoint2d.h | 111 ++ src/PartSet/PartSet_WidgetPoint2dDistance.cpp | 114 ++ src/PartSet/PartSet_WidgetPoint2dDistance.h | 65 + src/PartSet/PartSet_WidgetSketchLabel.cpp | 251 +++- src/PartSet/PartSet_WidgetSketchLabel.h | 48 +- .../SketchPlugin_ConstraintDistance.cpp | 10 +- .../SketchPlugin_ConstraintLength.cpp | 19 +- .../SketchPlugin_ConstraintRadius.cpp | 30 +- src/SketchPlugin/SketchPlugin_Sketch.cpp | 78 +- src/SketchPlugin/SketchPlugin_Sketch.h | 4 +- src/SketchPlugin/plugin-Sketch.xml | 78 +- src/XGUI/XGUI_ContextMenuMgr.cpp | 4 +- src/XGUI/XGUI_Displayer.cpp | 43 +- src/XGUI/XGUI_Displayer.h | 7 +- src/XGUI/XGUI_ModuleConnector.cpp | 19 +- src/XGUI/XGUI_ModuleConnector.h | 5 +- src/XGUI/XGUI_ObjectsBrowser.cpp | 2 +- src/XGUI/XGUI_ObjectsBrowser.h | 10 +- src/XGUI/XGUI_OperationMgr.cpp | 60 +- src/XGUI/XGUI_OperationMgr.h | 44 +- src/XGUI/XGUI_PropertyPanel.cpp | 17 +- src/XGUI/XGUI_PropertyPanel.h | 2 +- src/XGUI/XGUI_Selection.cpp | 50 +- src/XGUI/XGUI_Selection.h | 6 +- src/XGUI/XGUI_SelectionMgr.cpp | 4 +- src/XGUI/XGUI_ViewWindow.cpp | 5 + src/XGUI/XGUI_ViewWindow.h | 11 +- src/XGUI/XGUI_ViewerProxy.cpp | 68 +- src/XGUI/XGUI_ViewerProxy.h | 8 +- src/XGUI/XGUI_Workshop.cpp | 55 +- src/XGUI/XGUI_Workshop.h | 9 +- 82 files changed, 2681 insertions(+), 3890 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_IViewWindow.h delete mode 100644 src/ModuleBase/ModuleBase_WidgetFeature.cpp delete mode 100644 src/ModuleBase/ModuleBase_WidgetFeature.h delete mode 100644 src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp delete mode 100644 src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h delete mode 100644 src/ModuleBase/ModuleBase_WidgetPoint2D.cpp delete mode 100644 src/ModuleBase/ModuleBase_WidgetPoint2D.h delete mode 100644 src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp delete mode 100644 src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h delete mode 100644 src/PartSet/PartSet_Listener.cpp delete mode 100644 src/PartSet/PartSet_Listener.h create mode 100644 src/PartSet/PartSet_Operation.cpp create mode 100644 src/PartSet/PartSet_Operation.h delete mode 100644 src/PartSet/PartSet_OperationFeatureBase.cpp delete mode 100644 src/PartSet/PartSet_OperationFeatureBase.h delete mode 100644 src/PartSet/PartSet_OperationFeatureCreate.cpp delete mode 100644 src/PartSet/PartSet_OperationFeatureCreate.h delete mode 100644 src/PartSet/PartSet_OperationFeatureEdit.cpp delete mode 100644 src/PartSet/PartSet_OperationFeatureEdit.h delete mode 100644 src/PartSet/PartSet_OperationSketch.cpp delete mode 100644 src/PartSet/PartSet_OperationSketch.h delete mode 100644 src/PartSet/PartSet_OperationSketchBase.cpp delete mode 100644 src/PartSet/PartSet_OperationSketchBase.h create mode 100644 src/PartSet/PartSet_WidgetPoint2d.cpp create mode 100644 src/PartSet/PartSet_WidgetPoint2d.h create mode 100644 src/PartSet/PartSet_WidgetPoint2dDistance.cpp create mode 100644 src/PartSet/PartSet_WidgetPoint2dDistance.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index d7ed62fab..159f97c17 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -26,10 +26,9 @@ const static char* WDG_MULTISELECTOR = "multi_selector"; const static char* WDG_SHAPE_SELECTOR = "shape_selector"; const static char* WDG_CHOICE = "choice"; //Specific widgets -const static char* WDG_POINT_SELECTOR = "point_selector"; -const static char* WDG_POINT2D_DISTANCE = "point2ddistance"; -const static char* WDG_FEATURE_SELECTOR = "feature_selector"; -const static char* WDG_FEATURE_OR_ATTRIBUTE_SELECTOR = "feature_or_attribute_selector"; +//const static char* WDG_POINT2D_DISTANCE = "point2ddistance"; +//const static char* WDG_FEATURE_SELECTOR = "feature_selector"; +//const static char* WDG_FEATURE_OR_ATTRIBUTE_SELECTOR = "feature_or_attribute_selector"; const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor"; const static char* WDG_FILE_SELECTOR= "file_selector"; @@ -54,7 +53,7 @@ const static char* ATTRIBUTE_INTERNAL = "internal"; const static char* ATTRIBUTE_OBLIGATORY = "obligatory"; const static char* ATTRIBUTE_CONCEALMENT = "concealment"; // TODO: Rename -const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param"; +//const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param"; const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP; const static char* ANY_WDG_ICON = FEATURE_ICON; const static char* ANY_WDG_LABEL = "label"; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index ddf454e2c..a8c1cbd26 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -12,13 +12,11 @@ SET(PROJECT_HEADERS ModuleBase_WidgetDoubleValue.h ModuleBase_WidgetEditor.h ModuleBase_WidgetFactory.h - ModuleBase_WidgetFeature.h - ModuleBase_WidgetFeatureOrAttribute.h - ModuleBase_WidgetPoint2D.h +# ModuleBase_WidgetFeature.h +# ModuleBase_WidgetFeatureOrAttribute.h ModuleBase_WidgetSwitch.h ModuleBase_WidgetShapeSelector.h ModuleBase_IWorkshop.h - ModuleBase_WidgetPoint2dDistance.h ModuleBase_WidgetValue.h ModuleBase_WidgetValueFeature.h ModuleBase_Definitions.h @@ -34,6 +32,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetMultiSelector.h ModuleBase_ViewerFilters.h ModuleBase_ResultPrs.h + ModuleBase_IViewWindow.h ) SET(PROJECT_SOURCES @@ -46,12 +45,10 @@ SET(PROJECT_SOURCES ModuleBase_WidgetDoubleValue.cpp ModuleBase_WidgetEditor.cpp ModuleBase_WidgetFactory.cpp - ModuleBase_WidgetFeature.cpp - ModuleBase_WidgetFeatureOrAttribute.cpp - ModuleBase_WidgetPoint2D.cpp +# ModuleBase_WidgetFeature.cpp +# ModuleBase_WidgetFeatureOrAttribute.cpp ModuleBase_WidgetSwitch.cpp ModuleBase_WidgetShapeSelector.cpp - ModuleBase_WidgetPoint2dDistance.cpp ModuleBase_WidgetValue.cpp ModuleBase_WidgetValueFeature.cpp ModuleBase_WidgetChoice.cpp diff --git a/src/ModuleBase/ModuleBase_Definitions.h b/src/ModuleBase/ModuleBase_Definitions.h index 8cfed34b4..78a858bdd 100644 --- a/src/ModuleBase/ModuleBase_Definitions.h +++ b/src/ModuleBase/ModuleBase_Definitions.h @@ -2,10 +2,10 @@ #define ModuleBase_Definitions_H #include -#include +#include typedef QList QIntList; //!< list of int values typedef QList QShortList; //!< list of short int values typedef QList QDoubleList; //!< list of double values -typedef QList QFeatureList; //!< List of features +typedef QList QObjectPtrList; //!< List of ModelAPI_Objects #endif diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index daece8b0d..4aa92c553 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -4,33 +4,58 @@ #include "ModuleBase_ViewerPrs.h" #include "ModuleBase_Operation.h" #include "ModuleBase_ISelection.h" +#include "ModuleBase_OperationDescription.h" #include #include +#include #include +#include +#include +#include ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent) : QObject(theParent), myWorkshop(theParent) { + connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)), + SLOT(onOperationStarted(ModuleBase_Operation*))); + + connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), + SLOT(onOperationStopped(ModuleBase_Operation*))); + + connect(myWorkshop, SIGNAL(operationResumed(ModuleBase_Operation*)), + SLOT(onOperationResumed(ModuleBase_Operation*))); + + connect(myWorkshop, SIGNAL(operationComitted(ModuleBase_Operation*)), + SLOT(onOperationComitted(ModuleBase_Operation*))); + + connect(myWorkshop, SIGNAL(operationAborted(ModuleBase_Operation*)), + SLOT(onOperationAborted(ModuleBase_Operation*))); + connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this, - SLOT(onMousePressed(QMouseEvent*))); - connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this, - SLOT(onMouseReleased(QMouseEvent*))); - connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this, - SLOT(onMouseMoved(QMouseEvent*))); - connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this, - SLOT(onKeyRelease(QKeyEvent*))); - connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this, - SLOT(onMouseDoubleClick(QMouseEvent*))); + + + //connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this, + // SLOT(onMousePressed(QMouseEvent*))); + //connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this, + // SLOT(onMouseReleased(QMouseEvent*))); + //connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this, + // SLOT(onMouseMoved(QMouseEvent*))); + //connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this, + // SLOT(onKeyRelease(QKeyEvent*))); + //connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this, + // SLOT(onMouseDoubleClick(QMouseEvent*))); } void ModuleBase_IModule::launchOperation(const QString& theCmdId) { + if (!myWorkshop->canStartOperation(theCmdId)) + return; + ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString()); ModuleBase_ISelection* aSelection = myWorkshop->selection(); // Initialise operation with preliminary selection @@ -47,3 +72,67 @@ void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation) aMessage->setPointer(theOperation); Events_Loop::loop()->send(aMessage); } + +ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& theFeatureId) +{ + return new ModuleBase_Operation(theFeatureId.c_str(), this); +} + +ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId) +{ + ModuleBase_Operation* anOperation = getNewOperation(theFeatureId); + + // If the operation is launched as sub-operation of another then we have to initialise + // parent feature + ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation(); + if (aCurOperation) { + FeaturePtr aFeature = aCurOperation->feature(); + CompositeFeaturePtr aCompFea = std::dynamic_pointer_cast(aFeature); + if (aCompFea) + anOperation->setParentFeature(aCompFea); + } + + std::string aPluginFileName = myFeaturesInFiles[theFeatureId]; + Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); + aWdgReader.readAll(); + std::string aXmlCfg = aWdgReader.featureWidgetCfg(theFeatureId); + std::string aDescription = aWdgReader.featureDescription(theFeatureId); + + anOperation->getDescription()->setDescription(QString::fromStdString(aDescription)); + anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); + + return anOperation; +} + +void ModuleBase_IModule::createFeatures() +{ + registerValidators(); + + Config_ModuleReader aXMLReader = Config_ModuleReader(); + aXMLReader.readAll(); + myFeaturesInFiles = aXMLReader.featuresInFiles(); +} + + +void ModuleBase_IModule::actionCreated(QAction* theFeature) +{ + connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered())); +} + + +void ModuleBase_IModule::onFeatureTriggered() +{ + QAction* aCmd = dynamic_cast(sender()); + //Do nothing on uncheck + if (aCmd->isCheckable() && !aCmd->isChecked()) + return; + launchOperation(aCmd->data().toString()); +} + + +void ModuleBase_IModule::editFeature(FeaturePtr theFeature) +{ + ModuleBase_Operation* anOperation = createOperation(theFeature->getKind()); + anOperation->setFeature(theFeature); + sendOperation(anOperation); +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 08a33e42d..46d0e81ca 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -4,9 +4,13 @@ #include "ModuleBase.h" #include "ModuleBase_IWorkshop.h" +#include + #include #include +#include +#include class QAction; class QMouseEvent; @@ -29,10 +33,13 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject virtual ~ModuleBase_IModule() {} /// Reads description of features from XML file - virtual void createFeatures() = 0; + virtual void createFeatures(); /// Called on creation of menu item in desktop - virtual void featureCreated(QAction*) = 0; + virtual void actionCreated(QAction*); + + /// Called when user selects feature for editing + virtual void editFeature(FeaturePtr theFeature); /// Creates an operation and send it to loop /// \param theCmdId the operation name @@ -43,7 +50,7 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Creates custom widgets for property panel virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent, - Config_WidgetAPI* theWidgetApi, + Config_WidgetAPI* theWidgetApi, std::string theParentId, QList& theModelWidgets) { return 0; @@ -51,7 +58,27 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject ModuleBase_IWorkshop* workshop() const { return myWorkshop; } + /// Call back forlast tuning of property panel before operation performance + /// It is called as on clearing of property panel as on filling with new widgets + virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {} + +public slots: + void onFeatureTriggered(); + protected slots: + /// SLOT, that is called after the operation is started. Connect on the focus activated signal + virtual void onOperationStarted(ModuleBase_Operation* theOperation) {} + + /// SLOT, that is called after the operation is stopped. Switched off the modfications performed + /// by the operation start + virtual void onOperationStopped(ModuleBase_Operation* theOperation) {} + + virtual void onOperationResumed(ModuleBase_Operation* theOperation) {} + + virtual void onOperationComitted(ModuleBase_Operation* theOperation) {} + + virtual void onOperationAborted(ModuleBase_Operation* theOperation) {} + /// Called on selection changed event virtual void onSelectionChanged() {} @@ -59,25 +86,25 @@ protected slots: /// SLOT, that is called by mouse press in the viewer. /// The mouse released point is sent to the current operation to be processed. /// \param theEvent the mouse event - virtual void onMousePressed(QMouseEvent* theEvent) {} + //virtual void onMousePressed(QMouseEvent* theEvent) {} /// SLOT, that is called by mouse release in the viewer. /// The mouse released point is sent to the current operation to be processed. /// \param theEvent the mouse event - virtual void onMouseReleased(QMouseEvent* theEvent) {} + //virtual void onMouseReleased(QMouseEvent* theEvent) {} /// SLOT, that is called by mouse move in the viewer. /// The mouse moved point is sent to the current operation to be processed. /// \param theEvent the mouse event - virtual void onMouseMoved(QMouseEvent* theEvent) {} + //virtual void onMouseMoved(QMouseEvent* theEvent) {} /// SLOT, that is called by the mouse double click in the viewer. /// \param theEvent the mouse event - virtual void onMouseDoubleClick(QMouseEvent* theEvent) {} + //virtual void onMouseDoubleClick(QMouseEvent* theEvent) {} /// SLOT, that is called by the key in the viewer is clicked. /// \param theEvent the mouse event - virtual void onKeyRelease(QKeyEvent* theEvent) {} + //virtual void onKeyRelease(QKeyEvent* theEvent) {} protected: /// Sends the operation for launching @@ -87,16 +114,22 @@ protected slots: /// Creates a new operation /// \param theCmdId the operation name /// \param theFeatureKind a kind of feature to get the feature xml description - virtual ModuleBase_Operation* createOperation(const std::string& theCmdId, - const std::string& theFeatureKind = "") = 0; + virtual ModuleBase_Operation* createOperation(const std::string& theFeatureId); + + /// Register validators for this module + virtual void registerValidators() {} + /// Returns new instance of operation object (used in createOperation for customization) + virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId); protected: ModuleBase_IWorkshop* myWorkshop; - + std::map myFeaturesInFiles; }; + + //! This function must return a new module instance. extern "C" { typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*); diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index 7f8d9d32d..b0114eb0b 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -31,10 +31,14 @@ 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); + /// Emited when there is no next widget + void noMoreWidgets(); + public slots: /// Activate the next widget in the property panel /// \param theWidget a widget. The next widget should be activated diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index c1b06ca1b..037be3bd0 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -31,14 +31,14 @@ class ModuleBase_ISelection virtual QList getHighlighted(int theShapeTypeToSkip = -1) const = 0; /** - * Returns list of features currently selected in 3d viewer + * Returns list of features currently selected in object browser */ - virtual QList selectedObjects() const = 0; + virtual QObjectPtrList selectedObjects() const = 0; /** * Returns list of currently selected results */ - virtual QList selectedPresentations() const = 0; + virtual QObjectPtrList selectedPresentations() const = 0; //! Returns list of currently selected QModelIndexes virtual QModelIndexList selectedIndexes() const = 0; diff --git a/src/ModuleBase/ModuleBase_IViewWindow.h b/src/ModuleBase/ModuleBase_IViewWindow.h new file mode 100644 index 000000000..fcf763e44 --- /dev/null +++ b/src/ModuleBase/ModuleBase_IViewWindow.h @@ -0,0 +1,20 @@ + + +#ifndef ModuleBase_IViewWindow_H +#define ModuleBase_IViewWindow_H + +#include + + +/** +* Interface to ViewWindow object which contains 3d scene +*/ +class ModuleBase_IViewWindow +{ +public: + /// Returns OCCT object which contains 3d view object + virtual Handle(V3d_View) v3dView() const = 0; +}; + + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_IViewer.h b/src/ModuleBase/ModuleBase_IViewer.h index 3e573d223..c701f6108 100644 --- a/src/ModuleBase/ModuleBase_IViewer.h +++ b/src/ModuleBase/ModuleBase_IViewer.h @@ -9,6 +9,7 @@ class QMouseEvent; class QKeyEvent; class QContextMenuEvent; +class ModuleBase_IViewWindow; /** * A Base object for definition of connector object to @@ -64,16 +65,18 @@ Q_OBJECT signals: void lastViewClosed(); - void tryCloseView(); - void deleteView(); - void viewCreated(); - void mousePress(QMouseEvent* theEvent); - void mouseRelease(QMouseEvent* theEvent); - void mouseDoubleClick(QMouseEvent* theEvent); - void mouseMove(QMouseEvent* theEvent); - void keyPress(QKeyEvent* theEvent); - void keyRelease(QKeyEvent* theEvent); - void activated(); + void tryCloseView(ModuleBase_IViewWindow* theWnd); + void deleteView(ModuleBase_IViewWindow* theWnd); + void viewCreated(ModuleBase_IViewWindow* theWnd); + void activated(ModuleBase_IViewWindow* theWnd); + + void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + + void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent); + void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent); void selectionChanged(); void contextMenuRequested(QContextMenuEvent*); diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index 12e9aef22..94c1800d1 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -50,6 +50,9 @@ Q_OBJECT //! Returns currently active operation virtual ModuleBase_Operation* currentOperation() const = 0; + //! Returns true if the operation with id theId can be started + virtual bool canStartOperation(QString theId) = 0; + //! Returns AIS opbject by data object virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const = 0; @@ -58,13 +61,30 @@ Q_OBJECT //! Select features clearing previous selection. //! If the list is empty then selection will be cleared - virtual void setSelected(const QList& theFeatures) = 0; + virtual void setSelected(const QObjectPtrList& theFeatures) = 0; signals: void selectionChanged(); - void operationStarted(ModuleBase_Operation*); - void operationStopped(ModuleBase_Operation*); + /// Signal about an operation is started. It is emitted after the start() of operation is done. + void operationStarted(ModuleBase_Operation* theOperation); + + /// Signal about an operation is stopped. It is emitted after the stop() of operation is done. + /// \param theOperation a stopped operation + void operationStopped(ModuleBase_Operation* theOperation); + + /// Signal about an operation is resumed. It is emitted after the resume() of operation is done. + void operationResumed(ModuleBase_Operation* theOperation); + + /// Emitted when current operation is comitted + void operationComitted(ModuleBase_Operation* theOperation); + + /// Emitted when current operation is aborted + void operationAborted(ModuleBase_Operation* theOperation); + + /// Signal which is emited after activation of property panel + void propertyPanelActivated(); + }; #endif diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index c7525d742..b88becde9 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -74,63 +74,41 @@ bool ModuleBase_Operation::isNestedOperationsEnabled() const return true; } -void ModuleBase_Operation::storeCustomValue() -{ - if (!myFeature) { -#ifdef _DEBUG - qDebug() << "ModuleBase_Operation::storeCustom: " << - "trying to store value without opening a transaction."; -#endif - return; - } - - ModuleBase_ModelWidget* aCustom = dynamic_cast(sender()); - if (aCustom) - aCustom->storeValue(); -} - -void ModuleBase_Operation::startOperation() -{ - if (!myIsEditing) - createFeature(); -} - -void ModuleBase_Operation::stopOperation() -{ -} +//void ModuleBase_Operation::storeCustomValue() +//{ +// if (!myFeature) { +//#ifdef _DEBUG +// qDebug() << "ModuleBase_Operation::storeCustom: " << +// "trying to store value without opening a transaction."; +//#endif +// return; +// } +// +// ModuleBase_ModelWidget* aCustom = dynamic_cast(sender()); +// if (aCustom) +// aCustom->storeValue(); +//} -void ModuleBase_Operation::abortOperation() -{ -} - -void ModuleBase_Operation::commitOperation() -{ -} - -void ModuleBase_Operation::afterCommitOperation() -{ -} bool ModuleBase_Operation::canBeCommitted() const { return isValid(); } - -void ModuleBase_Operation::flushUpdated() -{ - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); -} +// +//void ModuleBase_Operation::flushUpdated() +//{ +// Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); +//} void ModuleBase_Operation::flushCreated() { Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); } -FeaturePtr ModuleBase_Operation::createFeature( - const bool theFlushMessage, CompositeFeaturePtr theCompositeFeature) +FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage) { - if (theCompositeFeature) { - myFeature = theCompositeFeature->addFeature(getDescription()->operationId().toStdString()); + if (myParentFeature) { + myFeature = myParentFeature->addFeature(getDescription()->operationId().toStdString()); } else { std::shared_ptr aDoc = document(); myFeature = aDoc->addFeature(getDescription()->operationId().toStdString()); @@ -167,7 +145,7 @@ bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const std::list aResults = aFeature->results(); std::list::const_iterator aIt; for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - if ((*aIt) == theObj) + if (theObj == (*aIt)) return true; } } @@ -185,15 +163,26 @@ void ModuleBase_Operation::start() { ModelAPI_Session::get()->startOperation(); + if (!myIsEditing) + createFeature(); + startOperation(); emit started(); } +void ModuleBase_Operation::postpone() +{ + if (myPropertyPanel) + disconnect(myPropertyPanel, 0, this, 0); + emit postponed(); +} + void ModuleBase_Operation::resume() { if (myPropertyPanel) - connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), - this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + connect(myPropertyPanel, SIGNAL(noMoreWidgets()), SLOT(commit())); + // connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), + // this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); emit resumed(); } @@ -213,13 +202,10 @@ void ModuleBase_Operation::abort() bool ModuleBase_Operation::commit() { if (canBeCommitted()) { - commitOperation(); - emit committed(); - - if (myPropertyPanel) - disconnect(myPropertyPanel, 0, this, 0); + if (myPropertyPanel) + disconnect(myPropertyPanel, 0, this, 0); - stopOperation(); + commitOperation(); // check whether there are modifications performed during the current operation // in the model // in case if there are no modifications, do not increase the undo/redo stack @@ -228,7 +214,9 @@ bool ModuleBase_Operation::commit() else ModelAPI_Session::get()->abortOperation(); + stopOperation(); emit stopped(); + emit committed(); afterCommitOperation(); return true; @@ -309,7 +297,7 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, QList aSelected = theSelection->getSelected(); std::list aResults = aFeature->results(); - QList aResList; + QObjectPtrList aResList; std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) aResList.append(*aIt); @@ -335,29 +323,29 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, } } -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(std::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); - bool isApplyed = aActiveWgt->setValue(aValue); - - delete aValue; - myIsModified = (myIsModified || isApplyed); - return isApplyed; -} +//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(std::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); +// bool isApplyed = aActiveWgt->setValue(aValue); +// +// delete aValue; +// myIsModified = (myIsModified || isApplyed); +// return isApplyed; +//} bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs, ModuleBase_IViewer* theViewer, @@ -376,6 +364,14 @@ void ModuleBase_Operation::clearPreselection() void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) { myPropertyPanel = theProp; - connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, - SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this, + // SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); + if (myPropertyPanel) { + connect(myPropertyPanel, SIGNAL(noMoreWidgets()), SLOT(commit())); + } } + +bool ModuleBase_Operation::isGranted(QString theId) const +{ + return myNestedFeatures.contains(theId); +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index f1b0ae218..208e35035 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -65,7 +65,7 @@ Q_OBJECT * the operation is not granted. * The method has to be redefined for granted operations. */ - virtual bool isGranted(ModuleBase_Operation* theOperation) const { return false; } + virtual bool isGranted(QString theId) const; /// Sets a list of model widgets, according to the operation feature xml definition /// \param theXmlRepresentation an xml feature definition @@ -110,11 +110,11 @@ Q_OBJECT /// 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 keyReleased(const int theKey) {}; /// If operation needs to redisplay its result during operation /// then this method has to return True - virtual bool hasPreview() const { return false; } + //virtual bool hasPreview() const { return false; } /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations @@ -130,12 +130,19 @@ Q_OBJECT /// Activates widgets by preselection if it is accepted virtual bool activateByPreselection(); + /// If the operation works with feature which is sub-feature of another one + /// then this variable has to be initialised by parent feature + /// before operation feature creating + void setParentFeature(CompositeFeaturePtr theParent) { myParentFeature = theParent; } + CompositeFeaturePtr parentFeature() const { return myParentFeature; } + signals: void started(); /// the operation is started void aborted(); /// the operation is aborted void committed(); /// the operation is committed void stopped(); /// the operation is aborted or committed void resumed(); /// the operation is resumed + void postponed(); /// the operation is postponed public slots: /// Starts operation @@ -145,6 +152,10 @@ signals: /// be better to inherit own operator from base one and redefine startOperation method /// instead. void start(); + + /// Deactivates current operation which can be resumed later. + void postpone(); + /// Resumes operation /// Public slot. Verifies whether operation can be started and starts operation. /// This slot is not virtual and cannot be redefined. Redefine startOperation method @@ -152,10 +163,12 @@ signals: /// be better to inherit own operator from base one and redefine startOperation method /// instead. void resume(); + /// Aborts operation /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined. /// Redefine abortOperation method to change behavior of operation instead void abort(); + /// Commits operation /// Public slot. Commits operation. This slot is not virtual and cannot be redefined. /// Redefine commitOperation method to change behavior of operation instead @@ -169,31 +182,35 @@ signals: // Data model methods. /// Stores a custom value in model. - virtual void storeCustomValue(); + //virtual void storeCustomValue(); /// Slots which listen the mode widget activation /// \param theWidget the model widget - virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget); + //virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget); protected: /// Virtual method called when operation started (see start() method for more description) /// Default impl calls corresponding slot and commits immediately. - virtual void startOperation(); + virtual void startOperation() {} + + /// Implementation of specific steps on postpone operation + virtual void postponeOperation() {} /// Virtual method called when operation stopped - committed or aborted. - virtual void stopOperation(); + virtual void stopOperation() {} /// Virtual method called when operation aborted (see abort() method for more description) - virtual void abortOperation(); + virtual void abortOperation() {} /// Virtual method called when operation committed (see commit() method for more description) - virtual void commitOperation(); + virtual void commitOperation() {} /// Virtual method called after operation committed (see commit() method for more description) - virtual void afterCommitOperation(); + virtual void afterCommitOperation() {} /// Send update message by loop - void flushUpdated(); + //void flushUpdated(); + /// Send created message by loop void flushCreated(); @@ -201,8 +218,7 @@ signals: /// \param theFlushMessage the flag whether the create message should be flushed /// \param theCompositeFeature the feature that must be used for adding the created object or null /// \returns the created - virtual FeaturePtr createFeature(const bool theFlushMessage = true, - CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr()); + virtual FeaturePtr createFeature(const bool theFlushMessage = true); /// Verifies whether this operator can be commited. /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled @@ -216,7 +232,7 @@ signals: /// \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); + //virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY); /// Return a widget value point by the selection and the viewer position /// The default realization returns false @@ -252,6 +268,12 @@ signals: /// Access to property panel ModuleBase_IPropertyPanel* myPropertyPanel; + + /// If the operation works with feature which is sub-feature of another one + /// then this variable has to be initialised by parent feature + /// before operation feature creating + CompositeFeaturePtr myParentFeature; + }; #endif diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 8df14bdc3..f246677ce 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -3,9 +3,8 @@ // Author: Vitaly Smetannikov #include "ModuleBase_Tools.h" -#include -#include -#include +#include +#include namespace ModuleBase_Tools { @@ -43,4 +42,8 @@ void zeroMargins(QLayout* theLayout) theLayout->setSpacing(5); } + + } + + diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 6c903d3fb..1d5a448c6 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -7,10 +7,8 @@ #include "ModuleBase.h" -#include -#include - -class GeomAPI_Shape; +class QWidget; +class QLayout; namespace ModuleBase_Tools { @@ -23,6 +21,7 @@ MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout); MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget); MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout); + } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index ee5bc67f4..6d5f90653 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -24,6 +24,7 @@ #include #include #include +#include ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData, @@ -60,6 +61,16 @@ double editedValue(double theValue, bool& isDone) bool ModuleBase_WidgetEditor::focusTo() { + // We can not launch here modal process for value editing because + // it can be called on other focusOutWidget event and will block it + QTimer::singleShot(1, this, SLOT(showPopupEditor())); + return true; +} + +void ModuleBase_WidgetEditor::showPopupEditor() +{ + // White while all events will be processed + QApplication::processEvents(); double aValue = mySpinBox->value(); bool isDone; aValue = editedValue(aValue, isDone); @@ -71,8 +82,6 @@ bool ModuleBase_WidgetEditor::focusTo() } emit valuesChanged(); emit focusOutWidget(this); - - return false; } void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.h b/src/ModuleBase/ModuleBase_WidgetEditor.h index 508e5ee53..ded826289 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetEditor.h @@ -47,6 +47,10 @@ Q_OBJECT /// \param theAttribute the feature attribute static void editFeatureValue(FeaturePtr theFeature, const std::string theAttribute); + private slots: + /// Shous popup window under cursor for data editing + void showPopupEditor(); + private: FeaturePtr myFeature; ///< the current widget feature QStringList myFeatureKinds; ///< the kinds of possible features diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index cc66a69b8..66bc824f4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -9,15 +9,14 @@ #include #include -#include -#include -#include +//#include +//#include #include #include #include #include #include -#include +//#include #include #include #include @@ -139,21 +138,15 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType } else if (theType == WDG_BOOLVALUE) { result = booleanControl(theParent); - } else if (theType == WDG_POINT_SELECTOR) { - result = pointSelectorControl(theParent); + //} else if (theType == WDG_FEATURE_SELECTOR) { + // result = featureSelectorControl(theParent); - } else if (theType == WDG_FEATURE_SELECTOR) { - result = featureSelectorControl(theParent); - - } else if (theType == WDG_FEATURE_OR_ATTRIBUTE_SELECTOR) { - result = featureOrAttributeSelectorControl(theParent); + //} else if (theType == WDG_FEATURE_OR_ATTRIBUTE_SELECTOR) { + // result = featureOrAttributeSelectorControl(theParent); } else if (theType == WDG_DOUBLEVALUE_EDITOR) { result = doubleValueEditor(theParent); - } else if (theType == WDG_POINT2D_DISTANCE) { - result = point2dDistanceControl(theParent); - } else if (theType == WDG_FILE_SELECTOR) { result = fileSelectorControl(theParent); @@ -170,7 +163,7 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType result = createContainer(theType, theParent); } else { result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, - myModelWidgets); + myParentId, myModelWidgets); #ifdef _DEBUG if (!result) {qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");} #endif @@ -206,29 +199,21 @@ QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent) return aDblWgt->getControl(); } -QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent) -{ - ModuleBase_WidgetPoint2D* aWidget = - new ModuleBase_WidgetPoint2D(theParent, myWidgetApi,myParentId); - myModelWidgets.append(aWidget); - return aWidget->getControl(); -} - -QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent) -{ - ModuleBase_WidgetFeature* aWidget = - new ModuleBase_WidgetFeature(theParent, myWidgetApi,myParentId); - myModelWidgets.append(aWidget); - return aWidget->getControl(); -} - -QWidget* ModuleBase_WidgetFactory::featureOrAttributeSelectorControl(QWidget* theParent) -{ - ModuleBase_WidgetFeatureOrAttribute* aWidget = - new ModuleBase_WidgetFeatureOrAttribute(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aWidget); - return aWidget->getControl(); -} +//QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent) +//{ +// ModuleBase_WidgetFeature* aWidget = +// new ModuleBase_WidgetFeature(theParent, myWidgetApi,myParentId); +// myModelWidgets.append(aWidget); +// return aWidget->getControl(); +//} + +//QWidget* ModuleBase_WidgetFactory::featureOrAttributeSelectorControl(QWidget* theParent) +//{ +// ModuleBase_WidgetFeatureOrAttribute* aWidget = +// new ModuleBase_WidgetFeatureOrAttribute(theParent, myWidgetApi, myParentId); +// myModelWidgets.append(aWidget); +// return aWidget->getControl(); +//} QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent) { @@ -254,14 +239,6 @@ QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) return aBoolWgt->getControl(); } -QWidget* ModuleBase_WidgetFactory::point2dDistanceControl(QWidget* theParent) -{ - ModuleBase_WidgetPoint2dDistance* aDistWgt = - new ModuleBase_WidgetPoint2dDistance(theParent, myWidgetApi, myParentId); - myModelWidgets.append(aDistWgt); - return aDistWgt->getControl(); -} - QWidget* ModuleBase_WidgetFactory::fileSelectorControl(QWidget* theParent) { ModuleBase_WidgetFileSelector* aFileSelectorWgt = diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index fd267d418..7d40f5b72 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -39,13 +39,11 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); QWidget* labelControl(QWidget* theParent); QWidget* doubleSpinBoxControl(QWidget* theParent); - QWidget* pointSelectorControl(QWidget* theParent); - QWidget* featureSelectorControl(QWidget* theParent); - QWidget* featureOrAttributeSelectorControl(QWidget* theParent); + //QWidget* featureSelectorControl(QWidget* theParent); + //QWidget* featureOrAttributeSelectorControl(QWidget* theParent); QWidget* doubleValueEditor(QWidget* theParent); QWidget* shapeSelectorControl(QWidget* theParent); QWidget* booleanControl(QWidget* theParent); - QWidget* point2dDistanceControl(QWidget* theParent); QWidget* fileSelectorControl(QWidget* theParent); QWidget* choiceControl(QWidget* theParent); QWidget* lineEditControl(QWidget* theParent); diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp deleted file mode 100644 index 3b28aeb6a..000000000 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// File: ModuleBase_WidgetFeature.cpp -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId) -{ - myContainer = new QWidget(theParent); - QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); - ModuleBase_Tools::adjustMargins(aControlLay); - - QString aLabelText = QString::fromStdString(theData->widgetLabel()); - myLabel = new QLabel(aLabelText, myContainer); - aControlLay->addWidget(myLabel); - - myEditor = new QLineEdit(myContainer); - QString anObjName = QString::fromStdString(attributeID()); - myEditor->setObjectName(anObjName); - myEditor->setReadOnly(true); - aControlLay->addWidget(myEditor); - - QString aTTip = QString::fromStdString(theData->widgetTooltip()); - myEditor->setToolTip(aTTip); - aControlLay->addWidget(myEditor); - aControlLay->setStretch(1, 1); -} - -ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature() -{ -} - -bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue) -{ - bool isDone = false; - - if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (aFeatureValue) - isDone = setObject(aFeatureValue->object()); - } - return isDone; -} - -bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSendEvent) -{ - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list aValidators; - std::list > anArguments; - aFactory->validators(parentID(), attributeID(), aValidators, anArguments); - - // Check the type of selected object - std::list::iterator aValidator = aValidators.begin(); - bool isValid = true; - for (; aValidator != aValidators.end(); aValidator++) { - const ModelAPI_ResultValidator* aResValidator = - dynamic_cast(*aValidator); - if (aResValidator) { - isValid = false; - if (aResValidator->isValid(theObject)) { - isValid = true; - break; - } - } - } - if (!isValid) - return false; - - // Check the acceptability of the object as attribute - aValidator = aValidators.begin(); - std::list >::iterator aArgs = anArguments.begin(); - for (; aValidator != aValidators.end(); aValidator++, aArgs++) { - const ModelAPI_RefAttrValidator* aAttrValidator = - dynamic_cast(*aValidator); - if (aAttrValidator) { - if (!aAttrValidator->isValid(myFeature, *aArgs, theObject)) { - return false; - } - } - } - - myObject = theObject; - myEditor->setText(theObject ? theObject->data()->name().c_str() : ""); - if (theSendEvent) - emit valuesChanged(); - return true; -} - -bool ModuleBase_WidgetFeature::storeValue() const -{ - //FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); - if (!myObject) - return false; - - std::shared_ptr aData = myFeature->data(); - std::shared_ptr aRef = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); - - ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this; - aRef->setObject(myObject); - myFeature->execute(); - updateObject(myFeature); - return true; -} - -bool ModuleBase_WidgetFeature::restoreValue() -{ - std::shared_ptr aData = myFeature->data(); - std::shared_ptr aRef = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); - - ObjectPtr anObjPtr = aRef->object(); - if (anObjPtr) { - myObject = anObjPtr; - myEditor->setText(myObject ? myObject->data()->name().c_str() : ""); - return true; - } - return false; -} - -QWidget* ModuleBase_WidgetFeature::getControl() const -{ - return myContainer; -} - -QList ModuleBase_WidgetFeature::getControls() const -{ - QList aList; - aList.append(myEditor); - return aList; -} diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.h b/src/ModuleBase/ModuleBase_WidgetFeature.h deleted file mode 100644 index ec7413654..000000000 --- a/src/ModuleBase/ModuleBase_WidgetFeature.h +++ /dev/null @@ -1,96 +0,0 @@ -// File: ModuleBase_WidgetFeature.h -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_WidgetFeature_H -#define ModuleBase_WidgetFeature_H - -#include -#include "ModuleBase_ModelWidget.h" - -#include -#include - -class ModuleBase_WidgetValue; -class ModelAPI_Feature; -class QWidget; -class QLabel; -class QLineEdit; -class QToolButton; - -/**\class ModuleBase_WidgetFeature - * \ingroup GUI - * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls - */ -class MODULEBASE_EXPORT ModuleBase_WidgetFeature : public ModuleBase_ModelWidget -{ -Q_OBJECT - public: - /// Constructor - /// \theParent the parent object - /// \theParent the parent object - /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetFeature(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId); - /// Destructor - virtual ~ModuleBase_WidgetFeature(); - - /// 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); - - /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue() const; - - virtual bool restoreValue(); - - /// Returns the internal parent wiget control, that can be shown anywhere - /// \returns the widget - QWidget* getControl() const; - - /// Returns list of widget controls - /// \return a control list - virtual QList getControls() const; - /// Defines if it is supposed that the widget should interact with the viewer. - virtual bool isViewerSelector() { return true; } - - protected: - /// Fill the widget values by given point - /// \param thePoint the point - /// \return the boolean result of the feature set - bool setObject(const ObjectPtr& theObject, bool theSendEvent = true); - - /// Returns current widget feature - /// \return the feature - const ObjectPtr object() const - { - return myObject; - } - - /// Returns the widget editor - /// \return the editor - QLineEdit* editor() const - { - return myEditor; - } - - /// Returns the possible feature kinds - /// \return the list of kinds - const QStringList& featureKinds() const - { - return myObjectKinds; - } - - protected: - ObjectPtr myObject; ///< the current widget feature - QStringList myObjectKinds; ///< the kinds of possible features - - private: - QWidget* myContainer; /// the parent top control - QLabel* myLabel; /// the editor information label - QLineEdit* myEditor; ///< the feature editor to visualize the feature name -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp deleted file mode 100644 index 9c052588d..000000000 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// File: ModuleBase_WidgetFeatureOrAttribute.cpp -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include - -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#include -#include -#include -#include - -ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_WidgetFeature(theParent, theData, theParentId) -{ -} - -ModuleBase_WidgetFeatureOrAttribute::~ModuleBase_WidgetFeatureOrAttribute() -{ -} - -bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theValue) -{ - bool isDone = false; - - if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (aFeatureValue) { - ObjectPtr aObject = aFeatureValue->object(); - - std::shared_ptr anAttribute = findAttribute(aFeatureValue); - if (anAttribute) { - isDone = setAttribute(anAttribute, false); - } - else if (aObject) { - isDone = setObject(aObject, false); - } - - if (isDone) - emit valuesChanged(); - } - } - return isDone; -} - -bool ModuleBase_WidgetFeatureOrAttribute::storeValue() const -{ - //FeaturePtr aFeature = std::dynamic_pointer_cast(theFeature); - //if (!aFeature) - // return false; - - std::shared_ptr aData = myFeature->data(); - std::shared_ptr aRef = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); - - if (myObject) - aRef->setObject(myObject); - if (myAttribute) - aRef->setAttr(myAttribute); - - myFeature->execute(); - updateObject(myFeature); - - return true; -} - -bool ModuleBase_WidgetFeatureOrAttribute::restoreValue() -{ - std::shared_ptr aData = myFeature->data(); - std::shared_ptr aRef = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); - - ObjectPtr aObj = aRef->object(); - FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object()); - if (aFeature) { - myObject = aFeature; - myAttribute = aRef->attr(); - - std::string aText = ""; - if (aFeature) - aText = aFeature->data()->name().c_str(); - if (myAttribute) - aText = myAttribute->attributeType().c_str(); - - editor()->setText(aText.c_str()); - return true; - } - return false; -} - -std::shared_ptr ModuleBase_WidgetFeatureOrAttribute::findAttribute( - ModuleBase_WidgetValue* theValue) -{ - std::shared_ptr anAttribute; - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (!aFeatureValue) - return anAttribute; - - std::shared_ptr aValuePoint = aFeatureValue->point(); - if (aValuePoint) { - ObjectPtr aObject = aFeatureValue->object(); - FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); - if (aFeature) { - // find the given point in the feature attributes - std::list > anAttiributes = aFeature->data() - ->attributes(GeomDataAPI_Point2D::type()); - std::list >::const_iterator anIt = anAttiributes - .begin(), aLast = anAttiributes.end(); - for (; anIt != aLast && !anAttribute; anIt++) { - std::shared_ptr aCurPoint = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(*anIt); - if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion()) - anAttribute = aCurPoint; - } - } - } - return anAttribute; -} - -bool ModuleBase_WidgetFeatureOrAttribute::setAttribute( - const std::shared_ptr& theAttribute, bool theSendEvent) -{ - if (!theAttribute) // || !featureKinds().contains(theAttribute->attributeType().c_str())) - return false; - - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list aValidators; - std::list > anArguments; - aFactory->validators(parentID(), attributeID(), aValidators, anArguments); - - // Check the acceptability of the attribute - std::list::iterator aValidator = aValidators.begin(); - int aSize = aValidators.size(); - std::list >::iterator aArgs = anArguments.begin(); - for (; aValidator != aValidators.end(); aValidator++, aArgs++) { - const ModelAPI_RefAttrValidator* aAttrValidator = - dynamic_cast(*aValidator); - if (aAttrValidator) { - if (!aAttrValidator->isValid(myFeature, *aArgs, theAttribute)) { - return false; - } - } - } - - myAttribute = theAttribute; - editor()->setText(theAttribute ? theAttribute->attributeType().c_str() : ""); - if (theSendEvent) - emit valuesChanged(); - return true; -} - diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h deleted file mode 100644 index 5fac25197..000000000 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h +++ /dev/null @@ -1,62 +0,0 @@ -// File: ModuleBase_WidgetFeatureOrAttribute.h -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_WidgetFeatureOrAttribute_H -#define ModuleBase_WidgetFeatureOrAttribute_H - -#include -#include "ModuleBase_WidgetFeature.h" - -#include - -class ModuleBase_WidgetValue; -class ModelAPI_Attribute; - -/**\class ModuleBase_WidgetFeatureOrAttribute - * \ingroup GUI - * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls - */ -class MODULEBASE_EXPORT ModuleBase_WidgetFeatureOrAttribute : public ModuleBase_WidgetFeature -{ -Q_OBJECT - public: - /// Constructor - /// \theParent the parent object - /// \theParent the parent object - /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId); - /// Destructor - virtual ~ModuleBase_WidgetFeatureOrAttribute(); - - /// 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); - - /// Saves the internal parameters to the given feature - /// \param theFeature a model feature to be changed - virtual bool storeValue() const; - - virtual bool restoreValue(); - /// Defines if it is supposed that the widget should interact with the viewer. - virtual bool isViewerSelector() { return true; } - - protected: - /// Returns the feature attribute if it can be found by the given value - /// \param theValue the widget value - /// \return an attribute or null - std::shared_ptr findAttribute(ModuleBase_WidgetValue* theValue); - - /// Set the attribute - /// \param theAttribute value - /// \return the boolean result of the attribute set - bool setAttribute(const std::shared_ptr& theAttribute, bool theSendEvent = - true); - - protected: - std::shared_ptr myAttribute; /// < the attribute -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index ea21968a1..74249c280 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -163,7 +163,7 @@ void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate) void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { activateShapeSelection(); - QList anEmptyList; + QObjectPtrList anEmptyList; myWorkshop->setSelected(anEmptyList); // Clear mySelection, myListControl and storeValue() onSelectionChanged(); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp deleted file mode 100644 index 130870221..000000000 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// File: ModuleBase_WidgetPoint2D.cpp -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId) -{ - myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); - QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)); - myGroupBox = new QGroupBox(aPageName, theParent); - myGroupBox->setFlat(false); - - QGridLayout* aGroupLay = new QGridLayout(myGroupBox); - ModuleBase_Tools::adjustMargins(aGroupLay); - aGroupLay->setColumnStretch(1, 1); - { - QLabel* aLabel = new QLabel(myGroupBox); - aLabel->setText("X"); - aLabel->setPixmap(QPixmap(":pictures/x_point.png")); - aGroupLay->addWidget(aLabel, 0, 0); - - myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox); - myXSpin->setMinimum(-DBL_MAX); - myXSpin->setMaximum(DBL_MAX); - myXSpin->setToolTip("X"); - aGroupLay->addWidget(myXSpin, 0, 1); - - connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); - } - { - QLabel* aLabel = new QLabel(myGroupBox); - aLabel->setText("Y"); - aLabel->setPixmap(QPixmap(":pictures/y_point.png")); - aGroupLay->addWidget(aLabel, 1, 0); - - myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox); - myYSpin->setMinimum(-DBL_MAX); - myYSpin->setMaximum(DBL_MAX); - myYSpin->setToolTip("X"); - aGroupLay->addWidget(myYSpin, 1, 1); - - connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); - } -} - -ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() -{ -} - -bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) -{ - bool isDone = false; - if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (aFeatureValue) { - std::shared_ptr aPoint = aFeatureValue->point(); - if (aPoint) { - setPoint(aPoint); - isDone = true; - } - } - } - return isDone; -} - -void ModuleBase_WidgetPoint2D::setPoint(const std::shared_ptr& thePoint) -{ - - bool isBlocked = this->blockSignals(true); - myXSpin->setValue(thePoint->x()); - myYSpin->setValue(thePoint->y()); - this->blockSignals(isBlocked); - - emit valuesChanged(); -} - -bool ModuleBase_WidgetPoint2D::storeValue() const -{ - std::shared_ptr aData = myFeature->data(); - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(attributeID())); - - ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; - bool isBlocked = that->blockSignals(true); - bool isImmutable = aPoint->setImmutable(true); -#ifdef _DEBUG - std::string _attr_name = myAttributeID; - double _X = myXSpin->value(); - double _Y = myYSpin->value(); -#endif - aPoint->setValue(myXSpin->value(), myYSpin->value()); - updateObject(myFeature); - aPoint->setImmutable(isImmutable); - that->blockSignals(isBlocked); - - return true; -} - -bool ModuleBase_WidgetPoint2D::restoreValue() -{ - std::shared_ptr aData = myFeature->data(); - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(attributeID())); - -#ifdef _DEBUG - std::string _attr_name = myAttributeID; - double _X = aPoint->x(); - double _Y = aPoint->y(); -#endif - bool isBlocked = this->blockSignals(true); - myXSpin->setValue(aPoint->x()); - myYSpin->setValue(aPoint->y()); - this->blockSignals(isBlocked); - return true; -} - -QWidget* ModuleBase_WidgetPoint2D::getControl() const -{ - return myGroupBox; -} - -QList ModuleBase_WidgetPoint2D::getControls() const -{ - QList aControls; - aControls.push_back(myXSpin); - aControls.push_back(myYSpin); - - return aControls; -} - -bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject) -{ - if (myOptionParam.length() == 0) - return false; - std::shared_ptr aData = theObject->data(); - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(myOptionParam)); - if (aPoint) { - bool isBlocked = this->blockSignals(true); - myXSpin->setValue(aPoint->x()); - myYSpin->setValue(aPoint->y()); - this->blockSignals(isBlocked); - - emit valuesChanged(); - emit storedPoint2D(theObject, myOptionParam); - return true; - } - return false; -} diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h deleted file mode 100644 index 394211980..000000000 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ /dev/null @@ -1,77 +0,0 @@ -// File: ModuleBase_WidgetPoint2D.h -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_WidgetPoint2D_H -#define ModuleBase_WidgetPoint2D_H - -#include -#include "ModuleBase_ModelWidget.h" - -#include - -class ModelAPI_Feature; -class ModuleBase_WidgetValue; -class GeomAPI_Pnt2d; - -class QGroupBox; -class ModuleBase_DoubleSpinBox; - -/**\class ModuleBase_WidgetPoint2D - * \ingroup GUI - * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls - */ -class MODULEBASE_EXPORT ModuleBase_WidgetPoint2D : public ModuleBase_ModelWidget -{ -Q_OBJECT - public: - /// Constructor - /// \theParent the parent object - /// \theParent the parent object - /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId); - /// Destructor - virtual ~ModuleBase_WidgetPoint2D(); - - /// 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); - - /// Saves the internal parameters to the given feature - /// \param theObject a model feature to be changed - virtual bool storeValue() const; - - virtual bool restoreValue(); - - /// Returns the internal parent wiget control, that can be shown anywhere - /// \returns the widget - QWidget* getControl() const; - - /// Returns list of widget controls - /// \return a control list - virtual QList getControls() const; - - bool initFromPrevious(ObjectPtr theObject); - -signals: - /// Signal about the point 2d set to the feature - /// \param the feature - /// \param the attribute of the feature - void storedPoint2D(ObjectPtr theObject, const std::string& theAttribute); - - protected: - /// Fill the widget values by given point - /// \param thePoint the point - void setPoint(const std::shared_ptr& thePoint); - - private: - QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets - ModuleBase_DoubleSpinBox* myXSpin; ///< the spin box for the X coordinate - ModuleBase_DoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate - - std::string myOptionParam; /// Parameter name which has to be taken from previous feature -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp deleted file mode 100644 index 210f4bcba..000000000 --- a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// File: ModuleBase_WidgetPoint2dDistance.h -// Created: 23 June 2014 -// Author: Vitaly Smetannikov - -#include -#include -#include - -#include -#include -#include - -#include -#include - -ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) -{ - myFirstPntName = theData->getProperty("first_point"); -} - -ModuleBase_WidgetPoint2dDistance::~ModuleBase_WidgetPoint2dDistance() -{ -} - -bool ModuleBase_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue) -{ - bool isDone = false; - - if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (aFeatureValue) { - std::shared_ptr aPnt = aFeatureValue->point(); - ObjectPtr aObject = aFeatureValue->object(); - FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); - if (aFeature && aPnt) { - setPoint(aFeature, aPnt); - isDone = true; - } - } - } - return isDone; -} - -void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, - const std::shared_ptr& thePnt) -{ - std::shared_ptr aData = theFeature->data(); - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(myFirstPntName)); - if (!aPoint) - return; - - double aRadius = thePnt->distance(aPoint->pnt()); - AttributeDoublePtr aReal = aData->real(attributeID()); - if (aReal && (aReal->value() != aRadius)) { - aReal->setValue(aRadius); - mySpinBox->setValue(aRadius); - } -} diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h deleted file mode 100644 index e80aa393b..000000000 --- a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h +++ /dev/null @@ -1,39 +0,0 @@ -// File: ModuleBase_WidgetPoint2dDistance.h -// Created: 23 June 2014 -// Author: Vitaly Smetannikov - -#ifndef ModuleBase_WidgetPoint2dDistance_H -#define ModuleBase_WidgetPoint2dDistance_H - -#include "ModuleBase.h" -#include "ModuleBase_WidgetDoubleValue.h" - -class ModuleBase_WidgetValue; -class GeomAPI_Pnt2d; - -class MODULEBASE_EXPORT ModuleBase_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue -{ -Q_OBJECT - public: - /// Constructor - /// \theParent the parent object - /// \theData the widget configuation. The attribute of the model widget is obtained from - ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId); - - virtual ~ModuleBase_WidgetPoint2dDistance(); - - /// 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); - - protected: - /// Set the second point which defines a value in the widget as a distance with a first point defined by feature - void setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt); - - private: - std::string myFirstPntName; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 146e62efb..9ccaf35ad 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -15,6 +15,7 @@ #include #include #include + #include #include #include @@ -27,6 +28,8 @@ #include #include #include +#include + #include #include @@ -127,24 +130,36 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const DataPtr aData = myFeature->data(); if (myUseSubShapes) { - std::shared_ptr aSelect = - std::dynamic_pointer_cast(aData->attribute(attributeID())); - ResultPtr aBody = std::dynamic_pointer_cast(mySelectedObject); if (aBody) { - aSelect->setValue(aBody, myShape); + AttributePtr aAttr = aData->attribute(attributeID()); + std::shared_ptr aSelectAttr = + std::dynamic_pointer_cast(aAttr); + + if (aSelectAttr) + aSelectAttr->setValue(aBody, myShape); updateObject(myFeature); return true; } } else { - std::shared_ptr aRef = - std::dynamic_pointer_cast(aData->attribute(attributeID())); - - ObjectPtr aObject = aRef->value(); - if (!(aObject && aObject->isSame(mySelectedObject))) { - aRef->setValue(mySelectedObject); - updateObject(myFeature); - return true; + AttributeReferencePtr aRef = aData->reference(attributeID()); + if (aRef) { + ObjectPtr aObject = aRef->value(); + if (!(aObject && aObject->isSame(mySelectedObject))) { + aRef->setValue(mySelectedObject); + updateObject(myFeature); + return true; + } + } else { + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) { + ObjectPtr aObject = aRefAttr->object(); + if (!(aObject && aObject->isSame(mySelectedObject))) { + aRefAttr->setObject(mySelectedObject); + updateObject(myFeature); + return true; + } + } } } return false; @@ -162,8 +177,14 @@ bool ModuleBase_WidgetShapeSelector::restoreValue() myShape = aSelect->value(); } } else { - std::shared_ptr aRef = aData->reference(attributeID()); - mySelectedObject = aRef->value(); + AttributeReferencePtr aRef = aData->reference(attributeID()); + if (aRef) + mySelectedObject = aRef->value(); + else { + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) + mySelectedObject = aRefAttr->object(); + } } updateSelectionName(); @@ -182,7 +203,7 @@ QList ModuleBase_WidgetShapeSelector::getControls() const //******************************************************************** void ModuleBase_WidgetShapeSelector::onSelectionChanged() { - QList aObjects = myWorkshop->selection()->selectedObjects(); + QObjectPtrList aObjects = myWorkshop->selection()->selectedPresentations(); if (aObjects.size() > 0) { ObjectPtr aObject = aObjects.first(); if ((!mySelectedObject) && (!aObject)) @@ -249,10 +270,6 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr myShape = theShape; if (mySelectedObject) { raisePanel(); - if (!myUseSubShapes) { - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE); - ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent); - } } updateSelectionName(); //activateSelection(false); @@ -384,23 +401,6 @@ void ModuleBase_WidgetShapeSelector::raisePanel() const } } -//******************************************************************** -bool ModuleBase_WidgetShapeSelector::focusTo() -{ - //activateSelection(true); - return ModuleBase_ModelWidget::focusTo(); -} - -//******************************************************************** -bool ModuleBase_WidgetShapeSelector::eventFilter(QObject* theObj, QEvent* theEvent) -{ - //if (theObj == myTextLine) { - // if (theEvent->type() == QEvent::FocusIn) - // activateSelection(true); - //} - return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); -} - //******************************************************************** bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue) { diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index eef773421..d0b04a6c6 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -40,8 +40,6 @@ Q_OBJECT virtual bool restoreValue(); - virtual bool focusTo(); - /// Returns the internal parent wiget control, that can be shown anywhere /// \returns the widget QWidget* getControl() const @@ -80,8 +78,6 @@ Q_OBJECT void onSelectionChanged(); protected: - bool eventFilter(QObject* theObj, QEvent* theEvent); - void updateSelectionName(); void raisePanel() const; diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp index 419c5d0b8..ed2764138 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.cpp +++ b/src/NewGeom/NewGeom_SalomeViewer.cpp @@ -59,68 +59,64 @@ void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel) OCCViewer_Viewer* aViewer = mySelector->viewer(); SUIT_ViewManager* aMgr = aViewer->getViewManager(); - connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed())); - connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)), this, SIGNAL(tryCloseView())); - connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)), this, SIGNAL(deleteView())); - connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)), this, SIGNAL(viewCreated())); - connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), this, SIGNAL(activated())); - - connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); - connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); - connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*))); - connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this, - SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*))); - connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this, - SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*))); - connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this, - SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*))); - - connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); -} - -//********************************************** -void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent) -{ - emit mousePress(theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent) -{ - emit mouseRelease(theEvent); - //if ((theEvent->button() == Qt::RightButton) && - // (theEvent->modifiers() == Qt::NoModifier)) { - // QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos()); - // emit contextMenuRequested(&aEvent); - //} -} - -//********************************************** -void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent) -{ - emit mouseDoubleClick(theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent) -{ - emit mouseMove(theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent) -{ - emit keyPress(theEvent); -} - -//********************************************** -void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent) -{ - emit keyRelease(theEvent); -} + // TODO: Provide ModuleBase_IViewWindow interface + //connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed())); + //connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)), this, SIGNAL(tryCloseView())); + //connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)), this, SIGNAL(deleteView())); + //connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)), this, SIGNAL(viewCreated())); + //connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), this, SIGNAL(activated())); + + //connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this, + // SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + //connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this, + // SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); + //connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this, + // SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*))); + //connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this, + // SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*))); + //connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this, + // SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*))); + //connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this, + // SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*))); + + //connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); +} + +//********************************************** +//void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent) +//{ +// emit mousePress(theEvent); +//} +// +////********************************************** +//void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent) +//{ +// emit mouseRelease(theEvent); +//} +// +////********************************************** +//void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent) +//{ +// emit mouseDoubleClick(theEvent); +//} +// +////********************************************** +//void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent) +//{ +// emit mouseMove(theEvent); +//} +// +////********************************************** +//void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent) +//{ +// emit keyPress(theEvent); +//} +// +////********************************************** +//void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent) +//{ +// emit keyRelease(theEvent); +//} //********************************************** void NewGeom_SalomeViewer::enableSelection(bool isEnabled) diff --git a/src/NewGeom/NewGeom_SalomeViewer.h b/src/NewGeom/NewGeom_SalomeViewer.h index 5148dcc6d..c0d1ec6ce 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.h +++ b/src/NewGeom/NewGeom_SalomeViewer.h @@ -65,12 +65,13 @@ Q_OBJECT } private slots: - void onMousePress(SUIT_ViewWindow*, QMouseEvent*); - void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); - void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*); - void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); - void onKeyPress(SUIT_ViewWindow*, QKeyEvent*); - void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*); + // TODO: Provide ModuleBase_IViewWindow interface + //void onMousePress(SUIT_ViewWindow*, QMouseEvent*); + //void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*); + //void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*); + //void onMouseMove(SUIT_ViewWindow*, QMouseEvent*); + //void onKeyPress(SUIT_ViewWindow*, QKeyEvent*); + //void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*); private: NewGeom_OCCSelector* mySelector; diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index dae5c3b4f..bdfcb5360 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -6,30 +6,36 @@ SET(PROJECT_HEADERS PartSet.h PartSet_Constants.h PartSet_EditLine.h - PartSet_Listener.h +# PartSet_Listener.h PartSet_Module.h - PartSet_OperationFeatureCreate.h - PartSet_OperationFeatureEdit.h - PartSet_OperationSketchBase.h - PartSet_OperationSketch.h - PartSet_OperationFeatureBase.h +# PartSet_OperationFeatureCreate.h +# PartSet_OperationFeatureEdit.h +# PartSet_OperationSketchBase.h +# PartSet_OperationSketch.h +# PartSet_OperationFeatureBase.h PartSet_Tools.h PartSet_WidgetSketchLabel.h PartSet_Validators.h + PartSet_WidgetPoint2d.h + PartSet_WidgetPoint2dDistance.h +# PartSet_Operation.h ) SET(PROJECT_SOURCES PartSet_EditLine.cpp - PartSet_Listener.cpp +# PartSet_Listener.cpp PartSet_Module.cpp - PartSet_OperationFeatureCreate.cpp - PartSet_OperationFeatureEdit.cpp - PartSet_OperationSketchBase.cpp - PartSet_OperationSketch.cpp - PartSet_OperationFeatureBase.cpp +# PartSet_OperationFeatureCreate.cpp +# PartSet_OperationFeatureEdit.cpp +# PartSet_OperationSketchBase.cpp +# PartSet_OperationSketch.cpp +# PartSet_OperationFeatureBase.cpp PartSet_Tools.cpp PartSet_WidgetSketchLabel.cpp PartSet_Validators.cpp + PartSet_WidgetPoint2d.cpp + PartSet_WidgetPoint2dDistance.cpp +# PartSet_Operation.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp deleted file mode 100644 index d12987ede..000000000 --- a/src/PartSet/PartSet_Listener.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// File: PartSet_Listener.h -// Created: 28 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include - -#ifdef _DEBUG -#include -#endif - -using namespace std; - -PartSet_Listener::PartSet_Listener(PartSet_Module* theModule) - : myModule(theModule) -{ - Events_Loop* aLoop = Events_Loop::loop(); - aLoop->registerListener(this, aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); - aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); -} - -PartSet_Listener::~PartSet_Listener() -{ -} - -//****************************************************** -void PartSet_Listener::processEvent(const std::shared_ptr& theMessage) -{ - ModuleBase_Operation* anOperation = myModule->xWorkshop()->operationMgr()->currentOperation(); - PartSet_OperationSketchBase* aSketchOp = dynamic_cast(anOperation); - if (!aSketchOp) - return; - - XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer(); - QString aType = QString(theMessage->eventID().eventText()); - if (aType == EVENT_OBJECT_CREATED) { - std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); - std::set aFeatures = aUpdMsg->objects(); - - PartSet_OperationSketch* aSketchOp = - dynamic_cast(myModule->xWorkshop()->operationMgr()->currentOperation()); - - std::set::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); - for (; anIt != aLast; anIt++) { - ObjectPtr aObj = (*anIt); - // If current operation is Sketch then there is no active sketching operation - // and possible the object was created by Redo operation - if (aSketchOp) { - XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer(); - // Very possible it is not displayed - aDisplayer->display(aObj, false); - } - } - } else if (aType == EVENT_OBJECT_TO_REDISPLAY) { - PartSet_OperationFeatureCreate* aCreationOp = - dynamic_cast - (myModule->xWorkshop()->operationMgr()->currentOperation()); - if (aCreationOp) { - // Deactivate currently creating objects for selection - XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer(); - FeaturePtr aFeature = aCreationOp->feature(); - const std::list& aResults = aFeature->results(); - std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); - - std::set aFeatures = aUpdMsg->objects(); - std::set::const_iterator aObjIt, aNoObj = aFeatures.cend(); - std::list::const_iterator anIt = aResults.begin(), aLast = aResults.end(); - for (; anIt != aLast; anIt++) { - aObjIt = aFeatures.find(*anIt); - if (aObjIt != aNoObj) { - aDisplayer->deactivate(*aObjIt); - } - } - } - } else if (aType == EVENT_OBJECT_DELETED) { - std::shared_ptr aDelMsg = - std::dynamic_pointer_cast(theMessage); - std::shared_ptr aDoc = aDelMsg->document(); - - std::set aGroups = aDelMsg->groups(); - std::set::const_iterator anIt = aGroups.begin(), aLast = aGroups.end(); - for (; anIt != aLast; anIt++) { - std::string aGroup = *anIt; - if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) { // Update only Sketch group - myModule->xWorkshop()->displayer()->eraseDeletedResults(); - myModule->updateCurrentPreview(aGroup); - } - } - } -} diff --git a/src/PartSet/PartSet_Listener.h b/src/PartSet/PartSet_Listener.h deleted file mode 100644 index 8950d2f64..000000000 --- a/src/PartSet/PartSet_Listener.h +++ /dev/null @@ -1,35 +0,0 @@ -// File: PartSet_Listener.h -// Created: 28 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PartSet_Listener_H -#define PartSet_Listener_H - -#include "PartSet.h" - -#include - -class PartSet_Module; - -/*! - \class PartSet_Listener - * \brief The operation for the sketch feature creation - */ -class PARTSET_EXPORT PartSet_Listener : public Events_Listener -{ - public: - /// Constructor - /// \param theId the feature identifier - /// \param theParent the operation parent - PartSet_Listener(PartSet_Module* theModule); - /// Destructor - virtual ~PartSet_Listener(); - - /// This method is called by loop when the event is started to process. - virtual void processEvent(const std::shared_ptr& theMessage); - - private: - PartSet_Module* myModule; ///< the current module -}; - -#endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 092b0769f..7204c0e12 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,17 +1,22 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "PartSet_Module.h" +//#include +//#include +//#include +//#include +//#include +#include "PartSet_WidgetSketchLabel.h" +#include "PartSet_Validators.h" +#include "PartSet_Tools.h" +#include "PartSet_WidgetPoint2D.h" +#include "PartSet_WidgetPoint2dDistance.h" +//#include "PartSet_Operation.h" #include -#include -#include -#include +#include +#include +#include +//#include +//#include #include #include @@ -38,24 +43,28 @@ #include #include - -#include -#include -#include -#include +#include +#include +#include + +//#include +//#include +//#include +//#include //#include //#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include #include #include #include +#include #include #include @@ -64,6 +73,7 @@ #include #endif + /*!Create and return new instance of XGUI_Module*/ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop) { @@ -71,21 +81,32 @@ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* } PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) - : ModuleBase_IModule(theWshop) + : ModuleBase_IModule(theWshop), + myIsDragging(false), myRestartingMode(true), myDragDone(false) { - //myWorkshop = theWshop; - myListener = new PartSet_Listener(this); + //myWorkshop = dynamic_cast(theWshop); + ModuleBase_IViewer* aViewer = aViewer = theWshop->viewer(); + connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*))); + + connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*))); + + connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*))); - connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)), - this, SLOT(onOperationStarted(ModuleBase_Operation*))); + //myListener = new PartSet_Listener(this); - connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this, - SLOT(onOperationStopped(ModuleBase_Operation*))); +// connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)), +// this, SLOT(onOperationStarted(ModuleBase_Operation*))); - XGUI_Workshop* aXWshop = xWorkshop(); - XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr(); - connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this, - SLOT(onContextMenuCommand(const QString&, bool))); +// connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this, +// SLOT(onOperationStopped(ModuleBase_Operation*))); + + //XGUI_Workshop* aXWshop = xWorkshop(); + //XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr(); + //connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this, + // SLOT(onContextMenuCommand(const QString&, bool))); } @@ -93,7 +114,7 @@ PartSet_Module::~PartSet_Module() { } -void PartSet_Module::createFeatures() +void PartSet_Module::registerValidators() { //Registering of validators SessionPtr aMgr = ModelAPI_Session::get(); @@ -103,404 +124,698 @@ void PartSet_Module::createFeatures() aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator); aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator); aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator); - - Config_ModuleReader aXMLReader = Config_ModuleReader(); - aXMLReader.readAll(); - myFeaturesInFiles = aXMLReader.featuresInFiles(); } -void PartSet_Module::featureCreated(QAction* theFeature) + +void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation) { - connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered())); + if (theOperation->isEditOperation()) + return; + /// Restart sketcher operations automatically + FeaturePtr aFeature = theOperation->feature(); + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aFeature); + if (aSPFeature && myRestartingMode) { + myLastOperationId = theOperation->id(); + myLastFeature = theOperation->feature(); + launchOperation(myLastOperationId); + } else { + breakOperationSequence(); + } } -std::string PartSet_Module::featureFile(const std::string& theFeatureId) +void PartSet_Module::breakOperationSequence() { - return myFeaturesInFiles[theFeatureId]; + myLastOperationId = ""; + myLastFeature = FeaturePtr(); + myRestartingMode = false; + } -/* - * - */ -void PartSet_Module::onFeatureTriggered() +void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation) { - QAction* aCmd = dynamic_cast(sender()); - //Do nothing on uncheck - if (aCmd->isCheckable() && !aCmd->isChecked()) - return; - launchOperation(aCmd->data().toString()); + breakOperationSequence(); } - void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation) { - XGUI_Workshop* aXWshp = xWorkshop(); - XGUI_Displayer* aDisplayer = aXWshp->displayer(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); - if (aPreviewOp) { - XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel(); - connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this, - SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection); - - //aDisplayer->deactivateObjectsOutOfContext(); - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); - if (aSketchOp) { - if (aSketchOp->isEditOperation()) { - setSketchingMode(getSketchPlane(aSketchOp->feature())); - } else { - aDisplayer->openLocalContext(); - aDisplayer->activateObjectsOutOfContext(QIntList()); - myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane); - aDisplayer->addSelectionFilter(myPlaneFilter); - QIntList aModes = sketchSelectionModes(aPreviewOp->feature()); - aDisplayer->setSelectionModes(aModes); - } + myRestartingMode = true; + if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) { + // Display all sketcher sub-Objects + myCurrentSketch = std::dynamic_pointer_cast(theOperation->feature()); + XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + FeaturePtr aFeature = myCurrentSketch->subFeature(i); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + aDisplayer->display((*aIt), false); + } + aDisplayer->display(aFeature); } + // Hide sketcher result + std::list aResults = myCurrentSketch->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + aDisplayer->erase((*aIt), false); + } + aDisplayer->erase(myCurrentSketch); } } void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) { - if (!theOperation) - return; - XGUI_Workshop* aXWshp = xWorkshop(); - XGUI_Displayer* aDisplayer = aXWshp->displayer(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); - if (aPreviewOp) { - XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel(); - - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); - if (aSketchOp) { - aDisplayer->closeLocalContexts(); - } else { - PartSet_OperationFeatureCreate* aCreationOp = - dynamic_cast(aPreviewOp); - if (aCreationOp) { - // Activate just created object for selection - FeaturePtr aFeature = aCreationOp->feature(); - QIntList aModes = sketchSelectionModes(aFeature); - const std::list& aResults = aFeature->results(); - std::list::const_iterator anIt, aLast = aResults.end(); - for (anIt = aResults.begin(); anIt != aLast; anIt++) { - aDisplayer->activate(*anIt, aModes); - } - aDisplayer->activate(aFeature, aModes); - aDisplayer->clearSelected(); + if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) { + // Hide all sketcher sub-Objects + XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + FeaturePtr aFeature = myCurrentSketch->subFeature(i); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + aDisplayer->erase((*aIt), false); } + aDisplayer->erase(aFeature, false); } - }// else { - // Activate results of current feature for selection - //FeaturePtr aFeature = theOperation->feature(); - //XGUI_Displayer* aDisplayer = aXWshp->displayer(); - //std::list aResults = aFeature->results(); - //std::list::const_iterator aIt; - //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - // aDisplayer->activate(*aIt); - //} - //} -} - -void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked) -{ - QList aFeatures = workshop()->selection()->selectedObjects(); - if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) { - FeaturePtr aFeature = std::dynamic_pointer_cast(aFeatures.first()); - if (aFeature) - editFeature(aFeature); + // Display sketcher result + std::list aResults = myCurrentSketch->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + aDisplayer->display((*aIt), false); + } + aDisplayer->display(myCurrentSketch); + + myCurrentSketch = CompositeFeaturePtr(); } } -void PartSet_Module::onMousePressed(QMouseEvent* theEvent) -{ - XGUI_Workshop* aXWshp = xWorkshop(); - PartSet_OperationSketchBase* aPreviewOp = - dynamic_cast(workshop()->currentOperation()); - if (aPreviewOp) { - ModuleBase_ISelection* aSelection = workshop()->selection(); - aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection); - } -} -void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) + +void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) { - PartSet_OperationSketchBase* aPreviewOp = - dynamic_cast(myWorkshop->currentOperation()); - if (aPreviewOp) { - ModuleBase_ISelection* aSelection = workshop()->selection(); - // Initialise operation with preliminary selection - aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection); + if ((theOperation->id() == myLastOperationId) && myLastFeature) { + ModuleBase_ModelWidget* aWgt = theOperation->propertyPanel()->activeWidget(); + if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) { + PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast(aWgt); + if (aPnt2dWgt) { + std::shared_ptr aData = myLastFeature->data(); + std::shared_ptr aPoint = + std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Line::END_ID())); + if (aPoint) { + aPnt2dWgt->setPoint(aPoint->x(), aPoint->y()); + PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(), + SketchPlugin_Line::START_ID(), aPoint->x(), aPoint->y()); + theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt); + } + } + } } } -void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) -{ - PartSet_OperationSketchBase* aPreviewOp = - dynamic_cast(myWorkshop->currentOperation()); - if (aPreviewOp) - aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()); -} -void PartSet_Module::onKeyRelease(QKeyEvent* theEvent) +void PartSet_Module::onSelectionChanged() { - ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - aPreviewOp->keyReleased(theEvent->key()); - } + // Activate edit operation for sketcher objects + //ModuleBase_ISelection* aSelect = myWorkshop->selection(); + //QObjectPtrList aObjects = aSelect->selectedPresentations(); + //if (aObjects.size() == 1) { + // FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first()); + // if (aFeature) { + // std::shared_ptr aSPFeature = + // std::dynamic_pointer_cast(aFeature); + // if (aSPFeature) { + // editFeature(aSPFeature); + // } + // } + //} } -void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent) -{ - PartSet_OperationSketchBase* aPreviewOp = - dynamic_cast(myWorkshop->currentOperation()); - Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); - if (aPreviewOp && (!aView.IsNull())) { - ModuleBase_ISelection* aSelection = workshop()->selection(); - // Initialise operation with preliminary selection - aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection); - } -} +//ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId) +//{ +// ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); +// if (aOperation) { +// // If the current operation is sketcher sub-operation then we have to create +// // Costomized operation +// if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()) { +// PartSet_Operation* aPSOp = new PartSet_Operation(theFeatureId.c_str(), this); +// aPSOp->setWorkshop(myWorkshop); +// connect(myWorkshop, SIGNAL(selectionChanged()), aPSOp, SLOT(onSelectionChanged())); +// return aPSOp; +// } +// } +// return ModuleBase_IModule::getNewOperation(theFeatureId); +//} -void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) -{ - myWorkshop->viewer()->setViewProjection(theX, theY, theZ); -} -void PartSet_Module::onSketchLaunched() +void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { - xWorkshop()->actionsMgr()->update(); - // Set working plane - ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - FeaturePtr aSketch = anOperation->feature(); - setSketchingMode(getSketchPlane(aSketch)); -} + if (!(theEvent->buttons() & Qt::LeftButton)) + return; + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + // Use only for sketch operations + if (aOperation && myCurrentSketch) { + if (!PartSet_Tools::sketchPlane(myCurrentSketch)) + return; -void PartSet_Module::onFitAllView() -{ - myWorkshop->viewer()->fitAll(); -} + bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID()); + bool isSketchOpe = sketchOperationIdList().contains(aOperation->id()); -void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject) -{ - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - - std::string aKind = aFeature ? aFeature->getKind() : ""; - ModuleBase_Operation* anOperation = createOperation(theName, aKind); - - PartSet_OperationSketchBase* aSketchOp = dynamic_cast(anOperation); - if (aSketchOp) { - PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast(anOperation); - if (aCreateOp) - aCreateOp->initFeature(aFeature); - else { - anOperation->setFeature(aFeature); - } - ModuleBase_ISelection* aSelection = workshop()->selection(); - // Initialise operation with preliminary selection - aSketchOp->initSelection(aSelection, myWorkshop->viewer()); - } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation - anOperation->setFeature(aFeature); - ////Deactivate result of current feature in order to avoid its selection - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - std::list aResults = aFeature->results(); - std::list::const_iterator aIt; - for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - aDisplayer->deactivate(*aIt); + // Avoid non-sketch operations + if (!isSketchOpe) + return; + + bool isEditing = aOperation->isEditOperation(); + + // Ignore creation sketch operation + if ((!isSketcher) && (!isEditing)) + return; + + // Remember highlighted objects for editing + ModuleBase_ISelection* aSelect = myWorkshop->selection(); + QList aObjects = aSelect->getHighlighted(); + myEditingFeatures.clear(); + if (aObjects.size() > 0) { + foreach(ModuleBase_ViewerPrs aPrs, aObjects) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object()); + if (aFeature) + myEditingFeatures.append(aFeature); + } + } + // If nothing highlighted - return + if (myEditingFeatures.size() == 0) + return; + + if (isSketcher) { + CompositeFeaturePtr aSketch = + std::dynamic_pointer_cast(aOperation->feature()); + if (!PartSet_Tools::sketchPlane(aSketch)) + return; + + //myCurrentSketch = aOperation->feature(); + myIsDragging = true; + get2dPoint(theWnd, theEvent, myCurX, myCurY); + myDragDone = false; + myWorkshop->viewer()->enableSelection(false); + + launchEditing(); + + } else if (isSketchOpe && isEditing) { + aOperation->abort(); + + //myCurrentSketch = aOperation->parentFeature(); + myIsDragging = true; + get2dPoint(theWnd, theEvent, myCurX, myCurY); + myDragDone = false; + myWorkshop->viewer()->enableSelection(false); + + QTimer::singleShot(10, this, SLOT(launchEditing())); } } - sendOperation(anOperation); - xWorkshop()->actionsMgr()->updateCheckState(); } -void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) -{ - ModuleBase_IViewer* aViewer = myWorkshop->viewer(); - aViewer->enableMultiselection(theEnabled); -} -void PartSet_Module::onStopSelection(const QList& theFeatures, const bool isStop) +void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, + double& theX, double& theY) { - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - //if (!isStop) { - // foreach(ObjectPtr aObject, theFeatures) { - // activateFeature(aObject); - // } - //} - aDisplayer->stopSelection(theFeatures, isStop, false); - - ModuleBase_IViewer* aViewer = myWorkshop->viewer(); - aViewer->enableSelection(!isStop); - - aDisplayer->updateViewer(); + Handle(V3d_View) aView = theWnd->v3dView(); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); + PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY); } -void PartSet_Module::onSetSelection(const QList& theFeatures) + +void PartSet_Module::launchEditing() { - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - aDisplayer->setSelected(theFeatures, false); - aDisplayer->updateViewer(); + if (myEditingFeatures.size() == 1) { + FeaturePtr aFeature = myEditingFeatures.first(); + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aFeature); + if (aSPFeature) { + editFeature(aSPFeature); + } + } } -void PartSet_Module::setSketchingMode(const gp_Pln& thePln) +void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - if (!myPlaneFilter.IsNull()) { - aDisplayer->removeSelectionFilter(myPlaneFilter); - myPlaneFilter.Nullify(); + if (myIsDragging) { + myIsDragging = false; + myWorkshop->viewer()->enableSelection(true); + if (myDragDone) + myWorkshop->currentOperation()->commit(); } - QIntList aModes; - // Clear standard selection modes - aDisplayer->setSelectionModes(aModes); - aDisplayer->openLocalContext(); - - // Set filter - mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln); - aDisplayer->addSelectionFilter(mySketchFilter); - - // Get default selection modes - aModes = sketchSelectionModes(ObjectPtr()); - aDisplayer->activateObjectsOutOfContext(aModes); } -void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode) + +void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { - bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide; - ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation(); - PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); - if (aPrevOp) { - std::list aList = aPrevOp->subFeatures(); - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - QIntList aModes = sketchSelectionModes(aPrevOp->feature()); - std::list::iterator aSFIt; - for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) { - std::list aResults = (*aSFIt)->results(); - std::list::iterator aIt; - for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { - if (!isDisplay) - aDisplayer->erase((*aIt), false); + if (myIsDragging) { + Handle(V3d_View) aView = theWnd->v3dView(); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); + double aX, aY; + PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY); + double dX = myCurX - aX; + double dY = myCurY - aY; + + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + QList aWidgets = aPanel->modelWidgets(); + foreach(ModuleBase_ModelWidget* aWgt, aWidgets) { + PartSet_WidgetPoint2D* aWgt2d = dynamic_cast(aWgt); + if (aWgt2d) { + aWgt2d->setPoint(aWgt2d->x() - dX, aWgt2d->y() - dY); } - if (!isDisplay) - aDisplayer->erase((*aSFIt), false); } - //aDisplayer->deactivateObjectsOutOfContext(); + myDragDone = true; + myCurX = aX; + myCurY = aY; } - if (isDisplay) - ModelAPI_EventCreator::get()->sendUpdated( - theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); } -ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId, - const std::string& theFeatureKind) -{ - // create the operation - ModuleBase_Operation* anOperation = 0; - if (theCmdId == PartSet_OperationSketch::Type()) { - anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this); - } else { - ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation(); - CompositeFeaturePtr aSketch; - PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); - if (aPrevOp) { - aSketch = aPrevOp->sketch(); - } - if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) { - anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch); - } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) { - anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch); - } - } - if (!anOperation) { - anOperation = new ModuleBase_Operation(theCmdId.c_str(), this); - } +QStringList PartSet_Module::sketchOperationIdList() const +{ + QStringList aIds; + aIds << SketchPlugin_Sketch::ID().c_str(); + aIds << SketchPlugin_Line::ID().c_str(); + aIds << SketchPlugin_Point::ID().c_str(); + aIds << SketchPlugin_Arc::ID().c_str(); + aIds << SketchPlugin_Circle::ID().c_str(); + return aIds; +} - // set operation description and list of widgets corresponding to the feature xml definition - std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind; - - std::string aPluginFileName = featureFile(aFeatureKind); - Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); - aWdgReader.readAll(); - std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind); - std::string aDescription = aWdgReader.featureDescription(aFeatureKind); - - anOperation->getDescription()->setDescription(QString::fromStdString(aDescription)); - anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); - - // connect the operation - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this, - SLOT(onFeatureConstructed(ObjectPtr, int))); - connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this, - SLOT(onRestartOperation(std::string, ObjectPtr))); - // If manage multi selection the it will be impossible to select more then one - // object under operation Edit -// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this, -// SLOT(onMultiSelectionEnabled(bool))); - - connect(aPreviewOp, SIGNAL(stopSelection(const QList&, const bool)), this, - SLOT(onStopSelection(const QList&, const bool))); - connect(aPreviewOp, SIGNAL(setSelection(const QList&)), this, - SLOT(onSetSelection(const QList&))); - - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); - if (aSketchOp) { - connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this, - SLOT(onPlaneSelected(double, double, double))); - connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView())); - connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched())); +void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape) +{ + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) { + /// If last line finished on vertex the lines creation sequence has to be break + ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + const QList& aWidgets = aPanel->modelWidgets(); + if (aWidgets.last() == aPanel->activeWidget()) { + breakOperationSequence(); + PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast(aPanel->activeWidget()); + PartSet_Tools::setConstraints(myCurrentSketch, aOperation->feature(), + SketchPlugin_Line::END_ID(), aPnt2dWgt->x(), aPnt2dWgt->y()); } } - - return anOperation; } -void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) -{ - ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - if (!anOperation) - return; +//void PartSet_Module::featureCreated(QAction* theFeature) +//{ +// connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered())); +//} - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (!aPreviewOp) - return; +//std::string PartSet_Module::featureFile(const std::string& theFeatureId) +//{ +// return myFeaturesInFiles[theFeatureId]; +//} - FeaturePtr aFeature = aPreviewOp->feature(); - if (!aFeature || aFeature->getKind() != theCmdId) - return; +/* + * + */ +//void PartSet_Module::onFeatureTriggered() +//{ +// QAction* aCmd = dynamic_cast(sender()); +// //Do nothing on uncheck +// if (aCmd->isCheckable() && !aCmd->isChecked()) +// return; +// launchOperation(aCmd->data().toString()); +//} + + +//void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation) +//{ +// XGUI_Workshop* aXWshp = xWorkshop(); +// XGUI_Displayer* aDisplayer = aXWshp->displayer(); +// PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); +// if (aPreviewOp) { +// XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel(); +// connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this, +// SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection); +// +// //aDisplayer->deactivateObjectsOutOfContext(); +// PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); +// if (aSketchOp) { +// if (aSketchOp->isEditOperation()) { +// setSketchingMode(getSketchPlane(aSketchOp->feature())); +// } else { +// aDisplayer->openLocalContext(); +// aDisplayer->activateObjectsOutOfContext(QIntList()); +// myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane); +// aDisplayer->addSelectionFilter(myPlaneFilter); +// QIntList aModes = sketchSelectionModes(aPreviewOp->feature()); +// aDisplayer->setSelectionModes(aModes); +// } +// } +// } +//} + +//void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) +//{ +// if (!theOperation) +// return; +// XGUI_Workshop* aXWshp = xWorkshop(); +// XGUI_Displayer* aDisplayer = aXWshp->displayer(); +// PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); +// if (aPreviewOp) { +// XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel(); +// +// PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); +// if (aSketchOp) { +// aDisplayer->closeLocalContexts(); +// } else { +// PartSet_OperationFeatureCreate* aCreationOp = +// dynamic_cast(aPreviewOp); +// if (aCreationOp) { +// // Activate just created object for selection +// FeaturePtr aFeature = aCreationOp->feature(); +// QIntList aModes = sketchSelectionModes(aFeature); +// const std::list& aResults = aFeature->results(); +// std::list::const_iterator anIt, aLast = aResults.end(); +// for (anIt = aResults.begin(); anIt != aLast; anIt++) { +// aDisplayer->activate(*anIt, aModes); +// } +// aDisplayer->activate(aFeature, aModes); +// aDisplayer->clearSelected(); +// } +// } +// }// else { +// // Activate results of current feature for selection +// //FeaturePtr aFeature = theOperation->feature(); +// //XGUI_Displayer* aDisplayer = aXWshp->displayer(); +// //std::list aResults = aFeature->results(); +// //std::list::const_iterator aIt; +// //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { +// // aDisplayer->activate(*aIt); +// //} +// //} +//} + +//void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked) +//{ +// QList aFeatures = workshop()->selection()->selectedObjects(); +// if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) { +// FeaturePtr aFeature = std::dynamic_pointer_cast(aFeatures.first()); +// if (aFeature) +// editFeature(aFeature); +// } +//} + +//void PartSet_Module::onMousePressed(QMouseEvent* theEvent) +//{ +// XGUI_Workshop* aXWshp = xWorkshop(); +// PartSet_OperationSketchBase* aPreviewOp = +// dynamic_cast(workshop()->currentOperation()); +// if (aPreviewOp) { +// ModuleBase_ISelection* aSelection = workshop()->selection(); +// aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection); +// } +//} + +//void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) +//{ +// PartSet_OperationSketchBase* aPreviewOp = +// dynamic_cast(myWorkshop->currentOperation()); +// if (aPreviewOp) { +// ModuleBase_ISelection* aSelection = workshop()->selection(); +// // Initialise operation with preliminary selection +// aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection); +// } +//} + +//void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) +//{ +// PartSet_OperationSketchBase* aPreviewOp = +// dynamic_cast(myWorkshop->currentOperation()); +// if (aPreviewOp) +// aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()); +//} + +//void PartSet_Module::onKeyRelease(QKeyEvent* theEvent) +//{ +// ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); +// PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); +// if (aPreviewOp) { +// aPreviewOp->keyReleased(theEvent->key()); +// } +//} + +//void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent) +//{ +// PartSet_OperationSketchBase* aPreviewOp = +// dynamic_cast(myWorkshop->currentOperation()); +// Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); +// if (aPreviewOp && (!aView.IsNull())) { +// ModuleBase_ISelection* aSelection = workshop()->selection(); +// // Initialise operation with preliminary selection +// aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection); +// } +//} + +//void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) +//{ +// myWorkshop->viewer()->setViewProjection(theX, theY, theZ); +//} + +//void PartSet_Module::onSketchLaunched() +//{ +// xWorkshop()->actionsMgr()->update(); +// // Set working plane +// ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); +// FeaturePtr aSketch = anOperation->feature(); +// setSketchingMode(getSketchPlane(aSketch)); +//} + +//void PartSet_Module::onFitAllView() +//{ +// myWorkshop->viewer()->fitAll(); +//} + +//void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject) +//{ +// FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); +// +// std::string aKind = aFeature ? aFeature->getKind() : ""; +// ModuleBase_Operation* anOperation = createOperation(theName, aKind); +// +// PartSet_OperationSketchBase* aSketchOp = dynamic_cast(anOperation); +// if (aSketchOp) { +// PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast(anOperation); +// if (aCreateOp) +// aCreateOp->initFeature(aFeature); +// else { +// anOperation->setFeature(aFeature); +// } +// ModuleBase_ISelection* aSelection = workshop()->selection(); +// // Initialise operation with preliminary selection +// aSketchOp->initSelection(aSelection, myWorkshop->viewer()); +// } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation +// anOperation->setFeature(aFeature); +// ////Deactivate result of current feature in order to avoid its selection +// XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); +// std::list aResults = aFeature->results(); +// std::list::const_iterator aIt; +// for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { +// aDisplayer->deactivate(*aIt); +// } +// } +// sendOperation(anOperation); +// xWorkshop()->actionsMgr()->updateCheckState(); +//} + +//void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) +//{ +// ModuleBase_IViewer* aViewer = myWorkshop->viewer(); +// aViewer->enableMultiselection(theEnabled); +//} + +//void PartSet_Module::onStopSelection(const QList& theFeatures, const bool isStop) +//{ +// XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); +// //if (!isStop) { +// // foreach(ObjectPtr aObject, theFeatures) { +// // activateFeature(aObject); +// // } +// //} +// aDisplayer->stopSelection(theFeatures, isStop, false); +// +// ModuleBase_IViewer* aViewer = myWorkshop->viewer(); +// aViewer->enableSelection(!isStop); +// +// aDisplayer->updateViewer(); +//} + +//void PartSet_Module::onSetSelection(const QList& theFeatures) +//{ +// XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); +// aDisplayer->setSelected(theFeatures, false); +// aDisplayer->updateViewer(); +//} + +//void PartSet_Module::setSketchingMode(const gp_Pln& thePln) +//{ +// XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); +// if (!myPlaneFilter.IsNull()) { +// aDisplayer->removeSelectionFilter(myPlaneFilter); +// myPlaneFilter.Nullify(); +// } +// QIntList aModes; +// // Clear standard selection modes +// aDisplayer->setSelectionModes(aModes); +// aDisplayer->openLocalContext(); +// +// // Set filter +// mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln); +// aDisplayer->addSelectionFilter(mySketchFilter); +// +// // Get default selection modes +// aModes = sketchSelectionModes(ObjectPtr()); +// aDisplayer->activateObjectsOutOfContext(aModes); +//} + +//void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode) +//{ +// bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide; +// ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation(); +// PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); +// if (aPrevOp) { +// std::list aList = aPrevOp->subFeatures(); +// XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); +// QIntList aModes = sketchSelectionModes(aPrevOp->feature()); +// std::list::iterator aSFIt; +// for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) { +// std::list aResults = (*aSFIt)->results(); +// std::list::iterator aIt; +// for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { +// if (!isDisplay) +// aDisplayer->erase((*aIt), false); +// } +// if (!isDisplay) +// aDisplayer->erase((*aSFIt), false); +// } +// //aDisplayer->deactivateObjectsOutOfContext(); +// } +// if (isDisplay) +// ModelAPI_EventCreator::get()->sendUpdated( +// theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); +//} + +//ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId, +// const std::string& theFeatureKind) +//{ +// // create the operation +// ModuleBase_Operation* anOperation = 0; +// if (theCmdId == PartSet_OperationSketch::Type()) { +// anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this); +// } else { +// ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation(); +// CompositeFeaturePtr aSketch; +// PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); +// if (aPrevOp) { +// aSketch = aPrevOp->sketch(); +// } +// if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) { +// anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch); +// } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) { +// anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch); +// } +// } +// +// if (!anOperation) { +// anOperation = new ModuleBase_Operation(theCmdId.c_str(), this); +// } +// +// // set operation description and list of widgets corresponding to the feature xml definition +// std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind; +// +// std::string aPluginFileName = featureFile(aFeatureKind); +// Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); +// aWdgReader.readAll(); +// std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind); +// std::string aDescription = aWdgReader.featureDescription(aFeatureKind); +// +// anOperation->getDescription()->setDescription(QString::fromStdString(aDescription)); +// anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); +// +// // connect the operation +// PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); +// if (aPreviewOp) { +// connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this, +// SLOT(onFeatureConstructed(ObjectPtr, int))); +// connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this, +// SLOT(onRestartOperation(std::string, ObjectPtr))); +// // If manage multi selection the it will be impossible to select more then one +// // object under operation Edit +//// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this, +//// SLOT(onMultiSelectionEnabled(bool))); +// +// connect(aPreviewOp, SIGNAL(stopSelection(const QList&, const bool)), this, +// SLOT(onStopSelection(const QList&, const bool))); +// connect(aPreviewOp, SIGNAL(setSelection(const QList&)), this, +// SLOT(onSetSelection(const QList&))); +// +// PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); +// if (aSketchOp) { +// connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this, +// SLOT(onPlaneSelected(double, double, double))); +// connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView())); +// connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched())); +// } +// } +// +// return anOperation; +//} + + +//void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) +//{ +// ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); +// if (!anOperation) +// return; +// +// PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); +// if (!aPreviewOp) +// return; +// +// FeaturePtr aFeature = aPreviewOp->feature(); +// if (!aFeature || aFeature->getKind() != theCmdId) +// return; +// +// XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); +// // Hide result of sketch +// std::list aResults = aFeature->results(); +// std::list::const_iterator aIt; +// for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) +// aDisplayer->erase(*aIt, false); +// +// std::list aList = aPreviewOp->subFeatures(); +// +// std::list::const_iterator anIt = aList.begin(), aLast = aList.end(); +// for (; anIt != aLast; anIt++) { +// std::shared_ptr aSPFeature = std::dynamic_pointer_cast< +// SketchPlugin_Feature>(*anIt); +// if (!aSPFeature) +// continue; +// std::list aResults = aSPFeature->results(); +// std::list::const_iterator aRIt; +// for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) { +// aDisplayer->display((*aRIt), false); +// aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt))); +// } +// aDisplayer->display(aSPFeature, false); +// aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature)); +// } +// aDisplayer->updateViewer(); +//} - XGUI_Displayer* aDisplayer = xWorkshop()->displayer(); - // Hide result of sketch - std::list aResults = aFeature->results(); - std::list::const_iterator aIt; - for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) - aDisplayer->erase(*aIt, false); - - std::list aList = aPreviewOp->subFeatures(); - - std::list::const_iterator anIt = aList.begin(), aLast = aList.end(); - for (; anIt != aLast; anIt++) { - std::shared_ptr aSPFeature = std::dynamic_pointer_cast< - SketchPlugin_Feature>(*anIt); - if (!aSPFeature) - continue; - std::list aResults = aSPFeature->results(); - std::list::const_iterator aRIt; - for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) { - aDisplayer->display((*aRIt), false); - aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt))); - } - aDisplayer->display(aSPFeature, false); - aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature)); - } - aDisplayer->updateViewer(); -} - -void PartSet_Module::editFeature(FeaturePtr theFeature) -{ - if (!theFeature) - return; +//void PartSet_Module::editFeature(FeaturePtr theFeature) +//{ +// if (!theFeature) +// return; // if (theFeature->getKind() == SKETCH_KIND) { //FeaturePtr aFeature = theFeature; @@ -510,103 +825,122 @@ void PartSet_Module::editFeature(FeaturePtr theFeature) //} //if (aFeature) { - onRestartOperation(theFeature->getKind(), theFeature); - updateCurrentPreview(theFeature->getKind()); +// onRestartOperation(theFeature->getKind(), theFeature); +// updateCurrentPreview(theFeature->getKind()); //} // } -} - -void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute) -{ - FeaturePtr aFeature = std::dynamic_pointer_cast(theFeature); - - PartSet_OperationSketchBase* aPreviewOp = - dynamic_cast(myWorkshop->currentOperation()); - if (!aPreviewOp) - return; - - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aFeature->data()->attribute(theAttribute)); - - PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(), - aPoint->y()); -} +//} + +//void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute) +//{ +// FeaturePtr aFeature = std::dynamic_pointer_cast(theFeature); +// +// PartSet_OperationSketchBase* aPreviewOp = +// dynamic_cast(myWorkshop->currentOperation()); +// if (!aPreviewOp) +// return; +// +// std::shared_ptr aPoint = std::dynamic_pointer_cast( +// aFeature->data()->attribute(theAttribute)); +// +// PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(), +// aPoint->y()); +//} QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, - Config_WidgetAPI* theWidgetApi, + Config_WidgetAPI* theWidgetApi, std::string theParentId, QList& theModelWidgets) { + XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); if (theType == "sketch-start-label") { - PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, ""); - aWgt->setOperationsMgr(xWorkshop()->operationMgr()); + PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId); + aWgt->setWorkshop(aWorkshop); theModelWidgets.append(aWgt); return aWgt->getControl(); - } else - return 0; -} + } else if (theType == "sketch-2dpoint_selector") { + PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId); + aWgt->setWorkshop(aWorkshop); + aWgt->setSketch(myCurrentSketch); + connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)), + this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&))); -XGUI_Workshop* PartSet_Module::xWorkshop() const -{ - XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); - if (aConnector) { - return aConnector->workshop(); - } - return 0; -} - - -QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature) -{ - QIntList aModes; - FeaturePtr aFeature = std::dynamic_pointer_cast(theFeature); - if (aFeature) { - if (aFeature->getKind() == SketchPlugin_Sketch::ID()) { - aModes.append(TopAbs_FACE); - return aModes; - } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) { - aModes.append(AIS_DSM_Text); - aModes.append(AIS_DSM_Line); - return aModes; - } - } - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); - return aModes; -} - + theModelWidgets.append(aWgt); + return aWgt->getControl(); + } if (theType == "point2ddistance") { + PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId); + aWgt->setWorkshop(aWorkshop); + aWgt->setSketch(myCurrentSketch); -gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const -{ - DataPtr aData = theSketch->data(); - std::shared_ptr anOrigin = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aNorm = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::NORM_ID())); - gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z()); - gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z()); - return gp_Pln(aOrig, aDir); + theModelWidgets.append(aWgt); + return aWgt->getControl(); + }else + return 0; } -void PartSet_Module::onSelectionChanged() -{ - ModuleBase_ISelection* aSelect = myWorkshop->selection(); - QList aSelected = aSelect->getSelected(); - // We need to stop edit operation if selection is cleared - if (aSelected.size() == 0) { - // do not perform commit of the current edit operation here, because - // this functionality is realized inside this operation - /*PartSet_OperationFeatureEdit* anEditOp = - dynamic_cast(myWorkshop->currentOperation()); - if (!anEditOp) - return; - anEditOp->commit();*/ - } else { - PartSet_OperationSketchBase* aSketchOp = - dynamic_cast(myWorkshop->currentOperation()); - if (aSketchOp) { - aSketchOp->selectionChanged(aSelect); - } - } -} +//XGUI_Workshop* PartSet_Module::xWorkshop() const +//{ +// XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); +// if (aConnector) { +// return aConnector->workshop(); +// } +// return 0; +//} + + +//QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature) +//{ +// QIntList aModes; +// FeaturePtr aFeature = std::dynamic_pointer_cast(theFeature); +// if (aFeature) { +// if (aFeature->getKind() == SketchPlugin_Sketch::ID()) { +// aModes.append(TopAbs_FACE); +// return aModes; +// } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) { +// aModes.append(AIS_DSM_Text); +// aModes.append(AIS_DSM_Line); +// return aModes; +// } +// } +// aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); +// aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); +// return aModes; +//} + + +//gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const +//{ +// DataPtr aData = theSketch->data(); +// std::shared_ptr anOrigin = std::dynamic_pointer_cast( +// aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); +// std::shared_ptr aNorm = std::dynamic_pointer_cast( +// aData->attribute(SketchPlugin_Sketch::NORM_ID())); +// gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z()); +// gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z()); +// return gp_Pln(aOrig, aDir); +//} + + +//void PartSet_Module::onSelectionChanged() +//{ +// ModuleBase_ISelection* aSelect = myWorkshop->selection(); +// QList aSelected = aSelect->getSelected(); +// // We need to stop edit operation if selection is cleared +// if (aSelected.size() == 0) { +// // do not perform commit of the current edit operation here, because +// // this functionality is realized inside this operation +// /*PartSet_OperationFeatureEdit* anEditOp = +// dynamic_cast(myWorkshop->currentOperation()); +// if (!anEditOp) +// return; +// anEditOp->commit();*/ +// } else { +// PartSet_OperationSketchBase* aSketchOp = +// dynamic_cast(myWorkshop->currentOperation()); +// if (aSketchOp) { +// aSketchOp->selectionChanged(aSelect); +// } +// } +//} diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index b42c1a93d..3e6a7d2a0 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -8,7 +8,10 @@ #include #include #include +#include + #include +#include #include #include @@ -17,12 +20,8 @@ #include -class PartSet_Listener; -class ModelAPI_Feature; -class XGUI_ViewerPrs; -class XGUI_Workshop; class ModuleBase_Operation; -class GeomAPI_AISObject; +class ModuleBase_IViewWindow; class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule { @@ -33,12 +32,12 @@ Q_OBJECT virtual ~PartSet_Module(); /// Reads description of features from XML file - virtual void createFeatures(); + //virtual void createFeatures(); /// Called on creation of menu item in desktop - virtual void featureCreated(QAction* theFeature); + //virtual void featureCreated(QAction* theFeature); - std::string featureFile(const std::string&); + //std::string featureFile(const std::string&); /// Creates an operation and send it to loop /// \param theCmdId the operation name @@ -46,119 +45,160 @@ Q_OBJECT /// Updates current operation preview, if it has it. /// \param theCmdId the operation name - void updateCurrentPreview(const std::string& theCmdId); + //void updateCurrentPreview(const std::string& theCmdId); /// Creates custom widgets for property panel virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent, - Config_WidgetAPI* theWidgetApi, + Config_WidgetAPI* theWidgetApi, std::string theParentId, QList& theModelWidgets); - XGUI_Workshop* xWorkshop() const; + //XGUI_Workshop* xWorkshop() const; /// Returns list of selection modes for the given object for sketch operation - static QIntList sketchSelectionModes(ObjectPtr theFeature); + //static QIntList sketchSelectionModes(ObjectPtr theFeature); + + /// Call back forlast tuning of property panel before operation performance + virtual void propertyPanelDefined(ModuleBase_Operation* theOperation); + + QStringList sketchOperationIdList() const; public slots: - void onFeatureTriggered(); + //void onFeatureTriggered(); /// SLOT, that is called after the operation is started. Connect on the focus activated signal - void onOperationStarted(ModuleBase_Operation* theOperation); + //void onOperationStarted(ModuleBase_Operation* theOperation); /// SLOT, that is called after the operation is stopped. Switched off the modfications performed /// by the operation start - void onOperationStopped(ModuleBase_Operation* theOperation); + //void onOperationStopped(ModuleBase_Operation* theOperation); /// SLOT, that is called afetr the popup menu action clicked. - void onContextMenuCommand(const QString& theId, bool isChecked); + //void onContextMenuCommand(const QString& theId, bool isChecked); /// SLOT, to apply to the current viewer the operation /// \param theX the X projection value /// \param theY the Y projection value /// \param theZ the Z projection value - void onPlaneSelected(double theX, double theY, double theZ); + //void onPlaneSelected(double theX, double theY, double theZ); /// SLOT, to fit all current viewer - void onFitAllView(); + //void onFitAllView(); - void onRestartOperation(std::string theName, ObjectPtr theFeature); + //void onRestartOperation(std::string theName, ObjectPtr theFeature); /// SLOT, to switch on/off the multi selection in the viewer /// \param theEnabled the enabled state - void onMultiSelectionEnabled(bool theEnabled); + //void onMultiSelectionEnabled(bool theEnabled); /// SLOT, to stop or start selection mode for the features /// \param theFeatures a list of features to be disabled /// \param theToStop the boolean state whether it it stopped or non stopped - void onStopSelection(const QList& theFeatures, const bool isStop); + //void onStopSelection(const QList& theFeatures, const bool isStop); /// SLOT, to set selection /// \param theFeatures a list of features to be selected - void onSetSelection(const QList& theFeatures); + //void onSetSelection(const QList& theFeatures); /// SLOT, Defines Sketch editing mode /// \param thePln - plane of current sketch - void setSketchingMode(const gp_Pln& thePln); + //void setSketchingMode(const gp_Pln& thePln); /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode /// \param theMode the mode appeared on the feature - void onFeatureConstructed(ObjectPtr theFeature, int theMode); + //void onFeatureConstructed(ObjectPtr theFeature, int theMode); /// Slot which reacts to the point 2d set to the feature. Creates a constraint /// \param the feature /// \param the attribute of the feature - void onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute); + //void onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute); /// Called when sketch is launched - void onSketchLaunched(); + //void onSketchLaunched(); protected slots: - /// Called on selection changed event + /// Called when previous operation is finished + virtual void onOperationComitted(ModuleBase_Operation* theOperation); + + virtual void onOperationAborted(ModuleBase_Operation* theOperation); + + virtual void onOperationStarted(ModuleBase_Operation* theOperation); + + virtual void onOperationStopped(ModuleBase_Operation* theOperation); + + /// Called when previous operation is finished virtual void onSelectionChanged(); + /// Called on selection changed event + //virtual void onSelectionChanged(); + /// SLOT, that is called by mouse press in the viewer. /// The mouse released point is sent to the current operation to be processed. /// \param theEvent the mouse event - virtual void onMousePressed(QMouseEvent* theEvent); + void onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); /// SLOT, that is called by mouse release in the viewer. /// The mouse released point is sent to the current operation to be processed. /// \param theEvent the mouse event - virtual void onMouseReleased(QMouseEvent* theEvent); + virtual void onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); /// SLOT, that is called by mouse move in the viewer. /// The mouse moved point is sent to the current operation to be processed. /// \param theEvent the mouse event - virtual void onMouseMoved(QMouseEvent* theEvent); + virtual void onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); /// SLOT, that is called by the mouse double click in the viewer. /// \param theEvent the mouse event - virtual void onMouseDoubleClick(QMouseEvent* theEvent); + //virtual void onMouseDoubleClick(QMouseEvent* theEvent); /// SLOT, that is called by the key in the viewer is clicked. /// \param theEvent the mouse event - virtual void onKeyRelease(QKeyEvent* theEvent); + //virtual void onKeyRelease(QKeyEvent* theEvent); + + /// Launches the operation from current highlighting + void launchEditing(); protected: - /// Creates a new operation - /// \param theCmdId the operation name - /// \param theFeatureKind a kind of feature to get the feature xml description - ModuleBase_Operation* createOperation(const std::string& theCmdId, - const std::string& theFeatureKind = ""); + /// Register validators for this module + virtual void registerValidators(); + /// Returns new instance of operation object (used in createOperation for customization) + //virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId); - protected: //! Edits the feature - void editFeature(FeaturePtr theFeature); + //void editFeature(FeaturePtr theFeature); - gp_Pln getSketchPlane(FeaturePtr theSketch) const; + //gp_Pln getSketchPlane(FeaturePtr theSketch) const; + + private slots: + void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape); private: + /// Converts mouse position to 2d coordinates. + /// Member myCurrentSketch has to be correctly defined + void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, + double& theX, double& theY); + + /// Breaks sequense of automatically resterted operations + void breakOperationSequence(); + //XGUI_Workshop* myWorkshop; - PartSet_Listener* myListener; + //PartSet_Listener* myListener; + + //std::map myFeaturesInFiles; + + //Handle(StdSelect_FaceFilter) myPlaneFilter; + //Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter; + QString myLastOperationId; + FeaturePtr myLastFeature; + + bool myIsDragging; + bool myDragDone; - std::map myFeaturesInFiles; + // Automatical restarting mode flag + bool myRestartingMode; - Handle(StdSelect_FaceFilter) myPlaneFilter; - Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter; + double myCurX, myCurY; + CompositeFeaturePtr myCurrentSketch; + QList myEditingFeatures; }; #endif diff --git a/src/PartSet/PartSet_Operation.cpp b/src/PartSet/PartSet_Operation.cpp new file mode 100644 index 000000000..efe1c95c7 --- /dev/null +++ b/src/PartSet/PartSet_Operation.cpp @@ -0,0 +1,17 @@ +// File: PartSet_Operation.cpp +// Created: 24 Nov 2014 +// Author: Vitaly SMETANNIKOV + +#include "PartSet_Operation.h" + +#include +#include + +void PartSet_Operation::onSelectionChanged() +{ + if (isEditOperation()) { + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + QList aHighlighted = aSelection->getHighlighted(); + QList aSelected = aSelection->getSelected(); + } +} \ No newline at end of file diff --git a/src/PartSet/PartSet_Operation.h b/src/PartSet/PartSet_Operation.h new file mode 100644 index 000000000..cac4bdd28 --- /dev/null +++ b/src/PartSet/PartSet_Operation.h @@ -0,0 +1,30 @@ +// File: PartSet_Operation.h +// Created: 24 Nov 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef PartSet_Operation_H +#define PartSet_Operation_H + +#include "PartSet.h" + +#include + +class ModuleBase_IWorkshop; + +class PARTSET_EXPORT PartSet_Operation : public ModuleBase_Operation +{ +Q_OBJECT + public: + PartSet_Operation(const QString& theId = "", QObject* theParent = 0) + :ModuleBase_Operation(theId, theParent) {} + + void setWorkshop(ModuleBase_IWorkshop* theWorkshop) { myWorkshop = theWorkshop; } + +public slots: + void onSelectionChanged(); + +private: + ModuleBase_IWorkshop* myWorkshop; +}; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_OperationFeatureBase.cpp b/src/PartSet/PartSet_OperationFeatureBase.cpp deleted file mode 100644 index 65689f2e6..000000000 --- a/src/PartSet/PartSet_OperationFeatureBase.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// File: PartSet_OperationFeatureBase.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include "ModuleBase_IPropertyPanel.h" -#include "ModuleBase_ISelection.h" -#include "ModuleBase_IViewer.h" - -#include - -#include -#include - -#ifdef _DEBUG -#include -#include -#endif - -#include - -using namespace std; - -PartSet_OperationFeatureBase::PartSet_OperationFeatureBase(const QString& theId, - QObject* theParent, - CompositeFeaturePtr theFeature) - : PartSet_OperationSketchBase(theId, theParent), - mySketch(theFeature) -{ -} - -PartSet_OperationFeatureBase::~PartSet_OperationFeatureBase() -{ -} - -CompositeFeaturePtr PartSet_OperationFeatureBase::sketch() const -{ - return mySketch; -} - -void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection) -{ - Handle(V3d_View) aView = theViewer->activeView(); - gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - double aX = aPoint.X(), anY = aPoint.Y(); - QList aSelected = theSelection->getSelected(); - - if (aSelected.empty()) { - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - } else { - ModuleBase_ViewerPrs aPrs = aSelected.first(); - if (getViewerPoint(aPrs, theViewer, aX, anY)) { - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); - } - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - } - } - ObjectPtr aFeature; - if (!aSelected.empty()) { - ModuleBase_ViewerPrs aPrs = aSelected.first(); - aFeature = aPrs.object(); - } else { - aFeature = feature(); // for the widget distance only - } - - bool isApplyed = setWidgetValue(aFeature, aX, anY); - if (isApplyed) { - flushUpdated(); - myPropertyPanel->activateNextWidget(); - } - // the operation can be committed only when there is no an active widget anymore - // if this check is absent, the edit operation for constraint perpendicular is stopped - // after the first object selection in the viewer(there are two objects to be selected) - // the second case is the constraint distance, the edit is stopped after any mouse click - // in the viewer whenever it is applyed or not to the selection control - if (!myPropertyPanel->activeWidget()) - commit(); -} - -bool PartSet_OperationFeatureBase::getViewerPoint(ModuleBase_ViewerPrs thePrs, - ModuleBase_IViewer* theViewer, - double& theX, double& theY) -{ - return PartSet_Tools::hasVertexShape(thePrs, sketch(), theViewer->activeView(), - theX, theY); -} - -/*bool PartSet_OperationFeatureBase::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(std::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); - 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 deleted file mode 100644 index ee290dd44..000000000 --- a/src/PartSet/PartSet_OperationFeatureBase.h +++ /dev/null @@ -1,63 +0,0 @@ -// File: PartSet_OperationFeatureBase.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PARTSET_OPERATIONFEATUREBASE_H -#define PARTSET_OPERATIONFEATUREBASE_H - -#include "PartSet.h" - -#include -#include - -#include - -class GeomDataAPI_Point2D; -class QMouseEvent; -class QKeyEvent; - -/*! - \class PartSet_OperationFeatureBase - * \brief The operation for the sketch feature creation - */ -class PARTSET_EXPORT PartSet_OperationFeatureBase : public PartSet_OperationSketchBase -{ -Q_OBJECT - - public: - /// Constructor - /// \param theId the feature identifier - /// \param theParent the operation parent - /// \param theSketch the parent feature - PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch); - /// Destructor - virtual ~PartSet_OperationFeatureBase(); - - /// Returns the operation sketch feature - /// \returns the sketch instance - virtual CompositeFeaturePtr sketch() const; - - /// Gives the current selected objects to be processed by the operation - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection); - - protected: - /// Return a widget value point by the selection and the viewer position - /// \param thePrs the presentation - /// \param theViewer a viewer to have the viewer the eye position - /// \param theX the horizontal coordinate - /// \param theY the vertical coordinate - /// \return true if the point exits in the selection - virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs, - ModuleBase_IViewer* theViewer, - double& theX, double& theY); - - protected: - CompositeFeaturePtr mySketch; ///< the sketch of the feature -}; - -#endif diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp deleted file mode 100644 index 8e18b6754..000000000 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ /dev/null @@ -1,195 +0,0 @@ -// File: PartSet_OperationFeatureCreate.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#ifdef _DEBUG -#include -#include -#endif - -#include - -using namespace std; - -PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId, - QObject* theParent, - CompositeFeaturePtr theFeature) - : PartSet_OperationFeatureBase(theId, theParent, theFeature) -{ -} - -PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate() -{ -} - -bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId) -{ - return theId == SketchPlugin_Line::ID() || theId == SketchPlugin_Point::ID() - || theId == SketchPlugin_Circle::ID() || theId == SketchPlugin_Arc::ID() - || theId == SketchPlugin_ConstraintDistance::ID() - || theId == SketchPlugin_ConstraintLength::ID() - || theId == SketchPlugin_ConstraintRadius::ID() - || theId == SketchPlugin_ConstraintParallel::ID() - || theId == SketchPlugin_ConstraintPerpendicular::ID() - || theId == SketchPlugin_ConstraintCoincidence::ID() - || theId == SketchPlugin_ConstraintRigid::ID(); -} - -void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) -{ - double aX, anY; - Handle(V3d_View) aView = theViewer->activeView(); - gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - setWidgetValue(feature(), aX, anY); - flushUpdated(); -} - -void PartSet_OperationFeatureCreate::keyReleased(const int theKey) -{ - switch (theKey) { - case Qt::Key_Return: - case Qt::Key_Enter: { - // it start a new line creation at a free point - if(isValid()) - restartOperation(feature()->getKind()); - } - break; - default: - break; - } -} - -void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection) -{ - Handle(V3d_View) aView = theViewer->activeView(); - gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - double aX = aPoint.X(), anY = aPoint.Y(); - bool isClosedContour = false; - - QList aSelected = theSelection->getSelected(); - - if (aSelected.empty()) { - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - } else { - ModuleBase_ViewerPrs aPrs = aSelected.first(); - if (getViewerPoint(aPrs, theViewer, aX, anY)) { - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); - isClosedContour = true; - } - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected - ObjectPtr aObject = aPrs.object(); - if (sketch()->isSub(aObject)) - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - else { - // we have to create the selected edge for the current sketch - ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch()); - aSelected.first().setFeature(aRes); - } - } - } - ObjectPtr aFeature; - if (!aSelected.empty()) { - ModuleBase_ViewerPrs aPrs = aSelected.first(); - aFeature = aPrs.object(); - } else { - aFeature = feature(); // for the widget distance only - } - - bool isApplyed = setWidgetValue(aFeature, aX, anY); - if (isApplyed) { - flushUpdated(); - myPropertyPanel->activateNextWidget(); - } - - 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 - restartOperation(feature()->getKind(), feature()); - } - } -} - -void PartSet_OperationFeatureCreate::startOperation() -{ - PartSet_OperationSketchBase::startOperation(); - //emit multiSelectionEnabled(false); -} - -void PartSet_OperationFeatureCreate::abortOperation() -{ - emit featureConstructed(feature(), FM_Hide); - PartSet_OperationSketchBase::abortOperation(); -} - -void PartSet_OperationFeatureCreate::stopOperation() -{ - PartSet_OperationSketchBase::stopOperation(); - //emit multiSelectionEnabled(true); -} - -void PartSet_OperationFeatureCreate::afterCommitOperation() -{ - PartSet_OperationSketchBase::afterCommitOperation(); - emit featureConstructed(feature(), FM_Deactivation); -} - -FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage, - CompositeFeaturePtr theCompositeFeature) -{ - FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch()); - - 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 deleted file mode 100644 index 45e29505e..000000000 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ /dev/null @@ -1,96 +0,0 @@ -// File: PartSet_OperationFeatureCreate.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PartSet_OperationFeatureCreate_H -#define PartSet_OperationFeatureCreate_H - -#include "PartSet.h" - -#include -#include - -#include - -class GeomDataAPI_Point2D; -class QMouseEvent; -class QKeyEvent; - -/*! - \class PartSet_OperationFeatureCreate - * \brief The operation for the sketch feature creation - */ -class PARTSET_EXPORT PartSet_OperationFeatureCreate : public PartSet_OperationFeatureBase -{ -Q_OBJECT - - public: - /// Returns true if the feature with the given kind can be created by this operation - /// \param theId the feature kind - /// \return the boolean result - static bool canProcessKind(const std::string& theId); - - /// Constructor - /// \param theId the feature identifier - /// \param theParent the operation parent - /// \param theSketch the parent feature - PartSet_OperationFeatureCreate( - const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch); - /// Destructor - virtual ~PartSet_OperationFeatureCreate(); - - /// Gives the current mouse point in the viewer - /// \param thePoint a point clicked in the viewer - /// \param theEvent the mouse event - virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer); - - /// Gives the current selected objects to be processed by the operation - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection); - /// Processes the key pressed in the view - /// \param theKey a key value - virtual void keyReleased(const int theKey); - - /// 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 - /// Virtual method called when operation started (see start() method for more description) - /// After the parent operation body perform, set sketch feature to the created line feature - virtual void startOperation(); - - /// Virtual method called when operation aborted (see abort() method for more description) - /// Before the feature is aborted, it should be hidden from the viewer - virtual void abortOperation(); - - /// Virtual method called when operation stopped - committed or aborted. - /// Restore the multi selection state - virtual void stopOperation(); - - /// Virtual method called after operation committed (see commit() method for more description) - virtual void afterCommitOperation(); - - /// Creates an operation new feature - /// In addition to the default realization it appends the created line feature to - /// the sketch feature - /// \param theFlushMessage the flag whether the create message should be flushed - /// \returns the created feature - virtual FeaturePtr createFeature(const bool theFlushMessage = true, - CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr()); - -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 deleted file mode 100644 index d44dfa3d7..000000000 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ /dev/null @@ -1,521 +0,0 @@ -// File: PartSet_OperationFeatureEdit.h -// Created: 05 May 2014 -// Author: Natalia ERMOLAEVA - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include - -#include - -#include - -#include -#include -#include - -#ifdef _DEBUG -#include -#endif - -#include - -using namespace std; - -PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId, - QObject* theParent, - CompositeFeaturePtr theFeature) - : PartSet_OperationFeatureBase(theId, theParent, theFeature), - myIsBlockedSelection(false), myIsBlockedByDoubleClick(false) -{ - myIsEditing = true; -} - -PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit() -{ -} - -void PartSet_OperationFeatureEdit::initSelection(ModuleBase_ISelection* theSelection, - ModuleBase_IViewer* theViewer) -{ - // the method of the parent should is useless here because it processes the given - // selection in different way - //PartSet_OperationFeatureBase::initSelection(theSelection, theViewer); - - QList aSelected = theSelection->getSelected(); - QList aHighlighted = theSelection->getHighlighted(); - - // there is a bug in OCC, where the highlighted objects are repeated and should be - // filtered on the unique state here - QList anUniqueHighlighted; - foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) { - if (!PartSet_Tools::isContainPresentation(anUniqueHighlighted, aPrs)) - anUniqueHighlighted.append(aPrs); - } - fillFeature2Attribute(anUniqueHighlighted, theViewer, myHighlightedFeature2Attribute); - - foreach (ModuleBase_ViewerPrs aPrs, anUniqueHighlighted) { - if (!PartSet_Tools::isContainPresentation(aSelected, aPrs)) - aSelected.append(aPrs); - } - fillFeature2Attribute(aSelected, theViewer, myAllFeature2Attribute); -} - -void PartSet_OperationFeatureEdit::fillFeature2Attribute( - const QList& thePresentations, - ModuleBase_IViewer* theViewer, - std::map >& theFeature2Attribute) -{ - // 1. find all features with skipping features with selected vertex shapes - theFeature2Attribute.clear(); - // firstly, collect the features without local selection - double aX, anY; - foreach (ModuleBase_ViewerPrs aPrs, thePresentations) { - if (getViewerPoint(aPrs, theViewer, aX, anY)) - continue; - else { - ObjectPtr aObject = aPrs.object(); - if (!aObject) - continue; - FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); - if (aFeature && theFeature2Attribute.find(aFeature) == theFeature2Attribute.end()) { - std::list aList; - // using an empty list as a sign, that this feature should be moved itself - theFeature2Attribute[aFeature] = aList; - } - } - } - // 2. collect the features with a local selection on them. - // if the list already has this feature, the local selection is skipped - // that means that if the selection contains a feature and a feature with local selected point, - // the edit is performed for a full feature - foreach (ModuleBase_ViewerPrs aPrs, thePresentations) { - if (getViewerPoint(aPrs, theViewer, aX, anY)) { - ObjectPtr aObject = aPrs.object(); - if (!aObject) - continue; - FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); - if (!aFeature) - continue; - - // append the attribute of the vertex if it is found on the current feature - std::shared_ptr aPoint2D = PartSet_Tools::getFeaturePoint( - aFeature, aX, anY); - std::string anAttribute = aFeature->data()->id(aPoint2D); - std::list aList; - if (theFeature2Attribute.find(aFeature) != theFeature2Attribute.end()) - aList = theFeature2Attribute[aFeature]; - - aList.push_back(anAttribute); - theFeature2Attribute[aFeature] = aList; - } - } -} - -void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) -{ - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - if(aActiveWgt && aActiveWgt->isViewerSelector()) { - // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased - PartSet_OperationFeatureBase::mousePressed(theEvent, theViewer, theSelection); - // the current point should be cleared because it is saved from the previous move and - // should be reinitialized after the start moving. It is important for example for the lenght - // constraint where the first widget is a viewer selector. - myCurPoint.clear(); - } - else { - // commit always until the selection restore is realized (for feature and local selection) - // TODO: check whether the selection is changed and restart the operation only if it is modified - commit(); - emitFeaturesDeactivation(); - // find nearest feature and restart the operation for it - Handle(V3d_View) aView = theViewer->activeView(); - QList aSelected = theSelection->getSelected(); - QList aHighlighted = theSelection->getHighlighted(); - - ObjectPtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, sketch(), - aSelected, aHighlighted); - if (aFeature) { - restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature); - } - } - // the next code is commented because the new attempt to commit/restart operation implementation: - //QList aSelected = theSelection->getSelected(); - //QList aHighlighted = theSelection->getHighlighted(); - //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); - //if (aHasShift && !aHighlighted.empty()) { - // foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) { - // aSelected.append(aPrs); - // } - //} - //ObjectPtr aObject; - ///*if (!aSelected.empty()) { - // aObject = aSelected.first().object(); - //} else { - // if (!aHighlighted.empty()) - // aObject = aHighlighted.first().object(); - //}*/ - //// the priority to a highlighted object in order to edit it, even if the selected object is - //// the feature of this operation. Otherwise, the highlighting is ignored and the selected - //// object is moved - //if (!aHighlighted.empty()) { - // aObject = aHighlighted.front().object(); - //} - //if (!aObject && !aSelected.empty()) // changed for a constrain - // aObject = aSelected.front().object(); - - //FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); - //if (!aFeature || aFeature != feature() || (aSelected.size() > 1)) { - // if (commit()) { - // theViewer->enableSelection(true); - // emit featureConstructed(feature(), FM_Deactivation); - - // // If we have selection and prehilighting with shift pressed - // // Then we have to select all these objects and restart as multi edit operfation - // //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); - // //if (aHasShift && !theHighlighted.empty()) { - // // QList aSelected; - // // std::list::const_iterator aIt; - // // for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt) - // // aSelected.append((*aIt).object()); - - // // for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) { - // // if (!aSelected.contains((*aIt).object())) - // // aSelected.append((*aIt).object()); - // // } - // // emit setSelection(aSelected); - // //} else - // if (aFeature) { - // std::string anOperationType = PartSet_OperationFeatureEdit::Type(); - // restartOperation(anOperationType, aFeature); - // } - // //} - // } - //} -} - -void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) -{ - if (!(theEvent->buttons() & Qt::LeftButton)) - return; - Handle(V3d_View) aView = theViewer->activeView(); - gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - - theViewer->enableSelection(false); - - //blockSelection(true); - if (myCurPoint.myIsInitialized) { - double aCurX, aCurY; - PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY); - - double aX, anY; - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - - double aDeltaX = aX - aCurX; - double aDeltaY = anY - aCurY; - - // the next code is commented because it is obsolete by the multi edit operation realization here - //if (myIsMultiOperation) { - // std::map>::iterator aFeatIter = myFeature2Attribute.begin(); - // while (aFeatIter != myFeature2Attribute.end()) { - // FeaturePtr aFeature = aFeatIter->first; - // std::list anAttributes = aFeatIter->second; - // // perform edit for the feature - // if (anAttributes.empty()) { - // std::shared_ptr aSketchFeature = - // std::dynamic_pointer_cast(aFeature); - // if (aSketchFeature) { - // aSketchFeature->move(aDeltaX, aDeltaY); - // } - // } - // // perform edit for the feature's attribute - // else { - // std::list::const_iterator anAttrIter = anAttributes.begin(), - // anAttrEnd = anAttributes.end(); - // for (; anAttrIter != anAttrEnd; anAttrIter++) { - // std::shared_ptr aPointAttr = std::dynamic_pointer_cast< - // GeomDataAPI_Point2D>(aFeature->data()->attribute(*anAttrIter)); - // if (aPointAttr) { - // aPointAttr->move(aDeltaX, aDeltaY); - // } - // } - // } - // aFeatIter++; - // } - //} - //else { // multieditoperation - - //std::shared_ptr aSketchFeature = std::dynamic_pointer_cast< - // SketchPlugin_Feature>(feature()); - - bool isMoved = false; - bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); - - // the functionality to move the feature attribute if it exists in the internal map - std::map>::iterator aFeatIter, aFeatLast; - if (aHasShift || myHighlightedFeature2Attribute.empty()) { - aFeatIter = myAllFeature2Attribute.begin(); - aFeatLast = myAllFeature2Attribute.end(); - } - else { - aFeatIter = myHighlightedFeature2Attribute.begin(); - aFeatLast = myHighlightedFeature2Attribute.end(); - } - - while (aFeatIter != aFeatLast) { - FeaturePtr aFeature = aFeatIter->first; - // MPV: added condition because it could be external edge of some object, not sketch - if (aFeature && !sketch()->isSub(aFeature)) { - aFeatIter++; - continue; - } - - std::list anAttributes = aFeatIter->second; - // perform edit for the feature - if (anAttributes.empty()) { - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(aFeature); - if (aSketchFeature) { - aSketchFeature->move(aDeltaX, aDeltaY); - isMoved = true; - } - } - // perform edit for the feature's attribute - else { - std::list::const_iterator anAttrIter = anAttributes.begin(), - anAttrEnd = anAttributes.end(); - for (; anAttrIter != anAttrEnd; anAttrIter++) { - std::shared_ptr aPointAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aFeature->data()->attribute(*anAttrIter)); - if (aPointAttr) { - aPointAttr->move(aDeltaX, aDeltaY); - isMoved = true; - } - } - } - aFeatIter++; - } - // the next code is commented because it is obsolete by the multi edit operation realization here - // the feature is moved only if there is no a local selection on this feature - //if (!isMoved) { - // // MPV: added condition because it could be external edge of some object, not sketch - // if (aSketchFeature && sketch()->isSub(aSketchFeature)) { - // aSketchFeature->move(aDeltaX, aDeltaY); - // static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); - // ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent); - // } - // } - //} // multieditoperation - sendFeatures(aHasShift); - } - - myCurPoint.setPoint(aPoint); -} - -void PartSet_OperationFeatureEdit::mouseReleased( - QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection) -{ - // the block is processed in order to do not commit the transaction until the started - // double click functionality is performed. It is reproduced on Linux only - if (myIsBlockedByDoubleClick) - return; - - theViewer->enableSelection(true); - // the next code is commented because it is obsolete by the multi edit operation realization here - //if (myIsMultiOperation) { - // if (commit()) { - // std::map>::iterator aFeatIter = myFeature2Attribute.begin(); - // while (aFeatIter != myFeature2Attribute.end()) { - // FeaturePtr aFeature = aFeatIter->first; - // if (aFeature) { - // emit featureConstructed(aFeature, FM_Deactivation); - // } - // aFeatIter++; - // } - // } - //} - //else { // multieditoperation - 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, theViewer, theSelection); - //}// else { - ////blockSelection(false); - ////} - //} // multieditoperation - } - else { - theViewer->enableSelection(true); - - // commit operation if there is no selected an highlighted objects anymore - Handle(V3d_View) aView = theViewer->activeView(); - QList aSelected = theSelection->getSelected(); - QList aHighlighted = theSelection->getHighlighted(); - - if (aSelected.empty() && aHighlighted.empty()) { - commit(); - emitFeaturesDeactivation(); - } - else if (aSelected.size() == 1) { - /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape - /// but for other IO, for example constraint dimensions. - /// It is empty and we have to use the process mouse release to start edition operation - /// for these objects - ObjectPtr anObject = aSelected.first().object(); - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind()) && - aFeature != feature()) { - restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature); - } - } - } -} - -void PartSet_OperationFeatureEdit::mouseDoubleClick( - QMouseEvent* theEvent, Handle_V3d_View theView, - ModuleBase_ISelection* theSelection) -{ - // TODO the functionality is important only for constraint feature. Should be moved in another place - QList aSelected = theSelection->getSelected(); - // in case when the double click happens on another constraint feature when selection control is active - // we should not perform the double click functionality - // if there is no the viewer selector widget active, the operation is restarted with a correct feature - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - if(aActiveWgt && aActiveWgt->isViewerSelector()) { - if (!aSelected.empty()) { - if (aSelected.size() == 1) { - /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape - /// but for other IO, for example constraint dimensions. - /// It is empty and we have to use the process mouse release to start edition operation - /// for these objects - ObjectPtr anObject = aSelected.first().object(); - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind()) && - aFeature != feature()) { - return; - } - } - } - } - - myIsBlockedByDoubleClick = true; - if (!aSelected.empty()) { - ModuleBase_ViewerPrs aFeaturePrs = aSelected.first(); - if (!aFeaturePrs.owner().IsNull()) { - Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast( - aFeaturePrs.owner()); - if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) { - bool isValid; - double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(), - isValid); - if (isValid) { - ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE()); - flushUpdated(); - } - } - } - } - myIsBlockedByDoubleClick = false; -} - -void PartSet_OperationFeatureEdit::startOperation() -{ - PartSet_OperationSketchBase::startOperation(); - //emit multiSelectionEnabled(false); - - myCurPoint.clear(); -} - -void PartSet_OperationFeatureEdit::stopOperation() -{ - //emit multiSelectionEnabled(true); - - //blockSelection(false, false); - - myHighlightedFeature2Attribute.clear(); - myAllFeature2Attribute.clear(); -} - -//void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection) -//{ -// if (myIsBlockedSelection == isBlocked) -// return; -// -// myIsBlockedSelection = isBlocked; -// QList aFeatureList; -// aFeatureList.append(feature()); -// -// //if (isBlocked) { -// // emit setSelection(QList()); -// // emit stopSelection(aFeatureList, true); -// //} else { -// // emit stopSelection(aFeatureList, false); -// // if (isRestoreSelection) -// // emit setSelection(aFeatureList); -// //} -//} - -FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool theFlushMessage, - CompositeFeaturePtr theCompositeFeature) -{ - // do nothing in order to do not create a new feature - return FeaturePtr(); -} - -void PartSet_OperationFeatureEdit::sendFeatures(const bool theIsAllFeatures) -{ - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); - - std::map>::iterator aFeatIter, aFeatLast; - if (theIsAllFeatures || myHighlightedFeature2Attribute.empty()) { - aFeatIter = myAllFeature2Attribute.begin(); - aFeatLast = myAllFeature2Attribute.end(); - } - else { - aFeatIter = myHighlightedFeature2Attribute.begin(); - aFeatLast = myHighlightedFeature2Attribute.end(); - } - while (aFeatIter != aFeatLast) { - FeaturePtr aFeature = aFeatIter->first; - if (aFeature) { - ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent); - } - aFeatIter++; - } - - Events_Loop::loop()->flush(anEvent); - flushUpdated(); -} - -void PartSet_OperationFeatureEdit::emitFeaturesDeactivation() -{ - std::map>::iterator aFeatIter = myAllFeature2Attribute.begin(); - while (aFeatIter != myAllFeature2Attribute.end()) { - FeaturePtr aFeature = aFeatIter->first; - if (aFeature) { - emit featureConstructed(aFeature, FM_Deactivation); - } - aFeatIter++; - } -} - diff --git a/src/PartSet/PartSet_OperationFeatureEdit.h b/src/PartSet/PartSet_OperationFeatureEdit.h deleted file mode 100644 index 267b494c6..000000000 --- a/src/PartSet/PartSet_OperationFeatureEdit.h +++ /dev/null @@ -1,156 +0,0 @@ -// File: PartSet_OperationFeatureEdit.h -// Created: 05 May 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PartSet_OperationFeatureEdit_H -#define PartSet_OperationFeatureEdit_H - -#include "PartSet.h" - -#include -#include - -class QMouseEvent; -class ModuleBase_ISelection; - -/*! - \class PartSet_OperationFeatureEdit - * \brief The operation for the sketch feature creation - */ -class PARTSET_EXPORT PartSet_OperationFeatureEdit : public PartSet_OperationFeatureBase -{ -Q_OBJECT - /// Struct to define gp point, with the state is the point is initialized - struct Point - { - /// Constructor - Point() - { - myIsInitialized = false; - } - /// Constructor - /// \param thePoint the point - Point(gp_Pnt thePoint) - { - setPoint(thePoint); - } - ~Point() - { - } - - /// clear the initialized flag. - void clear() - { - myIsInitialized = false; - } - /// set the point and switch on the initialized flag - /// \param thePoint the point - void setPoint(const gp_Pnt& thePoint) - { - myIsInitialized = true; - myPoint = thePoint; - } - - bool myIsInitialized; /// the state whether the point is set - gp_Pnt myPoint; /// the point - }; - - public: - /// Returns the operation type key - static std::string Type() - { - return "EditLine"; - } - - public: - /// Constructor - /// \param theId the feature identifier - /// \param theParent the operation parent - /// \param theFeature the parent feature - PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, CompositeFeaturePtr theFeature); - /// Destructor - virtual ~PartSet_OperationFeatureEdit(); - - - /// Initialisation of operation with preliminary selection - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - /// \param theViewer a viewer to have the viewer the eye position - virtual void initSelection(ModuleBase_ISelection* theSelection, - ModuleBase_IViewer* theViewer); - - /// Processes the mouse pressed in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection); - - /// Gives the current mouse point in the viewer - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer); - /// Gives the current selected objects to be processed by the operation - /// \param thePoint a point clicked in the viewer - /// \param theEvent the mouse event - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection); - - /// Processes the mouse double click in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView, - ModuleBase_ISelection* theSelection); - - protected: - /// \brief Virtual method called when operation is started - /// Virtual method called when operation started (see start() method for more description) - /// Switch off the multi selection state - virtual void startOperation(); - - /// Virtual method called when operation stopped - committed or aborted. - /// Restore the multi selection state - virtual void stopOperation(); - - /// Creates an operation new feature - /// Returns NULL feature. This is an operation of edition, not creation. - /// \param theFlushMessage the flag whether the create message should be flushed - /// \returns the created feature - virtual FeaturePtr createFeature(const bool theFlushMessage = true, - CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr()); - - protected: - void fillFeature2Attribute(const QList& thePresentations, - ModuleBase_IViewer* theViewer, - std::map >& theFeature2Attribute); - - /// Emits a signal about the selection blocking. Emits a signal to change the selection. - /// If the block is true, the signal clear selection, otherwise if restore selection flag allows, - /// the internal operation features are to be selected - /// \param isBlocked the state whether the operation is blocked or unblocked - /// \param isRestoreSelection the state whether the selected objects should be reselected - //void blockSelection(bool isBlocked, const bool isRestoreSelection = true); - - /// Sends the features - /// \param theIsAllFeatures a boolean value whether all features should be send or only the highlighted ones - void sendFeatures(const bool theIsAllFeatures); - - /// Sends signal about the current features are to be deactivated - void emitFeaturesDeactivation(); - - private: - // the next map should be removed when selection is processed in the move function - std::map > myHighlightedFeature2Attribute; /// a map of a feature to attributes - std::map > myAllFeature2Attribute; /// a map of a feature to attributes - - Point myCurPoint; ///< the current 3D point clicked or moved - bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal - bool myIsBlockedByDoubleClick; ///< the block value by double click is processed to avoid - ///< the mouse button release processing before the double click is finished -}; - -#endif diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp deleted file mode 100644 index 5d9454d7a..000000000 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ /dev/null @@ -1,292 +0,0 @@ -// File: PartSet_OperationSketch.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#ifdef _DEBUG -#include -#endif - -#include - -using namespace std; - -PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) - : PartSet_OperationSketchBase(theId, theParent) -{ -} - -PartSet_OperationSketch::~PartSet_OperationSketch() -{ -} - -CompositeFeaturePtr PartSet_OperationSketch::sketch() const -{ - return std::dynamic_pointer_cast(feature()); -} - -void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) -{ - if (hasSketchPlane()) { - // if shift button is pressed and there are some already selected objects, the operation should - // not be started. We just want to combine some selected objects. - bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); - QList aSelected = theSelection->getSelected(); - QList aHighlighted = theSelection->getHighlighted(); - // commented: the next code is commented because the nearestFeature check the highlighting - // and selection inside - //if (aHasShift && (aSelected.size() > 0)) { - // foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) - // aSelected.append(aPrs); - //} - //if (aHasShift && aSelected.size() > 0) - // return; - - // there should be a start of operation, which uses the pre-highlighted objects, - // the selected ones are collected here and are processed by a mouse move - //if (aHighlighted.size() == 1) { - //if (aSelected.size() > 0) { - // ObjectPtr aFeature = aSelected.first().object(); - // if (aFeature) { - // commented: end - Handle(V3d_View) aView = theViewer->activeView(); - ObjectPtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(), - aSelected, aHighlighted); - if (aFeature) - restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature); - //} - //} - //else - // myFeatures = aHighlighted; - //else - //myFeatures = aSelected; - } -} - - -void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelection) -{ - if (hasSketchPlane()) - return; - - QList aSelected = theSelection->getSelected(); - if (!aSelected.empty()) { - ModuleBase_ViewerPrs aPrs = aSelected.first(); - // We have to select a plane before any operation - TopoDS_Shape aShape = aPrs.shape(); - if (!aShape.IsNull()) { - std::shared_ptr aDir = setSketchPlane(aShape); - flushUpdated(); - emit featureConstructed(feature(), FM_Hide); - // If selection is not a sketcher presentation then it has to be stored as - // External shape - if (feature() != aPrs.object()) { - //std::shared_ptr aSketch = - // std::dynamic_pointer_cast(feature()); - DataPtr aData = feature()->data(); - AttributeSelectionPtr aSelAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); - if (aSelAttr) { - ResultPtr aRes = std::dynamic_pointer_cast(aPrs.object()); - if (aRes) { - GeomShapePtr aShapePtr(new GeomAPI_Shape()); - aShapePtr->setImpl(new TopoDS_Shape(aShape)); - aSelAttr->setValue(aRes, aShapePtr); - } - } - } else { - // Turn viewer to the plane - emit planeSelected(aDir->x(), aDir->y(), aDir->z()); - } - emit updatePropPanel(); - emit launchSketch(); - } - } -} - - -void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection) -{ - QList aSelected = theSelection->getSelected(); - if (hasSketchPlane()) { - /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape - /// but for other IO, for example constraint dimensions. - /// It is empty and we have to use the process mouse release to start edition operation - /// for these objects - if (aSelected.size() == 1) { - ObjectPtr aObject = aSelected.first().object(); - if (aObject) { - restartOperation(PartSet_OperationFeatureEdit::Type(), aObject); - } - } - } -} - -void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) -{ - if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) - return; - - // myFeatures are not filled in the previous realization, so, this code is just commented - // because has no effect - /*if (myFeatures.size() != 1) { - Handle(V3d_View) aView = theViewer->activeView(); - ObjectPtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(), - myFeatures); - if (aFeature) - restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature); - }*/ -} - -std::list PartSet_OperationSketch::subFeatures() const -{ - std::list aFeaList; - FeaturePtr aFeature = feature(); - if (!aFeature) - return aFeaList; - - std::shared_ptr aData = aFeature->data(); - if (!aData->isValid()) - return std::list(); - std::shared_ptr aRefList = std::dynamic_pointer_cast< - ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); - - std::list aList = aRefList->list(); - std::list::iterator aIt; - for (aIt = aList.begin(); aIt != aList.end(); ++aIt) { - FeaturePtr aFeature = std::dynamic_pointer_cast(*aIt); - if (aFeature) - aFeaList.push_back(aFeature); - } - return aFeaList; -} - -void PartSet_OperationSketch::stopOperation() -{ - PartSet_OperationSketchBase::stopOperation(); - emit featureConstructed(feature(), FM_Hide); -} - -void PartSet_OperationSketch::afterCommitOperation() -{ - FeaturePtr aFeature = feature(); - std::list aResults = aFeature->results(); - std::list::const_iterator aIt; - Events_ID anEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW); - for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - ModelAPI_EventCreator::get()->sendUpdated(*aIt, anEvent); - } - Events_Loop::loop()->flush(anEvent); -} - -bool PartSet_OperationSketch::isNestedOperationsEnabled() const -{ - return hasSketchPlane(); -} - -void PartSet_OperationSketch::startOperation() -{ - PartSet_OperationSketchBase::startOperation(); - if (!isEditOperation()) - emit fitAllView(); -} - -bool PartSet_OperationSketch::hasSketchPlane() const -{ - bool aHasPlane = false; - - if (feature()) { - std::shared_ptr aData = feature()->data(); - AttributeDoublePtr anAttr; - std::shared_ptr aNormal = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::NORM_ID())); - aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); - } - return aHasPlane; -} - -std::shared_ptr PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) -{ - if (theShape.IsNull()) - return std::shared_ptr(); - - // get selected shape - std::shared_ptr aGShape(new GeomAPI_Shape); - aGShape->setImpl(new TopoDS_Shape(theShape)); - - // get plane parameters - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); - - // set plane parameters to feature - std::shared_ptr aData = feature()->data(); - double anA, aB, aC, aD; - aPlane->coefficients(anA, aB, aC, aD); - - // calculate attributes of the sketch - std::shared_ptr aNormDir(new GeomAPI_Dir(anA, aB, aC)); - std::shared_ptr aCoords = aNormDir->xyz(); - std::shared_ptr aZero(new GeomAPI_XYZ(0, 0, 0)); - aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero)); - std::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); - // X axis is preferable to be dirX on the sketch - const double tol = Precision::Confusion(); - bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol; - std::shared_ptr aTempDir( - isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); - std::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); - std::shared_ptr aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir))); - - std::shared_ptr anOrigin = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - anOrigin->setValue(anOrigPnt); - std::shared_ptr aNormal = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::NORM_ID())); - aNormal->setValue(aNormDir); - std::shared_ptr aDirX = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::DIRX_ID())); - aDirX->setValue(aXDir); - std::shared_ptr aDirY = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::DIRY_ID())); - aDirY->setValue(aYDir); - std::shared_ptr aDir = aPlane->direction(); - return aDir; -} - - -bool PartSet_OperationSketch::isGranted(ModuleBase_Operation* theOperation) const -{ - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); - return aPreviewOp != NULL; -} - diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h deleted file mode 100644 index 1a770e16b..000000000 --- a/src/PartSet/PartSet_OperationSketch.h +++ /dev/null @@ -1,126 +0,0 @@ -// File: PartSet_OperationSketch.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PartSet_OperationSketch_H -#define PartSet_OperationSketch_H - -#include "PartSet.h" - -#include - -#include - -#include -#include - -class Handle_AIS_InteractiveObject; - -/*! - \class PartSet_OperationSketch - * \brief The operation for the sketch feature creation - */ -class PARTSET_EXPORT PartSet_OperationSketch : public PartSet_OperationSketchBase -{ -Q_OBJECT - public: - /// Returns the operation type key - static std::string Type() - { - return SketchPlugin_Sketch::ID(); - } - - public: - /// Constructor - /// \param theId the feature identifier - /// \param theParent the operation parent - PartSet_OperationSketch(const QString& theId, QObject* theParent); - /// Destructor - virtual ~PartSet_OperationSketch(); - - /// Returns True if the given operation is a Sketcher operation - virtual bool isGranted(ModuleBase_Operation* theOperation) const; - - - /// Returns the operation sketch feature - /// \returns the sketch instance - virtual CompositeFeaturePtr sketch() const; - - /// Processes the mouse pressed in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection); - - /// Processes the mouse release in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection); - - /// Gives the current mouse point in the viewer - /// \param thePoint a point clicked in the viewer - /// \param theEvent the mouse event - virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer); - - /// Returns the list of the nested features - /// \return the list of subfeatures - virtual std::list subFeatures() const; - - /// Virtual method called when operation stopped - committed or aborted. - /// Emits a signal to hide the preview of the operation - virtual void stopOperation(); - - /// Returns whether the nested operations are enabled. - /// The state can depend on the operation current state. - /// It returns true after the sketch plane is choosen. - /// \return enabled state - virtual bool isNestedOperationsEnabled() const; - - /// Returns whether the sketch plane is set - /// \return the boolean value whether the sketch is set - bool hasSketchPlane() const; - - /// Set the plane to the current sketch - /// \param theShape the shape - /// \return selected direction - std::shared_ptr setSketchPlane(const TopoDS_Shape& theShape); - - /// Called on selection changed when the operation is active - virtual void selectionChanged(ModuleBase_ISelection* theSelection); - - /// If operation needs to redisplay its result during operation - /// then this method has to return True - virtual bool hasPreview() const { return false; } - -signals: - /// signal about the sketch plane is selected - /// \param theX the value in the X direction of the plane - /// \param theX the value in the Y direction value of the plane - /// \param theX the value in the Z direction of the plane - void planeSelected(double theX, double theY, double theZ); - // signal about the viewer fit all perform - void fitAllView(); - - /// Signal to define sketch mode - void launchSketch(); - - /// Signal to update property panel - void updatePropPanel(); - - protected: - /// Virtual method called when operation started (see start() method for more description) - /// Default impl calls corresponding slot and commits immediately. - virtual void startOperation(); - - /// Virtual method called after operation committed (see commit() method for more description) - virtual void afterCommitOperation(); - - private: - QList myFeatures; ///< the features to apply the edit operation -}; - -#endif diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp deleted file mode 100644 index 310658e9b..000000000 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// File: PartSet_OperationSketchBase.cpp -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#ifdef _DEBUG -#include -#endif - -using namespace std; - -PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId, QObject* theParent) - : ModuleBase_Operation(theId, theParent) -{ -} - -PartSet_OperationSketchBase::~PartSet_OperationSketchBase() -{ -} - -std::shared_ptr PartSet_OperationSketchBase::preview(FeaturePtr theFeature) -{ - std::shared_ptr aFeature = std::dynamic_pointer_cast< - SketchPlugin_Feature>(theFeature); - if (aFeature) { - ResultPtr aRes = aFeature->firstResult(); - ResultBodyPtr aBody = std::dynamic_pointer_cast(aRes); - if (aBody) - return aBody->shape(); - } - return std::shared_ptr(); -} - -std::list PartSet_OperationSketchBase::subFeatures() const -{ - return std::list(); -} - -FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage) -{ - ModuleBase_Operation::createFeature(theFlushMessage); - if (myFeature) - emit featureConstructed(myFeature, FM_Activation); - return myFeature; -} - -void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) -{ -} -void PartSet_OperationSketchBase::mouseReleased( - QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection) -{ -} -void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) -{ -} -void PartSet_OperationSketchBase::mouseDoubleClick( - QMouseEvent* theEvent, Handle_V3d_View theView, - ModuleBase_ISelection* theSelection) -{ -} - -void PartSet_OperationSketchBase::selectionChanged(ModuleBase_ISelection* theSelection) -{ -} - -void PartSet_OperationSketchBase::restartOperation(const std::string& theType, ObjectPtr theFeature) -{ - FeaturePtr aFeature = ModelAPI_Feature::feature(theFeature); - if (aFeature) { - QStringList aNested = this->nestedFeatures(); - if (!aNested.isEmpty()) { - if (!aNested.contains(QString(aFeature->getKind().c_str()))) - return; - } - } - emit restartRequired(theType, theFeature); -} - - diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h deleted file mode 100644 index dacfb8fd7..000000000 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ /dev/null @@ -1,148 +0,0 @@ -// File: PartSet_OperationSketchBase.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PartSet_OperationSketchBase_H -#define PartSet_OperationSketchBase_H - -#include "PartSet.h" - -#include -#include -#include - -#include -#include - -#include -#include - -#include - -#include - -#include - -class Handle_V3d_View; -class QMouseEvent; -class GeomAPI_Shape; -class ModuleBase_ViewerPrs; -class ModuleBase_ISelection; -class ModuleBase_IViewer; - -/*! - \class PartSet_OperationSketchBase - * \brief The base operation for the sketch features. - * Base class for all sketch operations. It provides an access to the feature preview - */ -class PARTSET_EXPORT PartSet_OperationSketchBase : public ModuleBase_Operation -{ -Q_OBJECT - public: - enum FeatureActionMode - { - FM_Activation, - FM_Deactivation, - FM_Hide - }; - - public: - /// Constructor - /// \param theId an feature index - /// \param theParent the object parent - PartSet_OperationSketchBase(const QString& theId, QObject* theParent); - /// Destructor - virtual ~PartSet_OperationSketchBase(); - - /// Returns the feature preview shape - /// \param theFeature the feature object to obtain the preview - static std::shared_ptr preview(FeaturePtr theFeature); - - /// Returns the list of the nested features - /// \return the list of subfeatures - virtual std::list subFeatures() const; - - /// Returns the operation sketch feature - /// \returns the sketch instance - virtual CompositeFeaturePtr sketch() const = 0; - - /// Processes the mouse pressed in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection); - - /// Processes the mouse release in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, - ModuleBase_ISelection* theSelection); - - /// Processes the mouse move in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer); - - /// Processes the mouse double click in the point - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView, - ModuleBase_ISelection* theSelection); - - - /// Called on selection changed when the operation is active - virtual void selectionChanged(ModuleBase_ISelection* theSelection); - - /// Emits a signal about the operation start. This signal has an information about the feature. - /// If the provided feature is empty, the current operation feature is used. - /// \param theType a type of an operation started - /// theFeature the operation argument - void restartOperation(const std::string& theType, ObjectPtr theFeature = ObjectPtr()); - - /// If operation needs to redisplay its result during operation - /// then this method has to return True - virtual bool hasPreview() const { return true; } - -signals: - /// signal about the request to launch operation - /// theName the operation name - /// theFeature the operation argument - void restartRequired(std::string theName, ObjectPtr theFeature); - - /// Signal about the feature construing is finished - /// \param theFeature the result feature - /// \param theMode the mode of the feature modification - void featureConstructed(ObjectPtr theFeature, int theMode); - - /// Signal about the features should be selected - /// \param theSelected the list of selected presentations - void featureSelected(const std::list& theSelected); - - /// signal to enable/disable multi selection in the viewer - /// \param theEnabled the boolean state - //void multiSelectionEnabled(bool theEnabled); - - /// signal to enable/disable selection in the viewer - /// \param theFeatures a list of features to be disabled - /// \param theToStop the boolean state whether it it stopped or non stopped - void stopSelection(const QList& theFeatures, const bool theToStop); - - /// signal to set selection in the viewer - /// \param theFeatures a list of features to be disabled - void setSelection(const QList& theFeatures); - - protected: - /// Creates an operation new feature - /// In addition to the default realization it appends the created line feature to - /// the sketch feature - /// \param theFlushMessage the flag whether the create message should be flushed - /// \returns the created feature - virtual FeaturePtr createFeature(const bool theFlushMessage = true); -}; - -#endif diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index c97b6c68f..dbb12d393 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -352,19 +352,27 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch) { std::shared_ptr aPlane; - double aA, aB, aC, aD; std::shared_ptr aData = theSketch->data(); std::shared_ptr anOrigin = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); std::shared_ptr aNormal = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Sketch::NORM_ID())); - aA = aNormal->x(); - aB = aNormal->y(); - aC = aNormal->z(); - aD = 0; - - aPlane = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); + if (aNormal && anOrigin) { + double adX = aNormal->x(); + double adY = aNormal->y(); + double adZ = aNormal->z(); + + if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid + double aX = anOrigin->x(); + double aY = anOrigin->y(); + double aZ = anOrigin->z(); + gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ)); + double aA, aB, aC, aD; + aPln.Coefficients(aA, aB, aC, aD); + aPlane = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); + } + } return aPlane; } diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 5dda6eafb..53c98a47b 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -35,6 +35,7 @@ class PARTSET_EXPORT PartSet_Tools /// Converts the 2D screen point to the 3D point on the view according to the point of view /// \param thePoint a screen point /// \param theView a 3D view + // Transferred to ModuleBase static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView); /// \brief Converts the 3D point to the projected coodinates on the sketch plane. @@ -43,7 +44,7 @@ class PARTSET_EXPORT PartSet_Tools /// \param theX the X coordinate /// \param theY the Y coordinate static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch, - Handle(V3d_View) theView, + Handle(V3d_View) theView, double& theX, double& theY); /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point. diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp new file mode 100644 index 000000000..1fc77dc99 --- /dev/null +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -0,0 +1,268 @@ +// File: PartSet_WidgetPoint2D.cpp +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include "PartSet_WidgetPoint2D.h" +#include "PartSet_Tools.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) +{ + //myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); + QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)); + myGroupBox = new QGroupBox(aPageName, theParent); + myGroupBox->setFlat(false); + + QGridLayout* aGroupLay = new QGridLayout(myGroupBox); + ModuleBase_Tools::adjustMargins(aGroupLay); + aGroupLay->setColumnStretch(1, 1); + { + QLabel* aLabel = new QLabel(myGroupBox); + aLabel->setText("X"); + aLabel->setPixmap(QPixmap(":pictures/x_point.png")); + aGroupLay->addWidget(aLabel, 0, 0); + + myXSpin = new ModuleBase_DoubleSpinBox(myGroupBox); + myXSpin->setMinimum(-DBL_MAX); + myXSpin->setMaximum(DBL_MAX); + myXSpin->setToolTip("X"); + aGroupLay->addWidget(myXSpin, 0, 1); + + connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + } + { + QLabel* aLabel = new QLabel(myGroupBox); + aLabel->setText("Y"); + aLabel->setPixmap(QPixmap(":pictures/y_point.png")); + aGroupLay->addWidget(aLabel, 1, 0); + + myYSpin = new ModuleBase_DoubleSpinBox(myGroupBox); + myYSpin->setMinimum(-DBL_MAX); + myYSpin->setMaximum(DBL_MAX); + myYSpin->setToolTip("X"); + aGroupLay->addWidget(myYSpin, 1, 1); + + connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + } +} + +PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() +{ +} + +bool PartSet_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) +{ + bool isDone = false; + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue) { + std::shared_ptr aPoint = aFeatureValue->point(); + if (aPoint) { + setPoint(aPoint->x(), aPoint->y()); + isDone = true; + } + } + } + return isDone; +} + +void PartSet_WidgetPoint2D::setPoint(double theX, double theY) +{ + + bool isBlocked = this->blockSignals(true); + myXSpin->setValue(theX); + myYSpin->setValue(theY); + this->blockSignals(isBlocked); + + emit valuesChanged(); +} + +bool PartSet_WidgetPoint2D::storeValue() const +{ + std::shared_ptr aData = myFeature->data(); + std::shared_ptr aPoint = std::dynamic_pointer_cast( + aData->attribute(attributeID())); + + PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this; + bool isBlocked = that->blockSignals(true); + bool isImmutable = aPoint->setImmutable(true); +#ifdef _DEBUG + std::string _attr_name = myAttributeID; + double _X = myXSpin->value(); + double _Y = myYSpin->value(); +#endif + aPoint->setValue(myXSpin->value(), myYSpin->value()); + updateObject(myFeature); + aPoint->setImmutable(isImmutable); + that->blockSignals(isBlocked); + + return true; +} + +bool PartSet_WidgetPoint2D::restoreValue() +{ + std::shared_ptr aData = myFeature->data(); + std::shared_ptr aPoint = std::dynamic_pointer_cast( + aData->attribute(attributeID())); + +#ifdef _DEBUG + std::string _attr_name = myAttributeID; + double _X = aPoint->x(); + double _Y = aPoint->y(); +#endif + bool isBlocked = this->blockSignals(true); + myXSpin->setValue(aPoint->x()); + myYSpin->setValue(aPoint->y()); + this->blockSignals(isBlocked); + return true; +} + +QWidget* PartSet_WidgetPoint2D::getControl() const +{ + return myGroupBox; +} + +QList PartSet_WidgetPoint2D::getControls() const +{ + QList aControls; + aControls.append(myXSpin); + aControls.append(myYSpin); + return aControls; +} + +//bool PartSet_WidgetPoint2D::initFromPrevious(ObjectPtr theObject) +//{ +// if (myOptionParam.length() == 0) +// return false; +// std::shared_ptr aData = theObject->data(); +// std::shared_ptr aPoint = std::dynamic_pointer_cast( +// aData->attribute(myOptionParam)); +// if (aPoint) { +// bool isBlocked = this->blockSignals(true); +// myXSpin->setValue(aPoint->x()); +// myYSpin->setValue(aPoint->y()); +// this->blockSignals(isBlocked); +// +// emit valuesChanged(); +// emit storedPoint2D(theObject, myOptionParam); +// return true; +// } +// return false; +//} + +void PartSet_WidgetPoint2D::activate() +{ + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); + connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); + + QIntList aModes; + aModes << TopAbs_VERTEX; + myWorkshop->moduleConnector()->activateSubShapesSelection(aModes); +} + +void PartSet_WidgetPoint2D::deactivate() +{ + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); + disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); + myWorkshop->moduleConnector()->deactivateSubShapesSelection(); +} + + +void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) +{ + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + NCollection_List aShapes; + std::list aObjects; + aSelection->selectedShapes(aShapes, aObjects); + if (aShapes.Extent() > 0) { + TopoDS_Shape aShape = aShapes.First(); + if (!aShape.IsNull()) { + if (aShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); + if (!aVertex.IsNull()) { + // A case when point is taken from existing vertex + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + double aX, aY; + PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); + setPoint(aX, aY); + emit vertexSelected(aObjects.front(), aShape); + emit focusOutWidget(this); + return; + } + } + } + } + // A case when point is taken from mouse event + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); + double aX, anY; + PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY); + setPoint(aX, anY); + + emit focusOutWidget(this); +} + + +void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) +{ + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); + + double aX, anY; + PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY); + setPoint(aX, anY); +} + +double PartSet_WidgetPoint2D::x() const +{ + return myXSpin->value(); +} + +double PartSet_WidgetPoint2D::y() const +{ + return myYSpin->value(); +} + diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h new file mode 100644 index 000000000..444699848 --- /dev/null +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -0,0 +1,111 @@ +// File: PartSet_WidgetPoint2D.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_WidgetPoint2D_H +#define PartSet_WidgetPoint2D_H + +#include "PartSet.h" +#include +#include + +#include + +#include + +class ModelAPI_Feature; +class ModuleBase_WidgetValue; +class ModuleBase_IWorkshop; +class ModuleBase_DoubleSpinBox; +class ModuleBase_IViewWindow; +class GeomAPI_Pnt2d; +class XGUI_Workshop; + +class QGroupBox; +class QMouseEvent; + +/**\class PartSet_WidgetPoint2D + * \ingroup GUI + * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls + */ +class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget +{ +Q_OBJECT + public: + /// Constructor + /// \theParent the parent object + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from + PartSet_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId); + /// Destructor + virtual ~PartSet_WidgetPoint2D(); + + /// 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); + + /// Saves the internal parameters to the given feature + /// \param theObject a model feature to be changed + virtual bool storeValue() const; + + virtual bool restoreValue(); + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + //bool initFromPrevious(ObjectPtr theObject); + + /// The methiod called when widget is activated + virtual void activate(); + + /// The methiod called when widget is deactivated + virtual void deactivate(); + + XGUI_Workshop* workshop() const { return myWorkshop; } + + void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; } + + /// \returns the sketch instance + CompositeFeaturePtr sketch() const { return mySketch; } + void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; } + + /// Fill the widget values by given point + /// \param thePoint the point + void setPoint(double theX, double theY); + + /// Returns coordinate X currently defined in the control + double x() const; + + /// Returns coordinate Y currently defined in the control + double y() const; + +signals: + /// Signal about selection of an existing vertex from an object + /// \param theObject - the selected object + /// \param theShape - the selected shape + void vertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape); + +protected slots: + void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + + private: + XGUI_Workshop* myWorkshop; + + QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets + ModuleBase_DoubleSpinBox* myXSpin; ///< the spin box for the X coordinate + ModuleBase_DoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate + + //std::string myOptionParam; /// Parameter name which has to be taken from previous feature + + CompositeFeaturePtr mySketch; +}; + +#endif diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp new file mode 100644 index 000000000..29c0ad56b --- /dev/null +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -0,0 +1,114 @@ +// File: PartSet_WidgetPoint2dDistance.h +// Created: 23 June 2014 +// Author: Vitaly Smetannikov + +#include "PartSet_WidgetPoint2dDistance.h" +#include "PartSet_Tools.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) +{ + myFirstPntName = theData->getProperty("first_point"); +} + +PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() +{ +} + +//bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue) +//{ +// bool isDone = false; +// +// if (theValue) { +// ModuleBase_WidgetValueFeature* aFeatureValue = +// dynamic_cast(theValue); +// if (aFeatureValue) { +// std::shared_ptr aPnt = aFeatureValue->point(); +// ObjectPtr aObject = aFeatureValue->object(); +// FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); +// if (aFeature && aPnt) { +// setPoint(aFeature, aPnt); +// isDone = true; +// } +// } +// } +// return isDone; +//} + +void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, + const std::shared_ptr& thePnt) +{ + std::shared_ptr aData = theFeature->data(); + std::shared_ptr aPoint = std::dynamic_pointer_cast( + aData->attribute(myFirstPntName)); + if (!aPoint) + return; + + double aRadius = thePnt->distance(aPoint->pnt()); + AttributeDoublePtr aReal = aData->real(attributeID()); + if (aReal && (aReal->value() != aRadius)) { + aReal->setValue(aRadius); + mySpinBox->setValue(aRadius); + } +} + +void PartSet_WidgetPoint2dDistance::activate() +{ + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); + connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); +} + +void PartSet_WidgetPoint2dDistance::deactivate() +{ + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); + disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); +} + +void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) +{ + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); + + double aX, aY; + PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); + + std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); + setPoint(feature(), aPnt); + emit focusOutWidget(this); +} + +void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) +{ + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); + + double aX, aY; + PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); + + std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); + setPoint(feature(), aPnt); +} + + diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h new file mode 100644 index 000000000..7c2364780 --- /dev/null +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -0,0 +1,65 @@ +// File: PartSet_WidgetPoint2dDistance.h +// Created: 23 June 2014 +// Author: Vitaly Smetannikov + +#ifndef PartSet_WidgetPoint2dDistance_H +#define PartSet_WidgetPoint2dDistance_H + +#include "PartSet.h" +#include + +#include + +//class ModuleBase_WidgetValue; +class GeomAPI_Pnt2d; +class XGUI_Workshop; +class ModuleBase_IViewWindow; +class QMouseEvent; + +class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue +{ +Q_OBJECT + public: + /// Constructor + /// \theParent the parent object + /// \theData the widget configuation. The attribute of the model widget is obtained from + PartSet_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId); + + virtual ~PartSet_WidgetPoint2dDistance(); + + /// The methiod called when widget is activated + virtual void activate(); + + /// The methiod called when widget is deactivated + virtual void deactivate(); + + /// 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); + + XGUI_Workshop* workshop() const { return myWorkshop; } + + void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; } + + /// \returns the sketch instance + CompositeFeaturePtr sketch() const { return mySketch; } + void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; } + + protected slots: + void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); + +protected: + /// Set the second point which defines a value in the widget as a distance with a first point defined by feature + void setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt); + + private: + XGUI_Workshop* myWorkshop; + std::string myFirstPntName; + + CompositeFeaturePtr mySketch; +}; + +#endif diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index b6f18fb7f..def4e042e 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -3,19 +3,44 @@ // Author: Vitaly SMETANNIKOV #include "PartSet_WidgetSketchLabel.h" -#include "PartSet_OperationSketch.h" +#include "PartSet_Tools.h" + +#include +#include +#include +#include +#include #include -#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include #include +#include #include +#define PLANE_SIZE "200" +#define SKETCH_WIDTH "4" + + PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId), myPreviewDisplayed(false) { myText = QString::fromStdString(theData->getProperty("title")); myLabel = new QLabel("", theParent); @@ -25,6 +50,11 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, myLabel->setIndent(5); } +PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel() +{ + erasePreviewPlanes(); +} + QList PartSet_WidgetSketchLabel::getControls() const { return QList(); @@ -35,30 +65,217 @@ QWidget* PartSet_WidgetSketchLabel::getControl() const return myLabel; } -void PartSet_WidgetSketchLabel::setOperationsMgr(XGUI_OperationMgr* theMgr) +void PartSet_WidgetSketchLabel::onPlaneSelected() { - ModuleBase_Operation* aOperation = theMgr->currentOperation(); - if (aOperation->inherits("PartSet_OperationSketch")) { - PartSet_OperationSketch* aSketchOpe = static_cast(aOperation); - updateLabel(aSketchOpe); - connect(aSketchOpe, SIGNAL(updatePropPanel()), this, - SLOT(onPlaneSelected())); + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + QList aSelected = aSelection->getSelected(); + if (!aSelected.empty()) { + ModuleBase_ViewerPrs aPrs = aSelected.first(); + TopoDS_Shape aShape = aPrs.shape(); + if (!aShape.IsNull()) { + std::shared_ptr aDir = setSketchPlane(aShape); + if (aDir) { + erasePreviewPlanes(); + + if (aPrs.object() && (feature() != aPrs.object())) { + DataPtr aData = feature()->data(); + AttributeSelectionPtr aSelAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + if (aSelAttr) { + ResultPtr aRes = std::dynamic_pointer_cast(aPrs.object()); + if (aRes) { + GeomShapePtr aShapePtr(new GeomAPI_Shape()); + aShapePtr->setImpl(new TopoDS_Shape(aShape)); + aSelAttr->setValue(aRes, aShapePtr); + } + } + } else + myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z()); + + // Clear text in the label + myLabel->setText(""); + myLabel->setToolTip(""); + disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()), + this, SLOT(onPlaneSelected())); + + // Clear selection mode and define sketching mode + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->removeSelectionFilter(myPlaneFilter); + aDisp->closeLocalContexts(); + setSketchingMode(); + } + } } } -void PartSet_WidgetSketchLabel::onPlaneSelected() +std::shared_ptr PartSet_WidgetSketchLabel::plane() const { - PartSet_OperationSketch* aSketchOpe = static_cast(sender()); - updateLabel(aSketchOpe); + CompositeFeaturePtr aSketch = std::dynamic_pointer_cast(myFeature); + return PartSet_Tools::sketchPlane(aSketch); + } -void PartSet_WidgetSketchLabel::updateLabel(PartSet_OperationSketch* theSketchOpe) +void PartSet_WidgetSketchLabel::activate() { - if (theSketchOpe->hasSketchPlane()) { - myLabel->setText(""); - myLabel->setToolTip(""); + std::shared_ptr aPlane = plane(); + if (aPlane) { + setSketchingMode(); } else { + // We have to select a plane before any operation + showPreviewPlanes(); + + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->openLocalContext(); + aDisp->activateObjectsOutOfContext(QIntList()); + if (myPlaneFilter.IsNull()) + myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane); + aDisp->addSelectionFilter(myPlaneFilter); + QIntList aModes; + aModes << TopAbs_FACE; + aDisp->setSelectionModes(aModes); + myLabel->setText(myText); myLabel->setToolTip(myTooltip); + + connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onPlaneSelected())); + aDisp->updateViewer(); } } + +void PartSet_WidgetSketchLabel::deactivate() +{ + + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->removeSelectionFilter(myPlaneFilter); + //aDisp->removeSelectionFilter(mySketchFilter); + aDisp->closeLocalContexts(); + erasePreviewPlanes(); +} + +void PartSet_WidgetSketchLabel::erasePreviewPlanes() +{ + if (myPreviewDisplayed) { + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->eraseAIS(myYZPlane, false); + aDisp->eraseAIS(myXZPlane, false); + aDisp->eraseAIS(myXYPlane, false); + myPreviewDisplayed = false; + } +} + +void PartSet_WidgetSketchLabel::showPreviewPlanes() +{ + if (myPreviewDisplayed) + return; + + if (!myYZPlane) { // If planes are not created + // Create Preview + std::shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); + std::shared_ptr aYZDir(new GeomAPI_Dir(1, 0, 0)); + std::shared_ptr aXZDir(new GeomAPI_Dir(0, 1, 0)); + std::shared_ptr aXYDir(new GeomAPI_Dir(0, 0, 1)); + + int aR[] = {255, 0, 0}; + int aG[] = {0, 255, 0}; + int aB[] = {0, 0, 255}; + + myYZPlane = createPreviewPlane(anOrigin, aYZDir, aR); + myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG); + myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB); + } + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->displayAIS(myYZPlane, false); + aDisp->displayAIS(myXZPlane, false); + aDisp->displayAIS(myXYPlane, false); + myPreviewDisplayed = true; +} + + +AISObjectPtr PartSet_WidgetSketchLabel::createPreviewPlane(std::shared_ptr theOrigin, + std::shared_ptr theNorm, + const int theRGB[3]) +{ + double aSize = Config_PropManager::integer("Sketch planes", "Size of planes", PLANE_SIZE); + std::shared_ptr aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize); + AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject()); + aAIS->createShape(aFace); + aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH)); + aAIS->setColor(theRGB[0], theRGB[1], theRGB[2]); + return aAIS; +} + + +std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape) +{ + if (theShape.IsNull()) + return std::shared_ptr(); + + // get selected shape + std::shared_ptr aGShape(new GeomAPI_Shape); + aGShape->setImpl(new TopoDS_Shape(theShape)); + + // get plane parameters + std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); + + // set plane parameters to feature + std::shared_ptr aData = feature()->data(); + double anA, aB, aC, aD; + aPlane->coefficients(anA, aB, aC, aD); + + // calculate attributes of the sketch + std::shared_ptr aNormDir(new GeomAPI_Dir(anA, aB, aC)); + std::shared_ptr aCoords = aNormDir->xyz(); + std::shared_ptr aZero(new GeomAPI_XYZ(0, 0, 0)); + aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero)); + std::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); + // X axis is preferable to be dirX on the sketch + const double tol = Precision::Confusion(); + bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol; + std::shared_ptr aTempDir( + isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); + std::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); + std::shared_ptr aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir))); + + std::shared_ptr anOrigin = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + anOrigin->setValue(anOrigPnt); + std::shared_ptr aNormal = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::NORM_ID())); + aNormal->setValue(aNormDir); + std::shared_ptr aDirX = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::DIRX_ID())); + aDirX->setValue(aXDir); + std::shared_ptr aDirY = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::DIRY_ID())); + aDirY->setValue(aYDir); + std::shared_ptr aDir = aPlane->direction(); + return aDir; +} + + +void PartSet_WidgetSketchLabel::setSketchingMode() +{ + XGUI_Displayer* aDisp = myWorkshop->displayer(); + QIntList aModes; + // Clear standard selection modes if they are defined + aDisp->setSelectionModes(aModes); + aDisp->openLocalContext(); + + // Set filter + std::shared_ptr aPlane = plane(); + double aA, aB, aC, aD; + aPlane->coefficients(aA, aB, aC, aD); + gp_Pln aPln(aA, aB, aC, aD); + // No selection of external objects + //mySketchFilter = new ModuleBase_ShapeInPlaneFilter(aPln); + //aDisp->addSelectionFilter(mySketchFilter); + + // Get default selection modes + aModes.append(AIS_DSM_Text); + aModes.append(AIS_DSM_Line); + aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); + aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); + + aDisp->activateObjectsOutOfContext(aModes); +} diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 5ad06d65d..7c1d460be 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -8,10 +8,19 @@ #include "PartSet.h" #include +#include + +#include +#include +#include + +#include +#include class QLabel; class XGUI_OperationMgr; -class PartSet_OperationSketch; +class XGUI_Workshop; +//class PartSet_OperationSketch; class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_ModelWidget { @@ -20,9 +29,7 @@ Q_OBJECT PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); - virtual ~PartSet_WidgetSketchLabel() - { - } + virtual ~PartSet_WidgetSketchLabel(); /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed @@ -42,17 +49,46 @@ Q_OBJECT QWidget* getControl() const; - void setOperationsMgr(XGUI_OperationMgr* theMgr); + /// The methiod called when widget is activated + virtual void activate(); + + /// The methiod called when widget is deactivated + virtual void deactivate(); + + XGUI_Workshop* workshop() const { return myWorkshop; } + + void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; } + + std::shared_ptr plane() const; private slots: void onPlaneSelected(); private: - void updateLabel(PartSet_OperationSketch* theSketchOpe); + AISObjectPtr createPreviewPlane(std::shared_ptr theOrigin, + std::shared_ptr theNorm, + const int theRGB[3]); + + std::shared_ptr setSketchPlane(const TopoDS_Shape& theShape); + + void erasePreviewPlanes(); + void showPreviewPlanes(); + + void setSketchingMode(); QLabel* myLabel; QString myText; QString myTooltip; + + XGUI_Workshop* myWorkshop; + + AISObjectPtr myYZPlane; + AISObjectPtr myXZPlane; + AISObjectPtr myXYPlane; + bool myPreviewDisplayed; + + Handle(StdSelect_FaceFilter) myPlaneFilter; + //Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter; }; #endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 611d85a0f..97d41154c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -101,12 +101,18 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi // value calculation std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE())); - double aValue = aValueAttr->value(); + // TODO: has to be calculated on definition of reference object + double aValue; // Issue #196: checking the positivity of the distance constraint // there is a validator for a distance constraint, that the value should be positive // in case if an invalid value is set, the current distance value is shown - if (aValue <= 0) + if (aValueAttr->isInitialized()) + aValue = aValueAttr->value(); + else { aValue = calculateCurrentDistance(); + aValueAttr->setValue(aValue); + } + // End TODO AISObjectPtr anAIS = thePrevious; if (!anAIS) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 5b3d0f05f..5799a3a12 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -43,11 +43,11 @@ void SketchPlugin_ConstraintLength::execute() double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); - std::shared_ptr aValueAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); - if(!aValueAttr->isInitialized()) { - aValueAttr->setValue(aLenght); - } + //std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + // ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); + //if(!aValueAttr->isInitialized()) { + // aValueAttr->setValue(aLenght); + //} } } @@ -89,9 +89,16 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y()); } // value calculation + // TODO: has to be calculated on definition of reference object + double aDistance = aPoint1->distance(aPoint2); std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); - double aValue = aValueAttr->value(); + double aValue = aDistance; + if (aValueAttr->isInitialized()) + aValue = aValueAttr->value(); + else + aValueAttr->setValue(aValue); + // End TODO AISObjectPtr anAIS = thePrevious; if (!anAIS) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 8da7b3606..3aa6cba13 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -53,11 +53,11 @@ void SketchPlugin_ConstraintRadius::execute() if (aCenterAttr && aStartAttr) aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); } - std::shared_ptr aValueAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); - if(!aValueAttr->isInitialized()) { - aValueAttr->setValue(aRadius); - } + //std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + // ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); + //if(!aValueAttr->isInitialized()) { + // aValueAttr->setValue(aRadius); + //} } } @@ -85,14 +85,14 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou } // Prepare a circle - aData = aFeature->data(); + std::shared_ptr aCyrcData = aFeature->data(); std::shared_ptr aCenterAttr; double aRadius; if (aKind == SketchPlugin_Circle::ID()) { aCenterAttr = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Circle::CENTER_ID())); + aCyrcData->attribute(SketchPlugin_Circle::CENTER_ID())); AttributeDoublePtr aCircRadius = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Circle::RADIUS_ID())); + aCyrcData->attribute(SketchPlugin_Circle::RADIUS_ID())); aRadius = aCircRadius->value(); if (!aFlyoutPnt) { double aShift = aRadius * 1.1; @@ -104,13 +104,13 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou } } else if (aKind == SketchPlugin_Arc::ID()) { aCenterAttr = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Arc::CENTER_ID())); + aCyrcData->attribute(SketchPlugin_Arc::CENTER_ID())); std::shared_ptr aStartAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::START_ID())); + GeomDataAPI_Point2D>(aCyrcData->attribute(SketchPlugin_Arc::START_ID())); aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); if (!aFlyoutPnt) { std::shared_ptr aStartAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Arc::START_ID())); + GeomDataAPI_Point2D>(aCyrcData->attribute(SketchPlugin_Arc::START_ID())); aFlyoutAttr->setValue(aStartAttr->pnt()); aFlyoutPnt = sketch()->to3D(aStartAttr->pnt()->x(), aStartAttr->pnt()->y()); } @@ -123,12 +123,16 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou std::shared_ptr aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius)); // Value + // TODO: has to be calculated on definition of reference object std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE())); double aValue = aRadius; - if (aValueAttr && aValueAttr->isInitialized()) + if (aValueAttr->isInitialized()) aValue = aValueAttr->value(); - + else { + aValueAttr->setValue(aValue); + } + // End TODO AISObjectPtr anAIS = thePrevious; if (!anAIS) anAIS = AISObjectPtr(new GeomAPI_AISObject); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 4902305a8..213d38502 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -215,45 +215,45 @@ std::shared_ptr SketchPlugin_Sketch::plane() return std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); } -void addPlane(double theX, double theY, double theZ, - std::list >& theShapes) -{ - std::shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); - std::shared_ptr aNormal(new GeomAPI_Dir(theX, theY, theZ)); - double aSize = Config_PropManager::integer("Sketch planes", "Size of planes", PLANE_SIZE); - std::shared_ptr aFace = GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, - aSize); - theShapes.push_back(aFace); -} - -AISObjectPtr SketchPlugin_Sketch::getAISObject(AISObjectPtr thePrevious) -{ - std::shared_ptr aNorm = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::NORM_ID())); - - if (!aNorm || (aNorm->x() == 0 && aNorm->y() == 0 && aNorm->z() == 0)) { - AISObjectPtr aAIS = thePrevious; - if (!aAIS) { - std::list > aFaces; - - addPlane(1, 0, 0, aFaces); // YZ plane - addPlane(0, 1, 0, aFaces); // XZ plane - addPlane(0, 0, 1, aFaces); // XY plane - std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); - aAIS = AISObjectPtr(new GeomAPI_AISObject()); - aAIS->createShape(aCompound); - - std::vector aRGB = Config_PropManager::color("Sketch planes", "planes_color", - SKETCH_PLANE_COLOR); - aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); - - aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", - SKETCH_WIDTH)); - } - return aAIS; - } - return AISObjectPtr(); -} +//void addPlane(double theX, double theY, double theZ, +// std::list >& theShapes) +//{ +// std::shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); +// std::shared_ptr aNormal(new GeomAPI_Dir(theX, theY, theZ)); +// double aSize = Config_PropManager::integer("Sketch planes", "Size of planes", PLANE_SIZE); +// std::shared_ptr aFace = GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, +// aSize); +// theShapes.push_back(aFace); +//} + +//AISObjectPtr SketchPlugin_Sketch::getAISObject(AISObjectPtr thePrevious) +//{ +// std::shared_ptr aNorm = std::dynamic_pointer_cast( +// data()->attribute(SketchPlugin_Sketch::NORM_ID())); +// +// if (!aNorm || (aNorm->x() == 0 && aNorm->y() == 0 && aNorm->z() == 0)) { +// AISObjectPtr aAIS = thePrevious; +// if (!aAIS) { +// std::list > aFaces; +// +// addPlane(1, 0, 0, aFaces); // YZ plane +// addPlane(0, 1, 0, aFaces); // XZ plane +// addPlane(0, 0, 1, aFaces); // XY plane +// std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); +// aAIS = AISObjectPtr(new GeomAPI_AISObject()); +// aAIS->createShape(aCompound); +// +// std::vector aRGB = Config_PropManager::color("Sketch planes", "planes_color", +// SKETCH_PLANE_COLOR); +// aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); +// +// aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", +// SKETCH_WIDTH)); +// } +// return aAIS; +// } +// return AISObjectPtr(); +//} void SketchPlugin_Sketch::erase() { diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index c4802d483..66795f7bc 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -25,7 +25,7 @@ * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. */ -class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPresentable +class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_IPresentable { public: /// Sketch feature kind @@ -109,7 +109,7 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPr /// Returns the basis plane for the sketch std::shared_ptr plane(); - virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); /// removes also all sub-sketch elements SKETCHPLUGIN_EXPORT virtual void erase(); diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 82ba507be..d0881383b 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -6,22 +6,22 @@ - + - - + + - + - - - + + + @@ -30,18 +30,11 @@