Salome HOME
1dbed7d991705c59321a0e935eb31bc9a5a09022
[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                             bool                 theSeparateCornersAndMedium);
445   // Return list of group of nodes close to each other within theTolerance.
446   // Search among theNodes or in the whole mesh if theNodes is empty.
447
448   void MergeNodes (TListOfListOfNodes & theNodeGroups);
449   // In each group, the cdr of nodes are substituted by the first one
450   // in all elements.
451
452   typedef std::list< std::list< int > > TListOfListOfElementsID;
453
454   void FindEqualElements(TIDSortedElemSet &        theElements,
455                          TListOfListOfElementsID & theGroupsOfElementsID);
456   // Return list of group of elements build on the same nodes.
457   // Search among theElements or in the whole mesh if theElements is empty.
458
459   void MergeElements(TListOfListOfElementsID & theGroupsOfElementsID);
460   // In each group remove all but first of elements.
461
462   void MergeEqualElements();
463   // Remove all but one of elements built on the same nodes.
464   // Return nb of successfully merged groups.
465
466   int SimplifyFace (const std::vector<const SMDS_MeshNode *>& faceNodes,
467                     std::vector<const SMDS_MeshNode *>&       poly_nodes,
468                     std::vector<int>&                         quantities) const;
469   // Split face, defined by <faceNodes>, into several faces by repeating nodes.
470   // Is used by MergeNodes()
471
472   static bool CheckFreeBorderNodes(const SMDS_MeshNode* theNode1,
473                                    const SMDS_MeshNode* theNode2,
474                                    const SMDS_MeshNode* theNode3 = 0);
475   // Return true if the three nodes are on a free border
476
477   static bool FindFreeBorder (const SMDS_MeshNode*                  theFirstNode,
478                               const SMDS_MeshNode*                  theSecondNode,
479                               const SMDS_MeshNode*                  theLastNode,
480                               std::list< const SMDS_MeshNode* > &   theNodes,
481                               std::list< const SMDS_MeshElement* >& theFaces);
482   // Return nodes and faces of a free border if found 
483
484   enum Sew_Error {
485     SEW_OK,
486     // for SewFreeBorder()
487     SEW_BORDER1_NOT_FOUND,
488     SEW_BORDER2_NOT_FOUND,
489     SEW_BOTH_BORDERS_NOT_FOUND,
490     SEW_BAD_SIDE_NODES,
491     SEW_VOLUMES_TO_SPLIT,
492     // for SewSideElements()
493     SEW_DIFF_NB_OF_ELEMENTS,
494     SEW_TOPO_DIFF_SETS_OF_ELEMENTS,
495     SEW_BAD_SIDE1_NODES,
496     SEW_BAD_SIDE2_NODES,
497     SEW_INTERNAL_ERROR
498     };
499     
500
501   Sew_Error SewFreeBorder (const SMDS_MeshNode* theBorderFirstNode,
502                            const SMDS_MeshNode* theBorderSecondNode,
503                            const SMDS_MeshNode* theBorderLastNode,
504                            const SMDS_MeshNode* theSide2FirstNode,
505                            const SMDS_MeshNode* theSide2SecondNode,
506                            const SMDS_MeshNode* theSide2ThirdNode = 0,
507                            const bool           theSide2IsFreeBorder = true,
508                            const bool           toCreatePolygons = false,
509                            const bool           toCreatePolyedrs = false);
510   // Sew the free border to the side2 by replacing nodes in
511   // elements on the free border with nodes of the elements
512   // of the side 2. If nb of links in the free border and
513   // between theSide2FirstNode and theSide2LastNode are different,
514   // additional nodes are inserted on a link provided that no
515   // volume elements share the splitted link.
516   // The side 2 is a free border if theSide2IsFreeBorder == true.
517   // Sewing is peformed between the given first, second and last
518   // nodes on the sides.
519   // theBorderFirstNode is merged with theSide2FirstNode.
520   // if (!theSide2IsFreeBorder) then theSide2SecondNode gives
521   // the last node on the side 2, which will be merged with
522   // theBorderLastNode.
523   // if (theSide2IsFreeBorder) then theSide2SecondNode will
524   // be merged with theBorderSecondNode.
525   // if (theSide2IsFreeBorder && theSide2ThirdNode == 0) then
526   // the 2 free borders are sewn link by link and no additional
527   // nodes are inserted.
528   // Return false, if sewing failed.
529
530   Sew_Error SewSideElements (TIDSortedElemSet&    theSide1,
531                              TIDSortedElemSet&    theSide2,
532                              const SMDS_MeshNode* theFirstNode1ToMerge,
533                              const SMDS_MeshNode* theFirstNode2ToMerge,
534                              const SMDS_MeshNode* theSecondNode1ToMerge,
535                              const SMDS_MeshNode* theSecondNode2ToMerge);
536   // Sew two sides of a mesh. Nodes belonging to theSide1 are
537   // merged with nodes of elements of theSide2.
538   // Number of elements in theSide1 and in theSide2 must be
539   // equal and they should have similar node connectivity.
540   // The nodes to merge should belong to side s borders and
541   // the first node should be linked to the second.
542
543   void InsertNodesIntoLink(const SMDS_MeshElement*          theFace,
544                            const SMDS_MeshNode*             theBetweenNode1,
545                            const SMDS_MeshNode*             theBetweenNode2,
546                            std::list<const SMDS_MeshNode*>& theNodesToInsert,
547                            const bool                       toCreatePoly = false);
548   // insert theNodesToInsert into theFace between theBetweenNode1 and theBetweenNode2.
549   // If toCreatePoly is true, replace theFace by polygon, else split theFace.
550
551   void UpdateVolumes (const SMDS_MeshNode*             theBetweenNode1,
552                       const SMDS_MeshNode*             theBetweenNode2,
553                       std::list<const SMDS_MeshNode*>& theNodesToInsert);
554   // insert theNodesToInsert into all volumes, containing link
555   // theBetweenNode1 - theBetweenNode2, between theBetweenNode1 and theBetweenNode2.
556
557   void ConvertToQuadratic(const bool theForce3d, const bool theToBiQuad);
558   void ConvertToQuadratic(const bool theForce3d,
559                           TIDSortedElemSet& theElements, const bool theToBiQuad);
560   // Converts all mesh to quadratic or bi-quadratic one, deletes old elements, 
561   // replacing them with quadratic or bi-quadratic ones with the same id.
562   // If theForce3d = 1; this results in the medium node lying at the 
563   // middle of the line segments connecting start and end node of a mesh element.
564   // If theForce3d = 0; this results in the medium node lying at the 
565   // geometrical edge from which the mesh element is built.
566
567   bool ConvertFromQuadratic();
568   void ConvertFromQuadratic(TIDSortedElemSet& theElements);
569   // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing 
570   // them with ordinary mesh elements with the same id.
571   // Returns true in case of success, false otherwise.
572
573   static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
574                                const SMDS_MeshElement* elemInGroups,
575                                SMESHDS_Mesh *          aMesh);
576   // Add elemToAdd to the all groups the elemInGroups belongs to
577
578   static void RemoveElemFromGroups (const SMDS_MeshElement* element,
579                                     SMESHDS_Mesh *          aMesh);
580   // remove element from the all groups
581
582   static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
583                                    const SMDS_MeshElement* elemToAdd,
584                                    SMESHDS_Mesh *          aMesh);
585   // replace elemToRm by elemToAdd in the all groups
586
587   static void ReplaceElemInGroups (const SMDS_MeshElement*                     elemToRm,
588                                    const std::vector<const SMDS_MeshElement*>& elemToAdd,
589                                    SMESHDS_Mesh *                              aMesh);
590   // replace elemToRm by elemToAdd in the all groups
591
592   /*!
593    * \brief Return nodes linked to the given one in elements of the type
594    */
595   static void GetLinkedNodes( const SMDS_MeshNode* node,
596                               TIDSortedElemSet &   linkedNodes,
597                               SMDSAbs_ElementType  type = SMDSAbs_All );
598
599   /*!
600    * \brief Find corresponding nodes in two sets of faces 
601     * \param theSide1 - first face set
602     * \param theSide2 - second first face
603     * \param theFirstNode1 - a boundary node of set 1
604     * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
605     * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
606     * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
607     * \param nReplaceMap - output map of corresponding nodes
608     * \return Sew_Error  - is a success or not
609    */
610   static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
611                                      std::set<const SMDS_MeshElement*>& theSide2,
612                                      const SMDS_MeshNode*               theFirstNode1,
613                                      const SMDS_MeshNode*               theFirstNode2,
614                                      const SMDS_MeshNode*               theSecondNode1,
615                                      const SMDS_MeshNode*               theSecondNode2,
616                                      TNodeNodeMap &                     theNodeReplaceMap);
617
618   /*!
619    * \brief Returns true if given node is medium
620     * \param n - node to check
621     * \param typeToCheck - type of elements containing the node to ask about node status
622     * \return bool - check result
623    */
624   static bool IsMedium(const SMDS_MeshNode*      node,
625                        const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
626
627   int FindShape (const SMDS_MeshElement * theElem);
628   // Return an index of the shape theElem is on
629   // or zero if a shape not found
630
631   void DoubleElements( const TIDSortedElemSet& theElements );
632
633   bool DoubleNodes( const std::list< int >& theListOfNodes, 
634                     const std::list< int >& theListOfModifiedElems );
635   
636   bool DoubleNodes( const TIDSortedElemSet& theElems, 
637                     const TIDSortedElemSet& theNodesNot,
638                     const TIDSortedElemSet& theAffectedElems );
639
640   bool AffectedElemGroupsInRegion( const TIDSortedElemSet& theElems,
641                                    const TIDSortedElemSet& theNodesNot,
642                                    const TopoDS_Shape&     theShape,
643                                    TIDSortedElemSet& theAffectedElems);
644
645   bool DoubleNodesInRegion( const TIDSortedElemSet& theElems, 
646                             const TIDSortedElemSet& theNodesNot,
647                             const TopoDS_Shape&     theShape );
648   
649   double OrientedAngle(const gp_Pnt& p0, const gp_Pnt& p1, const gp_Pnt& g1, const gp_Pnt& g2);
650
651   bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
652                                      bool                                 createJointElems,
653                                      bool                                 onAllBoundaries);
654
655   bool CreateFlatElementsOnFacesGroups( const std::vector<TIDSortedElemSet>& theElems );
656
657   void CreateHoleSkin(double radius,
658                       const TopoDS_Shape& theShape,
659                       SMESH_NodeSearcher* theNodeSearcher,
660                       const char* groupName,
661                       std::vector<double>&   nodesCoords,
662                       std::vector<std::vector<int> >& listOfListOfNodes);
663
664   /*!
665    * \brief Generated skin mesh (containing 2D cells) from 3D mesh
666    * The created 2D mesh elements based on nodes of free faces of boundary volumes
667    * \return TRUE if operation has been completed successfully, FALSE otherwise
668    */
669   bool Make2DMeshFrom3D();
670
671   enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
672
673   int MakeBoundaryMesh(const TIDSortedElemSet& elements,
674                        Bnd_Dimension           dimension,
675                        SMESH_Group*            group = 0,
676                        SMESH_Mesh*             targetMesh = 0,
677                        bool                    toCopyElements = false,
678                        bool                    toCopyExistingBondary = false,
679                        bool                    toAddExistingBondary = false,
680                        bool                    aroundElements = false);
681
682  private:
683
684   /*!
685    * \brief Convert elements contained in a submesh to quadratic
686    * \return int - nb of checked elements
687    */
688   int convertElemToQuadratic(SMESHDS_SubMesh *   theSm,
689                              SMESH_MesherHelper& theHelper,
690                              const bool          theForce3d);
691
692   /*!
693    * \brief Convert quadratic elements to linear ones and remove quadratic nodes
694    * \return nb of checked elements
695    */
696   int removeQuadElem( SMESHDS_SubMesh *    theSm,
697                       SMDS_ElemIteratorPtr theItr,
698                       const int            theShapeID);
699   /*!
700    * \brief Create groups of elements made during transformation
701    * \param nodeGens - nodes making corresponding myLastCreatedNodes
702    * \param elemGens - elements making corresponding myLastCreatedElems
703    * \param postfix - to append to names of new groups
704    * \param targetMesh - mesh to create groups in
705    * \param topPresent - is there "top" elements that are created by sweeping
706    */
707   PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
708                            const SMESH_SequenceOfElemPtr& elemGens,
709                            const std::string&             postfix,
710                            SMESH_Mesh*                    targetMesh=0,
711                            const bool                     topPresent=true);
712   /*!
713    * \brief Create elements by sweeping an element
714    * \param elem - element to sweep
715    * \param newNodesItVec - nodes generated from each node of the element
716    * \param newElems - generated elements
717    * \param nbSteps - number of sweeping steps
718    * \param srcElements - to append elem for each generated element
719    */
720   void sweepElement(const SMDS_MeshElement*                    elem,
721                     const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
722                     std::list<const SMDS_MeshElement*>&        newElems,
723                     const int                                  nbSteps,
724                     SMESH_SequenceOfElemPtr&                   srcElements);
725
726   /*!
727    * \brief Create 1D and 2D elements around swept elements
728    * \param mapNewNodes - source nodes and ones generated from them
729    * \param newElemsMap - source elements and ones generated from them
730    * \param elemNewNodesMap - nodes generated from each node of each element
731    * \param elemSet - all swept elements
732    * \param nbSteps - number of sweeping steps
733    * \param srcElements - to append elem for each generated element
734    */
735   void makeWalls (TNodeOfNodeListMap &     mapNewNodes,
736                   TTElemOfElemListMap &    newElemsMap,
737                   TElemOfVecOfNnlmiMap &   elemNewNodesMap,
738                   TIDSortedElemSet&        elemSet,
739                   const int                nbSteps,
740                   SMESH_SequenceOfElemPtr& srcElements);
741
742   struct SMESH_MeshEditor_PathPoint
743   {
744     gp_Pnt myPnt;
745     gp_Dir myTgt;
746     double myAngle, myPrm;
747
748     SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
749     void          SetPnt      (const gp_Pnt& aP3D)  { myPnt  =aP3D; }
750     void          SetTangent  (const gp_Dir& aTgt)  { myTgt  =aTgt; }
751     void          SetAngle    (const double& aBeta) { myAngle=aBeta; }
752     void          SetParameter(const double& aPrm)  { myPrm  =aPrm; }
753     const gp_Pnt& Pnt         ()const               { return myPnt; }
754     const gp_Dir& Tangent     ()const               { return myTgt; }
755     double        Angle       ()const               { return myAngle; }
756     double        Parameter   ()const               { return myPrm; }
757   };
758   Extrusion_Error MakeEdgePathPoints(std::list<double>&                     aPrms,
759                                      const TopoDS_Edge&                     aTrackEdge,
760                                      bool                                   aFirstIsStart,
761                                      std::list<SMESH_MeshEditor_PathPoint>& aLPP);
762   Extrusion_Error MakeExtrElements(TIDSortedElemSet                       theElements[2],
763                                    std::list<SMESH_MeshEditor_PathPoint>& theFullList,
764                                    const bool                             theHasAngles,
765                                    std::list<double>&                     theAngles,
766                                    const bool                             theLinearVariation,
767                                    const bool                             theHasRefPoint,
768                                    const gp_Pnt&                          theRefPoint,
769                                    const bool                             theMakeGroups);
770   void LinearAngleVariation(const int     NbSteps,
771                             list<double>& theAngles);
772
773   bool doubleNodes( SMESHDS_Mesh*           theMeshDS,
774                     const TIDSortedElemSet& theElems,
775                     const TIDSortedElemSet& theNodesNot,
776                     TNodeNodeMap&           theNodeNodeMap,
777                     const bool              theIsDoubleElem );
778
779   void copyPosition( const SMDS_MeshNode* from,
780                      const SMDS_MeshNode* to );
781
782 private:
783
784   SMESH_Mesh *            myMesh;
785
786   // Nodes and elements created during last operation
787   SMESH_SequenceOfElemPtr myLastCreatedNodes, myLastCreatedElems;
788
789   // Description of error/warning occured during last operation
790   SMESH_ComputeErrorPtr   myError;
791 };
792
793 #endif