Salome HOME
[SALOME platform 0013410]: SubMesh not taken into account with Netgen 1D-2D et 1D...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_XmlHandler.cxx
1 // SMESH SMESHGUI : reading of xml file with list of available hypotheses and algorithms
2 //
3 // Copyright (C) 2003  CEA
4 //
5 // This library is free software; you can redistribute it and/or 
6 // modify it under the terms of the GNU Lesser General Public 
7 // License as published by the Free Software Foundation; either 
8 // version 2.1 of the License. 
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.com
20 //
21 // File   : SMESHGUI_XmlHandler.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
23 //
24
25 // SMESH includes
26 #include "SMESHGUI_XmlHandler.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_Hypotheses.h"
30
31 // SALOME GUI includes
32 #include "SUIT_ResourceMgr.h"
33
34 // SALOME KERNEL includes
35 #include <utilities.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 /* It's Need to tranlate lib name for WIN32 or X platform
85  * (only client lib, because server lib translates in SMESH_Gen_i::createHypothesis
86  *  for normal work of *.py files )
87  */
88       if( !myClientLib.isEmpty() )
89       {
90 #ifdef WNT
91       //myServerLib += ".dll";
92         myClientLib += ".dll";
93 #else
94       //myServerLib = "lib" + myServerLib + ".so";
95         myClientLib = "lib" + myClientLib + ".so";
96 #endif
97       }
98
99
100       QString aResName = atts.value("resources");
101       if (aResName != "")
102       {
103         MESSAGE("Loading Resources " << aResName.toLatin1().data());
104         SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
105         QString lang = resMgr->stringValue( resMgr->langSection(), "language", "en" );
106         resMgr->loadTranslator( "resources", QString( "%1_msg_%2.qm" ).arg( aResName, lang ) );
107         resMgr->loadTranslator( "resources", QString( "%1_images.qm" ).arg( aResName, lang ) );
108       }
109     }
110   }
111   else if (qName == "hypotheses") // group of hypotheses
112   {
113   }
114   else if (qName == "algorithms") // group of algorithms
115   {
116   }
117   else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
118   {
119     if (atts.value("type") != "")
120     {
121       QString aHypAlType = atts.value("type");
122       QString aLabel = atts.value("label-id");
123       QString anIcon = atts.value("icon-id");
124       bool isAux = atts.value("auxiliary") == "true";
125       bool isNeedGeom = true, isSupportSubmeshes = false;
126       QString aNeedGeom = atts.value("need-geom");
127       if ( !aNeedGeom.isEmpty() )
128         isNeedGeom = (aNeedGeom == "true");
129       QString suppSub = atts.value("support-submeshes");
130       if ( !suppSub.isEmpty() )
131         isSupportSubmeshes = (suppSub == "true");
132
133       QString aDimStr = atts.value("dim");
134       aDimStr = aDimStr.remove( ' ' );
135       QStringList aDimList = aDimStr.split( ',', QString::SkipEmptyParts );
136       QStringList::iterator anIter;
137       bool isOk;
138       QList<int> aDim;
139       for ( anIter = aDimList.begin(); anIter != aDimList.end(); ++anIter )
140       {
141         int aVal = (*anIter).toInt( &isOk );
142         if ( isOk )
143           aDim.append( aVal );
144       }
145
146       // for algo
147       enum { HYPOS = 0, OPT_HYPOS, INPUT, OUTPUT, NB_ATTRIBUTES };
148       const char* name [NB_ATTRIBUTES] = { "hypos", "opt-hypos", "input", "output" };
149       QStringList attr [NB_ATTRIBUTES];
150       for ( int i = 0; i < NB_ATTRIBUTES; ++i ) {
151         QString aStr = atts.value( name[i] );
152         if ( !aStr.isEmpty() ) {
153           aStr.remove( ' ' );
154           attr[ i ] = aStr.split( ',', QString::SkipEmptyParts );
155         }
156       }
157       
158       HypothesisData* aHypData =
159         new HypothesisData (aHypAlType, myPluginName, myServerLib, myClientLib,
160                             aLabel, anIcon, aDim, isAux,
161                             attr[ HYPOS ], attr[ OPT_HYPOS ], attr[ INPUT ], attr[ OUTPUT ],
162                             isNeedGeom, isSupportSubmeshes );
163
164       if (qName == "algorithm")
165       {
166         myAlgorithmsMap[aHypAlType] = aHypData;
167       }
168       else
169       {
170         myHypothesesMap[aHypAlType] = aHypData;
171       }
172     }
173   }
174   else if (qName == "hypotheses-set-group") // group of sets of hypotheses
175   {
176   }
177   else if (qName == "hypotheses-set") // a set of hypotheses
178   {
179     if (atts.value("name") != "")
180     {
181       HypothesesSet* aHypoSet = new HypothesesSet ( atts.value("name") );
182       myListOfHypothesesSets.append( aHypoSet );
183
184       for ( int isHypo = 0; isHypo < 2; ++isHypo )
185       {
186         QString aHypos = isHypo ? atts.value("hypos") : atts.value("algos");
187         aHypos = aHypos.remove( ' ' );
188         QStringList* aHypoList = isHypo ? & aHypoSet->HypoList : & aHypoSet->AlgoList;
189         *aHypoList = aHypos.split( ',', QString::SkipEmptyParts );
190       }
191     }
192   }
193   else
194   {
195     // error
196     return false;
197   }
198   return true;
199 }
200
201
202 /*!
203   Reimplemented from QXmlDefaultHandler.
204 */
205 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
206 {
207   return true;
208 }
209
210
211 /*!
212   Reimplemented from QXmlDefaultHandler.
213 */
214 bool SMESHGUI_XmlHandler::characters (const QString& ch)
215 {
216   // we are not interested in whitespaces
217   QString ch_simplified = ch.simplified();
218   if ( ch_simplified.isEmpty() )
219     return true;
220   return true;
221 }
222
223
224 /*!
225   Returns the default error string.
226
227   Reimplemented from QXmlDefaultHandler.
228 */
229 QString SMESHGUI_XmlHandler::errorString()
230 {
231   return "the document is not in the quote file format";
232 }
233
234 /*!
235   Returns the error protocol if parsing failed
236
237   Reimplemented from QXmlDefaultHandler.
238 */
239 QString SMESHGUI_XmlHandler::errorProtocol()
240 {
241   return myErrorProt;
242 }
243
244 /*!
245   Returns exception
246
247   Reimplemented from QXmlDefaultHandler.
248 */
249 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
250 {
251   myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
252     .arg(exception.message())
253     .arg(exception.lineNumber())
254     .arg(exception.columnNumber());
255   
256   return QXmlDefaultHandler::fatalError( exception );
257 }