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