Salome HOME
22316: EDF 2719 SMESH: Split hexas into prisms
[modules/smesh.git] / src / SMESH / SMESH_MeshEditor.hxx
1 // Copyright (C) 2007-2013  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.
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 // File      : SMESH_MeshEditor.hxx
24 // Created   : Mon Apr 12 14:56:19 2004
25 // Author    : Edward AGAPOV (eap)
26 // Module    : SMESH
27 //
28 #ifndef SMESH_MeshEditor_HeaderFile
29 #define SMESH_MeshEditor_HeaderFile
30
31 #include "SMESH_SMESH.hxx"
32
33 #include "SMDS_MeshElement.hxx"
34 #include "SMESH_Controls.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_TypeDefs.hxx"
37 #include "SMESH_ComputeError.hxx"
38
39 #include <utilities.h>
40
41 #include <TColStd_HSequenceOfReal.hxx>
42 #include <gp_Dir.hxx>
43
44 #include <list>
45 #include <map>
46 #include <set>
47
48 class SMDS_MeshFace;
49 class SMDS_MeshNode;
50 class gp_Ax1;
51 class gp_Vec;
52 class gp_Pnt;
53 class SMESH_MesherHelper;
54 class SMESH_NodeSearcher;
55
56 // ============================================================
57 /*!
58  * \brief Editor of a mesh
59  */
60 // ============================================================
61
62 class SMESH_EXPORT SMESH_MeshEditor
63 {
64 public:
65
66   SMESH_MeshEditor( SMESH_Mesh* theMesh );
67
68   SMESH_Mesh   *                 GetMesh()   { return myMesh; }
69   SMESHDS_Mesh *                 GetMeshDS() { return myMesh->GetMeshDS(); }
70
71   const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
72   const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
73   void                           CrearLastCreated();
74   SMESH_ComputeErrorPtr &        GetError() { return myError; }
75
76   /*!
77    * \brief Add element
78    */
79   SMDS_MeshElement* AddElement(const std::vector<const SMDS_MeshNode*> & nodes,
80                                const SMDSAbs_ElementType                 type,
81                                const bool                                isPoly,
82                                const int                                 ID = -1,
83                                const double                              ballDiameter=0.);
84   /*!
85    * \brief Add element
86    */
87   SMDS_MeshElement* AddElement(const std::vector<int>  & nodeIDs,
88                                const SMDSAbs_ElementType type,
89                                const bool                isPoly,
90                                const int                 ID = -1);
91
92   int Remove (const std::list< int >& theElemIDs, const bool isNodes);
93   // Remove a node or an element.
94   // Modify a compute state of sub-meshes which become empty
95
96   void Create0DElementsOnAllNodes( const TIDSortedElemSet& elements,
97                                    TIDSortedElemSet&       all0DElems);
98   // Create 0D elements on all nodes of the given object except those
99   // nodes on which a 0D element already exists. \a all0DElems returns
100   // all 0D elements found or created on nodes of \a elements
101
102   bool InverseDiag (const SMDS_MeshElement * theTria1,
103                     const SMDS_MeshElement * theTria2 );
104   // Replace two neighbour triangles with ones built on the same 4 nodes
105   // but having other common link.
106   // Return False if args are improper
107
108   bool InverseDiag (const SMDS_MeshNode * theNode1,
109                     const SMDS_MeshNode * theNode2 );
110   // Replace two neighbour triangles sharing theNode1-theNode2 link
111   // with ones built on the same 4 nodes but having other common link.
112   // Return false if proper faces not found
113
114   bool DeleteDiag (const SMDS_MeshNode * theNode1,
115                    const SMDS_MeshNode * theNode2 );
116   // Replace two neighbour triangles sharing theNode1-theNode2 link
117   // with a quadrangle built on the same 4 nodes.
118   // Return false if proper faces not found
119
120   bool Reorient (const SMDS_MeshElement * theElement);
121   // Reverse theElement orientation
122
123   int Reorient2D (TIDSortedElemSet &       theFaces,
124                   const gp_Dir&            theDirection,
125                   const SMDS_MeshElement * theFace);
126   // Reverse theFaces whose orientation to be same as that of theFace
127   // oriented according to theDirection. Return nb of reoriented faces
128
129   /*!
130    * \brief Fuse neighbour triangles into quadrangles.
131    * \param theElems     - The triangles to be fused.
132    * \param theCriterion - Is used to choose a neighbour to fuse with.
133    * \param theMaxAngle  - Is a max angle between element normals at which fusion
134    *                       is still performed; theMaxAngle is mesured in radians.
135    * \return bool - Success or not.
136    */
137   bool TriToQuad (TIDSortedElemSet &                   theElems,
138                   SMESH::Controls::NumericalFunctorPtr theCriterion,
139                   const double                         theMaxAngle);
140   /*!
141    * \brief Split quadrangles into triangles.
142    * \param theElems     - The faces to be splitted.
143    * \param theCriterion - Is used to choose a diagonal for splitting.
144    * \return bool - Success or not.
145    */
146   bool QuadToTri (TIDSortedElemSet &                   theElems,
147                   SMESH::Controls::NumericalFunctorPtr theCriterion);
148   /*!
149    * \brief Split quadrangles into triangles.
150    * \param theElems  - The faces to be splitted.
151    * \param the13Diag - Is used to choose a diagonal for splitting.
152    * \return bool - Success or not.
153    */
154   bool QuadToTri (TIDSortedElemSet & theElems,
155                   const bool         the13Diag);
156   /*!
157    * \brief Split each of given quadrangles into 4 triangles.
158    * \param theElems - The faces to be splitted. If empty all faces are split.
159    */
160   void QuadTo4Tri (TIDSortedElemSet & theElems);
161
162   /*!
163    * \brief Find better diagonal for splitting.
164    * \param theQuad      - The face to find better splitting of.
165    * \param theCriterion - Is used to choose a diagonal for splitting.
166    * \return int - 1 for 1-3 diagonal, 2 for 2-4, -1 - for errors.
167    */
168   int BestSplit (const SMDS_MeshElement*              theQuad,
169                  SMESH::Controls::NumericalFunctorPtr theCriterion);
170
171
172   typedef std::map < const SMDS_MeshElement*, int, TIDCompare > TFacetOfElem;
173
174     //!<2nd arg of SplitVolumes()
175   enum SplitVolumToTetraFlags { HEXA_TO_5 = 1, // split into tetrahedra
176                                 HEXA_TO_6,
177                                 HEXA_TO_24,
178                                 HEXA_TO_2_PRISMS, // split into prisms
179                                 HEXA_TO_4_PRISMS };
180   /*!
181    * \brief Split volumic elements into tetrahedra or prisms.
182    *        If facet ID < 0, element is split into tetrahedra,
183    *        else a hexahedron is split into prisms so that the given facet is
184    *        split into triangles
185    */
186   void SplitVolumes (const TFacetOfElem & theElems, const int theMethodFlags);
187
188   /*!
189    * \brief For hexahedra that will be split into prisms, finds facets to
190    *        split into triangles 
191    *  \param [in,out] theHexas - the hexahedra
192    *  \param [in]     theFacetNormal - facet normal
193    *  \param [out]    theFacets - the hexahedra and found facet IDs
194    */
195   void GetHexaFacetsToSplit( TIDSortedElemSet& theHexas,
196                              const gp_Ax1&     theFacetNormal,
197                              TFacetOfElem &    theFacets);
198
199
200   enum SmoothMethod { LAPLACIAN = 0, CENTROIDAL };
201
202   void Smooth (TIDSortedElemSet &               theElements,
203                std::set<const SMDS_MeshNode*> & theFixedNodes,
204                const SmoothMethod               theSmoothMethod,
205                const int                        theNbIterations,
206                double                           theTgtAspectRatio = 1.0,
207                const bool                       the2D = true);
208   // Smooth theElements using theSmoothMethod during theNbIterations
209   // or until a worst element has aspect ratio <= theTgtAspectRatio.
210   // Aspect Ratio varies in range [1.0, inf].
211   // If theElements is empty, the whole mesh is smoothed.
212   // theFixedNodes contains additionally fixed nodes. Nodes built
213   // on edges and boundary nodes are always fixed.
214   // If the2D, smoothing is performed using UV parameters of nodes
215   // on geometrical faces
216
217   typedef TIDTypeCompare TElemSort;
218   typedef std::map < const SMDS_MeshElement*,
219     std::list<const SMDS_MeshElement*>, TElemSort >                        TTElemOfElemListMap;
220   typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
221   typedef TNodeOfNodeListMap::iterator                                     TNodeOfNodeListMapItr;
222   typedef std::vector<TNodeOfNodeListMapItr>                               TVecOfNnlmiMap;
223   typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap, TElemSort >    TElemOfVecOfNnlmiMap;
224   typedef std::auto_ptr< std::list<int> > PGroupIDs;
225
226   PGroupIDs RotationSweep (TIDSortedElemSet & theElements,
227                            const gp_Ax1&      theAxis,
228                            const double       theAngle,
229                            const int          theNbSteps,
230                            const double       theToler,
231                            const bool         theMakeGroups,
232                            const bool         theMakeWalls=true);
233   // Generate new elements by rotation of theElements around theAxis
234   // by theAngle by theNbSteps
235
236   /*!
237    * Auxilary flag for advanced extrusion.
238    * BOUNDARY: create or not boundary for result of extrusion
239    * SEW:      try to use existing nodes or create new nodes in any case
240    */
241   enum ExtrusionFlags {
242     EXTRUSION_FLAG_BOUNDARY = 0x01,
243     EXTRUSION_FLAG_SEW = 0x02
244   };
245   
246   /*!
247    * special structure for control of extrusion functionality
248    */
249   struct ExtrusParam {
250     gp_Dir myDir; // direction of extrusion
251     Handle(TColStd_HSequenceOfReal) mySteps; // magnitudes for each step
252     SMESH_SequenceOfNode myNodes; // nodes for using in sewing
253   };
254
255   /*!
256    * Create new node in the mesh with given coordinates
257    * (auxiliary for advanced extrusion)
258    */
259   const SMDS_MeshNode* CreateNode(const double x,
260                                   const double y,
261                                   const double z,
262                                   const double tolnode,
263                                   SMESH_SequenceOfNode& aNodes);
264
265   /*!
266    * Generate new elements by extrusion of theElements
267    * It is a method used in .idl file. All functionality
268    * is implemented in the next method (see below) which
269    * is used in the current method.
270    * @param theElems - list of elements for extrusion
271    * @param newElemsMap returns history of extrusion
272    * @param theFlags set flags for performing extrusion (see description
273    *   of enum ExtrusionFlags for additional information)
274    * @param theTolerance - uses for comparing locations of nodes if flag
275    *   EXTRUSION_FLAG_SEW is set
276    */
277   PGroupIDs ExtrusionSweep (TIDSortedElemSet &   theElems,
278                             const gp_Vec&        theStep,
279                             const int            theNbSteps,
280                             TTElemOfElemListMap& newElemsMap,
281                             const bool           theMakeGroups,
282                             const int            theFlags = EXTRUSION_FLAG_BOUNDARY,
283                             const double         theTolerance = 1.e-6);
284   
285   /*!
286    * Generate new elements by extrusion of theElements
287    * @param theElems - list of elements for extrusion
288    * @param newElemsMap returns history of extrusion
289    * @param theFlags set flags for performing extrusion (see description
290    *   of enum ExtrusionFlags for additional information)
291    * @param theTolerance - uses for comparing locations of nodes if flag
292    *   EXTRUSION_FLAG_SEW is set
293    * @param theParams - special structure for manage of extrusion
294    */
295   PGroupIDs ExtrusionSweep (TIDSortedElemSet &   theElems,
296                             ExtrusParam&         theParams,
297                             TTElemOfElemListMap& newElemsMap,
298                             const bool           theMakeGroups,
299                             const int            theFlags,
300                             const double         theTolerance);
301
302
303   // Generate new elements by extrusion of theElements 
304   // by theStep by theNbSteps
305
306   enum Extrusion_Error {
307     EXTR_OK,
308     EXTR_NO_ELEMENTS, 
309     EXTR_PATH_NOT_EDGE,
310     EXTR_BAD_PATH_SHAPE,
311     EXTR_BAD_STARTING_NODE,
312     EXTR_BAD_ANGLES_NUMBER,
313     EXTR_CANT_GET_TANGENT
314     };
315   
316   Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet &   theElements,
317                                        SMESH_subMesh*       theTrackPattern,
318                                        const SMDS_MeshNode* theNodeStart,
319                                        const bool           theHasAngles,
320                                        std::list<double>&   theAngles,
321                                        const bool           theLinearVariation,
322                                        const bool           theHasRefPoint,
323                                        const gp_Pnt&        theRefPoint,
324                                        const bool           theMakeGroups);
325   Extrusion_Error ExtrusionAlongTrack (TIDSortedElemSet &   theElements,
326                                        SMESH_Mesh*          theTrackPattern,
327                                        const SMDS_MeshNode* theNodeStart,
328                                        const bool           theHasAngles,
329                                        std::list<double>&   theAngles,
330                                        const bool           theLinearVariation,
331                                        const bool           theHasRefPoint,
332                                        const gp_Pnt&        theRefPoint,
333                                        const bool           theMakeGroups);
334   // Generate new elements by extrusion of theElements along path given by theTrackPattern,
335   // theHasAngles are the rotation angles, base point can be given by theRefPoint
336
337   PGroupIDs Transform (TIDSortedElemSet & theElements,
338                        const gp_Trsf&     theTrsf,
339                        const bool         theCopy,
340                        const bool         theMakeGroups,
341                        SMESH_Mesh*        theTargetMesh=0);
342   // Move or copy theElements applying theTrsf to their nodes
343
344   typedef std::list< std::list< const SMDS_MeshNode* > > TListOfListOfNodes;
345
346   void FindCoincidentNodes (TIDSortedNodeSet &   theNodes,
347                             const double         theTolerance,
348                             TListOfListOfNodes & theGroupsOfNodes);
349   // Return list of group of nodes close to each other within theTolerance.
350   // Search among theNodes or in the whole mesh if theNodes is empty.
351
352   void MergeNodes (TListOfListOfNodes & theNodeGroups);
353   // In each group, the cdr of nodes are substituted by the first one
354   // in all elements.
355
356   typedef std::list< std::list< int > > TListOfListOfElementsID;
357
358   void FindEqualElements(TIDSortedElemSet &        theElements,
359                          TListOfListOfElementsID & theGroupsOfElementsID);
360   // Return list of group of elements build on the same nodes.
361   // Search among theElements or in the whole mesh if theElements is empty.
362
363   void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
364   // In each group remove all but first of elements.
365
366   void MergeEqualElements();
367   // Remove all but one of elements built on the same nodes.
368   // Return nb of successfully merged groups.
369
370   int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
371                     std::vector<const SMDS_MeshNode *>&       poly_nodes,
372                     std::vector<int>&                         quantities) const;
373   // Split face, defined by <faceNodes>, into several faces by repeating nodes.
374   // Is used by MergeNodes()
375
376   static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
377                                    const SMDS_MeshNode* theNode2,
378                                    const SMDS_MeshNode* theNode3 = 0);
379   // Return true if the three nodes are on a free border
380
381   static bool FindFreeBorder (const SMDS_MeshNode*                  theFirstNode,
382                               const SMDS_MeshNode*                  theSecondNode,
383                               const SMDS_MeshNode*                  theLastNode,
384                               std::list< const SMDS_MeshNode* > &   theNodes,
385                               std::list< const SMDS_MeshElement* >& theFaces);
386   // Return nodes and faces of a free border if found 
387
388   enum Sew_Error {
389     SEW_OK,
390     // for SewFreeBorder()
391     SEW_BORDER1_NOT_FOUND,
392     SEW_BORDER2_NOT_FOUND,
393     SEW_BOTH_BORDERS_NOT_FOUND,
394     SEW_BAD_SIDE_NODES,
395     SEW_VOLUMES_TO_SPLIT,
396     // for SewSideElements()
397     SEW_DIFF_NB_OF_ELEMENTS,
398     SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
399     SEW_BAD_SIDE1_NODES,
400     SEW_BAD_SIDE2_NODES,
401     SEW_INTERNAL_ERROR
402     };
403     
404
405   Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
406                            const SMDS_MeshNode* theBorderSecondNode,
407                            const SMDS_MeshNode* theBorderLastNode,
408                            const SMDS_MeshNode* theSide2FirstNode,
409                            const SMDS_MeshNode* theSide2SecondNode,
410                            const SMDS_MeshNode* theSide2ThirdNode = 0,
411                            const bool           theSide2IsFreeBorder = true,
412                            const bool           toCreatePolygons = false,
413                            const bool           toCreatePolyedrs = false);
414   // Sew the free border to the side2 by replacing nodes in
415   // elements on the free border with nodes of the elements
416   // of the side 2. If nb of links in the free border and
417   // between theSide2FirstNode and theSide2LastNode are different,
418   // additional nodes are inserted on a link provided that no
419   // volume elements share the splitted link.
420   // The side 2 is a free border if theSide2IsFreeBorder == true.
421   // Sewing is peformed between the given first, second and last
422   // nodes on the sides.
423   // theBorderFirstNode is merged with theSide2FirstNode.
424   // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
425   // the last node on the side 2, which will be merged with
426   // theBorderLastNode.
427   // if (theSide2IsFreeBorder) then theSide2SecondNode will
428   // be merged with theBorderSecondNode.
429   // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
430   // the 2 free borders are sewn link by link and no additional
431   // nodes are inserted.
432   // Return false, if sewing failed.
433
434   Sew_Error SewSideElements (TIDSortedElemSet&    theSide1,
435                              TIDSortedElemSet&    theSide2,
436                              const SMDS_MeshNode* theFirstNode1ToMerge,
437                              const SMDS_MeshNode* theFirstNode2ToMerge,
438                              const SMDS_MeshNode* theSecondNode1ToMerge,
439                              const SMDS_MeshNode* theSecondNode2ToMerge);
440   // Sew two sides of a mesh. Nodes belonging to theSide1 are
441   // merged with nodes of elements of theSide2.
442   // Number of elements in theSide1 and in theSide2 must be
443   // equal and they should have similar node connectivity.
444   // The nodes to merge should belong to side s borders and
445   // the first node should be linked to the second.
446
447   void InsertNodesIntoLink(const SMDS_MeshElement*          theFace,
448                            const SMDS_MeshNode*             theBetweenNode1,
449                            const SMDS_MeshNode*             theBetweenNode2,
450                            std::list<const SMDS_MeshNode*>& theNodesToInsert,
451                            const bool                       toCreatePoly = false);
452   // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
453   // If toCreatePoly is true, replace theFace by polygon, else split theFace.
454
455   void UpdateVolumes (const SMDS_MeshNode*             theBetweenNode1,
456                       const SMDS_MeshNode*             theBetweenNode2,
457                       std::list<const SMDS_MeshNode*>& theNodesToInsert);
458   // insert theNodesToInsert into all volumes, containing link
459   // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
460
461   void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
462   void ConvertToQuadratic(const bool theForce3d,
463                           TIDSortedElemSet& theElements, const bool theToBiQuad);
464   // Converts all mesh to quadratic or bi-quadratic one, deletes old elements, 
465   // replacing them with quadratic or bi-quadratic ones with the same id.
466   // If theForce3d = 1; this results in the medium node lying at the 
467   // middle of the line segments connecting start and end node of a mesh element.
468   // If theForce3d = 0; this results in the medium node lying at the 
469   // geometrical edge from which the mesh element is built.
470
471   bool ConvertFromQuadratic();
472   void ConvertFromQuadratic(TIDSortedElemSet& theElements);
473   // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing 
474   // them with ordinary mesh elements with the same id.
475   // Returns true in case of success, false otherwise.
476
477   static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
478                                const SMDS_MeshElement* elemInGroups,
479                                SMESHDS_Mesh *          aMesh);
480   // Add elemToAdd to the all groups the elemInGroups belongs to
481
482   static void RemoveElemFromGroups (const SMDS_MeshElement* element,
483                                     SMESHDS_Mesh *          aMesh);
484   // remove element from the all groups
485
486   static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
487                                    const SMDS_MeshElement* elemToAdd,
488                                    SMESHDS_Mesh *          aMesh);
489   // replace elemToRm by elemToAdd in the all groups
490
491   static void ReplaceElemInGroups (const SMDS_MeshElement*                     elemToRm,
492                                    const std::vector<const SMDS_MeshElement*>& elemToAdd,
493                                    SMESHDS_Mesh *                              aMesh);
494   // replace elemToRm by elemToAdd in the all groups
495
496   /*!
497    * \brief Return nodes linked to the given one in elements of the type
498    */
499   static void GetLinkedNodes( const SMDS_MeshNode* node,
500                               TIDSortedElemSet &   linkedNodes,
501                               SMDSAbs_ElementType  type = SMDSAbs_All );
502
503   /*!
504    * \brief Find corresponding nodes in two sets of faces 
505     * \param theSide1 - first face set
506     * \param theSide2 - second first face
507     * \param theFirstNode1 - a boundary node of set 1
508     * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
509     * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
510     * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
511     * \param nReplaceMap - output map of corresponding nodes
512     * \return Sew_Error  - is a success or not
513    */
514   static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
515                                      std::set<const SMDS_MeshElement*>& theSide2,
516                                      const SMDS_MeshNode*               theFirstNode1,
517                                      const SMDS_MeshNode*               theFirstNode2,
518                                      const SMDS_MeshNode*               theSecondNode1,
519                                      const SMDS_MeshNode*               theSecondNode2,
520                                      TNodeNodeMap &                     theNodeReplaceMap);
521
522   /*!
523    * \brief Returns true if given node is medium
524     * \param n - node to check
525     * \param typeToCheck - type of elements containing the node to ask about node status
526     * \return bool - check result
527    */
528   static bool IsMedium(const SMDS_MeshNode*      node,
529                        const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
530
531   int FindShape (const SMDS_MeshElement * theElem);
532   // Return an index of the shape theElem is on
533   // or zero if a shape not found
534
535   void DoubleElements( const TIDSortedElemSet& theElements );
536
537   bool DoubleNodes( const std::list< int >& theListOfNodes, 
538                     const std::list< int >& theListOfModifiedElems );
539   
540   bool DoubleNodes( const TIDSortedElemSet& theElems, 
541                     const TIDSortedElemSet& theNodesNot,
542                     const TIDSortedElemSet& theAffectedElems );
543
544   bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
545                                    const TIDSortedElemSet& theNodesNot,
546                                    const TopoDS_Shape&     theShape,
547                                    TIDSortedElemSet& theAffectedElems);
548
549   bool DoubleNodesInRegion( const TIDSortedElemSet& theElems, 
550                             const TIDSortedElemSet& theNodesNot,
551                             const TopoDS_Shape&     theShape );
552   
553   double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
554
555   bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
556                                      bool createJointElems);
557
558   bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
559
560   void CreateHoleSkin(double radius,
561                       const TopoDS_Shape& theShape,
562                       SMESH_NodeSearcher* theNodeSearcher,
563                       const char* groupName,
564                       std::vector<double>&   nodesCoords,
565                       std::vector<std::vector<int> >& listOfListOfNodes);
566
567   /*!
568    * \brief Generated skin mesh (containing 2D cells) from 3D mesh
569    * The created 2D mesh elements based on nodes of free faces of boundary volumes
570    * \return TRUE if operation has been completed successfully, FALSE otherwise
571    */
572   bool Make2DMeshFrom3D();
573
574   enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
575
576   int MakeBoundaryMesh(const TIDSortedElemSet& elements,
577                        Bnd_Dimension           dimension,
578                        SMESH_Group*            group = 0,
579                        SMESH_Mesh*             targetMesh = 0,
580                        bool                    toCopyElements = false,
581                        bool                    toCopyExistingBondary = false,
582                        bool                    toAddExistingBondary = false,
583                        bool                    aroundElements = false);
584
585  private:
586
587   /*!
588    * \brief Convert elements contained in a submesh to quadratic
589    * \return int - nb of checked elements
590    */
591   int convertElemToQuadratic(SMESHDS_SubMesh *   theSm,
592                              SMESH_MesherHelper& theHelper,
593                              const bool          theForce3d);
594
595   /*!
596    * \brief Convert quadratic elements to linear ones and remove quadratic nodes
597    * \return nb of checked elements
598    */
599   int removeQuadElem( SMESHDS_SubMesh *    theSm,
600                       SMDS_ElemIteratorPtr theItr,
601                       const int            theShapeID);
602   /*!
603    * \brief Create groups of elements made during transformation
604    * \param nodeGens - nodes making corresponding myLastCreatedNodes
605    * \param elemGens - elements making corresponding myLastCreatedElems
606    * \param postfix - to append to names of new groups
607    */
608   PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
609                            const SMESH_SequenceOfElemPtr& elemGens,
610                            const std::string&             postfix,
611                            SMESH_Mesh*                    targetMesh=0);
612   /*!
613    * \brief Create elements by sweeping an element
614    * \param elem - element to sweep
615    * \param newNodesItVec - nodes generated from each node of the element
616    * \param newElems - generated elements
617    * \param nbSteps - number of sweeping steps
618    * \param srcElements - to append elem for each generated element
619    */
620   void sweepElement(const SMDS_MeshElement*                    elem,
621                     const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
622                     std::list<const SMDS_MeshElement*>&        newElems,
623                     const int                                  nbSteps,
624                     SMESH_SequenceOfElemPtr&                   srcElements);
625
626   /*!
627    * \brief Create 1D and 2D elements around swept elements
628    * \param mapNewNodes - source nodes and ones generated from them
629    * \param newElemsMap - source elements and ones generated from them
630    * \param elemNewNodesMap - nodes generated from each node of each element
631    * \param elemSet - all swept elements
632    * \param nbSteps - number of sweeping steps
633    * \param srcElements - to append elem for each generated element
634    */
635   void makeWalls (TNodeOfNodeListMap &     mapNewNodes,
636                   TTElemOfElemListMap &    newElemsMap,
637                   TElemOfVecOfNnlmiMap &   elemNewNodesMap,
638                   TIDSortedElemSet&        elemSet,
639                   const int                nbSteps,
640                   SMESH_SequenceOfElemPtr& srcElements);
641
642   struct SMESH_MeshEditor_PathPoint
643   {
644     gp_Pnt myPnt;
645     gp_Dir myTgt;
646     double myAngle, myPrm;
647
648     SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
649     void          SetPnt      (const gp_Pnt& aP3D)  { myPnt  =aP3D; }
650     void          SetTangent  (const gp_Dir& aTgt)  { myTgt  =aTgt; }
651     void          SetAngle    (const double& aBeta) { myAngle=aBeta; }
652     void          SetParameter(const double& aPrm)  { myPrm  =aPrm; }
653     const gp_Pnt& Pnt         ()const               { return myPnt; }
654     const gp_Dir& Tangent     ()const               { return myTgt; }
655     double        Angle       ()const               { return myAngle; }
656     double        Parameter   ()const               { return myPrm; }
657   };
658   Extrusion_Error MakeEdgePathPoints(std::list<double>&                     aPrms,
659                                      const TopoDS_Edge&                     aTrackEdge,
660                                      bool                                   aFirstIsStart,
661                                      std::list<SMESH_MeshEditor_PathPoint>& aLPP);
662   Extrusion_Error MakeExtrElements(TIDSortedElemSet&                      theElements,
663                                    std::list<SMESH_MeshEditor_PathPoint>& theFullList,
664                                    const bool                             theHasAngles,
665                                    std::list<double>&                     theAngles,
666                                    const bool                             theLinearVariation,
667                                    const bool                             theHasRefPoint,
668                                    const gp_Pnt&                          theRefPoint,
669                                    const bool                             theMakeGroups);
670   void LinearAngleVariation(const int     NbSteps,
671                             list<double>& theAngles);
672
673   bool doubleNodes( SMESHDS_Mesh*                                           theMeshDS,
674                     const TIDSortedElemSet&                                 theElems,
675                     const TIDSortedElemSet&                                 theNodesNot,
676                     std::map< const SMDS_MeshNode*, const SMDS_MeshNode* >& theNodeNodeMap,
677                     const bool                                              theIsDoubleElem );
678
679 private:
680
681   SMESH_Mesh *            myMesh;
682
683   // Nodes and elements created during last operation
684   SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
685
686   // Description of error/warning occured during last operation
687   SMESH_ComputeErrorPtr   myError;
688 };
689
690 #endif