1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <test_HYDROData_Profile.h>
25 #include <HYDROData_Document.h>
26 #include <HYDROData_Tool.h>
27 #include <HYDROData_Profile.h>
28 #include <HYDROData_Iterator.h>
30 #include <TopoDS_Shape.hxx>
37 #include <QTextStream>
39 bool test_HYDROData_Profile::createTestFile( const QString& theFileName,
40 const bool theIsParametric )
42 QFile aTmpFile( theFileName );
43 if ( !aTmpFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
46 if ( theIsParametric )
48 QTextStream anOutStream( &aTmpFile );
50 anOutStream << "0 182.15 \n";
51 anOutStream << "4 181.95 \n";
52 anOutStream << "10.18 181.63 \n";
53 anOutStream << "14.75 179.27 \n";
54 anOutStream << "19.75 178.87 \n";
58 anOutStream << "-5 50 \n";
59 anOutStream << "0 15 \n";
60 anOutStream << "10.1 10 \n";
61 anOutStream << "20 20 \n";
62 anOutStream << "250 0.005 \n";
66 QTextStream anOutStream( &aTmpFile );
68 anOutStream << "1040499.17 6788618.13 182.15 \n";
69 anOutStream << "1040503.12 6788618.79 181.95 \n";
70 anOutStream << "1040509.21 6788619.81 181.63 \n";
71 anOutStream << "1040513.72 6788620.56 179.27 \n";
72 anOutStream << "1040518.65 6788621.38 178.87 \n";
80 void test_HYDROData_Profile::testFileImport()
82 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
84 QString aParamFileName = QDir::tempPath() + QDir::separator() + "parametric.pa";
85 QString aGeorefFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
86 if ( !createTestFile( aParamFileName, true ) || !createTestFile( aGeorefFileName, false ) )
87 return; // No file has been created
89 TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() );
91 CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName ) );
93 int aProfileCount = 0;
94 HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE );
95 for ( ; aDocIter.More(); aDocIter.Next() )
97 Handle(HYDROData_Profile) aProfile =
98 Handle(HYDROData_Profile)::DownCast( aDocIter.Current() );
99 if ( aProfile.IsNull() )
102 CPPUNIT_ASSERT( aProfile->IsValid() == false );
103 CPPUNIT_ASSERT( aProfile->NbPoints() == 5 );
108 CPPUNIT_ASSERT( aProfileCount == 2 );
110 Handle(HYDROData_Profile) aGeorefProfile =
111 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
113 aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() );
114 CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) );
116 // Check validity of imported profile
117 CPPUNIT_ASSERT( aGeorefProfile->IsValid() );
119 CPPUNIT_ASSERT( aGeorefProfile->GetTopShape().IsNull() == false );
121 aGeorefProfile->UpdateShape3D();
122 CPPUNIT_ASSERT( aGeorefProfile->GetShape3D().IsNull() == false );
124 HYDROData_Profile::ProfilePoints aProfilePoints = aGeorefProfile->GetProfilePoints();
125 CPPUNIT_ASSERT( aProfilePoints.Length() == 5 );
127 HYDROData_Profile::ProfilePoint aProfilePoint = aProfilePoints.Value( 3 );
128 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.X(), 1040509.21 ) );
129 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Y(), 6788619.81 ) );
130 CPPUNIT_ASSERT( ValuesEquals( aProfilePoint.Z(), 181.63 ) );
136 void test_HYDROData_Profile::testCopy()
138 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
140 Handle(HYDROData_Profile) aProfile1 =
141 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
143 QString aFileName = QDir::tempPath() + QDir::separator() + "georef.pa";
145 bool anIsFileCreated = createTestFile( aFileName, false );
147 if ( anIsFileCreated )
149 TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() );
150 CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) );
152 CPPUNIT_ASSERT( aProfile1->IsValid() );
153 CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 );
156 Handle(HYDROData_Profile) aProfile2 =
157 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
159 aProfile1->CopyTo( aProfile2 );
161 if ( anIsFileCreated )
163 CPPUNIT_ASSERT( aProfile2->IsValid() );
164 CPPUNIT_ASSERT( aProfile2->NbPoints() == 5 );