Salome HOME
introducing test on mesh extension, with resources generated first
[modules/hydro.git] / src / HYDRO_tests / test_Dependencies.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <test_Dependencies.h>
20 #include <HYDROData_Bathymetry.h>
21 #include <HYDROData_CalculationCase.h>
22 #include <HYDROData_Channel.h>
23 #include <HYDROData_Document.h>
24 #include <HYDROData_ImmersibleZone.h>
25 #include <HYDROData_Polyline3D.h>
26 #include <HYDROData_PolylineXY.h>
27
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRepBuilderAPI_MakeWire.hxx>
30
31 void test_Dependencies::test_dependencies_broad_cast()
32 {
33   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
34
35   Handle(HYDROData_Bathymetry) aBath =
36     Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
37
38   Handle(HYDROData_PolylineXY) aPoly =
39     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
40
41   Handle(HYDROData_Polyline3D) aPoly3d =
42     Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) );
43
44   Handle(HYDROData_ImmersibleZone) aZone =
45     Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
46
47   Handle(HYDROData_Channel) aChannel =
48     Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) );
49
50   Handle(HYDROData_CalculationCase) aCase =
51     Handle(HYDROData_CalculationCase)::DownCast( aDoc->CreateObject( KIND_CALCULATION ) );
52
53   aZone->SetPolyline( aPoly );
54   aZone->SetAltitudeObject( aBath );
55   aZone->Update();
56
57   aPoly3d->SetPolylineXY( aPoly );
58   aPoly3d->SetAltitudeObject( aBath );
59   aPoly3d->Update();
60
61   TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( gp_Pnt(), gp_Pnt( 1, 0, 0 ) ).Edge();
62   TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
63   aPoly3d->SetTopShape( aWire );
64   aPoly3d->SetShape3D( aWire );
65   CPPUNIT_ASSERT_EQUAL( true, aChannel->SetGuideLine( aPoly3d ) );
66   aChannel->Update();
67
68   aCase->AddGeometryObject( aZone );
69   aCase->AddGeometryObject( aChannel );
70   aCase->ClearChanged();
71
72   // 1. Change only Z values of the bathymetry
73   aBath->SetAltitudesInverted( true );
74
75   CPPUNIT_ASSERT_EQUAL( false, aZone->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
76   CPPUNIT_ASSERT_EQUAL( false, aPoly3d->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
77   CPPUNIT_ASSERT_EQUAL( true, aPoly3d->IsMustBeUpdated( HYDROData_Entity::Geom_Z ) );
78   CPPUNIT_ASSERT_EQUAL( true, aPoly3d->IsMustBeUpdated( HYDROData_Entity::Geom_3d ) );
79   CPPUNIT_ASSERT_EQUAL( false, aChannel->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
80   CPPUNIT_ASSERT_EQUAL( true, aChannel->IsMustBeUpdated( HYDROData_Entity::Geom_Z ) );
81   CPPUNIT_ASSERT_EQUAL( true, aChannel->IsMustBeUpdated( HYDROData_Entity::Geom_3d ) );
82   CPPUNIT_ASSERT_EQUAL( false, aCase->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
83
84   aPoly3d->ClearChanged();
85   aChannel->ClearChanged();
86
87   // 2. "Change" the polyline 2d
88   aPoly->Changed( HYDROData_Entity::Geom_2d );
89
90   CPPUNIT_ASSERT_EQUAL( true, aZone->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
91   CPPUNIT_ASSERT_EQUAL( true, aPoly3d->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
92   CPPUNIT_ASSERT_EQUAL( false, aPoly3d->IsMustBeUpdated( HYDROData_Entity::Geom_Z ) );
93   CPPUNIT_ASSERT_EQUAL( true, aPoly3d->IsMustBeUpdated( HYDROData_Entity::Geom_3d ) );
94   CPPUNIT_ASSERT_EQUAL( true, aChannel->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
95   CPPUNIT_ASSERT_EQUAL( false, aChannel->IsMustBeUpdated( HYDROData_Entity::Geom_Z ) );
96   CPPUNIT_ASSERT_EQUAL( true, aChannel->IsMustBeUpdated( HYDROData_Entity::Geom_3d ) );
97   CPPUNIT_ASSERT_EQUAL( true, aCase->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) );
98
99   aDoc->Close();
100 }
101
102 void test_Dependencies::test_calc_case_ref_objects()
103 {
104   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
105
106   Handle(HYDROData_ImmersibleZone) aZone =
107     Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
108
109   Handle(HYDROData_CalculationCase) aCase =
110     Handle(HYDROData_CalculationCase)::DownCast( aDoc->CreateObject( KIND_CALCULATION ) );
111
112   aCase->AddGeometryObject( aZone );
113   CPPUNIT_ASSERT_EQUAL( 1, aCase->GetAllReferenceObjects().Size() );
114   CPPUNIT_ASSERT_EQUAL( aZone->Label(), aCase->GetAllReferenceObjects().First()->Label() );
115
116   aDoc->Close();
117 }