1 // Copyright (C) 2017-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : FrontTrack_NodeGroups.cxx
20 // Created : Tue Apr 25 19:17:47 2017
21 // Author : Edward AGAPOV (eap)
23 #include "FrontTrack_NodeGroups.hxx"
24 #include "FrontTrack_Projector.hxx"
25 #include "FrontTrack_Utils.hxx"
27 #include <MEDCouplingMemArray.hxx>
28 #include <XAO_BrepGeometry.hxx>
29 #include <XAO_Xao.hxx>
31 #include <BRepBndLib.hxx>
32 #include <Bnd_Box.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopTools_IndexedMapOfShape.hxx>
36 #include <TopoDS_Shape.hxx>
40 //================================================================================
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
47 //================================================================================
49 void getProjectors( const TopoDS_Shape& theMainShape,
50 const TopAbs_ShapeEnum theSubType,
51 std::vector< FT_Projector > & theProjectors )
53 TopTools_IndexedMapOfShape subShapes;
54 TopExp::MapShapes( theMainShape, theSubType, subShapes );
56 std::cout << ". Nombre de subShapes : " << subShapes.Size() << std::endl;
59 theProjectors.resize( subShapes.Size() );
60 for ( int i = 1; i <= subShapes.Size(); ++i )
61 theProjectors[ i-1 ].setBoundaryShape( subShapes( i ));
65 //================================================================================
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
73 //================================================================================
75 void FT_NodeGroups::read( const std::vector< std::string >& theNodeFiles,
76 const XAO::Xao* theXao,
77 MEDCoupling::DataArrayDouble* theNodeCoords )
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] );
85 _nodesOnGeom.resize( theNodeFiles.size() );
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 )
91 _nodesOnGeom[i].read( theNodeFiles[i], xaoGroups, theNodeCoords, _projectors );
95 //================================================================================
97 * \brief Project and move nodes of a given group of nodes
99 //================================================================================
101 void FT_NodeGroups::projectAndMove( const int groupIndex )
103 _nodesOnGeom[ groupIndex ].projectAndMove();
106 //================================================================================
108 * \brief Return true if all nodes were successfully relocated
110 //================================================================================
112 bool FT_NodeGroups::isOK() const
114 for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
115 if ( ! _nodesOnGeom[ i ].isOK() )
121 //================================================================================
123 * \brief Print some statistics on node groups
125 //================================================================================
127 void FT_NodeGroups::dumpStat() const
129 for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
131 std::cout << _nodesOnGeom[i].getShapeDim() << "D "
132 << _nodesOnGeom[i].nbNodes() << " nodes" << std::endl;