1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_DumpPython.cxx
23 // Created : Thu Mar 24 17:17:59 2005
24 // Author : Julia DOROVSKIKH
27 #include "SMESH_PythonDump.hxx"
29 #include "SMESH_2smeshpy.hxx"
30 #include "SMESH_Comment.hxx"
31 #include "SMESH_Filter_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_MeshEditor_i.hxx"
35 #include <Basics_Utils.hxx>
36 #include <Basics_OCCTVersion.hxx>
37 #include <SALOMEDS_wrap.hxx>
39 #include <LDOMParser.hxx>
40 #include <TColStd_HSequenceOfInteger.hxx>
41 #include <TCollection_AsciiString.hxx>
43 #if OCC_VERSION_LARGE < 0x07050000
44 #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
49 #include "SMESH_TryCatch.hxx"
54 size_t TPythonDump::myCounter = 0;
55 const char theNotPublishedObjectName[] = "__NOT__Published__Object__";
57 TVar::TVar(CORBA::Double value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
58 TVar::TVar(CORBA::Long value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
59 TVar::TVar(CORBA::LongLong value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
60 TVar::TVar(CORBA::Short value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
61 TVar::TVar(const SMESH::double_array& value):myVals(value.length()), myIsList(true)
63 for ( size_t i = 0; i < value.length(); i++)
64 myVals[i] = SMESH_Comment(value[i]);
67 TPythonDump::TPythonDump():myVarsCounter(0),mySmesh(SMESH_Gen_i::GetSMESHGen())
72 TPythonDump::TPythonDump(SMESH_Gen_i *smesh):myVarsCounter(0),mySmesh(smesh)
80 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
81 std::string aString = myStream.str();
82 TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
83 if(!aCollection.IsEmpty())
85 const std::string & objEntry = aSMESHGen->GetLastObjEntry();
86 if ( !objEntry.empty() )
87 aCollection += (TVar::ObjPrefix() + objEntry ).c_str();
88 aSMESHGen->AddToPythonScript(aCollection);
90 // prevent misuse of already treated variables
91 aSMESHGen->UpdateParameters(CORBA::Object_var().in(),"");
96 TPythonDump& //!< store a variable value. Write either a value or '$varID$'
98 operator<<(const TVar& theVarValue)
100 const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices();
101 if ( theVarValue.myIsList )
104 for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i )
106 if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
107 myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
109 myStream << theVarValue.myVals[i-1];
110 if ( i < theVarValue.myVals.size() )
118 if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
119 myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
121 myStream << theVarValue.myVals[0];
129 operator<<(long int theArg){
136 operator<<(int theArg){
143 operator<<(long long theArg){
150 operator<<(double theArg){
157 operator<<(float theArg){
164 operator<<(const void* theArg){
171 operator<<(const char* theArg){
179 operator<<(const std::string& theArg){
186 operator<<(const SMESH::ElementType& theArg)
190 case ALL: myStream<<"ALL"; break;
191 case NODE: myStream<<"NODE"; break;
192 case EDGE: myStream<<"EDGE"; break;
193 case FACE: myStream<<"FACE"; break;
194 case VOLUME: myStream<<"VOLUME"; break;
195 case ELEM0D: myStream<<"ELEM0D"; break;
196 case BALL: myStream<<"BALL"; break;
197 default: myStream<<"__UNKNOWN__ElementType: " << theArg;
204 operator<<(const SMESH::GeometryType& theArg)
208 case Geom_POINT: myStream<<"Geom_POINT"; break;
209 case Geom_EDGE: myStream<<"Geom_EDGE"; break;
210 case Geom_TRIANGLE: myStream<<"Geom_TRIANGLE"; break;
211 case Geom_QUADRANGLE: myStream<<"Geom_QUADRANGLE"; break;
212 case Geom_POLYGON: myStream<<"Geom_POLYGON"; break;
213 case Geom_TETRA: myStream<<"Geom_TETRA"; break;
214 case Geom_PYRAMID: myStream<<"Geom_PYRAMID"; break;
215 case Geom_HEXA: myStream<<"Geom_HEXA"; break;
216 case Geom_PENTA: myStream<<"Geom_PENTA"; break;
217 case Geom_POLYHEDRA: myStream<<"Geom_POLYHEDRA"; break;
218 case Geom_BALL: myStream<<"Geom_BALL"; break;
219 default: myStream<<"__UNKNOWN__GeometryType: " << theArg;
225 operator<<(const SMESH::EntityType& theArg)
229 case Entity_0D: myStream<<"Entity_0D"; break;
230 case Entity_Edge: myStream<<"Entity_Edge"; break;
231 case Entity_Quad_Edge: myStream<<"Entity_Quad_Edge"; break;
232 case Entity_Triangle: myStream<<"Entity_Triangle"; break;
233 case Entity_Quad_Triangle: myStream<<"Entity_Quad_Triangle"; break;
234 case Entity_BiQuad_Triangle: myStream<<"Entity_BiQuad_Triangle"; break;
235 case Entity_Quadrangle: myStream<<"Entity_Quadrangle"; break;
236 case Entity_Quad_Quadrangle: myStream<<"Entity_Quad_Quadrangle"; break;
237 case Entity_BiQuad_Quadrangle: myStream<<"Entity_BiQuad_Quadrangle"; break;
238 case Entity_Polygon: myStream<<"Entity_Polygon"; break;
239 case Entity_Quad_Polygon: myStream<<"Entity_Quad_Polygon"; break;
240 case Entity_Tetra: myStream<<"Entity_Tetra"; break;
241 case Entity_Quad_Tetra: myStream<<"Entity_Quad_Tetra"; break;
242 case Entity_Pyramid: myStream<<"Entity_Pyramid"; break;
243 case Entity_Quad_Pyramid: myStream<<"Entity_Quad_Pyramid"; break;
244 case Entity_Hexa: myStream<<"Entity_Hexa"; break;
245 case Entity_Quad_Hexa: myStream<<"Entity_Quad_Hexa"; break;
246 case Entity_TriQuad_Hexa: myStream<<"Entity_TriQuad_Hexa"; break;
247 case Entity_Penta: myStream<<"Entity_Penta"; break;
248 case Entity_Quad_Penta: myStream<<"Entity_Quad_Penta"; break;
249 case Entity_BiQuad_Penta: myStream<<"Entity_BiQuad_Penta"; break;
250 case Entity_Hexagonal_Prism: myStream<<"Entity_Hexagonal_Prism"; break;
251 case Entity_Polyhedra: myStream<<"Entity_Polyhedra"; break;
252 case Entity_Quad_Polyhedra: myStream<<"Entity_Quad_Polyhedra"; break;
253 case Entity_Ball: myStream<<"Entity_Ball"; break;
254 case Entity_Last: myStream<<"Entity_Last"; break;
255 default: myStream<<"__UNKNOWN__EntityType: " << theArg;
261 TPythonDump::operator<<(const SMESH::long_array& theArg)
263 DumpArray( theArg, *this );
268 TPythonDump::operator<<(const SMESH::smIdType_array& theArg)
270 DumpArray( theArg, *this );
275 TPythonDump::operator<<(const SMESH::double_array& theArg)
277 DumpArray( theArg, *this );
282 TPythonDump::operator<<(const SMESH::nodes_array& theArg)
284 DumpArray( theArg, *this );
289 TPythonDump::operator<<(const SMESH::string_array& theArray)
292 for ( CORBA::ULong i = 1; i <= theArray.length(); i++ ) {
293 myStream << "'" << theArray[i-1] << "'";
294 if ( i < theArray.length() )
303 operator<<(SALOMEDS::SObject_ptr aSObject)
305 if ( !aSObject->_is_nil() ) {
306 CORBA::String_var entry = aSObject->GetID();
307 myStream << entry.in();
310 myStream << theNotPublishedObjectName;
317 operator<<(CORBA::Object_ptr theArg)
319 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
320 SALOMEDS::SObject_wrap aSObject = mySmesh->ObjectToSObject(theArg);
321 if(!aSObject->_is_nil()) {
322 CORBA::String_var id = aSObject->GetID();
324 } else if ( !CORBA::is_nil(theArg)) {
325 if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
326 myStream << "smeshObj_" << size_t(theArg);
328 myStream << theNotPublishedObjectName;
337 operator<<(SMESH::SMESH_Hypothesis_ptr theArg)
339 SALOMEDS::SObject_wrap aSObject = mySmesh->ObjectToSObject(theArg);
340 if(aSObject->_is_nil() && !CORBA::is_nil(theArg))
341 myStream << "hyp_" << theArg->GetId();
349 operator<<(SMESH::SMESH_IDSource_ptr theArg)
351 if ( CORBA::is_nil( theArg ) )
352 return *this << "None";
353 SALOMEDS::SObject_wrap aSObject = mySmesh->ObjectToSObject(theArg);
354 if(!aSObject->_is_nil())
356 return *this << aSObject;
358 if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theArg ))
360 return *this << filter;
362 if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theArg ))
364 SMESH::SMESH_Mesh_var mesh = theArg->GetMesh();
365 SMESH::smIdType_array_var anElementsId = theArg->GetIDs();
366 SMESH::array_of_ElementType_var types = theArg->GetTypes();
367 SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL;
368 SALOMEDS::SObject_wrap meshSO = mySmesh->ObjectToSObject(mesh);
370 if ( meshSO->_is_nil() ) // don't waste memory for dumping not published objects
371 return *this << mesh << ".GetIDSource([], " << type << ")";
373 return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
375 return *this << theNotPublishedObjectName;
380 operator<<(SMESH::FilterLibrary_i* theArg)
382 myStream<<"aFilterLibrary"<<theArg;
388 operator<<(SMESH::FilterManager_i* /*theArg*/)
390 myStream<<"aFilterManager";
396 operator<<(SMESH::Filter_i* theArg)
398 myStream<<"aFilter"<<theArg;
404 operator<<(SMESH::Functor_i* theArg)
407 FunctorType aFunctorType = theArg->GetFunctorType();
408 switch(aFunctorType) {
409 case FT_AspectRatio: myStream<< "aAspectRatio"; break;
410 case FT_AspectRatio3D: myStream<< "aAspectRatio3D"; break;
411 case FT_Warping: myStream<< "aWarping"; break;
412 case FT_MinimumAngle: myStream<< "aMinimumAngle"; break;
413 case FT_Taper: myStream<< "aTaper"; break;
414 case FT_Skew: myStream<< "aSkew"; break;
415 case FT_Area: myStream<< "aArea"; break;
416 case FT_Volume3D: myStream<< "aVolume3D"; break;
417 case FT_MaxElementLength2D: myStream<< "aMaxElementLength2D"; break;
418 case FT_MaxElementLength3D: myStream<< "aMaxElementLength3D"; break;
419 case FT_FreeBorders: myStream<< "aFreeBorders"; break;
420 case FT_FreeEdges: myStream<< "aFreeEdges"; break;
421 case FT_FreeNodes: myStream<< "aFreeNodes"; break;
422 case FT_FreeFaces: myStream<< "aFreeFaces"; break;
423 case FT_EqualNodes: myStream<< "aEqualNodes"; break;
424 case FT_EqualEdges: myStream<< "aEqualEdges"; break;
425 case FT_EqualFaces: myStream<< "aEqualFaces"; break;
426 case FT_EqualVolumes: myStream<< "aEqualVolumes"; break;
427 case FT_MultiConnection: myStream<< "aMultiConnection"; break;
428 case FT_MultiConnection2D: myStream<< "aMultiConnection2D"; break;
429 case FT_Length: myStream<< "aLength"; break;
430 case FT_Length2D: myStream<< "aLength2D"; break;
431 case FT_Length3D: myStream<< "aLength3D"; break;
432 case FT_Deflection2D: myStream<< "aDeflection2D"; break;
433 case FT_NodeConnectivityNumber:myStream<< "aNodeConnectivityNumber";break;
434 case FT_BelongToMeshGroup: myStream<< "aBelongToMeshGroup"; break;
435 case FT_BelongToGeom: myStream<< "aBelongToGeom"; break;
436 case FT_BelongToPlane: myStream<< "aBelongToPlane"; break;
437 case FT_BelongToCylinder: myStream<< "aBelongToCylinder"; break;
438 case FT_BelongToGenSurface: myStream<< "aBelongToGenSurface"; break;
439 case FT_LyingOnGeom: myStream<< "aLyingOnGeom"; break;
440 case FT_RangeOfIds: myStream<< "aRangeOfIds"; break;
441 case FT_BadOrientedVolume: myStream<< "aBadOrientedVolume"; break;
442 case FT_BareBorderVolume: myStream<< "aBareBorderVolume"; break;
443 case FT_BareBorderFace: myStream<< "aBareBorderFace"; break;
444 case FT_OverConstrainedVolume: myStream<< "aOverConstrainedVolume"; break;
445 case FT_OverConstrainedFace: myStream<< "aOverConstrainedFace"; break;
446 case FT_LinearOrQuadratic: myStream<< "aLinearOrQuadratic"; break;
447 case FT_GroupColor: myStream<< "aGroupColor"; break;
448 case FT_ElemGeomType: myStream<< "aElemGeomType"; break;
449 case FT_EntityType: myStream<< "aEntityType"; break;
450 case FT_CoplanarFaces: myStream<< "aCoplanarFaces"; break;
451 case FT_BallDiameter: myStream<< "aBallDiameter"; break;
452 case FT_ConnectedElements: myStream<< "aConnectedElements"; break;
453 case FT_LessThan: myStream<< "aLessThan"; break;
454 case FT_MoreThan: myStream<< "aMoreThan"; break;
455 case FT_EqualTo: myStream<< "aEqualTo"; break;
456 case FT_LogicalNOT: myStream<< "aLogicalNOT"; break;
457 case FT_LogicalAND: myStream<< "aLogicalAND"; break;
458 case FT_LogicalOR: myStream<< "aLogicalOR"; break;
459 case FT_Undefined: myStream<< "anUndefined"; break;
460 //default: -- commented to have a compilation warning
469 operator<<(SMESH::Measurements_i* /*theArg*/)
471 myStream<<"aMeasurements";
475 TPythonDump& TPythonDump:: operator<<(SMESH_Gen_i* /*theArg*/)
477 myStream << SMESHGenName(); return *this;
480 TPythonDump& TPythonDump::operator<<(SMESH_MeshEditor_i* theArg)
482 myStream << MeshEditorName() << "_" << ( theArg ? theArg->GetMeshId() : -1 ); return *this;
485 TPythonDump& TPythonDump::operator<<(const TCollection_AsciiString & theStr)
487 myStream << theStr; return *this;
490 TPythonDump& TPythonDump::operator<<(const SMESH::AxisStruct & theAxis)
492 *this << "SMESH.AxisStruct( "
493 << TVar( theAxis.x ) << ", "
494 << TVar( theAxis.y ) << ", "
495 << TVar( theAxis.z ) << ", "
496 << TVar( theAxis.vx ) << ", "
497 << TVar( theAxis.vy ) << ", "
498 << TVar( theAxis.vz ) << " )";
502 TPythonDump& TPythonDump::operator<<(const SMESH::DirStruct & theDir)
504 const SMESH::PointStruct & P = theDir.PS;
505 *this << "SMESH.DirStruct( SMESH.PointStruct ( "
506 << TVar( P.x ) << ", "
507 << TVar( P.y ) << ", "
508 << TVar( P.z ) << " ))";
512 TPythonDump& TPythonDump::operator<<(const SMESH::PointStruct & P)
514 *this << "SMESH.PointStruct ( "
515 << TVar( P.x ) << ", "
516 << TVar( P.y ) << ", "
517 << TVar( P.z ) << " )";
521 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups& theList)
523 DumpArray( theList, *this );
526 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups * theList)
528 DumpArray( *theList, *this );
531 TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGO& theList)
533 DumpArray( theList, *this );
536 TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGBO& theList)
538 DumpArray( theList, *this );
541 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfIDSources& theList)
543 DumpArray( theList, *this );
546 TPythonDump& TPythonDump::operator<<(const SMESH::submesh_array& theList)
548 DumpArray( theList, *this );
551 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfHypothesis& theList)
553 DumpArray( theList, *this );
556 TPythonDump& TPythonDump::operator<<(const SMESH::CoincidentFreeBorders& theCFB)
558 // dump CoincidentFreeBorders as a list of lists, each enclosed list
559 // contains node IDs of a group of coincident free borders where
560 // each consequent triple of IDs describe a free border: (n1, n2, nLast)
561 // For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes
562 // two groups of coincident free borders, each group including two borders
565 for ( CORBA::ULong i = 0; i < theCFB.coincidentGroups.length(); ++i )
567 const SMESH::FreeBordersGroup& aGRP = theCFB.coincidentGroups[ i ];
568 if ( i ) myStream << ",";
570 for ( CORBA::ULong iP = 0; iP < aGRP.length(); ++iP )
572 const SMESH::FreeBorderPart& aPART = aGRP[ iP ];
573 if ( 0 <= aPART.border && aPART.border < (CORBA::Long)theCFB.borders.length() )
575 if ( iP ) myStream << ", ";
576 const SMESH::FreeBorder& aBRD = theCFB.borders[ aPART.border ];
577 myStream << aBRD.nodeIDs[ aPART.node1 ] << ",";
578 myStream << aBRD.nodeIDs[ aPART.node2 ] << ",";
579 myStream << aBRD.nodeIDs[ aPART.nodeLast ];
589 const char* TPythonDump::NotPublishedObjectName()
591 return theNotPublishedObjectName;
594 TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" );
595 TCollection_AsciiString myLongStringEnd ( "TPythonDump::LongStringEnd" );
597 //================================================================================
599 * \brief Return marker of long string literal beginning
600 * \param type - a name of functionality producing the string literal
601 * \retval TCollection_AsciiString - the marker string to be written into
602 * a raw python script
604 //================================================================================
606 TCollection_AsciiString TPythonDump::LongStringStart(const char* type)
610 (Standard_Integer) strlen(type) +
615 //================================================================================
617 * \brief Return marker of long string literal end
618 * \retval TCollection_AsciiString - the marker string to be written into
619 * a raw python script
621 //================================================================================
623 TCollection_AsciiString TPythonDump::LongStringEnd()
625 return myLongStringEnd;
628 //================================================================================
630 * \brief Cut out a long string literal from a string
631 * \param theText - text possibly containing string literals
632 * \param theFrom - position in the text to search from
633 * \param theLongString - the retrieved literal
634 * \param theStringType - a name of functionality produced the literal
635 * \retval bool - true if a string literal found
637 * The literal is removed from theText; theFrom points position right after
638 * the removed literal
640 //================================================================================
642 bool TPythonDump::CutoutLongString( TCollection_AsciiString & theText,
644 TCollection_AsciiString & theLongString,
645 TCollection_AsciiString & theStringType)
647 if ( theFrom < 1 || theFrom > theText.Length() )
650 // ...script \ beg marker \ \ type \ literal \ end marker \ script...
651 // "theText myLongStringStart7 Pattern!!! SALOME Mesh Pattern file myLongStringEndtextEnd"
652 // 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
655 theFrom = theText.Location( myLongStringStart, theFrom, theText.Length() ); // = 09
659 // find where literal begins
660 int literalBeg = theFrom + myLongStringStart.Length(); // = 26
661 char* typeLenStr = (char*) theText.ToCString() + literalBeg - 1; // = "7 Pattern!!! SALO...."
662 int typeLen = atoi ( typeLenStr ); // = 7
663 while ( *typeLenStr != ' ' ) { // look for ' ' after typeLen
664 literalBeg++; // 26 -> 27
667 literalBeg += typeLen + 1; // = 35
668 if ( literalBeg > theText.Length() )
671 // where literal ends (i.e. end marker begins)
672 int literalEnd = theText.Location( myLongStringEnd, literalBeg, theText.Length() ); // = 64
674 literalEnd = theText.Length();
677 theLongString = theText.SubString( literalBeg, literalEnd - 1); // "!!! SALOME Mesh Pattern file "
679 theStringType = theText.SubString( literalBeg - typeLen, literalBeg - 1 ); // "Pattern"
681 literalEnd += myLongStringEnd.Length(); // = 79
682 TCollection_AsciiString textEnd = theText.SubString( literalEnd, theText.Length() ); // "textE..."
683 theText = theText.SubString( 1, theFrom - 1 ) + textEnd;
688 void printException( const char* text )
690 if (SALOME::VerbosityActivated())
691 std::cout << "Exception in SMESH_Gen_i::DumpPython(): " << text << std::endl;
694 //=======================================================================
695 //function : RemoveTabulation
697 //=======================================================================
698 void RemoveTabulation( TCollection_AsciiString& theScript )
700 std::string aString( theScript.ToCString() );
701 std::string::size_type aPos = 0;
702 while( aPos < aString.length() )
704 aPos = aString.find( "\n\t", aPos );
705 if( aPos == std::string::npos )
707 aString.replace( aPos, 2, "\n" );
710 theScript = aString.c_str();
714 //=======================================================================
715 //function : DumpPython
717 //=======================================================================
718 Engines::TMPFile* SMESH_Gen_i::DumpPython( CORBA::Boolean isPublished,
719 CORBA::Boolean isMultiFile,
720 CORBA::Boolean& isValidScript)
723 Kernel_Utils::Localizer loc;
725 SALOMEDS::Study_var aStudy = getStudyServant();
726 if (CORBA::is_nil(aStudy))
727 return new Engines::TMPFile(0);
729 CORBA::String_var compDataType = ComponentDataType();
730 SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
731 if (CORBA::is_nil(aSO))
732 return new Engines::TMPFile(0);
734 // Map study entries to object names
735 Resource_DataMapOfAsciiStringAsciiString aMap;
736 Resource_DataMapOfAsciiStringAsciiString aMapNames;
738 SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
739 for (Itr->InitEx(true); Itr->More(); Itr->Next()) {
740 SALOMEDS::SObject_wrap aValue = Itr->Value();
741 CORBA::String_var anID = aValue->GetID();
742 CORBA::String_var aName = aValue->GetName();
743 TCollection_AsciiString aGUIName ( (char*) aName.in() );
744 TCollection_AsciiString anEntry ( (char*) anID.in() );
745 if (aGUIName.Length() > 0) {
746 aMapNames.Bind( anEntry, aGUIName );
747 aMap.Bind( anEntry, aGUIName );
751 // Get trace of restored study
752 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
753 SALOMEDS::GenericAttribute_wrap anAttr =
754 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
756 SALOMEDS::AttributePythonObject_var pyAttr =
757 SALOMEDS::AttributePythonObject::_narrow(anAttr);
758 CORBA::String_var oldValue = pyAttr->GetObject();
759 TCollection_AsciiString aSavedTrace (oldValue.in());
761 // Add trace of API methods calls and replace study entries by names
762 TCollection_AsciiString aScript;
763 aScript += DumpPython_impl(aMap, aMapNames, isPublished, isMultiFile,
764 myIsHistoricalPythonDump, isValidScript, aSavedTrace);
766 int aLen = aScript.Length();
767 unsigned char* aBuffer = new unsigned char[aLen+1];
768 strcpy((char*)aBuffer, aScript.ToCString());
770 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
771 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
773 bool hasNotPublishedObjects = aScript.Location( SMESH::theNotPublishedObjectName, 1, aLen);
774 isValidScript = isValidScript && !hasNotPublishedObjects;
776 return aStreamFile._retn();
779 //=============================================================================
783 //=============================================================================
784 void SMESH_Gen_i::AddToPythonScript (const TCollection_AsciiString& theString)
786 if (myPythonScript.IsNull()) {
787 myPythonScript = new TColStd_HSequenceOfAsciiString;
789 myPythonScript->Append(theString);
792 //=============================================================================
794 * RemoveLastFromPythonScript
796 //=============================================================================
797 void SMESH_Gen_i::RemoveLastFromPythonScript()
799 if (!myPythonScript.IsNull()) {
800 int aLen = myPythonScript->Length();
801 myPythonScript->Remove(aLen);
805 //=======================================================================
806 //function : SavePython
808 //=======================================================================
809 void SMESH_Gen_i::SavePython()
811 // Dump trace of API methods calls
812 TCollection_AsciiString aScript = GetNewPythonLines();
814 // Check contents of PythonObject attribute
815 CORBA::String_var compDataType = ComponentDataType();
816 SALOMEDS::SObject_wrap aSO = getStudyServant()->FindComponent( compDataType.in() );
817 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
818 SALOMEDS::GenericAttribute_wrap anAttr =
819 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
821 SALOMEDS::AttributePythonObject_var pyAttr =
822 SALOMEDS::AttributePythonObject::_narrow(anAttr);
823 CORBA::String_var oldValue = pyAttr->GetObject();
824 TCollection_AsciiString oldScript (oldValue.in());
826 if (oldScript.Length() > 0) {
828 oldScript += aScript;
833 // Store in PythonObject attribute
834 pyAttr->SetObject(oldScript.ToCString(), 1);
836 // Clean trace of API methods calls
844 //=============================================================================
846 * FindEntries: Returns a sequence of start/end positions of entries in the string
848 //=============================================================================
849 Handle(TColStd_HSequenceOfInteger) FindEntries (TCollection_AsciiString& theString)
851 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
852 Standard_Integer aLen = theString.Length();
853 Standard_Boolean isFound = Standard_False;
855 char* arr = (char*) theString.ToCString();
856 Standard_Integer i = 0, j;
861 if ( isdigit( c )) { //Is digit?
863 isFound = Standard_False;
864 while((j < aLen) && ( isdigit(c) || c == ':' )) { //Check if it is an entry
866 if(c == ':') isFound = Standard_True;
870 int prev = (i < 1) ? 0 : (int)arr[i - 1];
871 // to distinguish from a sketcher command:
872 // last char should be a digit, not ":",
873 // previous char should not be '"'.
874 if (arr[j-2] != ':' && prev != '"') {
875 aSeq->Append(i+1); // +1 because AsciiString starts from 1
889 //================================================================================
891 * \brief Make a string be a valid python name
892 * \param aName - a string to fix
893 * \retval bool - true if aName was not modified
895 //================================================================================
897 bool fixPythonName(TCollection_AsciiString & aName)
899 bool isValidName = true;
900 int nbUnderscore = 0;
902 // replace not allowed chars by underscore
903 const char* name = aName.ToCString();
904 for ( p = 0; name[p]; ++p ) {
905 if ( !isalnum( name[p] ) && name[p] != '_' )
907 if ( p == 0 || p+1 == aName.Length() || name[p-1] == '_')
909 aName.Remove( p+1, 1 ); // remove __ and _ from the start and the end
911 name = aName.ToCString();
915 aName.SetValue( p+1, '_');
921 // aName must not start with a digit
922 if ( aName.IsIntegerValue() ) {
923 aName.Insert( 1, 'a' );
926 // shorten names like CartesianParameters3D_400_400_400_1000000_1
927 const int nbAllowedUnderscore = 3; /* changed from 2 to 3 by an user request
928 posted to SALOME Forum */
929 if ( aName.Length() > 20 && nbUnderscore > nbAllowedUnderscore )
931 p = aName.Location( "_", 20, aName.Length());
938 //================================================================================
940 * \brief Return Python module names of available plug-ins.
942 //================================================================================
944 std::vector<std::string> getPluginNames()
946 std::vector<std::string> pluginNames;
947 std::vector< std::string > xmlPaths = SMESH_Gen::GetPluginXMLPaths();
948 LDOMParser xmlParser;
949 for ( size_t i = 0; i < xmlPaths.size(); ++i )
951 bool error = xmlParser.parse( xmlPaths[i].c_str() );
954 TCollection_AsciiString data;
955 INFOS( xmlParser.GetError(data) );
958 // <meshers-group name="Standard Meshers"
959 // resources="StdMeshers"
960 // idl-module="StdMeshers"
961 // server-lib="StdMeshersEngine"
962 // gui-lib="StdMeshersGUI">
963 LDOM_Document xmlDoc = xmlParser.getDocument();
964 LDOM_NodeList nodeList = xmlDoc.getElementsByTagName( "meshers-group" );
965 for ( int i = 0; i < nodeList.getLength(); ++i )
967 LDOM_Node node = nodeList.item( i );
968 LDOM_Element& elem = (LDOM_Element&) node;
969 LDOMString idlModule = elem.getAttribute( "idl-module" );
970 if ( strlen( idlModule.GetString() ) > 0 )
971 pluginNames.push_back( idlModule.GetString() );
978 //================================================================================
980 * \brief Creates a Dump Python script
981 * \param [in,out] theObjectNames - map of an entry to a study and python name
982 * \param [in] theNames - - map of an entry to a study name
983 * \param [in] isPublished - \c true if dump of object publication in study is needed
984 * \param [in] isMultiFile - \c true if dump of each module goes to a separate file
985 * \param [in] isHistoricalDump - \c true if removed object should be dumped
986 * \param [out] aValidScript - returns \c true if the returned script seems valid
987 * \param [in,out] theSavedTrace - the dump stored in the study. It's cleared to
988 * decrease memory usage.
989 * \return TCollection_AsciiString - the result dump script.
991 //================================================================================
993 TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
994 (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
995 Resource_DataMapOfAsciiStringAsciiString& theNames,
998 bool isHistoricalDump,
1000 TCollection_AsciiString& theSavedTrace)
1004 const TCollection_AsciiString aSmeshpy ( SMESH_2smeshpy::SmeshpyName() );
1005 const TCollection_AsciiString aSMESHGen( SMESH_2smeshpy::GenName() );
1006 const TCollection_AsciiString anOldGen ( SMESH::TPythonDump::SMESHGenName() );
1007 const TCollection_AsciiString helper; // to comfortably append C strings to TCollection_AsciiString
1008 const TCollection_AsciiString tab( isMultiFile ? "\t" : "" ), nt = helper + "\n" + tab;
1009 TCollection_AsciiString optionalComment;
1011 std::list< TCollection_AsciiString > lines; // lines of a script
1012 std::list< TCollection_AsciiString >::iterator linesIt;
1014 lines.push_back( aSMESHGen + " = smeshBuilder.New()" );
1016 optionalComment = "#";
1017 lines.push_back( optionalComment + aSMESHGen + ".SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations:" );
1018 lines.push_back( " # multiples meshes built in parallel, complex and numerous mesh edition (performance)\n" );
1019 lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" );
1020 lines.push_back( helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()" );
1022 // Treat dump trace of restored study
1023 if (theSavedTrace.Length() > 0)
1025 linesIt = --lines.end();
1026 // Split theSavedTrace into lines
1027 int from = 1, end = theSavedTrace.Length(), to;
1028 while ( from < end && ( to = theSavedTrace.Location( "\n", from, end )))
1030 if ( theSavedTrace.ToCString()[from-1] == '\t' )
1033 lines.push_back( theSavedTrace.SubString( from, to - 1 ));
1036 // For the conversion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen
1037 // was replaces with "smeshgen" (==TPythonDump::SMESHGenName()).
1038 // Change "smesh" -> "smeshgen" in the trace saved before passage to smeshBuilder.py API
1040 theSavedTrace.Location( anOldGen + ".", 1, theSavedTrace.Length() );
1041 theSavedTrace.Clear();
1042 if ( !isNewVersion )
1044 const TCollection_AsciiString aSmeshCall ( "smesh." ), gen( "gen" );
1046 for ( ++linesIt; linesIt != lines.end(); ++linesIt )
1048 TCollection_AsciiString& aSavedLine = *linesIt;
1049 end = aSavedLine.Length(), from = 1;
1050 while ( from < end && ( beg = aSavedLine.Location( aSmeshCall, from, end )))
1052 char charBefore = ( beg == 1 ) ? ' ' : aSavedLine.Value( beg - 1 );
1053 if ( isspace( charBefore ) || charBefore == '=' ) { // "smesh." is not a part of a long word
1054 aSavedLine.Insert( beg + aSmeshCall.Length() - 1, gen );// "smesh" -> "smeshgen"
1055 end += gen.Length();
1057 from = beg + aSmeshCall.Length();
1063 // Add new dump trace of API methods calls to script lines
1064 if (!myPythonScript.IsNull())
1066 Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript;
1067 Standard_Integer istr, aLen = aPythonScript->Length();
1068 for (istr = 1; istr <= aLen; istr++)
1069 lines.push_back( aPythonScript->Value( istr ));
1072 // Convert IDL API calls into smeshBuilder.py API.
1073 // Some objects are wrapped with python classes and
1074 // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
1075 Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
1076 std::set< TCollection_AsciiString > aRemovedObjIDs;
1077 if ( !getenv("NO_2smeshpy_conversion"))
1078 SMESH_2smeshpy::ConvertScript( lines, anEntry2AccessorMethod,
1079 theObjectNames, aRemovedObjIDs,
1082 bool importGeom = false;
1083 GEOM::GEOM_Gen_ptr geom[2];
1084 for ( int isShaper = 0; isShaper < 2; ++isShaper )
1086 geom[ isShaper ] = GetGeomEngine( isShaper );
1087 if ( CORBA::is_nil( geom[ isShaper ]))
1089 // Add names of GEOM objects to theObjectNames to exclude same names of SMESH objects
1090 GEOM::string_array_var aGeomNames = geom[ isShaper ]->GetAllDumpNames();
1091 for ( CORBA::ULong ign = 0; ign < aGeomNames->length(); ign++) {
1092 TCollection_AsciiString aName = aGeomNames[ign].in();
1093 theObjectNames.Bind(aName, "1");
1097 TCollection_AsciiString anUpdatedScript;
1099 Resource_DataMapOfAsciiStringAsciiString mapRemoved;
1100 Resource_DataMapOfAsciiStringAsciiString mapEntries; // { entry: name } present in anUpdatedScript
1101 Standard_Integer objectCounter = 0;
1102 TCollection_AsciiString anEntry, aName, aGUIName, aBaseName("smeshObj_");
1104 std::string compDataType = ComponentDataType(); // SMESH module's data type
1105 SALOMEDS::SComponent_var smeshSO = getStudyServant()->FindComponent( compDataType.c_str() );
1106 CORBA::String_var smeshID = smeshSO->GetID();
1107 TCollection_AsciiString smeshEntry = smeshID.in();
1109 // Treat every script line and add it to anUpdatedScript
1110 for ( linesIt = lines.begin(); linesIt != lines.end(); ++linesIt )
1112 TCollection_AsciiString& aLine = *linesIt;
1113 anUpdatedScript += tab;
1115 //Replace characters used instead of quote marks to quote notebook variables
1117 while (( pos = aLine.Location( 1, SMESH::TVar::Quote(), pos, aLine.Length() )))
1118 aLine.SetValue( pos, '"' );
1120 // Find entries to be replaced by names
1121 Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aLine);
1122 const Standard_Integer aSeqLen = aSeq->Length();
1123 Standard_Integer aStart = 1;
1124 for (Standard_Integer i = 1; i <= aSeqLen; i += 2)
1126 if ( aStart < aSeq->Value(i) )
1127 anUpdatedScript += aLine.SubString( aStart, aSeq->Value(i) - 1 ); // line part before i-th entry
1128 anEntry = aLine.SubString( aSeq->Value(i), aSeq->Value(i + 1) );
1129 // is a GEOM object?
1130 CORBA::String_var geomName;
1131 if ( !CORBA::is_nil( geom[0] ))
1132 geomName = geom[0]->GetDumpName( anEntry.ToCString() );
1133 if (( !geomName.in() || !geomName.in()[0] ) && !CORBA::is_nil( geom[1] ))
1134 geomName = geom[1]->GetDumpName( anEntry.ToCString() );
1135 if ( !geomName.in() || !geomName.in()[0] ) {
1136 // is a SMESH object
1137 if ( theObjectNames.IsBound( anEntry )) {
1138 // The Object is in Study
1139 aName = theObjectNames.Find( anEntry );
1140 // check validity of aName
1141 bool isValidName = fixPythonName( aName );
1142 if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
1143 // diff objects have same name - make a new name by appending a digit
1144 TCollection_AsciiString aName2;
1145 Standard_Integer i = 0;
1147 aName2 = aName + "_" + ++i;
1148 } while (theObjectNames.IsBound(aName2) && anEntry != theObjectNames(aName2));
1150 isValidName = false;
1153 theObjectNames(anEntry) = aName;
1155 if ( aLine.Value(1) != '#' )
1156 mapEntries.Bind(anEntry, aName);
1160 if ( !anEntry.StartsWith( smeshEntry )) // not SMESH object
1162 aName = SMESH::TPythonDump::NotPublishedObjectName();
1168 aName = aBaseName + (++objectCounter);
1169 } while (theObjectNames.IsBound(aName));
1171 if ( !aRemovedObjIDs.count( anEntry ) && aLine.Value(1) != '#')
1172 mapRemoved.Bind(anEntry, aName);
1174 theObjectNames.Bind(anEntry, aName);
1177 theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
1181 aName = geomName.in();
1184 anUpdatedScript += aName;
1185 aStart = aSeq->Value(i + 1) + 1;
1187 } // loop on entries within aLine
1190 anUpdatedScript += aLine;
1191 else if ( aSeq->Value( aSeqLen ) < aLine.Length() )
1192 anUpdatedScript += aLine.SubString( aSeq->Value(aSeqLen) + 1, aLine.Length() );
1194 anUpdatedScript += '\n';
1197 // Make an initial part of aSript
1199 TCollection_AsciiString initPart = "import ";
1201 initPart += "salome, ";
1202 initPart += " SMESH, SALOMEDS\n";
1203 initPart += "from salome.smesh import smeshBuilder\n";
1204 if ( importGeom && isMultiFile )
1206 initPart += ("\n## import GEOM dump file ## \n"
1207 "import string, os, sys, re, inspect\n"
1208 "thisFile = inspect.getfile( inspect.currentframe() )\n"
1209 "thisModule = os.path.splitext( os.path.basename( thisFile ))[0]\n"
1210 "sys.path.insert( 0, os.path.dirname( thisFile ))\n"
1211 "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",thisModule)+\" import *\")\n\n");
1213 // import python files corresponding to plugins if they are used in anUpdatedScript
1215 //TCollection_AsciiString importStr;
1216 std::vector<std::string> pluginNames = getPluginNames();
1217 for ( size_t i = 0; i < pluginNames.size(); ++i )
1219 // Convert access to plugin members:
1220 // e.g. StdMeshers.QUAD_REDUCED -> smeshBuilder.QUAD_REDUCED
1221 TCollection_AsciiString pluginAccess = (pluginNames[i] + ".").c_str() ;
1222 int iFrom = 1, iPos;
1223 while (( iPos = anUpdatedScript.Location( pluginAccess, iFrom, anUpdatedScript.Length() )))
1225 //anUpdatedScript.Insert( iPos + pluginNames[i].size(), "Builder" );
1226 anUpdatedScript.Remove( iPos, pluginNames[i].size() );
1227 anUpdatedScript.Insert( iPos, "smeshBuilder" );
1228 iFrom = iPos - pluginNames[i].size() + 12;
1230 // if any plugin member is used, import the plugin
1232 // importStr += ( helper + "\n" "from salome." + pluginNames[i].c_str() +
1233 // " import " + pluginNames[i].c_str() +"Builder" );
1235 // if ( !importStr.IsEmpty() )
1236 // initPart += importStr + "\n";
1240 initPart += "def RebuildData():";
1243 anUpdatedScript.Prepend( initPart );
1245 // Make a final part of aScript
1247 // Dump object removal
1248 TCollection_AsciiString removeObjPart;
1249 if ( !mapRemoved.IsEmpty() ) {
1250 removeObjPart += nt + "## some objects were removed";
1251 removeObjPart += nt + "aStudyBuilder = salome.myStudy.NewBuilder()";
1252 Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapRemovedIt;
1253 for ( mapRemovedIt.Initialize( mapRemoved ); mapRemovedIt.More(); mapRemovedIt.Next() ) {
1254 aName = mapRemovedIt.Value(); // python name
1255 anEntry = mapRemovedIt.Key();
1256 removeObjPart += nt + "SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR(";
1257 removeObjPart += aName;
1258 // for object wrapped by class of smeshBuilder.py
1259 if ( anEntry2AccessorMethod.IsBound( anEntry ) )
1260 removeObjPart += helper + "." + anEntry2AccessorMethod( anEntry );
1261 removeObjPart += helper + "))" + nt + "if SO: aStudyBuilder.RemoveObjectWithChildren(SO)";
1266 TCollection_AsciiString setNamePart;
1267 Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapEntriesIt;
1268 for ( mapEntriesIt.Initialize( mapEntries ); mapEntriesIt.More(); mapEntriesIt.Next() )
1270 anEntry = mapEntriesIt.Key();
1271 aName = mapEntriesIt.Value(); // python name
1272 if ( theNames.IsBound( anEntry ))
1274 aGUIName = theNames.Find(anEntry);
1275 aGUIName.RemoveAll('\''); // remove a quote from a name (issue 22360)
1276 setNamePart += nt + aSMESHGen + ".SetName(" + aName;
1277 if ( anEntry2AccessorMethod.IsBound( anEntry ) )
1278 setNamePart += helper + "." + anEntry2AccessorMethod( anEntry );
1279 setNamePart += helper + ", '" + aGUIName + "')";
1282 if ( !setNamePart.IsEmpty() )
1284 setNamePart.Insert( 1, nt + "## Set names of Mesh objects" );
1287 // Store visual properties of displayed objects
1289 TCollection_AsciiString visualPropertiesPart;
1292 //Output the script that sets up the visual parameters.
1293 CORBA::String_var compDataType = ComponentDataType();
1294 CORBA::String_var script = getStudyServant()->GetDefaultScript( compDataType.in(), tab.ToCString() );
1295 if ( script.in() && script.in()[0] ) {
1296 visualPropertiesPart += nt + "### Store presentation parameters of displayed objects\n";
1297 visualPropertiesPart += script.in();
1301 anUpdatedScript += removeObjPart + '\n' + setNamePart + '\n' + visualPropertiesPart;
1308 "\nif __name__ == '__main__':"
1309 "\n\tSMESH_RebuildData = RebuildData"
1310 "\n\texec('import '+re.sub('SMESH$','GEOM',thisModule)+' as GEOM_dump')"
1311 "\n\tGEOM_dump.RebuildData()"
1312 "\n\texec('from '+re.sub('SMESH$','GEOM',thisModule)+' import * ')"
1313 "\n\tSMESH_RebuildData()";
1315 anUpdatedScript += "\n";
1317 // no need now as we use 'tab' and 'nt' variables depending on isMultiFile
1318 // if( !isMultiFile ) // remove unnecessary tabulation
1319 // RemoveTabulation( anUpdatedScript );
1321 // -----------------------------------------------------------------
1322 // put string literals describing patterns into separate functions
1323 // -----------------------------------------------------------------
1325 TCollection_AsciiString aLongString, aFunctionType;
1327 std::set< std::string > functionNameSet;
1328 while ( SMESH::TPythonDump::CutoutLongString( anUpdatedScript, where, aLongString, aFunctionType ))
1330 // make a python string literal
1331 aLongString.Prepend(":\n\treturn '''\n");
1332 aLongString += "\n\t'''\n\tpass\n";
1334 TCollection_AsciiString functionName;
1336 // check if the function returning this literal is already defined
1337 int posAlready = anUpdatedScript.Location( aLongString, where, anUpdatedScript.Length() );
1338 if ( posAlready ) // already defined
1340 // find the function name
1341 int functBeg = posAlready;
1342 char* script = (char*) anUpdatedScript.ToCString() + posAlready - 1; // look at ":" after "def function()"
1343 while ( *script != ' ' ) {
1347 functBeg++; // do not take ' '
1348 posAlready--; // do not take ':'
1349 functionName = anUpdatedScript.SubString( functBeg, posAlready );
1351 else // not defined yet
1353 // find a unique function name
1354 fixPythonName( aFunctionType );
1355 Standard_Integer nb = 0;
1356 do functionName = aFunctionType + "_" + ( nb++ ) + "()";
1357 while ( !functionNameSet.insert( functionName.ToCString() ).second );
1360 TCollection_AsciiString funDef = helper + "def " + functionName + aLongString;
1363 anUpdatedScript += helper + "\n\n" + funDef;
1368 anUpdatedScript.Insert( 1, funDef);
1369 where += funDef.Length();
1372 anUpdatedScript.InsertBefore( where, functionName ); // call function
1375 aValidScript = true;
1377 return anUpdatedScript;
1379 SMESH_CATCH( SMESH::printException );
1381 aValidScript = false;
1385 //=============================================================================
1389 //=============================================================================
1390 TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines()
1392 TCollection_AsciiString aScript;
1394 // Dump trace of API methods calls
1395 if (!myPythonScript.IsNull()) {
1396 Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript;
1397 Standard_Integer istr, aLen = aPythonScript->Length();
1398 for (istr = 1; istr <= aLen; istr++) {
1400 aScript += aPythonScript->Value(istr);
1408 //=============================================================================
1412 //=============================================================================
1413 void SMESH_Gen_i::CleanPythonTrace()
1415 TCollection_AsciiString aScript;
1417 // Clean trace of API methods calls
1418 if (!myPythonScript.IsNull()) {
1419 myPythonScript->Clear();
1423 //================================================================================
1425 * \brief Count inclusions of a string in a raw Python dump script
1427 //================================================================================
1429 int SMESH_Gen_i::CountInPyDump(const TCollection_AsciiString& theText)
1433 SALOMEDS::Study_var aStudy = getStudyServant();
1434 if ( CORBA::is_nil( aStudy ))
1437 SMESH_Gen_i* me = GetSMESHGen();
1438 CORBA::String_var compDataType = me->ComponentDataType();
1439 SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
1440 if ( CORBA::is_nil( aSO ))
1443 // Trace saved in the study
1444 SALOMEDS::GenericAttribute_wrap attr;
1445 if ( aSO->FindAttribute( attr.inout(), "AttributePythonObject" ))
1447 SALOMEDS::AttributePythonObject_var pyAttr =
1448 SALOMEDS::AttributePythonObject::_narrow( attr );
1449 CORBA::String_var script = pyAttr->GetObject();
1450 for ( const char * scriptPos = script.in(); true; ++scriptPos )
1451 if (( scriptPos = strstr( scriptPos, theText.ToCString() )))
1457 // New python commands
1458 if ( !me->myPythonScript.IsNull() )
1460 const int nbLines = me->myPythonScript->Length();
1461 for ( int i = 1; i <= nbLines; ++i )
1463 const TCollection_AsciiString& line = me->myPythonScript->Value( i );
1464 for ( int loc = 1; loc <= line.Length(); ++loc )
1465 if (( loc = line.Location( theText, loc, line.Length() )))