#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>
+#include <BRepBuilderAPI_MakePolygon.hxx>
#include <gp_XY.hxx>
#include <gp_XYZ.hxx>
#include <QColor>
#include <QStringList>
-#define PYTHON_PROFILE_ID "KIND_PROFILE"
-
IMPLEMENT_STANDARD_HANDLE(HYDROData_Profile, HYDROData_Object)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object)
QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
{
- QStringList aResList;
-
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
- if ( aDocument.IsNull() )
- return aResList;
-
- QString aDocName = aDocument->GetDocPyName();
- QString aProfileName = GetName();
+ QStringList aResList = dumpObjectCreation( theTreatedObjects );
- aResList << QString( "%1 = %2.CreateObject( %3 );" )
- .arg( aProfileName ).arg( aDocName ).arg( PYTHON_PROFILE_ID );
- aResList << QString( "%1.SetName( \"%1\" );" ).arg( aProfileName );
+ //TODO
return aResList;
}
{
HYDROData_Object::Update();
- BRepBuilderAPI_MakeWire aMakeWire;
-
- ProfilePoints aProfilePoints = GetProfilePoints();
- for ( int i = 1, n = aProfilePoints.Length(); i < n ; ++i )
+ TopoDS_Wire aWire;
+ 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 );
}
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() )
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() )
if ( !aFile.IsOpen() )
return false;
- bool aRes = ImportFromFile( aFile );
+ bool aRes = ImportFromFile( aFile, theIsRead );
// Close the file
aFile.Close();
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;
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 );
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 )
}
double aCoordZ = aValZ.RealValue();
+ if ( boost::math::isnan( aCoordZ ) || boost::math::isinf( aCoordZ ) )
+ aRes = false;
ProfilePoint aPoint( aCoordX, aCoordY, aCoordZ );
aPointsXYZ.Append( aPoint );