#include <QDir>
#include <QFile>
#include <QTextStream>
+#include <QString>
+
+const double EPS = 1E-2;
+extern QString REF_DATA_PATH;
+extern QString TMP_DIR;
bool test_HYDROData_Profile::createTestFile( const QString& theFileName,
const bool theIsParametric )
{
Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
- QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa";
- QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
+ QString aParamFileName = TMP_DIR + QDir::separator() + "parametric.pa";
+ QString aGeorefFileName = TMP_DIR + QDir::separator() + "georef.pa";
if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) )
return; // No file has been created
TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() );
NCollection_Sequence<int> aBadProfilesList;
- CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList ) );
+ CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, true ) );
int aProfileCount = 0;
HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE );
Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() );
- CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) );
+ bool notEmpty = false;
+ CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName, true, ¬Empty ) );
+ CPPUNIT_ASSERT( notEmpty );
// Check validity of imported profile
CPPUNIT_ASSERT( aGeorefProfile->IsValid() );
CPPUNIT_ASSERT( aProfilePoints.Length() == 5 );
HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 );
- CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.X(), 1040509.21 ) );
- CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Y(), 6788619.81 ) );
- CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Z(), 181.63 ) );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.X(), 1040509.21, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.Y(), 6788619.81, EPS );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.Z(), 181.63, EPS );
aDoc->Close();
}
Handle(HYDROData_Profile) aProfile1 =
Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
- QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
+ QString aFileName = TMP_DIR + QDir::separator() + "georef.pa";
bool anIsFileCreated = createTestFile( aFileName, false );
if ( anIsFileCreated )
{
+ bool notEmpty = false;
TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() );
- CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) );
+ CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName, true, ¬Empty ) );
+ CPPUNIT_ASSERT( notEmpty );
CPPUNIT_ASSERT( aProfile1->IsValid() );
CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 );
aDoc->Close();
}
+
+void operator << ( std::ostream& s, const gp_XYZ& p )
+{
+ s << "(" << p.X() << "; " << p.Y() << "; " << p.Z() << ") ";
+}
+
+bool operator == ( const gp_XYZ& p1, const gp_XYZ& p2 )
+{
+ return fabs(p1.X()-p2.X())<EPS && fabs(p1.Y()-p2.Y())<EPS && fabs(p1.Z()-p2.Z())<EPS;
+}
+
+void test_HYDROData_Profile::testProjection()
+{
+ std::string aPath = ( REF_DATA_PATH+"/profiles1.xyz" ).toStdString();
+
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+
+ TCollection_AsciiString aFileName( aPath.c_str() );
+ NCollection_Sequence<int> aBadProfilesList;
+ CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, false ) );
+ CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, true ) );
+
+ HYDROData_Iterator it( aDoc, KIND_PROFILE );
+ CPPUNIT_ASSERT( it.More() );
+ Handle(HYDROData_Profile) p1 = Handle(HYDROData_Profile)::DownCast( it.Current() ); it.Next();
+ CPPUNIT_ASSERT( it.More() );
+ Handle(HYDROData_Profile) p2 = Handle(HYDROData_Profile)::DownCast( it.Current() ); it.Next();
+ CPPUNIT_ASSERT( !it.More() );
+
+ CPPUNIT_ASSERT_EQUAL( QString( "Profile_1" ), p1->GetName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "Profile_2" ), p2->GetName() );
+
+ HYDROData_Profile::ProfilePoints pp1 = p1->GetProfilePoints();
+ int low1 = pp1.Lower(), up1 = pp1.Upper();
+ CPPUNIT_ASSERT_EQUAL( 1, low1 );
+ CPPUNIT_ASSERT_EQUAL( 6, up1 );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 1.0, 2.0, 5.0 ), pp1.Value( 1 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.04019, 4.0838, 4.0 ), pp1.Value( 2 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.9601, 5.9202, 3.0 ), pp1.Value( 3 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.08026, 8.16052, 3.0 ), pp1.Value( 4 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.9202, 9.84041, 4.0 ), pp1.Value( 5 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 6.0, 12.0, 5.0 ), pp1.Value( 6 ) );
+
+ HYDROData_Profile::ProfilePoints pp2 = p2->GetProfilePoints();
+ int low2 = pp2.Lower(), up2 = pp2.Upper();
+ CPPUNIT_ASSERT_EQUAL( 1, low2 );
+ CPPUNIT_ASSERT_EQUAL( 6, up2 );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 1.0, 2.0, 5.0 ), pp2.Value( 1 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.04019, 4.0838, 4.0 ), pp2.Value( 2 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.9601, 5.9202, 3.0 ), pp2.Value( 3 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.08, 8.16, 3.0 ), pp2.Value( 4 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.92, 9.84, 4.0 ), pp2.Value( 5 ) );
+ CPPUNIT_ASSERT_EQUAL( gp_XYZ( 6.0, 12.0, 5.0 ), pp2.Value( 6 ) );
+
+ aDoc->Close();
+}