Salome HOME
Copyright update 2021
[modules/smesh.git] / src / StdMeshers / StdMeshers_BlockRenumber.hxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH : implementation of SMESH idl descriptions
24 //  File   : StdMeshers_BlockRenumber.hxx
25 //  Author : Edward AGAPOV, OCC
26 //  Module : SMESH
27 //
28 #ifndef _SMESH_BlockRenumber_HXX_
29 #define _SMESH_BlockRenumber_HXX_
30
31 #include "SMESH_StdMeshers.hxx"
32
33 #include "SMESH_ComputeError.hxx"
34 #include "SMESH_Hypothesis.hxx"
35 #include "SMESH_MeshEditor.hxx"
36
37 #include <NCollection_DataMap.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopoDS_Vertex.hxx>
40
41 #include <boost/serialization/vector.hpp>
42 #include <map>
43
44 class SMESH_Mesh;
45 class TopoDS_Shape;
46 class TopoDS_TShape;
47 class TopoDS_Vertex;
48
49 // =========================================================
50 struct StdMeshers_BlockCS // Local coordinate system of a block
51 {
52   std::string _solid;
53   std::string _vertex000;
54   std::string _vertex001;
55
56   bool operator==( const StdMeshers_BlockCS& other ) const
57   {
58     return ( _solid     == other._solid &&
59              _vertex000 == other._vertex000 &&
60              _vertex001 == other._vertex001 );
61   }
62 };
63
64 // =========================================================
65 /*!
66  * \class 3D Hypothesis used by Hexahedron(ijk) algorithm
67  *        to renumber mesh of a block to be structured-like 
68  */
69 // =========================================================
70
71 class STDMESHERS_EXPORT StdMeshers_BlockRenumber : public SMESH_Hypothesis
72 {
73 public:
74   StdMeshers_BlockRenumber(int hypId, SMESH_Gen * gen);
75
76   void SetBlocksOrientation( std::vector< StdMeshers_BlockCS > & blockCS );
77
78   const std::vector< StdMeshers_BlockCS > &  GetBlocksOrientation() const { return _blockCS; }
79
80   virtual std::ostream & SaveTo(std::ostream & save) override;
81   virtual std::istream & LoadFrom(std::istream & load) override;
82
83   /*!
84    * \brief Initialize Fineness by the mesh built on the geometry
85    *  \param theMesh - the built mesh
86    *  \param theShape - the geometry of interest
87    *  \retval bool - true if parameter values have been successfully defined
88    */
89   bool SetParametersByMesh(const SMESH_Mesh* /*mesh*/, const TopoDS_Shape& /*shape*/) override
90   { return false; }
91
92   /*!
93    * \brief Initialize my parameter values by default parameters.
94    *  \retval bool - true if parameter values have been successfully defined
95    */
96   bool SetParametersByDefaults(const TDefaults& /*dflts*/, const SMESH_Mesh* /*mesh*/=0) override
97   { return false; }
98
99  public:
100
101   /*!
102    * \brief Check validity of parameter
103    */
104   SMESH_ComputeErrorPtr CheckHypothesis(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape) const;
105
106   /*!
107    * \brief Return true and vertices if block orientation is defined for a given solid
108    */
109   bool IsSolidIncluded( SMESH_Mesh&         mesh,
110                         const TopoDS_Shape& solid,
111                         TopoDS_Vertex&      vertex000,
112                         TopoDS_Vertex&      vertex001 ) const;
113
114  private:
115
116   // Persistence: define both input and output at once
117   friend class boost::serialization::access;
118   template<class Archive> void serialize( Archive & ar, const unsigned int /*version*/ )
119   {
120     ar & _blockCS;
121   }
122
123  protected:
124
125   std::vector< StdMeshers_BlockCS > _blockCS;
126
127   typedef NCollection_DataMap< TopoDS_Shape, std::pair< TopoDS_Vertex, TopoDS_Vertex > > TSolid2VV;
128   TSolid2VV                         _solids2vertices; // shapes defined by _blockCS, non-persistent
129 };
130
131 // =========================================================
132 /*!
133  * \brief Help in using StdMeshers_BlockRenumber
134  */
135 class StdMeshers_RenumberHelper
136 {
137 public:
138
139   StdMeshers_RenumberHelper( SMESH_Mesh&                     mesh,
140                              const StdMeshers_BlockRenumber* hyp);
141   /*!
142    * \brief Find default vertex at (0,0,0) local position
143    */
144   static TopoDS_Vertex GetVertex000( const TopTools_MapOfShape& cornerVertices );
145
146   /*!
147    * \brief Find a vertex of a solid located at the given point
148    */
149   static TopoDS_Vertex GetVertexAtPoint( const TopoDS_Shape& solid, const TopoDS_Shape& point );
150
151   /*!
152    * \brief Create a copy of an old node and remember this couple of nodes for replacement
153    */
154   void AddReplacingNode( const SMDS_MeshNode* & oldNode );
155
156   /*!
157    * \brief Replace old nodes by new ones
158    */
159   void DoReplaceNodes();
160
161 private:
162
163   SMESH_Mesh*                     _mesh;
164   const StdMeshers_BlockRenumber* _hyp;
165
166   SMESH_MeshEditor::TListOfListOfNodes _nodesToMerge;
167   std::list< const SMDS_MeshNode* >    _newOldNodes;
168 };
169
170 #endif