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 default: aParam1 = "MT_NONE"; break;
234 switch( aMarkerScale ) {
235 case MS_10: aParam2 = "MS_10"; break;
236 case MS_15: aParam2 = "MS_15"; break;
237 case MS_20: aParam2 = "MS_20"; break;
238 case MS_25: aParam2 = "MS_25"; break;
239 case MS_30: aParam2 = "MS_30"; break;
240 case MS_35: aParam2 = "MS_35"; break;
241 case MS_40: aParam2 = "MS_40"; break;
242 case MS_45: aParam2 = "MS_45"; break;
243 case MS_50: aParam2 = "MS_50"; break;
244 case MS_55: aParam2 = "MS_55"; break;
245 case MS_60: aParam2 = "MS_60"; break;
246 case MS_65: aParam2 = "MS_65"; break;
247 case MS_70: aParam2 = "MS_70"; break;
248 default: aParam2 = "MT_NONE"; break;
250 theStr<<thePrefix<<theName<<".SetMarkerStd(VISU."<<aParam1<<", VISU."<<aParam2<<")"<<endl;
253 int aMarkerTexture = theServant->GetMarkerTexture();
254 if( aMarkerTexture >= 0 )
255 theStr<<thePrefix<<theName<<".SetMarkerTexture(texture_map["<<aMarkerTexture<<"])"<<endl;
260 //---------------------------------------------------------------------------
261 struct TColoredPrs3dFactory
265 operator()(std::ostream& theStr,
266 std::string thePrefix)
274 struct TCreateFromResult: TColoredPrs3dFactory
276 VISU::ColoredPrs3d_i* myServant;
277 std::string myConstructorName;
278 std::string myArgumentName;
280 SALOMEDS::SObject_var mySObject;
283 TCreateFromResult(const SALOMEDS::SObject_ptr theSObject,
284 VISU::ColoredPrs3d_i* theServant,
285 const std::string& theName,
286 const std::string& theConstructorName,
287 const std::string& theArgumentName):
288 myServant(theServant),
289 myConstructorName(theConstructorName),
290 myArgumentName(theArgumentName),
293 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
298 operator()(std::ostream& theStr,
299 std::string thePrefix)
302 switch(myServant->GetEntity()){
304 aParam = "VISU.NODE";
307 aParam = "VISU.EDGE";
310 aParam = "VISU.FACE";
313 aParam = "VISU.CELL";
317 theStr<<thePrefix<<myName<<" = aVisu."<<myConstructorName<<"("<<myArgumentName<<
318 ", '"<<myServant->GetCMeshName()<<"'"<<
320 ", '"<<myServant->GetCFieldName()<<"'"<<
321 ", "<<myServant->GetTimeStampNumber()<<
324 theStr<<thePrefix<<"if "<<myName<<" != None:"<<endl;
327 // Add to Name->Object map
328 theStr<<thePrefix<<"aName2ObjectMap['"<<myName<<"'] = "<<myName<<endl;
330 // Set name (as this object could be renamed by user)
331 CORBA::String_var aNameInStudy = mySObject->GetName();
332 theStr<<thePrefix<<"visu.SetName("<<myName<<", '"<<aNameInStudy.in()<<"')"<<endl;
339 //---------------------------------------------------------------------------
341 ColoredPrs3dToPython(SALOMEDS::SObject_ptr theSObject,
342 VISU::ColoredPrs3d_i* theServant,
343 std::ostream& theStr,
344 const std::string& theName,
345 TColoredPrs3dFactory& thePrsFactory,
346 std::string thePrefix)
348 thePrefix = thePrsFactory(theStr, thePrefix);
350 // Set parameters common for all Prs3d objects (offset values)
351 Prs3dToPython(theServant, theStr, theName, thePrefix);
353 theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<", "<<theServant->GetPosY()<<")"<<endl;
354 theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<", "<<theServant->GetHeight()<<")"<<endl;
355 theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
356 theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
357 theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
360 switch(theServant->GetBarOrientation()){
361 case ColoredPrs3dBase::HORIZONTAL:
362 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
364 case ColoredPrs3dBase::VERTICAL:
365 aParam = "VISU.ColoredPrs3d.VERTICAL";
368 theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
370 theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
372 if(theServant->IsRangeFixed())
373 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
375 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
377 const VISU::ColoredPrs3d_i::TGroupNames aGroupNames = theServant->GetGroupNames();
378 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
379 for(; anIter != aGroupNames.end(); anIter++){
380 const std::string& aGroupName = *anIter;
381 theStr<<thePrefix<<theName<<".AddMeshOnGroup('"<<aGroupName<<"')"<<endl;
388 //---------------------------------------------------------------------------
390 GaussPointsToPython(SALOMEDS::SObject_ptr theSObject,
391 VISU::GaussPoints_i* theServant,
392 std::ostream& theStr,
393 const std::string& theName,
394 TColoredPrs3dFactory& thePrsFactory,
395 std::string thePrefix)
397 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
398 theStr<<thePrefix<<endl;
400 bool aBoolean = theServant->GetIsActiveLocalScalarBar();
401 theStr<<thePrefix<<theName<<".SetIsActiveLocalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
404 aBoolean = theServant->GetIsDispGlobalScalarBar();
405 theStr<<thePrefix<<theName<<".SetIsDispGlobalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
408 theStr<<thePrefix<<theName<<".SetSpacing("<<theServant->GetSpacing()<<")"<<endl;
410 aBoolean = theServant->GetBiColor();
411 theStr<<thePrefix<<theName<<".SetBiColor("<<GetBoolean(aBoolean)<<")"<<endl;
413 aBoolean = theServant->GetIsDeformed();
414 theStr<<thePrefix<<theName<<".SetIsDeformed("<<GetBoolean(aBoolean)<<")"<<endl;
415 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
418 switch(theServant->GetPrimitiveType()){
419 case VISU::GaussPoints::SPRITE :
420 aParam = "VISU.GaussPoints.SPRITE";
422 case VISU::GaussPoints::POINT :
423 aParam = "VISU.GaussPoints.POINT";
425 case VISU::GaussPoints::SPHERE :
426 aParam = "VISU.GaussPoints.SPHERE";
429 theStr<<thePrefix<<theName<<".SetPrimitiveType("<<aParam<<")"<<endl;
431 theStr<<thePrefix<<theName<<".SetClamp("<<theServant->GetClamp()<<")"<<endl;
433 QString aMainTexture = theServant->GetQMainTexture();
434 QString anAlphaTexture = theServant->GetQAlphaTexture();
435 theStr<<thePrefix<<theName<<".SetTextures('"<<aMainTexture.toLatin1().data()<<"', '"<<anAlphaTexture.toLatin1().data()<<"')"<<endl;
437 theStr<<thePrefix<<theName<<".SetAlphaThreshold("<<theServant->GetAlphaThreshold()<<")"<<endl;
439 theStr<<thePrefix<<theName<<".SetResolution("<<theServant->GetResolution()<<")"<<endl;
441 theStr<<thePrefix<<theName<<".SetFaceLimit("<<theServant->GetFaceLimit()<<")"<<endl;
443 aBoolean = theServant->GetIsColored();
444 theStr<<thePrefix<<theName<<".SetIsColored("<<GetBoolean(aBoolean)<<")"<<endl;
447 theStr<<thePrefix<<theName<<".SetMinSize("<<theServant->GetMinSize()<<")"<<endl;
448 theStr<<thePrefix<<theName<<".SetMaxSize("<<theServant->GetMaxSize()<<")"<<endl;
450 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
451 theStr<<thePrefix<<theName<<".SetGeomSize("<<theServant->GetGeomSize()<<")"<<endl;
454 theStr<<thePrefix<<theName<<".SetMagnification("<<theServant->GetMagnification()<<")"<<endl;
455 theStr<<thePrefix<<theName<<".SetMagnificationIncrement("<<theServant->GetMagnificationIncrement()<<")"<<endl;
457 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
458 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
464 //---------------------------------------------------------------------------
466 ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
467 VISU::ScalarMap_i* theServant,
468 std::ostream& theStr,
469 const std::string& theName,
470 TColoredPrs3dFactory& thePrsFactory,
471 std::string thePrefix)
473 thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
474 theStr<<thePrefix<<endl;
477 switch(theServant->GetScaling()){
479 aParam = "VISU.LINEAR";
482 aParam = "VISU.LOGARITHMIC";
485 std::string aVisible = theServant->IsBarVisible()? "True" : "False";
486 theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
487 theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
489 switch(theServant->GetGaussMetric()){
491 aParam = "VISU.AVERAGE";
494 aParam = "VISU.MINIMUM";
497 aParam = "VISU.MAXIMUM";
500 theStr<<thePrefix<<theName<<".SetGaussMetric("<<aParam<<")"<<endl;
502 SALOMEDS::Color aColor = theServant->GetLinkColor();
503 theStr<<thePrefix<<theName<<".SetLinkColor(SALOMEDS.Color("<<
504 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
506 if(theServant->IsRangeFixed())
507 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
509 theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
514 //---------------------------------------------------------------------------
516 MonoColorPrsToPython(SALOMEDS::SObject_ptr theSObject,
517 VISU::MonoColorPrs_i* theServant,
518 std::ostream& theStr,
519 const std::string& theName,
520 TColoredPrs3dFactory& thePrsFactory,
521 std::string thePrefix)
523 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
524 theStr<<thePrefix<<endl;
525 theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
526 theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
530 //---------------------------------------------------------------------------
532 DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
533 VISU::DeformedShape_i* theServant,
534 std::ostream& theStr,
535 const std::string& theName,
536 TColoredPrs3dFactory& thePrsFactory,
537 std::string thePrefix)
539 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
540 theStr<<thePrefix<<endl;
542 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
543 // theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
544 // theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
550 //---------------------------------------------------------------------------
552 StreamLinesToPython(SALOMEDS::SObject_ptr theSObject,
553 VISU::StreamLines_i* theServant,
554 std::ostream& theStr,
555 TEntry2NameMap& theEntry2NameMap,
556 const std::string& theName,
557 TColoredPrs3dFactory& thePrsFactory,
558 std::string thePrefix)
560 thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
561 // thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
562 theStr<<thePrefix<<endl;
565 switch(theServant->GetDirection()){
566 case StreamLines::FORWARD:
567 aParam = "VISU.StreamLines.FORWARD";
569 case StreamLines::BACKWARD:
570 aParam = "VISU.StreamLines.BACKWARD";
572 case StreamLines::BOTH:
573 aParam = "VISU.StreamLines.BOTH";
577 theStr<<thePrefix<<"aPrs3d = None"<<endl;
578 VISU::Prs3d_var aPrs3d = theServant->GetSource();
579 if(!CORBA::is_nil(aPrs3d)){
580 if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
581 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
582 CORBA::String_var anID = aSObject->GetID();
583 std::string anArg = theEntry2NameMap[anID.in()];
584 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
586 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
590 theStr<<thePrefix<<theName<<".SetParams("<<
591 theServant->GetIntegrationStep()<<", "<<
592 theServant->GetPropagationTime()<<", "<<
593 theServant->GetStepLength()<<", "<<
595 theServant->GetUsedPoints()<<", "<<
603 //---------------------------------------------------------------------------
605 DeformedShapeAndScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
606 VISU::DeformedShapeAndScalarMap_i* theServant,
607 std::ostream& theStr,
608 const std::string& theName,
609 TColoredPrs3dFactory& thePrsFactory,
610 std::string thePrefix)
612 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
613 theStr<<thePrefix<<endl;
615 theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
616 theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
619 VISU::Entity anEntity = theServant->GetScalarEntity();
622 aParam = "VISU.NODE";
625 aParam = "VISU.EDGE";
628 aParam = "VISU.FACE";
631 aParam = "VISU.CELL";
635 CORBA::String_var aFieldName = theServant->GetScalarFieldName();
636 CORBA::Long aTimeStampNumber = theServant->GetScalarTimeStampNumber();
638 theStr<<thePrefix<<theName<<".SetScalarField("<<
640 "'"<<aFieldName<<"', "<<
648 //---------------------------------------------------------------------------
650 VectorsToPython(SALOMEDS::SObject_ptr theSObject,
651 VISU::Vectors_i* theServant,
652 std::ostream& theStr,
653 const std::string& theName,
654 TColoredPrs3dFactory& thePrsFactory,
655 std::string thePrefix)
657 thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
658 theStr<<thePrefix<<endl;
660 theStr<<thePrefix<<theName<<".SetLineWidth("<<theServant->GetLineWidth()<<")"<<endl;
663 switch(theServant->GetGlyphType()){
665 aParam = "VISU.Vectors.ARROW";
668 aParam = "VISU.Vectors.CONE2";
671 aParam = "VISU.Vectors.CONE6";
674 aParam = "VISU.Vectors.NONE";
677 theStr<<thePrefix<<theName<<".SetGlyphType("<<aParam<<")"<<endl;
679 switch(theServant->GetGlyphPos()){
680 case Vectors::CENTER:
681 aParam = "VISU.Vectors.CENTER";
684 aParam = "VISU.Vectors.TAIL";
687 aParam = "VISU.Vectors.HEAD";
690 theStr<<thePrefix<<theName<<".SetGlyphPos("<<aParam<<")"<<endl;
696 //---------------------------------------------------------------------------
698 IsoSurfacesToPython(SALOMEDS::SObject_ptr theSObject,
699 VISU::IsoSurfaces_i* theServant,
700 std::ostream& theStr,
701 const std::string& theName,
702 TColoredPrs3dFactory& thePrsFactory,
703 std::string thePrefix)
705 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
706 theStr<<thePrefix<<endl;
708 theStr<<thePrefix<<theName<<".SetNbSurfaces("<<theServant->GetNbSurfaces()<<")"<<endl;
709 theStr<<thePrefix<<theName<<".ShowLabels("<<theServant->IsLabeled()<<","<<theServant->GetNbLabels()<<")"<<endl;
715 //---------------------------------------------------------------------------
717 CutPlanesToPython(SALOMEDS::SObject_ptr theSObject,
718 VISU::CutPlanes_i* theServant,
719 std::ostream& theStr,
720 const std::string& theName,
721 TColoredPrs3dFactory& thePrsFactory,
722 std::string thePrefix)
724 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
725 theStr<<thePrefix<<endl;
728 switch(theServant->GetOrientationType()){
730 aParam = "VISU.CutPlanes.XY";
733 aParam = "VISU.CutPlanes.YZ";
736 aParam = "VISU.CutPlanes.ZX";
739 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
741 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
742 CORBA::Long aNbPlanes = theServant->GetNbPlanes();
743 theStr<<thePrefix<<theName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
745 for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
746 if(!theServant->IsDefault(anId))
747 theStr<<thePrefix<<theName<<".SetPlanePosition("<<anId<<", "<<theServant->GetPlanePosition(anId)<<")"<<endl;
750 theStr<<thePrefix<<theName<<".UseDeformation("<<GetBoolean(theServant->IsDeformed())<<")"<<endl;
751 if(theServant->IsDeformed()){
752 theStr<< thePrefix << theName << ".SetScale(" << theServant->GetScale()<<")"<<endl;
753 std::string aStringEntity;
754 VISU::Entity anEntity = theServant->GetVectorialFieldEntity();
757 aStringEntity = "VISU.NODE";
760 aStringEntity = "VISU.EDGE";
763 aStringEntity = "VISU.FACE";
766 aStringEntity = "VISU.CELL";
769 theStr<< thePrefix << theName << ".SetVectorialField("<<aStringEntity<<", '" << theServant->GetVectorialFieldName() <<"')"<<endl;
775 //---------------------------------------------------------------------------
777 CutLinesToPython(SALOMEDS::SObject_ptr theSObject,
778 VISU::CutLines_i* theServant,
779 std::ostream& theStr,
780 const std::string& theName,
781 TColoredPrs3dFactory& thePrsFactory,
782 std::string thePrefix)
784 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
785 theStr<<thePrefix<<endl;
788 switch(theServant->GetOrientationType()){
790 aParam = "VISU.CutPlanes.XY";
793 aParam = "VISU.CutPlanes.YZ";
796 aParam = "VISU.CutPlanes.ZX";
799 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
801 switch(theServant->GetOrientationType2()){
803 aParam = "VISU.CutPlanes.XY";
806 aParam = "VISU.CutPlanes.YZ";
809 aParam = "VISU.CutPlanes.ZX";
812 theStr<<thePrefix<<theName<<".SetOrientation2("<<aParam<<", "<<theServant->GetRotateX2()<<", "<<theServant->GetRotateY2()<<")"<<endl;
814 theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
815 theStr<<thePrefix<<theName<<".SetDisplacement2("<<theServant->GetDisplacement2()<<")"<<endl;
817 if(!theServant->IsDefault())
818 theStr<<thePrefix<<theName<<".SetBasePlanePosition("<<theServant->GetBasePlanePosition()<<")"<<endl;
820 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
821 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
823 CORBA::Long aNbLines = theServant->GetNbLines();
824 theStr<<thePrefix<<theName<<".SetNbLines("<<aNbLines<<")"<<endl;
825 for(CORBA::Long anId = 0; anId < aNbLines; anId++){
826 if(!theServant->IsDefaultPosition(anId))
827 theStr<<thePrefix<<theName<<".SetLinePosition("<<anId<<", "<<theServant->GetLinePosition(anId)<<")"<<endl;
834 //---------------------------------------------------------------------------
836 CutSegmentToPython(SALOMEDS::SObject_ptr theSObject,
837 VISU::CutSegment_i* theServant,
838 std::ostream& theStr,
839 const std::string& theName,
840 TColoredPrs3dFactory& thePrsFactory,
841 std::string thePrefix)
843 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
844 theStr<<thePrefix<<endl;
846 double x1, y1, z1, x2, y2, z2;
847 theServant->GetPoint1(x1, y1, z1);
848 theServant->GetPoint2(x2, y2, z2);
849 theStr<<thePrefix<<theName<<".SetPoint1("<<x1<<", "<<y1<<", "<<z1<<")"<<endl;
850 theStr<<thePrefix<<theName<<".SetPoint2("<<x2<<", "<<y2<<", "<<z2<<")"<<endl;
852 CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
853 theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
859 //---------------------------------------------------------------------------
861 Plot3DToPython(SALOMEDS::SObject_ptr theSObject,
862 VISU::Plot3D_i* theServant,
863 std::ostream& theStr,
864 const std::string& theName,
865 TColoredPrs3dFactory& thePrsFactory,
866 std::string thePrefix)
868 thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
869 theStr<<thePrefix<<endl;
872 switch(theServant->GetOrientationType()){
874 aParam = "VISU.Plot3D.XY";
877 aParam = "VISU.Plot3D.YZ";
880 aParam = "VISU.Plot3D.ZX";
883 theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
885 theStr<<thePrefix<<theName<<".SetPlanePosition("<<theServant->GetPlanePosition()<<", "<<theServant->IsPositionRelative()<<")"<<endl;
886 theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
887 theStr<<thePrefix<<theName<<".SetContourPrs("<<theServant->GetIsContourPrs()<<")"<<endl;
888 theStr<<thePrefix<<theName<<".SetNbOfContours("<<theServant->GetNbOfContours()<<")"<<endl;
893 //---------------------------------------------------------------------------
895 void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
896 CORBA::Boolean theIsPublished,
897 CORBA::Boolean& theIsValidScript,
898 SALOMEDS::SObject_ptr theSObject,
899 std::ostream& theStr,
900 TName2EntryMap& theName2EntryMap,
901 TEntry2NameMap& theEntry2NameMap,
902 std::string theArgumentName,
903 std::string thePrefix);
905 //---------------------------------------------------------------------------
906 template<class TTableAttr>
908 TableAttrToPython(SALOMEDS::Study_ptr theStudy,
909 CORBA::Boolean theIsPublished,
910 CORBA::Boolean& theIsValidScript,
911 SALOMEDS::SObject_ptr theSObject,
912 TTableAttr theTableAttr,
913 const std::string& theAttrName,
914 std::ostream& theStr,
915 TName2EntryMap& theName2EntryMap,
916 TEntry2NameMap& theEntry2NameMap,
917 std::string theArgumentName,
918 std::string thePrefix)
920 SALOMEDS::GenericAttribute_var anAttr;
921 SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
922 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
923 SALOMEDS::AttributeString_var aComment =
924 SALOMEDS::AttributeString::_narrow(anAttr);
925 CORBA::String_var aValue = aComment->Value();
926 Storable::TRestoringMap aMap;
927 Storable::StringToMap(aValue.in(),aMap);
929 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
931 if(strcmp(aMethodName.toLatin1().data(),"ImportTables") == 0){
937 std::string aSObjectName = GetName(theSObject);
938 if(theArgumentName.empty())
939 theArgumentName = "aSComponent";
940 theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject("<<theArgumentName<<")"<<endl;
941 theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
944 theStr<<thePrefix<<"aBuilder.SetName("<<aSObjectName<<", \""<<theSObject->GetName()<<"\")"<<endl; // Fix for IPAL13165
945 std::string aName = "aTableAttr";
946 theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
947 aSObjectName<<", '"<<theAttrName<<"')"<<endl;
949 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
950 std::string aPrefix = thePrefix;
953 CORBA::String_var aString = theTableAttr->GetTitle();
954 theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
956 CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
957 theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
959 CORBA::Long aNbRows = theTableAttr->GetNbRows();
961 // push values and their indices into streams
962 strstream values, rows, columns;
964 for(CORBA::Long i = 1; i <= aNbColumns; i++){
965 for(CORBA::Long j = aNbRows; j > 0; j--){
966 if(theTableAttr->HasValue(j,i)){
967 values << comma << theTableAttr->GetValue(j,i);
969 columns << comma << i;
975 // push titles and units into streams
976 strstream rowUnits, rowTitles, colTitles;
977 SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
978 SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
980 for(CORBA::Long j = 1; j <= aNbRows; j++){
981 rowUnits << comma << "'" << aRowUnits [ j - 1 ] << "'";
982 rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
986 SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
988 for(CORBA::Long j = 1; j <= aNbColumns; j++){
989 colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
999 // write FillTable command
1000 theStr<< thePrefix << aName << "_values = [" << values.str() << "]" << endl;
1001 theStr<< thePrefix << aName << "_rows = [" << rows.str() << "]" << endl;
1002 theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
1003 theStr<< thePrefix << aName << "_rUnits = [" << rowUnits.str() << "]" << endl;
1004 theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
1005 theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
1006 theStr<< thePrefix << "visu.FillTable( "
1008 << aName << "_values, "
1009 << aName << "_rows, "
1010 << aName << "_columns, "
1011 << aName << "_rTitles, "
1012 << aName << "_rUnits, "
1013 << aName << "_cTitles )" << endl;
1015 if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
1016 theStr<<thePrefix<<endl;
1017 std::string aName = "aTable";
1018 theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
1019 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1020 theArgumentName = aName;
1022 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1023 std::string aPrefix2 = thePrefix + PREFIX;
1025 // Set name (as this object could be renamed by user)
1026 CORBA::String_var aNameInStudy = theSObject->GetName();
1027 theStr<<aPrefix2<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 1"<<endl;
1029 DumpChildrenToPython(theStudy,
1039 theStr<<aPrefix2<<"pass"<<endl<<endl;
1042 theStr<<thePrefix<<"pass"<<endl<<endl;
1043 theStr<<aPrefix<<"pass"<<endl<<endl;
1047 //---------------------------------------------------------------------------
1049 DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
1050 CORBA::Boolean theIsPublished,
1051 CORBA::Boolean& theIsValidScript,
1052 SALOMEDS::SObject_ptr theSObject,
1053 std::ostream& theStr,
1054 TName2EntryMap& theName2EntryMap,
1055 TEntry2NameMap& theEntry2NameMap,
1056 std::string theArgumentName,
1057 std::string thePrefix)
1059 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1060 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1061 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1062 DumpToPython(theStudy,
1075 //---------------------------------------------------------------------------
1077 DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
1078 CORBA::Boolean theIsPublished,
1079 CORBA::Boolean& theIsValidScript,
1080 SALOMEDS::SObject_ptr theSObject,
1081 std::ostream& theStr,
1082 TName2EntryMap& theName2EntryMap,
1083 TEntry2NameMap& theEntry2NameMap,
1084 std::string theArgumentName,
1085 std::string thePrefix)
1087 SALOMEDS::GenericAttribute_var anAttr;
1088 if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
1089 SALOMEDS::AttributeTableOfInteger_var aTableAttr =
1090 SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
1092 TableAttrToPython(theStudy,
1097 "AttributeTableOfInteger",
1104 }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
1105 SALOMEDS::AttributeTableOfReal_var aTableAttr =
1106 SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1108 TableAttrToPython(theStudy,
1113 "AttributeTableOfReal",
1124 //---------------------------------------------------------------------------
1126 DumpToPython(SALOMEDS::Study_ptr theStudy,
1127 CORBA::Boolean theIsPublished,
1128 CORBA::Boolean& theIsValidScript,
1129 SALOMEDS::SObject_ptr theSObject,
1130 std::ostream& theStr,
1131 TName2EntryMap& theName2EntryMap,
1132 TEntry2NameMap& theEntry2NameMap,
1133 std::string theArgumentName,
1134 std::string thePrefix)
1136 std::string aName = GetName(theSObject);
1140 CORBA::String_var anID = theSObject->GetID();
1141 CORBA::String_var aNameInStudy = theSObject->GetName();
1143 CORBA::Object_var anObj = SObjectToObject(theSObject);
1144 if (!CORBA::is_nil(anObj)) {
1145 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1146 if(!CORBA::is_nil(aBase)){
1147 std::string aName = GenerateName(theSObject, theName2EntryMap, theEntry2NameMap);
1149 VISU::VISUType aType = aBase->GetType();
1152 if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
1153 std::string aFileName = aServant->GetInitFileName();
1154 Result_i::ECreationId anId = aServant->GetCreationId();
1155 if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
1157 case Result_i::eImportFile:
1158 theStr<<thePrefix<<aName<<" = aVisu.CreateResult('"<<aFileName<<"')"<<endl;
1160 theStr<<thePrefix<<aName<<".SetBuildGroups("<<
1161 GetBoolean(aServant->IsGroupsDone())<<")"<<
1164 theStr<<thePrefix<<aName<<".SetBuildFields("<<
1165 GetBoolean(aServant->IsFieldsDone())<<", "<<
1166 GetBoolean(aServant->IsMinMaxDone())<<")"<<
1169 theStr<<thePrefix<<aName<<".Build(False, True)"<<endl;
1171 theStr<<thePrefix<<"if "<<aName<<".IsDone() :"<<endl;
1173 case Result_i::eCopyAndImportFile:
1174 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
1175 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1179 thePrefix += PREFIX;
1181 VISU::Result::EntityNames_var aMeshNames = aServant->GetMeshNames();
1182 if (aMeshNames->length() > 0) {
1183 for(size_t aMeshId = 0; aMeshId < aMeshNames->length(); aMeshId++){
1184 CORBA::String_var aMeshName = aMeshNames[aMeshId];
1185 VISU::Result::EntityNames_var aParts = aServant->GetPartNames(aMeshName);
1186 if (aParts->length() > 0) {
1187 for(size_t aPartId = 0; aPartId < aParts->length(); aPartId++){
1188 CORBA::String_var aPart = aParts[aPartId];
1189 VISU::Result::Resolution aResolution = aServant->GetResolution(aMeshName, aPart);
1191 switch(aResolution){
1192 case VISU::Result::FULL:
1193 aParam = "VISU.Result.FULL";
1195 case VISU::Result::MEDIUM:
1196 aParam = "VISU.Result.MEDIUM";
1198 case VISU::Result::LOW:
1199 aParam = "VISU.Result.LOW";
1201 case VISU::Result::HIDDEN:
1202 aParam = "VISU.Result.HIDDEN";
1205 theStr<<thePrefix<<aName<<".SetResolution('"<<aMeshName.in()<<"', '"<<aPart.in()<<"', "<<aParam<<")"<<endl;
1207 theStr<<thePrefix<<endl;
1213 theArgumentName = aName;
1214 DumpChildrenToPython(theStudy,
1224 theStr<<thePrefix<<"pass"<<endl<<endl;
1226 SALOMEDS::SObject_var aRefSObj;
1227 if(theSObject->FindSubObject(1,aRefSObj)){
1228 SALOMEDS::SObject_var aTargetRefSObj;
1229 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
1230 CORBA::String_var aString = aTargetRefSObj->GetName();
1231 theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
1232 theStr<<thePrefix<<"if aSObject:"<<endl;
1233 thePrefix += PREFIX;
1234 theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
1235 theStr<<thePrefix<<"if anObject:"<<endl;
1236 std::string aPrefix1 = thePrefix;
1237 thePrefix += PREFIX;
1240 case Result_i::eImportMed:
1241 theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
1243 case Result_i::eImportMedField:
1244 theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
1248 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1249 std::string aPrefix2 = thePrefix;
1250 thePrefix += PREFIX;
1252 theArgumentName = aName;
1253 DumpChildrenToPython(theStudy,
1263 theStr<<thePrefix<<"pass"<<endl<<endl;
1264 theStr<<aPrefix2<<"pass"<<endl<<endl;
1265 theStr<<aPrefix1<<"pass"<<endl<<endl;
1272 if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
1273 VISU::Entity anEntity = aServant->GetEntity();
1274 const std::string& aSubMeshName = aServant->GetSubMeshName();
1279 aParam = "VISU.NODE";
1282 aParam = "VISU.EDGE";
1285 aParam = "VISU.FACE";
1288 aParam = "VISU.CELL";
1292 if(aSubMeshName == "")
1293 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
1294 ", '"<<aServant->GetCMeshName()<<"'"<<
1298 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
1299 ", '"<<aServant->GetCMeshName()<<"'"<<
1301 ", '"<<aSubMeshName<<"'"<<
1304 theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
1305 ", '"<<aServant->GetCMeshName()<<"'"<<
1306 ", '"<<aSubMeshName<<"'"<<
1309 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1310 thePrefix += PREFIX;
1312 // Add to Name->Object map
1313 theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
1315 // Set name (as this object could be renamed by user)
1316 theStr<<thePrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1318 // Set parameters common for all Prs3d objects (offset values)
1319 Prs3dToPython(aServant,theStr,aName,thePrefix);
1321 // Set presentation parameters
1322 SALOMEDS::Color aColor;
1323 aColor = aServant->GetCellColor();
1324 theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
1325 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1327 aColor = aServant->GetNodeColor();
1328 theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
1329 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1331 aColor = aServant->GetLinkColor();
1332 theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
1333 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1336 switch(aServant->GetPresentationType()){
1338 aParam = "VISU.POINT";
1341 aParam = "VISU.WIREFRAME";
1344 aParam = "VISU.SHADED";
1347 aParam = "VISU.INSIDEFRAME";
1350 aParam = "VISU.SURFACEFRAME";
1353 aParam = "VISU.SHRINK";
1356 theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
1357 theStr<<thePrefix<<aName<<".SetShrink("<<(aServant->IsShrank()? "True" : "False")<<")"<<endl;
1358 theStr<<thePrefix<<endl;
1360 std::string aQuad2DPresent;
1361 switch(aServant->GetQuadratic2DPresentationType()){
1363 aQuad2DPresent = "VISU.LINES";
1366 aQuad2DPresent = "VISU.ARCS";
1370 theStr<<thePrefix<<aName<<".SetQuadratic2DPresentationType("<<aQuad2DPresent<<")"<<endl;
1372 DumpChildrenToPython(theStudy,
1382 theStr<<thePrefix<<"pass"<<endl<<endl;
1386 case VISU::TSCALARMAP:
1387 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
1388 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "ScalarMapOnField", theArgumentName);
1389 thePrefix = ScalarMapToPython(theSObject, aServant, theStr,aName, aPrsFactory, thePrefix);
1390 theStr<<thePrefix<<"pass"<<endl<<endl;
1393 case VISU::TDEFORMEDSHAPE:
1394 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
1395 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeOnField", theArgumentName);
1396 thePrefix = DeformedShapeToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1397 theStr<<thePrefix<<"pass"<<endl<<endl;
1400 case VISU::TSTREAMLINES:
1401 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
1402 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "StreamLinesOnField", theArgumentName);
1403 thePrefix = StreamLinesToPython(theSObject, aServant, theStr, theEntry2NameMap, aName, aPrsFactory, thePrefix);
1404 theStr<<thePrefix<<"pass"<<endl<<endl;
1407 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1408 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1409 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(GetServant(anObj).in())){
1410 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeAndScalarMapOnField", theArgumentName);
1411 thePrefix = DeformedShapeAndScalarMapToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1412 theStr<<thePrefix<<"pass"<<endl<<endl;
1415 case VISU::TVECTORS:
1416 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
1417 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "VectorsOnField", theArgumentName);
1418 thePrefix = VectorsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1419 theStr<<thePrefix<<"pass"<<endl<<endl;
1422 case VISU::TISOSURFACES:
1423 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
1424 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "IsoSurfacesOnField", theArgumentName);
1425 thePrefix = IsoSurfacesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1426 theStr<<thePrefix<<"pass"<<endl<<endl;
1429 case VISU::TCUTPLANES:
1430 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
1431 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutPlanesOnField", theArgumentName);
1432 thePrefix = CutPlanesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1433 theStr<<thePrefix<<"pass"<<endl<<endl;
1436 case VISU::TCUTLINES:
1437 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
1438 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutLinesOnField", theArgumentName);
1439 thePrefix = CutLinesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1441 theArgumentName = aName;
1442 DumpChildrenToPython(theStudy,
1452 theStr<<thePrefix<<"pass"<<endl<<endl;
1455 case VISU::TCUTSEGMENT:
1456 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(GetServant(anObj).in())){
1457 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutSegmentOnField", theArgumentName);
1458 thePrefix = CutSegmentToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1460 theArgumentName = aName;
1461 DumpChildrenToPython(theStudy,
1471 theStr<<thePrefix<<"pass"<<endl<<endl;
1475 if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
1476 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
1477 thePrefix = Plot3DToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1478 theStr<<thePrefix<<"pass"<<endl<<endl;
1481 case VISU::TPOINTMAP3D:
1482 if (PointMap3d_i* aServant = dynamic_cast<PointMap3d_i*>(GetServant(anObj).in())) {
1483 CORBA::Short aTag = theSObject->Tag();
1484 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1485 theStr<<thePrefix<<"if anIsFound:"<<endl;
1486 thePrefix += PREFIX;
1488 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1489 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1491 // Set name (as this object could be renamed by user)
1492 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1494 // Set PointMap3D Properties
1496 theStr<<thePrefix<<aName<<".SetScaleFactor("<<aServant->GetScaleFactor()<<")"<<endl;
1497 theStr<<thePrefix<<aName<<".SetContourPrs("<<aServant->GetIsContourPrs()<<")"<<endl;
1498 theStr<<thePrefix<<aName<<".SetNbOfContours("<<aServant->GetNbOfContours()<<")"<<endl;
1501 switch(aServant->GetScaling()){
1503 aParam = "VISU.LINEAR";
1506 aParam = "VISU.LOGARITHMIC";
1509 theStr<<thePrefix<<aName<<".SetScaling("<<aParam<<")"<<endl;
1511 theStr<<thePrefix<<aName<<".SetNbColors("<<aServant->GetNbColors()<<")"<<endl;
1512 theStr<<thePrefix<<aName<<".SetLabels("<<aServant->GetLabels()<<")"<<endl;
1514 switch(aServant->GetBarOrientation()){
1515 case ColoredPrs3dBase::HORIZONTAL:
1516 aParam = "VISU.ColoredPrs3d.HORIZONTAL";
1518 case ColoredPrs3dBase::VERTICAL:
1519 aParam = "VISU.ColoredPrs3d.VERTICAL";
1522 theStr<<thePrefix<<aName<<".SetBarOrientation("<<aParam<<")"<<endl;
1524 if(aServant->IsRangeFixed())
1525 theStr<<thePrefix<<aName<<".SetRange("<<aServant->GetMin()<<", "<<aServant->GetMax()<<")"<<endl;
1527 theStr<<thePrefix<<aName<<".SetSourceRange()"<<endl;
1529 theStr<<thePrefix<<aName<<".SetPosition("<<aServant->GetPosX()<<", "<<aServant->GetPosY()<<")"<<endl;
1530 theStr<<thePrefix<<aName<<".SetSize("<<aServant->GetWidth()<<", "<<aServant->GetHeight()<<")"<<endl;
1533 aServant->GetOffset(dx, dy, dz);
1534 theStr<<thePrefix<<aName<<".SetOffset("<<dx<<", "<<dy<<", "<<dz<<")"<<endl;
1537 theStr<<thePrefix<<endl;
1539 theArgumentName = aName;
1540 DumpChildrenToPython(theStudy,
1550 theStr<<thePrefix<<"pass"<<endl<<endl;
1553 case VISU::TGAUSSPOINTS:
1554 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(GetServant(anObj).in())){
1555 TCreateFromResult aPrsFactory(theSObject, aServant, aName, "GaussPointsOnField", theArgumentName);
1556 thePrefix = GaussPointsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1557 theStr<<thePrefix<<"pass"<<endl<<endl;
1561 if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
1563 bool withZ = aServant->GetZRow()>0;
1564 bool isV2 = aServant->GetIsV2();
1566 theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
1568 theStr << "WithZExt";
1572 theArgumentName<< // table
1573 ", "<<aServant->GetHRow()<< // H row
1574 ", "<<aServant->GetVRow(); // V row
1576 theStr << ", " << aServant->GetZRow(); // Z row
1578 theStr << ", " << aServant->GetIsV2(); // right axis
1580 theStr << ", '"<<aServant->GetTitle()<<"'"; // title
1581 SALOMEDS::Color aColor = aServant->GetColor();
1582 theStr << ",SALOMEDS.Color("<<
1583 aColor.R<<", "<<aColor.G<<", "<<aColor.B<<")"; // color
1586 switch(aServant->GetMarker()){
1587 case Curve::NONE: aParam = "VISU.Curve.NONE"; break;
1588 case Curve::CIRCLE: aParam = "VISU.Curve.CIRCLE"; break;
1589 case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
1590 case Curve::DIAMOND: aParam = "VISU.Curve.DIAMOND"; break;
1591 case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
1592 case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
1593 case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
1594 case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
1595 case Curve::CROSS: aParam = "VISU.Curve.CROSS"; break;
1596 case Curve::XCROSS: aParam = "VISU.Curve.XCROSS"; break;
1598 theStr<<", "<<aParam; // marker
1600 switch(aServant->GetLine()){
1601 case Curve::VOIDLINE: aParam = "VISU.Curve.VOIDLINE"; break;
1602 case Curve::SOLIDLINE: aParam = "VISU.Curve.SOLIDLINE"; break;
1603 case Curve::DASHLINE: aParam = "VISU.Curve.DASHLINE"; break;
1604 case Curve::DOTLINE: aParam = "VISU.Curve.DOTLINE"; break;
1605 case Curve::DASHDOTLINE: aParam = "VISU.Curve.DASHDOTLINE"; break;
1606 case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
1608 theStr<<", "<<aParam<<", "<<aServant->GetLineWidth()<<")"<<endl; // line type,width
1612 if(dynamic_cast<Table_i*>(GetServant(anObj).in())){
1613 SALOMEDS::GenericAttribute_var anAttr;
1614 if(theSObject->FindAttribute(anAttr,"AttributeString")){
1615 using namespace SALOMEDS;
1616 AttributeString_var aComment = AttributeString::_narrow(anAttr);
1617 CORBA::String_var aValue = aComment->Value();
1618 Storable::TRestoringMap aMap;
1619 Storable::StringToMap(aValue.in(),aMap);
1621 QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1623 if( aSourceId == "CutLines" ){
1624 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
1625 thePrefix += PREFIX;
1627 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
1628 theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
1629 theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
1630 theStr<<thePrefix<<"if aSObject:"<<endl;
1631 std::string aPrefix = thePrefix;
1632 thePrefix += PREFIX;
1634 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1635 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1637 // Set name (as this object could be renamed by user)
1638 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 2"<<endl;
1640 theStr<<thePrefix<<endl;
1642 theArgumentName = aName;
1643 DumpChildrenToPython(theStudy,
1653 theStr<<thePrefix<<"pass"<<endl<<endl;
1654 theStr<<aPrefix<<"pass"<<endl<<endl;
1655 }else if( aSourceId == "TableFile" ){
1656 CORBA::Short aTag = theSObject->Tag();
1657 theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1658 theStr<<thePrefix<<"if anIsFound:"<<endl;
1659 thePrefix += PREFIX;
1661 theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1662 theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1664 // Set name (as this object could be renamed by user)
1665 theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1667 theStr<<thePrefix<<endl;
1669 theArgumentName = aName;
1670 DumpChildrenToPython(theStudy,
1680 theStr<<thePrefix<<"pass"<<endl<<endl;
1681 }else if( aSourceId == "TableAttr" ){
1682 theArgumentName = aName;
1683 DumpTableAttrToPython(theStudy,
1699 } else { /*if(!CORBA::is_nil(anObj))*/
1700 SALOMEDS::GenericAttribute_var anAttr;
1701 if (theSObject->FindAttribute(anAttr,"AttributeString")) {
1702 SALOMEDS::AttributeString_var aComment =
1703 SALOMEDS::AttributeString::_narrow(anAttr);
1704 CORBA::String_var aValue = aComment->Value();
1705 Storable::TRestoringMap aMap;
1706 Storable::StringToMap(aValue.in(),aMap);
1708 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1710 if (aTypeName == "ImportTables") {
1711 QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1714 GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1715 QString aFirstStrAsTitle =
1716 VISU::Storable::FindValue(aMap,"myFirstStrAsTitle",&anIsExist);
1717 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"
1718 <<aFileName.toLatin1().data()<<"',"
1719 <<aFirstStrAsTitle.toLatin1().data()<<")"<<endl;
1720 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1721 thePrefix += PREFIX;
1723 theArgumentName = aName;
1724 DumpChildrenToPython(theStudy,
1734 theStr<<thePrefix<<"pass"<<endl<<endl;
1737 } else if (aTypeName == "VIEW3D") {
1738 std::string aName = GetName(theSObject);
1739 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1741 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1742 thePrefix += PREFIX;
1744 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1745 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1747 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1748 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1750 theStr<<thePrefix<<"pass"<<endl<<endl;
1752 } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1753 // Set name (as this object could be renamed by user)
1754 string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1755 string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1756 string anEntityTypeKey = "myEntityId";
1757 if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1758 int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1759 std::string anEntityType;
1760 switch ((TEntity)anEntity) {
1761 case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1762 case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1763 case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1764 case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1767 if (aTypeName == "ENTITY" ) {
1768 theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1769 <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1771 else if (aTypeName == "FAMILY") {
1772 if (aSubMeshName != aNameInStudy.in()) {
1773 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1774 <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1778 if (aSubMeshName != aNameInStudy.in()) {
1779 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1780 <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1786 DumpTableAttrToPython(theStudy,
1798 DumpChildrenToPython(theStudy,
1810 //---------------------------------------------------------------------------
1812 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1813 CORBA::Boolean theIsPublished,
1814 CORBA::Boolean& theIsValidScript,
1815 SALOMEDS::SObject_ptr theSObject,
1816 std::ostream& theStr,
1817 TName2EntryMap& theName2EntryMap,
1818 TEntry2NameMap& theEntry2NameMap,
1819 std::string theArgumentName,
1820 std::string thePrefix)
1822 SALOMEDS::SObject_var aTargetRefSObj;
1823 if(theSObject->ReferencedObject(aTargetRefSObj)){
1824 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1825 if(CORBA::is_nil(anObj))
1828 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1829 if(CORBA::is_nil(aBase))
1832 if(aBase->GetType() == VISU::TCURVE){
1833 CORBA::String_var anID = aTargetRefSObj->GetID();
1834 std::string anArg = theEntry2NameMap[anID.in()];
1835 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1836 thePrefix += PREFIX;
1837 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1838 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1839 theStr<<thePrefix<<"pass"<<endl<<endl;
1845 //---------------------------------------------------------------------------
1847 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1848 CORBA::Boolean theIsPublished,
1849 CORBA::Boolean& theIsValidScript,
1850 SALOMEDS::SObject_ptr theSObject,
1851 std::ostream& theStr,
1852 TName2EntryMap& theName2EntryMap,
1853 TEntry2NameMap& theEntry2NameMap,
1854 std::string theArgumentName,
1855 std::string thePrefix)
1857 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1858 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1859 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1860 CORBA::Object_var anObj = SObjectToObject(aSObject);
1861 if(CORBA::is_nil(anObj))
1864 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1865 if(CORBA::is_nil(aBase))
1868 if(aBase->GetType() == VISU::TCONTAINER){
1869 theStr<<thePrefix<<endl;
1870 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1871 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1872 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1873 std::string aPrefix = thePrefix + PREFIX;
1874 theArgumentName = aName;
1876 // Set name (as this object could be renamed by user)
1877 CORBA::String_var aNameInStudy = aSObject->GetName();
1878 theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1880 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1881 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1882 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1883 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1886 theStr<<aPrefix<<"pass"<<endl<<endl;
1892 //---------------------------------------------------------------------------
1894 DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1895 CORBA::Boolean theIsPublished,
1896 CORBA::Boolean& theIsValidScript,
1897 SALOMEDS::SObject_ptr theSObject,
1898 std::ostream& theStr,
1899 TName2EntryMap& theName2EntryMap,
1900 TEntry2NameMap& theEntry2NameMap,
1901 std::string theArgumentName,
1902 std::string thePrefix)
1905 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1906 for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1907 SALOMEDS::SObject_var aSObject = anIter->Value();
1908 CORBA::Object_var anObj = SObjectToObject(aSObject);
1909 if(CORBA::is_nil(anObj))
1912 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1913 if(CORBA::is_nil(aBase))
1916 if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1917 ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1918 theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1919 theStr<<thePrefix<<"if aCache != None:"<<endl;
1921 std::string aPrefix = thePrefix + PREFIX;
1922 std::string anArgument;
1923 VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1925 case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1926 case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1928 theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1930 if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1931 theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1933 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1934 for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1935 SALOMEDS::SObject_var aSObject = aChildIter->Value();
1936 CORBA::Object_var anObject = SObjectToObject(aSObject);
1937 if (CORBA::is_nil(anObject))
1940 ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1944 ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1948 Result_i* aResult = aDevice->GetCResult();
1949 std::string aResultEntry = aResult->GetEntry();
1950 std::string aResultName = theEntry2NameMap[aResultEntry];
1952 ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1953 std::string anEntity;
1954 switch(anInput->myEntity){
1955 case VISU::NODE : anEntity = "VISU.NODE"; break;
1956 case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1957 case VISU::FACE : anEntity = "VISU.FACE"; break;
1958 case VISU::CELL : anEntity = "VISU.CELL"; break;
1962 theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
1963 aResultName<<", '"<<
1964 anInput->myMeshName<<"', "<<
1966 anInput->myFieldName<<"', "<<
1967 anInput->myTimeStampNumber<<")"<<
1970 std::string aComment = aDevice->GetComment();
1971 theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
1972 theStr<<aPrefix<<"if aHolder != None:"<<endl;
1974 std::string aPrefix2 = aPrefix + PREFIX;
1975 CORBA::String_var aNameInStudy = aSObject->GetName();
1976 theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
1977 theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
1978 theStr<<aPrefix2<<"if aDevice != None:"<<endl;
1980 std::string aPrefix3 = aPrefix2 + PREFIX;
1981 TColoredPrs3dFactory aPrsFactory;
1982 switch(aDevice->GetType()){
1983 case VISU::TSCALARMAP:
1984 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
1985 ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1988 case VISU::TDEFORMEDSHAPE:
1989 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
1990 DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1993 case VISU::TSTREAMLINES:
1994 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
1995 StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
1998 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1999 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
2000 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
2001 DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2004 case VISU::TVECTORS:
2005 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
2006 VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2009 case VISU::TISOSURFACES:
2010 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
2011 IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2014 case VISU::TCUTPLANES:
2015 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
2016 CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2019 case VISU::TCUTLINES:
2020 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
2021 CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2024 case VISU::TCUTSEGMENT:
2025 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(aDevice)){
2026 CutSegmentToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2030 if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
2031 Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2034 case VISU::TGAUSSPOINTS:
2035 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
2036 GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2040 theStr<<aPrefix3<<"pass"<<endl;
2042 theStr<<aPrefix2<<"pass"<<endl<<endl;
2045 theStr<<aPrefix<<"pass"<<endl;
2052 //---------------------------------------------------------------------------
2054 DumpEvolutionsToPython(SALOMEDS::Study_ptr theStudy,
2055 CORBA::Boolean theIsPublished,
2056 CORBA::Boolean& theIsValidScript,
2057 SALOMEDS::SObject_ptr theSObject,
2058 std::ostream& theStr,
2059 TName2EntryMap& theName2EntryMap,
2060 TEntry2NameMap& theEntry2NameMap,
2061 std::string thePrefix)
2063 if(!theIsPublished) return;
2065 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2066 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2067 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2069 SALOMEDS::GenericAttribute_var anAttr;
2070 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2072 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2073 QString value (aStringAttr->Value());
2074 if(value.isEmpty()) continue;
2076 VISU::Storable::TRestoringMap aMap;
2077 VISU::Storable::StringToMap(value, aMap);
2080 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2081 if(!isExist || aTypeName != "EVOLUTION") continue;
2084 theStr<<thePrefix<<endl;
2085 QString evolutionName = aSObject->GetName();
2086 theStr<<thePrefix<<"#Evolution: "<<evolutionName.toLatin1().data()<<endl;
2087 theStr<<thePrefix<<endl;
2088 theStr<<thePrefix<<"evolutionSO = aBuilder.NewObject(aSComponent)"<<endl;
2089 theStr<<thePrefix<<"aBuilder.SetName(evolutionSO, '"<<evolutionName.toLatin1().data()<<"')"<< endl;
2090 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(evolutionSO, 'AttributeString')"<< endl;
2091 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2093 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2094 for (anIter->Init(); anIter->More(); anIter->Next()) {
2095 SALOMEDS::SObject_var anObj = anIter->Value();
2098 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(evolutionSO)"<<endl;
2099 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2100 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2101 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2102 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2105 SALOMEDS::SObject_var refObj;
2106 if(anObj->ReferencedObject(refObj)) {
2107 SALOMEDS::SObject_var father = refObj->GetFather();
2108 value = refObj->GetName();
2109 QString path(theStudy->GetObjectPath(father));
2110 //The following code requierd as a field name can contain '/' character
2111 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2113 value = anObj->GetName();
2114 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2117 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(anObj);
2118 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2119 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2121 std::string anArgumentName = "fieldSO";
2122 DumpTableAttrToPython(theStudy,
2136 theStr<<thePrefix<<endl;
2140 //---------------------------------------------------------------------------
2142 DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
2143 CORBA::Boolean theIsPublished,
2144 CORBA::Boolean& theIsValidScript,
2145 SALOMEDS::SObject_ptr theSObject,
2146 std::ostream& theStr,
2147 std::string thePrefix)
2150 if(!theIsPublished) return;
2152 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2153 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2154 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2156 SALOMEDS::GenericAttribute_var anAttr;
2157 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2159 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2160 QString value (aStringAttr->Value());
2161 if(value.isEmpty()) continue;
2163 VISU::Storable::TRestoringMap aMap;
2164 VISU::Storable::StringToMap(value, aMap);
2167 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2168 if(!isExist || aTypeName != "ANIMATION") continue;
2171 theStr<<thePrefix<<endl;
2172 QString animName = aSObject->GetName();
2173 theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
2174 theStr<<thePrefix<<endl;
2175 theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
2176 theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
2177 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
2178 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2182 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2183 for (anIter->Init(); anIter->More(); anIter->Next()) {
2184 SALOMEDS::SObject_var anObj = anIter->Value();
2187 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
2188 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2189 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2190 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2191 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2194 SALOMEDS::SObject_var refObj;
2195 if(anObj->ReferencedObject(refObj)) {
2196 SALOMEDS::SObject_var father = refObj->GetFather();
2197 value = refObj->GetName();
2198 QString path(theStudy->GetObjectPath(father));
2199 //The following code requierd as a field name can contain '/' character
2200 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2202 value = anObj->GetName();
2203 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2206 SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
2207 for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
2208 SALOMEDS::SObject_var aSubObj = aSubIter->Value();
2210 theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
2211 value = aSubObj->GetName();
2212 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
2213 if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
2214 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2215 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2216 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2224 theStr<<thePrefix<<endl;
2229 DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2230 CORBA::Boolean theIsPublished,
2231 CORBA::Boolean& theIsValidScript,
2232 SALOMEDS::SObject_ptr theSObject,
2233 std::ostream& theStr,
2234 std::string thePrefix,
2235 VISU_ClippingPlaneMgr& thePlaneMgr)
2238 if(!theIsPublished) return;
2240 VISU_CutPlaneFunction* aPlane;
2241 double aOrigin[3], aDir[3];
2242 for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2243 aPlane = thePlaneMgr.GetClippingPlane(i);
2244 aPlane->GetOrigin(aOrigin);
2245 aPlane->GetNormal(aDir);
2247 theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2248 aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2249 aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2250 aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;
2257 DumpTextureMapToPython(SALOMEDS::Study_ptr theStudy,
2258 CORBA::Boolean theIsPublished,
2259 CORBA::Boolean& theIsValidScript,
2260 SALOMEDS::SObject_ptr theSObject,
2261 std::ostream& theStr,
2262 std::string thePrefix,
2263 const StudyId2MarkerMap& theMarkerMap)
2268 if(CORBA::is_nil(theStudy))
2271 StudyId2MarkerMap::const_iterator anIter = theMarkerMap.find(theStudy->StudyId());
2272 if(anIter == theMarkerMap.end())
2275 theStr<<thePrefix<<"texture_map = {}"<<endl<<endl;
2277 const VTK::MarkerMap& aMarkerMap = anIter->second;
2278 VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
2279 for(; aMarkerIter != aMarkerMap.end(); aMarkerIter++) {
2280 int aMarkerId = aMarkerIter->first;
2281 std::string aMarkerTexture = aMarkerIter->second.first;
2282 theStr<<thePrefix<<"texture_map["<<aMarkerId<<"] = aVisu.LoadTexture(\""<<aMarkerTexture<<"\")"<<endl;
2288 //---------------------------------------------------------------------------
2291 DumpPython(CORBA::Object_ptr theStudy,
2292 CORBA::Boolean theIsPublished,
2293 CORBA::Boolean& theIsValidScript)
2295 theIsValidScript = false;
2297 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2298 if(CORBA::is_nil(aStudy))
2299 return new Engines::TMPFile(0);
2301 TName2EntryMap aName2EntryMap;
2302 TEntry2NameMap aEntry2NameMap;
2310 std::string aPrefix(PREFIX);
2311 aStr<<"def RebuildData(theStudy):"<<endl;
2312 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2313 aStr<<aPrefix<<"import SALOME_MED"<<endl;
2314 aStr<<aPrefix<<"import SALOMEDS"<<endl;
2315 aStr<<aPrefix<<"import VISU"<<endl;
2316 aStr<<aPrefix<<"import visu"<<endl;
2318 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2319 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2320 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2321 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2322 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2325 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2327 VISU::DumpClippingPlanesToPython(aStudy,
2333 myClippingPlaneMgr);
2335 VISU::DumpTextureMapToPython(aStudy,
2343 VISU::DumpChildrenToPython(aStudy,
2353 VISU::DumpEvolutionsToPython(aStudy,
2362 VISU::DumpContainersToPython(aStudy,
2372 VISU::DumpPrs3dCacheToPython(aStudy,
2382 VISU::DumpAnimationsToPython(aStudy,
2390 //Output the script that sets up the visul parameters.
2391 if(theIsPublished) {
2392 char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2393 if(script && strlen(script) > 0) {
2395 CORBA::string_free(script);
2399 aStr<<aPrefix<<"pass"<<endl;
2401 if(theIsPublished) { //SRN: define function for Animation
2403 //Define a function that find a SObject by its father's path and its name
2407 aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
2408 aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
2409 aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
2410 aStr<<aPrefix<<"while itr.More():"<<endl;
2411 aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
2412 aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
2413 aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
2414 aStr<<aPrefix<<aPrefix<<"pass"<<endl;
2415 aStr<<aPrefix<<"return None"<<endl;
2420 // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2421 // If the situation changes, then the following line should be removed, and theIsValidScript
2422 // should be set properly by those internal methods
2423 theIsValidScript = true;
2426 std::string aResult = aStr.str();
2427 //ofstream anFStream("/tmp/dump.py");
2428 //anFStream<<aResult<<endl;
2430 CORBA::ULong aSize = aResult.size() + 1;
2431 char* aBuffer = new char[aSize];
2432 strcpy(aBuffer,&aResult[0]);
2433 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2436 return new Engines::TMPFile(0);