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