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