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_CutSegment_i.hh"
39 #include "VISU_Vectors_i.hh"
40 #include "VISU_StreamLines_i.hh"
41 #include "VISU_Plot3D_i.hh"
42 #include "VISU_Table_i.hh"
43 #include "VISU_PointMap3d_i.hh"
44 #include "VISU_GaussPoints_i.hh"
45 #include "VISU_DeformedShapeAndScalarMap_i.hh"
46 #include "VISU_ColoredPrs3dCache_i.hh"
47 #include "VISU_ColoredPrs3dHolder_i.hh"
49 #include "utilities.h"
64 //---------------------------------------------------------------------------
65 static std::string PREFIX(" ");
67 typedef std::map<std::string,std::string> TName2EntryMap;
68 typedef std::map<std::string,std::string> TEntry2NameMap;
71 //---------------------------------------------------------------------------
74 GenerateName(std::string theName,
75 SALOMEDS::SObject_ptr theSObject,
76 TName2EntryMap& theName2EntryMap,
77 TEntry2NameMap& theEntry2NameMap,
80 if(theName2EntryMap.find(theName) != theName2EntryMap.end()){
81 theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix);
83 CORBA::String_var anID = theSObject->GetID();
84 theName2EntryMap[theName] = anID.in();
85 theEntry2NameMap[anID.in()] = theName;
86 //cout<<"GenerateName - "<<theName<<" => "<<anID.in()<<endl;
93 //---------------------------------------------------------------------------
94 struct TReplacePredicate
96 bool operator()(char theChar) const
98 return !(isdigit(theChar) || isalpha(theChar) || theChar == '_');
103 //---------------------------------------------------------------------------
106 GetName(SALOMEDS::SObject_ptr theSObject)
108 CORBA::String_var aString = theSObject->GetName();
110 std::string aName = QString(aString.in()).simplified().toLatin1().data();
112 //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_');
113 replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_');
115 if ( isdigit( aName[0] ))
116 aName.insert( 0, 1, 'a' );
122 //---------------------------------------------------------------------------
125 GenerateName(SALOMEDS::SObject_ptr theSObject,
126 TName2EntryMap& theName2EntryMap,
127 TEntry2NameMap& theEntry2NameMap)
129 std::string aName = GetName(theSObject);
131 return GenerateName(aName, theSObject, theName2EntryMap, theEntry2NameMap, 'X');
135 //---------------------------------------------------------------------------
138 GetBoolean(bool theArgument)
147 //---------------------------------------------------------------------------
150 GetColor(const SALOMEDS::Color& theColor)
152 std::ostringstream aStream;
153 aStream<<"SALOMEDS.Color("<<theColor.R<<", "<<theColor.G<<", "<<theColor.B<<")";
154 return aStream.str();
158 //---------------------------------------------------------------------------
159 typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy,
160 CORBA::Boolean theIsPublished,
161 CORBA::Boolean& theIsValidScript,
162 SALOMEDS::SObject_ptr theSObject,
163 std::ostream& theStr,
164 TName2EntryMap& theName2EntryMap,
165 TEntry2NameMap& theEntry2NameMap,
166 std::string theArgumentName,
167 std::string thePrefix);
171 DumpToPython(SALOMEDS::Study_ptr theStudy,
172 CORBA::Boolean theIsPublished,
173 CORBA::Boolean& theIsValidScript,
174 SALOMEDS::SObject_ptr theSObject,
175 std::ostream& theStr,
176 TName2EntryMap& theName2EntryMap,
177 TEntry2NameMap& theEntry2NameMap,
178 std::string theArgumentName,
179 std::string thePrefix);
182 //---------------------------------------------------------------------------
183 void SetClippingPlane(Prs3d_i* thePrs, string theName,
184 std::ostream& theStr,
185 std::string thePrefix)
187 VISU_CutPlaneFunction* aPlane;
188 VISU_Gen_i* aGen = VISU_Gen_i::GetVisuGenImpl();
189 VISU_ClippingPlaneMgr& aMgr = aGen->GetClippingPlaneMgr();
191 for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) {
192 aPlane = dynamic_cast<VISU_CutPlaneFunction*>(thePrs->GetClippingPlane(i));
194 if (!aPlane->isAuto()) {
195 aId = aMgr.GetPlaneId(aPlane);
197 theStr<<thePrefix<<"aVisu.ApplyClippingPlane("<<theName<<", "<<aId<<")"<<endl;
206 Prs3dToPython(VISU::Prs3d_i* theServant,
207 std::ostream& theStr,
208 const std::string& theName,
209 std::string thePrefix)
212 theServant->GetOffset(x,y,z);
213 theStr<<thePrefix<<theName<<".SetOffset("<<x<<", "<<y<<", "<<z<<")"<<endl;
214 SetClippingPlane(theServant, theName, theStr, thePrefix);
217 //---------------------------------------------------------------------------
218 struct TColoredPrs3dFactory
222 operator()(std::ostream& theStr,
223 std::string thePrefix)
231 struct TCreateFromResult: TColoredPrs3dFactory
233 VISU::ColoredPrs3d_i* myServant;
234 std::string myConstructorName;
235 std::string myArgumentName;
237 SALOMEDS::SObject_var mySObject;
240 TCreateFromResult(const SALOMEDS::SObject_var& theSObject,
241 VISU::ColoredPrs3d_i* theServant,
242 const std::string& theName,
243 const std::string& theConstructorName,
244 const std::string& theArgumentName):
245 myServant(theServant),
246 myConstructorName(theConstructorName),
247 myArgumentName(theArgumentName),
248 mySObject(theSObject),
254 operator()(std::ostream& theStr,
255 std::string thePrefix)
258 switch(myServant->GetEntity()){
260 aParam = "VISU.NODE";
263 aParam = "VISU.EDGE";
266 aParam = "VISU.FACE";
269 aParam = "VISU.CELL";
273 theStr<<thePrefix<<myName<<" = aVisu."<<myConstructorName<<"("<<myArgumentName<<
274 ", '"<<myServant->GetCMeshName()<<"'"<<
276 ", '"<<myServant->GetCFieldName()<<"'"<<
277 ", "<<myServant->GetTimeStampNumber()<<
280 theStr<<thePrefix<<"if "<<myName<<" != None:"<<endl;
283 // Add to Name->Object map
284 theStr<<thePrefix<<"aName2ObjectMap['"<<myName<<"'] = "<<myName<<endl;
286 // Set name (as this object could be renamed by user)
287 CORBA::String_var aNameInStudy = mySObject->GetName();
288 theStr<<thePrefix<<"visu.SetName("<<myName<<", '"<<aNameInStudy.in()<<"')"<<endl;
295 //---------------------------------------------------------------------------
297 ColoredPrs3dToPython(SALOMEDS::SObject_ptr theSObject,
298 VISU::ColoredPrs3d_i* theServant,
299 std::ostream& theStr,
300 const std::string& theName,
301 TColoredPrs3dFactory& thePrsFactory,
302 std::string thePrefix)
304 thePrefix = thePrsFactory(theStr, thePrefix);
306 // Set parameters common for all Prs3d objects (offset values)
307 Prs3dToPython(theServant, theStr, theName, thePrefix);
309 theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<", "<<theServant->GetPosY()<<")"<<endl;
310 theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<", "<<theServant->GetHeight()<<")"<<endl;
311 theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
312 theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
313 theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
316 switch(theServant->GetBarOrientation()){
317 case ColoredPrs3dBase::HORIZONTAL:
318 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
320 case ColoredPrs3dBase::VERTICAL:
321 aParam = "VISU.ColoredPrs3d.VERTICAL";
324 theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
326 theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
328 if(theServant->IsRangeFixed())
329 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
331 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
333 const VISU::ColoredPrs3d_i::TGroupNames aGroupNames = theServant->GetGroupNames();
334 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
335 for(; anIter != aGroupNames.end(); anIter++){
336 const std::string& aGroupName = *anIter;
337 theStr<<thePrefix<<theName<<".AddMeshOnGroup('"<<aGroupName<<"')"<<endl;
344 //---------------------------------------------------------------------------
346 GaussPointsToPython(SALOMEDS::SObject_ptr theSObject,
347 VISU::GaussPoints_i* theServant,
348 std::ostream& theStr,
349 const std::string& theName,
350 TColoredPrs3dFactory& thePrsFactory,
351 std::string thePrefix)
353 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
354 theStr<<thePrefix<<endl;
356 bool aBoolean = theServant->GetIsActiveLocalScalarBar();
357 theStr<<thePrefix<<theName<<".SetIsActiveLocalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
360 aBoolean = theServant->GetIsDispGlobalScalarBar();
361 theStr<<thePrefix<<theName<<".SetIsDispGlobalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
364 theStr<<thePrefix<<theName<<".SetSpacing("<<theServant->GetSpacing()<<")"<<endl;
366 aBoolean = theServant->GetBiColor();
367 theStr<<thePrefix<<theName<<".SetBiColor("<<GetBoolean(aBoolean)<<")"<<endl;
369 aBoolean = theServant->GetIsDeformed();
370 theStr<<thePrefix<<theName<<".SetIsDeformed("<<GetBoolean(aBoolean)<<")"<<endl;
371 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
374 switch(theServant->GetPrimitiveType()){
375 case VISU::GaussPoints::SPRITE :
376 aParam = "VISU.GaussPoints.SPRITE";
378 case VISU::GaussPoints::POINT :
379 aParam = "VISU.GaussPoints.POINT";
381 case VISU::GaussPoints::SPHERE :
382 aParam = "VISU.GaussPoints.SPHERE";
385 theStr<<thePrefix<<theName<<".SetPrimitiveType("<<aParam<<")"<<endl;
387 theStr<<thePrefix<<theName<<".SetClamp("<<theServant->GetClamp()<<")"<<endl;
389 QString aMainTexture = theServant->GetQMainTexture();
390 QString anAlphaTexture = theServant->GetQAlphaTexture();
391 theStr<<thePrefix<<theName<<".SetTextures('"<<aMainTexture.toLatin1().data()<<"', '"<<anAlphaTexture.toLatin1().data()<<"')"<<endl;
393 theStr<<thePrefix<<theName<<".SetAlphaThreshold("<<theServant->GetAlphaThreshold()<<")"<<endl;
395 theStr<<thePrefix<<theName<<".SetResolution("<<theServant->GetResolution()<<")"<<endl;
397 theStr<<thePrefix<<theName<<".SetFaceLimit("<<theServant->GetFaceLimit()<<")"<<endl;
399 aBoolean = theServant->GetIsColored();
400 theStr<<thePrefix<<theName<<".SetIsColored("<<GetBoolean(aBoolean)<<")"<<endl;
403 theStr<<thePrefix<<theName<<".SetMinSize("<<theServant->GetMinSize()<<")"<<endl;
404 theStr<<thePrefix<<theName<<".SetMaxSize("<<theServant->GetMaxSize()<<")"<<endl;
406 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
407 theStr<<thePrefix<<theName<<".SetGeomSize("<<theServant->GetGeomSize()<<")"<<endl;
410 theStr<<thePrefix<<theName<<".SetMagnification("<<theServant->GetMagnification()<<")"<<endl;
411 theStr<<thePrefix<<theName<<".SetMagnificationIncrement("<<theServant->GetMagnificationIncrement()<<")"<<endl;
413 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
414 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
420 //---------------------------------------------------------------------------
422 ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
423 VISU::ScalarMap_i* theServant,
424 std::ostream& theStr,
425 const std::string& theName,
426 TColoredPrs3dFactory& thePrsFactory,
427 std::string thePrefix)
429 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
430 theStr<<thePrefix<<endl;
433 switch(theServant->GetScaling()){
435 aParam = "VISU.LINEAR";
438 aParam = "VISU.LOGARITHMIC";
441 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
442 theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
443 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
445 switch(theServant->GetGaussMetric()){
447 aParam = "VISU.AVERAGE";
450 aParam = "VISU.MINIMUM";
453 aParam = "VISU.MAXIMUM";
456 theStr<<thePrefix<<theName<<".SetGaussMetric("<<aParam<<")"<<endl;
458 if(theServant->IsRangeFixed())
459 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
461 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
466 //---------------------------------------------------------------------------
468 MonoColorPrsToPython(SALOMEDS::SObject_ptr theSObject,
469 VISU::MonoColorPrs_i* theServant,
470 std::ostream& theStr,
471 const std::string& theName,
472 TColoredPrs3dFactory& thePrsFactory,
473 std::string thePrefix)
475 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
476 theStr<<thePrefix<<endl;
477 theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
478 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
482 //---------------------------------------------------------------------------
484 DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
485 VISU::DeformedShape_i* theServant,
486 std::ostream& theStr,
487 const std::string& theName,
488 TColoredPrs3dFactory& thePrsFactory,
489 std::string thePrefix)
491 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
492 theStr<<thePrefix<<endl;
494 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
495 // theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
496 // theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
502 //---------------------------------------------------------------------------
504 StreamLinesToPython(SALOMEDS::SObject_ptr theSObject,
505 VISU::StreamLines_i* theServant,
506 std::ostream& theStr,
507 TEntry2NameMap& theEntry2NameMap,
508 const std::string& theName,
509 TColoredPrs3dFactory& thePrsFactory,
510 std::string thePrefix)
512 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
513 // thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
514 theStr<<thePrefix<<endl;
517 switch(theServant->GetDirection()){
518 case StreamLines::FORWARD:
519 aParam = "VISU.StreamLines.FORWARD";
521 case StreamLines::BACKWARD:
522 aParam = "VISU.StreamLines.BACKWARD";
524 case StreamLines::BOTH:
525 aParam = "VISU.StreamLines.BOTH";
529 theStr<<thePrefix<<"aPrs3d = None"<<endl;
530 VISU::Prs3d_var aPrs3d = theServant->GetSource();
531 if(!CORBA::is_nil(aPrs3d)){
532 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
533 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
534 CORBA::String_var anID = aSObject->GetID();
535 std::string anArg = theEntry2NameMap[anID.in()];
536 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
538 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
542 theStr<<thePrefix<<theName<<".SetParams("<<
543 theServant->GetIntegrationStep()<<", "<<
544 theServant->GetPropagationTime()<<", "<<
545 theServant->GetStepLength()<<", "<<
547 theServant->GetUsedPoints()<<", "<<
555 //---------------------------------------------------------------------------
557 DeformedShapeAndScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
558 VISU::DeformedShapeAndScalarMap_i* theServant,
559 std::ostream& theStr,
560 const std::string& theName,
561 TColoredPrs3dFactory& thePrsFactory,
562 std::string thePrefix)
564 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
565 theStr<<thePrefix<<endl;
567 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
568 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
571 VISU::Entity anEntity = theServant->GetScalarEntity();
574 aParam = "VISU.NODE";
577 aParam = "VISU.EDGE";
580 aParam = "VISU.FACE";
583 aParam = "VISU.CELL";
587 CORBA::String_var aFieldName = theServant->GetScalarFieldName();
588 CORBA::Long aTimeStampNumber = theServant->GetScalarTimeStampNumber();
590 theStr<<thePrefix<<theName<<".SetScalarField("<<
592 "'"<<aFieldName<<"', "<<
600 //---------------------------------------------------------------------------
602 VectorsToPython(SALOMEDS::SObject_ptr theSObject,
603 VISU::Vectors_i* theServant,
604 std::ostream& theStr,
605 const std::string& theName,
606 TColoredPrs3dFactory& thePrsFactory,
607 std::string thePrefix)
609 thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
610 theStr<<thePrefix<<endl;
612 theStr<<thePrefix<<theName<<".SetLineWidth("<<theServant->GetLineWidth()<<")"<<endl;
615 switch(theServant->GetGlyphType()){
617 aParam = "VISU.Vectors.ARROW";
620 aParam = "VISU.Vectors.CONE2";
623 aParam = "VISU.Vectors.CONE6";
626 aParam = "VISU.Vectors.NONE";
629 theStr<<thePrefix<<theName<<".SetGlyphType("<<aParam<<")"<<endl;
631 switch(theServant->GetGlyphPos()){
632 case Vectors::CENTER:
633 aParam = "VISU.Vectors.CENTER";
636 aParam = "VISU.Vectors.TAIL";
639 aParam = "VISU.Vectors.HEAD";
642 theStr<<thePrefix<<theName<<".SetGlyphPos("<<aParam<<")"<<endl;
648 //---------------------------------------------------------------------------
650 IsoSurfacesToPython(SALOMEDS::SObject_ptr theSObject,
651 VISU::IsoSurfaces_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;
660 theStr<<thePrefix<<theName<<".SetNbSurfaces("<<theServant->GetNbSurfaces()<<")"<<endl;
661 theStr<<thePrefix<<theName<<".ShowLabels("<<theServant->IsLabeled()<<","<<theServant->GetNbLabels()<<")"<<endl;
667 //---------------------------------------------------------------------------
669 CutPlanesToPython(SALOMEDS::SObject_ptr theSObject,
670 VISU::CutPlanes_i* theServant,
671 std::ostream& theStr,
672 const std::string& theName,
673 TColoredPrs3dFactory& thePrsFactory,
674 std::string thePrefix)
676 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
677 theStr<<thePrefix<<endl;
680 switch(theServant->GetOrientationType()){
682 aParam = "VISU.CutPlanes.XY";
685 aParam = "VISU.CutPlanes.YZ";
688 aParam = "VISU.CutPlanes.ZX";
691 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
693 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
694 CORBA::Long aNbPlanes = theServant->GetNbPlanes();
695 theStr<<thePrefix<<theName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
697 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
698 if(!theServant->IsDefault(anId))
699 theStr<<thePrefix<<theName<<".SetPlanePosition("<<anId<<", "<<theServant->GetPlanePosition(anId)<<")"<<endl;
702 theStr<<thePrefix<<theName<<".UseDeformation("<<GetBoolean(theServant->IsDeformed())<<")"<<endl;
703 if(theServant->IsDeformed()){
704 theStr<< thePrefix << theName << ".SetScale(" << theServant->GetScale()<<")"<<endl;
705 std::string aStringEntity;
706 VISU::Entity anEntity = theServant->GetVectorialFieldEntity();
709 aStringEntity = "VISU.NODE";
712 aStringEntity = "VISU.EDGE";
715 aStringEntity = "VISU.FACE";
718 aStringEntity = "VISU.CELL";
721 theStr<< thePrefix << theName << ".SetVectorialField("<<aStringEntity<<", '" << theServant->GetVectorialFieldName() <<"')"<<endl;
727 //---------------------------------------------------------------------------
729 CutLinesToPython(SALOMEDS::SObject_ptr theSObject,
730 VISU::CutLines_i* theServant,
731 std::ostream& theStr,
732 const std::string& theName,
733 TColoredPrs3dFactory& thePrsFactory,
734 std::string thePrefix)
736 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
737 theStr<<thePrefix<<endl;
740 switch(theServant->GetOrientationType()){
742 aParam = "VISU.CutPlanes.XY";
745 aParam = "VISU.CutPlanes.YZ";
748 aParam = "VISU.CutPlanes.ZX";
751 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
753 switch(theServant->GetOrientationType2()){
755 aParam = "VISU.CutPlanes.XY";
758 aParam = "VISU.CutPlanes.YZ";
761 aParam = "VISU.CutPlanes.ZX";
764 theStr<<thePrefix<<theName<<".SetOrientation2("<<aParam<<", "<<theServant->GetRotateX2()<<", "<<theServant->GetRotateY2()<<")"<<endl;
766 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
767 theStr<<thePrefix<<theName<<".SetDisplacement2("<<theServant->GetDisplacement2()<<")"<<endl;
769 if(!theServant->IsDefault())
770 theStr<<thePrefix<<theName<<".SetBasePlanePosition("<<theServant->GetBasePlanePosition()<<")"<<endl;
772 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
773 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
775 CORBA::Long aNbLines = theServant->GetNbLines();
776 theStr<<thePrefix<<theName<<".SetNbLines("<<aNbLines<<")"<<endl;
777 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
778 if(!theServant->IsDefaultPosition(anId))
779 theStr<<thePrefix<<theName<<".SetLinePosition("<<anId<<", "<<theServant->GetLinePosition(anId)<<")"<<endl;
786 //---------------------------------------------------------------------------
788 CutSegmentToPython(SALOMEDS::SObject_ptr theSObject,
789 VISU::CutSegment_i* theServant,
790 std::ostream& theStr,
791 const std::string& theName,
792 TColoredPrs3dFactory& thePrsFactory,
793 std::string thePrefix)
795 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
796 theStr<<thePrefix<<endl;
798 double x1, y1, z1, x2, y2, z2;
799 theServant->GetPoint1(x1, y1, z1);
800 theServant->GetPoint2(x2, y2, z2);
801 theStr<<thePrefix<<theName<<".SetPoint1("<<x1<<", "<<y1<<", "<<z1<<")"<<endl;
802 theStr<<thePrefix<<theName<<".SetPoint2("<<x2<<", "<<y2<<", "<<z2<<")"<<endl;
804 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
805 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
811 //---------------------------------------------------------------------------
813 Plot3DToPython(SALOMEDS::SObject_ptr theSObject,
814 VISU::Plot3D_i* theServant,
815 std::ostream& theStr,
816 const std::string& theName,
817 TColoredPrs3dFactory& thePrsFactory,
818 std::string thePrefix)
820 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
821 theStr<<thePrefix<<endl;
824 switch(theServant->GetOrientationType()){
826 aParam = "VISU.Plot3D.XY";
829 aParam = "VISU.Plot3D.YZ";
832 aParam = "VISU.Plot3D.ZX";
835 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
837 theStr<<thePrefix<<theName<<".SetPlanePosition("<<theServant->GetPlanePosition()<<", "<<theServant->IsPositionRelative()<<")"<<endl;
838 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
839 theStr<<thePrefix<<theName<<".SetContourPrs("<<theServant->GetIsContourPrs()<<")"<<endl;
840 theStr<<thePrefix<<theName<<".SetNbOfContours("<<theServant->GetNbOfContours()<<")"<<endl;
845 //---------------------------------------------------------------------------
847 void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
848 CORBA::Boolean theIsPublished,
849 CORBA::Boolean& theIsValidScript,
850 SALOMEDS::SObject_ptr theSObject,
851 std::ostream& theStr,
852 TName2EntryMap& theName2EntryMap,
853 TEntry2NameMap& theEntry2NameMap,
854 std::string theArgumentName,
855 std::string thePrefix);
857 //---------------------------------------------------------------------------
858 template<class TTableAttr>
860 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
861 CORBA::Boolean theIsPublished,
862 CORBA::Boolean& theIsValidScript,
863 SALOMEDS::SObject_ptr theSObject,
864 TTableAttr theTableAttr,
865 const std::string& theAttrName,
866 std::ostream& theStr,
867 TName2EntryMap& theName2EntryMap,
868 TEntry2NameMap& theEntry2NameMap,
869 std::string theArgumentName,
870 std::string thePrefix)
872 SALOMEDS::GenericAttribute_var anAttr;
873 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
874 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
875 SALOMEDS::AttributeString_var aComment =
876 SALOMEDS::AttributeString::_narrow(anAttr);
877 CORBA::String_var aValue = aComment->Value();
878 Storable::TRestoringMap aMap;
879 Storable::StringToMap(aValue.in(),aMap);
881 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
883 if(strcmp(aMethodName.toLatin1().data(),"ImportTables") == 0){
889 std::string aSObjectName = GetName(theSObject);
890 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
891 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
894 theStr<<thePrefix<<"aBuilder.SetName("<<aSObjectName<<", \""<<theSObject->GetName()<<"\")"<<endl; // Fix for IPAL13165
895 std::string aName = "aTableAttr";
896 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
897 aSObjectName<<", '"<<theAttrName<<"')"<<endl;
899 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
900 std::string aPrefix = thePrefix;
903 CORBA::String_var aString = theTableAttr->GetTitle();
904 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
906 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
907 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
909 CORBA::Long aNbRows = theTableAttr->GetNbRows();
911 // push values and their indices into streams
912 strstream values, rows, columns;
914 for(CORBA::Long i = 1; i <= aNbColumns; i++){
915 for(CORBA::Long j = aNbRows; j > 0; j--){
916 if(theTableAttr->HasValue(j,i)){
917 values << comma << theTableAttr->GetValue(j,i);
919 columns << comma << i;
925 // push titles and units into streams
926 strstream rowUnits, rowTitles, colTitles;
927 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
928 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
930 for(CORBA::Long j = 1; j <= aNbRows; j++){
931 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
932 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
936 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
938 for(CORBA::Long j = 1; j <= aNbColumns; j++){
939 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
949 // write FillTable command
950 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
951 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
952 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
953 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
954 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
955 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
956 theStr<< thePrefix << "visu.FillTable( "
958 << aName << "_values, "
959 << aName << "_rows, "
960 << aName << "_columns, "
961 << aName << "_rTitles, "
962 << aName << "_rUnits, "
963 << aName << "_cTitles )" << endl;
965 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
966 theStr<<thePrefix<<endl;
967 std::string aName = "aTable";
968 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
969 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
970 theArgumentName = aName;
972 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
973 std::string aPrefix2 = thePrefix + PREFIX;
975 // Set name (as this object could be renamed by user)
976 CORBA::String_var aNameInStudy = theSObject->GetName();
977 theStr<<aPrefix2<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 1"<<endl;
979 DumpChildrenToPython(theStudy,
989 theStr<<aPrefix2<<"pass"<<endl<<endl;
992 theStr<<thePrefix<<"pass"<<endl<<endl;
993 theStr<<aPrefix<<"pass"<<endl<<endl;
997 //---------------------------------------------------------------------------
999 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
1000 CORBA::Boolean theIsPublished,
1001 CORBA::Boolean& theIsValidScript,
1002 SALOMEDS::SObject_ptr theSObject,
1003 std::ostream& theStr,
1004 TName2EntryMap& theName2EntryMap,
1005 TEntry2NameMap& theEntry2NameMap,
1006 std::string theArgumentName,
1007 std::string thePrefix)
1009 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1010 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1011 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1012 DumpToPython(theStudy,
1025 //---------------------------------------------------------------------------
1027 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
1028 CORBA::Boolean theIsPublished,
1029 CORBA::Boolean& theIsValidScript,
1030 SALOMEDS::SObject_ptr theSObject,
1031 std::ostream& theStr,
1032 TName2EntryMap& theName2EntryMap,
1033 TEntry2NameMap& theEntry2NameMap,
1034 std::string theArgumentName,
1035 std::string thePrefix)
1037 SALOMEDS::GenericAttribute_var anAttr;
1038 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
1039 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
1040 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
1042 TableAttrToPython(theStudy,
1047 "AttributeTableOfInteger",
1054 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
1055 SALOMEDS::AttributeTableOfReal_var aTableAttr =
1056 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1058 TableAttrToPython(theStudy,
1063 "AttributeTableOfReal",
1074 //---------------------------------------------------------------------------
1076 DumpToPython(SALOMEDS::Study_ptr theStudy,
1077 CORBA::Boolean theIsPublished,
1078 CORBA::Boolean& theIsValidScript,
1079 SALOMEDS::SObject_ptr theSObject,
1080 std::ostream& theStr,
1081 TName2EntryMap& theName2EntryMap,
1082 TEntry2NameMap& theEntry2NameMap,
1083 std::string theArgumentName,
1084 std::string thePrefix)
1086 std::string aName = GetName(theSObject);
1090 CORBA::String_var anID = theSObject->GetID();
1091 CORBA::String_var aNameInStudy = theSObject->GetName();
1093 CORBA::Object_var anObj = SObjectToObject(theSObject);
1094 if (!CORBA::is_nil(anObj)) {
1095 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1096 if(!CORBA::is_nil(aBase)){
1097 std::string aName = GenerateName(theSObject, theName2EntryMap, theEntry2NameMap);
1099 VISU::VISUType aType = aBase->GetType();
1102 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
1103 std::string aFileName = aServant->GetInitFileName();
1104 Result_i::ECreationId anId = aServant->GetCreationId();
1105 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
1107 case Result_i::eImportFile:
1108 theStr<<thePrefix<<aName<<" = aVisu.CreateResult('"<<aFileName<<"')"<<endl;
1110 theStr<<thePrefix<<aName<<".SetBuildGroups("<<
1111 GetBoolean(aServant->IsGroupsDone())<<")"<<
1114 theStr<<thePrefix<<aName<<".SetBuildFields("<<
1115 GetBoolean(aServant->IsFieldsDone())<<", "<<
1116 GetBoolean(aServant->IsMinMaxDone())<<")"<<
1119 theStr<<thePrefix<<aName<<".Build(False, True)"<<endl;
1121 theStr<<thePrefix<<"if "<<aName<<".IsDone() :"<<endl;
1123 case Result_i::eCopyAndImportFile:
1124 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
1125 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1129 thePrefix += PREFIX;
1131 VISU::Result::EntityNames_var aMeshNames = aServant->GetMeshNames();
1132 if (aMeshNames->length() > 0) {
1133 for(size_t aMeshId = 0; aMeshId < aMeshNames->length(); aMeshId++){
1134 CORBA::String_var aMeshName = aMeshNames[aMeshId];
1135 VISU::Result::EntityNames_var aParts = aServant->GetPartNames(aMeshName);
1136 if (aParts->length() > 0) {
1137 for(size_t aPartId = 0; aPartId < aParts->length(); aPartId++){
1138 CORBA::String_var aPart = aParts[aPartId];
1139 VISU::Result::Resolution aResolution = aServant->GetResolution(aMeshName, aPart);
1141 switch(aResolution){
1142 case VISU::Result::FULL:
1143 aParam = "VISU.Result.FULL";
1145 case VISU::Result::MEDIUM:
1146 aParam = "VISU.Result.MEDIUM";
1148 case VISU::Result::LOW:
1149 aParam = "VISU.Result.LOW";
1151 case VISU::Result::HIDDEN:
1152 aParam = "VISU.Result.HIDDEN";
1155 theStr<<thePrefix<<aName<<".SetResolution('"<<aMeshName.in()<<"', '"<<aPart.in()<<"', "<<aParam<<")"<<endl;
1157 theStr<<thePrefix<<endl;
1163 theArgumentName = aName;
1164 DumpChildrenToPython(theStudy,
1174 theStr<<thePrefix<<"pass"<<endl<<endl;
1176 SALOMEDS::SObject_var aRefSObj;
1177 if(theSObject->FindSubObject(1,aRefSObj)){
1178 SALOMEDS::SObject_var aTargetRefSObj;
1179 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
1180 CORBA::String_var aString = aTargetRefSObj->GetName();
1181 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
1182 theStr<<thePrefix<<"if aSObject:"<<endl;
1183 thePrefix += PREFIX;
1184 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
1185 theStr<<thePrefix<<"if anObject:"<<endl;
1186 std::string aPrefix1 = thePrefix;
1187 thePrefix += PREFIX;
1190 case Result_i::eImportMed:
1191 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
1193 case Result_i::eImportMedField:
1194 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
1198 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1199 std::string aPrefix2 = thePrefix;
1200 thePrefix += PREFIX;
1202 theArgumentName = aName;
1203 DumpChildrenToPython(theStudy,
1213 theStr<<thePrefix<<"pass"<<endl<<endl;
1214 theStr<<aPrefix2<<"pass"<<endl<<endl;
1215 theStr<<aPrefix1<<"pass"<<endl<<endl;
1222 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
1223 VISU::Entity anEntity = aServant->GetEntity();
1224 const std::string& aSubMeshName = aServant->GetSubMeshName();
1229 aParam = "VISU.NODE";
1232 aParam = "VISU.EDGE";
1235 aParam = "VISU.FACE";
1238 aParam = "VISU.CELL";
1242 if(aSubMeshName == "")
1243 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
1244 ", '"<<aServant->GetCMeshName()<<"'"<<
1248 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
1249 ", '"<<aServant->GetCMeshName()<<"'"<<
1251 ", '"<<aSubMeshName<<"'"<<
1254 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
1255 ", '"<<aServant->GetCMeshName()<<"'"<<
1256 ", '"<<aSubMeshName<<"'"<<
1259 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1260 thePrefix += PREFIX;
1262 // Add to Name->Object map
1263 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
1265 // Set name (as this object could be renamed by user)
1266 theStr<<thePrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1268 // Set parameters common for all Prs3d objects (offset values)
1269 Prs3dToPython(aServant,theStr,aName,thePrefix);
1271 // Set presentation parameters
1272 SALOMEDS::Color aColor;
1273 aColor = aServant->GetCellColor();
1274 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
1275 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1277 aColor = aServant->GetNodeColor();
1278 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
1279 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1281 aColor = aServant->GetLinkColor();
1282 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
1283 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1286 switch(aServant->GetPresentationType()){
1288 aParam = "VISU.POINT";
1291 aParam = "VISU.WIREFRAME";
1294 aParam = "VISU.SHADED";
1297 aParam = "VISU.INSIDEFRAME";
1300 aParam = "VISU.SURFACEFRAME";
1303 aParam = "VISU.SHRINK";
1306 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
1307 theStr<<thePrefix<<aName<<".SetShrink("<<(aServant->IsShrank()? "True" : "False")<<")"<<endl;
1308 theStr<<thePrefix<<endl;
1310 std::string aQuad2DPresent;
1311 switch(aServant->GetQuadratic2DPresentationType()){
1313 aQuad2DPresent = "VISU.LINES";
1316 aQuad2DPresent = "VISU.ARCS";
1320 theStr<<thePrefix<<aName<<".SetQuadratic2DPresentationType("<<aQuad2DPresent<<")"<<endl;
1322 DumpChildrenToPython(theStudy,
1332 theStr<<thePrefix<<"pass"<<endl<<endl;
1336 case VISU::TSCALARMAP:
1337 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
1338 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "ScalarMapOnField", theArgumentName);
1339 thePrefix = ScalarMapToPython(theSObject, aServant, theStr,aName, aPrsFactory, thePrefix);
1340 theStr<<thePrefix<<"pass"<<endl<<endl;
1343 case VISU::TDEFORMEDSHAPE:
1344 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
1345 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeOnField", theArgumentName);
1346 thePrefix = DeformedShapeToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1347 theStr<<thePrefix<<"pass"<<endl<<endl;
1350 case VISU::TSTREAMLINES:
1351 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
1352 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "StreamLinesOnField", theArgumentName);
1353 thePrefix = StreamLinesToPython(theSObject, aServant, theStr, theEntry2NameMap, aName, aPrsFactory, thePrefix);
1354 theStr<<thePrefix<<"pass"<<endl<<endl;
1357 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1358 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1359 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(GetServant(anObj).in())){
1360 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeAndScalarMapOnField", theArgumentName);
1361 thePrefix = DeformedShapeAndScalarMapToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1362 theStr<<thePrefix<<"pass"<<endl<<endl;
1365 case VISU::TVECTORS:
1366 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
1367 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "VectorsOnField", theArgumentName);
1368 thePrefix = VectorsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1369 theStr<<thePrefix<<"pass"<<endl<<endl;
1372 case VISU::TISOSURFACES:
1373 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
1374 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "IsoSurfacesOnField", theArgumentName);
1375 thePrefix = IsoSurfacesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1376 theStr<<thePrefix<<"pass"<<endl<<endl;
1379 case VISU::TCUTPLANES:
1380 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
1381 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutPlanesOnField", theArgumentName);
1382 thePrefix = CutPlanesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1383 theStr<<thePrefix<<"pass"<<endl<<endl;
1386 case VISU::TCUTLINES:
1387 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
1388 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutLinesOnField", theArgumentName);
1389 thePrefix = CutLinesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1391 theArgumentName = aName;
1392 DumpChildrenToPython(theStudy,
1402 theStr<<thePrefix<<"pass"<<endl<<endl;
1405 case VISU::TCUTSEGMENT:
1406 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(GetServant(anObj).in())){
1407 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutSegmentOnField", theArgumentName);
1408 thePrefix = CutSegmentToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1410 theArgumentName = aName;
1411 DumpChildrenToPython(theStudy,
1421 theStr<<thePrefix<<"pass"<<endl<<endl;
1425 if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
1426 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
1427 thePrefix = Plot3DToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1428 theStr<<thePrefix<<"pass"<<endl<<endl;
1431 case VISU::TPOINTMAP3D:
1432 if (PointMap3d_i* aServant = dynamic_cast<PointMap3d_i*>(GetServant(anObj).in())) {
1433 CORBA::Short aTag = theSObject->Tag();
1434 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1435 theStr<<thePrefix<<"if anIsFound:"<<endl;
1436 thePrefix += PREFIX;
1438 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1439 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1441 // Set name (as this object could be renamed by user)
1442 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1444 // Set PointMap3D Properties
1446 theStr<<thePrefix<<aName<<".SetScaleFactor("<<aServant->GetScaleFactor()<<")"<<endl;
1447 theStr<<thePrefix<<aName<<".SetContourPrs("<<aServant->GetIsContourPrs()<<")"<<endl;
1448 theStr<<thePrefix<<aName<<".SetNbOfContours("<<aServant->GetNbOfContours()<<")"<<endl;
1451 switch(aServant->GetScaling()){
1453 aParam = "VISU.LINEAR";
1456 aParam = "VISU.LOGARITHMIC";
1459 theStr<<thePrefix<<aName<<".SetScaling("<<aParam<<")"<<endl;
1461 theStr<<thePrefix<<aName<<".SetNbColors("<<aServant->GetNbColors()<<")"<<endl;
1462 theStr<<thePrefix<<aName<<".SetLabels("<<aServant->GetLabels()<<")"<<endl;
1464 switch(aServant->GetBarOrientation()){
1465 case ColoredPrs3dBase::HORIZONTAL:
1466 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
1468 case ColoredPrs3dBase::VERTICAL:
1469 aParam = "VISU.ColoredPrs3d.VERTICAL";
1472 theStr<<thePrefix<<aName<<".SetBarOrientation("<<aParam<<")"<<endl;
1474 if(aServant->IsRangeFixed())
1475 theStr<<thePrefix<<aName<<".SetRange("<<aServant->GetMin()<<", "<<aServant->GetMax()<<")"<<endl;
1477 theStr<<thePrefix<<aName<<".SetSourceRange()"<<endl;
1479 theStr<<thePrefix<<aName<<".SetPosition("<<aServant->GetPosX()<<", "<<aServant->GetPosY()<<")"<<endl;
1480 theStr<<thePrefix<<aName<<".SetSize("<<aServant->GetWidth()<<", "<<aServant->GetHeight()<<")"<<endl;
1483 aServant->GetOffset(dx, dy, dz);
1484 theStr<<thePrefix<<aName<<".SetOffset("<<dx<<", "<<dy<<", "<<dz<<")"<<endl;
1487 theStr<<thePrefix<<endl;
1489 theArgumentName = aName;
1490 DumpChildrenToPython(theStudy,
1500 theStr<<thePrefix<<"pass"<<endl<<endl;
1503 case VISU::TGAUSSPOINTS:
1504 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(GetServant(anObj).in())){
1505 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "GaussPointsOnField", theArgumentName);
1506 thePrefix = GaussPointsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1507 theStr<<thePrefix<<"pass"<<endl<<endl;
1511 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
1513 bool withZ = aServant->GetZRow()>0;
1515 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
1519 theArgumentName<< // table
1520 ", "<<aServant->GetHRow()<< // H row
1521 ", "<<aServant->GetVRow(); // V row
1523 theStr << ", " << aServant->GetZRow(); // Z row
1525 theStr << ", '"<<aServant->GetTitle()<<"'"; // title
1526 SALOMEDS::Color aColor = aServant->GetColor();
1527 theStr << ",SALOMEDS.Color("<<
1528 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<")"; // color
1531 switch(aServant->GetMarker()){
1532 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
1533 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
1534 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
1535 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
1536 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
1537 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
1538 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
1539 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
1540 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
1541 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
1543 theStr<<", "<<aParam; // marker
1545 switch(aServant->GetLine()){
1546 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
1547 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
1548 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
1549 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
1550 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
1551 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
1553 theStr<<", "<<aParam<<", "<<aServant->GetLineWidth()<<")"<<endl; // line type,width
1557 if(dynamic_cast<Table_i*>(GetServant(anObj).in())){
1558 SALOMEDS::GenericAttribute_var anAttr;
1559 if(theSObject->FindAttribute(anAttr,"AttributeString")){
1560 using namespace SALOMEDS;
1561 AttributeString_var aComment = AttributeString::_narrow(anAttr);
1562 CORBA::String_var aValue = aComment->Value();
1563 Storable::TRestoringMap aMap;
1564 Storable::StringToMap(aValue.in(),aMap);
1566 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1568 if( aSourceId == "CutLines" ){
1569 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
1570 thePrefix += PREFIX;
1572 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
1573 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
1574 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
1575 theStr<<thePrefix<<"if aSObject:"<<endl;
1576 std::string aPrefix = thePrefix;
1577 thePrefix += PREFIX;
1579 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1580 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1582 // Set name (as this object could be renamed by user)
1583 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 2"<<endl;
1585 theStr<<thePrefix<<endl;
1587 theArgumentName = aName;
1588 DumpChildrenToPython(theStudy,
1598 theStr<<thePrefix<<"pass"<<endl<<endl;
1599 theStr<<aPrefix<<"pass"<<endl<<endl;
1600 }else if( aSourceId == "TableFile" ){
1601 CORBA::Short aTag = theSObject->Tag();
1602 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1603 theStr<<thePrefix<<"if anIsFound:"<<endl;
1604 thePrefix += PREFIX;
1606 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1607 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1609 // Set name (as this object could be renamed by user)
1610 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1612 theStr<<thePrefix<<endl;
1614 theArgumentName = aName;
1615 DumpChildrenToPython(theStudy,
1625 theStr<<thePrefix<<"pass"<<endl<<endl;
1626 }else if( aSourceId == "TableAttr" ){
1627 theArgumentName = aName;
1628 DumpTableAttrToPython(theStudy,
1644 } else { /*if(!CORBA::is_nil(anObj))*/
1645 SALOMEDS::GenericAttribute_var anAttr;
1646 if (theSObject->FindAttribute(anAttr,"AttributeString")) {
1647 SALOMEDS::AttributeString_var aComment =
1648 SALOMEDS::AttributeString::_narrow(anAttr);
1649 CORBA::String_var aValue = aComment->Value();
1650 Storable::TRestoringMap aMap;
1651 Storable::StringToMap(aValue.in(),aMap);
1653 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1655 if (aTypeName == "ImportTables") {
1656 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1658 std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1659 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.toLatin1().data()<<"')"<<endl;
1660 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1661 thePrefix += PREFIX;
1663 theArgumentName = aName;
1664 DumpChildrenToPython(theStudy,
1674 theStr<<thePrefix<<"pass"<<endl<<endl;
1677 } else if (aTypeName == "VIEW3D") {
1678 std::string aName = GetName(theSObject);
1679 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1681 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1682 thePrefix += PREFIX;
1684 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1685 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1687 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1688 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1690 theStr<<thePrefix<<"pass"<<endl<<endl;
1692 } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1693 // Set name (as this object could be renamed by user)
1694 string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1695 string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1696 string anEntityTypeKey = "myEntityId";
1697 if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1698 int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1699 std::string anEntityType;
1700 switch ((TEntity)anEntity) {
1701 case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1702 case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1703 case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1704 case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1707 if (aTypeName == "ENTITY" ) {
1708 theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1709 <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1711 else if (aTypeName == "FAMILY") {
1712 if (aSubMeshName != aNameInStudy.in()) {
1713 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1714 <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1718 if (aSubMeshName != aNameInStudy.in()) {
1719 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1720 <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1726 DumpTableAttrToPython(theStudy,
1738 DumpChildrenToPython(theStudy,
1750 //---------------------------------------------------------------------------
1752 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1753 CORBA::Boolean theIsPublished,
1754 CORBA::Boolean& theIsValidScript,
1755 SALOMEDS::SObject_ptr theSObject,
1756 std::ostream& theStr,
1757 TName2EntryMap& theName2EntryMap,
1758 TEntry2NameMap& theEntry2NameMap,
1759 std::string theArgumentName,
1760 std::string thePrefix)
1762 SALOMEDS::SObject_var aTargetRefSObj;
1763 if(theSObject->ReferencedObject(aTargetRefSObj)){
1764 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1765 if(CORBA::is_nil(anObj))
1768 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1769 if(CORBA::is_nil(aBase))
1772 if(aBase->GetType() == VISU::TCURVE){
1773 CORBA::String_var anID = aTargetRefSObj->GetID();
1774 std::string anArg = theEntry2NameMap[anID.in()];
1775 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1776 thePrefix += PREFIX;
1777 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1778 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1779 theStr<<thePrefix<<"pass"<<endl<<endl;
1785 //---------------------------------------------------------------------------
1787 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1788 CORBA::Boolean theIsPublished,
1789 CORBA::Boolean& theIsValidScript,
1790 SALOMEDS::SObject_ptr theSObject,
1791 std::ostream& theStr,
1792 TName2EntryMap& theName2EntryMap,
1793 TEntry2NameMap& theEntry2NameMap,
1794 std::string theArgumentName,
1795 std::string thePrefix)
1797 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1798 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1799 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1800 CORBA::Object_var anObj = SObjectToObject(aSObject);
1801 if(CORBA::is_nil(anObj))
1804 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1805 if(CORBA::is_nil(aBase))
1808 if(aBase->GetType() == VISU::TCONTAINER){
1809 theStr<<thePrefix<<endl;
1810 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1811 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1812 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1813 std::string aPrefix = thePrefix + PREFIX;
1814 theArgumentName = aName;
1816 // Set name (as this object could be renamed by user)
1817 CORBA::String_var aNameInStudy = aSObject->GetName();
1818 theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1820 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1821 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1822 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1823 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1826 theStr<<aPrefix<<"pass"<<endl<<endl;
1832 //---------------------------------------------------------------------------
1834 DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1835 CORBA::Boolean theIsPublished,
1836 CORBA::Boolean& theIsValidScript,
1837 SALOMEDS::SObject_ptr theSObject,
1838 std::ostream& theStr,
1839 TName2EntryMap& theName2EntryMap,
1840 TEntry2NameMap& theEntry2NameMap,
1841 std::string theArgumentName,
1842 std::string thePrefix)
1845 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1846 for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1847 SALOMEDS::SObject_var aSObject = anIter->Value();
1848 CORBA::Object_var anObj = SObjectToObject(aSObject);
1849 if(CORBA::is_nil(anObj))
1852 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1853 if(CORBA::is_nil(aBase))
1856 if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1857 ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1858 theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1859 theStr<<thePrefix<<"if aCache != None:"<<endl;
1861 std::string aPrefix = thePrefix + PREFIX;
1862 std::string anArgument;
1863 VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1865 case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1866 case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1868 theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1870 if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1871 theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1873 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1874 for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1875 SALOMEDS::SObject_var aSObject = aChildIter->Value();
1876 CORBA::Object_var anObject = SObjectToObject(aSObject);
1877 if (CORBA::is_nil(anObject))
1880 ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1884 ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1888 Result_i* aResult = aDevice->GetCResult();
1889 std::string aResultEntry = aResult->GetEntry();
1890 std::string aResultName = theEntry2NameMap[aResultEntry];
1892 ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1893 std::string anEntity;
1894 switch(anInput->myEntity){
1895 case VISU::NODE : anEntity = "VISU.NODE"; break;
1896 case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1897 case VISU::FACE : anEntity = "VISU.FACE"; break;
1898 case VISU::CELL : anEntity = "VISU.CELL"; break;
1902 theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
1903 aResultName<<", '"<<
1904 anInput->myMeshName<<"', "<<
1906 anInput->myFieldName<<"', "<<
1907 anInput->myTimeStampNumber<<")"<<
1910 std::string aComment = aDevice->GetComment();
1911 theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
1912 theStr<<aPrefix<<"if aHolder != None:"<<endl;
1914 std::string aPrefix2 = aPrefix + PREFIX;
1915 CORBA::String_var aNameInStudy = aSObject->GetName();
1916 theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
1917 theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
1918 theStr<<aPrefix2<<"if aDevice != None:"<<endl;
1920 std::string aPrefix3 = aPrefix2 + PREFIX;
1921 TColoredPrs3dFactory aPrsFactory;
1922 switch(aDevice->GetType()){
1923 case VISU::TSCALARMAP:
1924 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
1925 ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1928 case VISU::TDEFORMEDSHAPE:
1929 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
1930 DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1933 case VISU::TSTREAMLINES:
1934 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
1935 StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
1938 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1939 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1940 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
1941 DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1944 case VISU::TVECTORS:
1945 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
1946 VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1949 case VISU::TISOSURFACES:
1950 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
1951 IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1954 case VISU::TCUTPLANES:
1955 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
1956 CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1959 case VISU::TCUTLINES:
1960 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
1961 CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1964 case VISU::TCUTSEGMENT:
1965 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(aDevice)){
1966 CutSegmentToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1970 if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
1971 Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1974 case VISU::TGAUSSPOINTS:
1975 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
1976 GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1980 theStr<<aPrefix3<<"pass"<<endl;
1982 theStr<<aPrefix2<<"pass"<<endl<<endl;
1985 theStr<<aPrefix<<"pass"<<endl;
1992 //---------------------------------------------------------------------------
1994 DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
1995 CORBA::Boolean theIsPublished,
1996 CORBA::Boolean& theIsValidScript,
1997 SALOMEDS::SObject_ptr theSObject,
1998 std::ostream& theStr,
1999 std::string thePrefix)
2002 if(!theIsPublished) return;
2004 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2005 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2006 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2008 SALOMEDS::GenericAttribute_var anAttr;
2009 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2011 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2012 QString value (aStringAttr->Value());
2013 if(value.isEmpty()) continue;
2015 VISU::Storable::TRestoringMap aMap;
2016 VISU::Storable::StringToMap(value, aMap);
2019 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2020 if(!isExist || aTypeName != "ANIMATION") continue;
2023 theStr<<thePrefix<<endl;
2024 QString animName = aSObject->GetName();
2025 theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
2026 theStr<<thePrefix<<endl;
2027 theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
2028 theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
2029 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
2030 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2034 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2035 for (anIter->Init(); anIter->More(); anIter->Next()) {
2036 SALOMEDS::SObject_var anObj = anIter->Value();
2039 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
2040 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2041 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2042 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2043 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2046 SALOMEDS::SObject_var refObj;
2047 if(anObj->ReferencedObject(refObj)) {
2048 SALOMEDS::SObject_var father = refObj->GetFather();
2049 value = refObj->GetName();
2050 QString path(theStudy->GetObjectPath(father));
2051 //The following code requierd as a field name can contain '/' character
2052 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2054 value = anObj->GetName();
2055 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2058 SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
2059 for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
2060 SALOMEDS::SObject_var aSubObj = aSubIter->Value();
2062 theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
2063 value = aSubObj->GetName();
2064 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
2065 if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
2066 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2067 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2068 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2076 theStr<<thePrefix<<endl;
2081 DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2082 CORBA::Boolean theIsPublished,
2083 CORBA::Boolean& theIsValidScript,
2084 SALOMEDS::SObject_ptr theSObject,
2085 std::ostream& theStr,
2086 std::string thePrefix,
2087 VISU_ClippingPlaneMgr& thePlaneMgr)
2090 if(!theIsPublished) return;
2092 VISU_CutPlaneFunction* aPlane;
2093 double aOrigin[3], aDir[3];
2094 for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2095 aPlane = thePlaneMgr.GetClippingPlane(i);
2096 aPlane->GetOrigin(aOrigin);
2097 aPlane->GetNormal(aDir);
2099 theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2100 aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2101 aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2102 aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;
2108 //---------------------------------------------------------------------------
2111 DumpPython(CORBA::Object_ptr theStudy,
2112 CORBA::Boolean theIsPublished,
2113 CORBA::Boolean& theIsValidScript)
2115 theIsValidScript = false;
2117 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2118 if(CORBA::is_nil(aStudy))
2119 return new Engines::TMPFile(0);
2121 TName2EntryMap aName2EntryMap;
2122 TEntry2NameMap aEntry2NameMap;
2130 std::string aPrefix(PREFIX);
2131 aStr<<"### This file is generated by SALOME automatically by dump python functionality"
2132 " of VISU component"<<endl<<endl;
2133 aStr<<"def RebuildData(theStudy):"<<endl;
2134 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2135 aStr<<aPrefix<<"import SALOME_MED"<<endl;
2136 aStr<<aPrefix<<"import SALOMEDS"<<endl;
2137 aStr<<aPrefix<<"import VISU"<<endl;
2138 aStr<<aPrefix<<"import visu"<<endl;
2140 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2141 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2142 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2143 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2144 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2147 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2149 VISU::DumpClippingPlanesToPython(aStudy,
2155 myClippingPlaneMgr);
2158 VISU::DumpChildrenToPython(aStudy,
2168 VISU::DumpContainersToPython(aStudy,
2178 VISU::DumpPrs3dCacheToPython(aStudy,
2188 VISU::DumpAnimationsToPython(aStudy,
2196 //Output the script that sets up the visul parameters.
2197 if(theIsPublished) {
2198 char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2199 if(script && strlen(script) > 0) {
2201 CORBA::string_free(script);
2205 aStr<<aPrefix<<"pass"<<endl;
2207 if(theIsPublished) { //SRN: define function for Animation
2209 //Define a function that find a SObject by its father's path and its name
2213 aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
2214 aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
2215 aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
2216 aStr<<aPrefix<<"while itr.More():"<<endl;
2217 aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
2218 aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
2219 aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
2220 aStr<<aPrefix<<aPrefix<<"pass"<<endl;
2221 aStr<<aPrefix<<"return None"<<endl;
2226 // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2227 // If the situation changes, then the following line should be removed, and theIsValidScript
2228 // should be set properly by those internal methods
2229 theIsValidScript = true;
2232 std::string aResult = aStr.str();
2233 //ofstream anFStream("/tmp/dump.py");
2234 //anFStream<<aResult<<endl;
2236 CORBA::ULong aSize = aResult.size() + 1;
2237 char* aBuffer = new char[aSize];
2238 strcpy(aBuffer,&aResult[0]);
2239 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2242 return new Engines::TMPFile(0);