1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <test_HYDROData_Profile.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_Tool.h>
23 #include <HYDROData_Profile.h>
24 #include <HYDROData_Iterator.h>
26 #include <TopoDS_Shape.hxx>
33 #include <QTextStream>
35 const double EPS = 1E-2;
37 bool test_HYDROData_Profile::createTestFile( const QString& theFileName,
38 const bool theIsParametric )
40 QFile aTmpFile( theFileName );
41 if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
44 if ( theIsParametric )
46 QTextStream anOutStream( &aTmpFile );
48 anOutStream << "0 182.15 \n";
49 anOutStream << "4 181.95 \n";
50 anOutStream << "10.18 181.63 \n";
51 anOutStream << "14.75 179.27 \n";
52 anOutStream << "19.75 178.87 \n";
56 anOutStream << "-5 50 \n";
57 anOutStream << "0 15 \n";
58 anOutStream << "10.1 10 \n";
59 anOutStream << "20 20 \n";
60 anOutStream << "250 0.005 \n";
64 QTextStream anOutStream( &aTmpFile );
66 anOutStream << "1040499.17 6788618.13 182.15 \n";
67 anOutStream << "1040503.12 6788618.79 181.95 \n";
68 anOutStream << "1040509.21 6788619.81 181.63 \n";
69 anOutStream << "1040513.72 6788620.56 179.27 \n";
70 anOutStream << "1040518.65 6788621.38 178.87 \n";
78 void test_HYDROData_Profile::testFileImport()
80 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
82 QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa";
83 QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
84 if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) )
85 return; // No file has been created
87 TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() );
89 NCollection_Sequence<int> aBadProfilesList;
90 CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList ) );
92 int aProfileCount = 0;
93 HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE );
94 for ( ; aDocIter.More(); aDocIter.Next() )
96 Handle(HYDROData_Profile) aProfile =
97 Handle(HYDROData_Profile)::DownCast( aDocIter.Current() );
98 if ( aProfile.IsNull() )
101 CPPUNIT_ASSERT( aProfile->IsValid() == false );
102 CPPUNIT_ASSERT( aProfile->NbPoints() == 5 );
107 CPPUNIT_ASSERT( aProfileCount == 2 );
109 Handle(HYDROData_Profile) aGeorefProfile =
110 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
112 aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() );
113 CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) );
115 // Check validity of imported profile
116 CPPUNIT_ASSERT( aGeorefProfile->IsValid() );
118 CPPUNIT_ASSERT( aGeorefProfile->GetTopShape().IsNull() == false );
120 aGeorefProfile->Update();
121 CPPUNIT_ASSERT( aGeorefProfile->GetShape3D().IsNull() == false );
123 HYDROData_Profile::ProfilePoints aProfilePoints = aGeorefProfile->GetProfilePoints();
124 CPPUNIT_ASSERT( aProfilePoints.Length() == 5 );
126 HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 );
127 CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.X(), 1040509.21, EPS );
128 CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.Y(), 6788619.81, EPS );
129 CPPUNIT_ASSERT_DOUBLES_EQUAL( aProfilePoint.Z(), 181.63, EPS );
135 void test_HYDROData_Profile::testCopy()
137 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
139 Handle(HYDROData_Profile) aProfile1 =
140 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
142 QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
144 bool anIsFileCreated = createTestFile( aFileName, false );
146 if ( anIsFileCreated )
148 TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() );
149 CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) );
151 CPPUNIT_ASSERT( aProfile1->IsValid() );
152 CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 );
155 Handle(HYDROData_Profile) aProfile2 =
156 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
158 aProfile1->CopyTo( aProfile2, false );
160 if ( anIsFileCreated )
162 CPPUNIT_ASSERT( aProfile2->IsValid() );
163 CPPUNIT_ASSERT( aProfile2->NbPoints() == 5 );