#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 <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;
+ QStringList aResList = dumpObjectCreation( theTreatedObjects );
+ QString aProfileName = GetObjPyName();
+
+ //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( "" );
+ }
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
- if ( aDocument.IsNull() )
- return aResList;
-
- QString aDocName = aDocument->GetDocPyName();
- QString aProfileName = GetName();
+ // 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 = %2.CreateObject( %3 );" )
- .arg( aProfileName ).arg( aDocName ).arg( PYTHON_PROFILE_ID );
- aResList << QString( "%1.SetName( \"%1\" );" ).arg( aProfileName );
+ aResList << QString( "%1.Update();" ).arg( aProfileName );
+ aResList << QString( "" );
return aResList;
}
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 );