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