1 // Copyright (C) 2007-2008 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.
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
22 // SMESH SMESHGUI : reading of xml file with list of available hypotheses and algorithms
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";
133 bool isNeedGeom = true, isSupportSubmeshes = false;
134 QString aNeedGeom = atts.value("need-geom");
135 if ( !aNeedGeom.isEmpty() )
136 isNeedGeom = (aNeedGeom == "true");
137 QString suppSub = atts.value("support-submeshes");
138 if ( !suppSub.isEmpty() )
139 isSupportSubmeshes = (suppSub == "true");
141 QString aDimStr = atts.value("dim");
142 aDimStr = aDimStr.remove( ' ' );
143 QStringList aDimList = QStringList::split( ',', aDimStr );
144 QStringList::iterator anIter;
146 QValueList<int> aDim;
147 for ( anIter = aDimList.begin(); anIter != aDimList.end(); ++anIter )
149 int aVal = (*anIter).toInt( &isOk );
155 enum { HYPOS = 0, OPT_HYPOS, INPUT, OUTPUT, NB_ATTRIBUTES };
156 const char* name [NB_ATTRIBUTES] = { "hypos", "opt-hypos", "input", "output" };
157 QStringList attr [NB_ATTRIBUTES];
158 for ( int i = 0; i < NB_ATTRIBUTES; ++i ) {
159 QString aStr = atts.value( name[i] );
160 if ( !aStr.isEmpty() ) {
162 attr[ i ] = QStringList::split( ',', aStr );
166 HypothesisData* aHypData =
167 new HypothesisData (aHypAlType, myPluginName, myServerLib, myClientLib,
168 aLabel, anIcon, aDim, isAux,
169 attr[ HYPOS ], attr[ OPT_HYPOS ], attr[ INPUT ], attr[ OUTPUT ],
170 isNeedGeom, isSupportSubmeshes );
172 if (qName == "algorithm")
174 myAlgorithmsMap[(char*)aHypAlType.latin1()] = aHypData;
178 myHypothesesMap[(char*)aHypAlType.latin1()] = aHypData;
182 else if (qName == "hypotheses-set-group") // group of sets of hypotheses
185 else if (qName == "hypotheses-set") // a set of hypotheses
187 if (atts.value("name") != "")
189 HypothesesSet* aHypoSet = new HypothesesSet ( atts.value("name") );
190 myListOfHypothesesSets.push_back( aHypoSet );
192 for ( int isHypo = 0; isHypo < 2; ++isHypo )
194 QString aHypos = isHypo ? atts.value("hypos") : atts.value("algos");
195 aHypos = aHypos.remove( ' ' );
196 QStringList* aHypoList = isHypo ? & aHypoSet->HypoList : & aHypoSet->AlgoList;
197 *aHypoList = QStringList::split( ',', aHypos );
211 Reimplemented from QXmlDefaultHandler.
213 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
220 Reimplemented from QXmlDefaultHandler.
222 bool SMESHGUI_XmlHandler::characters (const QString& ch)
224 // we are not interested in whitespaces
225 QString ch_simplified = ch.simplifyWhiteSpace();
226 if ( ch_simplified.isEmpty() )
233 Returns the default error string.
235 Reimplemented from QXmlDefaultHandler.
237 QString SMESHGUI_XmlHandler::errorString()
239 return "the document is not in the quote file format";
243 Returns the error protocol if parsing failed
245 Reimplemented from QXmlDefaultHandler.
247 QString SMESHGUI_XmlHandler::errorProtocol()
255 Reimplemented from QXmlDefaultHandler.
257 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
259 myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
260 .arg(exception.message())
261 .arg(exception.lineNumber())
262 .arg(exception.columnNumber());
264 return QXmlDefaultHandler::fatalError( exception );