]> SALOME platform Git repositories - modules/homard.git/blob - src/FrontTrack/FrontTrack_NodeGroups.cxx
Salome HOME
Merge changes from 'master' branch.
[modules/homard.git] / src / FrontTrack / FrontTrack_NodeGroups.cxx
1 // File      : FrontTrack_NodeGroups.cxx
2 // Created   : Tue Apr 25 19:17:47 2017
3 // Author    : Edward AGAPOV (eap)
4
5 #include "FrontTrack_NodeGroups.hxx"
6 #include "FrontTrack_Projector.hxx"
7 #include "FrontTrack_Utils.hxx"
8
9 #include <MEDCouplingMemArray.hxx>
10 #include <XAO_BrepGeometry.hxx>
11 #include <XAO_Xao.hxx>
12
13 #include <BRepBndLib.hxx>
14 #include <Bnd_Box.hxx>
15 #include <TopExp.hxx>
16 #include <TopExp_Explorer.hxx>
17 #include <TopTools_IndexedMapOfShape.hxx>
18 #include <TopoDS_Shape.hxx>
19
20 namespace
21 {
22   //================================================================================
23   /*!
24    * \brief Initialize FT_Projector's with all sub-shapes of given type
25    *  \param [in] theMainShape - the shape to explore
26    *  \param [in] theSubType - the type of sub-shapes
27    *  \param [out] theProjectors - the projectors
28    */
29   //================================================================================
30
31   void getProjectors( const TopoDS_Shape&           theMainShape,
32                       const TopAbs_ShapeEnum        theSubType,
33                       std::vector< FT_Projector > & theProjectors )
34   {
35     TopTools_IndexedMapOfShape subShapes;
36     TopExp::MapShapes( theMainShape, theSubType, subShapes );
37 #ifdef _DEBUG_
38     std::cout << ". Nombre de subShapes : " << subShapes.Size() << std::endl;
39 #endif
40
41     theProjectors.resize( subShapes.Size() );
42     for ( int i = 1; i <= subShapes.Size(); ++i )
43       theProjectors[ i-1 ].setBoundaryShape( subShapes( i ));
44   }
45 }
46
47 //================================================================================
48 /*!
49  * \brief Load node groups from files
50  *  \param [in] theNodeFiles - an array of names of files describing groups of nodes that
51  *         will be moved onto geometry
52  *  \param [in] theXaoGeom - the whole geometry to project on
53  *  \param [inout] theNodeCoords - array of node coordinates
54  */
55 //================================================================================
56
57 void FT_NodeGroups::read( const std::vector< std::string >& theNodeFiles,
58                           const XAO::Xao*                   theXao,
59                           MEDCoupling::DataArrayDouble*     theNodeCoords )
60 {
61   // get projectors for all boundary sub-shapes;
62   // index of a projector in the vector corresponds to a XAO index of a sub-shape
63   XAO::BrepGeometry* xaoGeom = dynamic_cast<XAO::BrepGeometry*>( theXao->getGeometry() );
64   getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_EDGE, _projectors[0] );
65   getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_FACE, _projectors[1] );
66
67   _nodesOnGeom.resize( theNodeFiles.size() );
68
69   // read node IDs and look for projectors to boundary sub-shapes by group name
70   FT_Utils::XaoGroups xaoGroups( theXao );
71   for ( size_t i = 0; i < theNodeFiles.size(); ++i )
72   {
73     _nodesOnGeom[i].read( theNodeFiles[i], xaoGroups, theNodeCoords, _projectors );
74   }
75 }
76
77 //================================================================================
78 /*!
79  * \brief Project and move nodes of a given group of nodes
80  */
81 //================================================================================
82
83 void FT_NodeGroups::projectAndMove( const int groupIndex )
84 {
85   _nodesOnGeom[ groupIndex ].projectAndMove();
86 }
87
88 //================================================================================
89 /*!
90  * \brief Return true if all nodes were successfully relocated
91  */
92 //================================================================================
93
94 bool FT_NodeGroups::isOK() const
95 {
96   for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
97     if ( ! _nodesOnGeom[ i ].isOK() )
98       return false;
99
100   return true;
101 }
102
103 //================================================================================
104 /*!
105  * \brief Print some statistics on node groups
106  */
107 //================================================================================
108
109 void FT_NodeGroups::dumpStat() const
110 {
111   for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
112   {
113     std::cout << _nodesOnGeom[i].getShapeDim() << "D "
114               << _nodesOnGeom[i].nbNodes() << " nodes" << std::endl;
115   }
116 }