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 bool test_HYDROData_Profile::createTestFile( const QString& theFileName,
36 const bool theIsParametric )
38 QFile aTmpFile( theFileName );
39 if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
42 if ( theIsParametric )
44 QTextStream anOutStream( &aTmpFile );
46 anOutStream << "0 182.15 \n";
47 anOutStream << "4 181.95 \n";
48 anOutStream << "10.18 181.63 \n";
49 anOutStream << "14.75 179.27 \n";
50 anOutStream << "19.75 178.87 \n";
54 anOutStream << "-5 50 \n";
55 anOutStream << "0 15 \n";
56 anOutStream << "10.1 10 \n";
57 anOutStream << "20 20 \n";
58 anOutStream << "250 0.005 \n";
62 QTextStream anOutStream( &aTmpFile );
64 anOutStream << "1040499.17 6788618.13 182.15 \n";
65 anOutStream << "1040503.12 6788618.79 181.95 \n";
66 anOutStream << "1040509.21 6788619.81 181.63 \n";
67 anOutStream << "1040513.72 6788620.56 179.27 \n";
68 anOutStream << "1040518.65 6788621.38 178.87 \n";
76 void test_HYDROData_Profile::testFileImport()
78 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
80 QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa";
81 QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
82 if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) )
83 return; // No file has been created
85 TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() );
87 CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName ) );
89 int aProfileCount = 0;
90 HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE );
91 for ( ; aDocIter.More(); aDocIter.Next() )
93 Handle(HYDROData_Profile) aProfile =
94 Handle(HYDROData_Profile)::DownCast( aDocIter.Current() );
95 if ( aProfile.IsNull() )
98 CPPUNIT_ASSERT( aProfile->IsValid() == false );
99 CPPUNIT_ASSERT( aProfile->NbPoints() == 5 );
104 CPPUNIT_ASSERT( aProfileCount == 2 );
106 Handle(HYDROData_Profile) aGeorefProfile =
107 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
109 aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() );
110 CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) );
112 // Check validity of imported profile
113 CPPUNIT_ASSERT( aGeorefProfile->IsValid() );
115 CPPUNIT_ASSERT( aGeorefProfile->GetTopShape().IsNull() == false );
117 aGeorefProfile->UpdateShape3D();
118 CPPUNIT_ASSERT( aGeorefProfile->GetShape3D().IsNull() == false );
120 HYDROData_Profile::ProfilePoints aProfilePoints = aGeorefProfile->GetProfilePoints();
121 CPPUNIT_ASSERT( aProfilePoints.Length() == 5 );
123 HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 );
124 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.X(), 1040509.21 ) );
125 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Y(), 6788619.81 ) );
126 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Z(), 181.63 ) );
132 void test_HYDROData_Profile::testCopy()
134 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
136 Handle(HYDROData_Profile) aProfile1 =
137 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
139 QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
141 bool anIsFileCreated = createTestFile( aFileName, false );
143 if ( anIsFileCreated )
145 TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() );
146 CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) );
148 CPPUNIT_ASSERT( aProfile1->IsValid() );
149 CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 );
152 Handle(HYDROData_Profile) aProfile2 =
153 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
155 aProfile1->CopyTo( aProfile2 );
157 if ( anIsFileCreated )
159 CPPUNIT_ASSERT( aProfile2->IsValid() );
160 CPPUNIT_ASSERT( aProfile2->NbPoints() == 5 );