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 stringstream 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 stringstream 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).trimmed().toLower();
1717 if ( aFirstStrAsTitle == "1" || aFirstStrAsTitle == "true" )
1718 aFirstStrAsTitle = "True";
1720 aFirstStrAsTitle = "False";
1721 theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"
1722 <<aFileName.toLatin1().data()<<"',"
1723 <<aFirstStrAsTitle.toLatin1().data()<<")"<<endl;
1724 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1725 thePrefix += PREFIX;
1727 theArgumentName = aName;
1728 DumpChildrenToPython(theStudy,
1738 theStr<<thePrefix<<"pass"<<endl<<endl;
1741 } else if (aTypeName == "VIEW3D") {
1742 std::string aName = GetName(theSObject);
1743 theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1745 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1746 thePrefix += PREFIX;
1748 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1749 theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1751 theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1752 theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1754 theStr<<thePrefix<<"pass"<<endl<<endl;
1756 } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1757 // Set name (as this object could be renamed by user)
1758 string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1759 string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1760 string anEntityTypeKey = "myEntityId";
1761 if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1762 int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1763 std::string anEntityType;
1764 switch ((TEntity)anEntity) {
1765 case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1766 case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1767 case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1768 case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1771 if (aTypeName == "ENTITY" ) {
1772 theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1773 <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1775 else if (aTypeName == "FAMILY") {
1776 if (aSubMeshName != aNameInStudy.in()) {
1777 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1778 <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1782 if (aSubMeshName != aNameInStudy.in()) {
1783 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1784 <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1790 DumpTableAttrToPython(theStudy,
1802 DumpChildrenToPython(theStudy,
1814 //---------------------------------------------------------------------------
1816 DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1817 CORBA::Boolean theIsPublished,
1818 CORBA::Boolean& theIsValidScript,
1819 SALOMEDS::SObject_ptr theSObject,
1820 std::ostream& theStr,
1821 TName2EntryMap& theName2EntryMap,
1822 TEntry2NameMap& theEntry2NameMap,
1823 std::string theArgumentName,
1824 std::string thePrefix)
1826 SALOMEDS::SObject_var aTargetRefSObj;
1827 if(theSObject->ReferencedObject(aTargetRefSObj)){
1828 CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1829 if(CORBA::is_nil(anObj))
1832 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1833 if(CORBA::is_nil(aBase))
1836 if(aBase->GetType() == VISU::TCURVE){
1837 CORBA::String_var anID = aTargetRefSObj->GetID();
1838 std::string anArg = theEntry2NameMap[anID.in()];
1839 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1840 thePrefix += PREFIX;
1841 theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1842 theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1843 theStr<<thePrefix<<"pass"<<endl<<endl;
1849 //---------------------------------------------------------------------------
1851 DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1852 CORBA::Boolean theIsPublished,
1853 CORBA::Boolean& theIsValidScript,
1854 SALOMEDS::SObject_ptr theSObject,
1855 std::ostream& theStr,
1856 TName2EntryMap& theName2EntryMap,
1857 TEntry2NameMap& theEntry2NameMap,
1858 std::string theArgumentName,
1859 std::string thePrefix)
1861 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1862 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1863 SALOMEDS::SObject_var aSObject = aChildItet->Value();
1864 CORBA::Object_var anObj = SObjectToObject(aSObject);
1865 if(CORBA::is_nil(anObj))
1868 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1869 if(CORBA::is_nil(aBase))
1872 if(aBase->GetType() == VISU::TCONTAINER){
1873 theStr<<thePrefix<<endl;
1874 std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1875 theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1876 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1877 std::string aPrefix = thePrefix + PREFIX;
1878 theArgumentName = aName;
1880 // Set name (as this object could be renamed by user)
1881 CORBA::String_var aNameInStudy = aSObject->GetName();
1882 theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1884 SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1885 for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1886 SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1887 DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1890 theStr<<aPrefix<<"pass"<<endl<<endl;
1896 //---------------------------------------------------------------------------
1898 DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1899 CORBA::Boolean theIsPublished,
1900 CORBA::Boolean& theIsValidScript,
1901 SALOMEDS::SObject_ptr theSObject,
1902 std::ostream& theStr,
1903 TName2EntryMap& theName2EntryMap,
1904 TEntry2NameMap& theEntry2NameMap,
1905 std::string theArgumentName,
1906 std::string thePrefix)
1909 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1910 for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1911 SALOMEDS::SObject_var aSObject = anIter->Value();
1912 CORBA::Object_var anObj = SObjectToObject(aSObject);
1913 if(CORBA::is_nil(anObj))
1916 VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1917 if(CORBA::is_nil(aBase))
1920 if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1921 ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1922 theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1923 theStr<<thePrefix<<"if aCache != None:"<<endl;
1925 std::string aPrefix = thePrefix + PREFIX;
1926 std::string anArgument;
1927 VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1929 case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1930 case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1932 theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1934 if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1935 theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1937 SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1938 for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1939 SALOMEDS::SObject_var aSObject = aChildIter->Value();
1940 CORBA::Object_var anObject = SObjectToObject(aSObject);
1941 if (CORBA::is_nil(anObject))
1944 ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1948 ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1952 Result_i* aResult = aDevice->GetCResult();
1953 std::string aResultEntry = aResult->GetEntry();
1954 std::string aResultName = theEntry2NameMap[aResultEntry];
1956 ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1957 std::string anEntity;
1958 switch(anInput->myEntity){
1959 case VISU::NODE : anEntity = "VISU.NODE"; break;
1960 case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1961 case VISU::FACE : anEntity = "VISU.FACE"; break;
1962 case VISU::CELL : anEntity = "VISU.CELL"; break;
1966 theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
1967 aResultName<<", '"<<
1968 anInput->myMeshName<<"', "<<
1970 anInput->myFieldName<<"', "<<
1971 anInput->myTimeStampNumber<<")"<<
1974 std::string aComment = aDevice->GetComment();
1975 theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
1976 theStr<<aPrefix<<"if aHolder != None:"<<endl;
1978 std::string aPrefix2 = aPrefix + PREFIX;
1979 CORBA::String_var aNameInStudy = aSObject->GetName();
1980 theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
1981 theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
1982 theStr<<aPrefix2<<"if aDevice != None:"<<endl;
1984 std::string aPrefix3 = aPrefix2 + PREFIX;
1985 TColoredPrs3dFactory aPrsFactory;
1986 switch(aDevice->GetType()){
1987 case VISU::TSCALARMAP:
1988 if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
1989 ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1992 case VISU::TDEFORMEDSHAPE:
1993 if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
1994 DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1997 case VISU::TSTREAMLINES:
1998 if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
1999 StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
2002 case VISU::TSCALARMAPONDEFORMEDSHAPE:
2003 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
2004 if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
2005 DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2008 case VISU::TVECTORS:
2009 if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
2010 VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2013 case VISU::TISOSURFACES:
2014 if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
2015 IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2018 case VISU::TCUTPLANES:
2019 if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
2020 CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2023 case VISU::TCUTLINES:
2024 if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
2025 CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2028 case VISU::TCUTSEGMENT:
2029 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(aDevice)){
2030 CutSegmentToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2034 if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
2035 Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2038 case VISU::TGAUSSPOINTS:
2039 if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
2040 GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2044 theStr<<aPrefix3<<"pass"<<endl;
2046 theStr<<aPrefix2<<"pass"<<endl<<endl;
2049 theStr<<aPrefix<<"pass"<<endl;
2056 //---------------------------------------------------------------------------
2058 DumpEvolutionsToPython(SALOMEDS::Study_ptr theStudy,
2059 CORBA::Boolean theIsPublished,
2060 CORBA::Boolean& theIsValidScript,
2061 SALOMEDS::SObject_ptr theSObject,
2062 std::ostream& theStr,
2063 TName2EntryMap& theName2EntryMap,
2064 TEntry2NameMap& theEntry2NameMap,
2065 std::string thePrefix)
2067 if(!theIsPublished) return;
2069 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2070 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2071 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2073 SALOMEDS::GenericAttribute_var anAttr;
2074 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2076 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2077 QString value (aStringAttr->Value());
2078 if(value.isEmpty()) continue;
2080 VISU::Storable::TRestoringMap aMap;
2081 VISU::Storable::StringToMap(value, aMap);
2084 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2085 if(!isExist || aTypeName != "EVOLUTION") continue;
2088 theStr<<thePrefix<<endl;
2089 QString evolutionName = aSObject->GetName();
2090 theStr<<thePrefix<<"#Evolution: "<<evolutionName.toLatin1().data()<<endl;
2091 theStr<<thePrefix<<endl;
2092 theStr<<thePrefix<<"evolutionSO = aBuilder.NewObject(aSComponent)"<<endl;
2093 theStr<<thePrefix<<"aBuilder.SetName(evolutionSO, '"<<evolutionName.toLatin1().data()<<"')"<< endl;
2094 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(evolutionSO, 'AttributeString')"<< endl;
2095 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2097 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2098 for (anIter->Init(); anIter->More(); anIter->Next()) {
2099 SALOMEDS::SObject_var anObj = anIter->Value();
2102 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(evolutionSO)"<<endl;
2103 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2104 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2105 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2106 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2109 SALOMEDS::SObject_var refObj;
2110 if(anObj->ReferencedObject(refObj)) {
2111 SALOMEDS::SObject_var father = refObj->GetFather();
2112 value = refObj->GetName();
2113 QString path(theStudy->GetObjectPath(father));
2114 //The following code requierd as a field name can contain '/' character
2115 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2117 value = anObj->GetName();
2118 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2121 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(anObj);
2122 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2123 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2125 std::string anArgumentName = "fieldSO";
2126 DumpTableAttrToPython(theStudy,
2140 theStr<<thePrefix<<endl;
2144 //---------------------------------------------------------------------------
2146 DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
2147 CORBA::Boolean theIsPublished,
2148 CORBA::Boolean& theIsValidScript,
2149 SALOMEDS::SObject_ptr theSObject,
2150 std::ostream& theStr,
2151 std::string thePrefix)
2154 if(!theIsPublished) return;
2156 SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2157 for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2158 SALOMEDS::SObject_var aSObject = aChildItet->Value();
2160 SALOMEDS::GenericAttribute_var anAttr;
2161 if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2163 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2164 QString value (aStringAttr->Value());
2165 if(value.isEmpty()) continue;
2167 VISU::Storable::TRestoringMap aMap;
2168 VISU::Storable::StringToMap(value, aMap);
2171 QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2172 if(!isExist || aTypeName != "ANIMATION") continue;
2175 theStr<<thePrefix<<endl;
2176 QString animName = aSObject->GetName();
2177 theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
2178 theStr<<thePrefix<<endl;
2179 theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
2180 theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
2181 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
2182 theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2186 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2187 for (anIter->Init(); anIter->More(); anIter->Next()) {
2188 SALOMEDS::SObject_var anObj = anIter->Value();
2191 theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
2192 if (anObj->FindAttribute(anAttr, "AttributeString")) {
2193 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2194 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2195 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2198 SALOMEDS::SObject_var refObj;
2199 if(anObj->ReferencedObject(refObj)) {
2200 SALOMEDS::SObject_var father = refObj->GetFather();
2201 value = refObj->GetName();
2202 QString path(theStudy->GetObjectPath(father));
2203 //The following code requierd as a field name can contain '/' character
2204 theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2206 value = anObj->GetName();
2207 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2210 SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
2211 for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
2212 SALOMEDS::SObject_var aSubObj = aSubIter->Value();
2214 theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
2215 value = aSubObj->GetName();
2216 if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
2217 if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
2218 aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2219 theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2220 theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2228 theStr<<thePrefix<<endl;
2233 DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2234 CORBA::Boolean theIsPublished,
2235 CORBA::Boolean& theIsValidScript,
2236 SALOMEDS::SObject_ptr theSObject,
2237 std::ostream& theStr,
2238 std::string thePrefix,
2239 VISU_ClippingPlaneMgr& thePlaneMgr)
2242 if(!theIsPublished) return;
2244 VISU_CutPlaneFunction* aPlane;
2245 double aOrigin[3], aDir[3];
2246 for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2247 aPlane = thePlaneMgr.GetClippingPlane(i);
2248 aPlane->GetOrigin(aOrigin);
2249 aPlane->GetNormal(aDir);
2251 theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2252 aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2253 aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2254 aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;
2261 DumpTextureMapToPython(SALOMEDS::Study_ptr theStudy,
2262 CORBA::Boolean theIsPublished,
2263 CORBA::Boolean& theIsValidScript,
2264 SALOMEDS::SObject_ptr theSObject,
2265 std::ostream& theStr,
2266 std::string thePrefix,
2267 const StudyId2MarkerMap& theMarkerMap)
2272 if(CORBA::is_nil(theStudy))
2275 StudyId2MarkerMap::const_iterator anIter = theMarkerMap.find(theStudy->StudyId());
2276 if(anIter == theMarkerMap.end())
2279 theStr<<thePrefix<<"texture_map = {}"<<endl<<endl;
2281 const VTK::MarkerMap& aMarkerMap = anIter->second;
2282 VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
2283 for(; aMarkerIter != aMarkerMap.end(); aMarkerIter++) {
2284 int aMarkerId = aMarkerIter->first;
2285 std::string aMarkerTexture = aMarkerIter->second.first;
2286 theStr<<thePrefix<<"texture_map["<<aMarkerId<<"] = aVisu.LoadTexture(\""<<aMarkerTexture<<"\")"<<endl;
2292 //---------------------------------------------------------------------------
2295 DumpPython(CORBA::Object_ptr theStudy,
2296 CORBA::Boolean theIsPublished,
2297 CORBA::Boolean& theIsValidScript)
2299 theIsValidScript = false;
2301 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2302 if(CORBA::is_nil(aStudy))
2303 return new Engines::TMPFile(0);
2305 TName2EntryMap aName2EntryMap;
2306 TEntry2NameMap aEntry2NameMap;
2314 std::string aPrefix(PREFIX);
2315 aStr<<"def RebuildData(theStudy):"<<endl;
2316 aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2317 aStr<<aPrefix<<"import SALOME_MED"<<endl;
2318 aStr<<aPrefix<<"import SALOMEDS"<<endl;
2319 aStr<<aPrefix<<"import VISU"<<endl;
2320 aStr<<aPrefix<<"import visu"<<endl;
2322 aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2323 aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2324 aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2325 aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2326 aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2329 SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2331 VISU::DumpClippingPlanesToPython(aStudy,
2337 myClippingPlaneMgr);
2339 VISU::DumpTextureMapToPython(aStudy,
2347 VISU::DumpChildrenToPython(aStudy,
2357 VISU::DumpEvolutionsToPython(aStudy,
2366 VISU::DumpContainersToPython(aStudy,
2376 VISU::DumpPrs3dCacheToPython(aStudy,
2386 VISU::DumpAnimationsToPython(aStudy,
2394 //Output the script that sets up the visul parameters.
2395 if(theIsPublished) {
2396 char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2397 if(script && strlen(script) > 0) {
2399 CORBA::string_free(script);
2403 aStr<<aPrefix<<"pass"<<endl;
2405 if(theIsPublished) { //SRN: define function for Animation
2407 //Define a function that find a SObject by its father's path and its name
2411 aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
2412 aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
2413 aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
2414 aStr<<aPrefix<<"while itr.More():"<<endl;
2415 aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
2416 aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
2417 aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
2418 aStr<<aPrefix<<aPrefix<<"pass"<<endl;
2419 aStr<<aPrefix<<"return None"<<endl;
2424 // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2425 // If the situation changes, then the following line should be removed, and theIsValidScript
2426 // should be set properly by those internal methods
2427 theIsValidScript = true;
2430 std::string aResult = aStr.str();
2431 //ofstream anFStream("/tmp/dump.py");
2432 //anFStream<<aResult<<endl;
2434 CORBA::ULong aSize = aResult.size() + 1;
2435 char* aBuffer = new char[aSize];
2436 strcpy(aBuffer,&aResult[0]);
2437 return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2440 return new Engines::TMPFile(0);