1 // SMESH SMESHGUI : reading of xml file with list of available hypotheses and algorithms
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // 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
21 // File : SMESHGUI_XmlHandler.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
26 #include "SMESHGUI_XmlHandler.h"
29 #include "SMESHGUI_Hypotheses.h"
31 // SALOME GUI includes
32 #include "SUIT_ResourceMgr.h"
34 // SALOME KERNEL includes
35 #include <utilities.h>
40 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
47 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
52 Starts parsing of document. Does some initialization
54 Reimplemented from QXmlDefaultHandler.
56 bool SMESHGUI_XmlHandler::startDocument()
63 Does different actions depending on the name of the tag and the
64 state you are in document.
66 Reimplemented from QXmlDefaultHandler.
68 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&,
70 const QXmlAttributes& atts)
72 if (qName == "meshers")
74 myHypothesesMap.clear();
75 myAlgorithmsMap.clear();
77 else if (qName == "meshers-group") // group of hypotheses and algorithms
79 // if (atts.value("server-lib") != "")
81 myPluginName = atts.value("name");
82 myServerLib = atts.value("server-lib");
83 myClientLib = atts.value("gui-lib");
84 /* It's Need to tranlate lib name for WIN32 or X platform
85 * (only client lib, because server lib translates in SMESH_Gen_i::createHypothesis
86 * for normal work of *.py files )
88 if( !myClientLib.isEmpty() )
91 //myServerLib += ".dll";
92 myClientLib += ".dll";
94 //myServerLib = "lib" + myServerLib + ".so";
95 myClientLib = "lib" + myClientLib + ".so";
100 QString aResName = atts.value("resources");
103 MESSAGE("Loading Resources " << aResName.toLatin1().data());
104 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
105 QString lang = resMgr->stringValue( resMgr->langSection(), "language", "en" );
106 resMgr->loadTranslator( "resources", QString( "%1_msg_%2.qm" ).arg( aResName, lang ) );
107 resMgr->loadTranslator( "resources", QString( "%1_images.qm" ).arg( aResName, lang ) );
111 else if (qName == "hypotheses") // group of hypotheses
114 else if (qName == "algorithms") // group of algorithms
117 else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
119 if (atts.value("type") != "")
121 QString aHypAlType = atts.value("type");
122 QString aLabel = atts.value("label-id");
123 QString anIcon = atts.value("icon-id");
124 bool isAux = atts.value("auxiliary") == "true";
125 bool isNeedGeom = true;
126 QString aNeedGeom = atts.value("need-geom");
127 if ( !aNeedGeom.isEmpty() )
128 isNeedGeom = (aNeedGeom == "true");
130 QString aDimStr = atts.value("dim");
131 aDimStr = aDimStr.remove( ' ' );
132 QStringList aDimList = aDimStr.split( ',', QString::SkipEmptyParts );
133 QStringList::iterator anIter;
136 for ( anIter = aDimList.begin(); anIter != aDimList.end(); ++anIter )
138 int aVal = (*anIter).toInt( &isOk );
144 enum { HYPOS = 0, OPT_HYPOS, INPUT, OUTPUT, NB_ATTRIBUTES };
145 const char* name [NB_ATTRIBUTES] = { "hypos", "opt-hypos", "input", "output" };
146 QStringList attr [NB_ATTRIBUTES];
147 for ( int i = 0; i < NB_ATTRIBUTES; ++i ) {
148 QString aStr = atts.value( name[i] );
149 if ( !aStr.isEmpty() ) {
151 attr[ i ] = aStr.split( ',', QString::SkipEmptyParts );
155 HypothesisData* aHypData =
156 new HypothesisData (aHypAlType, myPluginName, myServerLib, myClientLib,
157 aLabel, anIcon, aDim, isAux,
158 attr[ HYPOS ], attr[ OPT_HYPOS ], attr[ INPUT ], attr[ OUTPUT ], isNeedGeom );
160 if (qName == "algorithm")
162 myAlgorithmsMap[aHypAlType.toLatin1().data()] = aHypData;
166 myHypothesesMap[aHypAlType.toLatin1().data()] = aHypData;
170 else if (qName == "hypotheses-set-group") // group of sets of hypotheses
173 else if (qName == "hypotheses-set") // a set of hypotheses
175 if (atts.value("name") != "")
177 HypothesesSet* aHypoSet = new HypothesesSet ( atts.value("name") );
178 myListOfHypothesesSets.push_back( aHypoSet );
180 for ( int isHypo = 0; isHypo < 2; ++isHypo )
182 QString aHypos = isHypo ? atts.value("hypos") : atts.value("algos");
183 aHypos = aHypos.remove( ' ' );
184 QStringList* aHypoList = isHypo ? & aHypoSet->HypoList : & aHypoSet->AlgoList;
185 *aHypoList = aHypos.split( ',', QString::SkipEmptyParts );
199 Reimplemented from QXmlDefaultHandler.
201 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
208 Reimplemented from QXmlDefaultHandler.
210 bool SMESHGUI_XmlHandler::characters (const QString& ch)
212 // we are not interested in whitespaces
213 QString ch_simplified = ch.simplified();
214 if ( ch_simplified.isEmpty() )
221 Returns the default error string.
223 Reimplemented from QXmlDefaultHandler.
225 QString SMESHGUI_XmlHandler::errorString()
227 return "the document is not in the quote file format";
231 Returns the error protocol if parsing failed
233 Reimplemented from QXmlDefaultHandler.
235 QString SMESHGUI_XmlHandler::errorProtocol()
243 Reimplemented from QXmlDefaultHandler.
245 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
247 myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
248 .arg(exception.message())
249 .arg(exception.lineNumber())
250 .arg(exception.columnNumber());
252 return QXmlDefaultHandler::fatalError( exception );