1 // Copyright (C) 2007-2010 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_DumpPython.cc
25 // Author : Alexey PETROV
28 #include "VISU_Gen_i.hh"
29 #include "VISU_Result_i.hh"
30 #include "VISU_PrsObject_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Mesh_i.hh"
34 #include "VISU_ScalarMap_i.hh"
35 #include "VISU_IsoSurfaces_i.hh"
36 #include "VISU_DeformedShape_i.hh"
37 #include "VISU_CutPlanes_i.hh"
38 #include "VISU_CutLines_i.hh"
39 #include "VISU_CutSegment_i.hh"
40 #include "VISU_Vectors_i.hh"
41 #include "VISU_StreamLines_i.hh"
42 #include "VISU_Plot3D_i.hh"
43 #include "VISU_Table_i.hh"
44 #include "VISU_PointMap3d_i.hh"
45 #include "VISU_GaussPoints_i.hh"
46 #include "VISU_DeformedShapeAndScalarMap_i.hh"
47 #include "VISU_ColoredPrs3dCache_i.hh"
48 #include "VISU_ColoredPrs3dHolder_i.hh"
50 #include "utilities.h"
65 //---------------------------------------------------------------------------
66 static std::string PREFIX(" ");
68 typedef std::map<std::string,std::string> TName2EntryMap;
69 typedef std::map<std::string,std::string> TEntry2NameMap;
72 //---------------------------------------------------------------------------
75 GenerateName(std::string theName,
76 SALOMEDS::SObject_ptr theSObject,
77 TName2EntryMap& theName2EntryMap,
78 TEntry2NameMap& theEntry2NameMap,
81 if(theName2EntryMap.find(theName) != theName2EntryMap.end()){
82 theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix);
84 CORBA::String_var anID = theSObject->GetID();
85 theName2EntryMap[theName] = anID.in();
86 theEntry2NameMap[anID.in()] = theName;
87 //cout<<"GenerateName - "<<theName<<" => "<<anID.in()<<endl;
94 //---------------------------------------------------------------------------
95 struct TReplacePredicate
97 bool operator()(char theChar) const
99 return !(isdigit(theChar) || isalpha(theChar) || theChar == '_');
104 //---------------------------------------------------------------------------
107 GetName(SALOMEDS::SObject_ptr theSObject)
109 CORBA::String_var aString = theSObject->GetName();
111 std::string aName = QString(aString.in()).simplified().toLatin1().data();
113 //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_');
114 replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_');
116 if ( isdigit( aName[0] ))
117 aName.insert( 0, 1, 'a' );
123 //---------------------------------------------------------------------------
126 GenerateName(SALOMEDS::SObject_ptr theSObject,
127 TName2EntryMap& theName2EntryMap,
128 TEntry2NameMap& theEntry2NameMap)
130 std::string aName = GetName(theSObject);
132 return GenerateName(aName, theSObject, theName2EntryMap, theEntry2NameMap, 'X');
136 //---------------------------------------------------------------------------
139 GetBoolean(bool theArgument)
148 //---------------------------------------------------------------------------
151 GetColor(const SALOMEDS::Color& theColor)
153 std::ostringstream aStream;
154 aStream<<"SALOMEDS.Color("<<theColor.R<<", "<<theColor.G<<", "<<theColor.B<<")";
155 return aStream.str();
159 //---------------------------------------------------------------------------
160 typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy,
161 CORBA::Boolean theIsPublished,
162 CORBA::Boolean& theIsValidScript,
163 SALOMEDS::SObject_ptr theSObject,
164 std::ostream& theStr,
165 TName2EntryMap& theName2EntryMap,
166 TEntry2NameMap& theEntry2NameMap,
167 std::string theArgumentName,
168 std::string thePrefix);
172 DumpToPython(SALOMEDS::Study_ptr theStudy,
173 CORBA::Boolean theIsPublished,
174 CORBA::Boolean& theIsValidScript,
175 SALOMEDS::SObject_ptr theSObject,
176 std::ostream& theStr,
177 TName2EntryMap& theName2EntryMap,
178 TEntry2NameMap& theEntry2NameMap,
179 std::string theArgumentName,
180 std::string thePrefix);
183 //---------------------------------------------------------------------------
184 void SetClippingPlane(Prs3d_i* thePrs, string theName,
185 std::ostream& theStr,
186 std::string thePrefix)
188 VISU_CutPlaneFunction* aPlane;
189 VISU_Gen_i* aGen = VISU_Gen_i::GetVisuGenImpl();
190 VISU_ClippingPlaneMgr& aMgr = aGen->GetClippingPlaneMgr();
192 for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) {
193 aPlane = dynamic_cast<VISU_CutPlaneFunction*>(thePrs->GetClippingPlane(i));
195 if (!aPlane->isAuto()) {
196 aId = aMgr.GetPlaneId(aPlane);
198 theStr<<thePrefix<<"aVisu.ApplyClippingPlane("<<theName<<", "<<aId<<")"<<endl;
207 Prs3dToPython(VISU::Prs3d_i* theServant,
208 std::ostream& theStr,
209 const std::string& theName,
210 std::string thePrefix)
213 theServant->GetOffset(x,y,z);
214 theStr<<thePrefix<<theName<<".SetOffset("<<x<<", "<<y<<", "<<z<<")"<<endl;
215 SetClippingPlane(theServant, theName, theStr, thePrefix);
217 VISU::MarkerType aMarkerType = theServant->GetMarkerType();
218 if( aMarkerType != VISU::MT_NONE ) {
219 if( aMarkerType != VISU::MT_USER ) {
220 VISU::MarkerScale aMarkerScale = theServant->GetMarkerScale();
221 std::string aParam1, aParam2;
222 switch( aMarkerType ) {
223 case MT_POINT: aParam1 = "MT_POINT"; break;
224 case MT_PLUS: aParam1 = "MT_PLUS"; break;
225 case MT_STAR: aParam1 = "MT_STAR"; break;
226 case MT_O: aParam1 = "MT_O"; break;
227 case MT_X: aParam1 = "MT_X"; break;
228 case MT_O_POINT: aParam1 = "MT_O_POINT"; break;
229 case MT_O_PLUS: aParam1 = "MT_O_PLUS"; break;
230 case MT_O_STAR: aParam1 = "MT_O_STAR"; break;
231 case MT_O_X: aParam1 = "MT_O_X"; break;
232 case MT_POINT_SPRITE: aParam1 = "MT_POINT_SPRITE"; break;
233 default: aParam1 = "MT_NONE"; break;
235 switch( aMarkerScale ) {
236 case MS_10: aParam2 = "MS_10"; break;
237 case MS_15: aParam2 = "MS_15"; break;
238 case MS_20: aParam2 = "MS_20"; break;
239 case MS_25: aParam2 = "MS_25"; break;
240 case MS_30: aParam2 = "MS_30"; break;
241 case MS_35: aParam2 = "MS_35"; break;
242 case MS_40: aParam2 = "MS_40"; break;
243 case MS_45: aParam2 = "MS_45"; break;
244 case MS_50: aParam2 = "MS_50"; break;
245 case MS_55: aParam2 = "MS_55"; break;
246 case MS_60: aParam2 = "MS_60"; break;
247 case MS_65: aParam2 = "MS_65"; break;
248 case MS_70: aParam2 = "MS_70"; break;
249 default: aParam2 = "MS_NONE"; break;
251 if( aMarkerType == MT_POINT_SPRITE )
253 theStr<<thePrefix<<theName<<".SetMarkerStd(VISU."<<aParam1<<", VISU."<<aParam2<<")"<<endl;
256 int aMarkerTexture = theServant->GetMarkerTexture();
257 if( aMarkerTexture >= 0 )
258 theStr<<thePrefix<<theName<<".SetMarkerTexture(texture_map["<<aMarkerTexture<<"])"<<endl;
263 //---------------------------------------------------------------------------
264 struct TColoredPrs3dFactory
268 operator()(std::ostream& theStr,
269 std::string thePrefix)
277 struct TCreateFromResult: TColoredPrs3dFactory
279 VISU::ColoredPrs3d_i* myServant;
280 std::string myConstructorName;
281 std::string myArgumentName;
283 SALOMEDS::SObject_var mySObject;
286 TCreateFromResult(const SALOMEDS::SObject_ptr theSObject,
287 VISU::ColoredPrs3d_i* theServant,
288 const std::string& theName,
289 const std::string& theConstructorName,
290 const std::string& theArgumentName):
291 myServant(theServant),
292 myConstructorName(theConstructorName),
293 myArgumentName(theArgumentName),
296 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
301 operator()(std::ostream& theStr,
302 std::string thePrefix)
305 switch(myServant->GetEntity()){
307 aParam = "VISU.NODE";
310 aParam = "VISU.EDGE";
313 aParam = "VISU.FACE";
316 aParam = "VISU.CELL";
320 theStr<<thePrefix<<myName<<" = aVisu."<<myConstructorName<<"("<<myArgumentName<<
321 ", '"<<myServant->GetCMeshName()<<"'"<<
323 ", '"<<myServant->GetCFieldName()<<"'"<<
324 ", "<<myServant->GetTimeStampNumber()<<
327 theStr<<thePrefix<<"if "<<myName<<" != None:"<<endl;
330 // Add to Name->Object map
331 theStr<<thePrefix<<"aName2ObjectMap['"<<myName<<"'] = "<<myName<<endl;
333 // Set name (as this object could be renamed by user)
334 CORBA::String_var aNameInStudy = mySObject->GetName();
335 theStr<<thePrefix<<"visu.SetName("<<myName<<", '"<<aNameInStudy.in()<<"')"<<endl;
342 //---------------------------------------------------------------------------
344 ColoredPrs3dToPython(SALOMEDS::SObject_ptr theSObject,
345 VISU::ColoredPrs3d_i* theServant,
346 std::ostream& theStr,
347 const std::string& theName,
348 TColoredPrs3dFactory& thePrsFactory,
349 std::string thePrefix)
351 thePrefix = thePrsFactory(theStr, thePrefix);
353 // Set parameters common for all Prs3d objects (offset values)
354 Prs3dToPython(theServant, theStr, theName, thePrefix);
356 theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<", "<<theServant->GetPosY()<<")"<<endl;
357 theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<", "<<theServant->GetHeight()<<")"<<endl;
358 theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
359 theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
360 theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
363 switch(theServant->GetBarOrientation()){
364 case ColoredPrs3dBase::HORIZONTAL:
365 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
367 case ColoredPrs3dBase::VERTICAL:
368 aParam = "VISU.ColoredPrs3d.VERTICAL";
371 theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
373 theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
375 if(theServant->IsRangeFixed())
376 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
378 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
380 const VISU::ColoredPrs3d_i::TGroupNames aGroupNames = theServant->GetGroupNames();
381 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
382 for(; anIter != aGroupNames.end(); anIter++){
383 const std::string& aGroupName = *anIter;
384 theStr<<thePrefix<<theName<<".AddMeshOnGroup('"<<aGroupName<<"')"<<endl;
391 //---------------------------------------------------------------------------
393 GaussPointsToPython(SALOMEDS::SObject_ptr theSObject,
394 VISU::GaussPoints_i* theServant,
395 std::ostream& theStr,
396 const std::string& theName,
397 TColoredPrs3dFactory& thePrsFactory,
398 std::string thePrefix)
400 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
401 theStr<<thePrefix<<endl;
403 bool aBoolean = theServant->GetIsActiveLocalScalarBar();
404 theStr<<thePrefix<<theName<<".SetIsActiveLocalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
407 aBoolean = theServant->GetIsDispGlobalScalarBar();
408 theStr<<thePrefix<<theName<<".SetIsDispGlobalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
411 theStr<<thePrefix<<theName<<".SetSpacing("<<theServant->GetSpacing()<<")"<<endl;
413 aBoolean = theServant->GetBiColor();
414 theStr<<thePrefix<<theName<<".SetBiColor("<<GetBoolean(aBoolean)<<")"<<endl;
416 aBoolean = theServant->GetIsDeformed();
417 theStr<<thePrefix<<theName<<".SetIsDeformed("<<GetBoolean(aBoolean)<<")"<<endl;
418 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
421 switch(theServant->GetPrimitiveType()){
422 case VISU::GaussPoints::SPRITE :
423 aParam = "VISU.GaussPoints.SPRITE";
425 case VISU::GaussPoints::POINT :
426 aParam = "VISU.GaussPoints.POINT";
428 case VISU::GaussPoints::SPHERE :
429 aParam = "VISU.GaussPoints.SPHERE";
432 theStr<<thePrefix<<theName<<".SetPrimitiveType("<<aParam<<")"<<endl;
434 theStr<<thePrefix<<theName<<".SetClamp("<<theServant->GetClamp()<<")"<<endl;
436 QString aMainTexture = theServant->GetQMainTexture();
437 QString anAlphaTexture = theServant->GetQAlphaTexture();
438 theStr<<thePrefix<<theName<<".SetTextures('"<<aMainTexture.toLatin1().data()<<"', '"<<anAlphaTexture.toLatin1().data()<<"')"<<endl;
440 theStr<<thePrefix<<theName<<".SetAlphaThreshold("<<theServant->GetAlphaThreshold()<<")"<<endl;
442 theStr<<thePrefix<<theName<<".SetResolution("<<theServant->GetResolution()<<")"<<endl;
444 theStr<<thePrefix<<theName<<".SetFaceLimit("<<theServant->GetFaceLimit()<<")"<<endl;
446 aBoolean = theServant->GetIsColored();
447 theStr<<thePrefix<<theName<<".SetIsColored("<<GetBoolean(aBoolean)<<")"<<endl;
450 theStr<<thePrefix<<theName<<".SetMinSize("<<theServant->GetMinSize()<<")"<<endl;
451 theStr<<thePrefix<<theName<<".SetMaxSize("<<theServant->GetMaxSize()<<")"<<endl;
453 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
454 theStr<<thePrefix<<theName<<".SetGeomSize("<<theServant->GetGeomSize()<<")"<<endl;
457 theStr<<thePrefix<<theName<<".SetMagnification("<<theServant->GetMagnification()<<")"<<endl;
458 theStr<<thePrefix<<theName<<".SetMagnificationIncrement("<<theServant->GetMagnificationIncrement()<<")"<<endl;
460 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
461 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
467 //---------------------------------------------------------------------------
469 ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
470 VISU::ScalarMap_i* theServant,
471 std::ostream& theStr,
472 const std::string& theName,
473 TColoredPrs3dFactory& thePrsFactory,
474 std::string thePrefix)
476 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
477 theStr<<thePrefix<<endl;
480 switch(theServant->GetScaling()){
482 aParam = "VISU.LINEAR";
485 aParam = "VISU.LOGARITHMIC";
488 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
489 theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
490 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
492 switch(theServant->GetGaussMetric()){
494 aParam = "VISU.AVERAGE";
497 aParam = "VISU.MINIMUM";
500 aParam = "VISU.MAXIMUM";
503 theStr<<thePrefix<<theName<<".SetGaussMetric("<<aParam<<")"<<endl;
505 SALOMEDS::Color aColor = theServant->GetLinkColor();
506 theStr<<thePrefix<<theName<<".SetLinkColor(SALOMEDS.Color("<<
507 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
509 if(theServant->IsRangeFixed())
510 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
512 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
517 //---------------------------------------------------------------------------
519 MonoColorPrsToPython(SALOMEDS::SObject_ptr theSObject,
520 VISU::MonoColorPrs_i* theServant,
521 std::ostream& theStr,
522 const std::string& theName,
523 TColoredPrs3dFactory& thePrsFactory,
524 std::string thePrefix)
526 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
527 theStr<<thePrefix<<endl;
528 theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
529 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
533 //---------------------------------------------------------------------------
535 DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
536 VISU::DeformedShape_i* theServant,
537 std::ostream& theStr,
538 const std::string& theName,
539 TColoredPrs3dFactory& thePrsFactory,
540 std::string thePrefix)
542 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
543 theStr<<thePrefix<<endl;
545 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
546 // theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
547 // theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
553 //---------------------------------------------------------------------------
555 StreamLinesToPython(SALOMEDS::SObject_ptr theSObject,
556 VISU::StreamLines_i* theServant,
557 std::ostream& theStr,
558 TEntry2NameMap& theEntry2NameMap,
559 const std::string& theName,
560 TColoredPrs3dFactory& thePrsFactory,
561 std::string thePrefix)
563 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
564 // thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
565 theStr<<thePrefix<<endl;
568 switch(theServant->GetDirection()){
569 case StreamLines::FORWARD:
570 aParam = "VISU.StreamLines.FORWARD";
572 case StreamLines::BACKWARD:
573 aParam = "VISU.StreamLines.BACKWARD";
575 case StreamLines::BOTH:
576 aParam = "VISU.StreamLines.BOTH";
580 theStr<<thePrefix<<"aPrs3d = None"<<endl;
581 VISU::Prs3d_var aPrs3d = theServant->GetSource();
582 if(!CORBA::is_nil(aPrs3d)){
583 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
584 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
585 CORBA::String_var anID = aSObject->GetID();
586 std::string anArg = theEntry2NameMap[anID.in()];
587 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
589 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
593 theStr<<thePrefix<<theName<<".SetParams("<<
594 theServant->GetIntegrationStep()<<", "<<
595 theServant->GetPropagationTime()<<", "<<
596 theServant->GetStepLength()<<", "<<
598 theServant->GetUsedPoints()<<", "<<
606 //---------------------------------------------------------------------------
608 DeformedShapeAndScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
609 VISU::DeformedShapeAndScalarMap_i* theServant,
610 std::ostream& theStr,
611 const std::string& theName,
612 TColoredPrs3dFactory& thePrsFactory,
613 std::string thePrefix)
615 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
616 theStr<<thePrefix<<endl;
618 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
619 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
622 VISU::Entity anEntity = theServant->GetScalarEntity();
625 aParam = "VISU.NODE";
628 aParam = "VISU.EDGE";
631 aParam = "VISU.FACE";
634 aParam = "VISU.CELL";
638 CORBA::String_var aFieldName = theServant->GetScalarFieldName();
639 CORBA::Long aTimeStampNumber = theServant->GetScalarTimeStampNumber();
641 theStr<<thePrefix<<theName<<".SetScalarField("<<
643 "'"<<aFieldName<<"', "<<
651 //---------------------------------------------------------------------------
653 VectorsToPython(SALOMEDS::SObject_ptr theSObject,
654 VISU::Vectors_i* theServant,
655 std::ostream& theStr,
656 const std::string& theName,
657 TColoredPrs3dFactory& thePrsFactory,
658 std::string thePrefix)
660 thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
661 theStr<<thePrefix<<endl;
663 theStr<<thePrefix<<theName<<".SetLineWidth("<<theServant->GetLineWidth()<<")"<<endl;
666 switch(theServant->GetGlyphType()){
668 aParam = "VISU.Vectors.ARROW";
671 aParam = "VISU.Vectors.CONE2";
674 aParam = "VISU.Vectors.CONE6";
677 aParam = "VISU.Vectors.NONE";
680 theStr<<thePrefix<<theName<<".SetGlyphType("<<aParam<<")"<<endl;
682 switch(theServant->GetGlyphPos()){
683 case Vectors::CENTER:
684 aParam = "VISU.Vectors.CENTER";
687 aParam = "VISU.Vectors.TAIL";
690 aParam = "VISU.Vectors.HEAD";
693 theStr<<thePrefix<<theName<<".SetGlyphPos("<<aParam<<")"<<endl;
699 //---------------------------------------------------------------------------
701 IsoSurfacesToPython(SALOMEDS::SObject_ptr theSObject,
702 VISU::IsoSurfaces_i* theServant,
703 std::ostream& theStr,
704 const std::string& theName,
705 TColoredPrs3dFactory& thePrsFactory,
706 std::string thePrefix)
708 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
709 theStr<<thePrefix<<endl;
711 theStr<<thePrefix<<theName<<".SetNbSurfaces("<<theServant->GetNbSurfaces()<<")"<<endl;
712 theStr<<thePrefix<<theName<<".ShowLabels("<<theServant->IsLabeled()<<","<<theServant->GetNbLabels()<<")"<<endl;
718 //---------------------------------------------------------------------------
720 CutPlanesToPython(SALOMEDS::SObject_ptr theSObject,
721 VISU::CutPlanes_i* theServant,
722 std::ostream& theStr,
723 const std::string& theName,
724 TColoredPrs3dFactory& thePrsFactory,
725 std::string thePrefix)
727 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
728 theStr<<thePrefix<<endl;
731 switch(theServant->GetOrientationType()){
733 aParam = "VISU.CutPlanes.XY";
736 aParam = "VISU.CutPlanes.YZ";
739 aParam = "VISU.CutPlanes.ZX";
742 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
744 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
745 CORBA::Long aNbPlanes = theServant->GetNbPlanes();
746 theStr<<thePrefix<<theName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
748 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
749 if(!theServant->IsDefault(anId))
750 theStr<<thePrefix<<theName<<".SetPlanePosition("<<anId<<", "<<theServant->GetPlanePosition(anId)<<")"<<endl;
753 theStr<<thePrefix<<theName<<".UseDeformation("<<GetBoolean(theServant->IsDeformed())<<")"<<endl;
754 if(theServant->IsDeformed()){
755 theStr<< thePrefix << theName << ".SetScale(" << theServant->GetScale()<<")"<<endl;
756 std::string aStringEntity;
757 VISU::Entity anEntity = theServant->GetVectorialFieldEntity();
760 aStringEntity = "VISU.NODE";
763 aStringEntity = "VISU.EDGE";
766 aStringEntity = "VISU.FACE";
769 aStringEntity = "VISU.CELL";
772 theStr<< thePrefix << theName << ".SetVectorialField("<<aStringEntity<<", '" << theServant->GetVectorialFieldName() <<"')"<<endl;
778 //---------------------------------------------------------------------------
780 CutLinesToPython(SALOMEDS::SObject_ptr theSObject,
781 VISU::CutLines_i* theServant,
782 std::ostream& theStr,
783 const std::string& theName,
784 TColoredPrs3dFactory& thePrsFactory,
785 std::string thePrefix)
787 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
788 theStr<<thePrefix<<endl;
791 switch(theServant->GetOrientationType()){
793 aParam = "VISU.CutPlanes.XY";
796 aParam = "VISU.CutPlanes.YZ";
799 aParam = "VISU.CutPlanes.ZX";
802 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
804 switch(theServant->GetOrientationType2()){
806 aParam = "VISU.CutPlanes.XY";
809 aParam = "VISU.CutPlanes.YZ";
812 aParam = "VISU.CutPlanes.ZX";
815 theStr<<thePrefix<<theName<<".SetOrientation2("<<aParam<<", "<<theServant->GetRotateX2()<<", "<<theServant->GetRotateY2()<<")"<<endl;
817 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
818 theStr<<thePrefix<<theName<<".SetDisplacement2("<<theServant->GetDisplacement2()<<")"<<endl;
820 if(!theServant->IsDefault())
821 theStr<<thePrefix<<theName<<".SetBasePlanePosition("<<theServant->GetBasePlanePosition()<<")"<<endl;
823 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
824 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
826 CORBA::Long aNbLines = theServant->GetNbLines();
827 theStr<<thePrefix<<theName<<".SetNbLines("<<aNbLines<<")"<<endl;
828 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
829 if(!theServant->IsDefaultPosition(anId))
830 theStr<<thePrefix<<theName<<".SetLinePosition("<<anId<<", "<<theServant->GetLinePosition(anId)<<")"<<endl;
837 //---------------------------------------------------------------------------
839 CutSegmentToPython(SALOMEDS::SObject_ptr theSObject,
840 VISU::CutSegment_i* theServant,
841 std::ostream& theStr,
842 const std::string& theName,
843 TColoredPrs3dFactory& thePrsFactory,
844 std::string thePrefix)
846 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
847 theStr<<thePrefix<<endl;
849 double x1, y1, z1, x2, y2, z2;
850 theServant->GetPoint1(x1, y1, z1);
851 theServant->GetPoint2(x2, y2, z2);
852 theStr<<thePrefix<<theName<<".SetPoint1("<<x1<<", "<<y1<<", "<<z1<<")"<<endl;
853 theStr<<thePrefix<<theName<<".SetPoint2("<<x2<<", "<<y2<<", "<<z2<<")"<<endl;
855 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
856 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
862 //---------------------------------------------------------------------------
864 Plot3DToPython(SALOMEDS::SObject_ptr theSObject,
865 VISU::Plot3D_i* theServant,
866 std::ostream& theStr,
867 const std::string& theName,
868 TColoredPrs3dFactory& thePrsFactory,
869 std::string thePrefix)
871 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
872 theStr<<thePrefix<<endl;
875 switch(theServant->GetOrientationType()){
877 aParam = "VISU.Plot3D.XY";
880 aParam = "VISU.Plot3D.YZ";
883 aParam = "VISU.Plot3D.ZX";
886 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
888 theStr<<thePrefix<<theName<<".SetPlanePosition("<<theServant->GetPlanePosition()<<", "<<theServant->IsPositionRelative()<<")"<<endl;
889 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
890 theStr<<thePrefix<<theName<<".SetContourPrs("<<theServant->GetIsContourPrs()<<")"<<endl;
891 theStr<<thePrefix<<theName<<".SetNbOfContours("<<theServant->GetNbOfContours()<<")"<<endl;
896 //---------------------------------------------------------------------------
898 void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
899 CORBA::Boolean theIsPublished,
900 CORBA::Boolean& theIsValidScript,
901 SALOMEDS::SObject_ptr theSObject,
902 std::ostream& theStr,
903 TName2EntryMap& theName2EntryMap,
904 TEntry2NameMap& theEntry2NameMap,
905 std::string theArgumentName,
906 std::string thePrefix);
908 //---------------------------------------------------------------------------
909 template<class TTableAttr>
911 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
912 CORBA::Boolean theIsPublished,
913 CORBA::Boolean& theIsValidScript,
914 SALOMEDS::SObject_ptr theSObject,
915 TTableAttr theTableAttr,
916 const std::string& theAttrName,
917 std::ostream& theStr,
918 TName2EntryMap& theName2EntryMap,
919 TEntry2NameMap& theEntry2NameMap,
920 std::string theArgumentName,
921 std::string thePrefix)
923 SALOMEDS::GenericAttribute_var anAttr;
924 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
925 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
926 SALOMEDS::AttributeString_var aComment =
927 SALOMEDS::AttributeString::_narrow(anAttr);
928 CORBA::String_var aValue = aComment->Value();
929 Storable::TRestoringMap aMap;
930 Storable::StringToMap(aValue.in(),aMap);
932 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
934 if(strcmp(aMethodName.toLatin1().data(),"ImportTables") == 0){
940 std::string aSObjectName = GetName(theSObject);
941 if(theArgumentName.empty())
942 theArgumentName = "aSComponent";
943 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject("<<theArgumentName<<")"<<endl;
944 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
947 theStr<<thePrefix<<"aBuilder.SetName("<<aSObjectName<<", \""<<theSObject->GetName()<<"\")"<<endl; // Fix for IPAL13165
948 std::string aName = "aTableAttr";
949 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
950 aSObjectName<<", '"<<theAttrName<<"')"<<endl;
952 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
953 std::string aPrefix = thePrefix;
956 CORBA::String_var aString = theTableAttr->GetTitle();
957 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
959 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
960 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
962 CORBA::Long aNbRows = theTableAttr->GetNbRows();
964 // push values and their indices into streams
965 stringstream values, rows, columns;
967 for(CORBA::Long i = 1; i <= aNbColumns; i++){
968 for(CORBA::Long j = aNbRows; j > 0; j--){
969 if(theTableAttr->HasValue(j,i)){
970 values << comma << theTableAttr->GetValue(j,i);
972 columns << comma << i;
978 // push titles and units into streams
979 stringstream rowUnits, rowTitles, colTitles;
980 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
981 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
983 for(CORBA::Long j = 1; j <= aNbRows; j++){
984 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
985 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
989 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
991 for(CORBA::Long j = 1; j <= aNbColumns; j++){
992 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
1002 // write FillTable command
1003 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
1004 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
1005 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
1006 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
1007 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
1008 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
1009 theStr<< thePrefix << "visu.FillTable( "
1011 << aName << "_values, "
1012 << aName << "_rows, "
1013 << aName << "_columns, "
1014 << aName << "_rTitles, "
1015 << aName << "_rUnits, "
1016 << aName << "_cTitles )" << endl;
1018 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
1019 theStr<<thePrefix<<endl;
1020 std::string aName = "aTable";
1021 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
1022 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1023 theArgumentName = aName;
1025 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1026 std::string aPrefix2 = thePrefix + PREFIX;
1028 // Set name (as this object could be renamed by user)
1029 CORBA::String_var aNameInStudy = theSObject->GetName();
1030 theStr<<aPrefix2<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 1"<<endl;
1032 DumpChildrenToPython(theStudy,
1042 theStr<<aPrefix2<<"pass"<<endl<<endl;
1045 theStr<<thePrefix<<"pass"<<endl<<endl;
1046 theStr<<aPrefix<<"pass"<<endl<<endl;
1050 //---------------------------------------------------------------------------
1052 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
1053 CORBA::Boolean theIsPublished,
1054 CORBA::Boolean& theIsValidScript,
1055 SALOMEDS::SObject_ptr theSObject,
1056 std::ostream& theStr,
1057 TName2EntryMap& theName2EntryMap,
1058 TEntry2NameMap& theEntry2NameMap,
1059 std::string theArgumentName,
1060 std::string thePrefix)
1062 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1063 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1064 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1065 DumpToPython(theStudy,
1078 //---------------------------------------------------------------------------
1080 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
1081 CORBA::Boolean theIsPublished,
1082 CORBA::Boolean& theIsValidScript,
1083 SALOMEDS::SObject_ptr theSObject,
1084 std::ostream& theStr,
1085 TName2EntryMap& theName2EntryMap,
1086 TEntry2NameMap& theEntry2NameMap,
1087 std::string theArgumentName,
1088 std::string thePrefix)
1090 SALOMEDS::GenericAttribute_var anAttr;
1091 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
1092 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
1093 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
1095 TableAttrToPython(theStudy,
1100 "AttributeTableOfInteger",
1107 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
1108 SALOMEDS::AttributeTableOfReal_var aTableAttr =
1109 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1111 TableAttrToPython(theStudy,
1116 "AttributeTableOfReal",
1127 //---------------------------------------------------------------------------
1129 DumpToPython(SALOMEDS::Study_ptr theStudy,
1130 CORBA::Boolean theIsPublished,
1131 CORBA::Boolean& theIsValidScript,
1132 SALOMEDS::SObject_ptr theSObject,
1133 std::ostream& theStr,
1134 TName2EntryMap& theName2EntryMap,
1135 TEntry2NameMap& theEntry2NameMap,
1136 std::string theArgumentName,
1137 std::string thePrefix)
1139 std::string aName = GetName(theSObject);
1143 CORBA::String_var anID = theSObject->GetID();
1144 CORBA::String_var aNameInStudy = theSObject->GetName();
1146 CORBA::Object_var anObj = SObjectToObject(theSObject);
1147 if (!CORBA::is_nil(anObj)) {
1148 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1149 if(!CORBA::is_nil(aBase)){
1150 std::string aName = GenerateName(theSObject, theName2EntryMap, theEntry2NameMap);
1152 VISU::VISUType aType = aBase->GetType();
1155 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
1156 std::string aFileName = aServant->GetInitFileName();
1157 Result_i::ECreationId anId = aServant->GetCreationId();
1158 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
1160 case Result_i::eImportFile:
1161 theStr<<thePrefix<<aName<<" = aVisu.CreateResult('"<<aFileName<<"')"<<endl;
1163 theStr<<thePrefix<<aName<<".SetBuildGroups("<<
1164 GetBoolean(aServant->IsGroupsDone())<<")"<<
1167 theStr<<thePrefix<<aName<<".SetBuildFields("<<
1168 GetBoolean(aServant->IsFieldsDone())<<", "<<
1169 GetBoolean(aServant->IsMinMaxDone())<<")"<<
1172 theStr<<thePrefix<<aName<<".Build(False, True)"<<endl;
1174 theStr<<thePrefix<<"if "<<aName<<".IsDone() :"<<endl;
1176 case Result_i::eCopyAndImportFile:
1177 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
1178 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1182 thePrefix += PREFIX;
1184 VISU::Result::EntityNames_var aMeshNames = aServant->GetMeshNames();
1185 if (aMeshNames->length() > 0) {
1186 for(size_t aMeshId = 0; aMeshId < aMeshNames->length(); aMeshId++){
1187 CORBA::String_var aMeshName = aMeshNames[aMeshId];
1188 VISU::Result::EntityNames_var aParts = aServant->GetPartNames(aMeshName);
1189 if (aParts->length() > 0) {
1190 for(size_t aPartId = 0; aPartId < aParts->length(); aPartId++){
1191 CORBA::String_var aPart = aParts[aPartId];
1192 VISU::Result::Resolution aResolution = aServant->GetResolution(aMeshName, aPart);
1194 switch(aResolution){
1195 case VISU::Result::FULL:
1196 aParam = "VISU.Result.FULL";
1198 case VISU::Result::MEDIUM:
1199 aParam = "VISU.Result.MEDIUM";
1201 case VISU::Result::LOW:
1202 aParam = "VISU.Result.LOW";
1204 case VISU::Result::HIDDEN:
1205 aParam = "VISU.Result.HIDDEN";
1208 theStr<<thePrefix<<aName<<".SetResolution('"<<aMeshName.in()<<"', '"<<aPart.in()<<"', "<<aParam<<")"<<endl;
1210 theStr<<thePrefix<<endl;
1216 theArgumentName = aName;
1217 DumpChildrenToPython(theStudy,
1227 theStr<<thePrefix<<"pass"<<endl<<endl;
1229 SALOMEDS::SObject_var aRefSObj;
1230 if(theSObject->FindSubObject(1,aRefSObj)){
1231 SALOMEDS::SObject_var aTargetRefSObj;
1232 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
1233 CORBA::String_var aString = aTargetRefSObj->GetName();
1234 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
1235 theStr<<thePrefix<<"if aSObject:"<<endl;
1236 thePrefix += PREFIX;
1237 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
1238 theStr<<thePrefix<<"if anObject:"<<endl;
1239 std::string aPrefix1 = thePrefix;
1240 thePrefix += PREFIX;
1243 case Result_i::eImportMed:
1244 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
1246 case Result_i::eImportMedField:
1247 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
1251 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1252 std::string aPrefix2 = thePrefix;
1253 thePrefix += PREFIX;
1255 theArgumentName = aName;
1256 DumpChildrenToPython(theStudy,
1266 theStr<<thePrefix<<"pass"<<endl<<endl;
1267 theStr<<aPrefix2<<"pass"<<endl<<endl;
1268 theStr<<aPrefix1<<"pass"<<endl<<endl;
1275 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
1276 VISU::Entity anEntity = aServant->GetEntity();
1277 const std::string& aSubMeshName = aServant->GetSubMeshName();
1282 aParam = "VISU.NODE";
1285 aParam = "VISU.EDGE";
1288 aParam = "VISU.FACE";
1291 aParam = "VISU.CELL";
1295 if(aSubMeshName == "")
1296 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
1297 ", '"<<aServant->GetCMeshName()<<"'"<<
1301 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
1302 ", '"<<aServant->GetCMeshName()<<"'"<<
1304 ", '"<<aSubMeshName<<"'"<<
1307 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
1308 ", '"<<aServant->GetCMeshName()<<"'"<<
1309 ", '"<<aSubMeshName<<"'"<<
1312 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1313 thePrefix += PREFIX;
1315 // Add to Name->Object map
1316 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
1318 // Set name (as this object could be renamed by user)
1319 theStr<<thePrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1321 // Set parameters common for all Prs3d objects (offset values)
1322 Prs3dToPython(aServant,theStr,aName,thePrefix);
1324 // Set presentation parameters
1325 SALOMEDS::Color aColor;
1326 aColor = aServant->GetCellColor();
1327 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
1328 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1330 aColor = aServant->GetNodeColor();
1331 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
1332 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1334 aColor = aServant->GetLinkColor();
1335 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
1336 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1339 switch(aServant->GetPresentationType()){
1341 aParam = "VISU.POINT";
1344 aParam = "VISU.WIREFRAME";
1347 aParam = "VISU.SHADED";
1350 aParam = "VISU.INSIDEFRAME";
1353 aParam = "VISU.SURFACEFRAME";
1356 aParam = "VISU.SHRINK";
1359 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
1360 theStr<<thePrefix<<aName<<".SetShrink("<<(aServant->IsShrank()? "True" : "False")<<")"<<endl;
1361 theStr<<thePrefix<<endl;
1363 std::string aQuad2DPresent;
1364 switch(aServant->GetQuadratic2DPresentationType()){
1366 aQuad2DPresent = "VISU.LINES";
1369 aQuad2DPresent = "VISU.ARCS";
1373 theStr<<thePrefix<<aName<<".SetQuadratic2DPresentationType("<<aQuad2DPresent<<")"<<endl;
1375 DumpChildrenToPython(theStudy,
1385 theStr<<thePrefix<<"pass"<<endl<<endl;
1389 case VISU::TSCALARMAP:
1390 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
1391 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "ScalarMapOnField", theArgumentName);
1392 thePrefix = ScalarMapToPython(theSObject, aServant, theStr,aName, aPrsFactory, thePrefix);
1393 theStr<<thePrefix<<"pass"<<endl<<endl;
1396 case VISU::TDEFORMEDSHAPE:
1397 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
1398 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeOnField", theArgumentName);
1399 thePrefix = DeformedShapeToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1400 theStr<<thePrefix<<"pass"<<endl<<endl;
1403 case VISU::TSTREAMLINES:
1404 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
1405 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "StreamLinesOnField", theArgumentName);
1406 thePrefix = StreamLinesToPython(theSObject, aServant, theStr, theEntry2NameMap, aName, aPrsFactory, thePrefix);
1407 theStr<<thePrefix<<"pass"<<endl<<endl;
1410 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1411 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1412 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(GetServant(anObj).in())){
1413 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeAndScalarMapOnField", theArgumentName);
1414 thePrefix = DeformedShapeAndScalarMapToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1415 theStr<<thePrefix<<"pass"<<endl<<endl;
1418 case VISU::TVECTORS:
1419 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
1420 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "VectorsOnField", theArgumentName);
1421 thePrefix = VectorsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1422 theStr<<thePrefix<<"pass"<<endl<<endl;
1425 case VISU::TISOSURFACES:
1426 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
1427 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "IsoSurfacesOnField", theArgumentName);
1428 thePrefix = IsoSurfacesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1429 theStr<<thePrefix<<"pass"<<endl<<endl;
1432 case VISU::TCUTPLANES:
1433 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
1434 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutPlanesOnField", theArgumentName);
1435 thePrefix = CutPlanesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1436 theStr<<thePrefix<<"pass"<<endl<<endl;
1439 case VISU::TCUTLINES:
1440 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
1441 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutLinesOnField", theArgumentName);
1442 thePrefix = CutLinesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1444 theArgumentName = aName;
1445 DumpChildrenToPython(theStudy,
1455 theStr<<thePrefix<<"pass"<<endl<<endl;
1458 case VISU::TCUTSEGMENT:
1459 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(GetServant(anObj).in())){
1460 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutSegmentOnField", theArgumentName);
1461 thePrefix = CutSegmentToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1463 theArgumentName = aName;
1464 DumpChildrenToPython(theStudy,
1474 theStr<<thePrefix<<"pass"<<endl<<endl;
1478 if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
1479 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
1480 thePrefix = Plot3DToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1481 theStr<<thePrefix<<"pass"<<endl<<endl;
1484 case VISU::TPOINTMAP3D:
1485 if (PointMap3d_i* aServant = dynamic_cast<PointMap3d_i*>(GetServant(anObj).in())) {
1486 CORBA::Short aTag = theSObject->Tag();
1487 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1488 theStr<<thePrefix<<"if anIsFound:"<<endl;
1489 thePrefix += PREFIX;
1491 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1492 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1494 // Set name (as this object could be renamed by user)
1495 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1497 // Set PointMap3D Properties
1499 theStr<<thePrefix<<aName<<".SetScaleFactor("<<aServant->GetScaleFactor()<<")"<<endl;
1500 theStr<<thePrefix<<aName<<".SetContourPrs("<<aServant->GetIsContourPrs()<<")"<<endl;
1501 theStr<<thePrefix<<aName<<".SetNbOfContours("<<aServant->GetNbOfContours()<<")"<<endl;
1504 switch(aServant->GetScaling()){
1506 aParam = "VISU.LINEAR";
1509 aParam = "VISU.LOGARITHMIC";
1512 theStr<<thePrefix<<aName<<".SetScaling("<<aParam<<")"<<endl;
1514 theStr<<thePrefix<<aName<<".SetNbColors("<<aServant->GetNbColors()<<")"<<endl;
1515 theStr<<thePrefix<<aName<<".SetLabels("<<aServant->GetLabels()<<")"<<endl;
1517 switch(aServant->GetBarOrientation()){
1518 case ColoredPrs3dBase::HORIZONTAL:
1519 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
1521 case ColoredPrs3dBase::VERTICAL:
1522 aParam = "VISU.ColoredPrs3d.VERTICAL";
1525 theStr<<thePrefix<<aName<<".SetBarOrientation("<<aParam<<")"<<endl;
1527 if(aServant->IsRangeFixed())
1528 theStr<<thePrefix<<aName<<".SetRange("<<aServant->GetMin()<<", "<<aServant->GetMax()<<")"<<endl;
1530 theStr<<thePrefix<<aName<<".SetSourceRange()"<<endl;
1532 theStr<<thePrefix<<aName<<".SetPosition("<<aServant->GetPosX()<<", "<<aServant->GetPosY()<<")"<<endl;
1533 theStr<<thePrefix<<aName<<".SetSize("<<aServant->GetWidth()<<", "<<aServant->GetHeight()<<")"<<endl;
1536 aServant->GetOffset(dx, dy, dz);
1537 theStr<<thePrefix<<aName<<".SetOffset("<<dx<<", "<<dy<<", "<<dz<<")"<<endl;
1540 theStr<<thePrefix<<endl;
1542 theArgumentName = aName;
1543 DumpChildrenToPython(theStudy,
1553 theStr<<thePrefix<<"pass"<<endl<<endl;
1556 case VISU::TGAUSSPOINTS:
1557 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(GetServant(anObj).in())){
1558 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "GaussPointsOnField", theArgumentName);
1559 thePrefix = GaussPointsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1560 theStr<<thePrefix<<"pass"<<endl<<endl;
1564 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
1566 bool withZ = aServant->GetZRow()>0;
1567 bool isV2 = aServant->GetIsV2();
1569 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
1571 theStr << "WithZExt";
1575 theArgumentName<< // table
1576 ", "<<aServant->GetHRow()<< // H row
1577 ", "<<aServant->GetVRow(); // V row
1579 theStr << ", " << aServant->GetZRow(); // Z row
1581 theStr << ", " << aServant->GetIsV2(); // right axis
1583 theStr << ", '"<<aServant->GetTitle()<<"'"; // title
1584 SALOMEDS::Color aColor = aServant->GetColor();
1585 theStr << ",SALOMEDS.Color("<<
1586 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<")"; // color
1589 switch(aServant->GetMarker()){
1590 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
1591 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
1592 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
1593 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
1594 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
1595 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
1596 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
1597 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
1598 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
1599 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
1601 theStr<<", "<<aParam; // marker
1603 switch(aServant->GetLine()){
1604 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
1605 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
1606 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
1607 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
1608 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
1609 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
1611 theStr<<", "<<aParam<<", "<<aServant->GetLineWidth()<<")"<<endl; // line type,width
1615 if(dynamic_cast<Table_i*>(GetServant(anObj).in())){
1616 SALOMEDS::GenericAttribute_var anAttr;
1617 if(theSObject->FindAttribute(anAttr,"AttributeString")){
1618 using namespace SALOMEDS;
1619 AttributeString_var aComment = AttributeString::_narrow(anAttr);
1620 CORBA::String_var aValue = aComment->Value();
1621 Storable::TRestoringMap aMap;
1622 Storable::StringToMap(aValue.in(),aMap);
1624 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1626 if( aSourceId == "CutLines" ){
1627 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
1628 thePrefix += PREFIX;
1630 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
1631 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
1632 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
1633 theStr<<thePrefix<<"if aSObject:"<<endl;
1634 std::string aPrefix = thePrefix;
1635 thePrefix += PREFIX;
1637 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1638 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1640 // Set name (as this object could be renamed by user)
1641 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 2"<<endl;
1643 theStr<<thePrefix<<endl;
1645 theArgumentName = aName;
1646 DumpChildrenToPython(theStudy,
1656 theStr<<thePrefix<<"pass"<<endl<<endl;
1657 theStr<<aPrefix<<"pass"<<endl<<endl;
1658 }else if( aSourceId == "TableFile" ){
1659 CORBA::Short aTag = theSObject->Tag();
1660 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1661 theStr<<thePrefix<<"if anIsFound:"<<endl;
1662 thePrefix += PREFIX;
1664 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1665 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1667 // Set name (as this object could be renamed by user)
1668 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1670 theStr<<thePrefix<<endl;
1672 theArgumentName = aName;
1673 DumpChildrenToPython(theStudy,
1683 theStr<<thePrefix<<"pass"<<endl<<endl;
1684 }else if( aSourceId == "TableAttr" ){
1685 theArgumentName = aName;
1686 DumpTableAttrToPython(theStudy,
1702 } else { /*if(!CORBA::is_nil(anObj))*/
1703 SALOMEDS::GenericAttribute_var anAttr;
1704 if (theSObject->FindAttribute(anAttr,"AttributeString")) {
1705 SALOMEDS::AttributeString_var aComment =
1706 SALOMEDS::AttributeString::_narrow(anAttr);
1707 CORBA::String_var aValue = aComment->Value();
1708 Storable::TRestoringMap aMap;
1709 Storable::StringToMap(aValue.in(),aMap);
1711 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1713 if (aTypeName == "ImportTables") {
1714 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1717 GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1718 QString aFirstStrAsTitle =
1719 VISU::Storable::FindValue(aMap,"myFirstStrAsTitle",&anIsExist).trimmed().toLower();
1720 if ( aFirstStrAsTitle == "1" || aFirstStrAsTitle == "true" )
1721 aFirstStrAsTitle = "True";
1723 aFirstStrAsTitle = "False";
1724 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"
1725 <<aFileName.toLatin1().data()<<"',"
1726 <<aFirstStrAsTitle.toLatin1().data()<<")"<<endl;
1727 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1728 thePrefix += PREFIX;
1730 theArgumentName = aName;
1731 DumpChildrenToPython(theStudy,
1741 theStr<<thePrefix<<"pass"<<endl<<endl;
1744 } else if (aTypeName == "VIEW3D") {
1745 std::string aName = GetName(theSObject);
1746 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1748 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1749 thePrefix += PREFIX;
1751 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1752 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1754 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1755 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1757 theStr<<thePrefix<<"pass"<<endl<<endl;
1759 } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1760 // Set name (as this object could be renamed by user)
1761 string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1762 string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1763 string anEntityTypeKey = "myEntityId";
1764 if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1765 int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1766 std::string anEntityType;
1767 switch ((TEntity)anEntity) {
1768 case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1769 case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1770 case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1771 case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1774 if (aTypeName == "ENTITY" ) {
1775 theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1776 <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1778 else if (aTypeName == "FAMILY") {
1779 if (aSubMeshName != aNameInStudy.in()) {
1780 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1781 <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1785 if (aSubMeshName != aNameInStudy.in()) {
1786 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1787 <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1793 DumpTableAttrToPython(theStudy,
1805 DumpChildrenToPython(theStudy,
1817 //---------------------------------------------------------------------------
1819 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1820 CORBA::Boolean theIsPublished,
1821 CORBA::Boolean& theIsValidScript,
1822 SALOMEDS::SObject_ptr theSObject,
1823 std::ostream& theStr,
1824 TName2EntryMap& theName2EntryMap,
1825 TEntry2NameMap& theEntry2NameMap,
1826 std::string theArgumentName,
1827 std::string thePrefix)
1829 SALOMEDS::SObject_var aTargetRefSObj;
1830 if(theSObject->ReferencedObject(aTargetRefSObj)){
1831 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1832 if(CORBA::is_nil(anObj))
1835 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1836 if(CORBA::is_nil(aBase))
1839 if(aBase->GetType() == VISU::TCURVE){
1840 CORBA::String_var anID = aTargetRefSObj->GetID();
1841 std::string anArg = theEntry2NameMap[anID.in()];
1842 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1843 thePrefix += PREFIX;
1844 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1845 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1846 theStr<<thePrefix<<"pass"<<endl<<endl;
1852 //---------------------------------------------------------------------------
1854 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1855 CORBA::Boolean theIsPublished,
1856 CORBA::Boolean& theIsValidScript,
1857 SALOMEDS::SObject_ptr theSObject,
1858 std::ostream& theStr,
1859 TName2EntryMap& theName2EntryMap,
1860 TEntry2NameMap& theEntry2NameMap,
1861 std::string theArgumentName,
1862 std::string thePrefix)
1864 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1865 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1866 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1867 CORBA::Object_var anObj = SObjectToObject(aSObject);
1868 if(CORBA::is_nil(anObj))
1871 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1872 if(CORBA::is_nil(aBase))
1875 if(aBase->GetType() == VISU::TCONTAINER){
1876 theStr<<thePrefix<<endl;
1877 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1878 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1879 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1880 std::string aPrefix = thePrefix + PREFIX;
1881 theArgumentName = aName;
1883 // Set name (as this object could be renamed by user)
1884 CORBA::String_var aNameInStudy = aSObject->GetName();
1885 theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1887 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1888 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1889 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1890 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1893 theStr<<aPrefix<<"pass"<<endl<<endl;
1899 //---------------------------------------------------------------------------
1901 DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1902 CORBA::Boolean theIsPublished,
1903 CORBA::Boolean& theIsValidScript,
1904 SALOMEDS::SObject_ptr theSObject,
1905 std::ostream& theStr,
1906 TName2EntryMap& theName2EntryMap,
1907 TEntry2NameMap& theEntry2NameMap,
1908 std::string theArgumentName,
1909 std::string thePrefix)
1912 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1913 for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1914 SALOMEDS::SObject_var aSObject = anIter->Value();
1915 CORBA::Object_var anObj = SObjectToObject(aSObject);
1916 if(CORBA::is_nil(anObj))
1919 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1920 if(CORBA::is_nil(aBase))
1923 if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1924 ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1925 theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1926 theStr<<thePrefix<<"if aCache != None:"<<endl;
1928 std::string aPrefix = thePrefix + PREFIX;
1929 std::string anArgument;
1930 VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1932 case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1933 case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1935 theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1937 if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1938 theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1940 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1941 for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1942 SALOMEDS::SObject_var aSObject = aChildIter->Value();
1943 CORBA::Object_var anObject = SObjectToObject(aSObject);
1944 if (CORBA::is_nil(anObject))
1947 ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1951 ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1955 Result_i* aResult = aDevice->GetCResult();
1956 std::string aResultEntry = aResult->GetEntry();
1957 std::string aResultName = theEntry2NameMap[aResultEntry];
1959 ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1960 std::string anEntity;
1961 switch(anInput->myEntity){
1962 case VISU::NODE : anEntity = "VISU.NODE"; break;
1963 case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1964 case VISU::FACE : anEntity = "VISU.FACE"; break;
1965 case VISU::CELL : anEntity = "VISU.CELL"; break;
1969 theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
1970 aResultName<<", '"<<
1971 anInput->myMeshName<<"', "<<
1973 anInput->myFieldName<<"', "<<
1974 anInput->myTimeStampNumber<<")"<<
1977 std::string aComment = aDevice->GetComment();
1978 theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
1979 theStr<<aPrefix<<"if aHolder != None:"<<endl;
1981 std::string aPrefix2 = aPrefix + PREFIX;
1982 CORBA::String_var aNameInStudy = aSObject->GetName();
1983 theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
1984 theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
1985 theStr<<aPrefix2<<"if aDevice != None:"<<endl;
1987 std::string aPrefix3 = aPrefix2 + PREFIX;
1988 TColoredPrs3dFactory aPrsFactory;
1989 switch(aDevice->GetType()){
1990 case VISU::TSCALARMAP:
1991 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
1992 ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1995 case VISU::TDEFORMEDSHAPE:
1996 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
1997 DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2000 case VISU::TSTREAMLINES:
2001 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
2002 StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
2005 case VISU::TSCALARMAPONDEFORMEDSHAPE:
2006 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
2007 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
2008 DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2011 case VISU::TVECTORS:
2012 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
2013 VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2016 case VISU::TISOSURFACES:
2017 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
2018 IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2021 case VISU::TCUTPLANES:
2022 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
2023 CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2026 case VISU::TCUTLINES:
2027 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
2028 CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2031 case VISU::TCUTSEGMENT:
2032 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(aDevice)){
2033 CutSegmentToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2037 if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
2038 Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2041 case VISU::TGAUSSPOINTS:
2042 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
2043 GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2047 theStr<<aPrefix3<<"pass"<<endl;
2049 theStr<<aPrefix2<<"pass"<<endl<<endl;
2052 theStr<<aPrefix<<"pass"<<endl;
2059 //---------------------------------------------------------------------------
2061 DumpEvolutionsToPython(SALOMEDS::Study_ptr theStudy,
2062 CORBA::Boolean theIsPublished,
2063 CORBA::Boolean& theIsValidScript,
2064 SALOMEDS::SObject_ptr theSObject,
2065 std::ostream& theStr,
2066 TName2EntryMap& theName2EntryMap,
2067 TEntry2NameMap& theEntry2NameMap,
2068 std::string thePrefix)
2070 if(!theIsPublished) return;
2072 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2073 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2074 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2076 SALOMEDS::GenericAttribute_var anAttr;
2077 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2079 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2080 QString value (aStringAttr->Value());
2081 if(value.isEmpty()) continue;
2083 VISU::Storable::TRestoringMap aMap;
2084 VISU::Storable::StringToMap(value, aMap);
2087 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2088 if(!isExist || aTypeName != "EVOLUTION") continue;
2091 theStr<<thePrefix<<endl;
2092 QString evolutionName = aSObject->GetName();
2093 theStr<<thePrefix<<"#Evolution: "<<evolutionName.toLatin1().data()<<endl;
2094 theStr<<thePrefix<<endl;
2095 theStr<<thePrefix<<"evolutionSO = aBuilder.NewObject(aSComponent)"<<endl;
2096 theStr<<thePrefix<<"aBuilder.SetName(evolutionSO, '"<<evolutionName.toLatin1().data()<<"')"<< endl;
2097 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(evolutionSO, 'AttributeString')"<< endl;
2098 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2100 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2101 for (anIter->Init(); anIter->More(); anIter->Next()) {
2102 SALOMEDS::SObject_var anObj = anIter->Value();
2105 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(evolutionSO)"<<endl;
2106 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2107 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2108 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2109 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2112 SALOMEDS::SObject_var refObj;
2113 if(anObj->ReferencedObject(refObj)) {
2114 SALOMEDS::SObject_var father = refObj->GetFather();
2115 value = refObj->GetName();
2116 QString path(theStudy->GetObjectPath(father));
2117 //The following code requierd as a field name can contain '/' character
2118 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2120 value = anObj->GetName();
2121 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2124 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(anObj);
2125 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2126 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2128 std::string anArgumentName = "fieldSO";
2129 DumpTableAttrToPython(theStudy,
2143 theStr<<thePrefix<<endl;
2147 //---------------------------------------------------------------------------
2149 DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
2150 CORBA::Boolean theIsPublished,
2151 CORBA::Boolean& theIsValidScript,
2152 SALOMEDS::SObject_ptr theSObject,
2153 std::ostream& theStr,
2154 std::string thePrefix)
2157 if(!theIsPublished) return;
2159 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2160 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2161 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2163 SALOMEDS::GenericAttribute_var anAttr;
2164 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2166 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2167 QString value (aStringAttr->Value());
2168 if(value.isEmpty()) continue;
2170 VISU::Storable::TRestoringMap aMap;
2171 VISU::Storable::StringToMap(value, aMap);
2174 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2175 if(!isExist || aTypeName != "ANIMATION") continue;
2178 theStr<<thePrefix<<endl;
2179 QString animName = aSObject->GetName();
2180 theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
2181 theStr<<thePrefix<<endl;
2182 theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
2183 theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
2184 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
2185 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2189 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2190 for (anIter->Init(); anIter->More(); anIter->Next()) {
2191 SALOMEDS::SObject_var anObj = anIter->Value();
2194 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
2195 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2196 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2197 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2198 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2201 SALOMEDS::SObject_var refObj;
2202 if(anObj->ReferencedObject(refObj)) {
2203 SALOMEDS::SObject_var father = refObj->GetFather();
2204 value = refObj->GetName();
2205 QString path(theStudy->GetObjectPath(father));
2206 //The following code requierd as a field name can contain '/' character
2207 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2209 value = anObj->GetName();
2210 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2213 SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
2214 for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
2215 SALOMEDS::SObject_var aSubObj = aSubIter->Value();
2217 theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
2218 value = aSubObj->GetName();
2219 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
2220 if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
2221 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2222 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2223 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2231 theStr<<thePrefix<<endl;
2236 DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2237 CORBA::Boolean theIsPublished,
2238 CORBA::Boolean& theIsValidScript,
2239 SALOMEDS::SObject_ptr theSObject,
2240 std::ostream& theStr,
2241 std::string thePrefix,
2242 VISU_ClippingPlaneMgr& thePlaneMgr)
2245 if(!theIsPublished) return;
2247 VISU_CutPlaneFunction* aPlane;
2248 double aOrigin[3], aDir[3];
2249 for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2250 aPlane = thePlaneMgr.GetClippingPlane(i);
2251 aPlane->GetOrigin(aOrigin);
2252 aPlane->GetNormal(aDir);
2254 theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2255 aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2256 aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2257 aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;
2264 DumpTextureMapToPython(SALOMEDS::Study_ptr theStudy,
2265 CORBA::Boolean theIsPublished,
2266 CORBA::Boolean& theIsValidScript,
2267 SALOMEDS::SObject_ptr theSObject,
2268 std::ostream& theStr,
2269 std::string thePrefix,
2270 const StudyId2MarkerMap& theMarkerMap)
2275 if(CORBA::is_nil(theStudy))
2278 StudyId2MarkerMap::const_iterator anIter = theMarkerMap.find(theStudy->StudyId());
2279 if(anIter == theMarkerMap.end())
2282 theStr<<thePrefix<<"texture_map = {}"<<endl<<endl;
2284 const VTK::MarkerMap& aMarkerMap = anIter->second;
2285 VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
2286 for(; aMarkerIter != aMarkerMap.end(); aMarkerIter++) {
2287 int aMarkerId = aMarkerIter->first;
2288 std::string aMarkerTexture = aMarkerIter->second.first;
2289 theStr<<thePrefix<<"texture_map["<<aMarkerId<<"] = aVisu.LoadTexture(\""<<aMarkerTexture<<"\")"<<endl;
2295 //---------------------------------------------------------------------------
2298 DumpPython(CORBA::Object_ptr theStudy,
2299 CORBA::Boolean theIsPublished,
2300 CORBA::Boolean theIsMultiFile,
2301 CORBA::Boolean& theIsValidScript)
2303 theIsValidScript = false;
2305 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2306 if(CORBA::is_nil(aStudy))
2307 return new Engines::TMPFile(0);
2309 TName2EntryMap aName2EntryMap;
2310 TEntry2NameMap aEntry2NameMap;
2318 std::string aPrefix = theIsMultiFile ? PREFIX : "";
2319 if( theIsMultiFile )
2320 aStr<<"def RebuildData(theStudy):"<<endl;
2321 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2322 aStr<<aPrefix<<"import SALOME_MED"<<endl;
2323 aStr<<aPrefix<<"import SALOMEDS"<<endl;
2324 aStr<<aPrefix<<"import VISU"<<endl;
2325 aStr<<aPrefix<<"import visu"<<endl;
2327 if( !theIsMultiFile )
2328 aStr<<"theStudy = salome.myStudy"<<endl;
2329 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2330 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2331 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2332 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2333 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2336 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2338 VISU::DumpClippingPlanesToPython(aStudy,
2344 myClippingPlaneMgr);
2346 VISU::DumpTextureMapToPython(aStudy,
2354 VISU::DumpChildrenToPython(aStudy,
2364 VISU::DumpEvolutionsToPython(aStudy,
2373 VISU::DumpContainersToPython(aStudy,
2383 VISU::DumpPrs3dCacheToPython(aStudy,
2393 VISU::DumpAnimationsToPython(aStudy,
2401 //Output the script that sets up the visul parameters.
2402 if(theIsPublished) {
2403 char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2404 if(script && strlen(script) > 0) {
2406 CORBA::string_free(script);
2410 if( theIsMultiFile )
2411 aStr<<aPrefix<<"pass"<<endl;
2413 if(theIsPublished) { //SRN: define function for Animation
2417 //Define a function that find a SObject by its father's path and its name
2421 aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
2422 aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
2423 aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
2424 aStr<<aPrefix<<"while itr.More():"<<endl;
2425 aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
2426 aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
2427 aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
2428 aStr<<aPrefix<<aPrefix<<"pass"<<endl;
2429 aStr<<aPrefix<<"return None"<<endl;
2434 // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2435 // If the situation changes, then the following line should be removed, and theIsValidScript
2436 // should be set properly by those internal methods
2437 theIsValidScript = true;
2440 std::string aResult = aStr.str();
2441 //ofstream anFStream("/tmp/dump.py");
2442 //anFStream<<aResult<<endl;
2444 CORBA::ULong aSize = aResult.size() + 1;
2445 char* aBuffer = new char[aSize];
2446 strcpy(aBuffer,&aResult[0]);
2447 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2450 return new Engines::TMPFile(0);