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