#include <gp_XY.hxx>
#include <gp_XYZ.hxx>
#include <gp_Pnt2d.hxx>
+#include <gp_Ax3.hxx>
+#include <GeomAPI_ProjectPointOnSurf.hxx>
+#include <Geom_Plane.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TDataStd_RealArray.hxx>
int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
const TCollection_AsciiString& theFileName,
- NCollection_Sequence<int>& theBadProfilesIds )
+ NCollection_Sequence<int>& theBadProfilesIds,
+ bool isToProject )
{
if ( theDoc.IsNull() || theFileName.IsEmpty() )
return 0;
aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) );
bool anIsRead = false;
- if ( aNewProfile->ImportFromFile( aFile, &anIsRead ) )
+ if ( aNewProfile->ImportFromFile( aFile, isToProject, &anIsRead ) )
{
aCreatedProfiles.Append( aNewProfile );
aNewProfile.Nullify();
}
bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName,
- bool* theIsRead )
+ bool isToProject,
+ bool* isNotEmpty )
{
- if ( theIsRead )
- *theIsRead = false;
+ if( isNotEmpty )
+ *isNotEmpty = false;
// Try to open the file
OSD_File aFile( theFileName );
if ( !aFile.IsOpen() )
return false;
- bool aRes = ImportFromFile( aFile, theIsRead );
+ bool aRes = ImportFromFile( aFile, isToProject, isNotEmpty );
// Close the file
aFile.Close();
}
bool HYDROData_Profile::ImportFromFile( OSD_File& theFile,
- bool* theIsRead )
+ bool isToProject,
+ bool* isNotEmpty )
{
- if ( theIsRead )
- *theIsRead = false;
+ if( isNotEmpty )
+ *isNotEmpty = false;
if ( !theFile.IsOpen() )
return false;
}
// Set flag of read status to true
- if ( theIsRead )
- *theIsRead = true;
+ if( isNotEmpty )
+ *isNotEmpty = true;
TCollection_AsciiString aValX = aLine.Token( " \t", 1 );
TCollection_AsciiString aValY = aLine.Token( " \t", 2 );
}
else if ( anIsGeoref )
{
+ if( isToProject )
+ ProjectProfilePoints( aPointsXYZ );
SetProfilePoints( aPointsXYZ, true );
}
}
return aMiddlePoint;
- }
\ No newline at end of file
+ }
+
+void HYDROData_Profile::ProjectProfilePoints( ProfilePoints& thePoints )
+{
+ int low = thePoints.Lower(), up = thePoints.Upper();
+ gp_Pnt aFirst = thePoints.Value( low );
+ gp_Pnt aLast = thePoints.Value( up );
+ gp_Vec d( aFirst, aLast );
+ gp_Vec n( d.Y(), -d.X(), 0 );
+
+ Handle(Geom_Plane) aPlane = new Geom_Plane( aFirst, gp_Dir( n ) );
+ for( int i=low; i<=up; i++ )
+ {
+ gp_XYZ p = thePoints.Value( i );
+ gp_Pnt pp = GeomAPI_ProjectPointOnSurf( p, aPlane );
+ thePoints.SetValue( i, pp.XYZ() );
+ }
+}
*/
HYDRODATA_EXPORT static int ImportFromFile( const Handle(HYDROData_Document)& theDoc,
const TCollection_AsciiString& theFileName,
- NCollection_Sequence<int>& theBadProfilesIds );
+ NCollection_Sequence<int>& theBadProfilesIds,
+ bool isToProject = true );
/**
* Imports Profile data from file.
* \return \c true if file has been successfully read
*/
HYDRODATA_EXPORT virtual bool ImportFromFile( const TCollection_AsciiString& theFileName,
- bool* theIsRead = 0 );
+ bool isToProject = true,
+ bool* isNotEmpty = 0 );
/**
* Imports Profile data from file.
* \return \c true if file has been successfully read
*/
HYDRODATA_EXPORT virtual bool ImportFromFile( OSD_File& theFile,
- bool* theIsRead = 0 );
+ bool isToProject = true,
+ bool* isNotEmpty = 0 );
protected:
/**
TopoDS_Shape CreateProfileWire( bool canUseDefaultPoints ) const;
+ static void ProjectProfilePoints( ProfilePoints& thePoints );
+
protected:
friend class HYDROData_Iterator;
*/
static int ImportFromFile( HYDROData_Document theDoc,
const TCollection_AsciiString& theFileName,
- NCollection_Sequence<int>& theBadProfilesIds )
+ NCollection_Sequence<int>& theBadProfilesIds,
+ bool isToProject = true )
[int ( const Handle_HYDROData_Document&,
const TCollection_AsciiString&,
NCollection_Sequence<int>& )];
%MethodCode
Py_BEGIN_ALLOW_THREADS
- sipRes = HYDROData_Profile::ImportFromFile( a0, *a1, *a2 );
+ sipRes = HYDROData_Profile::ImportFromFile( a0, *a1, *a2, a3 );
Py_END_ALLOW_THREADS
%End
* \return \c true if file has been successfully read
*/
virtual bool ImportFromFile( const TCollection_AsciiString& theFileName,
- bool* theIsRead = 0 );
+ bool isToProject = true,
+ bool* isNotEmpty = 0 );
protected:
/**
--- /dev/null
+1 2 5
+2 4.1 4
+3 5.9 3
+4 8.2 3
+5 9.8 4
+6 12 5
#include <BRepTools.hxx>
-const QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test";
+QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test";
void test_HYDROData_CalcCase::test_add_int_wires()
#define _DEVDEBUG_
#include "HYDRO_trace.hxx"
-const QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test";
+extern QString REF_DATA_PATH;
const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt";
void test_HYDROData_LandCoverMap::test_add_2_objects()
#include <QDir>
#include <QFile>
#include <QTextStream>
+#include <QString>
const double EPS = 1E-2;
+extern QString REF_DATA_PATH;
bool test_HYDROData_Profile::createTestFile( const QString& theFileName,
const bool theIsParametric )
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() );
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();
+}
class test_HYDROData_Profile : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(test_HYDROData_Profile);
- CPPUNIT_TEST(testFileImport);
- CPPUNIT_TEST(testCopy);
+ CPPUNIT_TEST( testFileImport );
+ CPPUNIT_TEST( testCopy );
+ CPPUNIT_TEST( testProjection );
CPPUNIT_TEST_SUITE_END();
private:
// checks the copy/paste mechanism
void testCopy();
+ void testProjection();
};
CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Profile);