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