Salome HOME
another z layer for hilight presentation
[modules/hydro.git] / src / HYDROData / HYDROData_Profile.cxx
index 03c6ba856d899438800d28680cc2ddc9b5ee8e71..76dfad84e4cbe97516c276d931b1c9133e19db9c 100755 (executable)
@@ -43,8 +43,76 @@ HYDROData_Profile::~HYDROData_Profile()
 QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
+  QString aProfileName = GetObjPyName();
 
-  //TODO
+  //TCollection_AsciiString aFilePath = GetFilePath();
+  //if ( !aFilePath.IsEmpty() ) 
+  //{
+  //  aResList << QString( "%1.ImportFromFile( \"%2\" );" )
+  //            .arg( aName ).arg( aFilePath.ToCString() );
+  //}
+
+  bool anIsValidProfile = IsValid();
+  
+  QStringList aPntsDefinition;
+  QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
+
+  QString aGap = QString().fill( ' ', aPntsListName.length() + 5 );
+  if ( anIsValidProfile )
+  {
+    HYDROData_Profile::ProfilePoints aPointsList = GetProfilePoints();
+    for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
+    {
+      const ProfilePoint& aPoint = aPointsList.Value( k );
+      aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
+                         .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
+                         .arg( ( k < aNbPoints ? "," : "" ) );
+    }
+  }
+  else
+  {
+    HYDROData_IPolyline::PointsList aPointsList = GetParametricPoints();
+    for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
+    {
+      const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
+      aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
+                         .arg( aPoint.X() ).arg( aPoint.Y() )
+                         .arg( ( k < aNbPoints ? "," : "" ) );
+    }
+  }
+
+  if ( !aPntsDefinition.isEmpty() )
+  {
+    QString& aFirstStr = aPntsDefinition.first();
+    aFirstStr = aFirstStr.trimmed();
+    aFirstStr.prepend( QString( "%1 = [ " ).arg( aPntsListName ) );
+    
+    aPntsDefinition.last().append( " ];" );
+
+    aResList << aPntsDefinition;
+    
+    aResList << QString( "%1.%3( %2 );" )
+                .arg( aProfileName ).arg( aPntsListName )
+                .arg( anIsValidProfile ? "SetProfilePoints" : "SetParametricPoints" );
+  
+    aResList << QString( "" );
+  }
+
+  // Set a polyline type if it is not default
+  Handle(HYDROData_ProfileUZ) aPrf = GetProfileUZ( false );
+  if ( !aPrf.IsNull() )
+  {
+    HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
+    if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
+    {
+      aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 );" )
+                  .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
+      aResList << QString( "" );
+    }
+  }
+
+  aResList << QString( "%1.Update();" ).arg( aProfileName );
+  aResList << QString( "" );
 
   return aResList;
 }