]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Document's kind dependent features implemented
authorsbh <sergey.belash@opencascade.com>
Tue, 23 Sep 2014 09:16:48 +0000 (13:16 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 23 Sep 2014 09:16:48 +0000 (13:16 +0400)
14 files changed:
src/Config/Config_FeatureReader.cpp
src/Config/Config_FeatureReader.h
src/Config/Config_Keywords.h
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/FeaturesPlugin/plugin-Features.xml
src/Model/Model_Document.cpp
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_Command.cpp
src/XGUI/XGUI_Command.h
src/XGUI/XGUI_MenuGroupPanel.cpp
src/XGUI/XGUI_MenuGroupPanel.h
src/XGUI/XGUI_Workshop.cpp

index 19f4499e8e2660f19cc8cf2d1f72d9a3463e248c..1f7a65b2dcbc366f278e94c9c37b4d09da2d57ae 100644 (file)
@@ -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;
+}
index c9535c34bf72e4ca9d25aaa9fdcdf9799af895e0..92a9d705fc630b2bc17ce1d5b387eb8a40e89c3f 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <string>
 #include <list>
+#include <map>
 
 class Config_FeatureMessage;
 
@@ -34,9 +35,16 @@ class Config_FeatureReader : public Config_XMLReader
     const boost::shared_ptr<Config_FeatureMessage>& 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<std::string, std::string> myParentAttributes;
+  //std::string myLastWorkbench;
+  //std::string myLastGroup;
   std::string myLibraryName;
 
   std::list<std::string> myFeatures;
index 37acefda536fd7f8f6e2cebc9571cff9a8ca862a..f8f3bd6ed959cb7b5872853390734fda5581685e 100644 (file)
@@ -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";
index 3b206f3ce7a5717fa0a27b3d2613d30f0ecd7b10..81c5d37258f41e8828e9623b0bbe96e0d1ab1911 100644 (file)
@@ -138,6 +138,16 @@ xmlNodePtr Config_XMLReader::node(void* theNode)
   return static_cast<xmlNodePtr>(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.
  */
index b3e1554ee00d0c0752a69f2f2aed6ea060109788..bd9392841b131eb63816f3517db82a3c0543f5b2 100644 (file)
@@ -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);
 
index 9e265d525623c3695b3ff72cfd1b76534fc3af2b..876a748219b28b828aabf764b8ebbdc73204019d 100644 (file)
@@ -1,5 +1,5 @@
 <plugin>
-  <workbench id="Features">
+  <workbench id="Features" document="Part">
     <group id="Basic">
       <feature id="Extrusion" title="Extrusion" tooltip="Create a shape by extrusion of a contour" icon=":icons/extrusion.png">
           <source path="extrusion_widget.xml"/>
index 08eb944fa8e84d39e687cce872e802912fc61f2a..63a64fe6bb9b1e8a33b75c37809562a682a30435 100644 (file)
@@ -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<Model_Document> aDocToAdd = boost::dynamic_pointer_cast<Model_Document>(
       aFeature->documentToAdd());
   if (aFeature) {
index bf69b04c2c2b0c581e57aa496034a84772db6f43..843981afa30842414e15cbb198b5cf6c1ff27f94 100644 (file)
@@ -8,6 +8,8 @@
 #include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
 
+#include <ModelAPI_Session.h>
+
 #include <ModuleBase_Operation.h>
 #include <Events_Error.h>
 
@@ -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<XGUI_Command*>(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];
index 4a6ad4a6bc1d5e757bc882eab730bbf15f42eced..8df73304db8b4a2f1a8031d62ddb664277219b08 100644 (file)
@@ -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
index 07d0d310f8add811d55e7c3446d1f41b1423416e..4f726ab5d442b62cc99675b5ffe0fc175ee138d4 100644 (file)
@@ -4,17 +4,26 @@
 #include <QVariant>
 #include <QDebug>
 
-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
+}
index 696518789e5016eb85d83661af23a32e5c7599e2..0f5aa627159862b360ea38b44e0ec56c38600fa7 100644 (file)
@@ -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;
 };
index 30c459466e9eaa44c303d1c28ce09bc40501270c..a1883f26baec7d7eb14dce73bb02302f07784e91 100644 (file)
@@ -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);
index 7cf1f1d4164e5a76246034ddfc98d6e3b5e3e305..76de10371f6f1c4a0a87eb8f7cff50bcabf35963 100644 (file)
@@ -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
index bbec2aabffb3728a5a56d887f0367edc010ab541..25866c87cd26bb6216df220c51dbd62c819548de 100644 (file)
@@ -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<Events_Message>& 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<Config_FeatureMessage>& 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<Config_FeatureMessage>& 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<Config_FeatureMessage>& 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);