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