Salome HOME
Fix a bug that NbShapes() and ShapeInfo() return 2 solids for a box
[modules/geom.git] / src / GEOMGUI / GEOMGUI_XmlHandler.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 // GEOM GEOMGUI : reading of xml file with list of available plugin actions
23 // File   : GEOMGUI_XmlHandler.cxx
24 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
25
26 #include "GEOMGUI_XmlHandler.h"
27
28 #include "GEOMGUI.h"
29
30 // SALOME KERNEL includes
31 #include <utilities.h>
32
33 /*!
34  * Constructor
35  */
36 GEOMGUI_XmlHandler::GEOMGUI_XmlHandler()
37 {
38 }
39
40 /*!
41  * Destructor
42  */
43 GEOMGUI_XmlHandler::~GEOMGUI_XmlHandler()
44 {
45 }
46
47 /*!
48  * Starts parsing of document. Does some initialization
49  *
50  * Reimplemented from QXmlDefaultHandler.
51  */
52 bool GEOMGUI_XmlHandler::startDocument()
53 {
54   myErrorProt = "";
55   return true;
56 }
57
58 /*!
59  * Does different actions depending on the name of the tag and the
60  * state you are in document.
61  *
62  * Reimplemented from QXmlDefaultHandler.
63  */
64 bool GEOMGUI_XmlHandler::startElement (const QString&, const QString&,
65                                        const QString& qName,
66                                        const QXmlAttributes& atts)
67 {
68   if (qName == "geom-plugins") { // set of plugins
69     //myHypothesesMap.clear();
70     //myAlgorithmsMap.clear();
71   }
72   else if (qName == "geom-plugin") { // group of actions
73     myPluginData.myName      = atts.value("name");
74     myPluginData.myServerLib = atts.value("server-lib");
75     myPluginData.myClientLib = atts.value("gui-lib");
76
77     //QString aResName = atts.value("resources");
78     //if (aResName != "") {
79     //  SUIT_ResourceMgr* resMgr = GEOMGUI::resourceMgr();
80     //  QString lang = resMgr->stringValue( resMgr->langSection(), "language", "en" );
81     //  resMgr->loadTranslator( "resources", QString( "%1_msg_%2.qm" ).arg( aResName, lang ) );
82     //  resMgr->loadTranslator( "resources", QString( "%1_images.qm" ).arg( aResName, lang ) );
83     //}
84   }
85   else if (qName == "actions") { // group of actions
86   }
87   else if (qName == "action") { // an action
88     GEOMGUI_ActionData aData;
89     aData.myLabel     = atts.value("label");
90     aData.myIcon      = atts.value("icon");
91     aData.myMenu      = atts.value("menu");
92     aData.myTooltip   = atts.value("tooltip");
93     aData.myStatusBar = atts.value("status-bar");
94
95     myPluginData.myListOfActions.append(aData);
96   }
97   else {
98     // error
99     return false;
100   }
101   return true;
102 }
103
104 /*!
105  * Reimplemented from QXmlDefaultHandler.
106  */
107 bool GEOMGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
108 {
109   return true;
110 }
111
112 /*!
113  * Reimplemented from QXmlDefaultHandler.
114  */
115 bool GEOMGUI_XmlHandler::characters (const QString& ch)
116 {
117   // we are not interested in whitespaces
118   //QString ch_simplified = ch.simplified();
119   //if ( ch_simplified.isEmpty() )
120   //  return true;
121   return true;
122 }
123
124 /*!
125  * Returns the default error string.
126  *
127  * Reimplemented from QXmlDefaultHandler.
128  */
129 QString GEOMGUI_XmlHandler::errorString()
130 {
131   return "the document is not in the quote file format";
132 }
133
134 /*!
135  * Returns the error protocol if parsing failed
136  *
137  * Reimplemented from QXmlDefaultHandler.
138  */
139 QString GEOMGUI_XmlHandler::errorProtocol()
140 {
141   return myErrorProt;
142 }
143
144 /*!
145  * Returns exception
146  *
147  * Reimplemented from QXmlDefaultHandler.
148  */
149 bool GEOMGUI_XmlHandler::fatalError (const QXmlParseException& exception)
150 {
151   myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
152     .arg(exception.message())
153     .arg(exception.lineNumber())
154     .arg(exception.columnNumber());
155
156   return QXmlDefaultHandler::fatalError( exception );
157 }