Salome HOME
NCollection sequences improved.
[modules/hydro.git] / src / HYDROData / HYDROData_Profile.cxx
index f970509e255594371801463ab7ba79218b6f0673..03c6ba856d899438800d28680cc2ddc9b5ee8e71 100755 (executable)
@@ -4,6 +4,9 @@
 #include "HYDROData_Document.h"
 #include "HYDROData_Iterator.h"
 #include "HYDROData_Tool.h"
+#include "HYDROData_PolylineXY.h"
+
+#include <boost/math/special_functions/fpclassify.hpp>
 
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
@@ -25,8 +28,6 @@
 #include <QColor>
 #include <QStringList>
 
-#define PYTHON_PROFILE_ID "KIND_PROFILE"
-
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Profile, HYDROData_Object)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
 
@@ -41,18 +42,9 @@ HYDROData_Profile::~HYDROData_Profile()
 
 QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
 {
-  QStringList aResList;
+  QStringList aResList = dumpObjectCreation( theTreatedObjects );
 
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
-  if ( aDocument.IsNull() )
-    return aResList;
-                             
-  QString aDocName = aDocument->GetDocPyName();
-  QString aProfileName = GetName();
-
-  aResList << QString( "%1 = %2.CreateObject( %3 );" )
-              .arg( aProfileName ).arg( aDocName ).arg( PYTHON_PROFILE_ID );
-  aResList << QString( "%1.SetName( \"%1\" );" ).arg( aProfileName );
+  //TODO
 
   return aResList;
 }
@@ -86,41 +78,15 @@ void HYDROData_Profile::Update()
 {
   HYDROData_Object::Update();
 
-  BRepBuilderAPI_MakePolygon aMakeWire;
-
-  ProfilePoints aProfilePoints = GetProfilePoints();
-  for ( int i = 1, n = aProfilePoints.Length(); i <= n ; ++i )
-  {
-    ProfilePoint aPoint = aProfilePoints.Value( i );
-    gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
-    aMakeWire.Add( aPnt );
-  }
-
   TopoDS_Wire aWire;
-  if ( aMakeWire.IsDone() )
-    aWire = aMakeWire.Wire();
-
-  /*BRepBuilderAPI_MakeWire aMakeWire;
-
-  ProfilePoints aProfilePoints = GetProfilePoints();
-  for ( int i = 1, n = aProfilePoints.Length(); i < n ; ++i )
+  Handle(HYDROData_ProfileUZ) aProfile = GetProfileUZ( false );
+  if ( !aProfile.IsNull() )
   {
-    ProfilePoint aFirstPoint = aProfilePoints.Value( i );
-    ProfilePoint aSecPoint = aProfilePoints.Value( i + 1 );
-
-    gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z() );
-    gp_Pnt aPnt2( aSecPoint.X(),   aSecPoint.Y(),   aSecPoint.Z()   );
+    ProfilePoints aProfilePoints = GetProfilePoints();
+    HYDROData_IPolyline::SectionType aSectionType = aProfile->GetSectionType( 0 );
 
-    BRepBuilderAPI_MakeEdge aMakeEdge( aPnt1, aPnt2 );
-    TopoDS_Edge anEdge = aMakeEdge;
-
-    aMakeWire.Add( anEdge );
+    aWire = HYDROData_PolylineXY::BuildWire( aSectionType, false, aProfilePoints );
   }
-
-  TopoDS_Wire aWire;
-  if ( aMakeWire.IsDone() )
-    aWire = aMakeWire;*/
-
   SetShape3D( aWire );
 }
 
@@ -371,33 +337,40 @@ TCollection_AsciiString HYDROData_Profile::GetFilePath() const
   return aRes;
 }
 
-bool HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
-                                        const TCollection_AsciiString&    theFileName )
+int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
+                                       const TCollection_AsciiString&    theFileName,
+                                       NCollection_Sequence<int>&        theBadProfilesIds )
 {
   if ( theDoc.IsNull() || theFileName.IsEmpty() )
-    return false;
+    return 0;
 
   OSD_File aFile( theFileName );
   if ( !aFile.IsReadable() )
-    return false;
+    return 0;
 
   aFile.Open( OSD_ReadOnly, OSD_Protection() );
   if ( !aFile.IsOpen() )
-    return false;
+    return 0;
 
   NCollection_Sequence<Handle(HYDROData_Profile)> aCreatedProfiles;
 
+  int aProfileId = 1;
   Handle(HYDROData_Profile) aNewProfile;
-  while ( !aFile.IsAtEnd() )
+  for ( ; !aFile.IsAtEnd(); ++aProfileId )
   {
     if ( aNewProfile.IsNull() )
       aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
     
-    if ( aNewProfile->ImportFromFile( aFile ) )
+    bool anIsRead = false;
+    if ( aNewProfile->ImportFromFile( aFile, &anIsRead ) )
     {
       aCreatedProfiles.Append( aNewProfile );
       aNewProfile.Nullify();
     }
+    else if ( anIsRead )
+    {
+      theBadProfilesIds.Append( aProfileId );
+    }
   }
 
   if ( !aNewProfile.IsNull() )
@@ -418,11 +391,15 @@ bool HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc
     aProfile->SetBorderColor( HYDROData_Profile::DefaultBorderColor() );
   }
 
-  return !aCreatedProfiles.IsEmpty();
+  return aCreatedProfiles.Length();
 }
 
-bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName )
+bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
+                                        bool*                          theIsRead )
 {
+  if ( theIsRead )
+    *theIsRead = false;
+
   // Try to open the file
   OSD_File aFile( theFileName );
   if ( !aFile.IsReadable() )
@@ -432,7 +409,7 @@ bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileNa
   if ( !aFile.IsOpen() )
     return false;
 
-  bool aRes = ImportFromFile( aFile );
+  bool aRes = ImportFromFile( aFile, theIsRead );
 
   // Close the file
   aFile.Close();
@@ -446,8 +423,12 @@ bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileNa
   return aRes;
 }
 
-bool HYDROData_Profile::ImportFromFile( OSD_File& theFile )
+bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
+                                        bool*     theIsRead )
 {
+  if ( theIsRead )
+    *theIsRead = false;
+
   if ( !theFile.IsOpen() )
     return false;
 
@@ -475,6 +456,10 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile )
       break; // Next profile started
     }
 
+    // Set flag of read status to true
+    if ( theIsRead )
+      *theIsRead = true;
+
     TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
     TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
     TCollection_AsciiString aValZ = aLine.Token( " \t", 3 );
@@ -495,6 +480,10 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile )
     double aCoordX = aValX.RealValue();
     double aCoordY = aValY.RealValue();
 
+    if ( boost::math::isnan( aCoordX ) || boost::math::isinf( aCoordX ) ||
+         boost::math::isnan( aCoordY ) || boost::math::isinf( aCoordY ) )
+      aRes = false;
+
     if ( anIsParametric )
     {
       if ( aCoordX < aPrevVal )
@@ -518,6 +507,8 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile )
       }
 
       double aCoordZ = aValZ.RealValue();
+      if ( boost::math::isnan( aCoordZ ) || boost::math::isinf( aCoordZ ) )
+        aRes = false;
 
       ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
       aPointsXYZ.Append( aPoint );