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;
444 switch(theServant->GetGaussMetric()){
446 aParam = "VISU.AVERAGE";
449 aParam = "VISU.MINIMUM";
452 aParam = "VISU.MAXIMUM";
455 theStr<<thePrefix<<theName<<".SetGaussMetric("<<aParam<<")"<<endl;
457 if(theServant->IsRangeFixed())
458 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
460 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
465 //---------------------------------------------------------------------------
467 MonoColorPrsToPython(SALOMEDS::SObject_ptr theSObject,
468 VISU::MonoColorPrs_i* theServant,
469 std::ostream& theStr,
470 const std::string& theName,
471 TColoredPrs3dFactory& thePrsFactory,
472 std::string thePrefix)
474 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
475 theStr<<thePrefix<<endl;
476 theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
477 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
481 //---------------------------------------------------------------------------
483 DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
484 VISU::DeformedShape_i* theServant,
485 std::ostream& theStr,
486 const std::string& theName,
487 TColoredPrs3dFactory& thePrsFactory,
488 std::string thePrefix)
490 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
491 theStr<<thePrefix<<endl;
493 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
494 // theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
495 // theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
501 //---------------------------------------------------------------------------
503 StreamLinesToPython(SALOMEDS::SObject_ptr theSObject,
504 VISU::StreamLines_i* theServant,
505 std::ostream& theStr,
506 TEntry2NameMap& theEntry2NameMap,
507 const std::string& theName,
508 TColoredPrs3dFactory& thePrsFactory,
509 std::string thePrefix)
511 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
512 // thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
513 theStr<<thePrefix<<endl;
516 switch(theServant->GetDirection()){
517 case StreamLines::FORWARD:
518 aParam = "VISU.StreamLines.FORWARD";
520 case StreamLines::BACKWARD:
521 aParam = "VISU.StreamLines.BACKWARD";
523 case StreamLines::BOTH:
524 aParam = "VISU.StreamLines.BOTH";
528 theStr<<thePrefix<<"aPrs3d = None"<<endl;
529 VISU::Prs3d_var aPrs3d = theServant->GetSource();
530 if(!CORBA::is_nil(aPrs3d)){
531 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
532 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
533 CORBA::String_var anID = aSObject->GetID();
534 std::string anArg = theEntry2NameMap[anID.in()];
535 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
537 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
541 theStr<<thePrefix<<theName<<".SetParams("<<
542 theServant->GetIntegrationStep()<<", "<<
543 theServant->GetPropagationTime()<<", "<<
544 theServant->GetStepLength()<<", "<<
546 theServant->GetUsedPoints()<<", "<<
554 //---------------------------------------------------------------------------
556 DeformedShapeAndScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
557 VISU::DeformedShapeAndScalarMap_i* theServant,
558 std::ostream& theStr,
559 const std::string& theName,
560 TColoredPrs3dFactory& thePrsFactory,
561 std::string thePrefix)
563 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
564 theStr<<thePrefix<<endl;
566 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
567 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
570 VISU::Entity anEntity = theServant->GetScalarEntity();
573 aParam = "VISU.NODE";
576 aParam = "VISU.EDGE";
579 aParam = "VISU.FACE";
582 aParam = "VISU.CELL";
586 CORBA::String_var aFieldName = theServant->GetScalarFieldName();
587 CORBA::Long aTimeStampNumber = theServant->GetScalarTimeStampNumber();
589 theStr<<thePrefix<<theName<<".SetScalarField("<<
591 "'"<<aFieldName<<"', "<<
599 //---------------------------------------------------------------------------
601 VectorsToPython(SALOMEDS::SObject_ptr theSObject,
602 VISU::Vectors_i* theServant,
603 std::ostream& theStr,
604 const std::string& theName,
605 TColoredPrs3dFactory& thePrsFactory,
606 std::string thePrefix)
608 thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
609 theStr<<thePrefix<<endl;
611 theStr<<thePrefix<<theName<<".SetLineWidth("<<theServant->GetLineWidth()<<")"<<endl;
614 switch(theServant->GetGlyphType()){
616 aParam = "VISU.Vectors.ARROW";
619 aParam = "VISU.Vectors.CONE2";
622 aParam = "VISU.Vectors.CONE6";
625 aParam = "VISU.Vectors.NONE";
628 theStr<<thePrefix<<theName<<".SetGlyphType("<<aParam<<")"<<endl;
630 switch(theServant->GetGlyphPos()){
631 case Vectors::CENTER:
632 aParam = "VISU.Vectors.CENTER";
635 aParam = "VISU.Vectors.TAIL";
638 aParam = "VISU.Vectors.HEAD";
641 theStr<<thePrefix<<theName<<".SetGlyphPos("<<aParam<<")"<<endl;
647 //---------------------------------------------------------------------------
649 IsoSurfacesToPython(SALOMEDS::SObject_ptr theSObject,
650 VISU::IsoSurfaces_i* theServant,
651 std::ostream& theStr,
652 const std::string& theName,
653 TColoredPrs3dFactory& thePrsFactory,
654 std::string thePrefix)
656 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
657 theStr<<thePrefix<<endl;
659 theStr<<thePrefix<<theName<<".SetNbSurfaces("<<theServant->GetNbSurfaces()<<")"<<endl;
660 theStr<<thePrefix<<theName<<".ShowLabels("<<theServant->IsLabeled()<<","<<theServant->GetNbLabels()<<")"<<endl;
666 //---------------------------------------------------------------------------
668 CutPlanesToPython(SALOMEDS::SObject_ptr theSObject,
669 VISU::CutPlanes_i* theServant,
670 std::ostream& theStr,
671 const std::string& theName,
672 TColoredPrs3dFactory& thePrsFactory,
673 std::string thePrefix)
675 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
676 theStr<<thePrefix<<endl;
679 switch(theServant->GetOrientationType()){
681 aParam = "VISU.CutPlanes.XY";
684 aParam = "VISU.CutPlanes.YZ";
687 aParam = "VISU.CutPlanes.ZX";
690 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
692 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
693 CORBA::Long aNbPlanes = theServant->GetNbPlanes();
694 theStr<<thePrefix<<theName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
696 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
697 if(!theServant->IsDefault(anId))
698 theStr<<thePrefix<<theName<<".SetPlanePosition("<<anId<<", "<<theServant->GetPlanePosition(anId)<<")"<<endl;
701 theStr<<thePrefix<<theName<<".UseDeformation("<<GetBoolean(theServant->IsDeformed())<<")"<<endl;
702 if(theServant->IsDeformed()){
703 theStr<< thePrefix << theName << ".SetScale(" << theServant->GetScale()<<")"<<endl;
704 std::string aStringEntity;
705 VISU::Entity anEntity = theServant->GetVectorialFieldEntity();
708 aStringEntity = "VISU.NODE";
711 aStringEntity = "VISU.EDGE";
714 aStringEntity = "VISU.FACE";
717 aStringEntity = "VISU.CELL";
720 theStr<< thePrefix << theName << ".SetVectorialField("<<aStringEntity<<", '" << theServant->GetVectorialFieldName() <<"')"<<endl;
726 //---------------------------------------------------------------------------
728 CutLinesToPython(SALOMEDS::SObject_ptr theSObject,
729 VISU::CutLines_i* theServant,
730 std::ostream& theStr,
731 const std::string& theName,
732 TColoredPrs3dFactory& thePrsFactory,
733 std::string thePrefix)
735 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
736 theStr<<thePrefix<<endl;
739 switch(theServant->GetOrientationType()){
741 aParam = "VISU.CutPlanes.XY";
744 aParam = "VISU.CutPlanes.YZ";
747 aParam = "VISU.CutPlanes.ZX";
750 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
752 switch(theServant->GetOrientationType2()){
754 aParam = "VISU.CutPlanes.XY";
757 aParam = "VISU.CutPlanes.YZ";
760 aParam = "VISU.CutPlanes.ZX";
763 theStr<<thePrefix<<theName<<".SetOrientation2("<<aParam<<", "<<theServant->GetRotateX2()<<", "<<theServant->GetRotateY2()<<")"<<endl;
765 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
766 theStr<<thePrefix<<theName<<".SetDisplacement2("<<theServant->GetDisplacement2()<<")"<<endl;
768 if(!theServant->IsDefault())
769 theStr<<thePrefix<<theName<<".SetBasePlanePosition("<<theServant->GetBasePlanePosition()<<")"<<endl;
771 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
772 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
774 CORBA::Long aNbLines = theServant->GetNbLines();
775 theStr<<thePrefix<<theName<<".SetNbLines("<<aNbLines<<")"<<endl;
776 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
777 if(!theServant->IsDefaultPosition(anId))
778 theStr<<thePrefix<<theName<<".SetLinePosition("<<anId<<", "<<theServant->GetLinePosition(anId)<<")"<<endl;
785 //---------------------------------------------------------------------------
787 Plot3DToPython(SALOMEDS::SObject_ptr theSObject,
788 VISU::Plot3D_i* theServant,
789 std::ostream& theStr,
790 const std::string& theName,
791 TColoredPrs3dFactory& thePrsFactory,
792 std::string thePrefix)
794 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
795 theStr<<thePrefix<<endl;
798 switch(theServant->GetOrientationType()){
800 aParam = "VISU.Plot3D.XY";
803 aParam = "VISU.Plot3D.YZ";
806 aParam = "VISU.Plot3D.ZX";
809 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
811 theStr<<thePrefix<<theName<<".SetPlanePosition("<<theServant->GetPlanePosition()<<", "<<theServant->IsPositionRelative()<<")"<<endl;
812 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
813 theStr<<thePrefix<<theName<<".SetContourPrs("<<theServant->GetIsContourPrs()<<")"<<endl;
814 theStr<<thePrefix<<theName<<".SetNbOfContours("<<theServant->GetNbOfContours()<<")"<<endl;
819 //---------------------------------------------------------------------------
821 void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
822 CORBA::Boolean theIsPublished,
823 CORBA::Boolean& theIsValidScript,
824 SALOMEDS::SObject_ptr theSObject,
825 std::ostream& theStr,
826 TName2EntryMap& theName2EntryMap,
827 TEntry2NameMap& theEntry2NameMap,
828 std::string theArgumentName,
829 std::string thePrefix);
831 //---------------------------------------------------------------------------
832 template<class TTableAttr>
834 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
835 CORBA::Boolean theIsPublished,
836 CORBA::Boolean& theIsValidScript,
837 SALOMEDS::SObject_ptr theSObject,
838 TTableAttr theTableAttr,
839 const std::string& theAttrName,
840 std::ostream& theStr,
841 TName2EntryMap& theName2EntryMap,
842 TEntry2NameMap& theEntry2NameMap,
843 std::string theArgumentName,
844 std::string thePrefix)
846 SALOMEDS::GenericAttribute_var anAttr;
847 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
848 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
849 SALOMEDS::AttributeString_var aComment =
850 SALOMEDS::AttributeString::_narrow(anAttr);
851 CORBA::String_var aValue = aComment->Value();
852 Storable::TRestoringMap aMap;
853 Storable::StringToMap(aValue.in(),aMap);
855 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
857 if(strcmp(aMethodName.toLatin1().data(),"ImportTables") == 0){
863 std::string aSObjectName = GetName(theSObject);
864 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
865 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
868 theStr<<thePrefix<<"aBuilder.SetName("<<aSObjectName<<", \""<<theSObject->GetName()<<"\")"<<endl; // Fix for IPAL13165
869 std::string aName = "aTableAttr";
870 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
871 aSObjectName<<", '"<<theAttrName<<"')"<<endl;
873 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
874 std::string aPrefix = thePrefix;
877 CORBA::String_var aString = theTableAttr->GetTitle();
878 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
880 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
881 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
883 CORBA::Long aNbRows = theTableAttr->GetNbRows();
885 // push values and their indices into streams
886 strstream values, rows, columns;
888 for(CORBA::Long i = 1; i <= aNbColumns; i++){
889 for(CORBA::Long j = aNbRows; j > 0; j--){
890 if(theTableAttr->HasValue(j,i)){
891 values << comma << theTableAttr->GetValue(j,i);
893 columns << comma << i;
899 // push titles and units into streams
900 strstream rowUnits, rowTitles, colTitles;
901 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
902 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
904 for(CORBA::Long j = 1; j <= aNbRows; j++){
905 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
906 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
910 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
912 for(CORBA::Long j = 1; j <= aNbColumns; j++){
913 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
923 // write FillTable command
924 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
925 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
926 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
927 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
928 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
929 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
930 theStr<< thePrefix << "visu.FillTable( "
932 << aName << "_values, "
933 << aName << "_rows, "
934 << aName << "_columns, "
935 << aName << "_rTitles, "
936 << aName << "_rUnits, "
937 << aName << "_cTitles )" << endl;
939 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
940 theStr<<thePrefix<<endl;
941 std::string aName = "aTable";
942 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
943 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
944 theArgumentName = aName;
946 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
947 std::string aPrefix2 = thePrefix + PREFIX;
949 // Set name (as this object could be renamed by user)
950 CORBA::String_var aNameInStudy = theSObject->GetName();
951 theStr<<aPrefix2<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 1"<<endl;
953 DumpChildrenToPython(theStudy,
963 theStr<<aPrefix2<<"pass"<<endl<<endl;
966 theStr<<thePrefix<<"pass"<<endl<<endl;
967 theStr<<aPrefix<<"pass"<<endl<<endl;
971 //---------------------------------------------------------------------------
973 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
974 CORBA::Boolean theIsPublished,
975 CORBA::Boolean& theIsValidScript,
976 SALOMEDS::SObject_ptr theSObject,
977 std::ostream& theStr,
978 TName2EntryMap& theName2EntryMap,
979 TEntry2NameMap& theEntry2NameMap,
980 std::string theArgumentName,
981 std::string thePrefix)
983 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
984 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
985 SALOMEDS::SObject_var aSObject = aChildItet->Value();
986 DumpToPython(theStudy,
999 //---------------------------------------------------------------------------
1001 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
1002 CORBA::Boolean theIsPublished,
1003 CORBA::Boolean& theIsValidScript,
1004 SALOMEDS::SObject_ptr theSObject,
1005 std::ostream& theStr,
1006 TName2EntryMap& theName2EntryMap,
1007 TEntry2NameMap& theEntry2NameMap,
1008 std::string theArgumentName,
1009 std::string thePrefix)
1011 SALOMEDS::GenericAttribute_var anAttr;
1012 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
1013 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
1014 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
1016 TableAttrToPython(theStudy,
1021 "AttributeTableOfInteger",
1028 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
1029 SALOMEDS::AttributeTableOfReal_var aTableAttr =
1030 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1032 TableAttrToPython(theStudy,
1037 "AttributeTableOfReal",
1048 //---------------------------------------------------------------------------
1050 DumpToPython(SALOMEDS::Study_ptr theStudy,
1051 CORBA::Boolean theIsPublished,
1052 CORBA::Boolean& theIsValidScript,
1053 SALOMEDS::SObject_ptr theSObject,
1054 std::ostream& theStr,
1055 TName2EntryMap& theName2EntryMap,
1056 TEntry2NameMap& theEntry2NameMap,
1057 std::string theArgumentName,
1058 std::string thePrefix)
1060 std::string aName = GetName(theSObject);
1064 CORBA::String_var anID = theSObject->GetID();
1065 CORBA::String_var aNameInStudy = theSObject->GetName();
1067 CORBA::Object_var anObj = SObjectToObject(theSObject);
1068 if (!CORBA::is_nil(anObj)) {
1069 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1070 if(!CORBA::is_nil(aBase)){
1071 std::string aName = GenerateName(theSObject, theName2EntryMap, theEntry2NameMap);
1073 VISU::VISUType aType = aBase->GetType();
1076 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
1077 std::string aFileName = aServant->GetInitFileName();
1078 Result_i::ECreationId anId = aServant->GetCreationId();
1079 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
1081 case Result_i::eImportFile:
1082 theStr<<thePrefix<<aName<<" = aVisu.CreateResult('"<<aFileName<<"')"<<endl;
1084 theStr<<thePrefix<<aName<<".SetBuildGroups("<<
1085 GetBoolean(aServant->IsGroupsDone())<<")"<<
1088 theStr<<thePrefix<<aName<<".SetBuildFields("<<
1089 GetBoolean(aServant->IsFieldsDone())<<", "<<
1090 GetBoolean(aServant->IsMinMaxDone())<<")"<<
1093 theStr<<thePrefix<<aName<<".Build(False, True)"<<endl;
1095 theStr<<thePrefix<<"if "<<aName<<".IsDone() :"<<endl;
1097 case Result_i::eCopyAndImportFile:
1098 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
1099 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1103 thePrefix += PREFIX;
1105 VISU::Result::EntityNames_var aMeshNames = aServant->GetMeshNames();
1106 if (aMeshNames->length() > 0) {
1107 for(size_t aMeshId = 0; aMeshId < aMeshNames->length(); aMeshId++){
1108 CORBA::String_var aMeshName = aMeshNames[aMeshId];
1109 VISU::Result::EntityNames_var aParts = aServant->GetPartNames(aMeshName);
1110 if (aParts->length() > 0) {
1111 for(size_t aPartId = 0; aPartId < aParts->length(); aPartId++){
1112 CORBA::String_var aPart = aParts[aPartId];
1113 VISU::Result::Resolution aResolution = aServant->GetResolution(aMeshName, aPart);
1115 switch(aResolution){
1116 case VISU::Result::FULL:
1117 aParam = "VISU.Result.FULL";
1119 case VISU::Result::MEDIUM:
1120 aParam = "VISU.Result.MEDIUM";
1122 case VISU::Result::LOW:
1123 aParam = "VISU.Result.LOW";
1125 case VISU::Result::HIDDEN:
1126 aParam = "VISU.Result.HIDDEN";
1129 theStr<<thePrefix<<aName<<".SetResolution('"<<aMeshName.in()<<"', '"<<aPart.in()<<"', "<<aParam<<")"<<endl;
1131 theStr<<thePrefix<<endl;
1137 theArgumentName = aName;
1138 DumpChildrenToPython(theStudy,
1148 theStr<<thePrefix<<"pass"<<endl<<endl;
1150 SALOMEDS::SObject_var aRefSObj;
1151 if(theSObject->FindSubObject(1,aRefSObj)){
1152 SALOMEDS::SObject_var aTargetRefSObj;
1153 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
1154 CORBA::String_var aString = aTargetRefSObj->GetName();
1155 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
1156 theStr<<thePrefix<<"if aSObject:"<<endl;
1157 thePrefix += PREFIX;
1158 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
1159 theStr<<thePrefix<<"if anObject:"<<endl;
1160 std::string aPrefix1 = thePrefix;
1161 thePrefix += PREFIX;
1164 case Result_i::eImportMed:
1165 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
1167 case Result_i::eImportMedField:
1168 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
1172 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1173 std::string aPrefix2 = thePrefix;
1174 thePrefix += PREFIX;
1176 theArgumentName = aName;
1177 DumpChildrenToPython(theStudy,
1187 theStr<<thePrefix<<"pass"<<endl<<endl;
1188 theStr<<aPrefix2<<"pass"<<endl<<endl;
1189 theStr<<aPrefix1<<"pass"<<endl<<endl;
1196 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
1197 VISU::Entity anEntity = aServant->GetEntity();
1198 const std::string& aSubMeshName = aServant->GetSubMeshName();
1203 aParam = "VISU.NODE";
1206 aParam = "VISU.EDGE";
1209 aParam = "VISU.FACE";
1212 aParam = "VISU.CELL";
1216 if(aSubMeshName == "")
1217 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
1218 ", '"<<aServant->GetCMeshName()<<"'"<<
1222 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
1223 ", '"<<aServant->GetCMeshName()<<"'"<<
1225 ", '"<<aSubMeshName<<"'"<<
1228 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
1229 ", '"<<aServant->GetCMeshName()<<"'"<<
1230 ", '"<<aSubMeshName<<"'"<<
1233 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1234 thePrefix += PREFIX;
1236 // Add to Name->Object map
1237 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
1239 // Set name (as this object could be renamed by user)
1240 theStr<<thePrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1242 // Set parameters common for all Prs3d objects (offset values)
1243 Prs3dToPython(aServant,theStr,aName,thePrefix);
1245 // Set presentation parameters
1246 SALOMEDS::Color aColor;
1247 aColor = aServant->GetCellColor();
1248 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
1249 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1251 aColor = aServant->GetNodeColor();
1252 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
1253 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1255 aColor = aServant->GetLinkColor();
1256 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
1257 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1260 switch(aServant->GetPresentationType()){
1262 aParam = "VISU.POINT";
1265 aParam = "VISU.WIREFRAME";
1268 aParam = "VISU.SHADED";
1271 aParam = "VISU.INSIDEFRAME";
1274 aParam = "VISU.SURFACEFRAME";
1277 aParam = "VISU.SHRINK";
1280 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
1281 theStr<<thePrefix<<aName<<".SetShrink("<<(aServant->IsShrank()? "True" : "False")<<")"<<endl;
1282 theStr<<thePrefix<<endl;
1284 std::string aQuad2DPresent;
1285 switch(aServant->GetQuadratic2DPresentationType()){
1287 aQuad2DPresent = "VISU.LINES";
1290 aQuad2DPresent = "VISU.ARCS";
1294 theStr<<thePrefix<<aName<<".SetQuadratic2DPresentationType("<<aQuad2DPresent<<")"<<endl;
1296 DumpChildrenToPython(theStudy,
1306 theStr<<thePrefix<<"pass"<<endl<<endl;
1310 case VISU::TSCALARMAP:
1311 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
1312 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "ScalarMapOnField", theArgumentName);
1313 thePrefix = ScalarMapToPython(theSObject, aServant, theStr,aName, aPrsFactory, thePrefix);
1314 theStr<<thePrefix<<"pass"<<endl<<endl;
1317 case VISU::TDEFORMEDSHAPE:
1318 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
1319 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeOnField", theArgumentName);
1320 thePrefix = DeformedShapeToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1321 theStr<<thePrefix<<"pass"<<endl<<endl;
1324 case VISU::TSTREAMLINES:
1325 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
1326 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "StreamLinesOnField", theArgumentName);
1327 thePrefix = StreamLinesToPython(theSObject, aServant, theStr, theEntry2NameMap, aName, aPrsFactory, thePrefix);
1328 theStr<<thePrefix<<"pass"<<endl<<endl;
1331 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1332 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1333 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(GetServant(anObj).in())){
1334 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeAndScalarMapOnField", theArgumentName);
1335 thePrefix = DeformedShapeAndScalarMapToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1336 theStr<<thePrefix<<"pass"<<endl<<endl;
1339 case VISU::TVECTORS:
1340 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
1341 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "VectorsOnField", theArgumentName);
1342 thePrefix = VectorsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1343 theStr<<thePrefix<<"pass"<<endl<<endl;
1346 case VISU::TISOSURFACES:
1347 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
1348 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "IsoSurfacesOnField", theArgumentName);
1349 thePrefix = IsoSurfacesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1350 theStr<<thePrefix<<"pass"<<endl<<endl;
1353 case VISU::TCUTPLANES:
1354 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
1355 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutPlanesOnField", theArgumentName);
1356 thePrefix = CutPlanesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1357 theStr<<thePrefix<<"pass"<<endl<<endl;
1360 case VISU::TCUTLINES:
1361 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
1362 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutLinesOnField", theArgumentName);
1363 thePrefix = CutLinesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1365 theArgumentName = aName;
1366 DumpChildrenToPython(theStudy,
1376 theStr<<thePrefix<<"pass"<<endl<<endl;
1380 if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
1381 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
1382 thePrefix = Plot3DToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1383 theStr<<thePrefix<<"pass"<<endl<<endl;
1386 case VISU::TPOINTMAP3D:
1387 if (PointMap3d_i* aServant = dynamic_cast<PointMap3d_i*>(GetServant(anObj).in())) {
1388 CORBA::Short aTag = theSObject->Tag();
1389 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1390 theStr<<thePrefix<<"if anIsFound:"<<endl;
1391 thePrefix += PREFIX;
1393 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1394 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1396 // Set name (as this object could be renamed by user)
1397 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1399 // Set PointMap3D Properties
1401 theStr<<thePrefix<<aName<<".SetScaleFactor("<<aServant->GetScaleFactor()<<")"<<endl;
1402 theStr<<thePrefix<<aName<<".SetContourPrs("<<aServant->GetIsContourPrs()<<")"<<endl;
1403 theStr<<thePrefix<<aName<<".SetNbOfContours("<<aServant->GetNbOfContours()<<")"<<endl;
1406 switch(aServant->GetScaling()){
1408 aParam = "VISU.LINEAR";
1411 aParam = "VISU.LOGARITHMIC";
1414 theStr<<thePrefix<<aName<<".SetScaling("<<aParam<<")"<<endl;
1416 theStr<<thePrefix<<aName<<".SetNbColors("<<aServant->GetNbColors()<<")"<<endl;
1417 theStr<<thePrefix<<aName<<".SetLabels("<<aServant->GetLabels()<<")"<<endl;
1419 switch(aServant->GetBarOrientation()){
1420 case ColoredPrs3dBase::HORIZONTAL:
1421 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
1423 case ColoredPrs3dBase::VERTICAL:
1424 aParam = "VISU.ColoredPrs3d.VERTICAL";
1427 theStr<<thePrefix<<aName<<".SetBarOrientation("<<aParam<<")"<<endl;
1429 if(aServant->IsRangeFixed())
1430 theStr<<thePrefix<<aName<<".SetRange("<<aServant->GetMin()<<", "<<aServant->GetMax()<<")"<<endl;
1432 theStr<<thePrefix<<aName<<".SetSourceRange()"<<endl;
1434 theStr<<thePrefix<<aName<<".SetPosition("<<aServant->GetPosX()<<", "<<aServant->GetPosY()<<")"<<endl;
1435 theStr<<thePrefix<<aName<<".SetSize("<<aServant->GetWidth()<<", "<<aServant->GetHeight()<<")"<<endl;
1438 aServant->GetOffset(dx, dy, dz);
1439 theStr<<thePrefix<<aName<<".SetOffset("<<dx<<", "<<dy<<", "<<dz<<")"<<endl;
1442 theStr<<thePrefix<<endl;
1444 theArgumentName = aName;
1445 DumpChildrenToPython(theStudy,
1455 theStr<<thePrefix<<"pass"<<endl<<endl;
1458 case VISU::TGAUSSPOINTS:
1459 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(GetServant(anObj).in())){
1460 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "GaussPointsOnField", theArgumentName);
1461 thePrefix = GaussPointsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1462 theStr<<thePrefix<<"pass"<<endl<<endl;
1466 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
1468 bool withZ = aServant->GetZRow()>0;
1470 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
1474 theArgumentName<< // table
1475 ", "<<aServant->GetHRow()<< // H row
1476 ", "<<aServant->GetVRow(); // V row
1478 theStr << ", " << aServant->GetZRow(); // Z row
1480 theStr << ", '"<<aServant->GetTitle()<<"'"; // title
1481 SALOMEDS::Color aColor = aServant->GetColor();
1482 theStr << ",SALOMEDS.Color("<<
1483 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<")"; // color
1486 switch(aServant->GetMarker()){
1487 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
1488 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
1489 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
1490 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
1491 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
1492 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
1493 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
1494 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
1495 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
1496 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
1498 theStr<<", "<<aParam; // marker
1500 switch(aServant->GetLine()){
1501 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
1502 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
1503 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
1504 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
1505 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
1506 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
1508 theStr<<", "<<aParam<<", "<<aServant->GetLineWidth()<<")"<<endl; // line type,width
1512 if(dynamic_cast<Table_i*>(GetServant(anObj).in())){
1513 SALOMEDS::GenericAttribute_var anAttr;
1514 if(theSObject->FindAttribute(anAttr,"AttributeString")){
1515 using namespace SALOMEDS;
1516 AttributeString_var aComment = AttributeString::_narrow(anAttr);
1517 CORBA::String_var aValue = aComment->Value();
1518 Storable::TRestoringMap aMap;
1519 Storable::StringToMap(aValue.in(),aMap);
1521 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1523 if( aSourceId == "CutLines" ){
1524 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
1525 thePrefix += PREFIX;
1527 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
1528 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
1529 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
1530 theStr<<thePrefix<<"if aSObject:"<<endl;
1531 std::string aPrefix = thePrefix;
1532 thePrefix += PREFIX;
1534 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1535 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1537 // Set name (as this object could be renamed by user)
1538 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 2"<<endl;
1540 theStr<<thePrefix<<endl;
1542 theArgumentName = aName;
1543 DumpChildrenToPython(theStudy,
1553 theStr<<thePrefix<<"pass"<<endl<<endl;
1554 theStr<<aPrefix<<"pass"<<endl<<endl;
1555 }else if( aSourceId == "TableFile" ){
1556 CORBA::Short aTag = theSObject->Tag();
1557 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1558 theStr<<thePrefix<<"if anIsFound:"<<endl;
1559 thePrefix += PREFIX;
1561 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1562 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1564 // Set name (as this object could be renamed by user)
1565 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1567 theStr<<thePrefix<<endl;
1569 theArgumentName = aName;
1570 DumpChildrenToPython(theStudy,
1580 theStr<<thePrefix<<"pass"<<endl<<endl;
1581 }else if( aSourceId == "TableAttr" ){
1582 theArgumentName = aName;
1583 DumpTableAttrToPython(theStudy,
1599 } else { /*if(!CORBA::is_nil(anObj))*/
1600 SALOMEDS::GenericAttribute_var anAttr;
1601 if (theSObject->FindAttribute(anAttr,"AttributeString")) {
1602 SALOMEDS::AttributeString_var aComment =
1603 SALOMEDS::AttributeString::_narrow(anAttr);
1604 CORBA::String_var aValue = aComment->Value();
1605 Storable::TRestoringMap aMap;
1606 Storable::StringToMap(aValue.in(),aMap);
1608 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1610 if (aTypeName == "ImportTables") {
1611 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1613 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1614 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.toLatin1().data()<<"')"<<endl;
1615 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1616 thePrefix += PREFIX;
1618 theArgumentName = aName;
1619 DumpChildrenToPython(theStudy,
1629 theStr<<thePrefix<<"pass"<<endl<<endl;
1632 } else if (aTypeName == "VIEW3D") {
1633 std::string aName = GetName(theSObject);
1634 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1636 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1637 thePrefix += PREFIX;
1639 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1640 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1642 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1643 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1645 theStr<<thePrefix<<"pass"<<endl<<endl;
1647 } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1648 // Set name (as this object could be renamed by user)
1649 string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1650 string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1651 string anEntityTypeKey = "myEntityId";
1652 if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1653 int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1654 std::string anEntityType;
1655 switch ((TEntity)anEntity) {
1656 case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1657 case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1658 case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1659 case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1662 if (aTypeName == "ENTITY" ) {
1663 theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1664 <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1666 else if (aTypeName == "FAMILY") {
1667 if (aSubMeshName != aNameInStudy.in()) {
1668 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1669 <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1673 if (aSubMeshName != aNameInStudy.in()) {
1674 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1675 <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1681 DumpTableAttrToPython(theStudy,
1693 DumpChildrenToPython(theStudy,
1705 //---------------------------------------------------------------------------
1707 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1708 CORBA::Boolean theIsPublished,
1709 CORBA::Boolean& theIsValidScript,
1710 SALOMEDS::SObject_ptr theSObject,
1711 std::ostream& theStr,
1712 TName2EntryMap& theName2EntryMap,
1713 TEntry2NameMap& theEntry2NameMap,
1714 std::string theArgumentName,
1715 std::string thePrefix)
1717 SALOMEDS::SObject_var aTargetRefSObj;
1718 if(theSObject->ReferencedObject(aTargetRefSObj)){
1719 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1720 if(CORBA::is_nil(anObj))
1723 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1724 if(CORBA::is_nil(aBase))
1727 if(aBase->GetType() == VISU::TCURVE){
1728 CORBA::String_var anID = aTargetRefSObj->GetID();
1729 std::string anArg = theEntry2NameMap[anID.in()];
1730 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1731 thePrefix += PREFIX;
1732 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1733 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1734 theStr<<thePrefix<<"pass"<<endl<<endl;
1740 //---------------------------------------------------------------------------
1742 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1743 CORBA::Boolean theIsPublished,
1744 CORBA::Boolean& theIsValidScript,
1745 SALOMEDS::SObject_ptr theSObject,
1746 std::ostream& theStr,
1747 TName2EntryMap& theName2EntryMap,
1748 TEntry2NameMap& theEntry2NameMap,
1749 std::string theArgumentName,
1750 std::string thePrefix)
1752 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1753 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1754 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1755 CORBA::Object_var anObj = SObjectToObject(aSObject);
1756 if(CORBA::is_nil(anObj))
1759 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1760 if(CORBA::is_nil(aBase))
1763 if(aBase->GetType() == VISU::TCONTAINER){
1764 theStr<<thePrefix<<endl;
1765 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1766 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1767 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1768 std::string aPrefix = thePrefix + PREFIX;
1769 theArgumentName = aName;
1771 // Set name (as this object could be renamed by user)
1772 CORBA::String_var aNameInStudy = aSObject->GetName();
1773 theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1775 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1776 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1777 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1778 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1781 theStr<<aPrefix<<"pass"<<endl<<endl;
1787 //---------------------------------------------------------------------------
1789 DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1790 CORBA::Boolean theIsPublished,
1791 CORBA::Boolean& theIsValidScript,
1792 SALOMEDS::SObject_ptr theSObject,
1793 std::ostream& theStr,
1794 TName2EntryMap& theName2EntryMap,
1795 TEntry2NameMap& theEntry2NameMap,
1796 std::string theArgumentName,
1797 std::string thePrefix)
1800 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1801 for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1802 SALOMEDS::SObject_var aSObject = anIter->Value();
1803 CORBA::Object_var anObj = SObjectToObject(aSObject);
1804 if(CORBA::is_nil(anObj))
1807 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1808 if(CORBA::is_nil(aBase))
1811 if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1812 ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1813 theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1814 theStr<<thePrefix<<"if aCache != None:"<<endl;
1816 std::string aPrefix = thePrefix + PREFIX;
1817 std::string anArgument;
1818 VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1820 case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1821 case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1823 theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1825 if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1826 theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1828 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1829 for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1830 SALOMEDS::SObject_var aSObject = aChildIter->Value();
1831 CORBA::Object_var anObject = SObjectToObject(aSObject);
1832 if (CORBA::is_nil(anObject))
1835 ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1839 ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1843 Result_i* aResult = aDevice->GetCResult();
1844 std::string aResultEntry = aResult->GetEntry();
1845 std::string aResultName = theEntry2NameMap[aResultEntry];
1847 ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1848 std::string anEntity;
1849 switch(anInput->myEntity){
1850 case VISU::NODE : anEntity = "VISU.NODE"; break;
1851 case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1852 case VISU::FACE : anEntity = "VISU.FACE"; break;
1853 case VISU::CELL : anEntity = "VISU.CELL"; break;
1857 theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
1858 aResultName<<", '"<<
1859 anInput->myMeshName<<"', "<<
1861 anInput->myFieldName<<"', "<<
1862 anInput->myTimeStampNumber<<")"<<
1865 std::string aComment = aDevice->GetComment();
1866 theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
1867 theStr<<aPrefix<<"if aHolder != None:"<<endl;
1869 std::string aPrefix2 = aPrefix + PREFIX;
1870 CORBA::String_var aNameInStudy = aSObject->GetName();
1871 theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
1872 theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
1873 theStr<<aPrefix2<<"if aDevice != None:"<<endl;
1875 std::string aPrefix3 = aPrefix2 + PREFIX;
1876 TColoredPrs3dFactory aPrsFactory;
1877 switch(aDevice->GetType()){
1878 case VISU::TSCALARMAP:
1879 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
1880 ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1883 case VISU::TDEFORMEDSHAPE:
1884 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
1885 DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1888 case VISU::TSTREAMLINES:
1889 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
1890 StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
1893 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1894 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1895 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
1896 DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1899 case VISU::TVECTORS:
1900 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
1901 VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1904 case VISU::TISOSURFACES:
1905 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
1906 IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1909 case VISU::TCUTPLANES:
1910 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
1911 CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1914 case VISU::TCUTLINES:
1915 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
1916 CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1920 if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
1921 Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1924 case VISU::TGAUSSPOINTS:
1925 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
1926 GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1930 theStr<<aPrefix3<<"pass"<<endl;
1932 theStr<<aPrefix2<<"pass"<<endl<<endl;
1935 theStr<<aPrefix<<"pass"<<endl;
1942 //---------------------------------------------------------------------------
1944 DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
1945 CORBA::Boolean theIsPublished,
1946 CORBA::Boolean& theIsValidScript,
1947 SALOMEDS::SObject_ptr theSObject,
1948 std::ostream& theStr,
1949 std::string thePrefix)
1952 if(!theIsPublished) return;
1954 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1955 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1956 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1958 SALOMEDS::GenericAttribute_var anAttr;
1959 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
1961 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
1962 QString value (aStringAttr->Value());
1963 if(value.isEmpty()) continue;
1965 VISU::Storable::TRestoringMap aMap;
1966 VISU::Storable::StringToMap(value, aMap);
1969 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
1970 if(!isExist || aTypeName != "ANIMATION") continue;
1973 theStr<<thePrefix<<endl;
1974 QString animName = aSObject->GetName();
1975 theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
1976 theStr<<thePrefix<<endl;
1977 theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
1978 theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
1979 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
1980 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
1984 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
1985 for (anIter->Init(); anIter->More(); anIter->Next()) {
1986 SALOMEDS::SObject_var anObj = anIter->Value();
1989 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
1990 if (anObj->FindAttribute(anAttr, "AttributeString")) {
1991 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
1992 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
1993 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
1996 SALOMEDS::SObject_var refObj;
1997 if(anObj->ReferencedObject(refObj)) {
1998 SALOMEDS::SObject_var father = refObj->GetFather();
1999 value = refObj->GetName();
2000 QString path(theStudy->GetObjectPath(father));
2001 //The following code requierd as a field name can contain '/' character
2002 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2004 value = anObj->GetName();
2005 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2008 SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
2009 for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
2010 SALOMEDS::SObject_var aSubObj = aSubIter->Value();
2012 theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
2013 value = aSubObj->GetName();
2014 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
2015 if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
2016 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2017 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2018 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2026 theStr<<thePrefix<<endl;
2031 DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2032 CORBA::Boolean theIsPublished,
2033 CORBA::Boolean& theIsValidScript,
2034 SALOMEDS::SObject_ptr theSObject,
2035 std::ostream& theStr,
2036 std::string thePrefix,
2037 VISU_ClippingPlaneMgr& thePlaneMgr)
2040 if(!theIsPublished) return;
2042 VISU_CutPlaneFunction* aPlane;
2043 double aOrigin[3], aDir[3];
2044 for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2045 aPlane = thePlaneMgr.GetClippingPlane(i);
2046 aPlane->GetOrigin(aOrigin);
2047 aPlane->GetNormal(aDir);
2049 theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2050 aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2051 aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2052 aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;
2058 //---------------------------------------------------------------------------
2061 DumpPython(CORBA::Object_ptr theStudy,
2062 CORBA::Boolean theIsPublished,
2063 CORBA::Boolean& theIsValidScript)
2065 theIsValidScript = false;
2067 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2068 if(CORBA::is_nil(aStudy))
2069 return new Engines::TMPFile(0);
2071 TName2EntryMap aName2EntryMap;
2072 TEntry2NameMap aEntry2NameMap;
2080 std::string aPrefix(PREFIX);
2081 aStr<<"### This file is generated by SALOME automatically by dump python functionality"
2082 " of VISU component"<<endl<<endl;
2083 aStr<<"def RebuildData(theStudy):"<<endl;
2084 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2085 aStr<<aPrefix<<"import SALOME_MED"<<endl;
2086 aStr<<aPrefix<<"import SALOMEDS"<<endl;
2087 aStr<<aPrefix<<"import VISU"<<endl;
2088 aStr<<aPrefix<<"import visu"<<endl;
2090 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2091 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2092 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2093 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2094 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2097 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2099 VISU::DumpClippingPlanesToPython(aStudy,
2105 myClippingPlaneMgr);
2108 VISU::DumpChildrenToPython(aStudy,
2118 VISU::DumpContainersToPython(aStudy,
2128 VISU::DumpPrs3dCacheToPython(aStudy,
2138 VISU::DumpAnimationsToPython(aStudy,
2146 //Output the script that sets up the visul parameters.
2147 if(theIsPublished) {
2148 char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2149 if(script && strlen(script) > 0) {
2151 CORBA::string_free(script);
2155 aStr<<aPrefix<<"pass"<<endl;
2157 if(theIsPublished) { //SRN: define function for Animation
2159 //Define a function that find a SObject by its father's path and its name
2163 aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
2164 aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
2165 aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
2166 aStr<<aPrefix<<"while itr.More():"<<endl;
2167 aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
2168 aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
2169 aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
2170 aStr<<aPrefix<<aPrefix<<"pass"<<endl;
2171 aStr<<aPrefix<<"return None"<<endl;
2176 // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2177 // If the situation changes, then the following line should be removed, and theIsValidScript
2178 // should be set properly by those internal methods
2179 theIsValidScript = true;
2182 std::string aResult = aStr.str();
2183 //ofstream anFStream("/tmp/dump.py");
2184 //anFStream<<aResult<<endl;
2186 CORBA::ULong aSize = aResult.size() + 1;
2187 char* aBuffer = new char[aSize];
2188 strcpy(aBuffer,&aResult[0]);
2189 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2192 return new Engines::TMPFile(0);