1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : reading of xml file with list of available hypotheses and algorithms
24 // File : SMESHGUI_XmlHandler.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
28 #include "SMESHGUI_XmlHandler.h"
31 #include "SMESHGUI_Hypotheses.h"
33 // SALOME GUI includes
34 #include "SUIT_ResourceMgr.h"
36 // SALOME KERNEL includes
37 #include <utilities.h>
39 #define BAD_HYP_FLAG "NOT_FOUND"
44 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
51 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
56 Starts parsing of document. Does some initialization
58 Reimplemented from QXmlDefaultHandler.
60 bool SMESHGUI_XmlHandler::startDocument()
67 Does different actions depending on the name of the tag and the
68 state you are in document.
70 Reimplemented from QXmlDefaultHandler.
72 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&,
74 const QXmlAttributes& atts)
76 if (qName == "meshers")
78 myHypothesesMap.clear();
79 myAlgorithmsMap.clear();
81 else if (qName == "meshers-group") // group of hypotheses and algorithms
83 // if (atts.value("server-lib") != "")
85 myPluginName = atts.value("name");
86 myServerLib = atts.value("server-lib");
87 myClientLib = atts.value("gui-lib");
88 /* It's Need to translate lib name for WIN32 or X platform
89 * (only client lib, because server lib translates in SMESH_Gen_i::createHypothesis
90 * for normal work of *.py files )
92 if( !myClientLib.isEmpty() )
95 //myServerLib += ".dll";
96 myClientLib += ".dll";
97 #elif defined(__APPLE__)
98 myClientLib = "lib" + myClientLib + ".dylib";
100 myClientLib = "lib" + myClientLib + ".so";
105 QString aResName = atts.value("resources");
108 //MESSAGE("Loading Resources " << aResName.toLatin1().data());
109 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
110 QString lang = resMgr->stringValue( resMgr->langSection(), "language", "en" );
111 resMgr->loadTranslator( "resources", QString( "%1_msg_%2.qm" ).arg( aResName, lang ) );
112 resMgr->loadTranslator( "resources", QString( "%1_images.qm" ).arg( aResName, lang ) );
116 else if (qName == "hypotheses") // group of hypotheses
119 else if (qName == "algorithms") // group of algorithms
122 else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
124 if (atts.value("type") != "")
126 QString aHypAlType = atts.value("type");
127 QString aLabel = atts.value("label-id");
128 QString anIcon = atts.value("icon-id");
129 bool isAuxOrNeedHyp = ( qName == "hypothesis" ?
130 atts.value("auxiliary") == "true" :
131 atts.value("need-hyp" ) == "true" );
133 bool isSupportSubmeshes = false;
134 QString aNeedGeom = atts.value("need-geom");
135 if ( !aNeedGeom.isEmpty() )
136 isNeedGeom = (aNeedGeom == "true") ? 1 : (aNeedGeom == "never") ? -1 : 0;
137 QString suppSub = atts.value("support-submeshes");
138 if ( !suppSub.isEmpty() )
139 isSupportSubmeshes = (suppSub == "true");
140 QString context = atts.value("context");
141 if ( context.isEmpty() )
144 context = context.toUpper();
147 QString groupIDStr = atts.value("group-id");
148 int groupID = groupIDStr.toUInt( &isOk );
149 if ( !isOk ) groupID = -1;
150 QString priorityStr = atts.value("priority");
151 int priority = priorityStr.toUInt( &isOk );
152 if ( !isOk ) priority = -1;
154 QString aDimStr = atts.value("dim");
155 aDimStr = aDimStr.remove( ' ' );
156 QStringList aDimList = aDimStr.split( ',', QString::SkipEmptyParts );
157 QStringList::iterator anIter;
159 for ( anIter = aDimList.begin(); anIter != aDimList.end(); ++anIter )
161 int aVal = (*anIter).toInt( &isOk );
167 enum { HYPOS = 0, OPT_HYPOS, INPUT, OUTPUT, NB_ATTRIBUTES };
168 const char* name [NB_ATTRIBUTES] = { "hypos", "opt-hypos", "input", "output" };
169 QStringList attr [NB_ATTRIBUTES];
170 for ( int i = 0; i < NB_ATTRIBUTES; ++i ) {
171 QString aStr = atts.value( name[i] );
172 if ( !aStr.isEmpty() ) {
173 attr[i] = aStr.split( ',', QString::SkipEmptyParts );
174 for ( int j = 0; j < attr[i].count(); ++j )
175 attr[i][j] = attr[i][j].trimmed();
179 if ( !aHypAlType.contains( BAD_HYP_FLAG ) ) {
180 HypothesisData* aHypData =
181 new HypothesisData (aHypAlType, myPluginName, myServerLib, myClientLib,
182 aLabel, anIcon, context, groupID, priority, aDim, isAuxOrNeedHyp,
183 attr[ HYPOS ], attr[ OPT_HYPOS ], attr[ INPUT ], attr[ OUTPUT ],
184 isNeedGeom, isSupportSubmeshes );
186 if (qName == "algorithm")
188 myAlgorithmsMap.insert(aHypAlType,aHypData);
192 myHypothesesMap.insert(aHypAlType,aHypData);
197 else if (qName == "hypotheses-set-group") // group of sets of hypotheses
200 else if (qName == "hypotheses-set") // a set of hypotheses
202 if (atts.value("name") != "")
204 bool useCommonSize = ( atts.value("use-common-size") == "true" );
205 bool isQuadDominated = ( atts.value("quad-dominated") == "true" );
206 QString hypos = atts.value("hypos");
207 QString algos = atts.value("algos");
208 QString altHypos = atts.value("alt-hypos");
209 QString altAlgos = atts.value("alt-algos");
210 QString intHypos = atts.value("intern-edge-hypos");
211 QString intAlgos = atts.value("intern-edge-algos");
212 bool badSet = hypos.contains( BAD_HYP_FLAG ) || algos.contains( BAD_HYP_FLAG );
215 myListOfHypothesesSets.append
216 ( new HypothesesSet ( atts.value("name"),
217 useCommonSize, isQuadDominated,
218 hypos.split ( ',', QString::SkipEmptyParts ),
219 algos.split ( ',', QString::SkipEmptyParts ),
220 altHypos.split( ',', QString::SkipEmptyParts ),
221 altAlgos.split( ',', QString::SkipEmptyParts ),
222 intHypos.split( ',', QString::SkipEmptyParts ),
223 intAlgos.split( ',', QString::SkipEmptyParts )));
226 else if ( qName == "python-wrap" ||
229 qName == "accumulative-methods")
231 // elements used in SMESH_2smeshpy
244 Reimplemented from QXmlDefaultHandler.
246 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
253 Reimplemented from QXmlDefaultHandler.
255 bool SMESHGUI_XmlHandler::characters (const QString& ch)
257 // we are not interested in whitespaces
258 QString ch_simplified = ch.simplified();
259 if ( ch_simplified.isEmpty() )
266 Returns the default error string.
268 Reimplemented from QXmlDefaultHandler.
270 QString SMESHGUI_XmlHandler::errorString()
272 return "the document is not in the quote file format";
276 Returns the error protocol if parsing failed
278 Reimplemented from QXmlDefaultHandler.
280 QString SMESHGUI_XmlHandler::errorProtocol()
288 Reimplemented from QXmlDefaultHandler.
290 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
292 myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
293 .arg(exception.message())
294 .arg(exception.lineNumber())
295 .arg(exception.columnNumber());
297 return QXmlDefaultHandler::fatalError( exception );