1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
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"
42 #include "VISU_PointMap3d_i.hh"
43 #include "VISU_GaussPoints_i.hh"
44 #include "VISU_DeformedShapeAndScalarMap_i.hh"
45 #include "VISU_ColoredPrs3dCache_i.hh"
46 #include "VISU_ColoredPrs3dHolder_i.hh"
48 #include "utilities.h"
63 //---------------------------------------------------------------------------
64 static std::string PREFIX(" ");
66 typedef std::map<std::string,std::string> TName2EntryMap;
67 typedef std::map<std::string,std::string> TEntry2NameMap;
70 //---------------------------------------------------------------------------
73 GenerateName(std::string theName,
74 SALOMEDS::SObject_ptr theSObject,
75 TName2EntryMap& theName2EntryMap,
76 TEntry2NameMap& theEntry2NameMap,
79 if(theName2EntryMap.find(theName) != theName2EntryMap.end()){
80 theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix);
82 CORBA::String_var anID = theSObject->GetID();
83 theName2EntryMap[theName] = anID.in();
84 theEntry2NameMap[anID.in()] = theName;
85 //cout<<"GenerateName - "<<theName<<" => "<<anID.in()<<endl;
92 //---------------------------------------------------------------------------
93 struct TReplacePredicate
95 bool operator()(char theChar) const
97 return !(isdigit(theChar) || isalpha(theChar) || theChar == '_');
102 //---------------------------------------------------------------------------
105 GetName(SALOMEDS::SObject_ptr theSObject)
107 CORBA::String_var aString = theSObject->GetName();
109 std::string aName = QString(aString.in()).simplified().toLatin1().data();
111 //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_');
112 replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_');
114 if ( isdigit( aName[0] ))
115 aName.insert( 0, 1, 'a' );
121 //---------------------------------------------------------------------------
124 GenerateName(SALOMEDS::SObject_ptr theSObject,
125 TName2EntryMap& theName2EntryMap,
126 TEntry2NameMap& theEntry2NameMap)
128 std::string aName = GetName(theSObject);
130 return GenerateName(aName, theSObject, theName2EntryMap, theEntry2NameMap, 'X');
134 //---------------------------------------------------------------------------
137 GetBoolean(bool theArgument)
146 //---------------------------------------------------------------------------
149 GetColor(const SALOMEDS::Color& theColor)
151 std::ostringstream aStream;
152 aStream<<"SALOMEDS.Color("<<theColor.R<<", "<<theColor.G<<", "<<theColor.B<<")";
153 return aStream.str();
157 //---------------------------------------------------------------------------
158 typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy,
159 CORBA::Boolean theIsPublished,
160 CORBA::Boolean& theIsValidScript,
161 SALOMEDS::SObject_ptr theSObject,
162 std::ostream& theStr,
163 TName2EntryMap& theName2EntryMap,
164 TEntry2NameMap& theEntry2NameMap,
165 std::string theArgumentName,
166 std::string thePrefix);
170 DumpToPython(SALOMEDS::Study_ptr theStudy,
171 CORBA::Boolean theIsPublished,
172 CORBA::Boolean& theIsValidScript,
173 SALOMEDS::SObject_ptr theSObject,
174 std::ostream& theStr,
175 TName2EntryMap& theName2EntryMap,
176 TEntry2NameMap& theEntry2NameMap,
177 std::string theArgumentName,
178 std::string thePrefix);
181 //---------------------------------------------------------------------------
182 void SetClippingPlane(Prs3d_i* thePrs, string theName,
183 std::ostream& theStr,
184 std::string thePrefix)
186 VISU_CutPlaneFunction* aPlane;
187 VISU_Gen_i* aGen = VISU_Gen_i::GetVisuGenImpl();
188 VISU_ClippingPlaneMgr& aMgr = aGen->GetClippingPlaneMgr();
190 for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) {
191 aPlane = dynamic_cast<VISU_CutPlaneFunction*>(thePrs->GetClippingPlane(i));
193 if (!aPlane->isAuto()) {
194 aId = aMgr.GetPlaneId(aPlane);
196 theStr<<thePrefix<<"aVisu.ApplyClippingPlane("<<theName<<", "<<aId<<")"<<endl;
205 Prs3dToPython(VISU::Prs3d_i* theServant,
206 std::ostream& theStr,
207 const std::string& theName,
208 std::string thePrefix)
211 theServant->GetOffset(x,y,z);
212 theStr<<thePrefix<<theName<<".SetOffset("<<x<<", "<<y<<", "<<z<<")"<<endl;
213 SetClippingPlane(theServant, theName, theStr, thePrefix);
216 //---------------------------------------------------------------------------
217 struct TColoredPrs3dFactory
221 operator()(std::ostream& theStr,
222 std::string thePrefix)
230 struct TCreateFromResult: TColoredPrs3dFactory
232 VISU::ColoredPrs3d_i* myServant;
233 std::string myConstructorName;
234 std::string myArgumentName;
236 SALOMEDS::SObject_var mySObject;
239 TCreateFromResult(const SALOMEDS::SObject_var& theSObject,
240 VISU::ColoredPrs3d_i* theServant,
241 const std::string& theName,
242 const std::string& theConstructorName,
243 const std::string& theArgumentName):
244 myServant(theServant),
245 myConstructorName(theConstructorName),
246 myArgumentName(theArgumentName),
247 mySObject(theSObject),
253 operator()(std::ostream& theStr,
254 std::string thePrefix)
257 switch(myServant->GetEntity()){
259 aParam = "VISU.NODE";
262 aParam = "VISU.EDGE";
265 aParam = "VISU.FACE";
268 aParam = "VISU.CELL";
272 theStr<<thePrefix<<myName<<" = aVisu."<<myConstructorName<<"("<<myArgumentName<<
273 ", '"<<myServant->GetCMeshName()<<"'"<<
275 ", '"<<myServant->GetCFieldName()<<"'"<<
276 ", "<<myServant->GetTimeStampNumber()<<
279 theStr<<thePrefix<<"if "<<myName<<" != None:"<<endl;
282 // Add to Name->Object map
283 theStr<<thePrefix<<"aName2ObjectMap['"<<myName<<"'] = "<<myName<<endl;
285 // Set name (as this object could be renamed by user)
286 CORBA::String_var aNameInStudy = mySObject->GetName();
287 theStr<<thePrefix<<"visu.SetName("<<myName<<", '"<<aNameInStudy.in()<<"')"<<endl;
294 //---------------------------------------------------------------------------
296 ColoredPrs3dToPython(SALOMEDS::SObject_ptr theSObject,
297 VISU::ColoredPrs3d_i* theServant,
298 std::ostream& theStr,
299 const std::string& theName,
300 TColoredPrs3dFactory& thePrsFactory,
301 std::string thePrefix)
303 thePrefix = thePrsFactory(theStr, thePrefix);
305 // Set parameters common for all Prs3d objects (offset values)
306 Prs3dToPython(theServant, theStr, theName, thePrefix);
308 theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<", "<<theServant->GetPosY()<<")"<<endl;
309 theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<", "<<theServant->GetHeight()<<")"<<endl;
310 theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
311 theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
312 theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
315 switch(theServant->GetBarOrientation()){
316 case ColoredPrs3dBase::HORIZONTAL:
317 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
319 case ColoredPrs3dBase::VERTICAL:
320 aParam = "VISU.ColoredPrs3d.VERTICAL";
323 theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
325 theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
327 if(theServant->IsRangeFixed())
328 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
330 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
332 const VISU::ColoredPrs3d_i::TGroupNames aGroupNames = theServant->GetGroupNames();
333 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
334 for(; anIter != aGroupNames.end(); anIter++){
335 const std::string& aGroupName = *anIter;
336 theStr<<thePrefix<<theName<<".AddMeshOnGroup('"<<aGroupName<<"')"<<endl;
343 //---------------------------------------------------------------------------
345 GaussPointsToPython(SALOMEDS::SObject_ptr theSObject,
346 VISU::GaussPoints_i* theServant,
347 std::ostream& theStr,
348 const std::string& theName,
349 TColoredPrs3dFactory& thePrsFactory,
350 std::string thePrefix)
352 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
353 theStr<<thePrefix<<endl;
355 bool aBoolean = theServant->GetIsActiveLocalScalarBar();
356 theStr<<thePrefix<<theName<<".SetIsActiveLocalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
359 aBoolean = theServant->GetIsDispGlobalScalarBar();
360 theStr<<thePrefix<<theName<<".SetIsDispGlobalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
363 theStr<<thePrefix<<theName<<".SetSpacing("<<theServant->GetSpacing()<<")"<<endl;
365 aBoolean = theServant->GetBiColor();
366 theStr<<thePrefix<<theName<<".SetBiColor("<<GetBoolean(aBoolean)<<")"<<endl;
368 aBoolean = theServant->GetIsDeformed();
369 theStr<<thePrefix<<theName<<".SetIsDeformed("<<GetBoolean(aBoolean)<<")"<<endl;
370 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
373 switch(theServant->GetPrimitiveType()){
374 case VISU::GaussPoints::SPRITE :
375 aParam = "VISU.GaussPoints.SPRITE";
377 case VISU::GaussPoints::POINT :
378 aParam = "VISU.GaussPoints.POINT";
380 case VISU::GaussPoints::SPHERE :
381 aParam = "VISU.GaussPoints.SPHERE";
384 theStr<<thePrefix<<theName<<".SetPrimitiveType("<<aParam<<")"<<endl;
386 theStr<<thePrefix<<theName<<".SetClamp("<<theServant->GetClamp()<<")"<<endl;
388 QString aMainTexture = theServant->GetQMainTexture();
389 QString anAlphaTexture = theServant->GetQAlphaTexture();
390 theStr<<thePrefix<<theName<<".SetTextures('"<<aMainTexture.toLatin1().data()<<"', '"<<anAlphaTexture.toLatin1().data()<<"')"<<endl;
392 theStr<<thePrefix<<theName<<".SetAlphaThreshold("<<theServant->GetAlphaThreshold()<<")"<<endl;
394 theStr<<thePrefix<<theName<<".SetResolution("<<theServant->GetResolution()<<")"<<endl;
396 theStr<<thePrefix<<theName<<".SetFaceLimit("<<theServant->GetFaceLimit()<<")"<<endl;
398 aBoolean = theServant->GetIsColored();
399 theStr<<thePrefix<<theName<<".SetIsColored("<<GetBoolean(aBoolean)<<")"<<endl;
402 theStr<<thePrefix<<theName<<".SetMinSize("<<theServant->GetMinSize()<<")"<<endl;
403 theStr<<thePrefix<<theName<<".SetMaxSize("<<theServant->GetMaxSize()<<")"<<endl;
405 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
406 theStr<<thePrefix<<theName<<".SetGeomSize("<<theServant->GetGeomSize()<<")"<<endl;
409 theStr<<thePrefix<<theName<<".SetMagnification("<<theServant->GetMagnification()<<")"<<endl;
410 theStr<<thePrefix<<theName<<".SetMagnificationIncrement("<<theServant->GetMagnificationIncrement()<<")"<<endl;
412 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
413 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
419 //---------------------------------------------------------------------------
421 ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
422 VISU::ScalarMap_i* theServant,
423 std::ostream& theStr,
424 const std::string& theName,
425 TColoredPrs3dFactory& thePrsFactory,
426 std::string thePrefix)
428 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
429 theStr<<thePrefix<<endl;
432 switch(theServant->GetScaling()){
434 aParam = "VISU.LINEAR";
437 aParam = "VISU.LOGARITHMIC";
440 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
441 theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
442 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
447 //---------------------------------------------------------------------------
449 MonoColorPrsToPython(SALOMEDS::SObject_ptr theSObject,
450 VISU::MonoColorPrs_i* theServant,
451 std::ostream& theStr,
452 const std::string& theName,
453 TColoredPrs3dFactory& thePrsFactory,
454 std::string thePrefix)
456 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
457 theStr<<thePrefix<<endl;
458 theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
459 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
463 //---------------------------------------------------------------------------
465 DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
466 VISU::DeformedShape_i* theServant,
467 std::ostream& theStr,
468 const std::string& theName,
469 TColoredPrs3dFactory& thePrsFactory,
470 std::string thePrefix)
472 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
473 theStr<<thePrefix<<endl;
475 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
476 // theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
477 // theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
483 //---------------------------------------------------------------------------
485 StreamLinesToPython(SALOMEDS::SObject_ptr theSObject,
486 VISU::StreamLines_i* theServant,
487 std::ostream& theStr,
488 TEntry2NameMap& theEntry2NameMap,
489 const std::string& theName,
490 TColoredPrs3dFactory& thePrsFactory,
491 std::string thePrefix)
493 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
494 // thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
495 theStr<<thePrefix<<endl;
498 switch(theServant->GetDirection()){
499 case StreamLines::FORWARD:
500 aParam = "VISU.StreamLines.FORWARD";
502 case StreamLines::BACKWARD:
503 aParam = "VISU.StreamLines.BACKWARD";
505 case StreamLines::BOTH:
506 aParam = "VISU.StreamLines.BOTH";
510 theStr<<thePrefix<<"aPrs3d = None"<<endl;
511 VISU::Prs3d_var aPrs3d = theServant->GetSource();
512 if(!CORBA::is_nil(aPrs3d)){
513 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
514 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
515 CORBA::String_var anID = aSObject->GetID();
516 std::string anArg = theEntry2NameMap[anID.in()];
517 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
519 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
523 theStr<<thePrefix<<theName<<".SetParams("<<
524 theServant->GetIntegrationStep()<<", "<<
525 theServant->GetPropagationTime()<<", "<<
526 theServant->GetStepLength()<<", "<<
528 theServant->GetUsedPoints()<<", "<<
536 //---------------------------------------------------------------------------
538 DeformedShapeAndScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
539 VISU::DeformedShapeAndScalarMap_i* theServant,
540 std::ostream& theStr,
541 const std::string& theName,
542 TColoredPrs3dFactory& thePrsFactory,
543 std::string thePrefix)
545 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
546 theStr<<thePrefix<<endl;
548 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
549 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
552 VISU::Entity anEntity = theServant->GetScalarEntity();
555 aParam = "VISU.NODE";
558 aParam = "VISU.EDGE";
561 aParam = "VISU.FACE";
564 aParam = "VISU.CELL";
568 CORBA::String_var aFieldName = theServant->GetScalarFieldName();
569 CORBA::Long aTimeStampNumber = theServant->GetScalarTimeStampNumber();
571 theStr<<thePrefix<<theName<<".SetScalarField("<<
573 "'"<<aFieldName<<"', "<<
581 //---------------------------------------------------------------------------
583 VectorsToPython(SALOMEDS::SObject_ptr theSObject,
584 VISU::Vectors_i* theServant,
585 std::ostream& theStr,
586 const std::string& theName,
587 TColoredPrs3dFactory& thePrsFactory,
588 std::string thePrefix)
590 thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
591 theStr<<thePrefix<<endl;
593 theStr<<thePrefix<<theName<<".SetLineWidth("<<theServant->GetLineWidth()<<")"<<endl;
596 switch(theServant->GetGlyphType()){
598 aParam = "VISU.Vectors.ARROW";
601 aParam = "VISU.Vectors.CONE2";
604 aParam = "VISU.Vectors.CONE6";
607 aParam = "VISU.Vectors.NONE";
610 theStr<<thePrefix<<theName<<".SetGlyphType("<<aParam<<")"<<endl;
612 switch(theServant->GetGlyphPos()){
613 case Vectors::CENTER:
614 aParam = "VISU.Vectors.CENTER";
617 aParam = "VISU.Vectors.TAIL";
620 aParam = "VISU.Vectors.HEAD";
623 theStr<<thePrefix<<theName<<".SetGlyphPos("<<aParam<<")"<<endl;
629 //---------------------------------------------------------------------------
631 IsoSurfacesToPython(SALOMEDS::SObject_ptr theSObject,
632 VISU::IsoSurfaces_i* theServant,
633 std::ostream& theStr,
634 const std::string& theName,
635 TColoredPrs3dFactory& thePrsFactory,
636 std::string thePrefix)
638 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
639 theStr<<thePrefix<<endl;
641 theStr<<thePrefix<<theName<<".SetNbSurfaces("<<theServant->GetNbSurfaces()<<")"<<endl;
642 theStr<<thePrefix<<theName<<".ShowLabels("<<theServant->IsLabeled()<<","<<theServant->GetNbLabels()<<")"<<endl;
648 //---------------------------------------------------------------------------
650 CutPlanesToPython(SALOMEDS::SObject_ptr theSObject,
651 VISU::CutPlanes_i* theServant,
652 std::ostream& theStr,
653 const std::string& theName,
654 TColoredPrs3dFactory& thePrsFactory,
655 std::string thePrefix)
657 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
658 theStr<<thePrefix<<endl;
661 switch(theServant->GetOrientationType()){
663 aParam = "VISU.CutPlanes.XY";
666 aParam = "VISU.CutPlanes.YZ";
669 aParam = "VISU.CutPlanes.ZX";
672 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
674 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
675 CORBA::Long aNbPlanes = theServant->GetNbPlanes();
676 theStr<<thePrefix<<theName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
678 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
679 if(!theServant->IsDefault(anId))
680 theStr<<thePrefix<<theName<<".SetPlanePosition("<<anId<<", "<<theServant->GetPlanePosition(anId)<<")"<<endl;
683 theStr<<thePrefix<<theName<<".UseDeformation("<<GetBoolean(theServant->IsDeformed())<<")"<<endl;
684 if(theServant->IsDeformed()){
685 theStr<< thePrefix << theName << ".SetScale(" << theServant->GetScale()<<")"<<endl;
686 std::string aStringEntity;
687 VISU::Entity anEntity = theServant->GetVectorialFieldEntity();
690 aStringEntity = "VISU.NODE";
693 aStringEntity = "VISU.EDGE";
696 aStringEntity = "VISU.FACE";
699 aStringEntity = "VISU.CELL";
702 theStr<< thePrefix << theName << ".SetVectorialField("<<aStringEntity<<", '" << theServant->GetVectorialFieldName() <<"')"<<endl;
708 //---------------------------------------------------------------------------
710 CutLinesToPython(SALOMEDS::SObject_ptr theSObject,
711 VISU::CutLines_i* theServant,
712 std::ostream& theStr,
713 const std::string& theName,
714 TColoredPrs3dFactory& thePrsFactory,
715 std::string thePrefix)
717 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
718 theStr<<thePrefix<<endl;
721 switch(theServant->GetOrientationType()){
723 aParam = "VISU.CutPlanes.XY";
726 aParam = "VISU.CutPlanes.YZ";
729 aParam = "VISU.CutPlanes.ZX";
732 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
734 switch(theServant->GetOrientationType2()){
736 aParam = "VISU.CutPlanes.XY";
739 aParam = "VISU.CutPlanes.YZ";
742 aParam = "VISU.CutPlanes.ZX";
745 theStr<<thePrefix<<theName<<".SetOrientation2("<<aParam<<", "<<theServant->GetRotateX2()<<", "<<theServant->GetRotateY2()<<")"<<endl;
747 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
748 theStr<<thePrefix<<theName<<".SetDisplacement2("<<theServant->GetDisplacement2()<<")"<<endl;
750 if(!theServant->IsDefault())
751 theStr<<thePrefix<<theName<<".SetBasePlanePosition("<<theServant->GetBasePlanePosition()<<")"<<endl;
753 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
754 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
756 CORBA::Long aNbLines = theServant->GetNbLines();
757 theStr<<thePrefix<<theName<<".SetNbLines("<<aNbLines<<")"<<endl;
758 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
759 if(!theServant->IsDefaultPosition(anId))
760 theStr<<thePrefix<<theName<<".SetLinePosition("<<anId<<", "<<theServant->GetLinePosition(anId)<<")"<<endl;
767 //---------------------------------------------------------------------------
769 Plot3DToPython(SALOMEDS::SObject_ptr theSObject,
770 VISU::Plot3D_i* theServant,
771 std::ostream& theStr,
772 const std::string& theName,
773 TColoredPrs3dFactory& thePrsFactory,
774 std::string thePrefix)
776 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
777 theStr<<thePrefix<<endl;
780 switch(theServant->GetOrientationType()){
782 aParam = "VISU.Plot3D.XY";
785 aParam = "VISU.Plot3D.YZ";
788 aParam = "VISU.Plot3D.ZX";
791 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
793 theStr<<thePrefix<<theName<<".SetPlanePosition("<<theServant->GetPlanePosition()<<", "<<theServant->IsPositionRelative()<<")"<<endl;
794 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
795 theStr<<thePrefix<<theName<<".SetContourPrs("<<theServant->GetIsContourPrs()<<")"<<endl;
796 theStr<<thePrefix<<theName<<".SetNbOfContours("<<theServant->GetNbOfContours()<<")"<<endl;
801 //---------------------------------------------------------------------------
803 void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
804 CORBA::Boolean theIsPublished,
805 CORBA::Boolean& theIsValidScript,
806 SALOMEDS::SObject_ptr theSObject,
807 std::ostream& theStr,
808 TName2EntryMap& theName2EntryMap,
809 TEntry2NameMap& theEntry2NameMap,
810 std::string theArgumentName,
811 std::string thePrefix);
813 //---------------------------------------------------------------------------
814 template<class TTableAttr>
816 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
817 CORBA::Boolean theIsPublished,
818 CORBA::Boolean& theIsValidScript,
819 SALOMEDS::SObject_ptr theSObject,
820 TTableAttr theTableAttr,
821 const std::string& theAttrName,
822 std::ostream& theStr,
823 TName2EntryMap& theName2EntryMap,
824 TEntry2NameMap& theEntry2NameMap,
825 std::string theArgumentName,
826 std::string thePrefix)
828 SALOMEDS::GenericAttribute_var anAttr;
829 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
830 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
831 SALOMEDS::AttributeString_var aComment =
832 SALOMEDS::AttributeString::_narrow(anAttr);
833 CORBA::String_var aValue = aComment->Value();
834 Storable::TRestoringMap aMap;
835 Storable::StringToMap(aValue.in(),aMap);
837 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
839 if(strcmp(aMethodName.toLatin1().data(),"ImportTables") == 0){
845 std::string aSObjectName = GetName(theSObject);
846 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
847 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
850 theStr<<thePrefix<<"aBuilder.SetName("<<aSObjectName<<", \""<<theSObject->GetName()<<"\")"<<endl; // Fix for IPAL13165
851 std::string aName = "aTableAttr";
852 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
853 aSObjectName<<", '"<<theAttrName<<"')"<<endl;
855 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
856 std::string aPrefix = thePrefix;
859 CORBA::String_var aString = theTableAttr->GetTitle();
860 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
862 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
863 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
865 CORBA::Long aNbRows = theTableAttr->GetNbRows();
867 // push values and their indices into streams
868 strstream values, rows, columns;
870 for(CORBA::Long i = 1; i <= aNbColumns; i++){
871 for(CORBA::Long j = aNbRows; j > 0; j--){
872 if(theTableAttr->HasValue(j,i)){
873 values << comma << theTableAttr->GetValue(j,i);
875 columns << comma << i;
881 // push titles and units into streams
882 strstream rowUnits, rowTitles, colTitles;
883 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
884 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
886 for(CORBA::Long j = 1; j <= aNbRows; j++){
887 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
888 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
892 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
894 for(CORBA::Long j = 1; j <= aNbColumns; j++){
895 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
905 // write FillTable command
906 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
907 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
908 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
909 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
910 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
911 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
912 theStr<< thePrefix << "visu.FillTable( "
914 << aName << "_values, "
915 << aName << "_rows, "
916 << aName << "_columns, "
917 << aName << "_rTitles, "
918 << aName << "_rUnits, "
919 << aName << "_cTitles )" << endl;
921 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
922 theStr<<thePrefix<<endl;
923 std::string aName = "aTable";
924 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
925 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
926 theArgumentName = aName;
928 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
929 std::string aPrefix2 = thePrefix + PREFIX;
931 // Set name (as this object could be renamed by user)
932 CORBA::String_var aNameInStudy = theSObject->GetName();
933 theStr<<aPrefix2<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 1"<<endl;
935 DumpChildrenToPython(theStudy,
945 theStr<<aPrefix2<<"pass"<<endl<<endl;
948 theStr<<thePrefix<<"pass"<<endl<<endl;
949 theStr<<aPrefix<<"pass"<<endl<<endl;
953 //---------------------------------------------------------------------------
955 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
956 CORBA::Boolean theIsPublished,
957 CORBA::Boolean& theIsValidScript,
958 SALOMEDS::SObject_ptr theSObject,
959 std::ostream& theStr,
960 TName2EntryMap& theName2EntryMap,
961 TEntry2NameMap& theEntry2NameMap,
962 std::string theArgumentName,
963 std::string thePrefix)
965 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
966 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
967 SALOMEDS::SObject_var aSObject = aChildItet->Value();
968 DumpToPython(theStudy,
981 //---------------------------------------------------------------------------
983 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
984 CORBA::Boolean theIsPublished,
985 CORBA::Boolean& theIsValidScript,
986 SALOMEDS::SObject_ptr theSObject,
987 std::ostream& theStr,
988 TName2EntryMap& theName2EntryMap,
989 TEntry2NameMap& theEntry2NameMap,
990 std::string theArgumentName,
991 std::string thePrefix)
993 SALOMEDS::GenericAttribute_var anAttr;
994 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
995 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
996 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
998 TableAttrToPython(theStudy,
1003 "AttributeTableOfInteger",
1010 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
1011 SALOMEDS::AttributeTableOfReal_var aTableAttr =
1012 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1014 TableAttrToPython(theStudy,
1019 "AttributeTableOfReal",
1030 //---------------------------------------------------------------------------
1032 DumpToPython(SALOMEDS::Study_ptr theStudy,
1033 CORBA::Boolean theIsPublished,
1034 CORBA::Boolean& theIsValidScript,
1035 SALOMEDS::SObject_ptr theSObject,
1036 std::ostream& theStr,
1037 TName2EntryMap& theName2EntryMap,
1038 TEntry2NameMap& theEntry2NameMap,
1039 std::string theArgumentName,
1040 std::string thePrefix)
1042 std::string aName = GetName(theSObject);
1046 CORBA::String_var anID = theSObject->GetID();
1047 CORBA::String_var aNameInStudy = theSObject->GetName();
1049 CORBA::Object_var anObj = SObjectToObject(theSObject);
1050 if (!CORBA::is_nil(anObj)) {
1051 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1052 if(!CORBA::is_nil(aBase)){
1053 std::string aName = GenerateName(theSObject, theName2EntryMap, theEntry2NameMap);
1055 VISU::VISUType aType = aBase->GetType();
1058 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
1059 std::string aFileName = aServant->GetInitFileName();
1060 Result_i::ECreationId anId = aServant->GetCreationId();
1061 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
1063 case Result_i::eImportFile:
1064 theStr<<thePrefix<<aName<<" = aVisu.CreateResult('"<<aFileName<<"')"<<endl;
1066 theStr<<thePrefix<<aName<<".SetBuildGroups("<<
1067 GetBoolean(aServant->IsGroupsDone())<<")"<<
1070 theStr<<thePrefix<<aName<<".SetBuildFields("<<
1071 GetBoolean(aServant->IsFieldsDone())<<", "<<
1072 GetBoolean(aServant->IsMinMaxDone())<<")"<<
1075 theStr<<thePrefix<<aName<<".Build(False, True)"<<endl;
1077 theStr<<thePrefix<<"if "<<aName<<".IsDone() :"<<endl;
1079 case Result_i::eCopyAndImportFile:
1080 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
1081 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1085 thePrefix += PREFIX;
1087 VISU::Result::EntityNames_var aMeshNames = aServant->GetMeshNames();
1088 if (aMeshNames->length() > 0) {
1089 for(size_t aMeshId = 0; aMeshId < aMeshNames->length(); aMeshId++){
1090 CORBA::String_var aMeshName = aMeshNames[aMeshId];
1091 VISU::Result::EntityNames_var aParts = aServant->GetPartNames(aMeshName);
1092 if (aParts->length() > 0) {
1093 for(size_t aPartId = 0; aPartId < aParts->length(); aPartId++){
1094 CORBA::String_var aPart = aParts[aPartId];
1095 VISU::Result::Resolution aResolution = aServant->GetResolution(aMeshName, aPart);
1097 switch(aResolution){
1098 case VISU::Result::FULL:
1099 aParam = "VISU.Result.FULL";
1101 case VISU::Result::MEDIUM:
1102 aParam = "VISU.Result.MEDIUM";
1104 case VISU::Result::LOW:
1105 aParam = "VISU.Result.LOW";
1107 case VISU::Result::HIDDEN:
1108 aParam = "VISU.Result.HIDDEN";
1111 theStr<<thePrefix<<aName<<".SetResolution('"<<aMeshName.in()<<"', '"<<aPart.in()<<"', "<<aParam<<")"<<endl;
1113 theStr<<thePrefix<<endl;
1119 theArgumentName = aName;
1120 DumpChildrenToPython(theStudy,
1130 theStr<<thePrefix<<"pass"<<endl<<endl;
1132 SALOMEDS::SObject_var aRefSObj;
1133 if(theSObject->FindSubObject(1,aRefSObj)){
1134 SALOMEDS::SObject_var aTargetRefSObj;
1135 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
1136 CORBA::String_var aString = aTargetRefSObj->GetName();
1137 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
1138 theStr<<thePrefix<<"if aSObject:"<<endl;
1139 thePrefix += PREFIX;
1140 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
1141 theStr<<thePrefix<<"if anObject:"<<endl;
1142 std::string aPrefix1 = thePrefix;
1143 thePrefix += PREFIX;
1146 case Result_i::eImportMed:
1147 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
1149 case Result_i::eImportMedField:
1150 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
1154 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1155 std::string aPrefix2 = thePrefix;
1156 thePrefix += PREFIX;
1158 theArgumentName = aName;
1159 DumpChildrenToPython(theStudy,
1169 theStr<<thePrefix<<"pass"<<endl<<endl;
1170 theStr<<aPrefix2<<"pass"<<endl<<endl;
1171 theStr<<aPrefix1<<"pass"<<endl<<endl;
1178 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
1179 VISU::Entity anEntity = aServant->GetEntity();
1180 const std::string& aSubMeshName = aServant->GetSubMeshName();
1185 aParam = "VISU.NODE";
1188 aParam = "VISU.EDGE";
1191 aParam = "VISU.FACE";
1194 aParam = "VISU.CELL";
1198 if(aSubMeshName == "")
1199 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
1200 ", '"<<aServant->GetCMeshName()<<"'"<<
1204 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
1205 ", '"<<aServant->GetCMeshName()<<"'"<<
1207 ", '"<<aSubMeshName<<"'"<<
1210 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
1211 ", '"<<aServant->GetCMeshName()<<"'"<<
1212 ", '"<<aSubMeshName<<"'"<<
1215 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1216 thePrefix += PREFIX;
1218 // Add to Name->Object map
1219 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
1221 // Set name (as this object could be renamed by user)
1222 theStr<<thePrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1224 // Set parameters common for all Prs3d objects (offset values)
1225 Prs3dToPython(aServant,theStr,aName,thePrefix);
1227 // Set presentation parameters
1228 SALOMEDS::Color aColor;
1229 aColor = aServant->GetCellColor();
1230 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
1231 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1233 aColor = aServant->GetNodeColor();
1234 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
1235 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1237 aColor = aServant->GetLinkColor();
1238 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
1239 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1242 switch(aServant->GetPresentationType()){
1244 aParam = "VISU.POINT";
1247 aParam = "VISU.WIREFRAME";
1250 aParam = "VISU.SHADED";
1253 aParam = "VISU.INSIDEFRAME";
1256 aParam = "VISU.SURFACEFRAME";
1259 aParam = "VISU.SHRINK";
1262 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
1263 theStr<<thePrefix<<aName<<".SetShrink("<<(aServant->IsShrank()? "True" : "False")<<")"<<endl;
1264 theStr<<thePrefix<<endl;
1266 std::string aQuad2DPresent;
1267 switch(aServant->GetQuadratic2DPresentationType()){
1269 aQuad2DPresent = "VISU.LINES";
1272 aQuad2DPresent = "VISU.ARCS";
1276 theStr<<thePrefix<<aName<<".SetQuadratic2DPresentationType("<<aQuad2DPresent<<")"<<endl;
1278 DumpChildrenToPython(theStudy,
1288 theStr<<thePrefix<<"pass"<<endl<<endl;
1292 case VISU::TSCALARMAP:
1293 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
1294 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "ScalarMapOnField", theArgumentName);
1295 thePrefix = ScalarMapToPython(theSObject, aServant, theStr,aName, aPrsFactory, thePrefix);
1296 theStr<<thePrefix<<"pass"<<endl<<endl;
1299 case VISU::TDEFORMEDSHAPE:
1300 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
1301 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeOnField", theArgumentName);
1302 thePrefix = DeformedShapeToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1303 theStr<<thePrefix<<"pass"<<endl<<endl;
1306 case VISU::TSTREAMLINES:
1307 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
1308 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "StreamLinesOnField", theArgumentName);
1309 thePrefix = StreamLinesToPython(theSObject, aServant, theStr, theEntry2NameMap, aName, aPrsFactory, thePrefix);
1310 theStr<<thePrefix<<"pass"<<endl<<endl;
1313 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1314 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1315 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(GetServant(anObj).in())){
1316 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeAndScalarMapOnField", theArgumentName);
1317 thePrefix = DeformedShapeAndScalarMapToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1318 theStr<<thePrefix<<"pass"<<endl<<endl;
1321 case VISU::TVECTORS:
1322 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
1323 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "VectorsOnField", theArgumentName);
1324 thePrefix = VectorsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1325 theStr<<thePrefix<<"pass"<<endl<<endl;
1328 case VISU::TISOSURFACES:
1329 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
1330 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "IsoSurfacesOnField", theArgumentName);
1331 thePrefix = IsoSurfacesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1332 theStr<<thePrefix<<"pass"<<endl<<endl;
1335 case VISU::TCUTPLANES:
1336 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
1337 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutPlanesOnField", theArgumentName);
1338 thePrefix = CutPlanesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1339 theStr<<thePrefix<<"pass"<<endl<<endl;
1342 case VISU::TCUTLINES:
1343 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
1344 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutLinesOnField", theArgumentName);
1345 thePrefix = CutLinesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1347 theArgumentName = aName;
1348 DumpChildrenToPython(theStudy,
1358 theStr<<thePrefix<<"pass"<<endl<<endl;
1362 if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
1363 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
1364 thePrefix = Plot3DToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1365 theStr<<thePrefix<<"pass"<<endl<<endl;
1368 case VISU::TPOINTMAP3D:
1369 if (PointMap3d_i* aServant = dynamic_cast<PointMap3d_i*>(GetServant(anObj).in())) {
1370 CORBA::Short aTag = theSObject->Tag();
1371 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1372 theStr<<thePrefix<<"if anIsFound:"<<endl;
1373 thePrefix += PREFIX;
1375 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1376 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1378 // Set name (as this object could be renamed by user)
1379 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1381 // Set PointMap3D Properties
1383 theStr<<thePrefix<<aName<<".SetScaleFactor("<<aServant->GetScaleFactor()<<")"<<endl;
1384 theStr<<thePrefix<<aName<<".SetContourPrs("<<aServant->GetIsContourPrs()<<")"<<endl;
1385 theStr<<thePrefix<<aName<<".SetNbOfContours("<<aServant->GetNbOfContours()<<")"<<endl;
1388 switch(aServant->GetScaling()){
1390 aParam = "VISU.LINEAR";
1393 aParam = "VISU.LOGARITHMIC";
1396 theStr<<thePrefix<<aName<<".SetScaling("<<aParam<<")"<<endl;
1398 theStr<<thePrefix<<aName<<".SetNbColors("<<aServant->GetNbColors()<<")"<<endl;
1399 theStr<<thePrefix<<aName<<".SetLabels("<<aServant->GetLabels()<<")"<<endl;
1401 switch(aServant->GetBarOrientation()){
1402 case ColoredPrs3dBase::HORIZONTAL:
1403 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
1405 case ColoredPrs3dBase::VERTICAL:
1406 aParam = "VISU.ColoredPrs3d.VERTICAL";
1409 theStr<<thePrefix<<aName<<".SetBarOrientation("<<aParam<<")"<<endl;
1411 if(aServant->IsRangeFixed())
1412 theStr<<thePrefix<<aName<<".SetRange("<<aServant->GetMin()<<", "<<aServant->GetMax()<<")"<<endl;
1414 theStr<<thePrefix<<aName<<".SetSourceRange()"<<endl;
1416 theStr<<thePrefix<<aName<<".SetPosition("<<aServant->GetPosX()<<", "<<aServant->GetPosY()<<")"<<endl;
1417 theStr<<thePrefix<<aName<<".SetSize("<<aServant->GetWidth()<<", "<<aServant->GetHeight()<<")"<<endl;
1420 aServant->GetOffset(dx, dy, dz);
1421 theStr<<thePrefix<<aName<<".SetOffset("<<dx<<", "<<dy<<", "<<dz<<")"<<endl;
1424 theStr<<thePrefix<<endl;
1426 theArgumentName = aName;
1427 DumpChildrenToPython(theStudy,
1437 theStr<<thePrefix<<"pass"<<endl<<endl;
1440 case VISU::TGAUSSPOINTS:
1441 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(GetServant(anObj).in())){
1442 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "GaussPointsOnField", theArgumentName);
1443 thePrefix = GaussPointsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1444 theStr<<thePrefix<<"pass"<<endl<<endl;
1448 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
1450 bool withZ = aServant->GetZRow()>0;
1452 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
1456 theArgumentName<< // table
1457 ", "<<aServant->GetHRow()<< // H row
1458 ", "<<aServant->GetVRow(); // V row
1460 theStr << ", " << aServant->GetZRow(); // Z row
1462 theStr << ", '"<<aServant->GetTitle()<<"'"; // title
1463 SALOMEDS::Color aColor = aServant->GetColor();
1464 theStr << ",SALOMEDS.Color("<<
1465 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<")"; // color
1468 switch(aServant->GetMarker()){
1469 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
1470 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
1471 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
1472 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
1473 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
1474 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
1475 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
1476 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
1477 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
1478 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
1480 theStr<<", "<<aParam; // marker
1482 switch(aServant->GetLine()){
1483 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
1484 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
1485 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
1486 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
1487 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
1488 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
1490 theStr<<", "<<aParam<<", "<<aServant->GetLineWidth()<<")"<<endl; // line type,width
1494 if(dynamic_cast<Table_i*>(GetServant(anObj).in())){
1495 SALOMEDS::GenericAttribute_var anAttr;
1496 if(theSObject->FindAttribute(anAttr,"AttributeString")){
1497 using namespace SALOMEDS;
1498 AttributeString_var aComment = AttributeString::_narrow(anAttr);
1499 CORBA::String_var aValue = aComment->Value();
1500 Storable::TRestoringMap aMap;
1501 Storable::StringToMap(aValue.in(),aMap);
1503 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1505 if( aSourceId == "CutLines" ){
1506 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
1507 thePrefix += PREFIX;
1509 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
1510 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
1511 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
1512 theStr<<thePrefix<<"if aSObject:"<<endl;
1513 std::string aPrefix = thePrefix;
1514 thePrefix += PREFIX;
1516 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1517 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1519 // Set name (as this object could be renamed by user)
1520 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 2"<<endl;
1522 theStr<<thePrefix<<endl;
1524 theArgumentName = aName;
1525 DumpChildrenToPython(theStudy,
1535 theStr<<thePrefix<<"pass"<<endl<<endl;
1536 theStr<<aPrefix<<"pass"<<endl<<endl;
1537 }else if( aSourceId == "TableFile" ){
1538 CORBA::Short aTag = theSObject->Tag();
1539 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1540 theStr<<thePrefix<<"if anIsFound:"<<endl;
1541 thePrefix += PREFIX;
1543 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1544 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1546 // Set name (as this object could be renamed by user)
1547 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1549 theStr<<thePrefix<<endl;
1551 theArgumentName = aName;
1552 DumpChildrenToPython(theStudy,
1562 theStr<<thePrefix<<"pass"<<endl<<endl;
1563 }else if( aSourceId == "TableAttr" ){
1564 theArgumentName = aName;
1565 DumpTableAttrToPython(theStudy,
1581 } else { /*if(!CORBA::is_nil(anObj))*/
1582 SALOMEDS::GenericAttribute_var anAttr;
1583 if (theSObject->FindAttribute(anAttr,"AttributeString")) {
1584 SALOMEDS::AttributeString_var aComment =
1585 SALOMEDS::AttributeString::_narrow(anAttr);
1586 CORBA::String_var aValue = aComment->Value();
1587 Storable::TRestoringMap aMap;
1588 Storable::StringToMap(aValue.in(),aMap);
1590 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1592 if (aTypeName == "ImportTables") {
1593 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1595 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1596 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.toLatin1().data()<<"')"<<endl;
1597 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1598 thePrefix += PREFIX;
1600 theArgumentName = aName;
1601 DumpChildrenToPython(theStudy,
1611 theStr<<thePrefix<<"pass"<<endl<<endl;
1614 } else if (aTypeName == "VIEW3D") {
1615 std::string aName = GetName(theSObject);
1616 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1618 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1619 thePrefix += PREFIX;
1621 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1622 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1624 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1625 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1627 theStr<<thePrefix<<"pass"<<endl<<endl;
1629 } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1630 // Set name (as this object could be renamed by user)
1631 string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1632 string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1633 string anEntityTypeKey = "myEntityId";
1634 if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1635 int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1636 std::string anEntityType;
1637 switch ((TEntity)anEntity) {
1638 case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1639 case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1640 case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1641 case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1644 if (aTypeName == "ENTITY" ) {
1645 theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1646 <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1648 else if (aTypeName == "FAMILY") {
1649 if (aSubMeshName != aNameInStudy.in()) {
1650 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1651 <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1655 if (aSubMeshName != aNameInStudy.in()) {
1656 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1657 <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1663 DumpTableAttrToPython(theStudy,
1675 DumpChildrenToPython(theStudy,
1687 //---------------------------------------------------------------------------
1689 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1690 CORBA::Boolean theIsPublished,
1691 CORBA::Boolean& theIsValidScript,
1692 SALOMEDS::SObject_ptr theSObject,
1693 std::ostream& theStr,
1694 TName2EntryMap& theName2EntryMap,
1695 TEntry2NameMap& theEntry2NameMap,
1696 std::string theArgumentName,
1697 std::string thePrefix)
1699 SALOMEDS::SObject_var aTargetRefSObj;
1700 if(theSObject->ReferencedObject(aTargetRefSObj)){
1701 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1702 if(CORBA::is_nil(anObj))
1705 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1706 if(CORBA::is_nil(aBase))
1709 if(aBase->GetType() == VISU::TCURVE){
1710 CORBA::String_var anID = aTargetRefSObj->GetID();
1711 std::string anArg = theEntry2NameMap[anID.in()];
1712 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1713 thePrefix += PREFIX;
1714 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1715 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1716 theStr<<thePrefix<<"pass"<<endl<<endl;
1722 //---------------------------------------------------------------------------
1724 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1725 CORBA::Boolean theIsPublished,
1726 CORBA::Boolean& theIsValidScript,
1727 SALOMEDS::SObject_ptr theSObject,
1728 std::ostream& theStr,
1729 TName2EntryMap& theName2EntryMap,
1730 TEntry2NameMap& theEntry2NameMap,
1731 std::string theArgumentName,
1732 std::string thePrefix)
1734 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1735 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1736 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1737 CORBA::Object_var anObj = SObjectToObject(aSObject);
1738 if(CORBA::is_nil(anObj))
1741 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1742 if(CORBA::is_nil(aBase))
1745 if(aBase->GetType() == VISU::TCONTAINER){
1746 theStr<<thePrefix<<endl;
1747 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1748 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1749 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1750 std::string aPrefix = thePrefix + PREFIX;
1751 theArgumentName = aName;
1753 // Set name (as this object could be renamed by user)
1754 CORBA::String_var aNameInStudy = aSObject->GetName();
1755 theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1757 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1758 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1759 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1760 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1763 theStr<<aPrefix<<"pass"<<endl<<endl;
1769 //---------------------------------------------------------------------------
1771 DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1772 CORBA::Boolean theIsPublished,
1773 CORBA::Boolean& theIsValidScript,
1774 SALOMEDS::SObject_ptr theSObject,
1775 std::ostream& theStr,
1776 TName2EntryMap& theName2EntryMap,
1777 TEntry2NameMap& theEntry2NameMap,
1778 std::string theArgumentName,
1779 std::string thePrefix)
1782 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1783 for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1784 SALOMEDS::SObject_var aSObject = anIter->Value();
1785 CORBA::Object_var anObj = SObjectToObject(aSObject);
1786 if(CORBA::is_nil(anObj))
1789 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1790 if(CORBA::is_nil(aBase))
1793 if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1794 ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1795 theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1796 theStr<<thePrefix<<"if aCache != None:"<<endl;
1798 std::string aPrefix = thePrefix + PREFIX;
1799 std::string anArgument;
1800 VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1802 case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1803 case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1805 theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1807 if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1808 theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1810 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1811 for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1812 SALOMEDS::SObject_var aSObject = aChildIter->Value();
1813 CORBA::Object_var anObject = SObjectToObject(aSObject);
1814 if (CORBA::is_nil(anObject))
1817 ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1821 ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1825 Result_i* aResult = aDevice->GetCResult();
1826 std::string aResultEntry = aResult->GetEntry();
1827 std::string aResultName = theEntry2NameMap[aResultEntry];
1829 ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1830 std::string anEntity;
1831 switch(anInput->myEntity){
1832 case VISU::NODE : anEntity = "VISU.NODE"; break;
1833 case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1834 case VISU::FACE : anEntity = "VISU.FACE"; break;
1835 case VISU::CELL : anEntity = "VISU.CELL"; break;
1839 theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
1840 aResultName<<", '"<<
1841 anInput->myMeshName<<"', "<<
1843 anInput->myFieldName<<"', "<<
1844 anInput->myTimeStampNumber<<")"<<
1847 std::string aComment = aDevice->GetComment();
1848 theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
1849 theStr<<aPrefix<<"if aHolder != None:"<<endl;
1851 std::string aPrefix2 = aPrefix + PREFIX;
1852 CORBA::String_var aNameInStudy = aSObject->GetName();
1853 theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
1854 theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
1855 theStr<<aPrefix2<<"if aDevice != None:"<<endl;
1857 std::string aPrefix3 = aPrefix2 + PREFIX;
1858 TColoredPrs3dFactory aPrsFactory;
1859 switch(aDevice->GetType()){
1860 case VISU::TSCALARMAP:
1861 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
1862 ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1865 case VISU::TDEFORMEDSHAPE:
1866 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
1867 DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1870 case VISU::TSTREAMLINES:
1871 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
1872 StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
1875 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1876 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1877 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
1878 DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1881 case VISU::TVECTORS:
1882 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
1883 VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1886 case VISU::TISOSURFACES:
1887 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
1888 IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1891 case VISU::TCUTPLANES:
1892 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
1893 CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1896 case VISU::TCUTLINES:
1897 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
1898 CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1902 if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
1903 Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1906 case VISU::TGAUSSPOINTS:
1907 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
1908 GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1912 theStr<<aPrefix3<<"pass"<<endl;
1914 theStr<<aPrefix2<<"pass"<<endl<<endl;
1917 theStr<<aPrefix<<"pass"<<endl;
1924 //---------------------------------------------------------------------------
1926 DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
1927 CORBA::Boolean theIsPublished,
1928 CORBA::Boolean& theIsValidScript,
1929 SALOMEDS::SObject_ptr theSObject,
1930 std::ostream& theStr,
1931 std::string thePrefix)
1934 if(!theIsPublished) return;
1936 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1937 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1938 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1940 SALOMEDS::GenericAttribute_var anAttr;
1941 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
1943 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
1944 QString value (aStringAttr->Value());
1945 if(value.isEmpty()) continue;
1947 VISU::Storable::TRestoringMap aMap;
1948 VISU::Storable::StringToMap(value, aMap);
1951 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
1952 if(!isExist || aTypeName != "ANIMATION") continue;
1955 theStr<<thePrefix<<endl;
1956 QString animName = aSObject->GetName();
1957 theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
1958 theStr<<thePrefix<<endl;
1959 theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
1960 theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
1961 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
1962 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
1966 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
1967 for (anIter->Init(); anIter->More(); anIter->Next()) {
1968 SALOMEDS::SObject_var anObj = anIter->Value();
1971 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
1972 if (anObj->FindAttribute(anAttr, "AttributeString")) {
1973 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
1974 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
1975 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
1978 SALOMEDS::SObject_var refObj;
1979 if(anObj->ReferencedObject(refObj)) {
1980 SALOMEDS::SObject_var father = refObj->GetFather();
1981 value = refObj->GetName();
1982 QString path(theStudy->GetObjectPath(father));
1983 //The following code requierd as a field name can contain '/' character
1984 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
1986 value = anObj->GetName();
1987 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
1990 SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
1991 for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
1992 SALOMEDS::SObject_var aSubObj = aSubIter->Value();
1994 theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
1995 value = aSubObj->GetName();
1996 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
1997 if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
1998 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
1999 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2000 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2008 theStr<<thePrefix<<endl;
2013 DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2014 CORBA::Boolean theIsPublished,
2015 CORBA::Boolean& theIsValidScript,
2016 SALOMEDS::SObject_ptr theSObject,
2017 std::ostream& theStr,
2018 std::string thePrefix,
2019 VISU_ClippingPlaneMgr& thePlaneMgr)
2022 if(!theIsPublished) return;
2024 VISU_CutPlaneFunction* aPlane;
2025 double aOrigin[3], aDir[3];
2026 for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2027 aPlane = thePlaneMgr.GetClippingPlane(i);
2028 aPlane->GetOrigin(aOrigin);
2029 aPlane->GetNormal(aDir);
2031 theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2032 aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2033 aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2034 aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;
2040 //---------------------------------------------------------------------------
2043 DumpPython(CORBA::Object_ptr theStudy,
2044 CORBA::Boolean theIsPublished,
2045 CORBA::Boolean& theIsValidScript)
2047 theIsValidScript = false;
2049 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2050 if(CORBA::is_nil(aStudy))
2051 return new Engines::TMPFile(0);
2053 TName2EntryMap aName2EntryMap;
2054 TEntry2NameMap aEntry2NameMap;
2062 std::string aPrefix(PREFIX);
2063 aStr<<"### This file is generated by SALOME automatically by dump python functionality"
2064 " of VISU component"<<endl<<endl;
2065 aStr<<"def RebuildData(theStudy):"<<endl;
2066 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2067 aStr<<aPrefix<<"import SALOME_MED"<<endl;
2068 aStr<<aPrefix<<"import SALOMEDS"<<endl;
2069 aStr<<aPrefix<<"import VISU"<<endl;
2070 aStr<<aPrefix<<"import visu"<<endl;
2072 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2073 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2074 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2075 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2076 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2079 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2081 VISU::DumpClippingPlanesToPython(aStudy,
2087 myClippingPlaneMgr);
2090 VISU::DumpChildrenToPython(aStudy,
2100 VISU::DumpContainersToPython(aStudy,
2110 VISU::DumpPrs3dCacheToPython(aStudy,
2120 VISU::DumpAnimationsToPython(aStudy,
2128 //Output the script that sets up the visul parameters.
2129 if(theIsPublished) {
2130 char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2131 if(script && strlen(script) > 0) {
2133 CORBA::string_free(script);
2137 aStr<<aPrefix<<"pass"<<endl;
2139 if(theIsPublished) { //SRN: define function for Animation
2141 //Define a function that find a SObject by its father's path and its name
2145 aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
2146 aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
2147 aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
2148 aStr<<aPrefix<<"while itr.More():"<<endl;
2149 aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
2150 aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
2151 aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
2152 aStr<<aPrefix<<aPrefix<<"pass"<<endl;
2153 aStr<<aPrefix<<"return None"<<endl;
2158 // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2159 // If the situation changes, then the following line should be removed, and theIsValidScript
2160 // should be set properly by those internal methods
2161 theIsValidScript = true;
2164 std::string aResult = aStr.str();
2165 //ofstream anFStream("/tmp/dump.py");
2166 //anFStream<<aResult<<endl;
2168 CORBA::ULong aSize = aResult.size() + 1;
2169 char* aBuffer = new char[aSize];
2170 strcpy(aBuffer,&aResult[0]);
2171 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2174 return new Engines::TMPFile(0);