1 // Copyright (C) 2007-2020 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 <SALOMEDS_wrap.hxx>
38 #include <LDOMParser.hxx>
39 #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
40 #include <TColStd_HSequenceOfInteger.hxx>
41 #include <TCollection_AsciiString.hxx>
46 static int MYDEBUG = 0;
48 static int MYDEBUG = 0;
51 #include "SMESH_TryCatch.hxx"
56 size_t TPythonDump::myCounter = 0;
57 const char theNotPublishedObjectName[] = "__NOT__Published__Object__";
59 TVar::TVar(CORBA::Double value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
60 TVar::TVar(CORBA::Long value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
61 TVar::TVar(CORBA::Short value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
62 TVar::TVar(const SMESH::double_array& value):myVals(value.length()), myIsList(true)
64 for ( size_t i = 0; i < value.length(); i++)
65 myVals[i] = SMESH_Comment(value[i]);
69 TPythonDump():myVarsCounter(0)
77 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
78 std::string aString = myStream.str();
79 TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
80 if(!aCollection.IsEmpty())
82 const std::string & objEntry = aSMESHGen->GetLastObjEntry();
83 if ( !objEntry.empty() )
84 aCollection += (TVar::ObjPrefix() + objEntry ).c_str();
85 aSMESHGen->AddToPythonScript(aCollection);
86 if(MYDEBUG) MESSAGE(aString);
87 // prevent misuse of already treated variables
88 aSMESHGen->UpdateParameters(CORBA::Object_var().in(),"");
93 TPythonDump& //!< store a variable value. Write either a value or '$varID$'
95 operator<<(const TVar& theVarValue)
97 const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices();
98 if ( theVarValue.myIsList )
101 for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i )
103 if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
104 myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
106 myStream << theVarValue.myVals[i-1];
107 if ( i < theVarValue.myVals.size() )
115 if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
116 myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
118 myStream << theVarValue.myVals[0];
126 operator<<(long int theArg){
133 operator<<(int theArg){
140 operator<<(double theArg){
147 operator<<(float theArg){
154 operator<<(const void* theArg){
161 operator<<(const char* theArg){
169 operator<<(const std::string& theArg){
176 operator<<(const SMESH::ElementType& theArg)
180 case ALL: myStream<<"ALL"; break;
181 case NODE: myStream<<"NODE"; break;
182 case EDGE: myStream<<"EDGE"; break;
183 case FACE: myStream<<"FACE"; break;
184 case VOLUME: myStream<<"VOLUME"; break;
185 case ELEM0D: myStream<<"ELEM0D"; break;
186 case BALL: myStream<<"BALL"; break;
187 default: myStream<<"__UNKNOWN__ElementType: " << theArg;
194 operator<<(const SMESH::GeometryType& theArg)
198 case Geom_POINT: myStream<<"Geom_POINT"; break;
199 case Geom_EDGE: myStream<<"Geom_EDGE"; break;
200 case Geom_TRIANGLE: myStream<<"Geom_TRIANGLE"; break;
201 case Geom_QUADRANGLE: myStream<<"Geom_QUADRANGLE"; break;
202 case Geom_POLYGON: myStream<<"Geom_POLYGON"; break;
203 case Geom_TETRA: myStream<<"Geom_TETRA"; break;
204 case Geom_PYRAMID: myStream<<"Geom_PYRAMID"; break;
205 case Geom_HEXA: myStream<<"Geom_HEXA"; break;
206 case Geom_PENTA: myStream<<"Geom_PENTA"; break;
207 case Geom_POLYHEDRA: myStream<<"Geom_POLYHEDRA"; break;
208 case Geom_BALL: myStream<<"Geom_BALL"; break;
209 default: myStream<<"__UNKNOWN__GeometryType: " << theArg;
215 operator<<(const SMESH::EntityType& theArg)
219 case Entity_0D: myStream<<"Entity_0D"; break;
220 case Entity_Edge: myStream<<"Entity_Edge"; break;
221 case Entity_Quad_Edge: myStream<<"Entity_Quad_Edge"; break;
222 case Entity_Triangle: myStream<<"Entity_Triangle"; break;
223 case Entity_Quad_Triangle: myStream<<"Entity_Quad_Triangle"; break;
224 case Entity_BiQuad_Triangle: myStream<<"Entity_BiQuad_Triangle"; break;
225 case Entity_Quadrangle: myStream<<"Entity_Quadrangle"; break;
226 case Entity_Quad_Quadrangle: myStream<<"Entity_Quad_Quadrangle"; break;
227 case Entity_BiQuad_Quadrangle: myStream<<"Entity_BiQuad_Quadrangle"; break;
228 case Entity_Polygon: myStream<<"Entity_Polygon"; break;
229 case Entity_Quad_Polygon: myStream<<"Entity_Quad_Polygon"; break;
230 case Entity_Tetra: myStream<<"Entity_Tetra"; break;
231 case Entity_Quad_Tetra: myStream<<"Entity_Quad_Tetra"; break;
232 case Entity_Pyramid: myStream<<"Entity_Pyramid"; break;
233 case Entity_Quad_Pyramid: myStream<<"Entity_Quad_Pyramid"; break;
234 case Entity_Hexa: myStream<<"Entity_Hexa"; break;
235 case Entity_Quad_Hexa: myStream<<"Entity_Quad_Hexa"; break;
236 case Entity_TriQuad_Hexa: myStream<<"Entity_TriQuad_Hexa"; break;
237 case Entity_Penta: myStream<<"Entity_Penta"; break;
238 case Entity_Quad_Penta: myStream<<"Entity_Quad_Penta"; break;
239 case Entity_BiQuad_Penta: myStream<<"Entity_BiQuad_Penta"; break;
240 case Entity_Hexagonal_Prism: myStream<<"Entity_Hexagonal_Prism"; break;
241 case Entity_Polyhedra: myStream<<"Entity_Polyhedra"; break;
242 case Entity_Quad_Polyhedra: myStream<<"Entity_Quad_Polyhedra"; break;
243 case Entity_Ball: myStream<<"Entity_Ball"; break;
244 case Entity_Last: myStream<<"Entity_Last"; break;
245 default: myStream<<"__UNKNOWN__EntityType: " << theArg;
251 TPythonDump::operator<<(const SMESH::long_array& theArg)
253 DumpArray( theArg, *this );
258 TPythonDump::operator<<(const SMESH::double_array& theArg)
260 DumpArray( theArg, *this );
265 TPythonDump::operator<<(const SMESH::nodes_array& theArg)
267 DumpArray( theArg, *this );
272 TPythonDump::operator<<(const SMESH::string_array& theArray)
275 for ( CORBA::ULong i = 1; i <= theArray.length(); i++ ) {
276 myStream << "'" << theArray[i-1] << "'";
277 if ( i < theArray.length() )
286 operator<<(SALOMEDS::SObject_ptr aSObject)
288 if ( !aSObject->_is_nil() ) {
289 CORBA::String_var entry = aSObject->GetID();
290 myStream << entry.in();
293 myStream << theNotPublishedObjectName;
300 operator<<(CORBA::Object_ptr theArg)
302 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
303 SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg);
304 if(!aSObject->_is_nil()) {
305 CORBA::String_var id = aSObject->GetID();
307 } else if ( !CORBA::is_nil(theArg)) {
308 if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
309 myStream << "smeshObj_" << size_t(theArg);
311 myStream << theNotPublishedObjectName;
320 operator<<(SMESH::SMESH_Hypothesis_ptr theArg)
322 SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg);
323 if(aSObject->_is_nil() && !CORBA::is_nil(theArg))
324 myStream << "hyp_" << theArg->GetId();
332 operator<<(SMESH::SMESH_IDSource_ptr theArg)
334 if ( CORBA::is_nil( theArg ) )
335 return *this << "None";
336 SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg);
337 if(!aSObject->_is_nil())
339 return *this << aSObject;
341 if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theArg ))
343 return *this << filter;
345 if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theArg ))
347 SMESH::SMESH_Mesh_var mesh = theArg->GetMesh();
348 SMESH::long_array_var anElementsId = theArg->GetIDs();
349 SMESH::array_of_ElementType_var types = theArg->GetTypes();
350 SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL;
351 SALOMEDS::SObject_wrap meshSO = SMESH_Gen_i::ObjectToSObject(mesh);
352 if ( meshSO->_is_nil() ) // don't waste memory for dumping not published objects
353 return *this << mesh << ".GetIDSource([], " << type << ")";
355 return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
357 return *this << theNotPublishedObjectName;
362 operator<<(SMESH::FilterLibrary_i* theArg)
364 myStream<<"aFilterLibrary"<<theArg;
370 operator<<(SMESH::FilterManager_i* theArg)
372 myStream<<"aFilterManager";
378 operator<<(SMESH::Filter_i* theArg)
380 myStream<<"aFilter"<<theArg;
386 operator<<(SMESH::Functor_i* theArg)
389 FunctorType aFunctorType = theArg->GetFunctorType();
390 switch(aFunctorType) {
391 case FT_AspectRatio: myStream<< "aAspectRatio"; break;
392 case FT_AspectRatio3D: myStream<< "aAspectRatio3D"; break;
393 case FT_Warping: myStream<< "aWarping"; break;
394 case FT_MinimumAngle: myStream<< "aMinimumAngle"; break;
395 case FT_Taper: myStream<< "aTaper"; break;
396 case FT_Skew: myStream<< "aSkew"; break;
397 case FT_Area: myStream<< "aArea"; break;
398 case FT_Volume3D: myStream<< "aVolume3D"; break;
399 case FT_MaxElementLength2D: myStream<< "aMaxElementLength2D"; break;
400 case FT_MaxElementLength3D: myStream<< "aMaxElementLength3D"; break;
401 case FT_FreeBorders: myStream<< "aFreeBorders"; break;
402 case FT_FreeEdges: myStream<< "aFreeEdges"; break;
403 case FT_FreeNodes: myStream<< "aFreeNodes"; break;
404 case FT_FreeFaces: myStream<< "aFreeFaces"; break;
405 case FT_EqualNodes: myStream<< "aEqualNodes"; break;
406 case FT_EqualEdges: myStream<< "aEqualEdges"; break;
407 case FT_EqualFaces: myStream<< "aEqualFaces"; break;
408 case FT_EqualVolumes: myStream<< "aEqualVolumes"; break;
409 case FT_MultiConnection: myStream<< "aMultiConnection"; break;
410 case FT_MultiConnection2D: myStream<< "aMultiConnection2D"; break;
411 case FT_Length: myStream<< "aLength"; break;
412 case FT_Length2D: myStream<< "aLength2D"; break;
413 case FT_Length3D: myStream<< "aLength3D"; break;
414 case FT_Deflection2D: myStream<< "aDeflection2D"; break;
415 case FT_NodeConnectivityNumber:myStream<< "aNodeConnectivityNumber";break;
416 case FT_BelongToMeshGroup: myStream<< "aBelongToMeshGroup"; break;
417 case FT_BelongToGeom: myStream<< "aBelongToGeom"; break;
418 case FT_BelongToPlane: myStream<< "aBelongToPlane"; break;
419 case FT_BelongToCylinder: myStream<< "aBelongToCylinder"; break;
420 case FT_BelongToGenSurface: myStream<< "aBelongToGenSurface"; break;
421 case FT_LyingOnGeom: myStream<< "aLyingOnGeom"; break;
422 case FT_RangeOfIds: myStream<< "aRangeOfIds"; break;
423 case FT_BadOrientedVolume: myStream<< "aBadOrientedVolume"; break;
424 case FT_BareBorderVolume: myStream<< "aBareBorderVolume"; break;
425 case FT_BareBorderFace: myStream<< "aBareBorderFace"; break;
426 case FT_OverConstrainedVolume: myStream<< "aOverConstrainedVolume"; break;
427 case FT_OverConstrainedFace: myStream<< "aOverConstrainedFace"; break;
428 case FT_LinearOrQuadratic: myStream<< "aLinearOrQuadratic"; break;
429 case FT_GroupColor: myStream<< "aGroupColor"; break;
430 case FT_ElemGeomType: myStream<< "aElemGeomType"; break;
431 case FT_EntityType: myStream<< "aEntityType"; break;
432 case FT_CoplanarFaces: myStream<< "aCoplanarFaces"; break;
433 case FT_BallDiameter: myStream<< "aBallDiameter"; break;
434 case FT_ConnectedElements: myStream<< "aConnectedElements"; break;
435 case FT_LessThan: myStream<< "aLessThan"; break;
436 case FT_MoreThan: myStream<< "aMoreThan"; break;
437 case FT_EqualTo: myStream<< "aEqualTo"; break;
438 case FT_LogicalNOT: myStream<< "aLogicalNOT"; break;
439 case FT_LogicalAND: myStream<< "aLogicalAND"; break;
440 case FT_LogicalOR: myStream<< "aLogicalOR"; break;
441 case FT_Undefined: myStream<< "anUndefined"; break;
442 //default: -- commented to have a compilation warning
451 operator<<(SMESH::Measurements_i* theArg)
453 myStream<<"aMeasurements";
457 TPythonDump& TPythonDump:: operator<<(SMESH_Gen_i* theArg)
459 myStream << SMESHGenName(); return *this;
462 TPythonDump& TPythonDump::operator<<(SMESH_MeshEditor_i* theArg)
464 myStream << MeshEditorName() << "_" << ( theArg ? theArg->GetMeshId() : -1 ); return *this;
467 TPythonDump& TPythonDump::operator<<(const TCollection_AsciiString & theStr)
469 myStream << theStr; return *this;
472 TPythonDump& TPythonDump::operator<<(const SMESH::AxisStruct & theAxis)
474 *this << "SMESH.AxisStruct( "
475 << TVar( theAxis.x ) << ", "
476 << TVar( theAxis.y ) << ", "
477 << TVar( theAxis.z ) << ", "
478 << TVar( theAxis.vx ) << ", "
479 << TVar( theAxis.vy ) << ", "
480 << TVar( theAxis.vz ) << " )";
484 TPythonDump& TPythonDump::operator<<(const SMESH::DirStruct & theDir)
486 const SMESH::PointStruct & P = theDir.PS;
487 *this << "SMESH.DirStruct( SMESH.PointStruct ( "
488 << TVar( P.x ) << ", "
489 << TVar( P.y ) << ", "
490 << TVar( P.z ) << " ))";
494 TPythonDump& TPythonDump::operator<<(const SMESH::PointStruct & P)
496 *this << "SMESH.PointStruct ( "
497 << TVar( P.x ) << ", "
498 << TVar( P.y ) << ", "
499 << TVar( P.z ) << " )";
503 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups& theList)
505 DumpArray( theList, *this );
508 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups * theList)
510 DumpArray( *theList, *this );
513 TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGO& theList)
515 DumpArray( theList, *this );
518 TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGBO& theList)
520 DumpArray( theList, *this );
523 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfIDSources& theList)
525 DumpArray( theList, *this );
528 TPythonDump& TPythonDump::operator<<(const SMESH::submesh_array& theList)
530 DumpArray( theList, *this );
533 TPythonDump& TPythonDump::operator<<(const SMESH::ListOfHypothesis& theList)
535 DumpArray( theList, *this );
538 TPythonDump& TPythonDump::operator<<(const SMESH::CoincidentFreeBorders& theCFB)
540 // dump CoincidentFreeBorders as a list of lists, each enclosed list
541 // contains node IDs of a group of coincident free borders where
542 // each consequent triple of IDs describe a free border: (n1, n2, nLast)
543 // For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes
544 // two groups of coincident free borders, each group including two borders
547 for ( CORBA::ULong i = 0; i < theCFB.coincidentGroups.length(); ++i )
549 const SMESH::FreeBordersGroup& aGRP = theCFB.coincidentGroups[ i ];
550 if ( i ) myStream << ",";
552 for ( CORBA::ULong iP = 0; iP < aGRP.length(); ++iP )
554 const SMESH::FreeBorderPart& aPART = aGRP[ iP ];
555 if ( 0 <= aPART.border && aPART.border < (CORBA::Long)theCFB.borders.length() )
557 if ( iP ) myStream << ", ";
558 const SMESH::FreeBorder& aBRD = theCFB.borders[ aPART.border ];
559 myStream << aBRD.nodeIDs[ aPART.node1 ] << ",";
560 myStream << aBRD.nodeIDs[ aPART.node2 ] << ",";
561 myStream << aBRD.nodeIDs[ aPART.nodeLast ];
571 const char* TPythonDump::NotPublishedObjectName()
573 return theNotPublishedObjectName;
576 TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" );
577 TCollection_AsciiString myLongStringEnd ( "TPythonDump::LongStringEnd" );
579 //================================================================================
581 * \brief Return marker of long string literal beginning
582 * \param type - a name of functionality producing the string literal
583 * \retval TCollection_AsciiString - the marker string to be written into
584 * a raw python script
586 //================================================================================
588 TCollection_AsciiString TPythonDump::LongStringStart(const char* type)
592 (Standard_Integer) strlen(type) +
597 //================================================================================
599 * \brief Return marker of long string literal end
600 * \retval TCollection_AsciiString - the marker string to be written into
601 * a raw python script
603 //================================================================================
605 TCollection_AsciiString TPythonDump::LongStringEnd()
607 return myLongStringEnd;
610 //================================================================================
612 * \brief Cut out a long string literal from a string
613 * \param theText - text possibly containing string literals
614 * \param theFrom - position in the text to search from
615 * \param theLongString - the retrieved literal
616 * \param theStringType - a name of functionality produced the literal
617 * \retval bool - true if a string literal found
619 * The literal is removed from theText; theFrom points position right after
620 * the removed literal
622 //================================================================================
624 bool TPythonDump::CutoutLongString( TCollection_AsciiString & theText,
626 TCollection_AsciiString & theLongString,
627 TCollection_AsciiString & theStringType)
629 if ( theFrom < 1 || theFrom > theText.Length() )
632 // ...script \ beg marker \ \ type \ literal \ end marker \ script...
633 // "theText myLongStringStart7 Pattern!!! SALOME Mesh Pattern file myLongStringEndtextEnd"
634 // 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
637 theFrom = theText.Location( myLongStringStart, theFrom, theText.Length() ); // = 09
641 // find where literal begins
642 int literalBeg = theFrom + myLongStringStart.Length(); // = 26
643 char* typeLenStr = (char*) theText.ToCString() + literalBeg - 1; // = "7 Pattern!!! SALO...."
644 int typeLen = atoi ( typeLenStr ); // = 7
645 while ( *typeLenStr != ' ' ) { // look for ' ' after typeLen
646 literalBeg++; // 26 -> 27
649 literalBeg += typeLen + 1; // = 35
650 if ( literalBeg > theText.Length() )
653 // where literal ends (i.e. end marker begins)
654 int literalEnd = theText.Location( myLongStringEnd, literalBeg, theText.Length() ); // = 64
656 literalEnd = theText.Length();
659 theLongString = theText.SubString( literalBeg, literalEnd - 1); // "!!! SALOME Mesh Pattern file "
661 theStringType = theText.SubString( literalBeg - typeLen, literalBeg - 1 ); // "Pattern"
663 literalEnd += myLongStringEnd.Length(); // = 79
664 TCollection_AsciiString textEnd = theText.SubString( literalEnd, theText.Length() ); // "textE..."
665 theText = theText.SubString( 1, theFrom - 1 ) + textEnd;
670 void printException( const char* text )
673 std::cout << "Exception in SMESH_Gen_i::DumpPython(): " << text << std::endl;
677 //=======================================================================
678 //function : RemoveTabulation
680 //=======================================================================
681 void RemoveTabulation( TCollection_AsciiString& theScript )
683 std::string aString( theScript.ToCString() );
684 std::string::size_type aPos = 0;
685 while( aPos < aString.length() )
687 aPos = aString.find( "\n\t", aPos );
688 if( aPos == std::string::npos )
690 aString.replace( aPos, 2, "\n" );
693 theScript = aString.c_str();
697 //=======================================================================
698 //function : DumpPython
700 //=======================================================================
701 Engines::TMPFile* SMESH_Gen_i::DumpPython( CORBA::Boolean isPublished,
702 CORBA::Boolean isMultiFile,
703 CORBA::Boolean& isValidScript)
706 Kernel_Utils::Localizer loc;
708 SALOMEDS::Study_var aStudy = getStudyServant();
709 if (CORBA::is_nil(aStudy))
710 return new Engines::TMPFile(0);
712 CORBA::String_var compDataType = ComponentDataType();
713 SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
714 if (CORBA::is_nil(aSO))
715 return new Engines::TMPFile(0);
717 // Map study entries to object names
718 Resource_DataMapOfAsciiStringAsciiString aMap;
719 Resource_DataMapOfAsciiStringAsciiString aMapNames;
721 SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
722 for (Itr->InitEx(true); Itr->More(); Itr->Next()) {
723 SALOMEDS::SObject_wrap aValue = Itr->Value();
724 CORBA::String_var anID = aValue->GetID();
725 CORBA::String_var aName = aValue->GetName();
726 TCollection_AsciiString aGUIName ( (char*) aName.in() );
727 TCollection_AsciiString anEntry ( (char*) anID.in() );
728 if (aGUIName.Length() > 0) {
729 aMapNames.Bind( anEntry, aGUIName );
730 aMap.Bind( anEntry, aGUIName );
734 // Get trace of restored study
735 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
736 SALOMEDS::GenericAttribute_wrap anAttr =
737 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
739 SALOMEDS::AttributePythonObject_var pyAttr =
740 SALOMEDS::AttributePythonObject::_narrow(anAttr);
741 CORBA::String_var oldValue = pyAttr->GetObject();
742 TCollection_AsciiString aSavedTrace (oldValue.in());
744 // Add trace of API methods calls and replace study entries by names
745 TCollection_AsciiString aScript;
746 aScript += DumpPython_impl(aMap, aMapNames, isPublished, isMultiFile,
747 myIsHistoricalPythonDump, isValidScript, aSavedTrace);
749 int aLen = aScript.Length();
750 unsigned char* aBuffer = new unsigned char[aLen+1];
751 strcpy((char*)aBuffer, aScript.ToCString());
753 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
754 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
756 bool hasNotPublishedObjects = aScript.Location( SMESH::theNotPublishedObjectName, 1, aLen);
757 isValidScript = isValidScript && !hasNotPublishedObjects;
759 return aStreamFile._retn();
762 //=============================================================================
766 //=============================================================================
767 void SMESH_Gen_i::AddToPythonScript (const TCollection_AsciiString& theString)
769 if (myPythonScript.IsNull()) {
770 myPythonScript = new TColStd_HSequenceOfAsciiString;
772 myPythonScript->Append(theString);
775 //=============================================================================
777 * RemoveLastFromPythonScript
779 //=============================================================================
780 void SMESH_Gen_i::RemoveLastFromPythonScript()
782 if (!myPythonScript.IsNull()) {
783 int aLen = myPythonScript->Length();
784 myPythonScript->Remove(aLen);
788 //=======================================================================
789 //function : SavePython
791 //=======================================================================
792 void SMESH_Gen_i::SavePython()
794 // Dump trace of API methods calls
795 TCollection_AsciiString aScript = GetNewPythonLines();
797 // Check contents of PythonObject attribute
798 CORBA::String_var compDataType = ComponentDataType();
799 SALOMEDS::SObject_wrap aSO = getStudyServant()->FindComponent( compDataType.in() );
800 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
801 SALOMEDS::GenericAttribute_wrap anAttr =
802 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
804 SALOMEDS::AttributePythonObject_var pyAttr =
805 SALOMEDS::AttributePythonObject::_narrow(anAttr);
806 CORBA::String_var oldValue = pyAttr->GetObject();
807 TCollection_AsciiString oldScript (oldValue.in());
809 if (oldScript.Length() > 0) {
811 oldScript += aScript;
816 // Store in PythonObject attribute
817 pyAttr->SetObject(oldScript.ToCString(), 1);
819 // Clean trace of API methods calls
827 //=============================================================================
829 * FindEntries: Returns a sequence of start/end positions of entries in the string
831 //=============================================================================
832 Handle(TColStd_HSequenceOfInteger) FindEntries (TCollection_AsciiString& theString)
834 Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
835 Standard_Integer aLen = theString.Length();
836 Standard_Boolean isFound = Standard_False;
838 char* arr = (char*) theString.ToCString();
839 Standard_Integer i = 0, j;
844 if ( isdigit( c )) { //Is digit?
846 isFound = Standard_False;
847 while((j < aLen) && ( isdigit(c) || c == ':' )) { //Check if it is an entry
849 if(c == ':') isFound = Standard_True;
853 int prev = (i < 1) ? 0 : (int)arr[i - 1];
854 // to distinguish from a sketcher command:
855 // last char should be a digit, not ":",
856 // previous char should not be '"'.
857 if (arr[j-2] != ':' && prev != '"') {
858 aSeq->Append(i+1); // +1 because AsciiString starts from 1
872 //================================================================================
874 * \brief Make a string be a valid python name
875 * \param aName - a string to fix
876 * \retval bool - true if aName was not modified
878 //================================================================================
880 bool fixPythonName(TCollection_AsciiString & aName)
882 bool isValidName = true;
883 int nbUnderscore = 0;
885 // replace not allowed chars by underscore
886 const char* name = aName.ToCString();
887 for ( p = 0; name[p]; ++p ) {
888 if ( !isalnum( name[p] ) && name[p] != '_' )
890 if ( p == 0 || p+1 == aName.Length() || name[p-1] == '_')
892 aName.Remove( p+1, 1 ); // remove __ and _ from the start and the end
894 name = aName.ToCString();
898 aName.SetValue( p+1, '_');
904 // aName must not start with a digit
905 if ( aName.IsIntegerValue() ) {
906 aName.Insert( 1, 'a' );
909 // shorten names like CartesianParameters3D_400_400_400_1000000_1
910 const int nbAllowedUnderscore = 3; /* changed from 2 to 3 by an user request
911 posted to SALOME Forum */
912 if ( aName.Length() > 20 && nbUnderscore > nbAllowedUnderscore )
914 p = aName.Location( "_", 20, aName.Length());
921 //================================================================================
923 * \brief Return Python module names of available plug-ins.
925 //================================================================================
927 std::vector<std::string> getPluginNames()
929 std::vector<std::string> pluginNames;
930 std::vector< std::string > xmlPaths = SMESH_Gen::GetPluginXMLPaths();
931 LDOMParser xmlParser;
932 for ( size_t i = 0; i < xmlPaths.size(); ++i )
934 bool error = xmlParser.parse( xmlPaths[i].c_str() );
937 TCollection_AsciiString data;
938 INFOS( xmlParser.GetError(data) );
941 // <meshers-group name="Standard Meshers"
942 // resources="StdMeshers"
943 // idl-module="StdMeshers"
944 // server-lib="StdMeshersEngine"
945 // gui-lib="StdMeshersGUI">
946 LDOM_Document xmlDoc = xmlParser.getDocument();
947 LDOM_NodeList nodeList = xmlDoc.getElementsByTagName( "meshers-group" );
948 for ( int i = 0; i < nodeList.getLength(); ++i )
950 LDOM_Node node = nodeList.item( i );
951 LDOM_Element& elem = (LDOM_Element&) node;
952 LDOMString idlModule = elem.getAttribute( "idl-module" );
953 if ( strlen( idlModule.GetString() ) > 0 )
954 pluginNames.push_back( idlModule.GetString() );
961 //================================================================================
963 * \brief Creates a Dump Python script
964 * \param [in,out] theObjectNames - map of an entry to a study and python name
965 * \param [in] theNames - - map of an entry to a study name
966 * \param [in] isPublished - \c true if dump of object publication in study is needed
967 * \param [in] isMultiFile - \c true if dump of each module goes to a separate file
968 * \param [in] isHistoricalDump - \c true if removed object should be dumped
969 * \param [out] aValidScript - returns \c true if the returned script seems valid
970 * \param [in,out] theSavedTrace - the dump stored in the study. It's cleared to
971 * decrease memory usage.
972 * \return TCollection_AsciiString - the result dump script.
974 //================================================================================
976 TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
977 (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
978 Resource_DataMapOfAsciiStringAsciiString& theNames,
981 bool isHistoricalDump,
983 TCollection_AsciiString& theSavedTrace)
987 const TCollection_AsciiString aSmeshpy ( SMESH_2smeshpy::SmeshpyName() );
988 const TCollection_AsciiString aSMESHGen( SMESH_2smeshpy::GenName() );
989 const TCollection_AsciiString anOldGen ( SMESH::TPythonDump::SMESHGenName() );
990 const TCollection_AsciiString helper; // to comfortably append C strings to TCollection_AsciiString
991 const TCollection_AsciiString tab( isMultiFile ? "\t" : "" ), nt = helper + "\n" + tab;
992 TCollection_AsciiString optionalComment;
994 std::list< TCollection_AsciiString > lines; // lines of a script
995 std::list< TCollection_AsciiString >::iterator linesIt;
997 lines.push_back( aSMESHGen + " = smeshBuilder.New()" );
999 optionalComment = "#";
1000 lines.push_back( optionalComment + aSMESHGen + ".SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations:" );
1001 lines.push_back( " # multiples meshes built in parallel, complex and numerous mesh edition (performance)\n" );
1002 lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" );
1003 lines.push_back( helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()" );
1005 // Treat dump trace of restored study
1006 if (theSavedTrace.Length() > 0)
1008 linesIt = --lines.end();
1009 // Split theSavedTrace into lines
1010 int from = 1, end = theSavedTrace.Length(), to;
1011 while ( from < end && ( to = theSavedTrace.Location( "\n", from, end )))
1013 if ( theSavedTrace.ToCString()[from-1] == '\t' )
1016 lines.push_back( theSavedTrace.SubString( from, to - 1 ));
1019 // For the conversion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen
1020 // was replaces with "smeshgen" (==TPythonDump::SMESHGenName()).
1021 // Change "smesh" -> "smeshgen" in the trace saved before passage to smeshBuilder.py API
1023 theSavedTrace.Location( anOldGen + ".", 1, theSavedTrace.Length() );
1024 theSavedTrace.Clear();
1025 if ( !isNewVersion )
1027 const TCollection_AsciiString aSmeshCall ( "smesh." ), gen( "gen" );
1029 for ( ++linesIt; linesIt != lines.end(); ++linesIt )
1031 TCollection_AsciiString& aSavedLine = *linesIt;
1032 end = aSavedLine.Length(), from = 1;
1033 while ( from < end && ( beg = aSavedLine.Location( aSmeshCall, from, end )))
1035 char charBefore = ( beg == 1 ) ? ' ' : aSavedLine.Value( beg - 1 );
1036 if ( isspace( charBefore ) || charBefore == '=' ) { // "smesh." is not a part of a long word
1037 aSavedLine.Insert( beg + aSmeshCall.Length() - 1, gen );// "smesh" -> "smeshgen"
1038 end += gen.Length();
1040 from = beg + aSmeshCall.Length();
1046 // Add new dump trace of API methods calls to script lines
1047 if (!myPythonScript.IsNull())
1049 Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript;
1050 Standard_Integer istr, aLen = aPythonScript->Length();
1051 for (istr = 1; istr <= aLen; istr++)
1052 lines.push_back( aPythonScript->Value( istr ));
1055 // Convert IDL API calls into smeshBuilder.py API.
1056 // Some objects are wrapped with python classes and
1057 // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
1058 Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
1059 std::set< TCollection_AsciiString > aRemovedObjIDs;
1060 if ( !getenv("NO_2smeshpy_conversion"))
1061 SMESH_2smeshpy::ConvertScript( lines, anEntry2AccessorMethod,
1062 theObjectNames, aRemovedObjIDs,
1065 bool importGeom = false;
1066 GEOM::GEOM_Gen_ptr geom[2];
1067 for ( int isShaper = 0; isShaper < 2; ++isShaper )
1069 geom[ isShaper ] = GetGeomEngine( isShaper );
1070 if ( CORBA::is_nil( geom[ isShaper ]))
1072 // Add names of GEOM objects to theObjectNames to exclude same names of SMESH objects
1073 GEOM::string_array_var aGeomNames = geom[ isShaper ]->GetAllDumpNames();
1074 for ( CORBA::ULong ign = 0; ign < aGeomNames->length(); ign++) {
1075 TCollection_AsciiString aName = aGeomNames[ign].in();
1076 theObjectNames.Bind(aName, "1");
1080 TCollection_AsciiString anUpdatedScript;
1082 Resource_DataMapOfAsciiStringAsciiString mapRemoved;
1083 Resource_DataMapOfAsciiStringAsciiString mapEntries; // { entry: name } present in anUpdatedScript
1084 Standard_Integer objectCounter = 0;
1085 TCollection_AsciiString anEntry, aName, aGUIName, aBaseName("smeshObj_");
1087 std::string compDataType = ComponentDataType(); // SMESH module's data type
1088 SALOMEDS::SComponent_var smeshSO = getStudyServant()->FindComponent( compDataType.c_str() );
1089 CORBA::String_var smeshID = smeshSO->GetID();
1090 TCollection_AsciiString smeshEntry = smeshID.in();
1092 // Treat every script line and add it to anUpdatedScript
1093 for ( linesIt = lines.begin(); linesIt != lines.end(); ++linesIt )
1095 TCollection_AsciiString& aLine = *linesIt;
1096 anUpdatedScript += tab;
1098 //Replace characters used instead of quote marks to quote notebook variables
1100 while (( pos = aLine.Location( 1, SMESH::TVar::Quote(), pos, aLine.Length() )))
1101 aLine.SetValue( pos, '"' );
1103 // Find entries to be replaced by names
1104 Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aLine);
1105 const Standard_Integer aSeqLen = aSeq->Length();
1106 Standard_Integer aStart = 1;
1107 for (Standard_Integer i = 1; i <= aSeqLen; i += 2)
1109 if ( aStart < aSeq->Value(i) )
1110 anUpdatedScript += aLine.SubString( aStart, aSeq->Value(i) - 1 ); // line part before i-th entry
1111 anEntry = aLine.SubString( aSeq->Value(i), aSeq->Value(i + 1) );
1112 // is a GEOM object?
1113 CORBA::String_var geomName;
1114 if ( !CORBA::is_nil( geom[0] ))
1115 geomName = geom[0]->GetDumpName( anEntry.ToCString() );
1116 if (( !geomName.in() || !geomName.in()[0] ) && !CORBA::is_nil( geom[1] ))
1117 geomName = geom[1]->GetDumpName( anEntry.ToCString() );
1118 if ( !geomName.in() || !geomName.in()[0] ) {
1119 // is a SMESH object
1120 if ( theObjectNames.IsBound( anEntry )) {
1121 // The Object is in Study
1122 aName = theObjectNames.Find( anEntry );
1123 // check validity of aName
1124 bool isValidName = fixPythonName( aName );
1125 if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
1126 // diff objects have same name - make a new name by appending a digit
1127 TCollection_AsciiString aName2;
1128 Standard_Integer i = 0;
1130 aName2 = aName + "_" + ++i;
1131 } while (theObjectNames.IsBound(aName2) && anEntry != theObjectNames(aName2));
1133 isValidName = false;
1136 theObjectNames(anEntry) = aName;
1138 if ( aLine.Value(1) != '#' )
1139 mapEntries.Bind(anEntry, aName);
1143 if ( !anEntry.StartsWith( smeshEntry )) // not SMESH object
1145 aName = SMESH::TPythonDump::NotPublishedObjectName();
1151 aName = aBaseName + (++objectCounter);
1152 } while (theObjectNames.IsBound(aName));
1154 if ( !aRemovedObjIDs.count( anEntry ) && aLine.Value(1) != '#')
1155 mapRemoved.Bind(anEntry, aName);
1157 theObjectNames.Bind(anEntry, aName);
1160 theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
1164 aName = geomName.in();
1167 anUpdatedScript += aName;
1168 aStart = aSeq->Value(i + 1) + 1;
1170 } // loop on entries within aLine
1173 anUpdatedScript += aLine;
1174 else if ( aSeq->Value( aSeqLen ) < aLine.Length() )
1175 anUpdatedScript += aLine.SubString( aSeq->Value(aSeqLen) + 1, aLine.Length() );
1177 anUpdatedScript += '\n';
1180 // Make an initial part of aSript
1182 TCollection_AsciiString initPart = "import ";
1184 initPart += "salome, ";
1185 initPart += " SMESH, SALOMEDS\n";
1186 initPart += "from salome.smesh import smeshBuilder\n";
1187 if ( importGeom && isMultiFile )
1189 initPart += ("\n## import GEOM dump file ## \n"
1190 "import string, os, sys, re, inspect\n"
1191 "thisFile = inspect.getfile( inspect.currentframe() )\n"
1192 "thisModule = os.path.splitext( os.path.basename( thisFile ))[0]\n"
1193 "sys.path.insert( 0, os.path.dirname( thisFile ))\n"
1194 "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",thisModule)+\" import *\")\n\n");
1196 // import python files corresponding to plugins if they are used in anUpdatedScript
1198 //TCollection_AsciiString importStr;
1199 std::vector<std::string> pluginNames = getPluginNames();
1200 for ( size_t i = 0; i < pluginNames.size(); ++i )
1202 // Convert access to plugin members:
1203 // e.g. StdMeshers.QUAD_REDUCED -> smeshBuilder.QUAD_REDUCED
1204 TCollection_AsciiString pluginAccess = (pluginNames[i] + ".").c_str() ;
1205 int iFrom = 1, iPos;
1206 while (( iPos = anUpdatedScript.Location( pluginAccess, iFrom, anUpdatedScript.Length() )))
1208 //anUpdatedScript.Insert( iPos + pluginNames[i].size(), "Builder" );
1209 anUpdatedScript.Remove( iPos, pluginNames[i].size() );
1210 anUpdatedScript.Insert( iPos, "smeshBuilder" );
1211 iFrom = iPos - pluginNames[i].size() + 12;
1213 // if any plugin member is used, import the plugin
1215 // importStr += ( helper + "\n" "from salome." + pluginNames[i].c_str() +
1216 // " import " + pluginNames[i].c_str() +"Builder" );
1218 // if ( !importStr.IsEmpty() )
1219 // initPart += importStr + "\n";
1223 initPart += "def RebuildData():";
1226 anUpdatedScript.Prepend( initPart );
1228 // Make a final part of aScript
1230 // Dump object removal
1231 TCollection_AsciiString removeObjPart;
1232 if ( !mapRemoved.IsEmpty() ) {
1233 removeObjPart += nt + "## some objects were removed";
1234 removeObjPart += nt + "aStudyBuilder = salome.myStudy.NewBuilder()";
1235 Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapRemovedIt;
1236 for ( mapRemovedIt.Initialize( mapRemoved ); mapRemovedIt.More(); mapRemovedIt.Next() ) {
1237 aName = mapRemovedIt.Value(); // python name
1238 anEntry = mapRemovedIt.Key();
1239 removeObjPart += nt + "SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR(";
1240 removeObjPart += aName;
1241 // for object wrapped by class of smeshBuilder.py
1242 if ( anEntry2AccessorMethod.IsBound( anEntry ) )
1243 removeObjPart += helper + "." + anEntry2AccessorMethod( anEntry );
1244 removeObjPart += helper + "))" + nt + "if SO: aStudyBuilder.RemoveObjectWithChildren(SO)";
1249 TCollection_AsciiString setNamePart;
1250 Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapEntriesIt;
1251 for ( mapEntriesIt.Initialize( mapEntries ); mapEntriesIt.More(); mapEntriesIt.Next() )
1253 anEntry = mapEntriesIt.Key();
1254 aName = mapEntriesIt.Value(); // python name
1255 if ( theNames.IsBound( anEntry ))
1257 aGUIName = theNames.Find(anEntry);
1258 aGUIName.RemoveAll('\''); // remove a quote from a name (issue 22360)
1259 setNamePart += nt + aSMESHGen + ".SetName(" + aName;
1260 if ( anEntry2AccessorMethod.IsBound( anEntry ) )
1261 setNamePart += helper + "." + anEntry2AccessorMethod( anEntry );
1262 setNamePart += helper + ", '" + aGUIName + "')";
1265 if ( !setNamePart.IsEmpty() )
1267 setNamePart.Insert( 1, nt + "## Set names of Mesh objects" );
1270 // Store visual properties of displayed objects
1272 TCollection_AsciiString visualPropertiesPart;
1275 //Output the script that sets up the visual parameters.
1276 CORBA::String_var compDataType = ComponentDataType();
1277 CORBA::String_var script = getStudyServant()->GetDefaultScript( compDataType.in(), tab.ToCString() );
1278 if ( script.in() && script.in()[0] ) {
1279 visualPropertiesPart += nt + "### Store presentation parameters of displayed objects\n";
1280 visualPropertiesPart += script.in();
1284 anUpdatedScript += removeObjPart + '\n' + setNamePart + '\n' + visualPropertiesPart;
1291 "\nif __name__ == '__main__':"
1292 "\n\tSMESH_RebuildData = RebuildData"
1293 "\n\texec('import '+re.sub('SMESH$','GEOM',thisModule)+' as GEOM_dump')"
1294 "\n\tGEOM_dump.RebuildData()"
1295 "\n\texec('from '+re.sub('SMESH$','GEOM',thisModule)+' import * ')"
1296 "\n\tSMESH_RebuildData()";
1298 anUpdatedScript += "\n";
1300 // no need now as we use 'tab' and 'nt' variables depending on isMultiFile
1301 // if( !isMultiFile ) // remove unnecessary tabulation
1302 // RemoveTabulation( anUpdatedScript );
1304 // -----------------------------------------------------------------
1305 // put string literals describing patterns into separate functions
1306 // -----------------------------------------------------------------
1308 TCollection_AsciiString aLongString, aFunctionType;
1310 std::set< std::string > functionNameSet;
1311 while ( SMESH::TPythonDump::CutoutLongString( anUpdatedScript, where, aLongString, aFunctionType ))
1313 // make a python string literal
1314 aLongString.Prepend(":\n\treturn '''\n");
1315 aLongString += "\n\t'''\n\tpass\n";
1317 TCollection_AsciiString functionName;
1319 // check if the function returning this literal is already defined
1320 int posAlready = anUpdatedScript.Location( aLongString, where, anUpdatedScript.Length() );
1321 if ( posAlready ) // already defined
1323 // find the function name
1324 int functBeg = posAlready;
1325 char* script = (char*) anUpdatedScript.ToCString() + posAlready - 1; // look at ":" after "def function()"
1326 while ( *script != ' ' ) {
1330 functBeg++; // do not take ' '
1331 posAlready--; // do not take ':'
1332 functionName = anUpdatedScript.SubString( functBeg, posAlready );
1334 else // not defined yet
1336 // find a unique function name
1337 fixPythonName( aFunctionType );
1338 Standard_Integer nb = 0;
1339 do functionName = aFunctionType + "_" + ( nb++ ) + "()";
1340 while ( !functionNameSet.insert( functionName.ToCString() ).second );
1343 TCollection_AsciiString funDef = helper + "def " + functionName + aLongString;
1346 anUpdatedScript += helper + "\n\n" + funDef;
1351 anUpdatedScript.Insert( 1, funDef);
1352 where += funDef.Length();
1355 anUpdatedScript.InsertBefore( where, functionName ); // call function
1358 aValidScript = true;
1360 return anUpdatedScript;
1362 SMESH_CATCH( SMESH::printException );
1364 aValidScript = false;
1368 //=============================================================================
1372 //=============================================================================
1373 TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines()
1375 TCollection_AsciiString aScript;
1377 // Dump trace of API methods calls
1378 if (!myPythonScript.IsNull()) {
1379 Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript;
1380 Standard_Integer istr, aLen = aPythonScript->Length();
1381 for (istr = 1; istr <= aLen; istr++) {
1383 aScript += aPythonScript->Value(istr);
1391 //=============================================================================
1395 //=============================================================================
1396 void SMESH_Gen_i::CleanPythonTrace()
1398 TCollection_AsciiString aScript;
1400 // Clean trace of API methods calls
1401 if (!myPythonScript.IsNull()) {
1402 myPythonScript->Clear();
1406 //================================================================================
1408 * \brief Count inclusions of a string in a raw Python dump script
1410 //================================================================================
1412 int SMESH_Gen_i::CountInPyDump(const TCollection_AsciiString& theText)
1416 SALOMEDS::Study_var aStudy = getStudyServant();
1417 if ( CORBA::is_nil( aStudy ))
1420 SMESH_Gen_i* me = GetSMESHGen();
1421 CORBA::String_var compDataType = me->ComponentDataType();
1422 SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
1423 if ( CORBA::is_nil( aSO ))
1426 // Trace saved in the study
1427 SALOMEDS::GenericAttribute_wrap attr;
1428 if ( aSO->FindAttribute( attr.inout(), "AttributePythonObject" ))
1430 SALOMEDS::AttributePythonObject_var pyAttr =
1431 SALOMEDS::AttributePythonObject::_narrow( attr );
1432 CORBA::String_var script = pyAttr->GetObject();
1433 for ( const char * scriptPos = script.in(); true; ++scriptPos )
1434 if (( scriptPos = strstr( scriptPos, theText.ToCString() )))
1440 // New python commands
1441 if ( !me->myPythonScript.IsNull() )
1443 const int nbLines = me->myPythonScript->Length();
1444 for ( int i = 1; i <= nbLines; ++i )
1446 const TCollection_AsciiString& line = me->myPythonScript->Value( i );
1447 for ( int loc = 1; loc <= line.Length(); ++loc )
1448 if (( loc = line.Location( theText, loc, line.Length() )))