1 // SMESH SMESHGUI : reading of xml file with list of available hypotheses and algorithms
2 // Copyright (C) 2003 CEA
4 // This library is free software; you can redistribute it and/or
5 // // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESHGUI_XmlHandler.cxx
24 // Author : Julia DOROVSKIKH
28 #define INCLUDE_MENUITEM_DEF
31 #include <qfileinfo.h>
32 #include <qstringlist.h>
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Desktop.h"
38 #include "SMESHGUI_XmlHandler.h"
39 #include "SMESHGUI_Hypotheses.h"
40 #include "SMESHGUI_Utils.h"
42 #include "utilities.h"
49 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
56 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
61 Starts parsing of document. Does some initialization
63 Reimplemented from QXmlDefaultHandler.
65 bool SMESHGUI_XmlHandler::startDocument()
72 Does different actions depending on the name of the tag and the
73 state you are in document.
75 Reimplemented from QXmlDefaultHandler.
77 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&,
79 const QXmlAttributes& atts)
81 if (qName == "meshers")
83 myHypothesesMap.clear();
84 myAlgorithmsMap.clear();
86 else if (qName == "meshers-group") // group of hypotheses and algorithms
88 // if (atts.value("server-lib") != "")
90 myPluginName = atts.value("name");
91 myServerLib = atts.value("server-lib");
92 myClientLib = atts.value("gui-lib");
93 /* It's Need to tranlate lib name for WIN32 or X platform
94 * (only client lib, because server lib translates in SMESH_Gen_i::createHypothesis
95 * for normal work of *.py files )
97 if( !myClientLib.isEmpty() )
100 //myServerLib += ".dll";
101 myClientLib += ".dll";
103 //myServerLib = "lib" + myServerLib + ".so";
104 myClientLib = "lib" + myClientLib + ".so";
109 QString aResName = atts.value("resources");
112 MESSAGE("Loading Resources " << aResName);
113 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
114 resMgr->loadTranslator("resources",aResName+"_msg_en.qm");
115 resMgr->loadTranslator("resources",aResName+"_images.qm");
119 else if (qName == "hypotheses") // group of hypotheses
122 else if (qName == "algorithms") // group of algorithms
125 else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
127 if (atts.value("type") != "")
129 QString aHypAlType = atts.value("type");
130 QString aLabel = atts.value("label-id");
131 QString anIcon = atts.value("icon-id");
132 bool isAux = atts.value("auxiliary") == "true";
134 QString aDimStr = atts.value("dim");
135 aDimStr = aDimStr.remove( ' ' );
136 QStringList aDimList = QStringList::split( ',', aDimStr );
137 QStringList::iterator anIter;
139 QValueList<int> aDim;
140 for ( anIter = aDimList.begin(); anIter != aDimList.end(); ++anIter )
142 int aVal = (*anIter).toInt( &isOk );
148 enum { HYPOS = 0, OPT_HYPOS, INPUT, OUTPUT, NB_ATTRIBUTES };
149 const char* name [NB_ATTRIBUTES] = { "hypos", "opt-hypos", "input", "output" };
150 QStringList attr [NB_ATTRIBUTES];
151 for ( int i = 0; i < NB_ATTRIBUTES; ++i ) {
152 QString aStr = atts.value( name[i] );
153 if ( !aStr.isEmpty() ) {
155 attr[ i ] = QStringList::split( ',', aStr );
159 HypothesisData* aHypData =
160 new HypothesisData (aHypAlType, myPluginName, myServerLib, myClientLib,
161 aLabel, anIcon, aDim, isAux,
162 attr[ HYPOS ], attr[ OPT_HYPOS ], attr[ INPUT ], attr[ OUTPUT ]);
164 if (qName == "algorithm")
166 myAlgorithmsMap[(char*)aHypAlType.latin1()] = aHypData;
170 myHypothesesMap[(char*)aHypAlType.latin1()] = aHypData;
174 else if (qName == "hypotheses-set-group") // group of sets of hypotheses
177 else if (qName == "hypotheses-set") // a set of hypotheses
179 if (atts.value("name") != "")
181 HypothesesSet* aHypoSet = new HypothesesSet ( atts.value("name") );
182 myListOfHypothesesSets.push_back( aHypoSet );
184 for ( int isHypo = 0; isHypo < 2; ++isHypo )
186 QString aHypos = isHypo ? atts.value("hypos") : atts.value("algos");
187 aHypos = aHypos.remove( ' ' );
188 QStringList* aHypoList = isHypo ? & aHypoSet->HypoList : & aHypoSet->AlgoList;
189 *aHypoList = QStringList::split( ',', aHypos );
203 Reimplemented from QXmlDefaultHandler.
205 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
212 Reimplemented from QXmlDefaultHandler.
214 bool SMESHGUI_XmlHandler::characters (const QString& ch)
216 // we are not interested in whitespaces
217 QString ch_simplified = ch.simplifyWhiteSpace();
218 if ( ch_simplified.isEmpty() )
225 Returns the default error string.
227 Reimplemented from QXmlDefaultHandler.
229 QString SMESHGUI_XmlHandler::errorString()
231 return "the document is not in the quote file format";
235 Returns the error protocol if parsing failed
237 Reimplemented from QXmlDefaultHandler.
239 QString SMESHGUI_XmlHandler::errorProtocol()
247 Reimplemented from QXmlDefaultHandler.
249 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
251 myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
252 .arg(exception.message())
253 .arg(exception.lineNumber())
254 .arg(exception.columnNumber());
256 return QXmlDefaultHandler::fatalError( exception );