Salome HOME
Merge branch 'master' into gni/adaptation
[modules/smesh.git] / src / ADAPTFrontTrack / FrontTrack_NodeGroups.cxx
1 // Copyright (C) 2017-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : FrontTrack_NodeGroups.cxx
20 // Created   : Tue Apr 25 19:17:47 2017
21 // Author    : Edward AGAPOV (eap)
22
23 #include "FrontTrack_NodeGroups.hxx"
24 #include "FrontTrack_Projector.hxx"
25 #include "FrontTrack_Utils.hxx"
26
27 #include <MEDCouplingMemArray.hxx>
28 #include <XAO_BrepGeometry.hxx>
29 #include <XAO_Xao.hxx>
30
31 #include <BRepBndLib.hxx>
32 #include <Bnd_Box.hxx>
33 #include <TopExp.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopTools_IndexedMapOfShape.hxx>
36 #include <TopoDS_Shape.hxx>
37
38 namespace
39 {
40   //================================================================================
41   /*!
42    * \brief Initialize FT_Projector's with all sub-shapes of given type
43    *  \param [in] theMainShape - the shape to explore
44    *  \param [in] theSubType - the type of sub-shapes
45    *  \param [out] theProjectors - the projectors
46    */
47   //================================================================================
48
49   void getProjectors( const TopoDS_Shape&           theMainShape,
50                       const TopAbs_ShapeEnum        theSubType,
51                       std::vector< FT_Projector > & theProjectors )
52   {
53     TopTools_IndexedMapOfShape subShapes;
54     TopExp::MapShapes( theMainShape, theSubType, subShapes );
55 #ifdef _DEBUG_
56     std::cout << ". Nombre de subShapes : " << subShapes.Size() << std::endl;
57 #endif
58
59     theProjectors.resize( subShapes.Size() );
60     for ( int i = 1; i <= subShapes.Size(); ++i )
61       theProjectors[ i-1 ].setBoundaryShape( subShapes( i ));
62   }
63 }
64
65 //================================================================================
66 /*!
67  * \brief Load node groups from files
68  *  \param [in] theNodeFiles - an array of names of files describing groups of nodes that
69  *         will be moved onto geometry
70  *  \param [in] theXaoGeom - the whole geometry to project on
71  *  \param [inout] theNodeCoords - array of node coordinates
72  */
73 //================================================================================
74
75 void FT_NodeGroups::read( const std::vector< std::string >& theNodeFiles,
76                           const XAO::Xao*                   theXao,
77                           MEDCoupling::DataArrayDouble*     theNodeCoords )
78 {
79   // get projectors for all boundary sub-shapes;
80   // index of a projector in the vector corresponds to a XAO index of a sub-shape
81   XAO::BrepGeometry* xaoGeom = dynamic_cast<XAO::BrepGeometry*>( theXao->getGeometry() );
82   getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_EDGE, _projectors[0] );
83   getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_FACE, _projectors[1] );
84
85   _nodesOnGeom.resize( theNodeFiles.size() );
86
87   // read node IDs and look for projectors to boundary sub-shapes by group name
88   FT_Utils::XaoGroups xaoGroups( theXao );
89   for ( size_t i = 0; i < theNodeFiles.size(); ++i )
90   {
91     _nodesOnGeom[i].read( theNodeFiles[i], xaoGroups, theNodeCoords, _projectors );
92   }
93 }
94
95 //================================================================================
96 /*!
97  * \brief Project and move nodes of a given group of nodes
98  */
99 //================================================================================
100
101 void FT_NodeGroups::projectAndMove( const int groupIndex )
102 {
103   _nodesOnGeom[ groupIndex ].projectAndMove();
104 }
105
106 //================================================================================
107 /*!
108  * \brief Return true if all nodes were successfully relocated
109  */
110 //================================================================================
111
112 bool FT_NodeGroups::isOK() const
113 {
114   for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
115     if ( ! _nodesOnGeom[ i ].isOK() )
116       return false;
117
118   return true;
119 }
120
121 //================================================================================
122 /*!
123  * \brief Print some statistics on node groups
124  */
125 //================================================================================
126
127 void FT_NodeGroups::dumpStat() const
128 {
129   for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
130   {
131     std::cout << _nodesOnGeom[i].getShapeDim() << "D "
132               << _nodesOnGeom[i].nbNodes() << " nodes" << std::endl;
133   }
134 }