From 3950546b72ab1ff2c303c4314e0d2d7574a1629c Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 25 Apr 2014 17:33:45 +0400 Subject: [PATCH] Connect operations to SALOME (Issue #31) --- src/NewGeom/NewGeom_Module.cpp | 108 ++++++++++++- src/NewGeom/NewGeom_Module.h | 38 ++++- src/PartSet/PartSet_Module.cpp | 19 ++- src/PartSet/PartSet_Module.h | 2 + src/XGUI/CMakeLists.txt | 1 + src/XGUI/XGUI_MainWindow.cpp | 107 +------------ src/XGUI/XGUI_MainWindow.h | 20 --- src/XGUI/XGUI_Module.h | 2 + src/XGUI/XGUI_SalomeConnector.h | 39 +++++ src/XGUI/XGUI_SelectionMgr.cpp | 2 +- src/XGUI/XGUI_Workshop.cpp | 261 +++++++++++++++++++++++++------- src/XGUI/XGUI_Workshop.h | 35 ++++- 12 files changed, 442 insertions(+), 192 deletions(-) create mode 100644 src/XGUI/XGUI_SalomeConnector.h diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index e5f2ec1ee..affe26d79 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -3,8 +3,12 @@ #include "NewGeom_Module.h" #include "NewGeom_DataModel.h" +#include + #include #include +#include +#include extern "C" { @@ -18,44 +22,140 @@ extern "C" { } - +//****************************************************** NewGeom_Module::NewGeom_Module() : LightApp_Module( "NewGeom" ) { + myWorkshop = new XGUI_Workshop(this); } - +//****************************************************** NewGeom_Module::~NewGeom_Module() { } +//****************************************************** void NewGeom_Module::initialize(CAM_Application* theApp) { LightApp_Module::initialize(theApp); + + myWorkshop->startApplication(); } +//****************************************************** void NewGeom_Module::windows(QMap& theWndMap) const { theWndMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea ); } +//****************************************************** void NewGeom_Module::viewManagers(QStringList& theList) const { theList.append( OCCViewer_Viewer::Type() ); } +//****************************************************** bool NewGeom_Module::activateModule(SUIT_Study* theStudy) { - return LightApp_Module::activateModule(theStudy); + bool isDone = LightApp_Module::activateModule(theStudy); + if (isDone) { + setMenuShown( true ); + setToolShown( true ); + } + return isDone; } +//****************************************************** bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy) { + setMenuShown( false ); + setToolShown( false ); return LightApp_Module::deactivateModule(theStudy); } +//****************************************************** CAM_DataModel* NewGeom_Module::createDataModel() { - return new NewGeom_DataModel(this); + return new NewGeom_DataModel( this ); +} + +//****************************************************** +void NewGeom_Module::addFeature(const QString& theWBName, + const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + bool isCheckable, + QObject* theReciever, + const char* theMember, + const QKeySequence& theKeys) +{ + int aMenu = createMenu(theWBName, -1, -1, 50); + int aTool = createTool(theWBName); + + int aId = myActionsList.size(); + myActionsList.append(theId); + SUIT_Desktop* aDesk = application()->desktop(); + int aKeys = 0; + for (int i = 0; i < theKeys.count(); i++) + aKeys += theKeys[i]; + createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, + isCheckable, theReciever, theMember); + int aItemId = createMenu( aId, aMenu, -1, 10 ); + int aToolId = createTool( aId, aTool ); +} + +//****************************************************** +void NewGeom_Module::addEditCommand(const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + bool isCheckable, + QObject* theReciever, + const char* theMember, + const QKeySequence& theKeys) +{ + int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1); + + int aId = myActionsList.size(); + myActionsList.append(theId); + SUIT_Desktop* aDesk = application()->desktop(); + int aKeys = 0; + for (int i = 0; i < theKeys.count(); i++) + aKeys += theKeys[i]; + createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, + isCheckable, theReciever, theMember); + createMenu( aId, aMenu, 10 ); } +//****************************************************** +void NewGeom_Module::addEditMenuSeparator() +{ + int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1); + createMenu( separator(), aMenu, -1, 10 ); +} + +//****************************************************** +QMainWindow* NewGeom_Module::desktop() const +{ + return application()->desktop(); +} + +//****************************************************** +QString NewGeom_Module::commandId(const QAction* theCmd) const +{ + int aId = actionId(theCmd); + if (aId < myActionsList.size()) + return myActionsList[aId]; + return QString(); +} + +//****************************************************** +QAction* NewGeom_Module::command(const QString& theId) const +{ + int aId = myActionsList.indexOf(theId); + if ((aId != -1) && (aId < myActionsList.size())) { + return action(aId); + } + return 0; +} \ No newline at end of file diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index b18ff6606..8df0ef372 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -4,9 +4,15 @@ #define NewGeom_Module_H #include "NewGeom.h" + #include +#include + +#include + +class XGUI_Workshop; -class NewGeom_EXPORT NewGeom_Module: public LightApp_Module +class NewGeom_EXPORT NewGeom_Module: public LightApp_Module, public XGUI_SalomeConnector { Q_OBJECT public: @@ -17,6 +23,34 @@ public: virtual void windows( QMap& theWndMap) const; virtual void viewManagers( QStringList& theList) const; + //--- XGUI connector interface ----- + virtual void addFeature(const QString& theWBName, + const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + bool isCheckable = false, + QObject* reciever = 0, + const char* member = 0, + const QKeySequence& theKeys = QKeySequence()); + + virtual void addEditCommand(const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + bool isCheckable, + QObject* reciever, + const char* member, + const QKeySequence& theKeys); + + virtual void addEditMenuSeparator(); + + virtual QMainWindow* desktop() const; + + virtual QString commandId(const QAction* theCmd) const; + + virtual QAction* command(const QString& theId) const; + public slots: bool activateModule( SUIT_Study* theStudy); bool deactivateModule( SUIT_Study* theStudy); @@ -26,7 +60,9 @@ protected: private: + QStringList myActionsList; + XGUI_Workshop* myWorkshop; }; #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e0d4d32b9..c53208916 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -39,8 +39,9 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); - connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), - this, SLOT(onViewSelectionChanged())); + if (!myWorkshop->isSalomeMode()) + connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), + this, SLOT(onViewSelectionChanged())); } PartSet_Module::~PartSet_Module() @@ -70,18 +71,22 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId) void PartSet_Module::onFeatureTriggered() { XGUI_Command* aCmd = dynamic_cast(sender()); - QString aCmdId = aCmd->id(); - std::string aStdCmdId = aCmdId.toStdString(); + launchOperation(aCmd->id()); +} + +void PartSet_Module::launchOperation(const QString& theCmdId) +{ + std::string aStdCmdId = theCmdId.toStdString(); std::string aPluginFileName = featureFile(aStdCmdId); Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); aWdgReader.readAll(); std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId); std::string aDescription = aWdgReader.featureDescription(aStdCmdId); ModuleBase_PropPanelOperation* aPartSetOp; - if (aCmdId == "Sketch" ) { - aPartSetOp = new PartSet_OperationSketch(aCmdId, this); + if (theCmdId == "Sketch" ) { + aPartSetOp = new PartSet_OperationSketch(theCmdId, this); } else { - aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this); + aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this); } aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg)); aPartSetOp->setDescription(QString::fromStdString(aDescription)); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index fcf98a0c3..441014dde 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -23,6 +23,8 @@ public: virtual void featureCreated(XGUI_Command* theFeature); std::string featureFile(const std::string&); + virtual void launchOperation(const QString& theCmdId); + public slots: void onFeatureTriggered(); /// SLOT, that is called after the operation is started. Perform some specific for module diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index a246e4060..3741d32e6 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -27,6 +27,7 @@ SET(PROJECT_HEADERS XGUI_DataTreeModel.h XGUI_SelectionMgr.h XGUI_SwitchWidget.h + XGUI_SalomeConnector.h ) SET(PROJECT_AUTOMOC diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index b675c5fd7..cbc3e67f3 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -28,9 +28,7 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), - myObjectBrowser(0), - myPythonConsole(0), - myPropertyPanelDock(0) + myPythonConsole(0) { setWindowTitle(tr("New Geom")); myMenuBar = new XGUI_MainMenu(this); @@ -39,8 +37,6 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) setCentralWidget(aMdiArea); myViewer = new XGUI_Viewer(this); - - //createDockWidgets(); } XGUI_MainWindow::~XGUI_MainWindow(void) @@ -53,18 +49,6 @@ QMdiArea* XGUI_MainWindow::mdiArea() const return static_cast(centralWidget()); } -//****************************************************** -void XGUI_MainWindow::showObjectBrowser() -{ - myObjectBrowser->parentWidget()->show(); -} - -//****************************************************** -void XGUI_MainWindow::hideObjectBrowser() -{ - myObjectBrowser->parentWidget()->hide(); -} - //****************************************************** void XGUI_MainWindow::showPythonConsole() { @@ -89,93 +73,4 @@ void XGUI_MainWindow::hidePythonConsole() myPythonConsole->parentWidget()->hide(); } -void XGUI_MainWindow::showPropertyPanel() -{ - QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); - //setEnabled(true); - myPropertyPanelDock->show(); - myPropertyPanelDock->raise(); -} - -void XGUI_MainWindow::hidePropertyPanel() -{ - QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); - //setEnabled(false); - myPropertyPanelDock->hide(); -} -/* - * Creates dock widgets, places them in corresponding area - * and tabifies if necessary. - */ -void XGUI_MainWindow::createDockWidgets() -{ - QDockWidget* aObjDock = createObjectBrowser(); - addDockWidget(Qt::LeftDockWidgetArea, aObjDock); - myPropertyPanelDock = createPropertyPanel(); - addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock); - hidePropertyPanel(); //setWindowTitle(theTitle); -} - - -QDockWidget* XGUI_MainWindow::createPropertyPanel() -{ - QDockWidget* aPropPanel = new QDockWidget(this); - aPropPanel->setWindowTitle(tr("Property Panel")); - QAction* aViewAct = aPropPanel->toggleViewAction(); - aPropPanel->setObjectName(XGUI::PROP_PANEL); - - QWidget* aContent = new QWidget(aPropPanel); - QVBoxLayout* aMainLay = new QVBoxLayout(aContent); - aMainLay->setContentsMargins(3, 3, 3, 3); - aPropPanel->setWidget(aContent); - - QFrame* aFrm = new QFrame(aContent); - aFrm->setFrameStyle(QFrame::Sunken); - aFrm->setFrameShape(QFrame::Panel); - QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); - aBtnLay->setContentsMargins(0, 0, 0, 0); - aMainLay->addWidget(aFrm); - - QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); - aBtn->setFlat(true); - //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyHelpPressed())); - aBtnLay->addWidget(aBtn); - aBtnLay->addStretch(1); - aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); - aBtn->setObjectName(XGUI::PROP_PANEL_OK); - aBtn->setFlat(true); - //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyOkPressed())); - aBtnLay->addWidget(aBtn); - aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); - aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL); - aBtn->setFlat(true); - //connect(aBtn, SIGNAL(clicked()), this, SIGNAL(propertyClosePressed())); - aBtnLay->addWidget(aBtn); - - QWidget* aCustomWidget = new QWidget(aContent); - aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG); - aMainLay->addWidget(aCustomWidget); - aMainLay->addStretch(1); - - return aPropPanel; -} - -QDockWidget* XGUI_MainWindow::createObjectBrowser() -{ - QDockWidget* aObjDock = new QDockWidget(this); - aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - aObjDock->setWindowTitle(tr("Object browser")); - myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock); - aObjDock->setWidget(myObjectBrowser); - return aObjDock; -} diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 2a71a876a..553aa2735 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -6,7 +6,6 @@ class XGUI_MainMenu; class XGUI_Viewer; -class XGUI_ObjectsBrowser; class QMdiArea; class PyConsole_EnhConsole; @@ -29,12 +28,6 @@ public: return myMenuBar; } - //! Returns Object browser - XGUI_ObjectsBrowser* objectBrowser() const - { - return myObjectBrowser; - } - //! Returns MDI area QMdiArea* mdiArea() const; @@ -44,25 +37,12 @@ public: return myViewer; } - // Creates Dock widgets: Object broewser and Property panel - void createDockWidgets(); - void setPropertyPannelTitle(const QString& theTitle); - public slots: void showPythonConsole(); void hidePythonConsole(); - void showPropertyPanel(); - void hidePropertyPanel(); - void showObjectBrowser(); - void hideObjectBrowser(); private: - QDockWidget* createObjectBrowser(); - QDockWidget* createPropertyPanel(); - XGUI_MainMenu* myMenuBar; - XGUI_ObjectsBrowser* myObjectBrowser; - QDockWidget* myPropertyPanelDock; XGUI_Viewer* myViewer; diff --git a/src/XGUI/XGUI_Module.h b/src/XGUI/XGUI_Module.h index 347cc061a..48de0ad69 100644 --- a/src/XGUI/XGUI_Module.h +++ b/src/XGUI/XGUI_Module.h @@ -2,6 +2,7 @@ #define XGUI_Module_H #include +#include class XGUI_Command; @@ -10,6 +11,7 @@ class XGUI_Module public: virtual void createFeatures() = 0; virtual void featureCreated(XGUI_Command*) = 0; + virtual void launchOperation(const QString& theCmdId) = 0; virtual ~XGUI_Module() {}; }; diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h new file mode 100644 index 000000000..b2384b62d --- /dev/null +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -0,0 +1,39 @@ +#ifndef XGUI_SALOMECONNECTOR_H +#define XGUI_SALOMECONNECTOR_H + +#include "XGUI.h" + +#include + +class QMainWindow; + +class XGUI_EXPORT XGUI_SalomeConnector +{ +public: + virtual void addFeature(const QString& theWBName, + const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + bool isCheckable, + QObject* reciever, + const char* member, + const QKeySequence& theKeys) = 0; + + virtual void addEditCommand(const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + bool isCheckable, + QObject* reciever, + const char* member, + const QKeySequence& theKeys) = 0; + virtual void addEditMenuSeparator() = 0; + + virtual QMainWindow* desktop() const = 0; + + virtual QString commandId(const QAction* theCmd) const = 0; + virtual QAction* command(const QString& theId) const = 0; +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 6421d278b..c2d2c3de3 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -27,7 +27,7 @@ XGUI_SelectionMgr::~XGUI_SelectionMgr() void XGUI_SelectionMgr::onSelectionChanged() { - XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->mainWindow()->objectBrowser(); + XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->objectBrowser(); mySelectedData = aObjBrowser->selectedData(); // Set current document diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index f653683a1..1835a13f0 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -13,6 +13,7 @@ #include "XGUI_ObjectsBrowser.h" #include "XGUI_Displayer.h" #include "XGUI_OperationMgr.h" +#include "XGUI_SalomeConnector.h" #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #ifdef _DEBUG #include @@ -42,13 +44,16 @@ #include #endif -XGUI_Workshop::XGUI_Workshop() +XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) : QObject(), - myPartSetModule(NULL) + myPartSetModule(NULL), + mySalomeConnector(theConnector), + myPropertyPanelDock(0), + myObjectBrowser(0) { - myMainWindow = new XGUI_MainWindow(); + myMainWindow = mySalomeConnector? 0 : new XGUI_MainWindow(); mySelector = new XGUI_SelectionMgr(this); - myDisplayer = new XGUI_Displayer(myMainWindow->viewer()); + myDisplayer = myMainWindow? new XGUI_Displayer(myMainWindow->viewer()) : 0; myOperationMgr = new XGUI_OperationMgr(this); connect(myOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), @@ -72,9 +77,10 @@ void XGUI_Workshop::startApplication() Events_ID aPartSetId = aLoop->eventByName("PartSetModuleEvent"); aLoop->registerListener(this, aPartSetId); activateModule(); - myMainWindow->show(); - - updateCommandStatus(); + if (myMainWindow) { + myMainWindow->show(); + updateCommandStatus(); + } onNew(); // Testing of document creation //boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); @@ -92,6 +98,21 @@ void XGUI_Workshop::startApplication() //****************************************************** void XGUI_Workshop::initMenu() { + if (isSalomeMode()) { + // Create only Undo, Redo commands + salomeConnector()->addEditCommand("UNDO_CMD", + tr("Undo"), tr("Undo last command"), + QIcon(":pictures/undo.png"), + false, this, SLOT(onUndo()), + QKeySequence::Undo); + salomeConnector()->addEditCommand("REDO_CMD", + tr("Redo"), tr("Redo last command"), + QIcon(":pictures/redo.png"), + false, this, SLOT(onRedo()), + QKeySequence::Redo); + salomeConnector()->addEditMenuSeparator(); + return; + } XGUI_Workbench* aPage = myMainWindow->menuObject()->generalPage(); // File commands group @@ -179,28 +200,29 @@ void XGUI_Workshop::onOperationStarted() ModuleBase_PropPanelOperation* aOperation = (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation()); - if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel - } else { + if(!aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel connectWithOperation(aOperation); - QWidget* aPropWidget = myMainWindow->findChild(XGUI::PROP_PANEL_WDG); + QWidget* aPropWidget = myPropertyPanelDock->findChild(XGUI::PROP_PANEL_WDG); qDeleteAll(aPropWidget->children()); - myMainWindow->showPropertyPanel(); + showPropertyPanel(); XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aOperation); aFactory.createWidget(aPropWidget); - myMainWindow->setPropertyPannelTitle(aOperation->description()); + setPropertyPannelTitle(aOperation->description()); } } //****************************************************** void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) { - myMainWindow->hidePropertyPanel(); + hidePropertyPanel(); updateCommandStatus(); - XGUI_MainMenu* aMenu = myMainWindow->menuObject(); - aMenu->restoreCommandState(); + if (myMainWindow) { + XGUI_MainMenu* aMenu = myMainWindow->menuObject(); + aMenu->restoreCommandState(); + } } /* @@ -215,29 +237,39 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) return; } //Find or create Workbench - XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); QString aWchName = QString::fromStdString(theMessage->workbenchId()); - XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName); - if (!aPage) { - aPage = addWorkbench(aWchName); - } - //Find or create Group - QString aGroupName = QString::fromStdString(theMessage->groupId()); - XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName); - if (!aGroup) { - aGroup = aPage->addGroup(aGroupName); + if (isSalomeMode()) { + salomeConnector()->addFeature(aWchName, + QString::fromStdString(theMessage->id()), + QString::fromStdString(theMessage->text()), + QString::fromStdString(theMessage->tooltip()), + QIcon(theMessage->icon().c_str()), + false, this, + SLOT(onFeatureTriggered()), QKeySequence()); + } else { + XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); + XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName); + if (!aPage) { + aPage = addWorkbench(aWchName); + } + //Find or create Group + QString aGroupName = QString::fromStdString(theMessage->groupId()); + XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName); + if (!aGroup) { + aGroup = aPage->addGroup(aGroupName); + } + bool isUsePropPanel = theMessage->isUseInput(); + //Create feature... + XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()), + QString::fromStdString(theMessage->text()), + QString::fromStdString(theMessage->tooltip()), + QIcon(theMessage->icon().c_str()), + QKeySequence(), isUsePropPanel); + + connect(aCommand, SIGNAL(toggled(bool)), + myMainWindow->menuObject(), SLOT(onFeatureChecked(bool))); + myPartSetModule->featureCreated(aCommand); } - bool isUsePropPanel = theMessage->isUseInput(); - //Create feature... - XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()), - QString::fromStdString(theMessage->text()), - QString::fromStdString(theMessage->tooltip()), - QIcon(theMessage->icon().c_str()), - QKeySequence(), isUsePropPanel); - - connect(aCommand, SIGNAL(toggled(bool)), - myMainWindow->menuObject(), SLOT(onFeatureChecked(bool))); - myPartSetModule->featureCreated(aCommand); } /* @@ -247,17 +279,20 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) */ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation) { - QDockWidget* aPanel = myMainWindow->findChild(XGUI::PROP_PANEL); - QPushButton* aOkBtn = aPanel->findChild(XGUI::PROP_PANEL_OK); + QPushButton* aOkBtn = myPropertyPanelDock->findChild(XGUI::PROP_PANEL_OK); connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit())); - QPushButton* aCancelBtn = aPanel->findChild(XGUI::PROP_PANEL_CANCEL); + QPushButton* aCancelBtn = myPropertyPanelDock->findChild(XGUI::PROP_PANEL_CANCEL); connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort())); - XGUI_MainMenu* aMenu = myMainWindow->menuObject(); - XGUI_Command* aCommand = aMenu->feature(theOperation->operationId()); + QAction* aCommand = 0; + if (isSalomeMode()) { + aCommand = salomeConnector()->command(theOperation->operationId()); + } else { + XGUI_MainMenu* aMenu = myMainWindow->menuObject(); + aCommand = aMenu->feature(theOperation->operationId()); + } //Abort operation on uncheck the command connect(aCommand, SIGNAL(toggled(bool)), theOperation, SLOT(setRunning(bool))); - } //****************************************************** @@ -270,15 +305,17 @@ void XGUI_Workshop::onExit() void XGUI_Workshop::onNew() { QApplication::setOverrideCursor(Qt::WaitCursor); - if (myMainWindow->objectBrowser() == 0) { - myMainWindow->createDockWidgets(); - mySelector->connectObjectBrowser(myMainWindow->objectBrowser()); + if (objectBrowser() == 0) { + createDockWidgets(); + mySelector->connectObjectBrowser(objectBrowser()); + } + showObjectBrowser(); + if (!isSalomeMode()) { + myMainWindow->showPythonConsole(); + QMdiSubWindow* aWnd = myMainWindow->viewer()->createView(); + aWnd->showMaximized(); + updateCommandStatus(); } - myMainWindow->showObjectBrowser(); - myMainWindow->showPythonConsole(); - QMdiSubWindow* aWnd = myMainWindow->viewer()->createView(); - aWnd->showMaximized(); - updateCommandStatus(); QApplication::restoreOverrideCursor(); } @@ -305,7 +342,7 @@ void XGUI_Workshop::onSaveAs() //****************************************************** void XGUI_Workshop::onUndo() { - myMainWindow->objectBrowser()->setCurrentIndex(QModelIndex()); + objectBrowser()->setCurrentIndex(QModelIndex()); boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); boost::shared_ptr aDoc = aMgr->rootDocument(); aDoc->undo(); @@ -315,7 +352,7 @@ void XGUI_Workshop::onUndo() //****************************************************** void XGUI_Workshop::onRedo() { - myMainWindow->objectBrowser()->setCurrentIndex(QModelIndex()); + objectBrowser()->setCurrentIndex(QModelIndex()); boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); boost::shared_ptr aDoc = aMgr->rootDocument(); aDoc->redo(); @@ -395,6 +432,8 @@ bool XGUI_Workshop::activateModule() //****************************************************** void XGUI_Workshop::updateCommandStatus() { + if (isSalomeMode()) // TODO: update commands in SALOME + return; XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); QList aCommands = aMenuBar->features(); @@ -426,3 +465,121 @@ void XGUI_Workshop::updateCommandStatus() } } } + +//****************************************************** +QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent) +{ + QDockWidget* aObjDock = new QDockWidget(theParent); + aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + aObjDock->setWindowTitle(tr("Object browser")); + myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock); + aObjDock->setWidget(myObjectBrowser); + return aObjDock; +} + +//****************************************************** +QDockWidget* XGUI_Workshop::createPropertyPanel(QWidget* theParent) +{ + QDockWidget* aPropPanel = new QDockWidget(theParent); + aPropPanel->setWindowTitle(tr("Property Panel")); + QAction* aViewAct = aPropPanel->toggleViewAction(); + aPropPanel->setObjectName(XGUI::PROP_PANEL); + + QWidget* aContent = new QWidget(aPropPanel); + QVBoxLayout* aMainLay = new QVBoxLayout(aContent); + aMainLay->setContentsMargins(3, 3, 3, 3); + aPropPanel->setWidget(aContent); + + QFrame* aFrm = new QFrame(aContent); + aFrm->setFrameStyle(QFrame::Sunken); + aFrm->setFrameShape(QFrame::Panel); + QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); + aBtnLay->setContentsMargins(0, 0, 0, 0); + aMainLay->addWidget(aFrm); + + QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + aBtnLay->addStretch(1); + aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); + aBtn->setObjectName(XGUI::PROP_PANEL_OK); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); + aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + + QWidget* aCustomWidget = new QWidget(aContent); + aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG); + aMainLay->addWidget(aCustomWidget); + aMainLay->addStretch(1); + + return aPropPanel; +} + +//****************************************************** +void XGUI_Workshop::setPropertyPannelTitle(const QString& theTitle) +{ + myPropertyPanelDock->setWindowTitle(theTitle); +} + +//****************************************************** +/* + * Creates dock widgets, places them in corresponding area + * and tabifies if necessary. + */ +void XGUI_Workshop::createDockWidgets() +{ + QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : + myMainWindow; + QDockWidget* aObjDock = createObjectBrowser(aDesktop); + aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock); + myPropertyPanelDock = createPropertyPanel(aDesktop); + aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock); + hidePropertyPanel(); //tabifyDockWidget(aObjDock, myPropertyPanelDock); +} + +//****************************************************** +void XGUI_Workshop::showPropertyPanel() +{ + QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); + //setEnabled(true); + myPropertyPanelDock->show(); + myPropertyPanelDock->raise(); +} + +//****************************************************** +void XGUI_Workshop::hidePropertyPanel() +{ + QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); + //setEnabled(false); + myPropertyPanelDock->hide(); +} + +//****************************************************** +void XGUI_Workshop::showObjectBrowser() +{ + myObjectBrowser->parentWidget()->show(); +} + +//****************************************************** +void XGUI_Workshop::hideObjectBrowser() +{ + myObjectBrowser->parentWidget()->hide(); +} + +//****************************************************** +void XGUI_Workshop::onFeatureTriggered() +{ + QAction* aCmd = dynamic_cast(sender()); + if (aCmd) { + QString aId = salomeConnector()->commandId(aCmd); + if (!aId.isNull()) + myPartSetModule->launchOperation(aId); + } +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 6c9034d49..0b477c526 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -16,12 +16,17 @@ class XGUI_Workbench; class XGUI_SelectionMgr; class XGUI_Displayer; class XGUI_OperationMgr; +class XGUI_SalomeConnector; +class XGUI_ObjectsBrowser; class ModuleBase_Operation; class ModuleBase_PropPanelOperation; class Config_FeatureMessage; class Config_PointerMessage; +class QWidget; +class QDockWidget; + /**\class XGUI_Workshop * \ingroup GUI * \brief Class which defines a configuration of the application (Workshop) and launches it. @@ -31,7 +36,7 @@ class XGUI_EXPORT XGUI_Workshop: public QObject, public Events_Listener Q_OBJECT public: - XGUI_Workshop(); + XGUI_Workshop(XGUI_SalomeConnector* theConnector = 0); virtual ~XGUI_Workshop(); //! Starting of the application @@ -58,6 +63,14 @@ public: //! Redefinition of Events_Listener method virtual void processEvent(const Events_Message* theMessage); + XGUI_SalomeConnector* salomeConnector() const { return mySalomeConnector; } + + //! Returns true if the application works as SALOME module + bool isSalomeMode() const { return mySalomeConnector != 0; } + + //! Returns Object browser + XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; } + public slots: void updateCommandStatus(); @@ -69,6 +82,13 @@ public slots: void onUndo(); void onRedo(); + void showPropertyPanel(); + void hidePropertyPanel(); + void showObjectBrowser(); + void hideObjectBrowser(); + + void onFeatureTriggered(); + protected: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); @@ -89,13 +109,26 @@ private: XGUI_Module* loadModule(const QString& theModule); bool activateModule(); + QDockWidget* createObjectBrowser(QWidget* theParent); + QDockWidget* createPropertyPanel(QWidget* theParent); + + // Creates Dock widgets: Object browser and Property panel + void createDockWidgets(); + void setPropertyPannelTitle(const QString& theTitle); + + XGUI_MainWindow* myMainWindow; XGUI_Module* myPartSetModule; + XGUI_ObjectsBrowser* myObjectBrowser; + QDockWidget* myPropertyPanelDock; + XGUI_SelectionMgr* mySelector; XGUI_Displayer* myDisplayer; XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations + + XGUI_SalomeConnector* mySalomeConnector; }; #endif -- 2.39.2