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.org
23 // File : SMESHGUI_XmlHandler.cxx
24 // Author : Julia DOROVSKIKH
28 #define INCLUDE_MENUITEM_DEF
31 #include <qfileinfo.h>
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Desktop.h"
37 #include "SMESHGUI_XmlHandler.h"
38 #include "SMESHGUI_Hypotheses.h"
40 #include "utilities.h"
47 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
54 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
59 Starts parsing of document. Does some initialization
61 Reimplemented from QXmlDefaultHandler.
63 bool SMESHGUI_XmlHandler::startDocument()
70 Does different actions depending on the name of the tag and the
71 state you are in document.
73 Reimplemented from QXmlDefaultHandler.
75 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&,
77 const QXmlAttributes& atts)
79 if (qName == "meshers")
81 myHypothesesMap.clear();
82 myAlgorithmsMap.clear();
84 else if (qName == "meshers-group") // group of hypotheses and algorithms
86 // if (atts.value("server-lib") != "")
88 myPluginName = atts.value("name");
89 myServerLib = atts.value("server-lib");
90 myClientLib = atts.value("gui-lib");
92 QString aResName = atts.value("resources");
95 MESSAGE("Loading Resources " << aResName);
96 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
97 resMgr->loadTranslator("resources",aResName+"_msg_en.qm");
98 resMgr->loadTranslator("resources",aResName+"_images.qm");
102 else if (qName == "hypotheses") // group of hypotheses
105 else if (qName == "algorithms") // group of algorithms
108 else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
110 if (atts.value("type") != "")
112 QString aHypAlType = atts.value("type");
113 QString aLabel = atts.value("label-id");
114 QString anIcon = atts.value("icon-id");
115 HypothesisData* aHypLibNames =
116 new HypothesisData (myPluginName, myServerLib, myClientLib,
119 if (qName == "algorithm")
121 myAlgorithmsMap[(char*)aHypAlType.latin1()] = aHypLibNames;
125 myHypothesesMap[(char*)aHypAlType.latin1()] = aHypLibNames;
139 Reimplemented from QXmlDefaultHandler.
141 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
148 Reimplemented from QXmlDefaultHandler.
150 bool SMESHGUI_XmlHandler::characters (const QString& ch)
152 // we are not interested in whitespaces
153 QString ch_simplified = ch.simplifyWhiteSpace();
154 if ( ch_simplified.isEmpty() )
161 Returns the default error string.
163 Reimplemented from QXmlDefaultHandler.
165 QString SMESHGUI_XmlHandler::errorString()
167 return "the document is not in the quote file format";
171 Returns the error protocol if parsing failed
173 Reimplemented from QXmlDefaultHandler.
175 QString SMESHGUI_XmlHandler::errorProtocol()
183 Reimplemented from QXmlDefaultHandler.
185 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
187 myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
188 .arg(exception.message())
189 .arg(exception.lineNumber())
190 .arg(exception.columnNumber());
192 return QXmlDefaultHandler::fatalError( exception );