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