From: sbh Date: Tue, 23 Sep 2014 09:16:48 +0000 (+0400) Subject: Document's kind dependent features implemented X-Git-Tag: V_0.4.4~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=52558a1594f889f73337ed79f402a236e0f9b482;p=modules%2Fshaper.git Document's kind dependent features implemented --- diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 19f4499e8..1f7a65b2d 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -55,12 +55,11 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) aMessage->setUseInput(hasChild(theNode)); aEvLoop->send(aMessage); //The m_last* variables always defined before fillFeature() call. XML is a tree. - } else if (isNode(theNode, NODE_GROUP, NULL)) { - myLastGroup = getProperty(theNode, _ID); - } else if (isNode(theNode, NODE_WORKBENCH, NULL)) { - myLastWorkbench = getProperty(theNode, _ID); - //Process SOURCE, VALIDATOR nodes. + } else if (isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL)) { + storeAttribute(theNode, _ID); + storeAttribute(theNode, WORKBENCH_DOC); } + //Process SOURCE, VALIDATOR nodes. Config_XMLReader::processNode(theNode); } @@ -86,8 +85,9 @@ void Config_FeatureReader::fillFeature(xmlNodePtr theNode, outFeatureMessage->setTooltip(getProperty(theNode, FEATURE_TOOLTIP)); outFeatureMessage->setIcon(getProperty(theNode, FEATURE_ICON)); outFeatureMessage->setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE)); - outFeatureMessage->setGroupId(myLastGroup); - outFeatureMessage->setWorkbenchId(myLastWorkbench); + outFeatureMessage->setGroupId(restoreAttribute(NODE_GROUP, _ID)); + outFeatureMessage->setWorkbenchId(restoreAttribute(NODE_WORKBENCH, _ID)); + outFeatureMessage->setDocumentKind(restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC)); } bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode) @@ -99,3 +99,29 @@ bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode) } return true; } + +void Config_FeatureReader::storeAttribute(xmlNodePtr theNode, + const char* theNodeAttribute) +{ + std::string aKey = getNodeName(theNode) + ":" + std::string(theNodeAttribute); + std::string aValue = getProperty(theNode, theNodeAttribute); + if(!aValue.empty()) { + myParentAttributes[aKey] = aValue; + } +} + +std::string Config_FeatureReader::restoreAttribute(xmlNodePtr theNode, + const char* theNodeAttribute) +{ + return restoreAttribute(getNodeName(theNode).c_str(), theNodeAttribute); +} +std::string Config_FeatureReader::restoreAttribute(const char* theNodeName, + const char* theNodeAttribute) +{ + std::string aKey = std::string(theNodeName) + ":" + std::string(theNodeAttribute); + std::string result = ""; + if(myParentAttributes.find(aKey) != myParentAttributes.end()) { + result = myParentAttributes[aKey]; + } + return result; +} diff --git a/src/Config/Config_FeatureReader.h b/src/Config/Config_FeatureReader.h index c9535c34b..92a9d705f 100644 --- a/src/Config/Config_FeatureReader.h +++ b/src/Config/Config_FeatureReader.h @@ -14,6 +14,7 @@ #include #include +#include class Config_FeatureMessage; @@ -34,9 +35,16 @@ class Config_FeatureReader : public Config_XMLReader const boost::shared_ptr& outFeatureMessage); bool isInternalFeature(xmlNodePtr theRoot); + void storeAttribute(xmlNodePtr theNode, const char* theNodeAttribute); + std::string restoreAttribute(xmlNodePtr theNode, const char* theNodeAttribute); + std::string restoreAttribute(const char* theNodeName, const char* theNodeAttribute); + private: - std::string myLastWorkbench; - std::string myLastGroup; + /// A map to store all parent's attributes. + /// The key has from "Node_Name:Node_Attribute" + std::map myParentAttributes; + //std::string myLastWorkbench; + //std::string myLastGroup; std::string myLibraryName; std::list myFeatures; diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 37acefda5..f8f3bd6ed 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -40,6 +40,7 @@ const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor"; const static char* WDG_FILE_SELECTOR= "file_selector"; +const static char* WORKBENCH_DOC = "document"; //Common Widget's or Feature's Properties const static char* _ID = "id"; const static char* FEATURE_TOOLTIP = "tooltip"; diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 3b206f3ce..81c5d3725 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -138,6 +138,16 @@ xmlNodePtr Config_XMLReader::node(void* theNode) return static_cast(theNode); } +std::string Config_XMLReader::getNodeName(xmlNodePtr theNode) +{ + std::string result = ""; + char* aPropChars = (char*) theNode->name; + if (!aPropChars || aPropChars[0] == 0) + return result; + result = std::string(aPropChars); + return result; +} + /* * Returns named property for a given node as std::string. */ diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index b3e1554ee..bd9392841 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -47,6 +47,7 @@ class Config_XMLReader void readRecursively(xmlNodePtr theParent); xmlNodePtr node(void* theNode); + std::string getNodeName(xmlNodePtr theNode); std::string getProperty(xmlNodePtr theNode, const char* property); void processValidator(xmlNodePtr theNode); diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 9e265d525..876a74821 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -1,5 +1,5 @@ - + diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 08eb944fa..63a64fe6b 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -399,6 +399,8 @@ FeaturePtr Model_Document::addFeature(std::string theID) TDF_Label anEmptyLab; FeaturePtr anEmptyFeature; FeaturePtr aFeature = ModelAPI_Session::get()->createFeature(theID); + if (!aFeature) + return aFeature; boost::shared_ptr aDocToAdd = boost::dynamic_pointer_cast( aFeature->documentToAdd()); if (aFeature) { diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index bf69b04c2..843981afa 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -8,6 +8,8 @@ #include "XGUI_OperationMgr.h" #include "XGUI_SalomeConnector.h" +#include + #include #include @@ -69,6 +71,7 @@ void XGUI_ActionsMgr::update() setAllEnabled(true); setNestedCommandsEnabled(false); } + updateByDocumentKind(); updateCheckState(); } @@ -116,6 +119,25 @@ void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theCheck } } +/* + * Disables all actions which have the Document Kind different to + * the current document's kind + */ +void XGUI_ActionsMgr::updateByDocumentKind() +{ + std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind(); + QString aDocKind = QString::fromStdString(aStdDocKind); + foreach(QAction* eachAction, myActions.values()) { + XGUI_Command* aCmd = dynamic_cast(eachAction); + if(aCmd) { + QString aCmdDocKind = aCmd->documentKind(); + if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) { + eachAction->setEnabled(false); + } + } + } +} + void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled) { QAction* anAction = myActions[theId]; diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index 4a6ad4a6b..8df73304d 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -40,6 +40,8 @@ Q_OBJECT QKeySequence registerShortcut(const QString& theKeySequence); + void updateByDocumentKind(); + public slots: //! Update workbench actions according to OperationMgr state: //! No active operations: all actions but nested are available diff --git a/src/XGUI/XGUI_Command.cpp b/src/XGUI/XGUI_Command.cpp index 07d0d310f..4f726ab5d 100644 --- a/src/XGUI/XGUI_Command.cpp +++ b/src/XGUI/XGUI_Command.cpp @@ -4,17 +4,26 @@ #include #include -XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable) +XGUI_Command::XGUI_Command(const QString& theId, + const QString& theDocumentKind, + QObject * parent, + bool isCheckable) : QWidgetAction(parent), - myCheckable(isCheckable) + myCheckable(isCheckable), + myDocumentKind(theDocumentKind) { setData(theId); } -XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, - QObject* parent, bool isCheckable) +XGUI_Command::XGUI_Command(const QString& theId, + const QString& theDocumentKind, + const QIcon& icon, + const QString& text, + QObject* parent, + bool isCheckable) : QWidgetAction(parent), - myCheckable(isCheckable) + myCheckable(isCheckable), + myDocumentKind(theDocumentKind) { setIcon(icon); setText(text); @@ -25,6 +34,11 @@ XGUI_Command::~XGUI_Command() { } +const QString& XGUI_Command::documentKind() const +{ + return myDocumentKind; +} + QWidget* XGUI_Command::createWidget(QWidget* theParent) { if (theParent->inherits("XGUI_MenuGroupPanel")) { @@ -67,4 +81,4 @@ const QStringList& XGUI_Command::nestedCommands() const void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands) { this->myNestedCommands = myUnblockableCommands; -} \ No newline at end of file +} diff --git a/src/XGUI/XGUI_Command.h b/src/XGUI/XGUI_Command.h index 696518789..0f5aa6271 100644 --- a/src/XGUI/XGUI_Command.h +++ b/src/XGUI/XGUI_Command.h @@ -15,17 +15,14 @@ class XGUI_EXPORT XGUI_Command : public QWidgetAction { Q_OBJECT public: - XGUI_Command(const QString& theId, QObject * parent, bool isCheckable = false); - XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent, + XGUI_Command(const QString& theId, const QString& theDocumentKind, + QObject * parent, bool isCheckable = false); + XGUI_Command(const QString& theId, const QString& theDocumentKind, + const QIcon& icon, const QString& text, QObject* parent, bool isCheckable = false); ~XGUI_Command(); - //VSV: Don't use this method for compatibility with SALOME. Use the construction below - /*virtual QString id() const - { - return data().toString(); - }*/ - + const QString& documentKind() const; const QStringList& nestedCommands() const; void setNestedCommands(const QStringList& myUnblockableCommands); @@ -38,6 +35,8 @@ Q_OBJECT private: bool myCheckable; + + QString myDocumentKind; //! List of Ids of commands which WILL NOT be blocked when the command is on. QStringList myNestedCommands; }; diff --git a/src/XGUI/XGUI_MenuGroupPanel.cpp b/src/XGUI/XGUI_MenuGroupPanel.cpp index 30c459466..a1883f26b 100644 --- a/src/XGUI/XGUI_MenuGroupPanel.cpp +++ b/src/XGUI/XGUI_MenuGroupPanel.cpp @@ -67,11 +67,25 @@ void XGUI_MenuGroupPanel::resizeEvent(QResizeEvent* theEvent) myLayout->setRowStretch(myMaxRow + 1, 1); } -XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QString& theTitle, - const QString& theTip, const QIcon& theIcon, - const QKeySequence& theKeys, bool isCheckable) +XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, + const QString& theTip, + const QString& theTitle, + const QIcon& theIcon, + const QKeySequence& theKeys) { - XGUI_Command* aCommand = new XGUI_Command(theId, theIcon, theTitle, this, isCheckable); + return addFeature(theId, theTip, theTitle, theIcon, QString(), theKeys, false); +} + +XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, + const QString& theTitle, + const QString& theTip, + const QIcon& theIcon, + const QString& theDocumentKind, + const QKeySequence& theKeys, + bool isCheckable) +{ + XGUI_Command* aCommand = new XGUI_Command(theId, theDocumentKind, theIcon, + theTitle, this, isCheckable); aCommand->setToolTip(theTip); if (!theKeys.isEmpty()) { aCommand->setShortcut(theKeys); diff --git a/src/XGUI/XGUI_MenuGroupPanel.h b/src/XGUI/XGUI_MenuGroupPanel.h index 7cf1f1d41..76de10371 100644 --- a/src/XGUI/XGUI_MenuGroupPanel.h +++ b/src/XGUI/XGUI_MenuGroupPanel.h @@ -20,8 +20,18 @@ Q_OBJECT explicit XGUI_MenuGroupPanel(QWidget *parent = 0); //! Adding a new feature (Command) in the group - XGUI_Command* addFeature(const QString& theId, const QString& theTitle, const QString& theTip, - const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence(), + XGUI_Command* addFeature(const QString& theId, + const QString& theTip, + const QString& theTitle, + const QIcon& theIcon, + const QKeySequence& theKeys = QKeySequence()); + + XGUI_Command* addFeature(const QString& theId, + const QString& theTip, + const QString& theTitle, + const QIcon& theIcon, + const QString& theDocumentKind = QString(), + const QKeySequence& theKeys = QKeySequence(), bool isCheckable = false); //! Returns already created command by its ID diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index bbec2aabf..25866c87c 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -198,11 +198,11 @@ void XGUI_Workshop::initMenu() aCommand->connectTo(this, SLOT(onRedo())); aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"), - QIcon(":pictures/rebuild.png")); + QIcon(":pictures/rebuild.png"), QKeySequence()); aCommand->connectTo(this, SLOT(onRebuild())); aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"), - QIcon(":pictures/save.png")); + QIcon(":pictures/save.png"), QKeySequence()); aCommand->connectTo(this, SLOT(onSaveAs())); //aCommand->disable(); @@ -342,6 +342,7 @@ void XGUI_Workshop::processEvent(const boost::shared_ptr& theMes // Find and Activate active part if (myPartActivating) return; + myActionsMgr->update(); SessionPtr aMgr = ModelAPI_Session::get(); DocumentPtr aActiveDoc = aMgr->activeDocument(); DocumentPtr aDoc = aMgr->moduleDocument(); @@ -558,7 +559,8 @@ void XGUI_Workshop::addFeature(const boost::shared_ptr& t QString::fromStdString(theMessage->text()), QString::fromStdString(theMessage->tooltip()), QIcon(theMessage->icon().c_str()), - QKeySequence(), isUsePropPanel); + QKeySequence(), + isUsePropPanel); salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts)); myActionsMgr->addCommand(aAction); myModule->featureCreated(aAction); @@ -575,6 +577,7 @@ void XGUI_Workshop::addFeature(const boost::shared_ptr& t if (!aGroup) { aGroup = aPage->addGroup(aGroupName); } + QString aDocKind = QString::fromStdString(theMessage->documentKind()); // Check if hotkey sequence is already defined: QKeySequence aHotKey = myActionsMgr->registerShortcut( QString::fromStdString(theMessage->keysequence())); @@ -582,7 +585,9 @@ void XGUI_Workshop::addFeature(const boost::shared_ptr& t XGUI_Command* aCommand = aGroup->addFeature(aFeatureId, QString::fromStdString(theMessage->text()), QString::fromStdString(theMessage->tooltip()), - QIcon(theMessage->icon().c_str()), aHotKey, + QIcon(theMessage->icon().c_str()), + aDocKind, + aHotKey, isUsePropPanel); aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts)); myActionsMgr->addCommand(aCommand);