From 7de345ac623f20ab2f2e3405066c75c86f8e662a Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 20 May 2014 11:24:59 +0400 Subject: [PATCH] Adaptation of the application to SALOME interface (issue #31) --- src/NewGeom/CMakeLists.txt | 1 + src/NewGeom/NewGeom_Module.cpp | 58 ++++++++++++++++---------- src/NewGeom/NewGeom_Module.h | 34 ++++++++-------- src/PartSet/PartSet_Module.cpp | 8 ++-- src/PartSet/PartSet_Module.h | 2 +- src/XGUI/XGUI_ActionsMgr.cpp | 24 ++++------- src/XGUI/XGUI_ActionsMgr.h | 7 +--- src/XGUI/XGUI_Command.cpp | 21 ++-------- src/XGUI/XGUI_Command.h | 18 ++------ src/XGUI/XGUI_MenuGroupPanel.cpp | 8 ++-- src/XGUI/XGUI_Module.h | 4 +- src/XGUI/XGUI_SalomeConnector.h | 42 +++++++++---------- src/XGUI/XGUI_Workshop.cpp | 70 ++++++++++++++++---------------- 13 files changed, 140 insertions(+), 157 deletions(-) diff --git a/src/NewGeom/CMakeLists.txt b/src/NewGeom/CMakeLists.txt index 0f41fea7f..4eee4a294 100644 --- a/src/NewGeom/CMakeLists.txt +++ b/src/NewGeom/CMakeLists.txt @@ -44,6 +44,7 @@ ADD_DEFINITIONS( -DNewGeom_EXPORTS ${CAS_DEFINITIONS} ) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/XGUI ${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/ModuleBase + ${PROJECT_SOURCE_DIR}/src/ModelAPI ${SALOME_GUI_INCLUDE} ${SALOME_KERNEL_INCLUDE} ${CAS_INCLUDE_DIRS} diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index 2b7e8e5c9..549276279 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -19,6 +19,7 @@ #include #include +#include extern "C" { NewGeom_EXPORT CAM_Module* createModule() { @@ -126,15 +127,13 @@ CAM_DataModel* NewGeom_Module::createDataModel() } //****************************************************** -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) +QAction* NewGeom_Module::addFeature(const QString& theWBName, + const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + const QKeySequence& theKeys, + bool isCheckable) { int aMenu = createMenu(theWBName, -1, -1, 50); int aTool = createTool(theWBName); @@ -145,21 +144,21 @@ void NewGeom_Module::addFeature(const QString& theWBName, 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); + QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, + isCheckable); + aAction->setData(theId); int aItemId = createMenu( aId, aMenu, -1, 10 ); int aToolId = createTool( aId, aTool ); + return aAction; } //****************************************************** -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) +QAction* NewGeom_Module::addEditCommand(const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + const QKeySequence& theKeys, + bool isCheckable) { int aMenu = createMenu(tr( "MEN_DESK_EDIT" ), -1, -1); @@ -169,9 +168,11 @@ void NewGeom_Module::addEditCommand(const QString& theId, 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); + QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk, + isCheckable); + aAction->setData(theId); createMenu( aId, aMenu, 10 ); + return aAction; } //****************************************************** @@ -181,6 +182,21 @@ void NewGeom_Module::addEditMenuSeparator() createMenu( separator(), aMenu, -1, 10 ); } +//****************************************************** +QList NewGeom_Module::commandList() const +{ + QList aActions; + for (int i = 0; i < myActionsList.size(); i++) + aActions.append(action(i)); + return aActions; +} + +//****************************************************** +QStringList NewGeom_Module::commandIdList() const +{ + return myActionsList; +} + //****************************************************** QMainWindow* NewGeom_Module::desktop() const { diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index 9b63a18c6..ef0b4eb4a 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -34,24 +34,20 @@ public: virtual void selectionChanged(); //--- 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, + virtual QAction* 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); + const QKeySequence& theKeys = QKeySequence(), + bool isCheckable = false); + + virtual QAction* addEditCommand(const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + const QKeySequence& theKeys, + bool isCheckable); virtual void addEditMenuSeparator(); @@ -72,6 +68,12 @@ public: //! Returns interface to Salome viewer virtual XGUI_SalomeViewer* viewer() const { return myProxyViewer; } + //! Returns list of defined actions (just by NewGeom module) + virtual QList commandList() const; + + //! Returns list of Ids of defined actions (just by NewGeom module) + virtual QStringList commandIdList() const; + public slots: virtual bool activateModule( SUIT_Study* theStudy); virtual bool deactivateModule( SUIT_Study* theStudy); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 08b5bf2b6..99806f462 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -80,9 +80,9 @@ void PartSet_Module::createFeatures() myFeaturesInFiles = aXMLReader.featuresInFiles(); } -void PartSet_Module::featureCreated(XGUI_Command* theFeature) +void PartSet_Module::featureCreated(QAction* theFeature) { - theFeature->connectTo(this, SLOT(onFeatureTriggered())); + connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered())); } QStringList PartSet_Module::nestedFeatures(QString) @@ -100,11 +100,11 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId) */ void PartSet_Module::onFeatureTriggered() { - XGUI_Command* aCmd = dynamic_cast(sender()); + QAction* aCmd = dynamic_cast(sender()); //Do nothing on uncheck if(aCmd->isCheckable() && !aCmd->isChecked()) return; - launchOperation(aCmd->id()); + launchOperation(aCmd->data().toString()); } void PartSet_Module::launchOperation(const QString& theCmdId) diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 86c2d95f6..0c9e72a4a 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -31,7 +31,7 @@ public: XGUI_Workshop* workshop() const; virtual void createFeatures(); - virtual void featureCreated(XGUI_Command* theFeature); + virtual void featureCreated(QAction* theFeature); virtual QStringList nestedFeatures(QString theFeature); std::string featureFile(const std::string&); diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index a49689970..7f0b02d9a 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -21,20 +21,14 @@ XGUI_ActionsMgr::~XGUI_ActionsMgr() } -void XGUI_ActionsMgr::addCommand(QString theId, QAction* theCmd) +void XGUI_ActionsMgr::addCommand(QAction* theCmd) { - myActions.insert(theId,theCmd); - myActionsState.insert(theId, theCmd->isEnabled()); + QString aId = theCmd->data().toString(); + myActions.insert(aId, theCmd); + myActionsState.insert(aId, theCmd->isEnabled()); connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool))); } -void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd) -{ - myActions.insert(theCmd->id(),theCmd); - myActionsState.insert(theCmd->id(), theCmd->enabled()); - theCmd->connectTo(this, SLOT(setActionsDisabled(bool))); -} - void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled) { //Re-enable actions (just restore their state) @@ -47,13 +41,9 @@ void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled) saveCommandsState(); QString aSkippedId; - if (myWorkshop->isSalomeMode()) { - QAction* aToggledFeature = dynamic_cast(sender()); - aSkippedId = myWorkshop->salomeConnector()->commandId(aToggledFeature); - } else { - XGUI_Command* aToggledFeature = dynamic_cast(sender()); - aSkippedId = aToggledFeature->id(); - } + QAction* aToggledFeature = dynamic_cast(sender()); + aSkippedId = aToggledFeature->data().toString(); + QStringList anActionIdsList = myActions.keys(); foreach(QString eachKey, anActionIdsList) { if (eachKey == aSkippedId) { diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index 965f2289f..3390a83f3 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -24,12 +24,7 @@ public: virtual ~XGUI_ActionsMgr(); - void addCommand(XGUI_Command* theCmd); - - /// Register a command in SALOME mode - /// \param theId - string ID of the command - /// \param theCmd - command object - void addCommand(QString theId, QAction* theCmd); + void addCommand(QAction* theCmd); void saveCommandsState(); void restoreCommandState(); diff --git a/src/XGUI/XGUI_Command.cpp b/src/XGUI/XGUI_Command.cpp index 9b5dd7b9a..220e04f47 100644 --- a/src/XGUI/XGUI_Command.cpp +++ b/src/XGUI/XGUI_Command.cpp @@ -3,16 +3,18 @@ #include XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable) - : QWidgetAction(parent), myId(theId), myCheckable(isCheckable) + : QWidgetAction(parent), myCheckable(isCheckable) { + setData(theId); } XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent, bool isCheckable) - : QWidgetAction(parent), myId(theId), myCheckable(isCheckable) + : QWidgetAction(parent), myCheckable(isCheckable) { setIcon(icon); setText(text); + setData(theId); } XGUI_Command::~XGUI_Command() @@ -46,21 +48,6 @@ QWidget* XGUI_Command::createWidget(QWidget* theParent) return QWidgetAction::createWidget(theParent); } -bool XGUI_Command::enabled() const -{ - return isEnabled(); -} - -void XGUI_Command::enable() -{ - setEnabled(true); -} - -void XGUI_Command::disable() -{ - setEnabled(false); -} - void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot) { connect(this, SIGNAL(triggered(bool)), theResiver, theSlot); diff --git a/src/XGUI/XGUI_Command.h b/src/XGUI/XGUI_Command.h index 380b64ae4..dbd45b432 100644 --- a/src/XGUI/XGUI_Command.h +++ b/src/XGUI/XGUI_Command.h @@ -19,20 +19,11 @@ public: XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent, bool isCheckable = false); ~XGUI_Command(); - //! Returns true if the command is enabled - virtual bool enabled() const; - - //! Set the command enabled - virtual void enable(); - - //! Set the command disabled - virtual void disable(); - - //! Returns Id of the command - virtual QString id() const + //VSV: Don't use this method for compatibility with SALOME. Use the construction below + /*virtual QString id() const { - return myId; - } + return data().toString(); + }*/ const QStringList& unblockableCommands() const; void setUnblockableCommands(const QStringList& myUnblockableCommands); @@ -45,7 +36,6 @@ protected: virtual QWidget* createWidget(QWidget* theParent); private: - QString myId; bool myCheckable; //! List of Ids of commands which WILL NOT be blocked when the command is on. QStringList myUnblockableCommands; diff --git a/src/XGUI/XGUI_MenuGroupPanel.cpp b/src/XGUI/XGUI_MenuGroupPanel.cpp index 4f4673470..48a9ce1a8 100644 --- a/src/XGUI/XGUI_MenuGroupPanel.cpp +++ b/src/XGUI/XGUI_MenuGroupPanel.cpp @@ -76,9 +76,9 @@ XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QStrin XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const { - QList::const_iterator aIt; - for (aIt = myActions.constBegin(); aIt != myActions.constEnd(); ++aIt) - if ((*aIt)->id() == theId) - return (*aIt); + foreach (XGUI_Command* aCmd, myActions) { + if (aCmd->data().toString() == theId) + return aCmd; + } return 0; } diff --git a/src/XGUI/XGUI_Module.h b/src/XGUI/XGUI_Module.h index 48de0ad69..4df05ea2f 100644 --- a/src/XGUI/XGUI_Module.h +++ b/src/XGUI/XGUI_Module.h @@ -4,13 +4,13 @@ #include #include -class XGUI_Command; +class QAction; class XGUI_Module { public: virtual void createFeatures() = 0; - virtual void featureCreated(XGUI_Command*) = 0; + virtual void featureCreated(QAction*) = 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 index a55398cb1..48bb6e10f 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -23,18 +23,15 @@ public: //! \param theTip - a tooltip string (help) //! \param theIcon - icon //! \param isCheckable - is checkable or not - //! \param reciever - QObject which will react on the command call - //! \param member - a method of receiver which will be called on the command //! \param theKeys - hot keys - 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; + //! returns created action + virtual QAction* addFeature(const QString& theWBName, + const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + const QKeySequence& theKeys, + bool isCheckable) = 0; //! Creates a command in Edit menu of SALOME desktop //! \param theId - an id of the feature @@ -42,17 +39,14 @@ public: //! \param theTip - a tooltip string (help) //! \param theIcon - icon //! \param isCheckable - is checkable or not - //! \param reciever - QObject which will react on the command call - //! \param member - a method of receiver which will be called on the command //! \param theKeys - hot keys - 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; + //! returns created action + virtual QAction* addEditCommand(const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + const QKeySequence& theKeys, + bool isCheckable) = 0; //! Insert separator into Edit menu of SALOME desktop virtual void addEditMenuSeparator() = 0; @@ -66,6 +60,12 @@ public: //! Returns QAction instance by command string Id virtual QAction* command(const QString& theId) const = 0; + //! Returns list of defined actions (just by NewGeom module) + virtual QList commandList() const = 0; + + //! Returns list of Ids of defined actions (just by NewGeom module) + virtual QStringList commandIdList() const = 0; + //! Set nested actions dependent on command Id //! \param theId - the command ID //! \param theActions - the list of nested actions diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 1a11dca83..60c7f0b5b 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -129,16 +129,16 @@ void XGUI_Workshop::initMenu() { if (isSalomeMode()) { // Create only Undo, Redo commands - salomeConnector()->addEditCommand("UNDO_CMD", + QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD", tr("Undo"), tr("Undo last command"), QIcon(":pictures/undo.png"), - false, this, SLOT(onUndo()), - QKeySequence::Undo); - salomeConnector()->addEditCommand("REDO_CMD", + QKeySequence::Undo, false); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo())); + aAction = salomeConnector()->addEditCommand("REDO_CMD", tr("Redo"), tr("Redo last command"), QIcon(":pictures/redo.png"), - false, this, SLOT(onRedo()), - QKeySequence::Redo); + QKeySequence::Redo, false); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo())); salomeConnector()->addEditMenuSeparator(); return; } @@ -297,16 +297,15 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) bool isUsePropPanel = theMessage->isUseInput(); if (isSalomeMode()) { QString aId = QString::fromStdString(theMessage->id()); - salomeConnector()->addFeature(aWchName, - QString::fromStdString(theMessage->id()), - aId, - QString::fromStdString(theMessage->tooltip()), - QIcon(theMessage->icon().c_str()), - isUsePropPanel, this, - SLOT(onFeatureTriggered()), QKeySequence()); - myActionsMgr->addCommand(aId, salomeConnector()->command(aId)); + QAction* aAction = salomeConnector()->addFeature(aWchName, + aId, + QString::fromStdString(theMessage->text()), + QString::fromStdString(theMessage->tooltip()), + QIcon(theMessage->icon().c_str()), + QKeySequence(), isUsePropPanel); + myActionsMgr->addCommand(aAction); salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" ")); - + myPartSetModule->featureCreated(aAction); } else { XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); @@ -563,36 +562,39 @@ 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(); - QList::const_iterator aIt; - + QList aCommands; + if (isSalomeMode()) { // update commands in SALOME mode + aCommands = salomeConnector()->commandList(); + } else { + XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); + foreach (XGUI_Command* aCmd, aMenuBar->features()) + aCommands.append(aCmd); + } PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); if (aMgr->hasRootDocument()) { - XGUI_Command* aUndoCmd; - XGUI_Command* aRedoCmd; - foreach(XGUI_Command* aCmd, aCommands) { - if (aCmd->id() == "UNDO_CMD") + QAction* aUndoCmd; + QAction* aRedoCmd; + foreach(QAction* aCmd, aCommands) { + QString aId = aCmd->data().toString(); + if (aId == "UNDO_CMD") aUndoCmd = aCmd; - else if (aCmd->id() == "REDO_CMD") + else if (aId == "REDO_CMD") aRedoCmd = aCmd; else // Enable all commands - aCmd->enable(); + aCmd->setEnabled(true); } DocumentPtr aDoc = aMgr->rootDocument(); aUndoCmd->setEnabled(aDoc->canUndo()); aRedoCmd->setEnabled(aDoc->canRedo()); } else { - foreach(XGUI_Command* aCmd, aCommands) { - if (aCmd->id() == "NEW_CMD") - aCmd->enable(); - else if (aCmd->id() == "EXIT_CMD") - aCmd->enable(); + foreach(QAction* aCmd, aCommands) { + QString aId = aCmd->data().toString(); + if (aId == "NEW_CMD") + aCmd->setEnabled(true); + else if (aId == "EXIT_CMD") + aCmd->setEnabled(true); else - aCmd->disable(); + aCmd->setEnabled(false); } } } -- 2.39.2