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;
233 //===========================================================================
234 template<class TTableAttr>
236 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
237 CORBA::Boolean theIsPublished,
238 CORBA::Boolean& theIsValidScript,
239 SALOMEDS::SObject_ptr theSObject,
240 TTableAttr theTableAttr,
241 const std::string& theAttrName,
242 std::ostream& theStr,
243 TName2EntryMap& theName2EntryMap,
244 TEntry2NameMap& theEntry2NameMap,
245 std::string theArgumentName,
246 std::string thePrefix)
248 SALOMEDS::GenericAttribute_var anAttr;
249 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
250 if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){
251 SALOMEDS::AttributeComment_var aComment =
252 SALOMEDS::AttributeComment::_narrow(anAttr);
253 CORBA::String_var aValue = aComment->Value();
254 Storable::TRestoringMap aMap;
255 Storable::StrToMap(aValue.in(),aMap);
257 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
259 if(strcmp(aMethodName.latin1(),"ImportTables") == 0){
265 std::string aSObjectName = GetName(theSObject);
266 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
267 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
270 std::string aName = "aTableAttr";
271 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
272 aSObjectName<<",'"<<theAttrName<<"')"<<endl;
274 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
275 std::string aPrefix = thePrefix;
278 CORBA::String_var aString = theTableAttr->GetTitle();
279 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
281 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
282 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
284 CORBA::Long aNbRows = theTableAttr->GetNbRows();
286 // push values and their indices into streams
287 strstream values, rows, columns;
289 for(CORBA::Long i = 1; i <= aNbColumns; i++){
290 for(CORBA::Long j = aNbRows; j > 0; j--){
291 if(theTableAttr->HasValue(j,i)){
292 values << comma << theTableAttr->GetValue(j,i);
294 columns << comma << i;
300 // push titles and units into streams
301 strstream rowUnits, rowTitles, colTitles;
302 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
303 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
305 for(CORBA::Long j = 1; j <= aNbRows; j++){
306 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
307 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
311 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
313 for(CORBA::Long j = 1; j <= aNbColumns; j++){
314 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
324 // write FillTable command
325 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
326 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
327 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
328 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
329 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
330 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
331 theStr<< thePrefix << "visu.FillTable( "
333 << aName << "_values, "
334 << aName << "_rows, "
335 << aName << "_columns, "
336 << aName << "_rTitles, "
337 << aName << "_rUnits, "
338 << aName << "_cTitles )" << endl;
340 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
342 std::string aName = "aTable";
343 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
344 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
345 theArgumentName = aName;
347 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
348 std::string aPrefix2 = thePrefix + PREFIX;
350 DumpChildrenToPython(theStudy,
360 theStr<<aPrefix2<<"pass"<<endl<<endl;
363 theStr<<thePrefix<<"pass"<<endl<<endl;
364 theStr<<aPrefix<<"pass"<<endl<<endl;
368 //===========================================================================
370 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
371 CORBA::Boolean theIsPublished,
372 CORBA::Boolean& theIsValidScript,
373 SALOMEDS::SObject_ptr theSObject,
374 std::ostream& theStr,
375 TName2EntryMap& theName2EntryMap,
376 TEntry2NameMap& theEntry2NameMap,
377 std::string theArgumentName,
378 std::string thePrefix)
380 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
381 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
382 SALOMEDS::SObject_var aSObject = aChildItet->Value();
383 DumpToPython(theStudy,
396 //===========================================================================
398 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
399 CORBA::Boolean theIsPublished,
400 CORBA::Boolean& theIsValidScript,
401 SALOMEDS::SObject_ptr theSObject,
402 std::ostream& theStr,
403 TName2EntryMap& theName2EntryMap,
404 TEntry2NameMap& theEntry2NameMap,
405 std::string theArgumentName,
406 std::string thePrefix)
408 SALOMEDS::GenericAttribute_var anAttr;
409 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
410 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
411 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
413 TableAttrToPython(theStudy,
418 "AttributeTableOfInteger",
425 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
426 SALOMEDS::AttributeTableOfReal_var aTableAttr =
427 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
429 TableAttrToPython(theStudy,
434 "AttributeTableOfReal",
444 //===========================================================================
446 DumpToPython(SALOMEDS::Study_ptr theStudy,
447 CORBA::Boolean theIsPublished,
448 CORBA::Boolean& theIsValidScript,
449 SALOMEDS::SObject_ptr theSObject,
450 std::ostream& theStr,
451 TName2EntryMap& theName2EntryMap,
452 TEntry2NameMap& theEntry2NameMap,
453 std::string theArgumentName,
454 std::string thePrefix)
456 std::string aName = GetName(theSObject);
460 CORBA::Object_var anObj = SObjectToObject(theSObject);
461 if(!CORBA::is_nil(anObj)){
462 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
463 if(!CORBA::is_nil(aBase)){
464 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
465 CORBA::String_var anID = theSObject->GetID();
467 VISU::VISUType aType = aBase->GetType();
470 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
471 std::string aFileName = aServant->GetFileName();
472 Result_i::ECreationId anId = aServant->GetCreationId();
473 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
475 case Result_i::eImportFile:
476 theStr<<thePrefix<<aName<<" = aVisu.ImportFile('"<<aFileName<<"')"<<endl;
478 case Result_i::eCopyAndImportFile:
479 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
483 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
486 theArgumentName = aName;
487 DumpChildrenToPython(theStudy,
497 theStr<<thePrefix<<"pass"<<endl<<endl;
499 SALOMEDS::SObject_var aRefSObj;
500 if(theSObject->FindSubObject(1,aRefSObj)){
501 SALOMEDS::SObject_var aTargetRefSObj;
502 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
503 CORBA::String_var aString = aTargetRefSObj->GetName();
504 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
505 theStr<<thePrefix<<"if aSObject:"<<endl;
507 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
508 theStr<<thePrefix<<"if anObject:"<<endl;
509 std::string aPrefix1 = thePrefix;
513 case Result_i::eImportMed:
514 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
516 case Result_i::eImportMedField:
517 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
521 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
522 std::string aPrefix2 = thePrefix;
525 theArgumentName = aName;
526 DumpChildrenToPython(theStudy,
536 theStr<<thePrefix<<"pass"<<endl<<endl;
537 theStr<<aPrefix2<<"pass"<<endl<<endl;
538 theStr<<aPrefix1<<"pass"<<endl<<endl;
545 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
546 VISU::Entity anEntity = aServant->GetEntity();
547 const std::string& aSubMeshName = aServant->GetSubMeshName();
552 aParam = "VISU.NODE";
555 aParam = "VISU.EDGE";
558 aParam = "VISU.FACE";
561 aParam = "VISU.CELL";
565 if(aSubMeshName == "")
566 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
567 ",'"<<aServant->GetMeshName()<<"'"<<
571 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
572 ",'"<<aServant->GetMeshName()<<"'"<<
574 ",'"<<aSubMeshName<<"'"<<
577 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
578 ",'"<<aServant->GetMeshName()<<"'"<<
579 ",'"<<aSubMeshName<<"'"<<
582 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
585 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
587 SALOMEDS::Color aColor;
588 aColor = aServant->GetCellColor();
589 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
590 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
592 aColor = aServant->GetNodeColor();
593 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
594 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
596 aColor = aServant->GetLinkColor();
597 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
598 aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
601 switch(aServant->GetPresentationType()){
603 aParam = "VISU.POINT";
606 aParam = "VISU.WIREFRAME";
609 aParam = "VISU.SHADED";
612 aParam = "VISU.INSIDEFRAME";
615 aParam = "VISU.SURFACEFRAME";
618 aParam = "VISU.SHRINK";
621 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
624 DumpChildrenToPython(theStudy,
634 theStr<<thePrefix<<"pass"<<endl<<endl;
638 case VISU::TSCALARMAP:
639 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
640 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"ScalarMapOnField",theArgumentName,thePrefix);
641 theStr<<thePrefix<<"pass"<<endl<<endl;
644 case VISU::TDEFORMEDSHAPE:
645 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
646 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"DeformedShapeOnField",theArgumentName,thePrefix);
647 theStr<<thePrefix<<"pass"<<endl<<endl;
650 case VISU::TSTREAMLINES:
651 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
652 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"StreamLinesOnField",theArgumentName,thePrefix);
655 switch(aServant->GetDirection()){
656 case StreamLines::FORWARD:
657 aParam = "VISU.StreamLines.FORWARD";
659 case StreamLines::BACKWARD:
660 aParam = "VISU.StreamLines.BACKWARD";
662 case StreamLines::BOTH:
663 aParam = "VISU.StreamLines.BOTH";
667 theStr<<thePrefix<<"aPrs3d = None"<<endl;
668 VISU::Prs3d_var aPrs3d = aServant->GetSource();
669 if(!CORBA::is_nil(aPrs3d)){
670 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
671 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
672 CORBA::String_var anID = aSObject->GetID();
673 std::string anArg = theEntry2NameMap[anID.in()];
674 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
676 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
680 theStr<<thePrefix<<aName<<".SetParams("<<
681 aServant->GetIntegrationStep()<<","<<
682 aServant->GetPropagationTime()<<","<<
683 aServant->GetStepLength()<<","<<
685 aServant->GetUsedPoints()<<","<<
689 theStr<<thePrefix<<"pass"<<endl<<endl;
693 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
694 thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"VectorsOnField",theArgumentName,thePrefix);
696 theStr<<thePrefix<<aName<<".SetLineWidth("<<aServant->GetLineWidth()<<")"<<endl;
699 switch(aServant->GetGlyphType()){
701 aParam = "VISU.Vectors.ARROW";
704 aParam = "VISU.Vectors.CONE2";
707 aParam = "VISU.Vectors.CONE6";
710 aParam = "VISU.Vectors.NONE";
713 theStr<<thePrefix<<aName<<".SetGlyphType("<<aParam<<")"<<endl;
715 switch(aServant->GetGlyphPos()){
716 case Vectors::CENTER:
717 aParam = "VISU.Vectors.CENTER";
720 aParam = "VISU.Vectors.TAIL";
723 aParam = "VISU.Vectors.HEAD";
726 theStr<<thePrefix<<aName<<".SetGlyphPos("<<aParam<<")"<<endl;
728 theStr<<thePrefix<<"pass"<<endl<<endl;
731 case VISU::TISOSURFACE:
732 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
733 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"IsoSurfacesOnField",theArgumentName,thePrefix);
734 theStr<<thePrefix<<aName<<".SetNbSurfaces("<<aServant->GetNbSurfaces()<<")"<<endl;
735 theStr<<thePrefix<<"pass"<<endl<<endl;
738 case VISU::TCUTPLANES:
739 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
740 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutPlanesOnField",theArgumentName,thePrefix);
743 switch(aServant->GetOrientationType()){
745 aParam = "VISU.CutPlanes.XY";
748 aParam = "VISU.CutPlanes.YZ";
751 aParam = "VISU.CutPlanes.ZX";
754 theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
756 theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
757 CORBA::Long aNbPlanes = aServant->GetNbPlanes();
758 theStr<<thePrefix<<aName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
760 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
761 if(!aServant->IsDefault(anId))
762 theStr<<thePrefix<<aName<<".SetPlanePosition("<<anId<<","<<aServant->GetPlanePosition(anId)<<")"<<endl;
765 theStr<<thePrefix<<"pass"<<endl<<endl;
768 case VISU::TCUTLINES:
769 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
770 thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutLinesOnField",theArgumentName,thePrefix);
773 switch(aServant->GetOrientationType()){
775 aParam = "VISU.CutPlanes.XY";
778 aParam = "VISU.CutPlanes.YZ";
781 aParam = "VISU.CutPlanes.ZX";
784 theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
786 switch(aServant->GetOrientationType2()){
788 aParam = "VISU.CutPlanes.XY";
791 aParam = "VISU.CutPlanes.YZ";
794 aParam = "VISU.CutPlanes.ZX";
797 theStr<<thePrefix<<aName<<".SetOrientation2("<<aParam<<","<<aServant->GetRotateX2()<<","<<aServant->GetRotateY2()<<")"<<endl;
799 theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
800 theStr<<thePrefix<<aName<<".SetDisplacement2("<<aServant->GetDisplacement2()<<")"<<endl;
802 if(!aServant->IsDefault())
803 theStr<<thePrefix<<aName<<".SetBasePlanePosition("<<aServant->GetBasePlanePosition()<<")"<<endl;
805 CORBA::Long aNbLines = aServant->GetNbLines();
806 theStr<<thePrefix<<aName<<".SetNbLines("<<aNbLines<<")"<<endl;
807 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
808 if(!aServant->IsDefaultPosition(anId))
809 theStr<<thePrefix<<aName<<".SetLinePosition("<<anId<<","<<aServant->GetLinePosition(anId)<<")"<<endl;
814 theArgumentName = aName;
815 DumpChildrenToPython(theStudy,
825 theStr<<thePrefix<<"pass"<<endl<<endl;
829 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
831 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve(" <<
832 theArgumentName<< // table
833 ","<<aServant->GetHRow()<< // H row
834 ","<<aServant->GetVRow()<< // V row
835 ",'"<<aServant->GetTitle()<<"'"; // title
836 SALOMEDS::Color aColor = aServant->GetColor();
837 theStr << ",SALOMEDS.Color("<<
838 aColor.R<<","<<aColor.G<<","<<aColor.B<<")"; // color
841 switch(aServant->GetMarker()){
842 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
843 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
844 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
845 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
846 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
847 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
848 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
849 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
850 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
851 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
853 theStr<<","<<aParam; // marker
855 switch(aServant->GetLine()){
856 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
857 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
858 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
859 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
860 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
861 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
863 theStr<<","<<aParam<<","<<aServant->GetLineWidth()<<")"<<endl; // line type,width
867 if(Table_i* aServant = dynamic_cast<Table_i*>(GetServant(anObj).in())){
868 SALOMEDS::SObject_var aSObject = aServant->GetSObject();
869 SALOMEDS::GenericAttribute_var anAttr;
870 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
871 using namespace SALOMEDS;
872 AttributeComment_var aComment = AttributeComment::_narrow(anAttr);
873 CORBA::String_var aValue = aComment->Value();
874 Storable::TRestoringMap aMap;
875 Storable::StrToMap(aValue.in(),aMap);
877 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
879 if(strcmp(aSourceId.latin1(),"CutLines") == 0){
880 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
883 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
884 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
885 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
886 theStr<<thePrefix<<"if aSObject:"<<endl;
887 std::string aPrefix = thePrefix;
890 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
891 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
894 theArgumentName = aName;
895 DumpChildrenToPython(theStudy,
905 theStr<<thePrefix<<"pass"<<endl<<endl;
906 theStr<<aPrefix<<"pass"<<endl<<endl;
907 }else if(strcmp(aSourceId.latin1(),"TableFile") == 0){
908 CORBA::Short aTag = theSObject->Tag();
909 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
910 theStr<<thePrefix<<"if anIsFound:"<<endl;
913 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
914 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
917 theArgumentName = aName;
918 DumpChildrenToPython(theStudy,
928 theStr<<thePrefix<<"pass"<<endl<<endl;
929 }else if(strcmp(aSourceId.latin1(),"TableAttr") == 0){
930 theArgumentName = aName;
931 DumpTableAttrToPython(theStudy,
948 SALOMEDS::GenericAttribute_var anAttr;
949 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
950 SALOMEDS::AttributeComment_var aComment =
951 SALOMEDS::AttributeComment::_narrow(anAttr);
952 CORBA::String_var aValue = aComment->Value();
953 Storable::TRestoringMap aMap;
954 Storable::StrToMap(aValue.in(),aMap);
956 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
958 if(strcmp(aTypeName.latin1(),"ImportTables") == 0){
959 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
961 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
962 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.latin1()<<"')"<<endl;
963 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
966 theArgumentName = aName;
967 DumpChildrenToPython(theStudy,
977 theStr<<thePrefix<<"pass"<<endl<<endl;
980 }else if(strcmp(aTypeName.latin1(),"VIEW3D") == 0){
981 std::string aName = GetName(theSObject);
982 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
984 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
987 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
988 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
990 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeComment')"<<endl;
991 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
993 theStr<<thePrefix<<"pass"<<endl<<endl;
998 DumpTableAttrToPython(theStudy,
1010 DumpChildrenToPython(theStudy,
1022 //===========================================================================
1024 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1025 CORBA::Boolean theIsPublished,
1026 CORBA::Boolean& theIsValidScript,
1027 SALOMEDS::SObject_ptr theSObject,
1028 std::ostream& theStr,
1029 TName2EntryMap& theName2EntryMap,
1030 TEntry2NameMap& theEntry2NameMap,
1031 std::string theArgumentName,
1032 std::string thePrefix)
1034 SALOMEDS::SObject_var aTargetRefSObj;
1035 if(theSObject->ReferencedObject(aTargetRefSObj)){
1036 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1037 if(CORBA::is_nil(anObj))
1040 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1041 if(CORBA::is_nil(aBase))
1044 if(aBase->GetType() == VISU::TCURVE){
1045 CORBA::String_var anID = aTargetRefSObj->GetID();
1046 std::string anArg = theEntry2NameMap[anID.in()];
1047 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1048 thePrefix += PREFIX;
1049 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1050 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1051 theStr<<thePrefix<<"pass"<<endl<<endl;
1057 //===========================================================================
1059 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1060 CORBA::Boolean theIsPublished,
1061 CORBA::Boolean& theIsValidScript,
1062 SALOMEDS::SObject_ptr theSObject,
1063 std::ostream& theStr,
1064 TName2EntryMap& theName2EntryMap,
1065 TEntry2NameMap& theEntry2NameMap,
1066 std::string theArgumentName,
1067 std::string thePrefix)
1069 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1070 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1071 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1072 CORBA::Object_var anObj = SObjectToObject(aSObject);
1073 if(CORBA::is_nil(anObj))
1076 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1077 if(CORBA::is_nil(aBase))
1080 if(aBase->GetType() == VISU::TCONTAINER){
1082 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1083 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1084 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1085 std::string aPrefix = thePrefix + PREFIX;
1086 theArgumentName = aName;
1088 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1089 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1090 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1091 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1094 theStr<<aPrefix<<"pass"<<endl<<endl;
1100 //===========================================================================
1103 DumpPython(CORBA::Object_ptr theStudy,
1104 CORBA::Boolean theIsPublished,
1105 CORBA::Boolean& theIsValidScript)
1107 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1108 if(CORBA::is_nil(aStudy))
1109 return new Engines::TMPFile(0);
1111 TName2EntryMap aName2EntryMap;
1112 TEntry2NameMap aEntry2NameMap;
1120 std::string aPrefix(PREFIX);
1121 aStr<<"### This file is generated by SALOME automatically by dump python funcitonality"
1122 " of VISU component"<<endl<<endl;
1123 aStr<<"def RebuildData(theStudy):"<<endl;
1124 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
1125 aStr<<aPrefix<<"import SALOME_MED"<<endl;
1126 aStr<<aPrefix<<"import SALOMEDS"<<endl;
1127 aStr<<aPrefix<<"import VISU"<<endl;
1128 aStr<<aPrefix<<"import visu"<<endl;
1130 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
1131 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
1132 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
1133 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
1134 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
1137 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
1138 VISU::DumpChildrenToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1139 VISU::DumpContainersToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1141 aStr<<aPrefix<<"pass"<<endl;
1144 std::string aResult = aStr.str();
1145 //ofstream anFStream("/tmp/dump.py");
1146 //anFStream<<aResult<<endl;
1148 CORBA::ULong aSize = aResult.size() + 1;
1149 char* aBuffer = new char[aSize];
1150 strcpy(aBuffer,&aResult[0]);
1151 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
1154 return new Engines::TMPFile(0);