TCollection_AsciiString
SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
- Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
+ Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
{
theGen = new _pyGen( theEntry2AccessorMethod, theObjectNames );
//================================================================================
_pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
- Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
+ Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
: _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
myID2AccessorMethod( theEntry2AccessorMethod ),
myObjectNames( theObjectNames )
Handle(_pySubMesh) subMesh = new _pySubMesh( aCommand );
myObjects.insert( make_pair( subMeshID, subMesh ));
}
+
id_mesh->second->Process( aCommand );
return aCommand;
}
if ( !hyp->IsNull() &&
(*hyp)->IsAlgo() &&
theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
- (*hyp)->GetGeom() == theGeom &&
+ (*hyp)->GetGeom() == theGeom &&
(*hyp)->GetMesh() == theMesh )
return *hyp;
return 0;
//================================================================================
void _pyGen::setNeighbourCommand( Handle(_pyCommand)& theCmd,
- Handle(_pyCommand)& theOtherCmd,
- const bool theIsAfter )
+ Handle(_pyCommand)& theOtherCmd,
+ const bool theIsAfter )
{
list< Handle(_pyCommand) >::iterator pos;
pos = find( myCommands.begin(), myCommands.end(), theCmd );
while ( myObjectNames.IsBound( aNewID ) );
myObjectNames.Bind( aNewID, myObjectNames.IsBound( theID )
- ? (myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 ))
- : _pyID( "A" ) + aNewID );
+ ? (myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 ))
+ : _pyID( "A" ) + aNewID );
return aNewID;
}
}
}
// ----------------------------------------------------------------------
- else if ( method == "ExportToMED" ) { // ExportToMED() --> ExportMED()
+ else if ( method == "ExportToMED" || // ExportToMED() --> ExportMED()
+ method == "ExportToMEDX" ) { // ExportToMEDX() --> ExportMED()
theCommand->SetMethod( "ExportMED" );
}
// ----------------------------------------------------------------------
// remove hyp from myHypos
myHypos.remove( hyp );
}
+ // check for SubMesh order commands
+ else if ( theCommand->GetMethod() == "GetMeshOrder" ||
+ theCommand->GetMethod() == "SetMeshOrder" ) {
+ // In fact arguments and result values does not support complex containers
+ // such as list of list
+ // So, here we parse it manually
+ // GetMeshOrder
+ //for(int ind = 0, n = theCommand->GetNbResultValues();ind<n;ind++) {
+ // Handle(_pySubMesh) subMesh = theGen->FindSubMesh( theCommand->GetResultValue(ind) );
+ // SetMeshOrder
+ //for(int ind = 0, n = theCommand->GetNbArgs();ind<n;ind++) {
+ // Handle(_pySubMesh) subMesh = theGen->FindSubMesh( theCommand->GetArg(ind) );
+ const bool isArg = theCommand->GetMethod() == "SetMeshOrder";
+ const TCollection_AsciiString& cmdStr = theCommand->GetString();
+ int begPos = (/*isArg ? cmdStr.Search( "(" ) :*/ cmdStr.Search( "[" )) + 1;
+ int endPos = (isArg ? cmdStr.Search( ")" ) : cmdStr.Search( "=" )) - 1;
+ if ( begPos != -1 && begPos < endPos && endPos <= cmdStr.Length() ) {
+ TCollection_AsciiString aSubStr = cmdStr.SubString( begPos, endPos );
+ Standard_Integer index = 1;
+ TCollection_AsciiString anIDStr = aSubStr.Token("\t ,[]", index++);
+ while ( !anIDStr.IsEmpty() ) {
+ Handle(_pySubMesh) subMesh = theGen->FindSubMesh( anIDStr );
+ if ( !subMesh.IsNull() )
+ subMesh->Process( theCommand );
+ anIDStr = aSubStr.Token("\t ,[]", index++);
+ }
+ }
+ }
// add accessor method if necessary
else
{
"GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
"GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
"IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
- "Clear", "ConvertToStandalone"
+ "Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder"
,"" }; // <- mark of end
sameMethods.Insert( names );
}
if ( algo->IsWrapped() ) {
_pyID localAlgoID = theGen->GenerateNewID( algoID );
TCollection_AsciiString aNewCmdStr = localAlgoID +
- TCollection_AsciiString( " = " ) + theGen->GetID() +
- TCollection_AsciiString( ".CreateHypothesis( \"" ) + algo->GetAlgoType() +
- TCollection_AsciiString( "\" )" );
+ TCollection_AsciiString( " = " ) + theGen->GetID() +
+ TCollection_AsciiString( ".CreateHypothesis( \"" ) + algo->GetAlgoType() +
+ TCollection_AsciiString( "\" )" );
Handle(_pyCommand) newCmd = theGen->AddCommand( aNewCmdStr );
Handle(_pyAlgorithm) newAlgo = Handle(_pyAlgorithm)::DownCast(theGen->FindHyp( localAlgoID ));
if ( !newAlgo.IsNull() ) {
- newAlgo->Assign( algo, this->GetID() );
- newAlgo->SetCreationCmd( newCmd );
- algo = newAlgo;
- // set algorithm creation
- theGen->SetCommandBefore( newCmd, addCmd );
+ newAlgo->Assign( algo, this->GetID() );
+ newAlgo->SetCreationCmd( newCmd );
+ algo = newAlgo;
+ // set algorithm creation
+ theGen->SetCommandBefore( newCmd, addCmd );
}
else
- newCmd->Clear();
+ newCmd->Clear();
}
_pyID geom = addCmd->GetArg( 1 );
bool isLocalAlgo = ( geom != GetGeom() );
addCmd->SetArg( addCmd->GetNbArgs() + 1,
TCollection_AsciiString( "geom=" ) + geom );
// sm = mesh.GetSubMesh(geom, name) --> sm = ALGO.GetSubMesh()
- list < Handle(_pySubMesh) >::iterator smIt;
+ list < Handle(_pySubMesh) >::iterator smIt;
for ( smIt = mySubmeshes.begin(); smIt != mySubmeshes.end(); ++smIt ) {
- Handle(_pySubMesh) subMesh = *smIt;
+ Handle(_pySubMesh) subMesh = *smIt;
Handle(_pyCommand) subCmd = subMesh->GetCreationCmd();
if ( geom == subCmd->GetArg( 1 )) {
subCmd->SetObject( algo->GetID() );
subCmd->RemoveArgs();
- subMesh->SetCreator( algo );
+ subMesh->SetCreator( algo );
}
}
}
static TStringSet sameMethods;
if ( sameMethods.empty() ) {
const char * names[] = {
- "RemoveElements","RemoveNodes","AddNode","AddEdge","AddFace","AddPolygonalFace",
+ "RemoveElements","RemoveNodes","AddNode","Add0DElement","AddEdge","AddFace","AddPolygonalFace",
"AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode", "MoveClosestNodeToPoint",
"InverseDiag","DeleteDiag","Reorient","ReorientObject","TriToQuad","SplitQuad","SplitQuadObject",
"BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
hyp->AddArgMethod( "SetNumberOfSegments" );
// arg of SetScaleFactor() will become the 2-nd arg of hyp creation command
hyp->AddArgMethod( "SetScaleFactor" );
+ hyp->AddArgMethod( "SetReversedEdges" );
}
else if ( hypType == "Arithmetic1D" ) {
hyp = new _pyComplexParamHypo( theCreationCmd );
hyp->SetConvMethodAndType( "Arithmetic1D", "Regular_1D");
+ hyp->AddArgMethod( "SetStartLength" );
+ hyp->AddArgMethod( "SetEndLength" );
+ hyp->AddArgMethod( "SetReversedEdges" );
}
else if ( hypType == "StartEndLength" ) {
hyp = new _pyComplexParamHypo( theCreationCmd );
hyp->SetConvMethodAndType( "StartEndLength", "Regular_1D");
+ hyp->AddArgMethod( "SetStartLength" );
+ hyp->AddArgMethod( "SetEndLength" );
+ hyp->AddArgMethod( "SetReversedEdges" );
}
else if ( hypType == "Deflection1D" ) {
hyp->SetConvMethodAndType( "Deflection1D", "Regular_1D");
}
else if ( hypType == "QuadranglePreference" ) {
hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
- hyp->SetConvMethodAndType( "QuadranglePreference", "NETGEN_2D_ONLY");
+ hyp->SetConvMethodAndType( "SetQuadAllowed", "NETGEN_2D_ONLY");
}
else if ( hypType == "TrianglePreference" ) {
hyp->SetConvMethodAndType( "TrianglePreference", "Quadrangle_2D");
- }
+ }
+ // RadialQuadrangle_1D2D ----------
+ else if ( hypType == "RadialQuadrangle_1D2D" ) {
+ algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
+ algo->myArgs.Append( "algo=smesh.RADIAL_QUAD" );
+ }
+ else if ( hypType == "NumberOfLayers2D" ) {
+ hyp->SetConvMethodAndType( "NumberOfLayers", "RadialQuadrangle_1D2D");
+ hyp->AddArgMethod( "SetNumberOfLayers" );
+ }
+ else if ( hypType == "LayerDistribution2D" ) {
+ hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get2DHypothesis" );
+ hyp->SetConvMethodAndType( "LayerDistribution", "RadialQuadrangle_1D2D");
+ }
// BLSURF ----------
else if ( hypType == "BLSURF" ) {
algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
hyp->AddArgMethod( "SetNumberOfLayers" );
}
else if ( hypType == "LayerDistribution" ) {
- hyp = new _pyLayerDistributionHypo( theCreationCmd );
+ hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get3DHypothesis" );
hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
}
- if ( algo->IsValid() ) {
- return algo;
- }
- return hyp;
+ return algo->IsValid() ? algo : hyp;
}
//================================================================================
//================================================================================
void _pyHypothesis::Assign( const Handle(_pyHypothesis)& theOther,
- const _pyID& theMesh )
+ const _pyID& theMesh )
{
myIsWrapped = false;
myMesh = theMesh;
void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
{
- // ex: hyp.SetLength(start, 1)
- // hyp.SetLength(end, 0)
- ASSERT(( theCommand->GetMethod() == "SetLength" ));
- ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
- int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
- while ( myArgs.Length() < i )
- myArgs.Append( "[]" );
- myArgs( i ) = theCommand->GetArg( 1 ); // arg value
- myArgCommands.push_back( theCommand );
+ if( theCommand->GetMethod() == "SetLength" )
+ {
+ // NOW it becomes OBSOLETE
+ // ex: hyp.SetLength(start, 1)
+ // hyp.SetLength(end, 0)
+ ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
+ int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
+ while ( myArgs.Length() < i )
+ myArgs.Append( "[]" );
+ myArgs( i ) = theCommand->GetArg( 1 ); // arg value
+ myArgCommands.push_back( theCommand );
+ }
+ else
+ {
+ _pyHypothesis::Process( theCommand );
+ }
+}
+//================================================================================
+/*!
+ * \brief Clear SetObjectEntry() as it is called by methods of Mesh_Segment
+ */
+//================================================================================
+
+void _pyComplexParamHypo::Flush()
+{
+ if ( IsWrapped() )
+ {
+ list < Handle(_pyCommand) >::iterator cmd = myUnknownCommands.begin();
+ for ( ; cmd != myUnknownCommands.end(); ++cmd )
+ if ((*cmd)->GetMethod() == "SetObjectEntry" )
+ (*cmd)->Clear();
+ }
}
//================================================================================
my1dHyp->ClearAllCommands();
}
my1dHyp = hyp1d;
- if ( my1dHyp.IsNull() )
- return; // something wrong :(
-
- // make a new name for 1D hyp = "HypType" + "_Distribution"
- if ( my1dHyp->GetCreationCmd()->GetMethod() == "CreateHypothesis" ) {
- // not yet converted creation cmd
- TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
- TCollection_AsciiString hypType = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
- newName = hypType + "_Distribution";
- my1dHyp->GetCreationCmd()->SetResultValue( newName );
- }
- else {
- // already converted creation cmd
- newName = my1dHyp->GetCreationCmd()->GetResultValue();
- }
- // as creation of 1D hyp was written later then it's edition,
- // we need to find all it's edition calls and process them
- list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
- list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
- for ( ; cmdIt != cmds.end(); ++cmdIt ) {
- const _pyID& objID = (*cmdIt)->GetObject();
- if ( objID == hyp1dID ) {
- my1dHyp->Process( *cmdIt );
- my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
- ( *cmdIt )->SetObject( newName );
- }
- }
if ( !myArgCommands.empty() )
myArgCommands.front()->Clear();
- theCommand->SetArg( 1, newName );
myArgCommands.push_back( theCommand );
- // copy hyp1d's creation method and args
-// myCreationMethod = hyp1d->GetCreationMethod();
-// myArgs = hyp1d->GetArgs();
-// // make them cleared at conversion
-// myArgCommands = hyp1d->GetArgCommands();
-
-// // to be cleared at convertion only
-// myArgCommands.push_back( theCommand );
}
//================================================================================
_pyID geom = theAdditionCmd->GetArg( 1 );
- my1dHyp->SetMesh( theMesh );
- if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
- return false;
+ Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
+ if ( !algo.IsNull() )
+ {
+ my1dHyp->SetMesh( theMesh );
+ my1dHyp->SetConvMethodAndType(my1dHyp->GetAlgoCreationMethod().ToCString(),
+ algo->GetAlgoType().ToCString());
+ if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
+ return false;
- // clear "SetLayerDistribution()" cmd
- myArgCommands.front()->Clear();
+ // clear "SetLayerDistribution()" cmd
+ myArgCommands.back()->Clear();
- // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
+ // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
- // find RadialPrism algo created on <geom> for theMesh
- Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
- if ( !algo.IsNull() ) {
+ // find RadialPrism algo created on <geom> for theMesh
GetCreationCmd()->SetObject( algo->GetID() );
- GetCreationCmd()->SetMethod( "Get3DHypothesis" );
+ GetCreationCmd()->SetMethod( myAlgoMethod );
GetCreationCmd()->RemoveArgs();
theAdditionCmd->AddDependantCmd( GetCreationCmd() );
myIsWrapped = true;
void _pyLayerDistributionHypo::Flush()
{
- //my1dHyp.Nullify();
- //_pyHypothesis::Flush();
+ // as creation of 1D hyp was written later then it's edition,
+ // we need to find all it's edition calls and process them
+ if ( !my1dHyp.IsNull() )
+ {
+ _pyID hyp1dID = my1dHyp->GetCreationCmd()->GetResultValue();
+
+ // make a new name for 1D hyp = "HypType" + "_Distribution"
+ _pyID newName;
+ if ( my1dHyp->IsWrapped() ) {
+ newName = my1dHyp->GetCreationCmd()->GetMethod();
+ }
+ else {
+ TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
+ newName = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
+ }
+ newName += "_Distribution";
+ my1dHyp->GetCreationCmd()->SetResultValue( newName );
+
+ list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
+ list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
+ for ( ; cmdIt != cmds.end(); ++cmdIt ) {
+ const _pyID& objID = (*cmdIt)->GetObject();
+ if ( objID == hyp1dID ) {
+ my1dHyp->Process( *cmdIt );
+ my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
+ ( *cmdIt )->SetObject( newName );
+ }
+ }
+ // Set new hyp name to SetLayerDistribution() cmd
+ if ( !myArgCommands.empty() && !myArgCommands.back()->IsEmpty() )
+ myArgCommands.back()->SetArg( 1, newName );
+ }
}
//================================================================================
for ( ; !distrTypeNb && cmd != myUnknownCommands.rend(); ++cmd )
if ( (*cmd)->GetMethod() == "SetDistrType" )
distrTypeNb = (*cmd)->GetOrderNb();
+ else if (IsWrapped() && (*cmd)->GetMethod() == "SetObjectEntry" )
+ (*cmd)->Clear();
// clear commands before the last SetDistrType()
list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnknownCommands };
int nb1 = 0; // number of ' character at the left of =
int nb2 = 0; // number of " character at the left of =
for ( int i = 1; i < begPos-1; i++ ) {
- if ( myString.Value( i )=='\'' )
- nb1 += 1;
- else if ( myString.Value( i )=='"' )
- nb2 += 1;
+ if ( myString.Value( i )=='\'' )
+ nb1 += 1;
+ else if ( myString.Value( i )=='"' )
+ nb2 += 1;
}
// if number of ' or " is not divisible by 2,
// then get an object at the start of the command
if ( nb1 % 2 != 0 || nb2 % 2 != 0 )
- begPos = 1;
+ begPos = 1;
}
myObj = GetWord( myString, begPos, true );
// check if object is complex,
while ( begPos != EMPTY ) {
begPos += prevLen;
if( myString.Value( begPos ) == '(' )
- nbNestings++;
+ nbNestings++;
// check if we are looking at the closing parenthesis
while ( begPos <= Length() && isspace( myString.Value( begPos )))
++begPos;
if ( begPos > Length() )
break;
if ( myString.Value( begPos ) == ')' ) {
- nbNestings--;
- if( nbNestings == 0 )
- break;
+ nbNestings--;
+ if( nbNestings == 0 )
+ break;
}
myArgs.Append( GetWord( myString, begPos, true, true ));
SetBegPos( ARG1_IND + i, begPos );
return theEmptyString; // no word found
// end
end = beg + 1;
- while ( end <= theString.Length() && isWord( theString.Value( end ), dotIsWord))
- ++end;
- --end;
+ char begChar = theString.Value( beg );
+ if ( begChar == '"' || begChar == '\'' || begChar == '[') {
+ char endChar = ( begChar == '[' ) ? ']' : begChar;
+ // end is at the corresponding quoting mark or bracket
+ while ( end < theString.Length() &&
+ ( theString.Value( end ) != endChar || theString.Value( end-1 ) == '\\'))
+ ++end;
+ }
+ else {
+ while ( end <= theString.Length() && isWord( theString.Value( end ), dotIsWord))
+ ++end;
+ --end;
+ }
}
else { // search backward
// end
if ( end == 0 )
return theEmptyString; // no word found
beg = end - 1;
- while ( beg > 0 && isWord( theString.Value( beg ), dotIsWord))
- --beg;
- ++beg;
+ char endChar = theString.Value( end );
+ if ( endChar == '"' || endChar == '\'' ) {
+ // beg is at the corresponding quoting mark
+ while ( beg > 1 &&
+ ( theString.Value( beg ) != endChar || theString.Value( beg-1 ) == '\\'))
+ --beg;
+ }
+ else {
+ while ( beg > 0 && isWord( theString.Value( beg ), dotIsWord))
+ --beg;
+ ++beg;
+ }
}
theStartPos = beg;
//cout << theString << " ---- " << beg << " - " << end << endl;