Salome HOME
refs #430: incorrect coordinates in dump polyline
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineXY.cxx
index d40212e22a6018b713445af69ae6d516bb7512c7..9711309a883a4a7c50f99e675f1a9dfab909b87c 100755 (executable)
@@ -164,8 +164,10 @@ QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedO
       {
         const Point& aSectPoint = aSectPointsList.Value( k );
 
+        QString anXStr = QString::number( aSectPoint.X(), 'f', 2 );
+        QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 );
         aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName )
-          .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
+          .arg( i - 1 ).arg( anXStr ).arg( anYStr );
       }
     }
   }
@@ -389,14 +391,15 @@ TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType&
   TopoDS_Wire aWire;
   if( theType == SECTION_POLYLINE )
   {
+    int aNbPoints = thePoints.Length();
     BRepBuilderAPI_MakePolygon aMakeWire;
-    for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
+    for ( int i = 1, n = aNbPoints; i <= n ; ++i )
     {
       gp_XYZ aPoint = thePoints.Value( i );
       gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
       aMakeWire.Add( aPnt );
     }
-    if( theIsClosed )
+    if( theIsClosed && ( aNbPoints > 2 ) )
       aMakeWire.Close();
 
     if ( aMakeWire.IsDone() )
@@ -537,6 +540,11 @@ void HYDROData_PolylineXY::Update()
   setPolylineShape( aResult );
 }
 
+bool HYDROData_PolylineXY::IsHas2dPrs() const
+{
+  return true;
+}
+
 bool HYDROData_PolylineXY::IsEditable() const
 {
   return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
@@ -1096,4 +1104,26 @@ QPainterPath HYDROData_PolylineXY::GetPainterPath() const
   return aPath;
 }
 
+void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
+{
+  NCollection_Sequence<TCollection_AsciiString>           aSectNames;
+  NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
+  NCollection_Sequence<bool>                              aSectClosures;
+  GetSections( aSectNames, aSectTypes, aSectClosures );
+
+  gp_XY aDelta( theDx, theDy );
+  for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
+  {
+    PointsList aPoints = GetPoints( i );
+    for( int j = 1, n = aPoints.Size(); j <= n; ++j )
+    {
+      Point& aPoint = aPoints.ChangeValue( j );
+      aPoint += aDelta;
+    }
+    SetPoints( i, aPoints );
+  }
+  SetToUpdate( true );
+}
+
+