1 // Copyright (C) 2007-2013 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
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>
42 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
49 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
54 Starts parsing of document. Does some initialization
56 Reimplemented from QXmlDefaultHandler.
58 bool SMESHGUI_XmlHandler::startDocument()
65 Does different actions depending on the name of the tag and the
66 state you are in document.
68 Reimplemented from QXmlDefaultHandler.
70 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&,
72 const QXmlAttributes& atts)
74 if (qName == "meshers")
76 myHypothesesMap.clear();
77 myAlgorithmsMap.clear();
79 else if (qName == "meshers-group") // group of hypotheses and algorithms
81 // if (atts.value("server-lib") != "")
83 myPluginName = atts.value("name");
84 myServerLib = atts.value("server-lib");
85 myClientLib = atts.value("gui-lib");
86 /* It's Need to tranlate lib name for WIN32 or X platform
87 * (only client lib, because server lib translates in SMESH_Gen_i::createHypothesis
88 * for normal work of *.py files )
90 if( !myClientLib.isEmpty() )
93 //myServerLib += ".dll";
94 myClientLib += ".dll";
96 //myServerLib = "lib" + myServerLib + ".so";
97 myClientLib = "lib" + myClientLib + ".so";
102 QString aResName = atts.value("resources");
105 MESSAGE("Loading Resources " << aResName.toLatin1().data());
106 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
107 QString lang = resMgr->stringValue( resMgr->langSection(), "language", "en" );
108 resMgr->loadTranslator( "resources", QString( "%1_msg_%2.qm" ).arg( aResName, lang ) );
109 resMgr->loadTranslator( "resources", QString( "%1_images.qm" ).arg( aResName, lang ) );
113 else if (qName == "hypotheses") // group of hypotheses
116 else if (qName == "algorithms") // group of algorithms
119 else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
121 if (atts.value("type") != "")
123 QString aHypAlType = atts.value("type");
124 QString aLabel = atts.value("label-id");
125 QString anIcon = atts.value("icon-id");
126 bool isAux = atts.value("auxiliary") == "true";
127 bool isNeedGeom = true, isSupportSubmeshes = false;
128 QString aNeedGeom = atts.value("need-geom");
129 if ( !aNeedGeom.isEmpty() )
130 isNeedGeom = (aNeedGeom == "true");
131 QString suppSub = atts.value("support-submeshes");
132 if ( !suppSub.isEmpty() )
133 isSupportSubmeshes = (suppSub == "true");
135 QString aDimStr = atts.value("dim");
136 aDimStr = aDimStr.remove( ' ' );
137 QStringList aDimList = aDimStr.split( ',', QString::SkipEmptyParts );
138 QStringList::iterator anIter;
141 for ( anIter = aDimList.begin(); anIter != aDimList.end(); ++anIter )
143 int aVal = (*anIter).toInt( &isOk );
149 enum { HYPOS = 0, OPT_HYPOS, INPUT, OUTPUT, NB_ATTRIBUTES };
150 const char* name [NB_ATTRIBUTES] = { "hypos", "opt-hypos", "input", "output" };
151 QStringList attr [NB_ATTRIBUTES];
152 for ( int i = 0; i < NB_ATTRIBUTES; ++i ) {
153 QString aStr = atts.value( name[i] );
154 if ( !aStr.isEmpty() ) {
156 attr[ i ] = aStr.split( ',', QString::SkipEmptyParts );
160 HypothesisData* aHypData =
161 new HypothesisData (aHypAlType, myPluginName, myServerLib, myClientLib,
162 aLabel, anIcon, aDim, isAux,
163 attr[ HYPOS ], attr[ OPT_HYPOS ], attr[ INPUT ], attr[ OUTPUT ],
164 isNeedGeom, isSupportSubmeshes );
166 if (qName == "algorithm")
168 myAlgorithmsMap.insert(aHypAlType,aHypData);
172 myHypothesesMap.insert(aHypAlType,aHypData);
176 else if (qName == "hypotheses-set-group") // group of sets of hypotheses
179 else if (qName == "hypotheses-set") // a set of hypotheses
181 if (atts.value("name") != "")
183 HypothesesSet* aHypoSet = new HypothesesSet ( atts.value("name") );
184 myListOfHypothesesSets.append( aHypoSet );
186 for ( int isHypo = 0; isHypo < 2; ++isHypo )
188 QString aHypos = isHypo ? atts.value("hypos") : atts.value("algos");
189 aHypos = aHypos.remove( ' ' );
190 aHypoSet->set( !isHypo, aHypos.split( ',', QString::SkipEmptyParts ) );
194 else if ( qName == "python-wrap" ||
197 qName == "accumulative-methods")
199 // elements used in SMESH_2smeshpy
212 Reimplemented from QXmlDefaultHandler.
214 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
221 Reimplemented from QXmlDefaultHandler.
223 bool SMESHGUI_XmlHandler::characters (const QString& ch)
225 // we are not interested in whitespaces
226 QString ch_simplified = ch.simplified();
227 if ( ch_simplified.isEmpty() )
234 Returns the default error string.
236 Reimplemented from QXmlDefaultHandler.
238 QString SMESHGUI_XmlHandler::errorString()
240 return "the document is not in the quote file format";
244 Returns the error protocol if parsing failed
246 Reimplemented from QXmlDefaultHandler.
248 QString SMESHGUI_XmlHandler::errorProtocol()
256 Reimplemented from QXmlDefaultHandler.
258 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
260 myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
261 .arg(exception.message())
262 .arg(exception.lineNumber())
263 .arg(exception.columnNumber());
265 return QXmlDefaultHandler::fatalError( exception );