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_Plot3D_i.hh"
41 #include "VISU_Table_i.hh"
43 #include "utilities.h"
50 #include <qfileinfo.h>
57 static std::string PREFIX(" ");
59 typedef std::map<std::string,std::string> TName2EntryMap;
60 typedef std::map<std::string,std::string> TEntry2NameMap;
64 GenerateName(std::string theName,
65 SALOMEDS::SObject_ptr theSObject,
66 TName2EntryMap& theName2EntryMap,
67 TEntry2NameMap& theEntry2NameMap,
70 if(theName2EntryMap.find(theName) != theName2EntryMap.end()){
71 theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix);
73 CORBA::String_var anID = theSObject->GetID();
74 theName2EntryMap[theName] = anID.in();
75 theEntry2NameMap[anID.in()] = theName;
76 //cout<<"GenerateName - "<<theName<<" => "<<anID.in()<<endl;
82 struct TReplacePredicate{
83 bool operator()(char theChar) const
85 return !(isdigit(theChar) || isalpha(theChar) || theChar == '_');
91 GetName(SALOMEDS::SObject_ptr theSObject)
93 CORBA::String_var aString = theSObject->GetName();
95 std::string aName = QString(aString.in()).simplifyWhiteSpace().latin1();
97 //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_');
98 replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_');
100 if ( isdigit( aName[0] ))
101 aName.insert( 0, 1, 'a' );
108 GenerateName(SALOMEDS::SObject_ptr theSObject,
109 TName2EntryMap& theName2EntryMap,
110 TEntry2NameMap& theEntry2NameMap)
112 std::string aName = GetName(theSObject);
114 return GenerateName(aName,theSObject,theName2EntryMap,theEntry2NameMap,'X');
118 //===========================================================================
119 typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy,
120 CORBA::Boolean theIsPublished,
121 CORBA::Boolean& theIsValidScript,
122 SALOMEDS::SObject_ptr theSObject,
123 std::ostream& theStr,
124 TName2EntryMap& theName2EntryMap,
125 TEntry2NameMap& theEntry2NameMap,
126 std::string theArgumentName,
127 std::string thePrefix);
131 DumpToPython(SALOMEDS::Study_ptr theStudy,
132 CORBA::Boolean theIsPublished,
133 CORBA::Boolean& theIsValidScript,
134 SALOMEDS::SObject_ptr theSObject,
135 std::ostream& theStr,
136 TName2EntryMap& theName2EntryMap,
137 TEntry2NameMap& theEntry2NameMap,
138 std::string theArgumentName,
139 std::string thePrefix);
142 //===========================================================================
144 ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
145 VISU::ScalarMap_i* theServant,
146 std::ostream& theStr,
147 std::string& theName,
148 const std::string& theConstructorName,
149 const std::string& theArgumentName,
150 std::string thePrefix)
153 switch(theServant->GetEntity()){
155 aParam = "VISU.NODE";
158 aParam = "VISU.EDGE";
161 aParam = "VISU.FACE";
164 aParam = "VISU.CELL";
168 theStr<<thePrefix<<theName<<" = aVisu."<<theConstructorName<<"("<<theArgumentName<<
169 ",'"<<theServant->GetMeshName()<<"'"<<
171 ",'"<<theServant->GetFieldName()<<"'"<<
172 ","<<theServant->GetIteration()<<
175 theStr<<thePrefix<<"if "<<theName<<":"<<endl;
178 theStr<<thePrefix<<"aName2ObjectMap['"<<theName<<"'] = "<<theName<<endl;
180 theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
182 switch(theServant->GetScaling()){
184 aParam = "VISU.LINEAR";
187 aParam = "VISU.LOGARITHMIC";
190 theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
191 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<","<<theServant->GetMax()<<")"<<endl;
193 switch(theServant->GetBarOrientation()){
194 case ScalarMap::HORIZONTAL:
195 aParam = "VISU.ScalarMap.HORIZONTAL";
197 case ScalarMap::VERTICAL:
198 aParam = "VISU.ScalarMap.VERTICAL";
201 theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
203 theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<","<<theServant->GetPosY()<<")"<<endl;
204 theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<","<<theServant->GetHeight()<<")"<<endl;
205 theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
206 theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
207 theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
213 //===========================================================================
215 DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
216 VISU::DeformedShape_i* theServant,
217 std::ostream& theStr,
218 std::string& theName,
219 const std::string& theConstructorName,
220 const std::string& theArgumentName,
221 std::string thePrefix)
223 thePrefix = ScalarMapToPython(theSObject,theServant,theStr,theName,theConstructorName,theArgumentName,thePrefix);
224 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
225 theStr<<thePrefix<<theName<<".ShowColored("<<theServant->IsColored()<<")"<<endl;
226 SALOMEDS::Color aColor = theServant->GetColor();
227 theStr<<thePrefix<<theName<<".SetColor(SALOMEDS.Color("<<
228 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
233 //===========================================================================
235 void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
236 CORBA::Boolean theIsPublished,
237 CORBA::Boolean& theIsValidScript,
238 SALOMEDS::SObject_ptr theSObject,
239 std::ostream& theStr,
240 TName2EntryMap& theName2EntryMap,
241 TEntry2NameMap& theEntry2NameMap,
242 std::string theArgumentName,
243 std::string thePrefix);
245 //===========================================================================
246 template<class TTableAttr>
248 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
249 CORBA::Boolean theIsPublished,
250 CORBA::Boolean& theIsValidScript,
251 SALOMEDS::SObject_ptr theSObject,
252 TTableAttr theTableAttr,
253 const std::string& theAttrName,
254 std::ostream& theStr,
255 TName2EntryMap& theName2EntryMap,
256 TEntry2NameMap& theEntry2NameMap,
257 std::string theArgumentName,
258 std::string thePrefix)
260 SALOMEDS::GenericAttribute_var anAttr;
261 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
262 if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){
263 SALOMEDS::AttributeComment_var aComment =
264 SALOMEDS::AttributeComment::_narrow(anAttr);
265 CORBA::String_var aValue = aComment->Value();
266 Storable::TRestoringMap aMap;
267 Storable::StrToMap(aValue.in(),aMap);
269 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
271 if(strcmp(aMethodName.latin1(),"ImportTables") == 0){
277 std::string aSObjectName = GetName(theSObject);
278 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
279 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
282 std::string aName = "aTableAttr";
283 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
284 aSObjectName<<",'"<<theAttrName<<"')"<<endl;
286 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
287 std::string aPrefix = thePrefix;
290 CORBA::String_var aString = theTableAttr->GetTitle();
291 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
293 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
294 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
296 CORBA::Long aNbRows = theTableAttr->GetNbRows();
298 // push values and their indices into streams
299 strstream values, rows, columns;
301 for(CORBA::Long i = 1; i <= aNbColumns; i++){
302 for(CORBA::Long j = aNbRows; j > 0; j--){
303 if(theTableAttr->HasValue(j,i)){
304 values << comma << theTableAttr->GetValue(j,i);
306 columns << comma << i;
312 // push titles and units into streams
313 strstream rowUnits, rowTitles, colTitles;
314 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
315 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
317 for(CORBA::Long j = 1; j <= aNbRows; j++){
318 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
319 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
323 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
325 for(CORBA::Long j = 1; j <= aNbColumns; j++){
326 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
336 // write FillTable command
337 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
338 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
339 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
340 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
341 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
342 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
343 theStr<< thePrefix << "visu.FillTable( "
345 << aName << "_values, "
346 << aName << "_rows, "
347 << aName << "_columns, "
348 << aName << "_rTitles, "
349 << aName << "_rUnits, "
350 << aName << "_cTitles )" << endl;
352 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
354 std::string aName = "aTable";
355 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
356 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
357 theArgumentName = aName;
359 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
360 std::string aPrefix2 = thePrefix + PREFIX;
362 DumpChildrenToPython(theStudy,
372 theStr<<aPrefix2<<"pass"<<endl<<endl;
375 theStr<<thePrefix<<"pass"<<endl<<endl;
376 theStr<<aPrefix<<"pass"<<endl<<endl;
380 //===========================================================================
382 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
383 CORBA::Boolean theIsPublished,
384 CORBA::Boolean& theIsValidScript,
385 SALOMEDS::SObject_ptr theSObject,
386 std::ostream& theStr,
387 TName2EntryMap& theName2EntryMap,
388 TEntry2NameMap& theEntry2NameMap,
389 std::string theArgumentName,
390 std::string thePrefix)
392 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
393 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
394 SALOMEDS::SObject_var aSObject = aChildItet->Value();
395 DumpToPython(theStudy,
408 //===========================================================================
410 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
411 CORBA::Boolean theIsPublished,
412 CORBA::Boolean& theIsValidScript,
413 SALOMEDS::SObject_ptr theSObject,
414 std::ostream& theStr,
415 TName2EntryMap& theName2EntryMap,
416 TEntry2NameMap& theEntry2NameMap,
417 std::string theArgumentName,
418 std::string thePrefix)
420 SALOMEDS::GenericAttribute_var anAttr;
421 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
422 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
423 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
425 TableAttrToPython(theStudy,
430 "AttributeTableOfInteger",
437 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
438 SALOMEDS::AttributeTableOfReal_var aTableAttr =
439 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
441 TableAttrToPython(theStudy,
446 "AttributeTableOfReal",
456 //===========================================================================
458 DumpToPython(SALOMEDS::Study_ptr theStudy,
459 CORBA::Boolean theIsPublished,
460 CORBA::Boolean& theIsValidScript,
461 SALOMEDS::SObject_ptr theSObject,
462 std::ostream& theStr,
463 TName2EntryMap& theName2EntryMap,
464 TEntry2NameMap& theEntry2NameMap,
465 std::string theArgumentName,
466 std::string thePrefix)
468 std::string aName = GetName(theSObject);
472 CORBA::Object_var anObj = SObjectToObject(theSObject);
473 if(!CORBA::is_nil(anObj)){
474 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
475 if(!CORBA::is_nil(aBase)){
476 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
477 CORBA::String_var anID = theSObject->GetID();
479 VISU::VISUType aType = aBase->GetType();
482 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
483 std::string aFileName = aServant->GetFileName();
484 Result_i::ECreationId anId = aServant->GetCreationId();
485 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
487 case Result_i::eImportFile:
488 theStr<<thePrefix<<aName<<" = aVisu.ImportFile('"<<aFileName<<"')"<<endl;
490 case Result_i::eCopyAndImportFile:
491 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
495 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
498 theArgumentName = aName;
499 DumpChildrenToPython(theStudy,
509 theStr<<thePrefix<<"pass"<<endl<<endl;
511 SALOMEDS::SObject_var aRefSObj;
512 if(theSObject->FindSubObject(1,aRefSObj)){
513 SALOMEDS::SObject_var aTargetRefSObj;
514 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
515 CORBA::String_var aString = aTargetRefSObj->GetName();
516 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
517 theStr<<thePrefix<<"if aSObject:"<<endl;
519 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
520 theStr<<thePrefix<<"if anObject:"<<endl;
521 std::string aPrefix1 = thePrefix;
525 case Result_i::eImportMed:
526 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
528 case Result_i::eImportMedField:
529 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
533 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
534 std::string aPrefix2 = thePrefix;
537 theArgumentName = aName;
538 DumpChildrenToPython(theStudy,
548 theStr<<thePrefix<<"pass"<<endl<<endl;
549 theStr<<aPrefix2<<"pass"<<endl<<endl;
550 theStr<<aPrefix1<<"pass"<<endl<<endl;
557 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
558 VISU::Entity anEntity = aServant->GetEntity();
559 const std::string& aSubMeshName = aServant->GetSubMeshName();
564 aParam = "VISU.NODE";
567 aParam = "VISU.EDGE";
570 aParam = "VISU.FACE";
573 aParam = "VISU.CELL";
577 if(aSubMeshName == "")
578 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
579 ",'"<<aServant->GetMeshName()<<"'"<<
583 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
584 ",'"<<aServant->GetMeshName()<<"'"<<
586 ",'"<<aSubMeshName<<"'"<<
589 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
590 ",'"<<aServant->GetMeshName()<<"'"<<
591 ",'"<<aSubMeshName<<"'"<<
594 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
597 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
599 SALOMEDS::Color aColor;
600 aColor = aServant->GetCellColor();
601 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
602 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
604 aColor = aServant->GetNodeColor();
605 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
606 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
608 aColor = aServant->GetLinkColor();
609 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
610 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
613 switch(aServant->GetPresentationType()){
615 aParam = "VISU.POINT";
618 aParam = "VISU.WIREFRAME";
621 aParam = "VISU.SHADED";
624 aParam = "VISU.INSIDEFRAME";
627 aParam = "VISU.SURFACEFRAME";
630 aParam = "VISU.SHRINK";
633 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
636 DumpChildrenToPython(theStudy,
646 theStr<<thePrefix<<"pass"<<endl<<endl;
650 case VISU::TSCALARMAP:
651 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
652 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"ScalarMapOnField",theArgumentName,thePrefix);
653 theStr<<thePrefix<<"pass"<<endl<<endl;
656 case VISU::TDEFORMEDSHAPE:
657 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
658 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"DeformedShapeOnField",theArgumentName,thePrefix);
659 theStr<<thePrefix<<"pass"<<endl<<endl;
662 case VISU::TSTREAMLINES:
663 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
664 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"StreamLinesOnField",theArgumentName,thePrefix);
667 switch(aServant->GetDirection()){
668 case StreamLines::FORWARD:
669 aParam = "VISU.StreamLines.FORWARD";
671 case StreamLines::BACKWARD:
672 aParam = "VISU.StreamLines.BACKWARD";
674 case StreamLines::BOTH:
675 aParam = "VISU.StreamLines.BOTH";
679 theStr<<thePrefix<<"aPrs3d = None"<<endl;
680 VISU::Prs3d_var aPrs3d = aServant->GetSource();
681 if(!CORBA::is_nil(aPrs3d)){
682 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
683 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
684 CORBA::String_var anID = aSObject->GetID();
685 std::string anArg = theEntry2NameMap[anID.in()];
686 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
688 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
692 theStr<<thePrefix<<aName<<".SetParams("<<
693 aServant->GetIntegrationStep()<<","<<
694 aServant->GetPropagationTime()<<","<<
695 aServant->GetStepLength()<<","<<
697 aServant->GetUsedPoints()<<","<<
701 theStr<<thePrefix<<"pass"<<endl<<endl;
705 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
706 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"VectorsOnField",theArgumentName,thePrefix);
708 theStr<<thePrefix<<aName<<".SetLineWidth("<<aServant->GetLineWidth()<<")"<<endl;
711 switch(aServant->GetGlyphType()){
713 aParam = "VISU.Vectors.ARROW";
716 aParam = "VISU.Vectors.CONE2";
719 aParam = "VISU.Vectors.CONE6";
722 aParam = "VISU.Vectors.NONE";
725 theStr<<thePrefix<<aName<<".SetGlyphType("<<aParam<<")"<<endl;
727 switch(aServant->GetGlyphPos()){
728 case Vectors::CENTER:
729 aParam = "VISU.Vectors.CENTER";
732 aParam = "VISU.Vectors.TAIL";
735 aParam = "VISU.Vectors.HEAD";
738 theStr<<thePrefix<<aName<<".SetGlyphPos("<<aParam<<")"<<endl;
740 theStr<<thePrefix<<"pass"<<endl<<endl;
743 case VISU::TISOSURFACE:
744 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
745 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"IsoSurfacesOnField",theArgumentName,thePrefix);
746 theStr<<thePrefix<<aName<<".SetNbSurfaces("<<aServant->GetNbSurfaces()<<")"<<endl;
747 theStr<<thePrefix<<"pass"<<endl<<endl;
750 case VISU::TCUTPLANES:
751 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
752 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutPlanesOnField",theArgumentName,thePrefix);
755 switch(aServant->GetOrientationType()){
757 aParam = "VISU.CutPlanes.XY";
760 aParam = "VISU.CutPlanes.YZ";
763 aParam = "VISU.CutPlanes.ZX";
766 theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
768 theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
769 CORBA::Long aNbPlanes = aServant->GetNbPlanes();
770 theStr<<thePrefix<<aName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
772 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
773 if(!aServant->IsDefault(anId))
774 theStr<<thePrefix<<aName<<".SetPlanePosition("<<anId<<","<<aServant->GetPlanePosition(anId)<<")"<<endl;
777 theStr<<thePrefix<<"pass"<<endl<<endl;
780 case VISU::TCUTLINES:
781 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
782 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutLinesOnField",theArgumentName,thePrefix);
785 switch(aServant->GetOrientationType()){
787 aParam = "VISU.CutPlanes.XY";
790 aParam = "VISU.CutPlanes.YZ";
793 aParam = "VISU.CutPlanes.ZX";
796 theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
798 switch(aServant->GetOrientationType2()){
800 aParam = "VISU.CutPlanes.XY";
803 aParam = "VISU.CutPlanes.YZ";
806 aParam = "VISU.CutPlanes.ZX";
809 theStr<<thePrefix<<aName<<".SetOrientation2("<<aParam<<","<<aServant->GetRotateX2()<<","<<aServant->GetRotateY2()<<")"<<endl;
811 theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
812 theStr<<thePrefix<<aName<<".SetDisplacement2("<<aServant->GetDisplacement2()<<")"<<endl;
814 if(!aServant->IsDefault())
815 theStr<<thePrefix<<aName<<".SetBasePlanePosition("<<aServant->GetBasePlanePosition()<<")"<<endl;
817 CORBA::Long aNbLines = aServant->GetNbLines();
818 theStr<<thePrefix<<aName<<".SetNbLines("<<aNbLines<<")"<<endl;
819 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
820 if(!aServant->IsDefaultPosition(anId))
821 theStr<<thePrefix<<aName<<".SetLinePosition("<<anId<<","<<aServant->GetLinePosition(anId)<<")"<<endl;
826 theArgumentName = aName;
827 DumpChildrenToPython(theStudy,
837 theStr<<thePrefix<<"pass"<<endl<<endl;
841 if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
843 /*thePrefix = ScalarMapToPython(theSObject, aServant, theStr, aName,
844 "Plot3DOnField", theArgumentName, thePrefix);
847 switch(aServant->GetOrientationType()){
849 aParam = "VISU.CutPlanes.XY";
852 aParam = "VISU.CutPlanes.YZ";
855 aParam = "VISU.CutPlanes.ZX";
858 theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
860 theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
861 CORBA::Long aNbPlanes = aServant->GetNbPlanes();
862 theStr<<thePrefix<<aName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
864 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
865 if(!aServant->IsDefault(anId))
866 theStr<<thePrefix<<aName<<".SetPlanePosition("<<anId<<","<<aServant->GetPlanePosition(anId)<<")"<<endl;
869 theStr<<thePrefix<<"pass"<<endl<<endl;*/
873 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
875 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve(" <<
876 theArgumentName<< // table
877 ","<<aServant->GetHRow()<< // H row
878 ","<<aServant->GetVRow()<< // V row
879 ",'"<<aServant->GetTitle()<<"'"; // title
880 SALOMEDS::Color aColor = aServant->GetColor();
881 theStr << ",SALOMEDS.Color("<<
882 aColor.R<<","<<aColor.G<<","<<aColor.B<<")"; // color
885 switch(aServant->GetMarker()){
886 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
887 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
888 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
889 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
890 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
891 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
892 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
893 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
894 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
895 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
897 theStr<<","<<aParam; // marker
899 switch(aServant->GetLine()){
900 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
901 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
902 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
903 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
904 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
905 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
907 theStr<<","<<aParam<<","<<aServant->GetLineWidth()<<")"<<endl; // line type,width
911 if(Table_i* aServant = dynamic_cast<Table_i*>(GetServant(anObj).in())){
912 SALOMEDS::SObject_var aSObject = aServant->GetSObject();
913 SALOMEDS::GenericAttribute_var anAttr;
914 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
915 using namespace SALOMEDS;
916 AttributeComment_var aComment = AttributeComment::_narrow(anAttr);
917 CORBA::String_var aValue = aComment->Value();
918 Storable::TRestoringMap aMap;
919 Storable::StrToMap(aValue.in(),aMap);
921 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
923 if(strcmp(aSourceId.latin1(),"CutLines") == 0){
924 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
927 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
928 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
929 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
930 theStr<<thePrefix<<"if aSObject:"<<endl;
931 std::string aPrefix = thePrefix;
934 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
935 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
938 theArgumentName = aName;
939 DumpChildrenToPython(theStudy,
949 theStr<<thePrefix<<"pass"<<endl<<endl;
950 theStr<<aPrefix<<"pass"<<endl<<endl;
951 }else if(strcmp(aSourceId.latin1(),"TableFile") == 0){
952 CORBA::Short aTag = theSObject->Tag();
953 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
954 theStr<<thePrefix<<"if anIsFound:"<<endl;
957 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
958 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
961 theArgumentName = aName;
962 DumpChildrenToPython(theStudy,
972 theStr<<thePrefix<<"pass"<<endl<<endl;
973 }else if(strcmp(aSourceId.latin1(),"TableAttr") == 0){
974 theArgumentName = aName;
975 DumpTableAttrToPython(theStudy,
992 SALOMEDS::GenericAttribute_var anAttr;
993 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
994 SALOMEDS::AttributeComment_var aComment =
995 SALOMEDS::AttributeComment::_narrow(anAttr);
996 CORBA::String_var aValue = aComment->Value();
997 Storable::TRestoringMap aMap;
998 Storable::StrToMap(aValue.in(),aMap);
1000 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1002 if(strcmp(aTypeName.latin1(),"ImportTables") == 0){
1003 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1005 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1006 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.latin1()<<"')"<<endl;
1007 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1008 thePrefix += PREFIX;
1010 theArgumentName = aName;
1011 DumpChildrenToPython(theStudy,
1021 theStr<<thePrefix<<"pass"<<endl<<endl;
1024 }else if(strcmp(aTypeName.latin1(),"VIEW3D") == 0){
1025 std::string aName = GetName(theSObject);
1026 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1028 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1029 thePrefix += PREFIX;
1031 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1032 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1034 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeComment')"<<endl;
1035 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1037 theStr<<thePrefix<<"pass"<<endl<<endl;
1042 DumpTableAttrToPython(theStudy,
1054 DumpChildrenToPython(theStudy,
1066 //===========================================================================
1068 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1069 CORBA::Boolean theIsPublished,
1070 CORBA::Boolean& theIsValidScript,
1071 SALOMEDS::SObject_ptr theSObject,
1072 std::ostream& theStr,
1073 TName2EntryMap& theName2EntryMap,
1074 TEntry2NameMap& theEntry2NameMap,
1075 std::string theArgumentName,
1076 std::string thePrefix)
1078 SALOMEDS::SObject_var aTargetRefSObj;
1079 if(theSObject->ReferencedObject(aTargetRefSObj)){
1080 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1081 if(CORBA::is_nil(anObj))
1084 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1085 if(CORBA::is_nil(aBase))
1088 if(aBase->GetType() == VISU::TCURVE){
1089 CORBA::String_var anID = aTargetRefSObj->GetID();
1090 std::string anArg = theEntry2NameMap[anID.in()];
1091 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1092 thePrefix += PREFIX;
1093 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1094 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1095 theStr<<thePrefix<<"pass"<<endl<<endl;
1101 //===========================================================================
1103 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1104 CORBA::Boolean theIsPublished,
1105 CORBA::Boolean& theIsValidScript,
1106 SALOMEDS::SObject_ptr theSObject,
1107 std::ostream& theStr,
1108 TName2EntryMap& theName2EntryMap,
1109 TEntry2NameMap& theEntry2NameMap,
1110 std::string theArgumentName,
1111 std::string thePrefix)
1113 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1114 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1115 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1116 CORBA::Object_var anObj = SObjectToObject(aSObject);
1117 if(CORBA::is_nil(anObj))
1120 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1121 if(CORBA::is_nil(aBase))
1124 if(aBase->GetType() == VISU::TCONTAINER){
1126 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1127 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1128 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1129 std::string aPrefix = thePrefix + PREFIX;
1130 theArgumentName = aName;
1132 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1133 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1134 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1135 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1138 theStr<<aPrefix<<"pass"<<endl<<endl;
1144 //===========================================================================
1147 DumpPython(CORBA::Object_ptr theStudy,
1148 CORBA::Boolean theIsPublished,
1149 CORBA::Boolean& theIsValidScript)
1151 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1152 if(CORBA::is_nil(aStudy))
1153 return new Engines::TMPFile(0);
1155 TName2EntryMap aName2EntryMap;
1156 TEntry2NameMap aEntry2NameMap;
1164 std::string aPrefix(PREFIX);
1165 aStr<<"### This file is generated by SALOME automatically by dump python funcitonality"
1166 " of VISU component"<<endl<<endl;
1167 aStr<<"def RebuildData(theStudy):"<<endl;
1168 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
1169 aStr<<aPrefix<<"import SALOME_MED"<<endl;
1170 aStr<<aPrefix<<"import SALOMEDS"<<endl;
1171 aStr<<aPrefix<<"import VISU"<<endl;
1172 aStr<<aPrefix<<"import visu"<<endl;
1174 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
1175 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
1176 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
1177 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
1178 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
1181 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
1182 VISU::DumpChildrenToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1183 VISU::DumpContainersToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1185 aStr<<aPrefix<<"pass"<<endl;
1188 std::string aResult = aStr.str();
1189 //ofstream anFStream("/tmp/dump.py");
1190 //anFStream<<aResult<<endl;
1192 CORBA::ULong aSize = aResult.size() + 1;
1193 char* aBuffer = new char[aSize];
1194 strcpy(aBuffer,&aResult[0]);
1195 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
1198 return new Engines::TMPFile(0);