1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_DumpPython.cc
24 // Author : Alexey PETROV
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_PrsObject_i.hh"
31 #include "VISU_Prs3d_i.hh"
32 #include "VISU_Mesh_i.hh"
33 #include "VISU_ScalarMap_i.hh"
34 #include "VISU_IsoSurfaces_i.hh"
35 #include "VISU_DeformedShape_i.hh"
36 #include "VISU_CutPlanes_i.hh"
37 #include "VISU_CutLines_i.hh"
38 #include "VISU_Vectors_i.hh"
39 #include "VISU_StreamLines_i.hh"
40 #include "VISU_Table_i.hh"
42 #include "utilities.h"
49 #include <qfileinfo.h>
56 static std::string PREFIX(" ");
58 typedef std::map<std::string,std::string> TName2EntryMap;
59 typedef std::map<std::string,std::string> TEntry2NameMap;
63 GenerateName(std::string theName,
64 SALOMEDS::SObject_ptr theSObject,
65 TName2EntryMap& theName2EntryMap,
66 TEntry2NameMap& theEntry2NameMap,
69 if(theName2EntryMap.find(theName) != theName2EntryMap.end()){
70 theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix);
72 CORBA::String_var anID = theSObject->GetID();
73 theName2EntryMap[theName] = anID.in();
74 theEntry2NameMap[anID.in()] = theName;
75 //cout<<"GenerateName - "<<theName<<" => "<<anID.in()<<endl;
81 struct TReplacePredicate{
82 bool operator()(char theChar) const
84 return !(isdigit(theChar) || isalpha(theChar) || theChar == '_');
90 GetName(SALOMEDS::SObject_ptr theSObject)
92 CORBA::String_var aString = theSObject->GetName();
94 std::string aName = QString(aString.in()).simplifyWhiteSpace().latin1();
96 //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_');
97 replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_');
99 if ( isdigit( aName[0] ))
100 aName.insert( 0, 1, 'a' );
107 GenerateName(SALOMEDS::SObject_ptr theSObject,
108 TName2EntryMap& theName2EntryMap,
109 TEntry2NameMap& theEntry2NameMap)
111 std::string aName = GetName(theSObject);
113 return GenerateName(aName,theSObject,theName2EntryMap,theEntry2NameMap,'X');
117 //===========================================================================
118 typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy,
119 CORBA::Boolean theIsPublished,
120 CORBA::Boolean& theIsValidScript,
121 SALOMEDS::SObject_ptr theSObject,
122 std::ostream& theStr,
123 TName2EntryMap& theName2EntryMap,
124 TEntry2NameMap& theEntry2NameMap,
125 std::string theArgumentName,
126 std::string thePrefix);
130 DumpToPython(SALOMEDS::Study_ptr theStudy,
131 CORBA::Boolean theIsPublished,
132 CORBA::Boolean& theIsValidScript,
133 SALOMEDS::SObject_ptr theSObject,
134 std::ostream& theStr,
135 TName2EntryMap& theName2EntryMap,
136 TEntry2NameMap& theEntry2NameMap,
137 std::string theArgumentName,
138 std::string thePrefix);
141 //===========================================================================
143 ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
144 VISU::ScalarMap_i* theServant,
145 std::ostream& theStr,
146 std::string& theName,
147 const std::string& theConstructorName,
148 const std::string& theArgumentName,
149 std::string thePrefix)
152 switch(theServant->GetEntity()){
154 aParam = "VISU.NODE";
157 aParam = "VISU.EDGE";
160 aParam = "VISU.FACE";
163 aParam = "VISU.CELL";
167 theStr<<thePrefix<<theName<<" = aVisu."<<theConstructorName<<"("<<theArgumentName<<
168 ",'"<<theServant->GetMeshName()<<"'"<<
170 ",'"<<theServant->GetFieldName()<<"'"<<
171 ","<<theServant->GetIteration()<<
174 theStr<<thePrefix<<"if "<<theName<<":"<<endl;
177 theStr<<thePrefix<<"aName2ObjectMap['"<<theName<<"'] = "<<theName<<endl;
179 theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
181 switch(theServant->GetScaling()){
183 aParam = "VISU.LINEAR";
186 aParam = "VISU.LOGARITHMIC";
189 theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
190 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<","<<theServant->GetMax()<<")"<<endl;
192 switch(theServant->GetBarOrientation()){
193 case ScalarMap::HORIZONTAL:
194 aParam = "VISU.ScalarMap.HORIZONTAL";
196 case ScalarMap::VERTICAL:
197 aParam = "VISU.ScalarMap.VERTICAL";
200 theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
202 theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<","<<theServant->GetPosY()<<")"<<endl;
203 theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<","<<theServant->GetHeight()<<")"<<endl;
204 theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
205 theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
206 theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
212 //===========================================================================
214 DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
215 VISU::DeformedShape_i* theServant,
216 std::ostream& theStr,
217 std::string& theName,
218 const std::string& theConstructorName,
219 const std::string& theArgumentName,
220 std::string thePrefix)
222 thePrefix = ScalarMapToPython(theSObject,theServant,theStr,theName,theConstructorName,theArgumentName,thePrefix);
223 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
224 theStr<<thePrefix<<theName<<".ShowColored("<<theServant->IsColored()<<")"<<endl;
225 SALOMEDS::Color aColor = theServant->GetColor();
226 theStr<<thePrefix<<theName<<".SetColor(SALOMEDS.Color("<<
227 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
232 //===========================================================================
234 void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
235 CORBA::Boolean theIsPublished,
236 CORBA::Boolean& theIsValidScript,
237 SALOMEDS::SObject_ptr theSObject,
238 std::ostream& theStr,
239 TName2EntryMap& theName2EntryMap,
240 TEntry2NameMap& theEntry2NameMap,
241 std::string theArgumentName,
242 std::string thePrefix);
244 //===========================================================================
245 template<class TTableAttr>
247 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
248 CORBA::Boolean theIsPublished,
249 CORBA::Boolean& theIsValidScript,
250 SALOMEDS::SObject_ptr theSObject,
251 TTableAttr theTableAttr,
252 const std::string& theAttrName,
253 std::ostream& theStr,
254 TName2EntryMap& theName2EntryMap,
255 TEntry2NameMap& theEntry2NameMap,
256 std::string theArgumentName,
257 std::string thePrefix)
259 SALOMEDS::GenericAttribute_var anAttr;
260 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
261 if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){
262 SALOMEDS::AttributeComment_var aComment =
263 SALOMEDS::AttributeComment::_narrow(anAttr);
264 CORBA::String_var aValue = aComment->Value();
265 Storable::TRestoringMap aMap;
266 Storable::StrToMap(aValue.in(),aMap);
268 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
270 if(strcmp(aMethodName.latin1(),"ImportTables") == 0){
276 std::string aSObjectName = GetName(theSObject);
277 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
278 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
281 std::string aName = "aTableAttr";
282 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
283 aSObjectName<<",'"<<theAttrName<<"')"<<endl;
285 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
286 std::string aPrefix = thePrefix;
289 CORBA::String_var aString = theTableAttr->GetTitle();
290 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
292 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
293 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
295 CORBA::Long aNbRows = theTableAttr->GetNbRows();
297 // push values and their indices into streams
298 strstream values, rows, columns;
300 for(CORBA::Long i = 1; i <= aNbColumns; i++){
301 for(CORBA::Long j = aNbRows; j > 0; j--){
302 if(theTableAttr->HasValue(j,i)){
303 values << comma << theTableAttr->GetValue(j,i);
305 columns << comma << i;
311 // push titles and units into streams
312 strstream rowUnits, rowTitles, colTitles;
313 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
314 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
316 for(CORBA::Long j = 1; j <= aNbRows; j++){
317 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
318 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
322 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
324 for(CORBA::Long j = 1; j <= aNbColumns; j++){
325 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
335 // write FillTable command
336 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
337 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
338 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
339 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
340 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
341 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
342 theStr<< thePrefix << "visu.FillTable( "
344 << aName << "_values, "
345 << aName << "_rows, "
346 << aName << "_columns, "
347 << aName << "_rTitles, "
348 << aName << "_rUnits, "
349 << aName << "_cTitles )" << endl;
351 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
353 std::string aName = "aTable";
354 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
355 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
356 theArgumentName = aName;
358 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
359 std::string aPrefix2 = thePrefix + PREFIX;
361 DumpChildrenToPython(theStudy,
371 theStr<<aPrefix2<<"pass"<<endl<<endl;
374 theStr<<thePrefix<<"pass"<<endl<<endl;
375 theStr<<aPrefix<<"pass"<<endl<<endl;
379 //===========================================================================
381 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
382 CORBA::Boolean theIsPublished,
383 CORBA::Boolean& theIsValidScript,
384 SALOMEDS::SObject_ptr theSObject,
385 std::ostream& theStr,
386 TName2EntryMap& theName2EntryMap,
387 TEntry2NameMap& theEntry2NameMap,
388 std::string theArgumentName,
389 std::string thePrefix)
391 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
392 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
393 SALOMEDS::SObject_var aSObject = aChildItet->Value();
394 DumpToPython(theStudy,
407 //===========================================================================
409 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
410 CORBA::Boolean theIsPublished,
411 CORBA::Boolean& theIsValidScript,
412 SALOMEDS::SObject_ptr theSObject,
413 std::ostream& theStr,
414 TName2EntryMap& theName2EntryMap,
415 TEntry2NameMap& theEntry2NameMap,
416 std::string theArgumentName,
417 std::string thePrefix)
419 SALOMEDS::GenericAttribute_var anAttr;
420 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
421 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
422 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
424 TableAttrToPython(theStudy,
429 "AttributeTableOfInteger",
436 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
437 SALOMEDS::AttributeTableOfReal_var aTableAttr =
438 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
440 TableAttrToPython(theStudy,
445 "AttributeTableOfReal",
455 //===========================================================================
457 DumpToPython(SALOMEDS::Study_ptr theStudy,
458 CORBA::Boolean theIsPublished,
459 CORBA::Boolean& theIsValidScript,
460 SALOMEDS::SObject_ptr theSObject,
461 std::ostream& theStr,
462 TName2EntryMap& theName2EntryMap,
463 TEntry2NameMap& theEntry2NameMap,
464 std::string theArgumentName,
465 std::string thePrefix)
467 std::string aName = GetName(theSObject);
471 CORBA::Object_var anObj = SObjectToObject(theSObject);
472 if(!CORBA::is_nil(anObj)){
473 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
474 if(!CORBA::is_nil(aBase)){
475 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
476 CORBA::String_var anID = theSObject->GetID();
478 VISU::VISUType aType = aBase->GetType();
481 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
482 std::string aFileName = aServant->GetFileName();
483 Result_i::ECreationId anId = aServant->GetCreationId();
484 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
486 case Result_i::eImportFile:
487 theStr<<thePrefix<<aName<<" = aVisu.ImportFile('"<<aFileName<<"')"<<endl;
489 case Result_i::eCopyAndImportFile:
490 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
494 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
497 theArgumentName = aName;
498 DumpChildrenToPython(theStudy,
508 theStr<<thePrefix<<"pass"<<endl<<endl;
510 SALOMEDS::SObject_var aRefSObj;
511 if(theSObject->FindSubObject(1,aRefSObj)){
512 SALOMEDS::SObject_var aTargetRefSObj;
513 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
514 CORBA::String_var aString = aTargetRefSObj->GetName();
515 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
516 theStr<<thePrefix<<"if aSObject:"<<endl;
518 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
519 theStr<<thePrefix<<"if anObject:"<<endl;
520 std::string aPrefix1 = thePrefix;
524 case Result_i::eImportMed:
525 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
527 case Result_i::eImportMedField:
528 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
532 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
533 std::string aPrefix2 = thePrefix;
536 theArgumentName = aName;
537 DumpChildrenToPython(theStudy,
547 theStr<<thePrefix<<"pass"<<endl<<endl;
548 theStr<<aPrefix2<<"pass"<<endl<<endl;
549 theStr<<aPrefix1<<"pass"<<endl<<endl;
556 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
557 VISU::Entity anEntity = aServant->GetEntity();
558 const std::string& aSubMeshName = aServant->GetSubMeshName();
563 aParam = "VISU.NODE";
566 aParam = "VISU.EDGE";
569 aParam = "VISU.FACE";
572 aParam = "VISU.CELL";
576 if(aSubMeshName == "")
577 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
578 ",'"<<aServant->GetMeshName()<<"'"<<
582 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
583 ",'"<<aServant->GetMeshName()<<"'"<<
585 ",'"<<aSubMeshName<<"'"<<
588 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
589 ",'"<<aServant->GetMeshName()<<"'"<<
590 ",'"<<aSubMeshName<<"'"<<
593 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
596 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
598 SALOMEDS::Color aColor;
599 aColor = aServant->GetCellColor();
600 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
601 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
603 aColor = aServant->GetNodeColor();
604 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
605 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
607 aColor = aServant->GetLinkColor();
608 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
609 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
612 switch(aServant->GetPresentationType()){
614 aParam = "VISU.POINT";
617 aParam = "VISU.WIREFRAME";
620 aParam = "VISU.SHADED";
623 aParam = "VISU.INSIDEFRAME";
626 aParam = "VISU.SURFACEFRAME";
629 aParam = "VISU.SHRINK";
632 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
635 DumpChildrenToPython(theStudy,
645 theStr<<thePrefix<<"pass"<<endl<<endl;
649 case VISU::TSCALARMAP:
650 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
651 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"ScalarMapOnField",theArgumentName,thePrefix);
652 theStr<<thePrefix<<"pass"<<endl<<endl;
655 case VISU::TDEFORMEDSHAPE:
656 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
657 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"DeformedShapeOnField",theArgumentName,thePrefix);
658 theStr<<thePrefix<<"pass"<<endl<<endl;
661 case VISU::TSTREAMLINES:
662 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
663 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"StreamLinesOnField",theArgumentName,thePrefix);
666 switch(aServant->GetDirection()){
667 case StreamLines::FORWARD:
668 aParam = "VISU.StreamLines.FORWARD";
670 case StreamLines::BACKWARD:
671 aParam = "VISU.StreamLines.BACKWARD";
673 case StreamLines::BOTH:
674 aParam = "VISU.StreamLines.BOTH";
678 theStr<<thePrefix<<"aPrs3d = None"<<endl;
679 VISU::Prs3d_var aPrs3d = aServant->GetSource();
680 if(!CORBA::is_nil(aPrs3d)){
681 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
682 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
683 CORBA::String_var anID = aSObject->GetID();
684 std::string anArg = theEntry2NameMap[anID.in()];
685 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
687 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
691 theStr<<thePrefix<<aName<<".SetParams("<<
692 aServant->GetIntegrationStep()<<","<<
693 aServant->GetPropagationTime()<<","<<
694 aServant->GetStepLength()<<","<<
696 aServant->GetUsedPoints()<<","<<
700 theStr<<thePrefix<<"pass"<<endl<<endl;
704 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
705 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"VectorsOnField",theArgumentName,thePrefix);
707 theStr<<thePrefix<<aName<<".SetLineWidth("<<aServant->GetLineWidth()<<")"<<endl;
710 switch(aServant->GetGlyphType()){
712 aParam = "VISU.Vectors.ARROW";
715 aParam = "VISU.Vectors.CONE2";
718 aParam = "VISU.Vectors.CONE6";
721 aParam = "VISU.Vectors.NONE";
724 theStr<<thePrefix<<aName<<".SetGlyphType("<<aParam<<")"<<endl;
726 switch(aServant->GetGlyphPos()){
727 case Vectors::CENTER:
728 aParam = "VISU.Vectors.CENTER";
731 aParam = "VISU.Vectors.TAIL";
734 aParam = "VISU.Vectors.HEAD";
737 theStr<<thePrefix<<aName<<".SetGlyphPos("<<aParam<<")"<<endl;
739 theStr<<thePrefix<<"pass"<<endl<<endl;
742 case VISU::TISOSURFACE:
743 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
744 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"IsoSurfacesOnField",theArgumentName,thePrefix);
745 theStr<<thePrefix<<aName<<".SetNbSurfaces("<<aServant->GetNbSurfaces()<<")"<<endl;
746 theStr<<thePrefix<<"pass"<<endl<<endl;
749 case VISU::TCUTPLANES:
750 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
751 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutPlanesOnField",theArgumentName,thePrefix);
754 switch(aServant->GetOrientationType()){
756 aParam = "VISU.CutPlanes.XY";
759 aParam = "VISU.CutPlanes.YZ";
762 aParam = "VISU.CutPlanes.ZX";
765 theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
767 theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
768 CORBA::Long aNbPlanes = aServant->GetNbPlanes();
769 theStr<<thePrefix<<aName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
771 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
772 if(!aServant->IsDefault(anId))
773 theStr<<thePrefix<<aName<<".SetPlanePosition("<<anId<<","<<aServant->GetPlanePosition(anId)<<")"<<endl;
776 theStr<<thePrefix<<"pass"<<endl<<endl;
779 case VISU::TCUTLINES:
780 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
781 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutLinesOnField",theArgumentName,thePrefix);
784 switch(aServant->GetOrientationType()){
786 aParam = "VISU.CutPlanes.XY";
789 aParam = "VISU.CutPlanes.YZ";
792 aParam = "VISU.CutPlanes.ZX";
795 theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
797 switch(aServant->GetOrientationType2()){
799 aParam = "VISU.CutPlanes.XY";
802 aParam = "VISU.CutPlanes.YZ";
805 aParam = "VISU.CutPlanes.ZX";
808 theStr<<thePrefix<<aName<<".SetOrientation2("<<aParam<<","<<aServant->GetRotateX2()<<","<<aServant->GetRotateY2()<<")"<<endl;
810 theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
811 theStr<<thePrefix<<aName<<".SetDisplacement2("<<aServant->GetDisplacement2()<<")"<<endl;
813 if(!aServant->IsDefault())
814 theStr<<thePrefix<<aName<<".SetBasePlanePosition("<<aServant->GetBasePlanePosition()<<")"<<endl;
816 CORBA::Long aNbLines = aServant->GetNbLines();
817 theStr<<thePrefix<<aName<<".SetNbLines("<<aNbLines<<")"<<endl;
818 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
819 if(!aServant->IsDefaultPosition(anId))
820 theStr<<thePrefix<<aName<<".SetLinePosition("<<anId<<","<<aServant->GetLinePosition(anId)<<")"<<endl;
825 theArgumentName = aName;
826 DumpChildrenToPython(theStudy,
836 theStr<<thePrefix<<"pass"<<endl<<endl;
840 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
842 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve(" <<
843 theArgumentName<< // table
844 ","<<aServant->GetHRow()<< // H row
845 ","<<aServant->GetVRow()<< // V row
846 ",'"<<aServant->GetTitle()<<"'"; // title
847 SALOMEDS::Color aColor = aServant->GetColor();
848 theStr << ",SALOMEDS.Color("<<
849 aColor.R<<","<<aColor.G<<","<<aColor.B<<")"; // color
852 switch(aServant->GetMarker()){
853 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
854 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
855 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
856 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
857 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
858 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
859 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
860 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
861 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
862 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
864 theStr<<","<<aParam; // marker
866 switch(aServant->GetLine()){
867 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
868 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
869 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
870 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
871 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
872 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
874 theStr<<","<<aParam<<","<<aServant->GetLineWidth()<<")"<<endl; // line type,width
878 if(Table_i* aServant = dynamic_cast<Table_i*>(GetServant(anObj).in())){
879 SALOMEDS::SObject_var aSObject = aServant->GetSObject();
880 SALOMEDS::GenericAttribute_var anAttr;
881 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
882 using namespace SALOMEDS;
883 AttributeComment_var aComment = AttributeComment::_narrow(anAttr);
884 CORBA::String_var aValue = aComment->Value();
885 Storable::TRestoringMap aMap;
886 Storable::StrToMap(aValue.in(),aMap);
888 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
890 if(strcmp(aSourceId.latin1(),"CutLines") == 0){
891 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
894 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
895 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
896 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
897 theStr<<thePrefix<<"if aSObject:"<<endl;
898 std::string aPrefix = thePrefix;
901 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
902 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
905 theArgumentName = aName;
906 DumpChildrenToPython(theStudy,
916 theStr<<thePrefix<<"pass"<<endl<<endl;
917 theStr<<aPrefix<<"pass"<<endl<<endl;
918 }else if(strcmp(aSourceId.latin1(),"TableFile") == 0){
919 CORBA::Short aTag = theSObject->Tag();
920 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
921 theStr<<thePrefix<<"if anIsFound:"<<endl;
924 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
925 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
928 theArgumentName = aName;
929 DumpChildrenToPython(theStudy,
939 theStr<<thePrefix<<"pass"<<endl<<endl;
940 }else if(strcmp(aSourceId.latin1(),"TableAttr") == 0){
941 theArgumentName = aName;
942 DumpTableAttrToPython(theStudy,
959 SALOMEDS::GenericAttribute_var anAttr;
960 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
961 SALOMEDS::AttributeComment_var aComment =
962 SALOMEDS::AttributeComment::_narrow(anAttr);
963 CORBA::String_var aValue = aComment->Value();
964 Storable::TRestoringMap aMap;
965 Storable::StrToMap(aValue.in(),aMap);
967 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
969 if(strcmp(aTypeName.latin1(),"ImportTables") == 0){
970 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
972 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
973 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.latin1()<<"')"<<endl;
974 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
977 theArgumentName = aName;
978 DumpChildrenToPython(theStudy,
988 theStr<<thePrefix<<"pass"<<endl<<endl;
991 }else if(strcmp(aTypeName.latin1(),"VIEW3D") == 0){
992 std::string aName = GetName(theSObject);
993 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
995 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
998 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
999 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1001 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeComment')"<<endl;
1002 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1004 theStr<<thePrefix<<"pass"<<endl<<endl;
1009 DumpTableAttrToPython(theStudy,
1021 DumpChildrenToPython(theStudy,
1033 //===========================================================================
1035 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1036 CORBA::Boolean theIsPublished,
1037 CORBA::Boolean& theIsValidScript,
1038 SALOMEDS::SObject_ptr theSObject,
1039 std::ostream& theStr,
1040 TName2EntryMap& theName2EntryMap,
1041 TEntry2NameMap& theEntry2NameMap,
1042 std::string theArgumentName,
1043 std::string thePrefix)
1045 SALOMEDS::SObject_var aTargetRefSObj;
1046 if(theSObject->ReferencedObject(aTargetRefSObj)){
1047 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1048 if(CORBA::is_nil(anObj))
1051 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1052 if(CORBA::is_nil(aBase))
1055 if(aBase->GetType() == VISU::TCURVE){
1056 CORBA::String_var anID = aTargetRefSObj->GetID();
1057 std::string anArg = theEntry2NameMap[anID.in()];
1058 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1059 thePrefix += PREFIX;
1060 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1061 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1062 theStr<<thePrefix<<"pass"<<endl<<endl;
1068 //===========================================================================
1070 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1071 CORBA::Boolean theIsPublished,
1072 CORBA::Boolean& theIsValidScript,
1073 SALOMEDS::SObject_ptr theSObject,
1074 std::ostream& theStr,
1075 TName2EntryMap& theName2EntryMap,
1076 TEntry2NameMap& theEntry2NameMap,
1077 std::string theArgumentName,
1078 std::string thePrefix)
1080 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1081 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1082 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1083 CORBA::Object_var anObj = SObjectToObject(aSObject);
1084 if(CORBA::is_nil(anObj))
1087 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1088 if(CORBA::is_nil(aBase))
1091 if(aBase->GetType() == VISU::TCONTAINER){
1093 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1094 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1095 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1096 std::string aPrefix = thePrefix + PREFIX;
1097 theArgumentName = aName;
1099 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1100 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1101 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1102 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1105 theStr<<aPrefix<<"pass"<<endl<<endl;
1111 //===========================================================================
1114 DumpPython(CORBA::Object_ptr theStudy,
1115 CORBA::Boolean theIsPublished,
1116 CORBA::Boolean& theIsValidScript)
1118 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1119 if(CORBA::is_nil(aStudy))
1120 return new Engines::TMPFile(0);
1122 TName2EntryMap aName2EntryMap;
1123 TEntry2NameMap aEntry2NameMap;
1131 std::string aPrefix(PREFIX);
1132 aStr<<"### This file is generated by SALOME automatically by dump python funcitonality"
1133 " of VISU component"<<endl<<endl;
1134 aStr<<"def RebuildData(theStudy):"<<endl;
1135 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
1136 aStr<<aPrefix<<"import SALOME_MED"<<endl;
1137 aStr<<aPrefix<<"import SALOMEDS"<<endl;
1138 aStr<<aPrefix<<"import VISU"<<endl;
1139 aStr<<aPrefix<<"import visu"<<endl;
1141 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
1142 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
1143 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
1144 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
1145 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
1148 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
1149 VISU::DumpChildrenToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1150 VISU::DumpContainersToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1152 aStr<<aPrefix<<"pass"<<endl;
1155 std::string aResult = aStr.str();
1156 //ofstream anFStream("/tmp/dump.py");
1157 //anFStream<<aResult<<endl;
1159 CORBA::ULong aSize = aResult.size() + 1;
1160 char* aBuffer = new char[aSize];
1161 strcpy(aBuffer,&aResult[0]);
1162 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
1165 return new Engines::TMPFile(0);