Salome HOME
Merge from PortingMED3 07Apr11
[modules/visu.git] / src / VISU_I / VISU_DumpPython.cc
index d782714ea228e6c4f880baed244ad8bad13c0b83..38b1318d8878861529af5be5a4018321eb5235c7 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  VISU OBJECT : interactive object for VISU entities implementation
 //  File   : VISU_DumpPython.cc
 //  Author : Alexey PETROV
@@ -35,6 +36,7 @@
 #include "VISU_DeformedShape_i.hh"
 #include "VISU_CutPlanes_i.hh"
 #include "VISU_CutLines_i.hh"
+#include "VISU_CutSegment_i.hh"
 #include "VISU_Vectors_i.hh"
 #include "VISU_StreamLines_i.hh"
 #include "VISU_Plot3D_i.hh"
@@ -48,7 +50,7 @@
 #include "utilities.h"
 
 #include <cctype>
-#include <strstream>
+#include <sstream>
 #include <functional>
 
 #include <QString>
@@ -211,6 +213,51 @@ namespace VISU
     theServant->GetOffset(x,y,z);
     theStr<<thePrefix<<theName<<".SetOffset("<<x<<", "<<y<<", "<<z<<")"<<endl;
     SetClippingPlane(theServant, theName, theStr, thePrefix);
+
+    VISU::MarkerType aMarkerType = theServant->GetMarkerType();
+    if( aMarkerType != VISU::MT_NONE ) {
+      if( aMarkerType != VISU::MT_USER ) {
+        VISU::MarkerScale aMarkerScale = theServant->GetMarkerScale();
+        std::string aParam1, aParam2;
+        switch( aMarkerType ) {
+        case MT_POINT:   aParam1 = "MT_POINT"; break;
+        case MT_PLUS:    aParam1 = "MT_PLUS"; break;
+        case MT_STAR:    aParam1 = "MT_STAR"; break;
+        case MT_O:       aParam1 = "MT_O"; break;
+        case MT_X:       aParam1 = "MT_X"; break;
+        case MT_O_POINT: aParam1 = "MT_O_POINT"; break;
+        case MT_O_PLUS:  aParam1 = "MT_O_PLUS"; break;
+        case MT_O_STAR:  aParam1 = "MT_O_STAR"; break;
+        case MT_O_X:     aParam1 = "MT_O_X"; break;
+        case MT_POINT_SPRITE: aParam1 = "MT_POINT_SPRITE"; break;
+        default:         aParam1 = "MT_NONE"; break;
+        }
+        switch( aMarkerScale ) {
+        case MS_10:      aParam2 = "MS_10"; break;
+        case MS_15:      aParam2 = "MS_15"; break;
+        case MS_20:      aParam2 = "MS_20"; break;
+        case MS_25:      aParam2 = "MS_25"; break;
+        case MS_30:      aParam2 = "MS_30"; break;
+        case MS_35:      aParam2 = "MS_35"; break;
+        case MS_40:      aParam2 = "MS_40"; break;
+        case MS_45:      aParam2 = "MS_45"; break;
+        case MS_50:      aParam2 = "MS_50"; break;
+        case MS_55:      aParam2 = "MS_55"; break;
+        case MS_60:      aParam2 = "MS_60"; break;
+        case MS_65:      aParam2 = "MS_65"; break;
+        case MS_70:      aParam2 = "MS_70"; break;
+        default:         aParam2 = "MS_NONE"; break;
+        }
+        if( aMarkerType == MT_POINT_SPRITE )
+          aParam2 = "MS_NONE";
+        theStr<<thePrefix<<theName<<".SetMarkerStd(VISU."<<aParam1<<", VISU."<<aParam2<<")"<<endl;
+      }
+      else {
+        int aMarkerTexture = theServant->GetMarkerTexture();
+        if( aMarkerTexture >= 0 )
+          theStr<<thePrefix<<theName<<".SetMarkerTexture(texture_map["<<aMarkerTexture<<"])"<<endl;
+      }
+    }
   }
 
   //---------------------------------------------------------------------------
@@ -236,7 +283,7 @@ namespace VISU
     SALOMEDS::SObject_var mySObject;
     std::string myName;
 
-    TCreateFromResult(const SALOMEDS::SObject_var& theSObject,
+    TCreateFromResult(const SALOMEDS::SObject_ptr theSObject,
                      VISU::ColoredPrs3d_i* theServant,
                      const std::string& theName,
                      const std::string& theConstructorName,
@@ -244,9 +291,10 @@ namespace VISU
       myServant(theServant),
       myConstructorName(theConstructorName),
       myArgumentName(theArgumentName),
-      mySObject(theSObject),
       myName(theName)
-    {}
+    {
+      mySObject = SALOMEDS::SObject::_duplicate(theSObject);
+    }
 
     virtual
     std::string
@@ -441,6 +489,28 @@ namespace VISU
     theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
     theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
 
+    switch(theServant->GetGaussMetric()){
+    case AVERAGE:
+      aParam = "VISU.AVERAGE";
+      break;
+    case MINIMUM:
+      aParam = "VISU.MINIMUM";
+      break;
+    case MAXIMUM:
+      aParam = "VISU.MAXIMUM";
+      break;
+    }
+    theStr<<thePrefix<<theName<<".SetGaussMetric("<<aParam<<")"<<endl;
+
+    SALOMEDS::Color aColor = theServant->GetLinkColor();
+    theStr<<thePrefix<<theName<<".SetLinkColor(SALOMEDS.Color("<<
+      aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
+
+    if(theServant->IsRangeFixed())
+      theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
+    else
+      theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
+
     return thePrefix;
   }
 
@@ -764,6 +834,31 @@ namespace VISU
   }
 
 
+  //---------------------------------------------------------------------------
+  std::string
+  CutSegmentToPython(SALOMEDS::SObject_ptr theSObject,
+                    VISU::CutSegment_i* theServant,
+                    std::ostream& theStr,
+                    const std::string& theName,
+                    TColoredPrs3dFactory& thePrsFactory,
+                    std::string thePrefix)
+  {
+    thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
+    theStr<<thePrefix<<endl;
+
+    double x1, y1, z1, x2, y2, z2;
+    theServant->GetPoint1(x1, y1, z1);
+    theServant->GetPoint2(x2, y2, z2);
+    theStr<<thePrefix<<theName<<".SetPoint1("<<x1<<", "<<y1<<", "<<z1<<")"<<endl;
+    theStr<<thePrefix<<theName<<".SetPoint2("<<x2<<", "<<y2<<", "<<z2<<")"<<endl;
+
+    CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
+    theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
+
+    return thePrefix;
+  }
+
+
   //---------------------------------------------------------------------------
   std::string
   Plot3DToPython(SALOMEDS::SObject_ptr theSObject,
@@ -843,7 +938,9 @@ namespace VISU
     }
 
     std::string aSObjectName = GetName(theSObject);
-    theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
+    if(theArgumentName.empty())
+      theArgumentName = "aSComponent";
+    theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject("<<theArgumentName<<")"<<endl;
     theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
     thePrefix += PREFIX;
 
@@ -865,7 +962,7 @@ namespace VISU
     CORBA::Long aNbRows = theTableAttr->GetNbRows();
 
     // push values and their indices into streams
-    strstream values, rows, columns;
+    stringstream values, rows, columns;
     string comma = "";
     for(CORBA::Long i = 1; i <= aNbColumns; i++){
       for(CORBA::Long j = aNbRows; j > 0; j--){
@@ -879,7 +976,7 @@ namespace VISU
       }
     }
     // push titles and units into streams
-    strstream rowUnits, rowTitles, colTitles;
+    stringstream rowUnits, rowTitles, colTitles;
     SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
     SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
     comma = "";
@@ -1358,6 +1455,25 @@ namespace VISU
            theStr<<thePrefix<<"pass"<<endl<<endl;
           }
           return;
+        case VISU::TCUTSEGMENT:
+          if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(GetServant(anObj).in())){
+           TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutSegmentOnField", theArgumentName);
+           thePrefix = CutSegmentToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
+
+           theArgumentName = aName;
+           DumpChildrenToPython(theStudy,
+                                theIsPublished,
+                                theIsValidScript,
+                                theSObject,
+                                theStr,
+                                theName2EntryMap,
+                                theEntry2NameMap,
+                                theArgumentName,
+                                thePrefix);
+
+           theStr<<thePrefix<<"pass"<<endl<<endl;
+          }
+          return;
         case VISU::TPLOT3D:
           if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
            TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
@@ -1448,16 +1564,21 @@ namespace VISU
           if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
           {
            bool withZ = aServant->GetZRow()>0;
+            bool isV2 = aServant->GetIsV2();
              
            theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
-           if( withZ )
+           if( isV2 )
+             theStr << "WithZExt";
+           else if( withZ )
              theStr << "WithZ";
            theStr << "(" <<
               theArgumentName<< // table
-                ", "<<aServant->GetHRow()<< // H row
-                  ", "<<aServant->GetVRow(); // V row
-           if( withZ )
+              ", "<<aServant->GetHRow()<< // H row
+              ", "<<aServant->GetVRow(); // V row
+           if( withZ || isV2 )
              theStr << ", " << aServant->GetZRow(); // Z row
+           if( isV2 )
+             theStr << ", " << aServant->GetIsV2(); // right axis
 
            theStr << ", '"<<aServant->GetTitle()<<"'"; // title
            SALOMEDS::Color aColor = aServant->GetColor();
@@ -1592,8 +1713,17 @@ namespace VISU
          if (aTypeName == "ImportTables") {
            QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
            if(anIsExist){
-             std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
-             theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.toLatin1().data()<<"')"<<endl;
+             std::string aName =
+                GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
+              QString aFirstStrAsTitle =
+                VISU::Storable::FindValue(aMap,"myFirstStrAsTitle",&anIsExist).trimmed().toLower();
+             if ( aFirstStrAsTitle == "1" || aFirstStrAsTitle == "true" )
+               aFirstStrAsTitle = "True";
+             else
+               aFirstStrAsTitle = "False";
+             theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"
+                    <<aFileName.toLatin1().data()<<"',"
+                    <<aFirstStrAsTitle.toLatin1().data()<<")"<<endl;
              theStr<<thePrefix<<"if "<<aName<<":"<<endl;
              thePrefix += PREFIX;
 
@@ -1898,6 +2028,11 @@ namespace VISU
                    CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
                    break;
                  }
+               case VISU::TCUTSEGMENT:
+                 if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(aDevice)){
+                   CutSegmentToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
+                   break;
+                 }
                case VISU::TPLOT3D:
                  if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
                    Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
@@ -1921,6 +2056,94 @@ namespace VISU
   }
 
     
+  //---------------------------------------------------------------------------
+  void
+  DumpEvolutionsToPython(SALOMEDS::Study_ptr theStudy,
+                         CORBA::Boolean theIsPublished,
+                         CORBA::Boolean& theIsValidScript,
+                         SALOMEDS::SObject_ptr theSObject,
+                         std::ostream& theStr,
+                         TName2EntryMap& theName2EntryMap,
+                         TEntry2NameMap& theEntry2NameMap,
+                         std::string thePrefix)
+  {
+    if(!theIsPublished) return;
+
+    SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
+    for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
+      SALOMEDS::SObject_var aSObject = aChildItet->Value();
+          
+      SALOMEDS::GenericAttribute_var anAttr;
+      if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
+      
+      SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
+      QString value (aStringAttr->Value());
+      if(value.isEmpty()) continue;
+
+      VISU::Storable::TRestoringMap aMap;
+      VISU::Storable::StringToMap(value, aMap);
+      bool isExist;
+      
+      QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
+      if(!isExist || aTypeName != "EVOLUTION") continue;
+
+      //EVOLUTION
+      theStr<<thePrefix<<endl;
+      QString evolutionName = aSObject->GetName();
+      theStr<<thePrefix<<"#Evolution: "<<evolutionName.toLatin1().data()<<endl;
+      theStr<<thePrefix<<endl;
+      theStr<<thePrefix<<"evolutionSO = aBuilder.NewObject(aSComponent)"<<endl;
+      theStr<<thePrefix<<"aBuilder.SetName(evolutionSO, '"<<evolutionName.toLatin1().data()<<"')"<< endl;
+      theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(evolutionSO, 'AttributeString')"<< endl;
+      theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
+
+      SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
+      for (anIter->Init(); anIter->More(); anIter->Next()) {
+        SALOMEDS::SObject_var anObj = anIter->Value();
+
+        //FIELD
+        theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(evolutionSO)"<<endl;
+        if (anObj->FindAttribute(anAttr, "AttributeString")) {
+          aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
+          theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
+          theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
+        }
+       
+        SALOMEDS::SObject_var refObj;
+        if(anObj->ReferencedObject(refObj)) {
+          SALOMEDS::SObject_var father = refObj->GetFather();
+          value = refObj->GetName();
+          QString path(theStudy->GetObjectPath(father));
+          //The following code requierd as a field name can contain '/' character
+          theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
+        }
+        value = anObj->GetName();
+        if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
+
+        //TABLE
+        SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(anObj);
+        for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
+          SALOMEDS::SObject_var aSObject = aChildItet->Value();
+
+          std::string anArgumentName = "fieldSO";
+          DumpTableAttrToPython(theStudy,
+                                theIsPublished,
+                                theIsValidScript,
+                                aSObject,
+                                theStr,
+                                theName2EntryMap,
+                                theEntry2NameMap,
+                                anArgumentName,
+                                thePrefix);
+        }
+      }
+      
+    }
+
+    theStr<<thePrefix<<endl;
+  }
+
+
   //---------------------------------------------------------------------------
   void
   DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
@@ -2037,11 +2260,44 @@ namespace VISU
   }  
 
 
+  void
+  DumpTextureMapToPython(SALOMEDS::Study_ptr theStudy,
+                         CORBA::Boolean theIsPublished,
+                         CORBA::Boolean& theIsValidScript,
+                         SALOMEDS::SObject_ptr theSObject,
+                         std::ostream& theStr,
+                         std::string thePrefix,
+                         const StudyId2MarkerMap& theMarkerMap)
+  {
+    if(!theIsPublished)
+      return;
+
+    if(CORBA::is_nil(theStudy))
+      return;
+
+    StudyId2MarkerMap::const_iterator anIter = theMarkerMap.find(theStudy->StudyId());
+    if(anIter == theMarkerMap.end())
+      return;
+
+    theStr<<thePrefix<<"texture_map = {}"<<endl<<endl;
+
+    const VTK::MarkerMap& aMarkerMap = anIter->second;
+    VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
+    for(; aMarkerIter != aMarkerMap.end(); aMarkerIter++) {
+      int aMarkerId = aMarkerIter->first;
+      std::string aMarkerTexture = aMarkerIter->second.first;
+      theStr<<thePrefix<<"texture_map["<<aMarkerId<<"] = aVisu.LoadTexture(\""<<aMarkerTexture<<"\")"<<endl;
+    }
+    theStr<<endl;
+  }  
+
+
   //---------------------------------------------------------------------------
   Engines::TMPFile*
   VISU_Gen_i::
   DumpPython(CORBA::Object_ptr theStudy,
             CORBA::Boolean theIsPublished,
+            CORBA::Boolean theIsMultiFile,
             CORBA::Boolean& theIsValidScript)
   {
     theIsValidScript = false;
@@ -2059,16 +2315,17 @@ namespace VISU
 #define aStr cout
 #endif
 
-    std::string aPrefix(PREFIX);
-    aStr<<"### This file is generated by SALOME automatically by dump python functionality"
-      " of VISU component"<<endl<<endl;
-    aStr<<"def RebuildData(theStudy):"<<endl;
+    std::string aPrefix = theIsMultiFile ? PREFIX : "";
+    if( theIsMultiFile )
+      aStr<<"def RebuildData(theStudy):"<<endl;
     aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
     aStr<<aPrefix<<"import SALOME_MED"<<endl;
     aStr<<aPrefix<<"import SALOMEDS"<<endl;
     aStr<<aPrefix<<"import VISU"<<endl;
     aStr<<aPrefix<<"import visu"<<endl;
     aStr<<endl;
+    if( !theIsMultiFile )
+      aStr<<"theStudy = salome.myStudy"<<endl;
     aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
     aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
     aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
@@ -2086,6 +2343,13 @@ namespace VISU
                                     aPrefix, 
                                     myClippingPlaneMgr);
 
+    VISU::DumpTextureMapToPython(aStudy,
+                                 theIsPublished,
+                                 theIsValidScript,
+                                 aComponent.in(),
+                                 aStr,
+                                 aPrefix,
+                                 myMarkerMap);
 
     VISU::DumpChildrenToPython(aStudy,
                               theIsPublished,
@@ -2097,6 +2361,15 @@ namespace VISU
                               "",
                               aPrefix);
 
+    VISU::DumpEvolutionsToPython(aStudy,
+                                theIsPublished,
+                                theIsValidScript,
+                                aComponent.in(),
+                                aStr,
+                                aName2EntryMap,
+                                aEntry2NameMap,
+                                aPrefix);
+
     VISU::DumpContainersToPython(aStudy,
                                 theIsPublished,
                                 theIsValidScript,
@@ -2134,10 +2407,13 @@ namespace VISU
       }
     }
 
-    aStr<<aPrefix<<"pass"<<endl;
+    if( theIsMultiFile )
+      aStr<<aPrefix<<"pass"<<endl;
 
     if(theIsPublished) { //SRN: define function for Animation
 
+      aPrefix = PREFIX;
+
       //Define a function that find a SObject by its father's path and its name
       aStr<<endl;
       aStr<<endl;