Salome HOME
DCQ:prepare 2.0.0
[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 using namespace std;
29 #define  INCLUDE_MENUITEM_DEF 
30
31 #include "SMESHGUI_XmlHandler.h"
32
33 // QT Include
34 //#include <qaccel.h>
35 #include <qfileinfo.h>
36
37 /*!
38   Constructor
39 */
40 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
41 {
42 }
43
44 /*!
45   Destructor
46 */
47 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
48 {
49 }
50
51 /*!
52   Starts parsing of document. Does some initialization
53
54   Reimplemented from QXmlDefaultHandler.
55 */
56 bool SMESHGUI_XmlHandler::startDocument()
57 {
58   myErrorProt = "";
59   return TRUE;
60 }
61
62 /*!
63   Does different actions depending on the name of the tag and the
64   state you are in document.
65
66   Reimplemented from QXmlDefaultHandler.
67 */
68 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&, 
69                                         const QString& qName, 
70                                         const QXmlAttributes& atts)
71 {
72   if (qName == "meshers")
73   {
74     myHypothesesMap.clear();
75     myAlgorithmsMap.clear();
76   }
77   else if (qName == "meshers-group") // group of hypotheses and algorithms
78   {
79 //    if (atts.value("server-lib") != "")
80     {
81       myPluginName = atts.value("name");
82       myServerLib  = atts.value("server-lib");
83       myClientLib  = atts.value("gui-lib");
84
85       QString aResName = atts.value("resources");
86       if (aResName != "")
87       {
88         MESSAGE("Loading Resources " << aResName);
89         QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
90         QString msg;
91         if (!resMgr->loadResources(aResName, msg))
92           MESSAGE(msg);
93       }
94     }
95   }
96   else if (qName == "hypotheses") // group of hypotheses
97   {
98   }
99   else if (qName == "algorithms") // group of algorithms
100   {
101   }
102   else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
103   {
104     if (atts.value("type") != "")
105     {
106       QString aHypAlType = atts.value("type");
107       QString aLabel = atts.value("label-id");
108       QString anIcon = atts.value("icon-id");
109       HypothesisData* aHypLibNames =
110         new HypothesisData (myPluginName, myServerLib, myClientLib,
111                             aLabel, anIcon);
112
113       if (qName == "algorithm")
114       {
115         myAlgorithmsMap[(char*)aHypAlType.latin1()] = aHypLibNames;
116       }
117       else
118       {
119         myHypothesesMap[(char*)aHypAlType.latin1()] = aHypLibNames;
120       }
121     }
122   }
123   else
124   {
125     // error
126     return FALSE;
127   }
128   return TRUE;
129 }
130
131
132 /*!
133   Reimplemented from QXmlDefaultHandler.
134 */
135 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
136 {
137   return TRUE;
138 }
139
140
141 /*!
142   Reimplemented from QXmlDefaultHandler.
143 */
144 bool SMESHGUI_XmlHandler::characters (const QString& ch)
145 {
146   // we are not interested in whitespaces
147   QString ch_simplified = ch.simplifyWhiteSpace();
148   if ( ch_simplified.isEmpty() )
149     return TRUE;
150   return TRUE;
151 }
152
153
154 /*!
155   Returns the default error string.
156
157   Reimplemented from QXmlDefaultHandler.
158 */
159 QString SMESHGUI_XmlHandler::errorString()
160 {
161   return "the document is not in the quote file format";
162 }
163
164 /*!
165   Returns the error protocol if parsing failed
166
167   Reimplemented from QXmlDefaultHandler.
168 */
169 QString SMESHGUI_XmlHandler::errorProtocol()
170 {
171   return myErrorProt;
172 }
173
174 /*!
175   Returns exception
176
177   Reimplemented from QXmlDefaultHandler.
178 */
179 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
180 {
181   myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
182     .arg(exception.message())
183     .arg(exception.lineNumber())
184     .arg(exception.columnNumber());
185   
186   return QXmlDefaultHandler::fatalError( exception );
187 }