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