Salome HOME
Bug #334: Different behavior in Edit calculation case input panel.
[modules/hydro.git] / src / HYDROData / HYDROData_Profile.cxx
index 6d0d68571bebd1c3266ae42f8c4c29681583de53..76dfad84e4cbe97516c276d931b1c9133e19db9c 100755 (executable)
@@ -43,21 +43,7 @@ HYDROData_Profile::~HYDROData_Profile()
 QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
-  QString aName = GetObjPyName();
-
-  QColor aFillingColor = GetFillingColor();
-  aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
-              .arg( aFillingColor.red()  ).arg( aFillingColor.green() )
-              .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
-  aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aName );
-  aResList << QString( "" );
-
-  QColor aBorderColor = GetBorderColor();
-  aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
-              .arg( aBorderColor.red()  ).arg( aBorderColor.green() )
-              .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
-  aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aName );
-  aResList << QString( "" );
+  QString aProfileName = GetObjPyName();
 
   //TCollection_AsciiString aFilePath = GetFilePath();
   //if ( !aFilePath.IsEmpty() ) 
@@ -66,22 +52,22 @@ QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObje
   //            .arg( aName ).arg( aFilePath.ToCString() );
   //}
 
-  bool isValid = IsValid();
-  QString aGap = QString().fill( ' ', 11 );
+  bool anIsValidProfile = IsValid();
   
-  aResList << QString( "points = [" );
+  QStringList aPntsDefinition;
+  QString aPntsListName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "profile_points" );
 
-  if ( isValid )
+  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 );
-      aResList << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" ).arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
-        .arg( ( k < aNbPoints ? "," : "" ) );
+      aPntsDefinition << QString( aGap + "gp_XYZ( %1, %2, %3 )%4" )
+                         .arg( aPoint.X() ).arg( aPoint.Y() ).arg( aPoint.Z() )
+                         .arg( ( k < aNbPoints ? "," : "" ) );
     }
-    aResList << QString( "];" );
-    aResList << QString( "%1.SetProfilePoints( points );" ).arg( aName );
   }
   else
   {
@@ -89,11 +75,27 @@ QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObje
     for ( int k = 1, aNbPoints = aPointsList.Size(); k <= aNbPoints; ++k )
     {
       const HYDROData_IPolyline::Point& aPoint = aPointsList.Value( k );
-      aResList << QString( aGap + "gp_XY( %1, %2 )%3" ).arg( aPoint.X() ).arg( aPoint.Y() )
-        .arg( ( k < aNbPoints ? "," : "" ) );
+      aPntsDefinition << QString( aGap + "gp_XY( %1, %2 )%3" )
+                         .arg( aPoint.X() ).arg( aPoint.Y() )
+                         .arg( ( k < aNbPoints ? "," : "" ) );
     }
-    aResList << QString( "];" );
-    aResList << QString( "%1.SetParametricPoints( points )" ).arg( aName );
+  }
+
+  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
@@ -103,13 +105,13 @@ QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObje
     HYDROData_IPolyline::SectionType aSecType = aPrf->GetSectionType( 0 );
     if ( aSecType != HYDROData_IPolyline::SECTION_POLYLINE )
     {
-      aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 );" ).arg( aName )
-        .arg( "HYDROData_IPolyline.SECTION_SPLINE" );
+      aResList << QString( "%1.GetProfileUZ().SetSectionType( 0, %2 );" )
+                  .arg( aProfileName ).arg( "HYDROData_IPolyline.SECTION_SPLINE" );
+      aResList << QString( "" );
     }
   }
 
-  aResList << QString( "" );
-  aResList << QString( "%1.Update();" ).arg( aName );
+  aResList << QString( "%1.Update();" ).arg( aProfileName );
   aResList << QString( "" );
 
   return aResList;