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