1 // Copyright (C) 2014-2023 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Config_Keywords.h>
21 #include <Config_Common.h>
22 #include <Config_FeatureMessage.h>
23 #include <Config_AttributeMessage.h>
24 #include <Config_FeatureReader.h>
25 #include <Config_Translator.h>
26 #include <Events_Message.h>
27 #include <Events_Loop.h>
29 #include <libxml/parser.h>
30 #include <libxml/tree.h>
31 #include <libxml/xmlstring.h>
41 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
42 const std::string& theLibraryName,
43 const std::string& theDocSection,
44 const char* theEventGenerated)
45 : Config_XMLReader(theXmlFile),
46 myLibraryName(theLibraryName),
47 myLibraryDocSection(theDocSection),
48 myEventGenerated(theEventGenerated ? theEventGenerated : Config_FeatureMessage::GUI_EVENT()),
49 myIsProcessWidgets(theEventGenerated != NULL)
53 Config_FeatureReader::~Config_FeatureReader()
57 std::list<std::string> Config_FeatureReader::features() const
62 void Config_FeatureReader::processNode(xmlNodePtr theNode)
64 Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
65 if (isNode(theNode, NODE_FEATURE, NULL)) {
66 storeAttribute(theNode, _ID);
67 std::shared_ptr<Config_FeatureMessage>
68 aMessage(new Config_FeatureMessage(aMenuItemEvent, this));
69 fillFeature(theNode, aMessage);
70 myFeatures.push_back(getProperty(theNode, _ID));
71 //If a feature has xml definition for it's widget:
72 aMessage->setUseInput(hasChild(theNode));
73 Events_Loop::loop()->send(aMessage);
74 //The m_last* variables always defined before fillFeature() call. XML is a tree.
75 } else if (isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL)) {
76 storeAttribute(theNode, _ID);
77 storeAttribute(theNode, GROUP_TOOLBAR);
78 storeAttribute(theNode, WORKBENCH_DOC, true);
79 } else if (myIsProcessWidgets) {
80 // widgets, like shape_selector or containers, like toolbox
81 if (isAttributeNode(theNode)) {
82 std::shared_ptr<Config_AttributeMessage>
83 aMessage(new Config_AttributeMessage(aMenuItemEvent, this));
84 aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
85 std::string anAttributeID = getProperty(theNode, _ID);
86 if (!anAttributeID.empty()) {
87 aMessage->setAttributeId(anAttributeID);
88 aMessage->setObligatory(getBooleanAttribute(theNode, ATTR_OBLIGATORY, true));
89 bool isConcealment = getBooleanAttribute(theNode, ATTR_CONCEALMENT, false);
90 aMessage->setConcealment(isConcealment);
91 bool isMainArg = isConcealment && getBooleanAttribute(theNode, ATTR_MAIN_ARG, false);
92 aMessage->setMainArgument(isMainArg);
93 aMessage->setGeometricalSelection(getBooleanAttribute(theNode,
94 ATTR_GEOMETRICAL_SELECTION,
97 std::list<std::pair<std::string, std::string> > aCases;
98 xmlNodePtr aCaseNode = hasParentRecursive(theNode,
99 WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, WDG_OPTIONALBOX, WDG_RADIOBOX_ITEM, NULL);
101 std::string aCaseNodeID = getProperty(aCaseNode, _ID);
102 std::string aSwitchNodeID = "";
103 const xmlChar* aName = aCaseNode->name;
104 xmlNodePtr aSwitchNode = 0;
105 if (!xmlStrcmp(aName, (const xmlChar *) WDG_SWITCH_CASE)) {
106 aSwitchNode = hasParentRecursive(aCaseNode, WDG_SWITCH, NULL);
108 else if (!xmlStrcmp(aName, (const xmlChar *) WDG_TOOLBOX_BOX)) {
109 aSwitchNode = hasParentRecursive(aCaseNode, WDG_TOOLBOX, NULL);
111 else if (!xmlStrcmp(aName, (const xmlChar *)WDG_RADIOBOX_ITEM)) {
112 aSwitchNode = hasParentRecursive(aCaseNode, WDG_RADIOBOX, NULL);
114 if (!xmlStrcmp(aName, (const xmlChar *) WDG_OPTIONALBOX)) {
115 /// the box is optional, attribute is in case
116 /// if the optional attribute value is not empty
117 aSwitchNode = aCaseNode;
120 aSwitchNodeID = getProperty(aSwitchNode, _ID);
122 aCases.push_back(std::make_pair(aSwitchNodeID, aCaseNodeID));
123 aCaseNode = hasParentRecursive(aSwitchNode, WDG_SWITCH_CASE,
124 WDG_TOOLBOX_BOX, WDG_OPTIONALBOX, WDG_RADIOBOX_ITEM, NULL);
126 aMessage->setCases(aCases);
127 Events_Loop::loop()->send(aMessage);
129 // container pages, like "case" or "box"
130 } else if (isNode(theNode, WDG_OPTIONALBOX, WDG_SWITCH, WDG_SWITCH_CASE,
131 WDG_TOOLBOX, WDG_TOOLBOX_BOX,
132 WDG_RADIOBOX, WDG_RADIOBOX_ITEM, NULL)) {
133 storeAttribute(theNode, _ID); // save case:caseId (or box:boxId)
136 //Process SOURCE nodes.
137 Config_XMLReader::processNode(theNode);
140 void Config_FeatureReader::cleanup(xmlNodePtr theNode)
142 if (isNode(theNode, WDG_OPTIONALBOX, WDG_SWITCH, WDG_SWITCH_CASE,
143 WDG_TOOLBOX, WDG_TOOLBOX_BOX, WDG_RADIOBOX_ITEM, WDG_RADIOBOX, NULL)) {
144 // cleanup id of cases when leave case node
145 cleanupAttribute(theNode, _ID);
149 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
151 bool result = isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
152 if(!result && myIsProcessWidgets) {
153 result = isNode(theNode, NODE_FEATURE,
154 WDG_GROUP, WDG_OPTIONALBOX,
155 WDG_TOOLBOX, WDG_TOOLBOX_BOX,
156 WDG_RADIOBOX, WDG_RADIOBOX_ITEM,
157 WDG_SWITCH, WDG_SWITCH_CASE, NULL);
162 void Config_FeatureReader::fillFeature(xmlNodePtr theFeatureNode,
163 const std::shared_ptr<Config_FeatureMessage>& outFeatureMessage)
165 std::string anId = getProperty(theFeatureNode, _ID);
166 outFeatureMessage->setId(anId);
167 outFeatureMessage->setPluginLibrary(myLibraryName);
168 outFeatureMessage->setNestedFeatures(getProperty(theFeatureNode, FEATURE_NESTED));
169 outFeatureMessage->setActionsWhenNested(getNormalizedProperty(theFeatureNode,
170 FEATURE_WHEN_NESTED));
171 outFeatureMessage->setModal(getBooleanAttribute(theFeatureNode, FEATURE_MODAL, false));
172 bool isAutoPreview = getBooleanAttribute(theFeatureNode, FEATURE_AUTO_PREVIEW, true);
173 outFeatureMessage->setAutoPreview(isAutoPreview);
174 outFeatureMessage->setApplyContinue(
175 getBooleanAttribute(theFeatureNode, FEATURE_APPLY_CONTINUE, false));
177 bool isInternal = getBooleanAttribute(theFeatureNode, ATTR_INTERNAL, false);
178 outFeatureMessage->setInternal(isInternal);
180 std::string aHelpFile = getProperty(theFeatureNode, HELP_FILE);
181 if (!aHelpFile.empty()) {
183 (myLibraryDocSection.empty() ? myLibraryName : myLibraryDocSection) + "/" + aHelpFile;
184 outFeatureMessage->setHelpFileName(aHelpFile);
187 bool isHideFaces = getBooleanAttribute(theFeatureNode, HIDEFACES_PANEL, false);
188 outFeatureMessage->setHideFacesPanel(isHideFaces);
190 bool isConfirmAbort = getBooleanAttribute(theFeatureNode, ABORT_CONFIRMATION, true);
191 outFeatureMessage->setAbortConfirmation(isConfirmAbort);
194 // //Internal feature has no visual representation.
198 std::string aText = Config_Translator::translate(anId, getProperty(theFeatureNode, FEATURE_TEXT));
199 outFeatureMessage->setText(aText);
200 bool isTitleInToolbar = getBooleanAttribute(theFeatureNode, FEATURE_TITLE_IN_TOOLBAR, true);
201 outFeatureMessage->setTitleInToolbar(isTitleInToolbar);
202 std::string aToolTip = Config_Translator::translate(
203 anId, getProperty(theFeatureNode, FEATURE_TOOLTIP));
204 outFeatureMessage->setTooltip(aToolTip);
205 outFeatureMessage->setIcon(getProperty(theFeatureNode, FEATURE_ICON));
206 outFeatureMessage->setKeysequence(getProperty(theFeatureNode, FEATURE_KEYSEQUENCE));
208 std::string aGroupName = restoreAttribute(NODE_GROUP, _ID);
209 std::string aWBNName = restoreAttribute(NODE_WORKBENCH, _ID);
210 std::string isGroupToolbarId = restoreAttribute(NODE_GROUP, GROUP_TOOLBAR);
211 bool isGroupToolbar = false;
212 if (isGroupToolbarId.length() > 0)
213 isGroupToolbar = (isGroupToolbarId == "yes");
214 outFeatureMessage->setGroupId(aGroupName);
215 outFeatureMessage->setWorkbenchId(aWBNName);
216 outFeatureMessage->setToolBarId(isGroupToolbar ? aGroupName : aWBNName);
218 // Get document kind of a feature, if empty set workbench's kind (might be empty too)
219 std::string aDocKind = getProperty(theFeatureNode, FEATURE_DOC);
220 if(aDocKind.empty()) {
221 aDocKind = restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC);
223 outFeatureMessage->setDocumentKind(aDocKind);