/// Called on selection changed event\r
virtual void onSelectionChanged() {}\r
\r
- protected:\r
- /// Register validators for this module\r
+protected:\r
+ /// Register validators for this module\r
virtual void registerValidators() {}\r
\r
/// Register selection filters for this module\r
#include <XGUI_ObjectsBrowser.h>
#include <XGUI_OperationMgr.h>
#include <XGUI_Displayer.h>
+#include <XGUI_MenuMgr.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_Preferences.h>
return new SHAPERGUI_DataModel(this);
}
-QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo)
+QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
+ const bool isAddSeparator,
+ bool isMenuAction, bool isToolAction)
{
return addFeature(theWBName,
theInfo.id,
theInfo.toolTip,
theInfo.icon,
theInfo.shortcut,
- theInfo.checkable);
+ theInfo.checkable,
+ isAddSeparator, isMenuAction, isToolAction);
}
//******************************************************
QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theId,
- const QString& theTitle, const QString& theTip,
- const QIcon& theIcon, const QKeySequence& theKeys,
- bool isCheckable)
+ const QString& theTitle, const QString& theTip,
+ const QIcon& theIcon, const QKeySequence& theKeys,
+ bool isCheckable, const bool isAddSeparator,
+ bool isMenuAction, bool isToolAction)
{
static QString aLastTool = "";
static int aNb = 0;
}
aNb++;
- int aMenu = createMenu(theWBName, -1, -1, 50);
- int aTool = createTool(theWBName, theWBName);
-
int aId = myActionsList.size();
myActionsList.append(theId);
SUIT_Desktop* aDesk = application()->desktop();
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);
+ if (isMenuAction) {
+ int aWBMenu = createMenu(theWBName, -1, -1, 50/*10-Window, 1000 - Help*/);
+ int aItemId = createMenu(aId, aWBMenu);
+ if (isAddSeparator)
+ createMenu(separator(), aWBMenu);
+ }
+ if (isToolAction) {
+ int aWBTool = createTool(theWBName, theWBName);
+ int aToolId = createTool(aId, aWBTool);
+ if (isAddSeparator)
+ createTool(separator(), aWBTool);
+ }
return aAction;
}
}
QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
- const ActionInfo& theInfo,
- const QList<QAction*>& theNestedActions)
+ const ActionInfo& theInfo,
+ const QList<QAction*>& theNestedActions,
+ bool isMenuAction, bool isToolAction)
{
- int aMenu = createMenu(theWBName, -1, -1, 50);
- int aTool = createTool(theWBName, theWBName);
-
int aId = myActionsList.size();
myActionsList.append(theInfo.id);
SUIT_Desktop* aDesk = application()->desktop();
anAction->setShortcut(theInfo.shortcut);
anAction->setFont(theInfo.font);
- //int aItemId = createMenu(aId, aMenu, -1, 10);
- int aToolId = createTool(anAction, aTool, aId);
-
+ if (isMenuAction) {
+ int aWBMenu = createMenu(theWBName, -1, -1, 50);
+ int aItemId = createMenu(anAction, aWBMenu);
+ }
+ if (isToolAction) {
+ int aWBTool = createTool(theWBName, theWBName);
+ int aToolId = createTool(anAction, aWBTool);
+ }
return anAction;
}
{
return workshop()->operationMgr()->abortAllOperations();
}
+
+void SHAPERGUI::createFeatureActions()
+{
+ myWorkshop->menuMgr()->createFeatureActions();
+}
virtual QAction* addFeature(const QString& theWBName, const QString& theId,
const QString& theTitle, const QString& theTip, const QIcon& theIcon,
const QKeySequence& theKeys = QKeySequence(),
- bool isCheckable = false);
+ bool isCheckable = false, const bool isAddSeparator = false,
+ bool isMenuAction = true, bool isToolAction = true);
//! Add feature (QAction) in the \a theWBName toolbar with given \a theInfo about action
virtual QAction* addFeature(const QString& theWBName,
- const ActionInfo& theInfo);
+ const ActionInfo& theInfo, const bool isAddSeparator,
+ bool isMenuAction = true, bool isToolAction = true);
/// Add a nested feature
/// \param theWBName a workbench name
/// \param theNestedActions a list of nested actions
virtual QAction* addFeatureOfNested(const QString& theWBName,
const ActionInfo& theInfo,
- const QList<QAction*>& theNestedActions);
+ const QList<QAction*>& theNestedActions,
+ bool isMenuAction = true, bool isToolAction = true);
//! Returns true if the feature action is a nested action, in other words,
//! it is created by addNestedFeature().
/// \param theAction an ation to add
/// \param theToolBarTitle a name of tool bar
virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle );
-
+
+ /// Creates menu/tool bar actions for loaded features stored in the menu manager
+ virtual void createFeatureActions();
+
virtual QMainWindow* desktop() const;
virtual QString commandId(const QAction* theCmd) const;
myFeatureInfo.push_back(theMessage);
}
-const std::list<std::shared_ptr<Config_FeatureMessage> >& XGUI_MenuGroup::featureInfo() const
+const std::list<std::shared_ptr<Config_FeatureMessage> >& XGUI_MenuGroup::featuresInfo() const
{
return myFeatureInfo;
}
/// Returns container of existing features
/// \returns list
- const std::list<std::shared_ptr<Config_FeatureMessage> >& featureInfo() const;
+ const std::list<std::shared_ptr<Config_FeatureMessage> >& featuresInfo() const;
private:
std::string myName; /// a name of the workbench
#endif
return;
}
- {
- std::string aWchName = theMessage->workbenchId();
- std::shared_ptr<XGUI_MenuWorkbench> aWorkbench = findWorkbench(aWchName);
-
- std::string aGroupName = theMessage->groupId();
- std::shared_ptr<XGUI_MenuGroup> aGroup = aWorkbench->findGroup(aGroupName);
-
- aGroup->setFeatureInfo(theMessage);
- }
-
+#ifdef HAVE_SALOME
+ std::shared_ptr<XGUI_MenuWorkbench> aWorkbench = findWorkbench(theMessage->workbenchId());
+ std::shared_ptr<XGUI_MenuGroup> aGroup = aWorkbench->findGroup(theMessage->groupId());
+ aGroup->setFeatureInfo(theMessage);
+#else
ActionInfo aFeatureInfo;
aFeatureInfo.initFrom(theMessage);
}
}
-#ifdef HAVE_SALOME
- XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
- QAction* aAction;
- if (isColumnButton) {
- aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList);
- } else {
- //Issue #650: in the SALOME mode the tooltip should be same as text
- aFeatureInfo.toolTip = aFeatureInfo.text;
- aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
- }
- aSalomeConnector->setFeatureInfo(aFeatureInfo.id, theMessage);
-
- myWorkshop->actionsMgr()->addCommand(aAction);
- myWorkshop->module()->actionCreated(aAction);
-#else
//Find or create Workbench
AppElements_MainMenu* aMenuBar = myWorkshop->mainWindow()->menuObject();
AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
#endif
}
-std::shared_ptr<XGUI_MenuWorkbench> XGUI_MenuMgr::findWorkbench(std::string& theWorkbenchName)
+std::shared_ptr<XGUI_MenuWorkbench> XGUI_MenuMgr::findWorkbench(const std::string& theWorkbenchName)
{
std::list< std::shared_ptr<XGUI_MenuWorkbench> >::const_iterator anIt = myWorkbenches.begin(),
aLast = myWorkbenches.end();
}
return aResultWorkbench;
}
+
+void XGUI_MenuMgr::createFeatureActions()
+{
+#ifdef HAVE_SALOME
+ std::list< std::shared_ptr<XGUI_MenuWorkbench> >::const_iterator anIt = myWorkbenches.begin(),
+ aLast = myWorkbenches.end();
+ XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
+ for (; anIt != aLast; anIt++) {
+ std::shared_ptr<XGUI_MenuWorkbench> aWorkbench = *anIt;
+ std::string aWchName = aWorkbench->getName();
+ const std::list<std::shared_ptr<XGUI_MenuGroup> >& aGroups = aWorkbench->groups();
+ std::list<std::shared_ptr<XGUI_MenuGroup> >::const_iterator aGIt = aGroups.begin(),
+ aGLast = aGroups.end();
+ for (; aGIt != aGLast; aGIt++) {
+ const std::shared_ptr<XGUI_MenuGroup> aGroup = *aGIt;
+ std::string aGName = aGroup->getName();
+ const std::list<std::shared_ptr<Config_FeatureMessage> >& aFeaturesInfo = aGroup->featuresInfo();
+ std::list<std::shared_ptr<Config_FeatureMessage> >::const_iterator aFIt = aFeaturesInfo.begin(),
+ aFLast = aFeaturesInfo.end();
+ int aFSize = aFeaturesInfo.size();
+ for(int i = 0; aFIt != aFLast; aFIt++, i++) {
+ std::shared_ptr<Config_FeatureMessage> aMessage = *aFIt;
+ bool aUseSeparator = i == aFSize-1;
+ QAction* aAction = buildAction(aMessage, aWchName, aUseSeparator);
+
+ aSalomeConnector->setFeatureInfo(QString::fromStdString(aMessage->id()), aMessage);
+ myWorkshop->actionsMgr()->addCommand(aAction);
+ myWorkshop->module()->actionCreated(aAction);
+ }
+ }
+ }
+#endif
+}
+
+QAction* XGUI_MenuMgr::buildAction(const std::shared_ptr<Config_FeatureMessage>& theMessage,
+ const std::string& theWchName, const bool aUseSeparator) const
+{
+ QAction* anAction;
+
+#ifdef HAVE_SALOME
+ XGUI_SalomeConnector* aSalomeConnector = myWorkshop->salomeConnector();
+
+ ActionInfo aFeatureInfo;
+ aFeatureInfo.initFrom(theMessage);
+ QStringList aNestedFeatures =
+ QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
+ QList<QAction*> aNestedActList;
+ if (!aNestedFeatures.isEmpty()) {
+ QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
+ XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
+ XGUI_ActionsMgr* anActionsMgr = myWorkshop->actionsMgr();
+ if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
+ QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
+ QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
+ aNestedActList << anAction;
+ }
+ if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
+ QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
+ QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
+ aNestedActList << anAction;
+ }
+ anAction = aSalomeConnector->addFeatureOfNested(theWchName.c_str(), aFeatureInfo,
+ aNestedActList, false, true);
+ QAction* aMenuAction = aSalomeConnector->addFeature(theWchName.c_str(), aFeatureInfo,
+ aUseSeparator, true, false);
+ myWorkshop->module()->actionCreated(aMenuAction);
+ }
+ else {
+ //Issue #650: in the SALOME mode the tooltip should be same as text
+ aFeatureInfo.toolTip = aFeatureInfo.text;
+ anAction = aSalomeConnector->addFeature(theWchName.c_str(), aFeatureInfo, aUseSeparator);
+ }
+#endif
+ return anAction;
+}
class XGUI_Workshop;
class Config_FeatureMessage;
+class QAction;
+
/**
* \ingroup GUI
* A class for management of menu actions (features). The actions should be arranged like they are
XGUI_EXPORT XGUI_MenuMgr(XGUI_Workshop* theWorkshop);
XGUI_EXPORT virtual ~XGUI_MenuMgr() {}
+ XGUI_EXPORT void createFeatureActions();
+
/// Redefinition of Events_Listener method
XGUI_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
/// Finds or creates a workbench for the given name
/// \param theWorkbenchName a name defined in XML
/// \return an instance of workbench
- std::shared_ptr<XGUI_MenuWorkbench> findWorkbench(std::string& theWorkbenchName);
+ std::shared_ptr<XGUI_MenuWorkbench> findWorkbench(const std::string& theWorkbenchName);
+
+ /// Creates a new action by the message
+ /// \param theMessage an XML information of the feature
+ /// \param theWchName a workbench name, will be used as menu/tool bar name
+ /// \param aUseSeparator boolean value if a separator should be added after the action
+ /// \return an action
+ QAction* buildAction(const std::shared_ptr<Config_FeatureMessage>& theMessage,
+ const std::string& theWchName, const bool aUseSeparator) const;
private:
XGUI_Workshop* myWorkshop; /// the current workshop
//! \param theIcon - icon
//! \param isCheckable - is checkable or not
//! \param theKeys - hot keys
+ //! \param isAddSeparator boolean flag about adding separator after the action
+ //! \param isMenuAction boolean flag about adding the action to application menu bar
+ //! \param isToolAction boolean flag about adding the action to application tool bar
//! 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;
+ const QKeySequence& theKeys, bool isCheckable, const bool isAddSeparator,
+ bool isMenuAction = true, bool isToolAction = true) = 0;
//! Creates a feature (command) in SALOME desktop
//! \param theWBName - name of toolbar (workbench)
//! \param theInfo - information about action (icon, text, etc)
+ //! \param isAddSeparator boolean flag about adding separator after the action
+ //! \param isMenuAction boolean flag about adding the action to application menu bar
+ //! \param isToolAction boolean flag about adding the action to application tool bar
virtual QAction* addFeature(const QString& theWBName,
- const ActionInfo& theInfo) = 0;
+ const ActionInfo& theInfo, const bool isAddSeparator,
+ bool isMenuAction = true, bool isToolAction = true) = 0;
//! Creates a feature (command) in SALOME desktop
//! \param theWBName - name of toolbar (workbench)
//! \param theInfo - information about action (icon, text, etc)
//! \param theNestedActions a list of nested actions
+ //! \param isMenuAction boolean flag about adding the action to application menu bar
+ //! \param isToolAction boolean flag about adding the action to application tool bar
virtual QAction* addFeatureOfNested(const QString& theWBName,
- const ActionInfo& theInfo,
- const QList<QAction*>& theNestedActions) = 0;
+ const ActionInfo& theInfo,
+ const QList<QAction*>& theNestedActions,
+ bool isMenuAction = true, bool isToolAction = true) = 0;
//! Returns true if the feature action is a nested action, in other words,
//! it is created by addFeatureOfNested().
/// \param theToolBarTitle the toolbar name
virtual bool addActionInToolbar( QAction* theAction, const QString& theToolBarTitle ) = 0;
+ /// Creates menu/tool bar actions for loaded features stored in the menu manager
+ virtual void createFeatureActions() = 0;
+
//! Returns desktop window of SALOME
virtual QMainWindow* desktop() const = 0;
// myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
myModule->createFeatures();
+ salomeConnector()->createFeatureActions();
//myActionsMgr->update();
return true;
}