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