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);
}
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)
}
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;
+}
#include <string>
#include <list>
+#include <map>
class Config_FeatureMessage;
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;
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";
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.
*/
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);
<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"/>
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) {
#include "XGUI_OperationMgr.h"
#include "XGUI_SalomeConnector.h"
+#include <ModelAPI_Session.h>
+
#include <ModuleBase_Operation.h>
#include <Events_Error.h>
setAllEnabled(true);
setNestedCommandsEnabled(false);
}
+ updateByDocumentKind();
updateCheckState();
}
}
}
+/*
+ * 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];
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
#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);
{
}
+const QString& XGUI_Command::documentKind() const
+{
+ return myDocumentKind;
+}
+
QWidget* XGUI_Command::createWidget(QWidget* theParent)
{
if (theParent->inherits("XGUI_MenuGroupPanel")) {
void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
{
this->myNestedCommands = myUnblockableCommands;
-}
\ No newline at end of file
+}
{
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);
private:
bool myCheckable;
+
+ QString myDocumentKind;
//! List of Ids of commands which WILL NOT be blocked when the command is on.
QStringList myNestedCommands;
};
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);
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
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();
// Find and Activate active part
if (myPartActivating)
return;
+ myActionsMgr->update();
SessionPtr aMgr = ModelAPI_Session::get();
DocumentPtr aActiveDoc = aMgr->activeDocument();
DocumentPtr aDoc = aMgr->moduleDocument();
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);
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()));
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);