Salome HOME
Merge branch 'BR_2017' of ssh://git.salome-platform.org/modules/hydro into BR_2017
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_Tool.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_HYDROData_Tool.h>
20 #include <HYDROData_Tool.h>
21 #include <TopoDS_Edge.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <TopoDS_Face.hxx>
24 #include <TopoDS.hxx>
25 #include <TestViewer.h>
26 #include <TestShape.h>
27 #include <TopTools_ListOfShape.hxx>
28 #include <AIS_DisplayMode.hxx>
29 #include <QString>
30 #include <QColor>
31 #include <BRep_Builder.hxx>
32 #include <BRepTools.hxx>
33 #include <TopExp.hxx>
34 #include <TopTools_IndexedMapOfShape.hxx>
35 #include <TopoDS_Iterator.hxx>
36
37 extern QString REF_DATA_PATH;
38
39 void test_HYDROData_Tool::test_rebuild_cmp()
40 {
41   QString RefPath = REF_DATA_PATH;
42   BRep_Builder bb;
43   {
44     TopoDS_Shape in, out;
45
46     BRepTools::Read(in, (RefPath + "/f_cmp.brep").toStdString().c_str(), bb);
47     out = HYDROData_Tool::RebuildCmp(in);
48
49     {
50       TopTools_IndexedMapOfShape dummy;
51       TopExp::MapShapes(out, TopAbs_COMPOUND, dummy);
52       CPPUNIT_ASSERT_EQUAL(1, dummy.Extent());
53
54       dummy.Clear();
55       TopExp::MapShapes(out, TopAbs_SHELL, dummy);
56       CPPUNIT_ASSERT_EQUAL(3, dummy.Extent());
57
58       dummy.Clear();
59       TopExp::MapShapes(out, TopAbs_FACE, dummy);
60       CPPUNIT_ASSERT_EQUAL(14, dummy.Extent());
61
62       std::multiset<int> nbF, ndFref;
63       ndFref.insert(1); //one face
64       ndFref.insert(4); // one shell (contains 4 faces)
65       ndFref.insert(4); // one shell (contains 4 faces)
66       ndFref.insert(5); // one shell (contains 5 faces)
67       TopoDS_Iterator itS(out);
68       for (;itS.More();itS.Next())
69       {
70         const TopoDS_Shape& CSH = itS.Value();
71         dummy.Clear();
72         TopExp::MapShapes(CSH, TopAbs_FACE, dummy);
73         nbF.insert(dummy.Extent());
74       }
75
76       CPPUNIT_ASSERT(ndFref == nbF); 
77
78     }
79
80     TestViewer::show( out, AIS_Shaded, true, "rebuild_cmp_out" );
81     CPPUNIT_ASSERT_IMAGES
82   }
83
84 }
85
86
87