1 // Copyright (C) 2007-2012 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 ] << "'";
1004 // write FillTable command
1005 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
1006 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
1007 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
1008 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
1009 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
1010 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
1011 theStr<< thePrefix << "visu.FillTable( "
1013 << aName << "_values, "
1014 << aName << "_rows, "
1015 << aName << "_columns, "
1016 << aName << "_rTitles, "
1017 << aName << "_rUnits, "
1018 << aName << "_cTitles )" << endl;
1020 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
1021 theStr<<thePrefix<<endl;
1022 std::string aName = "aTable";
1023 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
1024 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1025 theArgumentName = aName;
1027 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1028 std::string aPrefix2 = thePrefix + PREFIX;
1030 // Set name (as this object could be renamed by user)
1031 CORBA::String_var aNameInStudy = theSObject->GetName();
1032 theStr<<aPrefix2<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 1"<<endl;
1034 DumpChildrenToPython(theStudy,
1044 theStr<<aPrefix2<<"pass"<<endl<<endl;
1047 theStr<<thePrefix<<"pass"<<endl<<endl;
1048 theStr<<aPrefix<<"pass"<<endl<<endl;
1052 //---------------------------------------------------------------------------
1054 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
1055 CORBA::Boolean theIsPublished,
1056 CORBA::Boolean& theIsValidScript,
1057 SALOMEDS::SObject_ptr theSObject,
1058 std::ostream& theStr,
1059 TName2EntryMap& theName2EntryMap,
1060 TEntry2NameMap& theEntry2NameMap,
1061 std::string theArgumentName,
1062 std::string thePrefix)
1064 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1065 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1066 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1067 DumpToPython(theStudy,
1080 //---------------------------------------------------------------------------
1082 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
1083 CORBA::Boolean theIsPublished,
1084 CORBA::Boolean& theIsValidScript,
1085 SALOMEDS::SObject_ptr theSObject,
1086 std::ostream& theStr,
1087 TName2EntryMap& theName2EntryMap,
1088 TEntry2NameMap& theEntry2NameMap,
1089 std::string theArgumentName,
1090 std::string thePrefix)
1092 SALOMEDS::GenericAttribute_var anAttr;
1093 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
1094 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
1095 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
1097 TableAttrToPython(theStudy,
1102 "AttributeTableOfInteger",
1109 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
1110 SALOMEDS::AttributeTableOfReal_var aTableAttr =
1111 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1113 TableAttrToPython(theStudy,
1118 "AttributeTableOfReal",
1129 //---------------------------------------------------------------------------
1131 DumpToPython(SALOMEDS::Study_ptr theStudy,
1132 CORBA::Boolean theIsPublished,
1133 CORBA::Boolean& theIsValidScript,
1134 SALOMEDS::SObject_ptr theSObject,
1135 std::ostream& theStr,
1136 TName2EntryMap& theName2EntryMap,
1137 TEntry2NameMap& theEntry2NameMap,
1138 std::string theArgumentName,
1139 std::string thePrefix)
1141 std::string aName = GetName(theSObject);
1145 CORBA::String_var anID = theSObject->GetID();
1146 CORBA::String_var aNameInStudy = theSObject->GetName();
1148 CORBA::Object_var anObj = SObjectToObject(theSObject);
1149 if (!CORBA::is_nil(anObj)) {
1150 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1151 if(!CORBA::is_nil(aBase)){
1152 std::string aName = GenerateName(theSObject, theName2EntryMap, theEntry2NameMap);
1154 VISU::VISUType aType = aBase->GetType();
1157 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
1158 std::string aFileName = aServant->GetInitFileName();
1159 Result_i::ECreationId anId = aServant->GetCreationId();
1160 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
1162 case Result_i::eImportFile:
1163 theStr<<thePrefix<<aName<<" = aVisu.CreateResult('"<<aFileName<<"')"<<endl;
1165 theStr<<thePrefix<<aName<<".SetBuildGroups("<<
1166 GetBoolean(aServant->IsGroupsDone())<<")"<<
1169 theStr<<thePrefix<<aName<<".SetBuildFields("<<
1170 GetBoolean(aServant->IsFieldsDone())<<", "<<
1171 GetBoolean(aServant->IsMinMaxDone())<<")"<<
1174 theStr<<thePrefix<<aName<<".Build(False, True)"<<endl;
1176 theStr<<thePrefix<<"if "<<aName<<".IsDone() :"<<endl;
1178 case Result_i::eCopyAndImportFile:
1179 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
1180 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1184 thePrefix += PREFIX;
1186 VISU::Result::EntityNames_var aMeshNames = aServant->GetMeshNames();
1187 if (aMeshNames->length() > 0) {
1188 for(size_t aMeshId = 0; aMeshId < aMeshNames->length(); aMeshId++){
1189 CORBA::String_var aMeshName = aMeshNames[aMeshId];
1190 VISU::Result::EntityNames_var aParts = aServant->GetPartNames(aMeshName);
1191 if (aParts->length() > 0) {
1192 for(size_t aPartId = 0; aPartId < aParts->length(); aPartId++){
1193 CORBA::String_var aPart = aParts[aPartId];
1194 VISU::Result::Resolution aResolution = aServant->GetResolution(aMeshName, aPart);
1196 switch(aResolution){
1197 case VISU::Result::FULL:
1198 aParam = "VISU.Result.FULL";
1200 case VISU::Result::MEDIUM:
1201 aParam = "VISU.Result.MEDIUM";
1203 case VISU::Result::LOW:
1204 aParam = "VISU.Result.LOW";
1206 case VISU::Result::HIDDEN:
1207 aParam = "VISU.Result.HIDDEN";
1210 theStr<<thePrefix<<aName<<".SetResolution('"<<aMeshName.in()<<"', '"<<aPart.in()<<"', "<<aParam<<")"<<endl;
1212 theStr<<thePrefix<<endl;
1218 theArgumentName = aName;
1219 DumpChildrenToPython(theStudy,
1229 theStr<<thePrefix<<"pass"<<endl<<endl;
1231 SALOMEDS::SObject_var aRefSObj;
1232 if(theSObject->FindSubObject(1,aRefSObj)){
1233 SALOMEDS::SObject_var aTargetRefSObj;
1234 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
1235 CORBA::String_var aString = aTargetRefSObj->GetName();
1236 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
1237 theStr<<thePrefix<<"if aSObject:"<<endl;
1238 thePrefix += PREFIX;
1239 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
1240 theStr<<thePrefix<<"if anObject:"<<endl;
1241 std::string aPrefix1 = thePrefix;
1242 thePrefix += PREFIX;
1245 case Result_i::eImportMed:
1246 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
1248 case Result_i::eImportMedField:
1249 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
1253 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1254 std::string aPrefix2 = thePrefix;
1255 thePrefix += PREFIX;
1257 theArgumentName = aName;
1258 DumpChildrenToPython(theStudy,
1268 theStr<<thePrefix<<"pass"<<endl<<endl;
1269 theStr<<aPrefix2<<"pass"<<endl<<endl;
1270 theStr<<aPrefix1<<"pass"<<endl<<endl;
1277 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
1278 VISU::Entity anEntity = aServant->GetEntity();
1279 const std::string& aSubMeshName = aServant->GetSubMeshName();
1284 aParam = "VISU.NODE";
1287 aParam = "VISU.EDGE";
1290 aParam = "VISU.FACE";
1293 aParam = "VISU.CELL";
1297 if(aSubMeshName == "")
1298 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
1299 ", '"<<aServant->GetCMeshName()<<"'"<<
1303 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
1304 ", '"<<aServant->GetCMeshName()<<"'"<<
1306 ", '"<<aSubMeshName<<"'"<<
1309 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
1310 ", '"<<aServant->GetCMeshName()<<"'"<<
1311 ", '"<<aSubMeshName<<"'"<<
1314 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1315 thePrefix += PREFIX;
1317 // Add to Name->Object map
1318 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
1320 // Set name (as this object could be renamed by user)
1321 theStr<<thePrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1323 // Set parameters common for all Prs3d objects (offset values)
1324 Prs3dToPython(aServant,theStr,aName,thePrefix);
1326 // Set presentation parameters
1327 SALOMEDS::Color aColor;
1328 aColor = aServant->GetCellColor();
1329 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
1330 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1332 aColor = aServant->GetNodeColor();
1333 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
1334 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1336 aColor = aServant->GetLinkColor();
1337 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
1338 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1341 switch(aServant->GetPresentationType()){
1343 aParam = "VISU.POINT";
1346 aParam = "VISU.WIREFRAME";
1349 aParam = "VISU.SHADED";
1352 aParam = "VISU.INSIDEFRAME";
1355 aParam = "VISU.SURFACEFRAME";
1358 aParam = "VISU.SHRINK";
1361 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
1362 theStr<<thePrefix<<aName<<".SetShrink("<<(aServant->IsShrank()? "True" : "False")<<")"<<endl;
1363 theStr<<thePrefix<<endl;
1365 std::string aQuad2DPresent;
1366 switch(aServant->GetQuadratic2DPresentationType()){
1368 aQuad2DPresent = "VISU.LINES";
1371 aQuad2DPresent = "VISU.ARCS";
1375 theStr<<thePrefix<<aName<<".SetQuadratic2DPresentationType("<<aQuad2DPresent<<")"<<endl;
1377 DumpChildrenToPython(theStudy,
1387 theStr<<thePrefix<<"pass"<<endl<<endl;
1391 case VISU::TSCALARMAP:
1392 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
1393 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "ScalarMapOnField", theArgumentName);
1394 thePrefix = ScalarMapToPython(theSObject, aServant, theStr,aName, aPrsFactory, thePrefix);
1395 theStr<<thePrefix<<"pass"<<endl<<endl;
1398 case VISU::TDEFORMEDSHAPE:
1399 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
1400 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeOnField", theArgumentName);
1401 thePrefix = DeformedShapeToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1402 theStr<<thePrefix<<"pass"<<endl<<endl;
1405 case VISU::TSTREAMLINES:
1406 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
1407 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "StreamLinesOnField", theArgumentName);
1408 thePrefix = StreamLinesToPython(theSObject, aServant, theStr, theEntry2NameMap, aName, aPrsFactory, thePrefix);
1409 theStr<<thePrefix<<"pass"<<endl<<endl;
1412 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1413 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1414 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(GetServant(anObj).in())){
1415 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeAndScalarMapOnField", theArgumentName);
1416 thePrefix = DeformedShapeAndScalarMapToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1417 theStr<<thePrefix<<"pass"<<endl<<endl;
1420 case VISU::TVECTORS:
1421 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
1422 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "VectorsOnField", theArgumentName);
1423 thePrefix = VectorsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1424 theStr<<thePrefix<<"pass"<<endl<<endl;
1427 case VISU::TISOSURFACES:
1428 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
1429 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "IsoSurfacesOnField", theArgumentName);
1430 thePrefix = IsoSurfacesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1431 theStr<<thePrefix<<"pass"<<endl<<endl;
1434 case VISU::TCUTPLANES:
1435 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
1436 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutPlanesOnField", theArgumentName);
1437 thePrefix = CutPlanesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1438 theStr<<thePrefix<<"pass"<<endl<<endl;
1441 case VISU::TCUTLINES:
1442 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
1443 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutLinesOnField", theArgumentName);
1444 thePrefix = CutLinesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1446 theArgumentName = aName;
1447 DumpChildrenToPython(theStudy,
1457 theStr<<thePrefix<<"pass"<<endl<<endl;
1460 case VISU::TCUTSEGMENT:
1461 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(GetServant(anObj).in())){
1462 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutSegmentOnField", theArgumentName);
1463 thePrefix = CutSegmentToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1465 theArgumentName = aName;
1466 DumpChildrenToPython(theStudy,
1476 theStr<<thePrefix<<"pass"<<endl<<endl;
1480 if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
1481 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
1482 thePrefix = Plot3DToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1483 theStr<<thePrefix<<"pass"<<endl<<endl;
1486 case VISU::TPOINTMAP3D:
1487 if (PointMap3d_i* aServant = dynamic_cast<PointMap3d_i*>(GetServant(anObj).in())) {
1489 SALOMEDS::GenericAttribute_var anAttr;
1490 if(theSObject->FindAttribute(anAttr,"AttributeString")){
1491 using namespace SALOMEDS;
1492 AttributeString_var aComment = AttributeString::_narrow(anAttr);
1493 CORBA::String_var aValue = aComment->Value();
1494 Storable::TRestoringMap aMap;
1495 Storable::StringToMap(aValue.in(),aMap);
1497 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1499 if( aSourceId == "TableAttr" ) {
1500 DumpTableAttrToPython(theStudy,
1513 CORBA::Short aTag = theSObject->Tag();
1514 theStr<<thePrefix<<"anIsFound, aSObject = "<<(theArgumentName.empty() ? "aSComponent" : theArgumentName)<<".FindSubObject("<<aTag<<")"<<endl;
1515 theStr<<thePrefix<<"if anIsFound:"<<endl;
1516 thePrefix += PREFIX;
1518 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1519 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1521 // Set name (as this object could be renamed by user)
1522 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1524 // Set PointMap3D Properties
1526 theStr<<thePrefix<<aName<<".SetScaleFactor("<<aServant->GetScaleFactor()<<")"<<endl;
1527 theStr<<thePrefix<<aName<<".SetContourPrs("<<aServant->GetIsContourPrs()<<")"<<endl;
1528 theStr<<thePrefix<<aName<<".SetNbOfContours("<<aServant->GetNbOfContours()<<")"<<endl;
1531 switch(aServant->GetScaling()){
1533 aParam = "VISU.LINEAR";
1536 aParam = "VISU.LOGARITHMIC";
1539 theStr<<thePrefix<<aName<<".SetScaling("<<aParam<<")"<<endl;
1541 theStr<<thePrefix<<aName<<".SetNbColors("<<aServant->GetNbColors()<<")"<<endl;
1542 theStr<<thePrefix<<aName<<".SetLabels("<<aServant->GetLabels()<<")"<<endl;
1544 switch(aServant->GetBarOrientation()){
1545 case ColoredPrs3dBase::HORIZONTAL:
1546 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
1548 case ColoredPrs3dBase::VERTICAL:
1549 aParam = "VISU.ColoredPrs3d.VERTICAL";
1552 theStr<<thePrefix<<aName<<".SetBarOrientation("<<aParam<<")"<<endl;
1554 if(aServant->IsRangeFixed())
1555 theStr<<thePrefix<<aName<<".SetRange("<<aServant->GetMin()<<", "<<aServant->GetMax()<<")"<<endl;
1557 theStr<<thePrefix<<aName<<".SetSourceRange()"<<endl;
1559 theStr<<thePrefix<<aName<<".SetPosition("<<aServant->GetPosX()<<", "<<aServant->GetPosY()<<")"<<endl;
1560 theStr<<thePrefix<<aName<<".SetSize("<<aServant->GetWidth()<<", "<<aServant->GetHeight()<<")"<<endl;
1563 aServant->GetOffset(dx, dy, dz);
1564 theStr<<thePrefix<<aName<<".SetOffset("<<dx<<", "<<dy<<", "<<dz<<")"<<endl;
1567 theStr<<thePrefix<<endl;
1569 theArgumentName = aName;
1570 DumpChildrenToPython(theStudy,
1580 theStr<<thePrefix<<"pass"<<endl<<endl;
1583 case VISU::TGAUSSPOINTS:
1584 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(GetServant(anObj).in())){
1585 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "GaussPointsOnField", theArgumentName);
1586 thePrefix = GaussPointsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1587 theStr<<thePrefix<<"pass"<<endl<<endl;
1591 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
1593 bool withZ = aServant->GetZRow()>0;
1594 bool isV2 = aServant->GetIsV2();
1596 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
1598 theStr << "WithZExt";
1602 theArgumentName<< // table
1603 ", "<<aServant->GetHRow()<< // H row
1604 ", "<<aServant->GetVRow(); // V row
1606 theStr << ", " << aServant->GetZRow(); // Z row
1608 theStr << ", " << aServant->GetIsV2(); // right axis
1610 theStr << ", '"<<aServant->GetTitle()<<"'"; // title
1611 SALOMEDS::Color aColor = aServant->GetColor();
1612 theStr << ",SALOMEDS.Color("<<
1613 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<")"; // color
1616 switch(aServant->GetMarker()){
1617 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
1618 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
1619 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
1620 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
1621 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
1622 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
1623 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
1624 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
1625 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
1626 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
1628 theStr<<", "<<aParam; // marker
1630 switch(aServant->GetLine()){
1631 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
1632 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
1633 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
1634 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
1635 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
1636 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
1638 theStr<<", "<<aParam<<", "<<aServant->GetLineWidth()<<")"<<endl; // line type,width
1642 if(dynamic_cast<Table_i*>(GetServant(anObj).in())){
1643 SALOMEDS::GenericAttribute_var anAttr;
1644 if(theSObject->FindAttribute(anAttr,"AttributeString")){
1645 using namespace SALOMEDS;
1646 AttributeString_var aComment = AttributeString::_narrow(anAttr);
1647 CORBA::String_var aValue = aComment->Value();
1648 Storable::TRestoringMap aMap;
1649 Storable::StringToMap(aValue.in(),aMap);
1651 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1653 if( aSourceId == "CutLines" ){
1654 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
1655 thePrefix += PREFIX;
1657 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
1658 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
1659 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
1660 theStr<<thePrefix<<"if aSObject:"<<endl;
1661 std::string aPrefix = thePrefix;
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()<<"') # 2"<<endl;
1670 theStr<<thePrefix<<endl;
1672 theArgumentName = aName;
1673 DumpChildrenToPython(theStudy,
1683 theStr<<thePrefix<<"pass"<<endl<<endl;
1684 theStr<<aPrefix<<"pass"<<endl<<endl;
1685 }else if( aSourceId == "TableFile" ){
1686 CORBA::Short aTag = theSObject->Tag();
1687 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1688 theStr<<thePrefix<<"if anIsFound:"<<endl;
1689 thePrefix += PREFIX;
1691 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1692 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1694 // Set name (as this object could be renamed by user)
1695 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1697 theStr<<thePrefix<<endl;
1699 theArgumentName = aName;
1700 DumpChildrenToPython(theStudy,
1710 theStr<<thePrefix<<"pass"<<endl<<endl;
1711 }else if( aSourceId == "TableAttr" ){
1712 //theArgumentName = aName;
1713 DumpTableAttrToPython(theStudy,
1729 } else { /*if(!CORBA::is_nil(anObj))*/
1730 SALOMEDS::GenericAttribute_var anAttr;
1731 if (theSObject->FindAttribute(anAttr,"AttributeString")) {
1732 SALOMEDS::AttributeString_var aComment =
1733 SALOMEDS::AttributeString::_narrow(anAttr);
1734 CORBA::String_var aValue = aComment->Value();
1735 Storable::TRestoringMap aMap;
1736 Storable::StringToMap(aValue.in(),aMap);
1738 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1740 if (aTypeName == "ImportTables") {
1741 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1744 GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1745 QString aFirstStrAsTitle =
1746 VISU::Storable::FindValue(aMap,"myFirstStrAsTitle",&anIsExist).trimmed().toLower();
1747 if ( aFirstStrAsTitle == "1" || aFirstStrAsTitle == "true" )
1748 aFirstStrAsTitle = "True";
1750 aFirstStrAsTitle = "False";
1751 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"
1752 <<aFileName.toLatin1().data()<<"',"
1753 <<aFirstStrAsTitle.toLatin1().data()<<")"<<endl;
1754 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1755 thePrefix += PREFIX;
1757 theArgumentName = aName;
1758 DumpChildrenToPython(theStudy,
1768 theStr<<thePrefix<<"pass"<<endl<<endl;
1771 } else if (aTypeName == "VIEW3D") {
1772 std::string aName = GetName(theSObject);
1773 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1775 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1776 thePrefix += PREFIX;
1778 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1779 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1781 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1782 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1784 theStr<<thePrefix<<"pass"<<endl<<endl;
1786 } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1787 // Set name (as this object could be renamed by user)
1788 string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1789 string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1790 string anEntityTypeKey = "myEntityId";
1791 if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1792 int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1793 std::string anEntityType;
1794 switch ((TEntity)anEntity) {
1795 case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1796 case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1797 case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1798 case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1801 if (aTypeName == "ENTITY" ) {
1802 theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1803 <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1805 else if (aTypeName == "FAMILY") {
1806 if (aSubMeshName != aNameInStudy.in()) {
1807 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1808 <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1812 if (aSubMeshName != aNameInStudy.in()) {
1813 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1814 <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1820 DumpTableAttrToPython(theStudy,
1832 DumpChildrenToPython(theStudy,
1844 //---------------------------------------------------------------------------
1846 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1847 CORBA::Boolean theIsPublished,
1848 CORBA::Boolean& theIsValidScript,
1849 SALOMEDS::SObject_ptr theSObject,
1850 std::ostream& theStr,
1851 TName2EntryMap& theName2EntryMap,
1852 TEntry2NameMap& theEntry2NameMap,
1853 std::string theArgumentName,
1854 std::string thePrefix)
1856 SALOMEDS::SObject_var aTargetRefSObj;
1857 if(theSObject->ReferencedObject(aTargetRefSObj)){
1858 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1859 if(CORBA::is_nil(anObj))
1862 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1863 if(CORBA::is_nil(aBase))
1866 if(aBase->GetType() == VISU::TCURVE){
1867 CORBA::String_var anID = aTargetRefSObj->GetID();
1868 std::string anArg = theEntry2NameMap[anID.in()];
1869 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1870 thePrefix += PREFIX;
1871 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1872 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1873 theStr<<thePrefix<<"pass"<<endl<<endl;
1879 //---------------------------------------------------------------------------
1881 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1882 CORBA::Boolean theIsPublished,
1883 CORBA::Boolean& theIsValidScript,
1884 SALOMEDS::SObject_ptr theSObject,
1885 std::ostream& theStr,
1886 TName2EntryMap& theName2EntryMap,
1887 TEntry2NameMap& theEntry2NameMap,
1888 std::string theArgumentName,
1889 std::string thePrefix)
1891 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1892 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1893 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1894 CORBA::Object_var anObj = SObjectToObject(aSObject);
1895 if(CORBA::is_nil(anObj))
1898 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1899 if(CORBA::is_nil(aBase))
1902 if(aBase->GetType() == VISU::TCONTAINER){
1903 theStr<<thePrefix<<endl;
1904 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1905 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1906 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1907 std::string aPrefix = thePrefix + PREFIX;
1908 theArgumentName = aName;
1910 // Set name (as this object could be renamed by user)
1911 CORBA::String_var aNameInStudy = aSObject->GetName();
1912 theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1914 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1915 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1916 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1917 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1920 theStr<<aPrefix<<"pass"<<endl<<endl;
1926 //---------------------------------------------------------------------------
1928 DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1929 CORBA::Boolean theIsPublished,
1930 CORBA::Boolean& theIsValidScript,
1931 SALOMEDS::SObject_ptr theSObject,
1932 std::ostream& theStr,
1933 TName2EntryMap& theName2EntryMap,
1934 TEntry2NameMap& theEntry2NameMap,
1935 std::string theArgumentName,
1936 std::string thePrefix)
1939 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1940 for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1941 SALOMEDS::SObject_var aSObject = anIter->Value();
1942 CORBA::Object_var anObj = SObjectToObject(aSObject);
1943 if(CORBA::is_nil(anObj))
1946 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1947 if(CORBA::is_nil(aBase))
1950 if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1951 ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1952 theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1953 theStr<<thePrefix<<"if aCache != None:"<<endl;
1955 std::string aPrefix = thePrefix + PREFIX;
1956 std::string anArgument;
1957 VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1959 case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1960 case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1962 theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1964 if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1965 theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1967 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1968 for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1969 SALOMEDS::SObject_var aSObject = aChildIter->Value();
1970 CORBA::Object_var anObject = SObjectToObject(aSObject);
1971 if (CORBA::is_nil(anObject))
1974 ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1978 ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1982 Result_i* aResult = aDevice->GetCResult();
1986 std::string aResultEntry = aResult->GetEntry();
1987 std::string aResultName = theEntry2NameMap[aResultEntry];
1989 ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1990 std::string anEntity;
1991 switch(anInput->myEntity){
1992 case VISU::NODE : anEntity = "VISU.NODE"; break;
1993 case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1994 case VISU::FACE : anEntity = "VISU.FACE"; break;
1995 case VISU::CELL : anEntity = "VISU.CELL"; break;
1999 theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
2000 aResultName<<", '"<<
2001 anInput->myMeshName<<"', "<<
2003 anInput->myFieldName<<"', "<<
2004 anInput->myTimeStampNumber<<")"<<
2007 std::string aComment = aDevice->GetComment();
2008 theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
2009 theStr<<aPrefix<<"if aHolder != None:"<<endl;
2011 std::string aPrefix2 = aPrefix + PREFIX;
2012 CORBA::String_var aNameInStudy = aSObject->GetName();
2013 theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
2014 theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
2015 theStr<<aPrefix2<<"if aDevice != None:"<<endl;
2017 std::string aPrefix3 = aPrefix2 + PREFIX;
2018 TColoredPrs3dFactory aPrsFactory;
2019 switch(aDevice->GetType()){
2020 case VISU::TSCALARMAP:
2021 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
2022 ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2025 case VISU::TDEFORMEDSHAPE:
2026 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
2027 DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2030 case VISU::TSTREAMLINES:
2031 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
2032 StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
2035 case VISU::TSCALARMAPONDEFORMEDSHAPE:
2036 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
2037 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
2038 DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2041 case VISU::TVECTORS:
2042 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
2043 VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2046 case VISU::TISOSURFACES:
2047 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
2048 IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2051 case VISU::TCUTPLANES:
2052 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
2053 CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2056 case VISU::TCUTLINES:
2057 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
2058 CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2061 case VISU::TCUTSEGMENT:
2062 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(aDevice)){
2063 CutSegmentToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2067 if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
2068 Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2071 case VISU::TGAUSSPOINTS:
2072 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
2073 GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2077 theStr<<aPrefix3<<"pass"<<endl;
2079 theStr<<aPrefix2<<"pass"<<endl<<endl;
2082 theStr<<aPrefix<<"pass"<<endl;
2089 //---------------------------------------------------------------------------
2091 DumpEvolutionsToPython(SALOMEDS::Study_ptr theStudy,
2092 CORBA::Boolean theIsPublished,
2093 CORBA::Boolean& theIsValidScript,
2094 SALOMEDS::SObject_ptr theSObject,
2095 std::ostream& theStr,
2096 TName2EntryMap& theName2EntryMap,
2097 TEntry2NameMap& theEntry2NameMap,
2098 std::string thePrefix)
2100 if(!theIsPublished) return;
2102 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2103 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2104 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2106 SALOMEDS::GenericAttribute_var anAttr;
2107 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2109 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2110 QString value (aStringAttr->Value());
2111 if(value.isEmpty()) continue;
2113 VISU::Storable::TRestoringMap aMap;
2114 VISU::Storable::StringToMap(value, aMap);
2117 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2118 if(!isExist || aTypeName != "EVOLUTION") continue;
2121 theStr<<thePrefix<<endl;
2122 QString evolutionName = aSObject->GetName();
2123 theStr<<thePrefix<<"#Evolution: "<<evolutionName.toLatin1().data()<<endl;
2124 theStr<<thePrefix<<endl;
2125 theStr<<thePrefix<<"evolutionSO = aBuilder.NewObject(aSComponent)"<<endl;
2126 theStr<<thePrefix<<"aBuilder.SetName(evolutionSO, '"<<evolutionName.toLatin1().data()<<"')"<< endl;
2127 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(evolutionSO, 'AttributeString')"<< endl;
2128 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2130 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2131 for (anIter->Init(); anIter->More(); anIter->Next()) {
2132 SALOMEDS::SObject_var anObj = anIter->Value();
2135 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(evolutionSO)"<<endl;
2136 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2137 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2138 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2139 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2142 SALOMEDS::SObject_var refObj;
2143 if(anObj->ReferencedObject(refObj)) {
2144 SALOMEDS::SObject_var father = refObj->GetFather();
2145 value = refObj->GetName();
2146 QString path(theStudy->GetObjectPath(father));
2147 //The following code requierd as a field name can contain '/' character
2148 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,visu.getSObjectByFatherPathAndName(theStudy, '"<<
2149 path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2151 value = anObj->GetName();
2152 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2155 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(anObj);
2156 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2157 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2159 std::string anArgumentName = "fieldSO";
2160 DumpTableAttrToPython(theStudy,
2174 theStr<<thePrefix<<endl;
2178 //---------------------------------------------------------------------------
2180 DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
2181 CORBA::Boolean theIsPublished,
2182 CORBA::Boolean& theIsValidScript,
2183 SALOMEDS::SObject_ptr theSObject,
2184 std::ostream& theStr,
2185 std::string thePrefix)
2188 if(!theIsPublished) return;
2190 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2191 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2192 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2194 SALOMEDS::GenericAttribute_var anAttr;
2195 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2197 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2198 QString value (aStringAttr->Value());
2199 if(value.isEmpty()) continue;
2201 VISU::Storable::TRestoringMap aMap;
2202 VISU::Storable::StringToMap(value, aMap);
2205 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2206 if(!isExist || aTypeName != "ANIMATION") continue;
2209 theStr<<thePrefix<<endl;
2210 QString animName = aSObject->GetName();
2211 theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
2212 theStr<<thePrefix<<endl;
2213 theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
2214 theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
2215 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
2216 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2220 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2221 for (anIter->Init(); anIter->More(); anIter->Next()) {
2222 SALOMEDS::SObject_var anObj = anIter->Value();
2225 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
2226 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2227 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2228 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2229 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2232 SALOMEDS::SObject_var refObj;
2233 if(anObj->ReferencedObject(refObj)) {
2234 SALOMEDS::SObject_var father = refObj->GetFather();
2235 value = refObj->GetName();
2236 QString path(theStudy->GetObjectPath(father));
2237 //The following code requierd as a field name can contain '/' character
2238 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,visu.getSObjectByFatherPathAndName(theStudy, '"<<
2239 path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2241 value = anObj->GetName();
2242 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2245 SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
2246 for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
2247 SALOMEDS::SObject_var aSubObj = aSubIter->Value();
2249 theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
2250 value = aSubObj->GetName();
2251 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
2252 if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
2253 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2254 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2255 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2263 theStr<<thePrefix<<endl;
2268 DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2269 CORBA::Boolean theIsPublished,
2270 CORBA::Boolean& theIsValidScript,
2271 SALOMEDS::SObject_ptr theSObject,
2272 std::ostream& theStr,
2273 std::string thePrefix,
2274 VISU_ClippingPlaneMgr& thePlaneMgr)
2277 if(!theIsPublished) return;
2279 VISU_CutPlaneFunction* aPlane;
2280 double aOrigin[3], aDir[3];
2281 for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2282 aPlane = thePlaneMgr.GetClippingPlane(i);
2283 aPlane->GetOrigin(aOrigin);
2284 aPlane->GetNormal(aDir);
2286 theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2287 aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2288 aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2289 aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;
2296 DumpTextureMapToPython(SALOMEDS::Study_ptr theStudy,
2297 CORBA::Boolean theIsPublished,
2298 CORBA::Boolean& theIsValidScript,
2299 SALOMEDS::SObject_ptr theSObject,
2300 std::ostream& theStr,
2301 std::string thePrefix,
2302 const StudyId2MarkerMap& theMarkerMap)
2307 if(CORBA::is_nil(theStudy))
2310 StudyId2MarkerMap::const_iterator anIter = theMarkerMap.find(theStudy->StudyId());
2311 if(anIter == theMarkerMap.end())
2314 theStr<<thePrefix<<"texture_map = {}"<<endl<<endl;
2316 const VTK::MarkerMap& aMarkerMap = anIter->second;
2317 VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
2318 for(; aMarkerIter != aMarkerMap.end(); aMarkerIter++) {
2319 int aMarkerId = aMarkerIter->first;
2320 std::string aMarkerTexture = aMarkerIter->second.first;
2321 theStr<<thePrefix<<"texture_map["<<aMarkerId<<"] = aVisu.LoadTexture(\""<<aMarkerTexture<<"\")"<<endl;
2327 //---------------------------------------------------------------------------
2330 DumpPython(CORBA::Object_ptr theStudy,
2331 CORBA::Boolean theIsPublished,
2332 CORBA::Boolean theIsMultiFile,
2333 CORBA::Boolean& theIsValidScript)
2335 theIsValidScript = false;
2337 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2338 if(CORBA::is_nil(aStudy))
2339 return new Engines::TMPFile(0);
2341 TName2EntryMap aName2EntryMap;
2342 TEntry2NameMap aEntry2NameMap;
2350 std::string aPrefix = theIsMultiFile ? PREFIX : "";
2351 if( theIsMultiFile )
2352 aStr<<"def RebuildData(theStudy):"<<endl;
2353 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2354 aStr<<aPrefix<<"import SALOME_MED"<<endl;
2355 aStr<<aPrefix<<"import SALOMEDS"<<endl;
2356 aStr<<aPrefix<<"import VISU"<<endl;
2357 aStr<<aPrefix<<"import visu"<<endl;
2359 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2360 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2361 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2362 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2363 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2366 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2368 VISU::DumpClippingPlanesToPython(aStudy,
2374 myClippingPlaneMgr);
2376 VISU::DumpTextureMapToPython(aStudy,
2384 VISU::DumpChildrenToPython(aStudy,
2394 VISU::DumpEvolutionsToPython(aStudy,
2403 VISU::DumpContainersToPython(aStudy,
2413 VISU::DumpPrs3dCacheToPython(aStudy,
2423 VISU::DumpAnimationsToPython(aStudy,
2432 SALOMEDS::AttributeParameter_var ap = aStudy->GetModuleParameters("Interface Applicative", "Post-Pro", -1);
2433 if(!CORBA::is_nil(ap)) {
2434 std::map<std::string,std::string>::iterator it = aEntry2NameMap.begin();
2435 for( ;it != aEntry2NameMap.end(); it++ ) {
2437 if ( ((*it).first).length() < 7 ) continue;
2438 std::string tail( (*it).first, 6, ((*it).first).length()-1 );
2439 std::string newEntry(ComponentDataType());
2440 newEntry+=("_"+tail);
2442 CORBA::String_var anEntry = CORBA::string_dup(newEntry.c_str());
2444 if( ap->IsSet(anEntry, 6) ) { //6 Means string array, see SALOMEDS_Attributes.idl AttributeParameter interface
2445 std::string idCommand = std::string("visu.getObjectID(") + (*it).second + std::string(")");
2446 SALOMEDS::StringSeq_var aSeq= ap->GetStrArray(anEntry);
2447 int oldLenght = aSeq->length();
2448 aSeq->length(oldLenght+2);
2449 aSeq[oldLenght] = CORBA::string_dup("_PT_OBJECT_ID_");
2450 aSeq[oldLenght + 1] = CORBA::string_dup(idCommand.c_str());
2451 ap->SetStrArray( anEntry, aSeq );
2458 //Output the script that sets up the visul parameters.
2459 if(theIsPublished) {
2460 char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2461 if(script && strlen(script) > 0) {
2463 CORBA::string_free(script);
2467 if( theIsMultiFile )
2468 aStr<<aPrefix<<"pass"<<endl;
2470 // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2471 // If the situation changes, then the following line should be removed, and theIsValidScript
2472 // should be set properly by those internal methods
2473 theIsValidScript = true;
2476 std::string aResult = aStr.str();
2477 //ofstream anFStream("/tmp/dump.py");
2478 //anFStream<<aResult<<endl;
2480 CORBA::ULong aSize = aResult.size() + 1;
2481 char* aBuffer = new char[aSize];
2482 strcpy(aBuffer,&aResult[0]);
2483 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2486 return new Engines::TMPFile(0);