Salome HOME
020749: EDF 1291 SMESH : Create 2D Mesh from 3D improvement
[modules/smesh.git] / src / SMESH / SMESH_MeshEditor.hxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File      : SMESH_MeshEditor.hxx
25 // Created   : Mon Apr 12 14:56:19 2004
26 // Author    : Edward AGAPOV (eap)
27 // Module    : SMESH
28 //
29 #ifndef SMESH_MeshEditor_HeaderFile
30 #define SMESH_MeshEditor_HeaderFile
31
32 #include "SMESH_SMESH.hxx"
33
34 #include "SMDS_MeshElement.hxx"
35 #include "SMESH_Controls.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_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    * \retval 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    * \retval 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    * \retval 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    * \retval 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 structire 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    * (auxilary 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 cuurent 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 deleteing 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   // Converts all mesh to quadratic one, deletes old elements, replacing 
466   // them with quadratic ones with the same id.
467   // If theForce3d = 1; this results in the medium node lying at the 
468   // middle of the line segments connecting start and end node of a mesh 
469   // element
470   // If theForce3d = 0; this results in the medium node lying at the 
471   // geometrical edge from which the mesh element is built
472
473   bool ConvertFromQuadratic();
474   // Converts all mesh from quadratic to ordinary ones, deletes old quadratic elements, replacing 
475   // them with ordinary mesh elements with the same id.
476   // Returns true in case of success, false otherwise.
477
478   static void AddToSameGroups (const SMDS_MeshElement* elemToAdd,
479                                const SMDS_MeshElement* elemInGroups,
480                                SMESHDS_Mesh *          aMesh);
481   // Add elemToAdd to the all groups the elemInGroups belongs to
482
483   static void RemoveElemFromGroups (const SMDS_MeshElement* element,
484                                     SMESHDS_Mesh *          aMesh);
485   // remove element from the all groups
486
487   static void ReplaceElemInGroups (const SMDS_MeshElement* elemToRm,
488                                    const SMDS_MeshElement* elemToAdd,
489                                    SMESHDS_Mesh *          aMesh);
490   // replace elemToRm by elemToAdd in the all groups
491
492   static void ReplaceElemInGroups (const SMDS_MeshElement*                     elemToRm,
493                                    const std::vector<const SMDS_MeshElement*>& elemToAdd,
494                                    SMESHDS_Mesh *                              aMesh);
495   // replace elemToRm by elemToAdd in the all groups
496
497   /*!
498    * \brief Return nodes linked to the given one in elements of the type
499    */
500   static void GetLinkedNodes( const SMDS_MeshNode* node,
501                               TIDSortedElemSet &   linkedNodes,
502                               SMDSAbs_ElementType  type = SMDSAbs_All );
503
504   static const SMDS_MeshElement* FindFaceInSet(const SMDS_MeshNode*    n1,
505                                                const SMDS_MeshNode*    n2,
506                                                const TIDSortedElemSet& elemSet,
507                                                const TIDSortedElemSet& avoidSet,
508                                                int*                    i1=0,
509                                                int*                    i2=0);
510   // Return a face having linked nodes n1 and n2 and which is
511   // - not in avoidSet,
512   // - in elemSet provided that !elemSet.empty()
513   // i1 and i2 optionally returns indices of n1 and n2
514
515   /*!
516    * \brief Find corresponding nodes in two sets of faces 
517     * \param theSide1 - first face set
518     * \param theSide2 - second first face
519     * \param theFirstNode1 - a boundary node of set 1
520     * \param theFirstNode2 - a node of set 2 corresponding to theFirstNode1
521     * \param theSecondNode1 - a boundary node of set 1 linked with theFirstNode1
522     * \param theSecondNode2 - a node of set 2 corresponding to theSecondNode1
523     * \param nReplaceMap - output map of corresponding nodes
524     * \retval Sew_Error  - is a success or not
525    */
526   static Sew_Error FindMatchingNodes(std::set<const SMDS_MeshElement*>& theSide1,
527                                      std::set<const SMDS_MeshElement*>& theSide2,
528                                      const SMDS_MeshNode*               theFirstNode1,
529                                      const SMDS_MeshNode*               theFirstNode2,
530                                      const SMDS_MeshNode*               theSecondNode1,
531                                      const SMDS_MeshNode*               theSecondNode2,
532                                      TNodeNodeMap &                     theNodeReplaceMap);
533
534   /*!
535    * \brief Returns true if given node is medium
536     * \param n - node to check
537     * \param typeToCheck - type of elements containing the node to ask about node status
538     * \retval bool - check result
539    */
540   static bool IsMedium(const SMDS_MeshNode*      node,
541                        const SMDSAbs_ElementType typeToCheck = SMDSAbs_All);
542
543   int FindShape (const SMDS_MeshElement * theElem);
544   // Return an index of the shape theElem is on
545   // or zero if a shape not found
546
547   SMESH_Mesh * GetMesh() { return myMesh; }
548
549   SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
550
551   const SMESH_SequenceOfElemPtr& GetLastCreatedNodes() const { return myLastCreatedNodes; }
552
553   const SMESH_SequenceOfElemPtr& GetLastCreatedElems() const { return myLastCreatedElems; }
554
555   bool DoubleNodes( const std::list< int >& theListOfNodes, 
556                     const std::list< int >& theListOfModifiedElems );
557   
558   bool DoubleNodes( const TIDSortedElemSet& theElems, 
559                     const TIDSortedElemSet& theNodesNot,
560                     const TIDSortedElemSet& theAffectedElems );
561
562   bool DoubleNodesInRegion( const TIDSortedElemSet& theElems, 
563                             const TIDSortedElemSet& theNodesNot,
564                             const TopoDS_Shape&     theShape );
565   
566   bool DoubleNodesOnGroupBoundaries( const std::vector<TIDSortedElemSet>& theElems,
567                                      bool createJointElems);
568
569   /*!
570    * \brief Generated skin mesh (containing 2D cells) from 3D mesh
571    * The created 2D mesh elements based on nodes of free faces of boundary volumes
572    * \return TRUE if operation has been completed successfully, FALSE otherwise
573    */
574   bool Make2DMeshFrom3D();
575
576   enum Bnd_Dimension { BND_2DFROM3D, BND_1DFROM3D, BND_1DFROM2D };
577
578   int MakeBoundaryMesh(const TIDSortedElemSet& elements,
579                        Bnd_Dimension           dimension,
580                        SMESH_Group*            group = 0,
581                        SMESH_Mesh*             targetMesh = 0,
582                        bool                    toCopyElements = false,
583                        bool                    toCopyExistingBondary = false,
584                        bool                    toAddExistingBondary = false,
585                        bool                    aroundElements = false);
586
587
588  private:
589
590   /*!
591    * \brief Convert elements contained in a submesh to quadratic
592     * \retval int - nb of checked elements
593    */
594   int convertElemToQuadratic(SMESHDS_SubMesh *   theSm,
595                              SMESH_MesherHelper& theHelper,
596                              const bool          theForce3d);
597
598   /*!
599    * \brief Convert quadratic elements to linear ones and remove quadratic nodes
600     * \retval int - nb of checked elements
601    */
602   int removeQuadElem( SMESHDS_SubMesh *    theSm,
603                       SMDS_ElemIteratorPtr theItr,
604                       const int            theShapeID);
605   /*!
606    * \brief Create groups of elements made during transformation
607    * \param nodeGens - nodes making corresponding myLastCreatedNodes
608    * \param elemGens - elements making corresponding myLastCreatedElems
609    * \param postfix - to append to names of new groups
610    */
611   PGroupIDs generateGroups(const SMESH_SequenceOfElemPtr& nodeGens,
612                            const SMESH_SequenceOfElemPtr& elemGens,
613                            const std::string&             postfix,
614                            SMESH_Mesh*                    targetMesh=0);
615
616
617   typedef std::map<const SMDS_MeshNode*, std::list<const SMDS_MeshNode*> > TNodeOfNodeListMap;
618   typedef TNodeOfNodeListMap::iterator                                     TNodeOfNodeListMapItr;
619   typedef std::vector<TNodeOfNodeListMapItr>                               TVecOfNnlmiMap;
620   typedef std::map<const SMDS_MeshElement*, TVecOfNnlmiMap >               TElemOfVecOfNnlmiMap;
621
622   /*!
623    * \brief Create elements by sweeping an element
624     * \param elem - element to sweep
625     * \param newNodesItVec - nodes generated from each node of the element
626     * \param newElems - generated elements
627     * \param nbSteps - number of sweeping steps
628     * \param srcElements - to append elem for each generated element
629    */
630   void sweepElement(const SMDS_MeshElement*                    elem,
631                     const std::vector<TNodeOfNodeListMapItr> & newNodesItVec,
632                     std::list<const SMDS_MeshElement*>&        newElems,
633                     const int                                  nbSteps,
634                     SMESH_SequenceOfElemPtr&                   srcElements);
635
636   /*!
637    * \brief Create 1D and 2D elements around swept elements
638     * \param mapNewNodes - source nodes and ones generated from them
639     * \param newElemsMap - source elements and ones generated from them
640     * \param elemNewNodesMap - nodes generated from each node of each element
641     * \param elemSet - all swept elements
642     * \param nbSteps - number of sweeping steps
643     * \param srcElements - to append elem for each generated element
644    */
645   void makeWalls (TNodeOfNodeListMap &     mapNewNodes,
646                   TElemOfElemListMap &     newElemsMap,
647                   TElemOfVecOfNnlmiMap &   elemNewNodesMap,
648                   TIDSortedElemSet&        elemSet,
649                   const int                nbSteps,
650                   SMESH_SequenceOfElemPtr& srcElements);
651
652   struct SMESH_MeshEditor_PathPoint
653   {
654     gp_Pnt myPnt;
655     gp_Dir myTgt;
656     double myAngle, myPrm;
657
658     SMESH_MeshEditor_PathPoint(): myPnt(99., 99., 99.), myTgt(1.,0.,0.), myAngle(0), myPrm(0) {}
659     void          SetPnt      (const gp_Pnt& aP3D)  { myPnt  =aP3D; }
660     void          SetTangent  (const gp_Dir& aTgt)  { myTgt  =aTgt; }
661     void          SetAngle    (const double& aBeta) { myAngle=aBeta; }
662     void          SetParameter(const double& aPrm)  { myPrm  =aPrm; }
663     const gp_Pnt& Pnt         ()const               { return myPnt; }
664     const gp_Dir& Tangent     ()const               { return myTgt; }
665     double        Angle       ()const               { return myAngle; }
666     double        Parameter   ()const               { return myPrm; }
667   };
668   Extrusion_Error MakeEdgePathPoints(std::list<double>&                     aPrms,
669                                      const TopoDS_Edge&                     aTrackEdge,
670                                      bool                                   aFirstIsStart,
671                                      std::list<SMESH_MeshEditor_PathPoint>& aLPP);
672   Extrusion_Error MakeExtrElements(TIDSortedElemSet&                      theElements,
673                                    std::list<SMESH_MeshEditor_PathPoint>& theFullList,
674                                    const bool                             theHasAngles,
675                                    std::list<double>&                     theAngles,
676                                    const bool                             theLinearVariation,
677                                    const bool                             theHasRefPoint,
678                                    const gp_Pnt&                          theRefPoint,
679                                    const bool                             theMakeGroups);
680   void LinearAngleVariation(const int     NbSteps,
681                             list<double>& theAngles);
682
683   bool doubleNodes( SMESHDS_Mesh*                                           theMeshDS,
684                     const TIDSortedElemSet&                                 theElems,
685                     const TIDSortedElemSet&                                 theNodesNot,
686                     std::map< const SMDS_MeshNode*, const SMDS_MeshNode* >& theNodeNodeMap,
687                     const bool                                              theIsDoubleElem );
688
689 private:
690
691   SMESH_Mesh * myMesh;
692
693   /*!
694    * Sequence for keeping nodes created during last operation
695    */
696   SMESH_SequenceOfElemPtr myLastCreatedNodes;
697
698   /*!
699    * Sequence for keeping elements created during last operation
700    */
701   SMESH_SequenceOfElemPtr myLastCreatedElems;
702
703 };
704
705 #endif