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