Creation of the operation manager to provide the operations stack.
LoadPluginsInfo();
if (myPlugins.find(theFeatureID) != myPlugins.end()) {
- if (myPluginObjs.find(myPlugins[theFeatureID]) == myPluginObjs.end()) {
+ myCurrentPluginName = myPlugins[theFeatureID];
+ if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
// load plugin library if not yet done
- myCurrentPluginName = myPlugins[theFeatureID];
loadLibrary(myCurrentPluginName);
}
if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
return myOperationId;
}
+/*!
+ * \brief Replied whether the operation should be commited after the start, or the operation itself
+ * do that. The default realization provides the check by the operation having the xml prepresentation
+ * @return the boolean value
+ */
+bool ModuleBase_Operation::isPerformedImmediately() const
+{
+ return xmlRepresentation().isEmpty();
+}
+
std::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
{
return myFeature;
// Operation processing.
virtual QString operationId() const;
+ virtual bool isPerformedImmediately() const;
+
std::shared_ptr<ModelAPI_Feature> feature() const;
OperationState state() const;
#include <XGUI_MainWindow.h>
#include <XGUI_Displayer.h>
+#include <XGUI_Viewer.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_OperationMgr.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
{
myWorkshop = theWshop;
+ XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
+
+ connect(anOperationMgr, SIGNAL(beforeOperationStart()), this, SLOT(onBeforeOperationStart()));
}
PartSet_Module::~PartSet_Module()
else
aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(aPartSetOp);
- if (aPreviewOp)
- connect(aPreviewOp, SIGNAL(visualizePreview()), this, SLOT(onVisualizePreview()));
-
aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
aPartSetOp->setDescription(QString::fromStdString(aDescription));
aMessage.setPointer(aPartSetOp);
Event_Loop::loop()->send(aMessage);
}
-void PartSet_Module::onVisualizePreview()
+/**
+ * Slot that is called by the operation requiring of preview display or erase
+ * \param isDisplay the display or erase state
+*/
+void PartSet_Module::onVisualizePreview(bool isDisplay)
{
- ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
if (!anOperation)
return;
if (!aPreviewOp)
return;
- myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview());
+ if (isDisplay)
+ myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview());
+ else
+ myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
+}
+
+void PartSet_Module::onBeforeOperationStart()
+{
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ connect(anOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
+ connect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
+ connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+ aPreviewOp, SLOT(onViewSelectionChanged()));
+ }
+}
+
+void PartSet_Module::onOperationStopped()
+{
+ ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(sender());
+ if (!anOperation)
+ return;
+
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ disconnect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
+ disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+ aPreviewOp, SLOT(onViewSelectionChanged()));
+ }
}
public slots:
void onFeatureTriggered();
- void onVisualizePreview();
+ void onBeforeOperationStart();
+ void onOperationStopped();
+ void onVisualizePreview(bool isDisplay);
private:
XGUI_Workshop* myWorkshop;
PartSet_OperationSketch::~PartSet_OperationSketch()
{
}
+
+/**
+ * The sketch can not be created immediately, firstly a plane should be set
+ * \return false value
+ */
+bool PartSet_OperationSketch::isPerformedImmediately() const
+{
+ return false;
+}
public:
PartSet_OperationSketch(const QString& theId, QObject* theParent);
virtual ~PartSet_OperationSketch();
+
+ virtual bool isPerformedImmediately() const;
};
#endif
{
ModuleBase_PropPanelOperation::startOperation();
- emit visualizePreview();
+ emit visualizePreview(true);
+}
+
+/*!
+ * Perform the operation stop and emit signal about visualization stop of the operation preview
+ */
+void PartSet_OperationSketchBase::stopOperation()
+{
+ ModuleBase_PropPanelOperation::stopOperation();
+
+ emit visualizePreview(false);
}
const TopoDS_Shape& preview() const;
signals:
- void visualizePreview();
+ /**
+ * The signal about preview visualization.
+ * \param isDisplay a state whether the preview should be displayed or erased
+ */
+ void visualizePreview(bool isDisplay);
protected:
virtual void startOperation();
+ virtual void stopOperation();
};
#endif
XGUI_MainMenu.h
XGUI_MainWindow.h
XGUI_MenuGroupPanel.h
+ XGUI_Module.h
XGUI_Tools.h
XGUI_Workbench.h
XGUI_Workshop.h
XGUI_DocumentDataModel.h
XGUI_PartDataModel.h
XGUI_ObjectsBrowser.h
+ XGUI_OperationMgr.h
XGUI_DataTreeModel.h
XGUI_SelectionMgr.h
XGUI_SwitchWidget.h
XGUI_DocumentDataModel.cpp
XGUI_PartDataModel.cpp
XGUI_ObjectsBrowser.cpp
+ XGUI_OperationMgr.cpp
XGUI_SelectionMgr.cpp
XGUI_SwitchWidget.cpp
)
aContext->UpdateCurrentViewer();
}
+
+/*!
+ * Erase the feature and a shape.
+ * \param theFeature a feature instance
+ * \param theFeature a shape
+ */
+void XGUI_Displayer::Erase(std::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape)
+{
+ Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
+ aContext->EraseAll();
+}
void Display(std::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
+ void Erase(std::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
+
protected:
XGUI_Viewer* myViewer; ///< the viewer
};
\r
#define CREATE_MODULE "createModule"\r
\r
-#endif //XGUI_Module\r
\ No newline at end of file
+#endif //XGUI_Module\r
--- /dev/null
+#include "XGUI_OperationMgr.h"
+
+#include "ModuleBase_Operation.h"
+
+#include <QMessageBox>
+
+/*!
+ \brief Constructor
+ */
+XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
+: QObject(theParent)
+{
+}
+
+/*!
+ \brief Destructor
+ */
+XGUI_OperationMgr::~XGUI_OperationMgr()
+{
+}
+
+/*!
+ \brief Returns the current operation or NULL
+ * \return the current operation
+ */
+ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
+{
+ return myOperations.count() > 0 ? myOperations.last() : 0;
+}
+
+/*!
+ \brief Sets the current operation or NULL
+ * \return the current operation
+ */
+bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
+{
+ if (!canStartOperation(theOperation))
+ return false;
+
+ myOperations.append(theOperation);
+ emit beforeOperationStart();
+
+ connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
+ theOperation->start();
+
+ emit afterOperationStart();
+ return true;
+}
+
+bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
+{
+ bool aCanStart = true;
+ ModuleBase_Operation* aCurrentOp = currentOperation();
+ if (aCurrentOp && !theOperation->isGranted())
+ {
+ int anAnswer = QMessageBox::question(0, tr("Operation launch"),
+ tr("Previous operation is not finished and will be aborted"),
+ QMessageBox::Ok, QMessageBox::Cancel);
+ if (anAnswer == QMessageBox::Ok)
+ aCurrentOp->abort();
+ else
+ aCanStart = false;
+ }
+ return aCanStart;
+}
+
+void XGUI_OperationMgr::commitCurrentOperation()
+{
+ ModuleBase_Operation* anOperation = currentOperation();
+ if (!anOperation)
+ return;
+
+ anOperation->commit();
+}
+
+void XGUI_OperationMgr::onOperationStopped()
+{
+ ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+ ModuleBase_Operation* anOperation = currentOperation();
+ if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
+ return;
+
+ myOperations.removeAll(anOperation);
+
+ // get last operation which can be resumed
+ ModuleBase_Operation* aResultOp = 0;
+ QListIterator<ModuleBase_Operation*> anIt(myOperations);
+ anIt.toBack();
+ while(anIt.hasPrevious())
+ {
+ ModuleBase_Operation* anOp = anIt.previous();
+ if (anOp) {
+ aResultOp = anOp;
+ break;
+ }
+ }
+ if (aResultOp)
+ startOperation(aResultOp);
+}
--- /dev/null
+#ifndef XGUI_OperationMgr_H
+#define XGUI_OperationMgr_H
+
+#include "XGUI.h"
+
+#include <ModuleBase_Operation.h>
+
+#include <QList>
+#include <QObject>
+
+/**\class XGUI_OperationMgr
+ * \ingroup GUI
+ * \brief Operation manager. Servers to manupulate to the workshop operations. Contains a stack
+ * of started operations and uses the upper one as a current.
+ */
+class XGUI_EXPORT XGUI_OperationMgr : public QObject
+{
+ Q_OBJECT
+public:
+ XGUI_OperationMgr(QObject* theParent);
+ virtual ~XGUI_OperationMgr();
+
+ ModuleBase_Operation* currentOperation() const;
+ bool startOperation(ModuleBase_Operation* theOperation);
+
+ void commitCurrentOperation();
+
+signals:
+ void beforeOperationStart();
+ void afterOperationStart();
+
+protected:
+ bool canStartOperation(ModuleBase_Operation* theOperation);
+
+protected slots:
+ void onOperationStopped();
+
+private:
+ typedef QList<ModuleBase_Operation*> Operations;
+ Operations myOperations;
+};
+
+#endif
#include "XGUI_SelectionMgr.h"
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_Displayer.h"
+#include "XGUI_OperationMgr.h"
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Feature.h>
XGUI_Workshop::XGUI_Workshop()
: QObject(),
- myCurrentOperation(NULL),
myPartSetModule(NULL)
{
myMainWindow = new XGUI_MainWindow();
mySelector = new XGUI_SelectionMgr(this);
myDisplayer = new XGUI_Displayer(myMainWindow->viewer());
+ myOperationMgr = new XGUI_OperationMgr(this);
+ connect(myOperationMgr, SIGNAL(beforeOperationStart()), this, SLOT(onBeforeOperationStart()));
+ connect(myOperationMgr, SIGNAL(afterOperationStart()), this, SLOT(onAfterOperationStart()));
}
//******************************************************
const Config_PointerMessage* aPartSetMsg =
dynamic_cast<const Config_PointerMessage*>(theMessage);
if (aPartSetMsg) {
- ModuleBase_PropPanelOperation* aOperation =
+ ModuleBase_PropPanelOperation* anOperation =
(ModuleBase_PropPanelOperation*)(aPartSetMsg->pointer());
- setCurrentOperation(aOperation);
- if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
- myCurrentOperation->start();
- myCurrentOperation->commit();
- updateCommandStatus();
- } else {
- fillPropertyPanel(aOperation);
+
+ if (myOperationMgr->startOperation(anOperation))
+ {
+ if (anOperation->isPerformedImmediately())
+ {
+ myOperationMgr->commitCurrentOperation();
+ updateCommandStatus();
+ }
+ /*if(anOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
+ //connectToPropertyPanel(anOperation);
+
+ anOperation->start();
+
+ if (anOperation->isPerformedImmediately()) {
+ anOperation->commit();
+ updateCommandStatus();
+ }
+ } else {
+ connectToPropertyPanel(anOperation);
+ QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
+ qDeleteAll(aPropWidget->children());
+
+ anOperation->start();
+
+ XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(anOperation);
+ aFactory.createWidget(aPropWidget);
+ myMainWindow->setPropertyPannelTitle(anOperation->description());
+ }*/
}
return;
}
}
+void XGUI_Workshop::onBeforeOperationStart()
+{
+ ModuleBase_PropPanelOperation* aOperation =
+ (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation());
+
+ if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
+ //myPartSetModule->connectToPropertyPanel(aOperation);
+ } else {
+ connectToPropertyPanel(aOperation);
+ QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
+ qDeleteAll(aPropWidget->children());
+ }
+}
+
+void XGUI_Workshop::onAfterOperationStart()
+{
+ ModuleBase_PropPanelOperation* aOperation =
+ (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation());
+
+ if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
+ } else {
+ XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aOperation);
+ QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
+ aFactory.createWidget(aPropWidget);
+ myMainWindow->setPropertyPannelTitle(aOperation->description());
+ }
+}
+
/*
*
*/
/*
*
*/
-void XGUI_Workshop::fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation)
+/*void XGUI_Workshop::fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation)
{
connectToPropertyPanel(theOperation);
QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(theOperation);
aFactory.createWidget(aPropWidget);
myMainWindow->setPropertyPannelTitle(theOperation->description());
-}
-
-void XGUI_Workshop::setCurrentOperation(ModuleBase_Operation* theOperation)
-{
- //FIXME: Ask user about aborting of current operation?
- if (myCurrentOperation) {
- //TODO get isOperation from document
- if (myCurrentOperation->isRunning())
- myCurrentOperation->abort();
-
- myCurrentOperation->deleteLater();
- }
- myCurrentOperation = theOperation;
-}
+}*/
/*
* Makes a signal/slot connections between Property Panel
class XGUI_Workbench;
class XGUI_SelectionMgr;
class XGUI_Displayer;
+class XGUI_OperationMgr;
class ModuleBase_Operation;
class ModuleBase_PropPanelOperation;
//! Returns displayer
XGUI_Displayer* displayer() const { return myDisplayer; }
+ //! ! Returns operation manager.
+ XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
+
//! Creates and adds a new workbench (menu group) with the given name and returns it
XGUI_Workbench* addWorkbench(const QString& theName);
- //! Returns the current operation or NULL
- ModuleBase_Operation* currentOperation() { return myCurrentOperation; }
-
//! Redefinition of Event_Listener method
virtual void processEvent(const Event_Message* theMessage);
protected:
//Event-loop processing methods:
void addFeature(const Config_FeatureMessage*);
- void fillPropertyPanel(ModuleBase_PropPanelOperation* theOperation);
void connectToPropertyPanel(ModuleBase_Operation* theOperation);
- void setCurrentOperation(ModuleBase_Operation* theOperation);
+
+protected slots:
+ void onBeforeOperationStart();
+ void onAfterOperationStart();
private:
void initMenu();
XGUI_SelectionMgr* mySelector;
XGUI_Displayer* myDisplayer;
- ModuleBase_Operation* myCurrentOperation;
+ XGUI_OperationMgr* myOperationMgr;
};
#endif