Salome HOME
PAL6938
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_XmlHandler.cxx
1 //  SMESH SMESHGUI : reading of xml file with list of available hypotheses and algorithms
2 //  Copyright (C) 2003  CEA
3 //
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.
8 //
9
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.
14 //
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
18 //
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
20 //
21 //
22 //
23 //  File   : SMESHGUI_XmlHandler.cxx
24 //  Author : Julia DOROVSKIKH
25 //  Module : SMESH
26 //  $Header$
27
28 #define  INCLUDE_MENUITEM_DEF 
29
30 // QT Include
31 #include <qfileinfo.h>
32
33 #include "QAD_ResourceMgr.h"
34 #include "QAD_Desktop.h"
35
36 #include "SMESHGUI_XmlHandler.h"
37 #include "SMESHGUI_Hypotheses.h"
38
39 #include "utilities.h"
40
41 using namespace std;
42
43 /*!
44   Constructor
45 */
46 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
47 {
48 }
49
50 /*!
51   Destructor
52 */
53 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
54 {
55 }
56
57 /*!
58   Starts parsing of document. Does some initialization
59
60   Reimplemented from QXmlDefaultHandler.
61 */
62 bool SMESHGUI_XmlHandler::startDocument()
63 {
64   myErrorProt = "";
65   return TRUE;
66 }
67
68 /*!
69   Does different actions depending on the name of the tag and the
70   state you are in document.
71
72   Reimplemented from QXmlDefaultHandler.
73 */
74 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&, 
75                                         const QString& qName, 
76                                         const QXmlAttributes& atts)
77 {
78   if (qName == "meshers")
79   {
80     myHypothesesMap.clear();
81     myAlgorithmsMap.clear();
82   }
83   else if (qName == "meshers-group") // group of hypotheses and algorithms
84   {
85 //    if (atts.value("server-lib") != "")
86     {
87       myPluginName = atts.value("name");
88       myServerLib  = atts.value("server-lib");
89       myClientLib  = atts.value("gui-lib");
90
91       QString aResName = atts.value("resources");
92       if (aResName != "")
93       {
94         MESSAGE("Loading Resources " << aResName);
95         QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
96         QString msg;
97         if (!resMgr->loadResources(aResName, msg))
98           MESSAGE(msg);
99       }
100     }
101   }
102   else if (qName == "hypotheses") // group of hypotheses
103   {
104   }
105   else if (qName == "algorithms") // group of algorithms
106   {
107   }
108   else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
109   {
110     if (atts.value("type") != "")
111     {
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,
117                             aLabel, anIcon);
118
119       if (qName == "algorithm")
120       {
121         myAlgorithmsMap[(char*)aHypAlType.latin1()] = aHypLibNames;
122       }
123       else
124       {
125         myHypothesesMap[(char*)aHypAlType.latin1()] = aHypLibNames;
126       }
127     }
128   }
129   else
130   {
131     // error
132     return FALSE;
133   }
134   return TRUE;
135 }
136
137
138 /*!
139   Reimplemented from QXmlDefaultHandler.
140 */
141 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
142 {
143   return TRUE;
144 }
145
146
147 /*!
148   Reimplemented from QXmlDefaultHandler.
149 */
150 bool SMESHGUI_XmlHandler::characters (const QString& ch)
151 {
152   // we are not interested in whitespaces
153   QString ch_simplified = ch.simplifyWhiteSpace();
154   if ( ch_simplified.isEmpty() )
155     return TRUE;
156   return TRUE;
157 }
158
159
160 /*!
161   Returns the default error string.
162
163   Reimplemented from QXmlDefaultHandler.
164 */
165 QString SMESHGUI_XmlHandler::errorString()
166 {
167   return "the document is not in the quote file format";
168 }
169
170 /*!
171   Returns the error protocol if parsing failed
172
173   Reimplemented from QXmlDefaultHandler.
174 */
175 QString SMESHGUI_XmlHandler::errorProtocol()
176 {
177   return myErrorProt;
178 }
179
180 /*!
181   Returns exception
182
183   Reimplemented from QXmlDefaultHandler.
184 */
185 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
186 {
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());
191   
192   return QXmlDefaultHandler::fatalError( exception );
193 }