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