Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_XmlHandler.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Hypotheses.h"
00032
00033
00034 #include "SUIT_ResourceMgr.h"
00035
00036
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")
00080 {
00081
00082 {
00083 myPluginName = atts.value("name");
00084 myServerLib = atts.value("server-lib");
00085 myClientLib = atts.value("gui-lib");
00086
00087
00088
00089
00090 if( !myClientLib.isEmpty() )
00091 {
00092 #ifdef WNT
00093
00094 myClientLib += ".dll";
00095 #else
00096
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")
00114 {
00115 }
00116 else if (qName == "algorithms")
00117 {
00118 }
00119 else if (qName == "hypothesis" || qName == "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
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[aHypAlType] = aHypData;
00169 }
00170 else
00171 {
00172 myHypothesesMap[aHypAlType] = aHypData;
00173 }
00174 }
00175 }
00176 else if (qName == "hypotheses-set-group")
00177 {
00178 }
00179 else if (qName == "hypotheses-set")
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
00195 {
00196
00197 return false;
00198 }
00199 return true;
00200 }
00201
00202
00206 bool SMESHGUI_XmlHandler::endElement (const QString&, const QString&, const QString&)
00207 {
00208 return true;
00209 }
00210
00211
00215 bool SMESHGUI_XmlHandler::characters (const QString& ch)
00216 {
00217
00218 QString ch_simplified = ch.simplified();
00219 if ( ch_simplified.isEmpty() )
00220 return true;
00221 return true;
00222 }
00223
00224
00230 QString SMESHGUI_XmlHandler::errorString()
00231 {
00232 return "the document is not in the quote file format";
00233 }
00234
00240 QString SMESHGUI_XmlHandler::errorProtocol()
00241 {
00242 return myErrorProt;
00243 }
00244
00250 bool SMESHGUI_XmlHandler::fatalError (const QXmlParseException& exception)
00251 {
00252 myErrorProt += QString("fatal parsing error: %1 in line %2, column %3\n")
00253 .arg(exception.message())
00254 .arg(exception.lineNumber())
00255 .arg(exception.columnNumber());
00256
00257 return QXmlDefaultHandler::fatalError( exception );
00258 }