X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_2smeshpy.cxx;h=4340ab41b8bd7a4a28dc174102638f7354e59b55;hp=96724a917b5d5d8b070906f614fefe60cf3399b8;hb=21c57ac1ede30f0bee01db8fbec004e6956eaafe;hpb=6fdc7dc872210feb3672f429545b996698e0932f diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index 96724a917..4340ab41b 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -1,26 +1,25 @@ -// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses // File : SMESH_2D_Algo_i.hxx // Author : Paul RASCLE, EDF // Module : SMESH @@ -29,7 +28,7 @@ // File : SMESH_2smeshpy.cxx // Created : Fri Nov 18 13:20:10 2005 // Author : Edward AGAPOV (eap) - +// #include "SMESH_2smeshpy.hxx" #include "utilities.h" @@ -237,6 +236,13 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID ); if ( id_editor != myMeshEditors.end() ) { id_editor->second->Process( aCommand ); + TCollection_AsciiString processedCommand = aCommand->GetString(); + // some commands of SMESH_MeshEditor create meshes + if ( aCommand->GetMethod().Search("MakeMesh") != -1 ) { + Handle(_pyMesh) mesh = new _pyMesh( aCommand, aCommand->GetResultValue() ); + aCommand->GetString() = processedCommand; // discard changes made by _pyMesh + myMeshes.insert( make_pair( mesh->GetID(), mesh )); + } return aCommand; } // SMESH_Hypothesis method? @@ -289,17 +295,20 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand ) // CreateHypothesis( theHypType, theLibName ) // Compute( mesh, geom ) // mesh creation - if ( theCommand->GetMethod() == "CreateMesh" || - theCommand->GetMethod() == "CreateEmptyMesh" || - theCommand->GetMethod() == "CreateMeshesFromUNV" || - theCommand->GetMethod() == "CreateMeshesFromSTL") + TCollection_AsciiString method = theCommand->GetMethod(); + if ( method == "CreateMesh" || method == "CreateEmptyMesh") { Handle(_pyMesh) mesh = new _pyMesh( theCommand ); myMeshes.insert( make_pair( mesh->GetID(), mesh )); return; } - - if(theCommand->GetMethod() == "CreateMeshesFromMED") + if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL") + { + Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() ); + myMeshes.insert( make_pair( mesh->GetID(), mesh )); + return; + } + if( method == "CreateMeshesFromMED") { for(int ind = 0;indGetNbResultValues();ind++) { @@ -309,14 +318,14 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand ) } // CreateHypothesis() - if ( theCommand->GetMethod() == "CreateHypothesis" ) + if ( method == "CreateHypothesis" ) { myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand )); return; } // smeshgen.Compute( mesh, geom ) --> mesh.Compute() - if ( theCommand->GetMethod() == "Compute" ) + if ( method == "Compute" ) { const _pyID& meshID = theCommand->GetArg( 1 ); map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID ); @@ -329,7 +338,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand ) } // leave only one smeshgen.GetPattern() in the script - if ( theCommand->GetMethod() == "GetPattern" ) { + if ( method == "GetPattern" ) { if ( myHasPattern ) { theCommand->Clear(); return; @@ -338,9 +347,14 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand ) } // Concatenate( [mesh1, ...], ... ) - if ( theCommand->GetMethod() == "Concatenate" || - theCommand->GetMethod() == "ConcatenateWithGroups") + if ( method == "Concatenate" || method == "ConcatenateWithGroups") { + if ( method == "ConcatenateWithGroups" ) { + theCommand->SetMethod( "Concatenate" ); + theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" ); + } + Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() ); + myMeshes.insert( make_pair( mesh->GetID(), mesh )); AddMeshAccessorMethod( theCommand ); } @@ -596,18 +610,17 @@ static bool sameGroupType( const _pyID& grpID, */ //================================================================================ -_pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd): - _pyObject(theCreationCmd), myHasEditor(false) +_pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd) + : _pyObject(theCreationCmd), myHasEditor(false) { // convert my creation command Handle(_pyCommand) creationCmd = GetCreationCmd(); - TCollection_AsciiString str = creationCmd->GetMethod(); - + //TCollection_AsciiString str = creationCmd->GetMethod(); +// if(str != "CreateMeshesFromUNV" && +// str != "CreateMeshesFromMED" && +// str != "CreateMeshesFromSTL") creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() ); - if(str != "CreateMeshesFromUNV" && - str != "CreateMeshesFromMED" && - str != "CreateMeshesFromSTL") - creationCmd->SetMethod( "Mesh" ); + creationCmd->SetMethod( "Mesh" ); theGen->SetAccessorMethod( GetID(), "GetMesh()" ); } @@ -893,20 +906,53 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand) sameMethods.Insert( names ); } + // names of SMESH_MeshEditor methods which differ from methods of class Mesh + // only last two arguments + static TStringSet diffLastTwoArgsMethods; + if (diffLastTwoArgsMethods.empty() ){ + const char * names[] = { + "MirrorMakeGroups","MirrorObjectMakeGroups", + "TranslateMakeGroups","TranslateObjectMakeGroups", + "RotateMakeGroups","RotateObjectMakeGroups", + ""};// <- mark of the end + diffLastTwoArgsMethods.Insert( names ); + } + if ( sameMethods.Contains( theCommand->GetMethod() )) { theCommand->SetObject( myMesh ); // meshes made by *MakeMesh() methods are not wrapped by _pyMesh, // so let _pyMesh care of it (TMP?) - if ( theCommand->GetMethod().Search("MakeMesh") != -1 ) - _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod() +// if ( theCommand->GetMethod().Search("MakeMesh") != -1 ) +// _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod() } else { - // editor creation command is needed only if any editor function is called - theGen->AddMeshAccessorMethod( theCommand ); // for *Object() - if ( !myCreationCmdStr.IsEmpty() ) { - GetCreationCmd()->GetString() = myCreationCmdStr; - myCreationCmdStr.Clear(); + + //Replace SMESH_MeshEditor "MakeGroups" functions on the Mesh + //functions with the flag "theMakeGroups = True" like: + //SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True) + int pos = theCommand->GetMethod().Search("MakeGroups"); + if( pos != -1) { + // 1. Remove "MakeGroups" from the Command + TCollection_AsciiString aMethod = theCommand->GetMethod(); + int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1; + aMethod.Trunc(pos-1); + theCommand->SetMethod(aMethod); + + // 2. Set Mesh object instead of SMESH_MeshEditor + theCommand->SetObject( myMesh ); + + // 3. And add last "True" argument + while(nbArgsToAdd--) + theCommand->SetArg(theCommand->GetNbArgs()+1,"True "); + } + else { + // editor creation command is needed only if any editor function is called + theGen->AddMeshAccessorMethod( theCommand ); // for *Object() + if ( !myCreationCmdStr.IsEmpty() ) { + GetCreationCmd()->GetString() = myCreationCmdStr; + myCreationCmdStr.Clear(); + } } } } @@ -1667,8 +1713,22 @@ const TCollection_AsciiString & _pyCommand::GetObject() { // beginning int begPos = GetBegPos( RESULT_IND ) + myRes.Length(); - if ( begPos < 1 ) + if ( begPos < 1 ) { begPos = myString.Location( "=", 1, Length() ) + 1; + // is '=' in the string argument (for example, name) or not + 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 ( IsEqual(myString.Value( i ), "'" ) ) + nb1 += 1; + else if ( IsEqual( 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; + } // store myObj = GetWord( myString, begPos, true ); SetBegPos( OBJECT_IND, begPos );