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