Back to index

salome-smesh  6.5.0
SMESHGUI_XmlHandler.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : reading of xml file with list of available hypotheses and algorithms
00024 // File   : SMESHGUI_XmlHandler.cxx
00025 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_XmlHandler.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Hypotheses.h"
00032 
00033 // SALOME GUI includes
00034 #include "SUIT_ResourceMgr.h"
00035 
00036 // SALOME KERNEL includes
00037 #include <utilities.h>
00038 
00042 SMESHGUI_XmlHandler::SMESHGUI_XmlHandler()
00043 {
00044 }
00045 
00049 SMESHGUI_XmlHandler::~SMESHGUI_XmlHandler()
00050 {
00051 }
00052 
00058 bool SMESHGUI_XmlHandler::startDocument()
00059 {
00060   myErrorProt = "";
00061   return true;
00062 }
00063 
00070 bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&, 
00071                                         const QString& qName, 
00072                                         const QXmlAttributes& atts)
00073 {
00074   if (qName == "meshers")
00075   {
00076     myHypothesesMap.clear();
00077     myAlgorithmsMap.clear();
00078   }
00079   else if (qName == "meshers-group") // group of hypotheses and algorithms
00080   {
00081 //    if (atts.value("server-lib") != "")
00082     {
00083       myPluginName = atts.value("name");
00084       myServerLib  = atts.value("server-lib");
00085       myClientLib  = atts.value("gui-lib");
00086 /* It's Need to tranlate lib name for WIN32 or X platform
00087  * (only client lib, because server lib translates in SMESH_Gen_i::createHypothesis
00088  *  for normal work of *.py files )
00089  */
00090       if( !myClientLib.isEmpty() )
00091       {
00092 #ifdef WNT
00093       //myServerLib += ".dll";
00094         myClientLib += ".dll";
00095 #else
00096       //myServerLib = "lib" + myServerLib + ".so";
00097         myClientLib = "lib" + myClientLib + ".so";
00098 #endif
00099       }
00100 
00101 
00102       QString aResName = atts.value("resources");
00103       if (aResName != "")
00104       {
00105         MESSAGE("Loading Resources " << aResName.toLatin1().data());
00106         SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
00107         QString lang = resMgr->stringValue( resMgr->langSection(), "language", "en" );
00108         resMgr->loadTranslator( "resources", QString( "%1_msg_%2.qm" ).arg( aResName, lang ) );
00109         resMgr->loadTranslator( "resources", QString( "%1_images.qm" ).arg( aResName, lang ) );
00110       }
00111     }
00112   }
00113   else if (qName == "hypotheses") // group of hypotheses
00114   {
00115   }
00116   else if (qName == "algorithms") // group of algorithms
00117   {
00118   }
00119   else if (qName == "hypothesis" || qName == "algorithm") // hypothesis or algorithm
00120   {
00121     if (atts.value("type") != "")
00122     {
00123       QString aHypAlType = atts.value("type");
00124       QString aLabel = atts.value("label-id");
00125       QString anIcon = atts.value("icon-id");
00126       bool isAux = atts.value("auxiliary") == "true";
00127       bool isNeedGeom = true, isSupportSubmeshes = false;
00128       QString aNeedGeom = atts.value("need-geom");
00129       if ( !aNeedGeom.isEmpty() )
00130         isNeedGeom = (aNeedGeom == "true");
00131       QString suppSub = atts.value("support-submeshes");
00132       if ( !suppSub.isEmpty() )
00133         isSupportSubmeshes = (suppSub == "true");
00134 
00135       QString aDimStr = atts.value("dim");
00136       aDimStr = aDimStr.remove( ' ' );
00137       QStringList aDimList = aDimStr.split( ',', QString::SkipEmptyParts );
00138       QStringList::iterator anIter;
00139       bool isOk;
00140       QList<int> aDim;
00141       for ( anIter = aDimList.begin(); anIter != aDimList.end(); ++anIter )
00142       {
00143         int aVal = (*anIter).toInt( &isOk );
00144         if ( isOk )
00145           aDim.append( aVal );
00146       }
00147 
00148       // for algo
00149       enum { HYPOS = 0, OPT_HYPOS, INPUT, OUTPUT, NB_ATTRIBUTES };
00150       const char* name [NB_ATTRIBUTES] = { "hypos", "opt-hypos", "input", "output" };
00151       QStringList attr [NB_ATTRIBUTES];
00152       for ( int i = 0; i < NB_ATTRIBUTES; ++i ) {
00153         QString aStr = atts.value( name[i] );
00154         if ( !aStr.isEmpty() ) {
00155           aStr.remove( ' ' );
00156           attr[ i ] = aStr.split( ',', QString::SkipEmptyParts );
00157         }
00158       }
00159       
00160       HypothesisData* aHypData =
00161         new HypothesisData (aHypAlType, myPluginName, myServerLib, myClientLib,
00162                             aLabel, anIcon, aDim, isAux,
00163                             attr[ HYPOS ], attr[ OPT_HYPOS ], attr[ INPUT ], attr[ OUTPUT ],
00164                             isNeedGeom, isSupportSubmeshes );
00165 
00166       if (qName == "algorithm")
00167       {
00168         myAlgorithmsMap.insert(aHypAlType,aHypData);
00169       }
00170       else
00171       {
00172         myHypothesesMap.insert(aHypAlType,aHypData);
00173       }
00174     }
00175   }
00176   else if (qName == "hypotheses-set-group") // group of sets of hypotheses
00177   {
00178   }
00179   else if (qName == "hypotheses-set") // a set of hypotheses
00180   {
00181     if (atts.value("name") != "")
00182     {
00183       HypothesesSet* aHypoSet = new HypothesesSet ( atts.value("name") );
00184       myListOfHypothesesSets.append( aHypoSet );
00185 
00186       for ( int isHypo = 0; isHypo < 2; ++isHypo )
00187       {
00188         QString aHypos = isHypo ? atts.value("hypos") : atts.value("algos");
00189         aHypos = aHypos.remove( ' ' );
00190         aHypoSet->set( !isHypo, aHypos.split( ',', QString::SkipEmptyParts ) );
00191       }
00192     }
00193   }
00194   else if ( qName == "python-wrap" ||
00195             qName == "algo"        ||
00196             qName == "hypo"         )
00197   {
00198     // elements used in SMESH_2smeshpy
00199     return true;
00200   }
00201   else
00202   {
00203     // error
00204     return false;
00205   }
00206   return true;
00207 }
00208 
00209 
00213 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
00214 {
00215   return true;
00216 }
00217 
00218 
00222 bool SMESHGUI_XmlHandler::characters (const QString& ch)
00223 {
00224   // we are not interested in whitespaces
00225   QString ch_simplified = ch.simplified();
00226   if ( ch_simplified.isEmpty() )
00227     return true;
00228   return true;
00229 }
00230 
00231 
00237 QString SMESHGUI_XmlHandler::errorString()
00238 {
00239   return "the document is not in the quote file format";
00240 }
00241 
00247 QString SMESHGUI_XmlHandler::errorProtocol()
00248 {
00249   return myErrorProt;
00250 }
00251 
00257 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
00258 {
00259   myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
00260     .arg(exception.message())
00261     .arg(exception.lineNumber())
00262     .arg(exception.columnNumber());
00263   
00264   return QXmlDefaultHandler::fatalError( exception );
00265 }