From a4ffa6e5a1578063cf8e3003b3ef98dbd3f32324 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 13 Apr 2016 10:24:59 +0300 Subject: [PATCH] Issue 1303 Re-ordering of Sketcher menus: additional structure for feature info to store the XML order. --- src/XGUI/XGUI_MenuGroup.cpp | 13 ++++++++++++- src/XGUI/XGUI_MenuGroup.h | 24 ++++++++++++++++++++++-- src/XGUI/XGUI_MenuMgr.cpp | 28 ++++++++++++++++++++++++++++ src/XGUI/XGUI_MenuMgr.h | 21 ++++++++++++++++----- src/XGUI/XGUI_MenuWorkbench.cpp | 27 ++++++++++++++++++++++++++- src/XGUI/XGUI_MenuWorkbench.h | 25 ++++++++++++++++++++++++- 6 files changed, 128 insertions(+), 10 deletions(-) diff --git a/src/XGUI/XGUI_MenuGroup.cpp b/src/XGUI/XGUI_MenuGroup.cpp index e0bc02e2d..c2ce5b20f 100755 --- a/src/XGUI/XGUI_MenuGroup.cpp +++ b/src/XGUI/XGUI_MenuGroup.cpp @@ -6,6 +6,17 @@ #include -XGUI_MenuGroup::XGUI_MenuGroup() +XGUI_MenuGroup::XGUI_MenuGroup(const std::string& theName) +: myName(theName) { } + +void XGUI_MenuGroup::setFeatureInfo(const std::shared_ptr& theMessage) +{ + myFeatureInfo.push_back(theMessage); +} + +const std::list >& XGUI_MenuGroup::featureInfo() const +{ + return myFeatureInfo; +} diff --git a/src/XGUI/XGUI_MenuGroup.h b/src/XGUI/XGUI_MenuGroup.h index d4d08329e..c1748f313 100755 --- a/src/XGUI/XGUI_MenuGroup.h +++ b/src/XGUI/XGUI_MenuGroup.h @@ -9,6 +9,11 @@ #include "XGUI.h" +#include +#include + +class Config_FeatureMessage; + /** * \ingroup GUI * A class for management of menu actions (features). The actions should be arranged like they are @@ -19,9 +24,24 @@ class XGUI_EXPORT XGUI_MenuGroup { public: /// Constructor - XGUI_MenuGroup(); + XGUI_MenuGroup(const std::string& theName); virtual ~XGUI_MenuGroup() {} + + /// Returns a name of the workbench + /// \return workbench name + std::string getName() const { return myName; } + + /// Stores XML information for the feature kind + /// \param theMessage a container of the feature XML properties + virtual void setFeatureInfo(const std::shared_ptr& theMessage); + + /// Returns container of existing features + /// \returns list + const std::list >& featureInfo() const; + +private: + std::string myName; /// a name of the workbench + std::list > myFeatureInfo; /// container of existing features }; #endif /* XGUI_MENUGROUP_H_ */ - diff --git a/src/XGUI/XGUI_MenuMgr.cpp b/src/XGUI/XGUI_MenuMgr.cpp index 1e55b6218..8dff16c1f 100755 --- a/src/XGUI/XGUI_MenuMgr.cpp +++ b/src/XGUI/XGUI_MenuMgr.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include @@ -58,6 +60,15 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr& theM #endif return; } + { + std::string aWchName = theMessage->workbenchId(); + std::shared_ptr aWorkbench = findWorkbench(aWchName); + + std::string aGroupName = theMessage->groupId(); + std::shared_ptr aGroup = aWorkbench->findGroup(aGroupName); + + aGroup->setFeatureInfo(theMessage); + } ActionInfo aFeatureInfo; aFeatureInfo.initFrom(theMessage); @@ -126,3 +137,20 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr& theM myWorkshop->module()->actionCreated(aCommand); #endif } + +std::shared_ptr XGUI_MenuMgr::findWorkbench(std::string& theWorkbenchName) +{ + std::list< std::shared_ptr >::const_iterator anIt = myWorkbenches.begin(), + aLast = myWorkbenches.end(); + std::shared_ptr aResultWorkbench; + for (; anIt != aLast && !aResultWorkbench; anIt++) { + std::shared_ptr aWorkbench = *anIt; + if (aWorkbench->getName() == theWorkbenchName) + aResultWorkbench = aWorkbench; + } + if (!aResultWorkbench) { + aResultWorkbench = std::shared_ptr(new XGUI_MenuWorkbench(theWorkbenchName)); + myWorkbenches.push_back(aResultWorkbench); + } + return aResultWorkbench; +} diff --git a/src/XGUI/XGUI_MenuMgr.h b/src/XGUI/XGUI_MenuMgr.h index dc5ddfb9c..74bf04407 100755 --- a/src/XGUI/XGUI_MenuMgr.h +++ b/src/XGUI/XGUI_MenuMgr.h @@ -11,6 +11,11 @@ #include +#include +#include +#include + +class XGUI_MenuWorkbench; class XGUI_Workshop; class Config_FeatureMessage; @@ -20,23 +25,29 @@ class Config_FeatureMessage; * in XML file. It listens the read feature of XML and fills internal structure of menu workbenches * and groups of feature. After, it creates menues and tools in the module. */ -class XGUI_EXPORT XGUI_MenuMgr : public Events_Listener +class XGUI_MenuMgr : public Events_Listener { public: /// Constructor /// \param the current workshop - XGUI_MenuMgr(XGUI_Workshop* theWorkshop); - virtual ~XGUI_MenuMgr() {} + XGUI_EXPORT XGUI_MenuMgr(XGUI_Workshop* theWorkshop); + XGUI_EXPORT virtual ~XGUI_MenuMgr() {} - //! Redefinition of Events_Listener method - virtual void processEvent(const std::shared_ptr& theMessage); + /// Redefinition of Events_Listener method + XGUI_EXPORT virtual void processEvent(const std::shared_ptr& theMessage); protected: /// Process event "Add a feature" void addFeature(const std::shared_ptr& 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 findWorkbench(std::string& theWorkbenchName); + private: XGUI_Workshop* myWorkshop; /// the current workshop + std::list< std::shared_ptr > myWorkbenches; /// container of existing workbenchs }; #endif /* XGUI_MENUMGR_H_ */ diff --git a/src/XGUI/XGUI_MenuWorkbench.cpp b/src/XGUI/XGUI_MenuWorkbench.cpp index 297d643e6..8107893fc 100755 --- a/src/XGUI/XGUI_MenuWorkbench.cpp +++ b/src/XGUI/XGUI_MenuWorkbench.cpp @@ -6,6 +6,31 @@ #include -XGUI_MenuWorkbench::XGUI_MenuWorkbench() +#include + +XGUI_MenuWorkbench::XGUI_MenuWorkbench(const std::string& theName) +: myName(theName) +{ +} + +std::shared_ptr XGUI_MenuWorkbench::findGroup(const std::string& theGroupName) +{ + std::list< std::shared_ptr >::const_iterator anIt = myGroups.begin(), + aLast = myGroups.end(); + std::shared_ptr aResultGroup = 0; + for (; anIt != aLast && !aResultGroup; anIt++) { + std::shared_ptr aGroup = *anIt; + if (aGroup->getName() == theGroupName) + aResultGroup = aGroup; + } + if (!aResultGroup) { + aResultGroup = std::shared_ptr(new XGUI_MenuGroup(theGroupName)); + myGroups.push_back(aResultGroup); + } + return aResultGroup; +} + +const std::list >& XGUI_MenuWorkbench::groups() const { + return myGroups; } diff --git a/src/XGUI/XGUI_MenuWorkbench.h b/src/XGUI/XGUI_MenuWorkbench.h index 11597bb17..079fe3d35 100755 --- a/src/XGUI/XGUI_MenuWorkbench.h +++ b/src/XGUI/XGUI_MenuWorkbench.h @@ -9,6 +9,12 @@ #include "XGUI.h" +#include +#include +#include + +class XGUI_MenuGroup; + /** * \ingroup GUI * A class for management of menu actions (features). The actions should be arranged like they are @@ -19,9 +25,26 @@ class XGUI_EXPORT XGUI_MenuWorkbench { public: /// Constructor - XGUI_MenuWorkbench(); + XGUI_MenuWorkbench(const std::string& theName); /// Destructor virtual ~XGUI_MenuWorkbench() {} + + /// Returns a name of the workbench + /// \return workbench name + std::string getName() const { return myName; } + + /// Finds or creates a group for the given name + /// \param theGroupName a name defined in XML + /// \return an instance of group + std::shared_ptr findGroup(const std::string& theGroupName); + + /// Returns container of existing groups + /// \returns list + const std::list >& groups() const; + +private: + std::string myName; /// a name of the workbench + std::list > myGroups; /// container of existing groups }; #endif /* XGUI_MENUWORKBENCH_H_ */ -- 2.39.2