+
+//================================================================================
+/*!
+ * \brief Reads _pyHypothesis'es from resource files of mesher Plugins
+ */
+//================================================================================
+
+_pyHypothesisReader::_pyHypothesisReader()
+{
+ // Read xml files
+ vector< string > xmlPaths = SMESH_Gen::GetPluginXMLPaths();
+ LDOMParser xmlParser;
+ for ( size_t i = 0; i < xmlPaths.size(); ++i )
+ {
+ bool error = xmlParser.parse( xmlPaths[i].c_str() );
+ if ( error )
+ {
+ _AString data;
+ INFOS( xmlParser.GetError(data) );
+ continue;
+ }
+ // <algorithm type="Regular_1D"
+ // label-id="Wire discretisation"
+ // ...>
+ // <python-wrap>
+ // <algo>Regular_1D=Segment()</algo>
+ // <hypo>LocalLength=LocalLength(SetLength(1),,SetPrecision(1))</hypo>
+ //
+ LDOM_Document xmlDoc = xmlParser.getDocument();
+ LDOM_NodeList algoNodeList = xmlDoc.getElementsByTagName( "algorithm" );
+ for ( int i = 0; i < algoNodeList.getLength(); ++i )
+ {
+ LDOM_Node algoNode = algoNodeList.item( i );
+ LDOM_Element& algoElem = (LDOM_Element&) algoNode;
+ LDOM_NodeList pyAlgoNodeList = algoElem.getElementsByTagName( "algo" );
+ if ( pyAlgoNodeList.getLength() < 1 ) continue;
+
+ _AString text, algoType, method, arg;
+ for ( int iA = 0; iA < pyAlgoNodeList.getLength(); ++iA )
+ {
+ LDOM_Node pyAlgoNode = pyAlgoNodeList.item( iA );
+ LDOM_Node textNode = pyAlgoNode.getFirstChild();
+ text = textNode.getNodeValue();
+ Handle(_pyCommand) algoCmd = new _pyCommand( text );
+ algoType = algoCmd->GetResultValue();
+ method = algoCmd->GetMethod();
+ arg = algoCmd->GetArg(1);
+ if ( !algoType.IsEmpty() && !method.IsEmpty() )
+ {
+ Handle(_pyAlgorithm) algo = new _pyAlgorithm( algoCmd );
+ algo->SetConvMethodAndType( method, algoType );
+ if ( !arg.IsEmpty() )
+ algo->setCreationArg( 1, arg );
+
+ myType2Hyp[ algoType ] = algo;
+ break;
+ }
+ }
+ if ( algoType.IsEmpty() ) continue;
+
+ LDOM_NodeList pyHypoNodeList = algoElem.getElementsByTagName( "hypo" );
+ _AString hypType;
+ Handle( _pyHypothesis ) hyp;
+ for ( int iH = 0; iH < pyHypoNodeList.getLength(); ++iH )
+ {
+ LDOM_Node pyHypoNode = pyHypoNodeList.item( iH );
+ LDOM_Node textNode = pyHypoNode.getFirstChild();
+ text = textNode.getNodeValue();
+ Handle(_pyCommand) hypoCmd = new _pyCommand( text );
+ hypType = hypoCmd->GetResultValue();
+ method = hypoCmd->GetMethod();
+ if ( !hypType.IsEmpty() && !method.IsEmpty() )
+ {
+ map<_AString, Handle(_pyHypothesis)>::iterator type2hyp = myType2Hyp.find( hypType );
+ if ( type2hyp == myType2Hyp.end() )
+ hyp = new _pyHypothesis( hypoCmd );
+ else
+ hyp = type2hyp->second;
+ hyp->SetConvMethodAndType( method, algoType );
+ for ( int iArg = 1; iArg <= hypoCmd->GetNbArgs(); ++iArg )
+ {
+ _pyCommand argCmd( hypoCmd->GetArg( iArg ));
+ _AString argMethod = argCmd.GetMethod();
+ _AString argNbText = argCmd.GetArg( 1 );
+ if ( argMethod.IsEmpty() && !argCmd.IsEmpty() )
+ hyp->setCreationArg( 1, argCmd.GetString() ); // e.g. Parameters(smesh.SIMPLE)
+ else
+ hyp->AddArgMethod( argMethod,
+ argNbText.IsIntegerValue() ? argNbText.IntegerValue() : 1 );
+ }
+ myType2Hyp[ hypType ] = hyp;
+ }
+ }
+ }
+ // <hypothesis type="BLSURF_Parameters"
+ // ...
+ // dim="2">
+ // <python-wrap>
+ // <accumulative-methods>
+ // SetEnforcedVertex,
+ // SetEnforcedVertexNamed
+ // </accumulative-methods>
+ // </python-wrap>
+ // </hypothesis>
+ //
+ LDOM_NodeList hypNodeList = xmlDoc.getElementsByTagName( "hypothesis" );
+ for ( int i = 0; i < hypNodeList.getLength(); ++i )
+ {
+ LDOM_Node hypNode = hypNodeList.item( i );
+ LDOM_Element& hypElem = (LDOM_Element&) hypNode;
+ _AString hypType = hypElem.getAttribute("type");
+ LDOM_NodeList methNodeList = hypElem.getElementsByTagName( "accumulative-methods" );
+ if ( methNodeList.getLength() != 1 || hypType.IsEmpty() ) continue;
+
+ map<_AString, Handle(_pyHypothesis)>::const_iterator type2hyp = myType2Hyp.find( hypType );
+ if ( type2hyp == myType2Hyp.end() ) continue;
+
+ LDOM_Node methNode = methNodeList.item( 0 );
+ LDOM_Node textNode = methNode.getFirstChild();
+ _AString text = textNode.getNodeValue();
+ _AString method;
+ int pos = 1;
+ do {
+ method = _pyCommand::GetWord( text, pos, /*forward= */true );
+ pos += method.Length();
+ type2hyp->second->AddAccumulativeMethod( method );
+ }
+ while ( !method.IsEmpty() );
+ }
+
+ } // loop on xmlPaths
+}
+
+//================================================================================
+/*!
+ * \brief Returns a new hypothesis initialized according to the read information
+ */
+//================================================================================
+
+Handle(_pyHypothesis)
+_pyHypothesisReader::GetHypothesis(const _AString& hypType,
+ const Handle(_pyCommand)& creationCmd) const
+{
+ Handle(_pyHypothesis) resHyp, sampleHyp;
+
+ map<_AString, Handle(_pyHypothesis)>::const_iterator type2hyp = myType2Hyp.find( hypType );
+ if ( type2hyp != myType2Hyp.end() )
+ sampleHyp = type2hyp->second;
+
+ if ( sampleHyp.IsNull() )
+ {
+ resHyp = new _pyHypothesis(creationCmd);
+ }
+ else
+ {
+ if ( sampleHyp->IsAlgo() )
+ resHyp = new _pyAlgorithm( creationCmd );
+ else
+ resHyp = new _pyHypothesis(creationCmd);
+ resHyp->Assign( sampleHyp, _pyID() );
+ }
+ return resHyp;
+}