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