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_LandCoverMap.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_LandCoverMap.h>
22 #include <HYDROData_PolylineXY.h>
23 #include <TopoDS_Edge.hxx>
24 #include <TopoDS_Wire.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TColgp_HArray1OfPnt.hxx>
27 #include <GeomAPI_Interpolate.hxx>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRepBuilderAPI_MakeFace.hxx>
30 #include <BRepBuilderAPI_MakeWire.hxx>
31 #include <TestViewer.h>
32 #include <AIS_DisplayMode.hxx>
36 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
38 int n = theXYList.size()/2;
39 Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
40 for( int i=1; i<=n; i++ )
42 double x = theXYList[2*i-2];
43 double y = theXYList[2*i-1];
44 gp_Pnt aPnt( x, y, 0 );
45 aPointsArray->SetValue( i, aPnt );
47 GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
48 anInterpolator.Perform();
49 bool aResult = anInterpolator.IsDone() == Standard_True;
52 Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
53 return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
59 TopoDS_Face LandCover( const QList<double>& theXYList )
61 TopoDS_Edge anEdge = Spline( theXYList, true );
65 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
66 TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face();
70 void test_HYDROData_LandCoverMap::test_add_2_objects()
72 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
74 Handle(HYDROData_LandCoverMap) aMap =
75 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
77 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
79 TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
80 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
82 TopoDS_Face aLC2 = LandCover( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
83 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
85 TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
86 TestViewer::AssertEqual( "LandCoverMap_Add_2_Objects" );
88 //TODO: check the types
93 void test_HYDROData_LandCoverMap::test_split_by_polyline()
95 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
97 Handle(HYDROData_LandCoverMap) aMap =
98 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
100 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
102 TopoDS_Face aLC = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
103 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
105 Handle(HYDROData_PolylineXY) aPolyline =
106 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
107 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire();
108 aPolyline->SetShape( aWire );
110 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
112 TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
113 //TestViewer::show( aWire, QColor(), 0 );
114 TestViewer::AssertEqual( "LandCoverMap_Split_1" );
116 //TODO: check the types