Salome HOME
68331f6634d0bb84a395ff5ade188e719253cfdb
[modules/smesh.git] / src / SMESH / SMESH_MesherHelper.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:      SMESH_MesherHelper.cxx
21 // Created:   15.02.06 15:22:41
22 // Author:    Sergey KUUL
23 // Copyright: Open CASCADE 2006
24
25
26 #include "SMESH_MesherHelper.hxx"
27
28 #include "SMDS_FacePosition.hxx" 
29 #include "SMDS_EdgePosition.hxx"
30 #include "SMESH_MeshEditor.hxx"
31
32 #include <BRepAdaptor_Surface.hxx>
33 #include <BRepTools.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRepTools_WireExplorer.hxx>
36 #include <Geom2d_Curve.hxx>
37 #include <Geom_Curve.hxx>
38 #include <Geom_Surface.hxx>
39 #include <ShapeAnalysis.hxx>
40 #include <TopExp.hxx>
41 #include <TopExp_Explorer.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 #include <TopTools_MapOfShape.hxx>
44 #include <TopoDS.hxx>
45 #include <gp_Pnt2d.hxx>
46
47 #include <Standard_Failure.hxx>
48 #include <Standard_ErrorHandler.hxx>
49
50 #include <utilities.h>
51
52 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
53
54 //================================================================================
55 /*!
56  * \brief Constructor
57  */
58 //================================================================================
59
60 SMESH_MesherHelper::SMESH_MesherHelper(SMESH_Mesh& theMesh)
61   : myMesh(&theMesh), myShapeID(-1), myCreateQuadratic(false)
62 {
63   mySetElemOnShape = ( ! myMesh->HasShapeToMesh() );
64 }
65
66 //=======================================================================
67 //function : CheckShape
68 //purpose  : 
69 //=======================================================================
70
71 bool SMESH_MesherHelper::IsQuadraticSubMesh(const TopoDS_Shape& aSh)
72 {
73   SMESHDS_Mesh* meshDS = GetMeshDS();
74   // we can create quadratic elements only if all elements
75   // created on subshapes of given shape are quadratic
76   // also we have to fill myNLinkNodeMap
77   myCreateQuadratic = true;
78   mySeamShapeIds.clear();
79   myDegenShapeIds.clear();
80   TopAbs_ShapeEnum subType( aSh.ShapeType()==TopAbs_FACE ? TopAbs_EDGE : TopAbs_FACE );
81   SMDSAbs_ElementType elemType( subType==TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge );
82
83   TopExp_Explorer exp( aSh, subType );
84   for (; exp.More() && myCreateQuadratic; exp.Next()) {
85     if ( SMESHDS_SubMesh * subMesh = meshDS->MeshElements( exp.Current() )) {
86       if ( SMDS_ElemIteratorPtr it = subMesh->GetElements() ) {
87         while(it->more()) {
88           const SMDS_MeshElement* e = it->next();
89           if ( e->GetType() != elemType || !e->IsQuadratic() ) {
90             myCreateQuadratic = false;
91             break;
92           }
93           else {
94             // fill NLinkNodeMap
95             switch ( e->NbNodes() ) {
96             case 3:
97               AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(2)); break;
98             case 6:
99               AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(3));
100               AddNLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(4));
101               AddNLinkNode(e->GetNode(2),e->GetNode(0),e->GetNode(5)); break;
102             case 8:
103               AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(4));
104               AddNLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(5));
105               AddNLinkNode(e->GetNode(2),e->GetNode(3),e->GetNode(6));
106               AddNLinkNode(e->GetNode(3),e->GetNode(0),e->GetNode(7));
107               break;
108             default:
109               myCreateQuadratic = false;
110               break;
111             }
112           }
113         }
114       }
115     }
116   }
117
118   if(!myCreateQuadratic) {
119     myNLinkNodeMap.clear();
120   }
121   SetSubShape( aSh );
122
123   return myCreateQuadratic;
124 }
125
126 //================================================================================
127 /*!
128  * \brief Set geomerty to make elements on
129   * \param aSh - geomertic shape
130  */
131 //================================================================================
132
133 void SMESH_MesherHelper::SetSubShape(const int aShID)
134 {
135   if ( aShID == myShapeID )
136     return;
137   if ( aShID > 1 )
138     SetSubShape( GetMeshDS()->IndexToShape( aShID ));
139   else
140     SetSubShape( TopoDS_Shape() );
141 }
142
143 //================================================================================
144 /*!
145  * \brief Set geomerty to make elements on
146   * \param aSh - geomertic shape
147  */
148 //================================================================================
149
150 void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh)
151 {
152   if ( myShape.IsSame( aSh ))
153     return;
154
155   myShape = aSh;
156   mySeamShapeIds.clear();
157   myDegenShapeIds.clear();
158
159   if ( myShape.IsNull() ) {
160     myShapeID  = -1;
161     return;
162   }
163   SMESHDS_Mesh* meshDS = GetMeshDS();
164   myShapeID = meshDS->ShapeToIndex(aSh);
165
166   // treatment of periodic faces
167   for ( TopExp_Explorer eF( aSh, TopAbs_FACE ); eF.More(); eF.Next() )
168   {
169     const TopoDS_Face& face = TopoDS::Face( eF.Current() );
170     BRepAdaptor_Surface surface( face );
171     if ( surface.IsUPeriodic() || surface.IsVPeriodic() )
172     {
173       for (TopExp_Explorer exp( face, TopAbs_EDGE ); exp.More(); exp.Next())
174       {
175         // look for a seam edge
176         const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() );
177         if ( BRep_Tool::IsClosed( edge, face )) {
178           // initialize myPar1, myPar2 and myParIndex
179           if ( mySeamShapeIds.empty() ) {
180             gp_Pnt2d uv1, uv2;
181             BRep_Tool::UVPoints( edge, face, uv1, uv2 );
182             if ( Abs( uv1.Coord(1) - uv2.Coord(1) ) < Abs( uv1.Coord(2) - uv2.Coord(2) ))
183             {
184               myParIndex = 1; // U periodic
185               myPar1 = surface.FirstUParameter();
186               myPar2 = surface.LastUParameter();
187             }
188             else {
189               myParIndex = 2;  // V periodic
190               myPar1 = surface.FirstVParameter();
191               myPar2 = surface.LastVParameter();
192             }
193           }
194           // store seam shape indices, negative if shape encounters twice
195           int edgeID = meshDS->ShapeToIndex( edge );
196           mySeamShapeIds.insert( IsSeamShape( edgeID ) ? -edgeID : edgeID );
197           for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() ) {
198             int vertexID = meshDS->ShapeToIndex( v.Current() );
199             mySeamShapeIds.insert( IsSeamShape( vertexID ) ? -vertexID : vertexID );
200           }
201         }
202
203         // look for a degenerated edge
204         if ( BRep_Tool::Degenerated( edge )) {
205           myDegenShapeIds.insert( meshDS->ShapeToIndex( edge ));
206           for ( TopExp_Explorer v( edge, TopAbs_VERTEX ); v.More(); v.Next() )
207             myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() ));
208         }
209       }
210     }
211   }
212 }
213
214 //================================================================================
215   /*!
216    * \brief Check if inFaceNode argument is necessary for call GetNodeUV(F,..)
217     * \param F - the face
218     * \retval bool - return true if the face is periodic
219    */
220 //================================================================================
221
222 bool SMESH_MesherHelper::GetNodeUVneedInFaceNode(const TopoDS_Face& F) const
223 {
224   if ( F.IsNull() ) return !mySeamShapeIds.empty();
225
226   if ( !F.IsNull() && !myShape.IsNull() && myShape.IsSame( F ))
227     return !mySeamShapeIds.empty();
228
229   Handle(Geom_Surface) aSurface = BRep_Tool::Surface( F );
230   if ( !aSurface.IsNull() )
231     return ( aSurface->IsUPeriodic() || aSurface->IsVPeriodic() );
232
233   return false;
234 }
235
236 //=======================================================================
237 //function : IsMedium
238 //purpose  : 
239 //=======================================================================
240
241 bool SMESH_MesherHelper::IsMedium(const SMDS_MeshNode*      node,
242                                  const SMDSAbs_ElementType typeToCheck)
243 {
244   return SMESH_MeshEditor::IsMedium( node, typeToCheck );
245 }
246
247 //=======================================================================
248 //function : AddNLinkNode
249 //purpose  : 
250 //=======================================================================
251 /*!
252  * Auxilary function for filling myNLinkNodeMap
253  */
254 void SMESH_MesherHelper::AddNLinkNode(const SMDS_MeshNode* n1,
255                                      const SMDS_MeshNode* n2,
256                                      const SMDS_MeshNode* n12)
257 {
258   NLink link( n1, n2 );
259   if ( n1 > n2 ) link = NLink( n2, n1 );
260   // add new record to map
261   myNLinkNodeMap.insert( make_pair(link,n12));
262 }
263
264 //=======================================================================
265 /*!
266  * \brief Select UV on either of 2 pcurves of a seam edge, closest to the given UV
267  * \param uv1 - UV on the seam
268  * \param uv2 - UV within a face
269  * \retval gp_Pnt2d - selected UV
270  */
271 //=======================================================================
272
273 gp_Pnt2d SMESH_MesherHelper::GetUVOnSeam( const gp_Pnt2d& uv1, const gp_Pnt2d& uv2 ) const
274 {
275   double p1 = uv1.Coord( myParIndex );
276   double p2 = uv2.Coord( myParIndex );
277   double p3 = ( Abs( p1 - myPar1 ) < Abs( p1 - myPar2 )) ? myPar2 : myPar1;
278   if ( Abs( p2 - p1 ) > Abs( p2 - p3 ))
279     p1 = p3;
280   gp_Pnt2d result = uv1;
281   result.SetCoord( myParIndex, p1 );
282   return result;
283 }
284
285 //=======================================================================
286 /*!
287  * \brief Return node UV on face
288  * \param F - the face
289  * \param n - the node
290  * \param n2 - a node of element being created located inside a face
291  * \retval gp_XY - resulting UV
292  * 
293  * Auxilary function called form GetMediumNode()
294  */
295 //=======================================================================
296
297 gp_XY SMESH_MesherHelper::GetNodeUV(const TopoDS_Face&   F,
298                                     const SMDS_MeshNode* n,
299                                     const SMDS_MeshNode* n2) const
300 {
301   gp_Pnt2d uv( 1e100, 1e100 );
302   const SMDS_PositionPtr Pos = n->GetPosition();
303   if(Pos->GetTypeOfPosition()==SMDS_TOP_FACE)
304   {
305     // node has position on face
306     const SMDS_FacePosition* fpos =
307       static_cast<const SMDS_FacePosition*>(n->GetPosition().get());
308     uv = gp_Pnt2d(fpos->GetUParameter(),fpos->GetVParameter());
309   }
310   else if(Pos->GetTypeOfPosition()==SMDS_TOP_EDGE)
311   {
312     // node has position on edge => it is needed to find
313     // corresponding edge from face, get pcurve for this
314     // edge and recieve value from this pcurve
315     const SMDS_EdgePosition* epos =
316       static_cast<const SMDS_EdgePosition*>(n->GetPosition().get());
317     SMESHDS_Mesh* meshDS = GetMeshDS();
318     int edgeID = Pos->GetShapeId();
319     TopoDS_Edge E = TopoDS::Edge(meshDS->IndexToShape(edgeID));
320     double f, l;
321     TopLoc_Location loc;
322     Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l);
323     uv = C2d->Value( epos->GetUParameter() );
324     // for a node on a seam edge select one of UVs on 2 pcurves
325     if ( n2 && IsSeamShape( edgeID ) )
326       uv = GetUVOnSeam( uv, GetNodeUV( F, n2, 0 ));
327   }
328   else if(Pos->GetTypeOfPosition()==SMDS_TOP_VERTEX)
329   {
330     if ( int vertexID = n->GetPosition()->GetShapeId() ) {
331       bool ok = true;
332       const TopoDS_Vertex& V = TopoDS::Vertex(GetMeshDS()->IndexToShape(vertexID));
333       try {
334         uv = BRep_Tool::Parameters( V, F );
335       }
336       catch (Standard_Failure& exc) {
337         ok = false;
338       }
339       if ( !ok ) {
340         for ( TopExp_Explorer vert(F,TopAbs_VERTEX); !ok && vert.More(); vert.Next() )
341           ok = ( V == vert.Current() );
342         if ( !ok ) {
343 #ifdef _DEBUG_
344           MESSAGE ( "SMESH_MesherHelper::GetNodeUV(); Vertex " << vertexID
345                << " not in face " << GetMeshDS()->ShapeToIndex( F ) );
346 #endif
347           // get UV of a vertex closest to the node
348           double dist = 1e100;
349           gp_Pnt pn ( n->X(),n->Y(),n->Z() );
350           for ( TopExp_Explorer vert(F,TopAbs_VERTEX); !ok && vert.More(); vert.Next() ) {
351             TopoDS_Vertex curV = TopoDS::Vertex( vert.Current() );
352             gp_Pnt p = BRep_Tool::Pnt( curV );
353             double curDist = p.SquareDistance( pn );
354             if ( curDist < dist ) {
355               dist = curDist;
356               uv = BRep_Tool::Parameters( curV, F );
357               if ( dist < DBL_MIN ) break;
358             }
359           }
360         }
361         else {
362           TopTools_ListIteratorOfListOfShape it( myMesh->GetAncestors( V ));
363           for ( ; it.More(); it.Next() ) {
364             if ( it.Value().ShapeType() == TopAbs_EDGE ) {
365               const TopoDS_Edge & edge = TopoDS::Edge( it.Value() );
366               double f,l;
367               Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edge, F, f, l);
368               if ( !C2d.IsNull() ) {
369                 double u = ( V == TopExp::FirstVertex( edge ) ) ?  f : l;
370                 uv = C2d->Value( u );
371                 break;
372               }
373             }
374           }
375         }
376       }
377       if ( n2 && IsSeamShape( vertexID ) )
378         uv = GetUVOnSeam( uv, GetNodeUV( F, n2, 0 ));
379     }
380   }
381   return uv.XY();
382 }
383
384 //=======================================================================
385 /*!
386  * \brief Return node U on edge
387  * \param E - the Edge
388  * \param n - the node
389  * \retval double - resulting U
390  * 
391  * Auxilary function called form GetMediumNode()
392  */
393 //=======================================================================
394
395 double SMESH_MesherHelper::GetNodeU(const TopoDS_Edge&   E,
396                                     const SMDS_MeshNode* n)
397 {
398   double param = 0;
399   const SMDS_PositionPtr Pos = n->GetPosition();
400   if(Pos->GetTypeOfPosition()==SMDS_TOP_EDGE) {
401     const SMDS_EdgePosition* epos =
402       static_cast<const SMDS_EdgePosition*>(n->GetPosition().get());
403     param =  epos->GetUParameter();
404   }
405   else if(Pos->GetTypeOfPosition()==SMDS_TOP_VERTEX) {
406     SMESHDS_Mesh * meshDS = GetMeshDS();
407     int vertexID = n->GetPosition()->GetShapeId();
408     const TopoDS_Vertex& V = TopoDS::Vertex(meshDS->IndexToShape(vertexID));
409     param =  BRep_Tool::Parameter( V, E );
410   }
411   return param;
412 }
413
414 //=======================================================================
415 //function : GetMediumNode
416 //purpose  : 
417 //=======================================================================
418 /*!
419  * Special function for search or creation medium node
420  */
421 const SMDS_MeshNode* SMESH_MesherHelper::GetMediumNode(const SMDS_MeshNode* n1,
422                                                        const SMDS_MeshNode* n2,
423                                                        bool force3d)
424 {
425   TopAbs_ShapeEnum shapeType = myShape.IsNull() ? TopAbs_SHAPE : myShape.ShapeType();
426
427   NLink link(( n1 < n2 ? n1 : n2 ), ( n1 < n2 ? n2 : n1 ));
428   ItNLinkNode itLN = myNLinkNodeMap.find( link );
429   if ( itLN != myNLinkNodeMap.end() ) {
430     return (*itLN).second;
431   }
432   else {
433     // create medium node
434     SMDS_MeshNode* n12;
435     SMESHDS_Mesh* meshDS = GetMeshDS();
436     int faceID = -1, edgeID = -1;
437     const SMDS_PositionPtr Pos1 = n1->GetPosition();
438     const SMDS_PositionPtr Pos2 = n2->GetPosition();
439   
440     if( myShape.IsNull() )
441     {
442       if( Pos1->GetTypeOfPosition()==SMDS_TOP_FACE ) {
443         faceID = Pos1->GetShapeId();
444       }
445       else if( Pos2->GetTypeOfPosition()==SMDS_TOP_FACE ) {
446         faceID = Pos2->GetShapeId();
447       }
448
449       if( Pos1->GetTypeOfPosition()==SMDS_TOP_EDGE ) {
450         edgeID = Pos1->GetShapeId();
451       }
452       if( Pos2->GetTypeOfPosition()==SMDS_TOP_EDGE ) {
453         edgeID = Pos2->GetShapeId();
454       }
455     }
456
457     if(!force3d) {
458       // we try to create medium node using UV parameters of
459       // nodes, else - medium between corresponding 3d points
460       if(faceID>-1 || shapeType == TopAbs_FACE) {
461         // obtaining a face and 2d points for nodes
462         TopoDS_Face F;
463         if( myShape.IsNull() )
464           F = TopoDS::Face(meshDS->IndexToShape(faceID));
465         else {
466           F = TopoDS::Face(myShape);
467           faceID = myShapeID;
468         }
469
470         gp_XY p1 = GetNodeUV(F,n1,n2);
471         gp_XY p2 = GetNodeUV(F,n2,n1);
472
473         //checking if surface is periodic
474         Handle(Geom_Surface) S = BRep_Tool::Surface(F);
475         Standard_Real UF,UL,VF,VL;
476         S->Bounds(UF,UL,VF,VL);
477
478         Standard_Real u,v;
479         Standard_Boolean isUPeriodic = S->IsUPeriodic();
480         if(isUPeriodic) {
481           Standard_Real UPeriod = S->UPeriod();
482           Standard_Real p2x = p2.X()+ShapeAnalysis::AdjustByPeriod(p2.X(),p1.X(),UPeriod);
483           Standard_Real pmid = (p1.X()+p2x)/2.;
484           u = pmid+ShapeAnalysis::AdjustToPeriod(pmid,UF,UL);
485         }
486         else 
487           u= (p1.X()+p2.X())/2.;
488
489         Standard_Boolean isVPeriodic = S->IsVPeriodic();
490         if(isVPeriodic) {
491           Standard_Real VPeriod = S->VPeriod();
492           Standard_Real p2y = p2.Y()+ShapeAnalysis::AdjustByPeriod(p2.Y(),p1.Y(),VPeriod);
493           Standard_Real pmid = (p1.Y()+p2y)/2.;
494           v = pmid+ShapeAnalysis::AdjustToPeriod(pmid,VF,VL);
495         }
496         else
497           v = (p1.Y()+p2.Y())/2.;
498
499         gp_Pnt P = S->Value(u, v);
500         n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
501         meshDS->SetNodeOnFace(n12, faceID, u, v);
502         myNLinkNodeMap.insert(NLinkNodeMap::value_type(link,n12));
503         return n12;
504       }
505       if (edgeID>-1 || shapeType == TopAbs_EDGE) {
506
507         TopoDS_Edge E;
508         if( myShape.IsNull() )
509           E = TopoDS::Edge(meshDS->IndexToShape(edgeID));
510         else {
511           E = TopoDS::Edge(myShape);
512           edgeID = myShapeID;
513         }
514
515         double p1 = GetNodeU(E,n1);
516         double p2 = GetNodeU(E,n2);
517
518         double f,l;
519         Handle(Geom_Curve) C = BRep_Tool::Curve(E, f, l);
520         if(!C.IsNull()) {
521
522           Standard_Boolean isPeriodic = C->IsPeriodic();
523           double u;
524           if(isPeriodic) {
525             Standard_Real Period = C->Period();
526             Standard_Real p = p2+ShapeAnalysis::AdjustByPeriod(p2,p1,Period);
527             Standard_Real pmid = (p1+p)/2.;
528             u = pmid+ShapeAnalysis::AdjustToPeriod(pmid,C->FirstParameter(),C->LastParameter());
529           }
530           else
531             u = (p1+p2)/2.;
532
533           gp_Pnt P = C->Value( u );
534           n12 = meshDS->AddNode(P.X(), P.Y(), P.Z());
535           meshDS->SetNodeOnEdge(n12, edgeID, u);
536           myNLinkNodeMap.insert(NLinkNodeMap::value_type(link,n12));
537           return n12;
538         }
539       }
540     }
541     // 3d variant
542     double x = ( n1->X() + n2->X() )/2.;
543     double y = ( n1->Y() + n2->Y() )/2.;
544     double z = ( n1->Z() + n2->Z() )/2.;
545     n12 = meshDS->AddNode(x,y,z);
546     if(edgeID>-1)
547         meshDS->SetNodeOnEdge(n12, edgeID);
548     else if(faceID>-1)
549         meshDS->SetNodeOnFace(n12, faceID);
550     else
551       meshDS->SetNodeInVolume(n12, myShapeID);
552     myNLinkNodeMap.insert(NLinkNodeMap::value_type(link,n12));
553     return n12;
554   }
555 }
556
557 //=======================================================================
558 /*!
559  * Creates a node
560  */
561 //=======================================================================
562
563 SMDS_MeshNode* SMESH_MesherHelper::AddNode(double x, double y, double z, int ID)
564 {
565   SMESHDS_Mesh * meshDS = GetMeshDS();
566   SMDS_MeshNode* node = 0;
567   if ( ID )
568     node = meshDS->AddNodeWithID( x, y, z, ID );
569   else
570     node = meshDS->AddNode( x, y, z );
571   if ( mySetElemOnShape && myShapeID > 0 ) {
572     switch ( myShape.ShapeType() ) {
573     case TopAbs_SOLID:  meshDS->SetNodeInVolume( node, myShapeID); break;
574     case TopAbs_SHELL:  meshDS->SetNodeInVolume( node, myShapeID); break;
575     case TopAbs_FACE:   meshDS->SetNodeOnFace(   node, myShapeID); break;
576     case TopAbs_EDGE:   meshDS->SetNodeOnEdge(   node, myShapeID); break;
577     case TopAbs_VERTEX: meshDS->SetNodeOnVertex( node, myShapeID); break;
578     default: ;
579     }
580   }
581   return node;
582 }
583
584 //=======================================================================
585 /*!
586  * Creates quadratic or linear edge
587  */
588 //=======================================================================
589
590 SMDS_MeshEdge* SMESH_MesherHelper::AddEdge(const SMDS_MeshNode* n1,
591                                                 const SMDS_MeshNode* n2,
592                                                 const int id,
593                                                 const bool force3d)
594 {
595   SMESHDS_Mesh * meshDS = GetMeshDS();
596   
597   SMDS_MeshEdge* edge = 0;
598   if (myCreateQuadratic) {
599     const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
600     if(id)
601       edge = meshDS->AddEdgeWithID(n1, n2, n12, id);
602     else
603       edge = meshDS->AddEdge(n1, n2, n12);
604   }
605   else {
606     if(id)
607       edge = meshDS->AddEdgeWithID(n1, n2, id);
608     else
609       edge = meshDS->AddEdge(n1, n2);
610   }
611
612   if ( mySetElemOnShape && myShapeID > 0 )
613     meshDS->SetMeshElementOnShape( edge, myShapeID );
614
615   return edge;
616 }
617
618 //=======================================================================
619 /*!
620  * Creates quadratic or linear triangle
621  */
622 //=======================================================================
623
624 SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
625                                            const SMDS_MeshNode* n2,
626                                            const SMDS_MeshNode* n3,
627                                            const int id,
628                                            const bool force3d)
629 {
630   SMESHDS_Mesh * meshDS = GetMeshDS();
631   SMDS_MeshFace* elem = 0;
632   if(!myCreateQuadratic) {
633     if(id)
634       elem = meshDS->AddFaceWithID(n1, n2, n3, id);
635     else
636       elem = meshDS->AddFace(n1, n2, n3);
637   }
638   else {
639     const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
640     const SMDS_MeshNode* n23 = GetMediumNode(n2,n3,force3d);
641     const SMDS_MeshNode* n31 = GetMediumNode(n3,n1,force3d);
642
643     if(id)
644       elem = meshDS->AddFaceWithID(n1, n2, n3, n12, n23, n31, id);
645     else
646       elem = meshDS->AddFace(n1, n2, n3, n12, n23, n31);
647   }
648   if ( mySetElemOnShape && myShapeID > 0 )
649     meshDS->SetMeshElementOnShape( elem, myShapeID );
650
651   return elem;
652 }
653
654 //=======================================================================
655 /*!
656  * Creates quadratic or linear quadrangle
657  */
658 //=======================================================================
659
660 SMDS_MeshFace* SMESH_MesherHelper::AddFace(const SMDS_MeshNode* n1,
661                                            const SMDS_MeshNode* n2,
662                                            const SMDS_MeshNode* n3,
663                                            const SMDS_MeshNode* n4,
664                                            const int id,
665                                            const bool force3d)
666 {
667   SMESHDS_Mesh * meshDS = GetMeshDS();
668   SMDS_MeshFace* elem = 0;
669   if(!myCreateQuadratic) {
670     if(id)
671       elem = meshDS->AddFaceWithID(n1, n2, n3, n4, id);
672     else
673       elem = meshDS->AddFace(n1, n2, n3, n4);
674   }
675   else {
676     const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
677     const SMDS_MeshNode* n23 = GetMediumNode(n2,n3,force3d);
678     const SMDS_MeshNode* n34 = GetMediumNode(n3,n4,force3d);
679     const SMDS_MeshNode* n41 = GetMediumNode(n4,n1,force3d);
680
681     if(id)
682       elem = meshDS->AddFaceWithID(n1, n2, n3, n4, n12, n23, n34, n41, id);
683     else
684       elem = meshDS->AddFace(n1, n2, n3, n4, n12, n23, n34, n41);
685   }
686   if ( mySetElemOnShape && myShapeID > 0 )
687     meshDS->SetMeshElementOnShape( elem, myShapeID );
688
689   return elem;
690 }
691
692 //=======================================================================
693 /*!
694  * Creates quadratic or linear volume
695  */
696 //=======================================================================
697
698 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
699                                                const SMDS_MeshNode* n2,
700                                                const SMDS_MeshNode* n3,
701                                                const SMDS_MeshNode* n4,
702                                                const SMDS_MeshNode* n5,
703                                                const SMDS_MeshNode* n6,
704                                                const int id,
705                                                const bool force3d)
706 {
707   SMESHDS_Mesh * meshDS = GetMeshDS();
708   SMDS_MeshVolume* elem = 0;
709   if(!myCreateQuadratic) {
710     if(id)
711       elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, id);
712     else
713       elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6);
714   }
715   else {
716     const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
717     const SMDS_MeshNode* n23 = GetMediumNode(n2,n3,force3d);
718     const SMDS_MeshNode* n31 = GetMediumNode(n3,n1,force3d);
719
720     const SMDS_MeshNode* n45 = GetMediumNode(n4,n5,force3d);
721     const SMDS_MeshNode* n56 = GetMediumNode(n5,n6,force3d);
722     const SMDS_MeshNode* n64 = GetMediumNode(n6,n4,force3d);
723
724     const SMDS_MeshNode* n14 = GetMediumNode(n1,n4,force3d);
725     const SMDS_MeshNode* n25 = GetMediumNode(n2,n5,force3d);
726     const SMDS_MeshNode* n36 = GetMediumNode(n3,n6,force3d);
727
728     if(id)
729       elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, 
730                                      n12, n23, n31, n45, n56, n64, n14, n25, n36, id);
731     else
732       elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6,
733                                n12, n23, n31, n45, n56, n64, n14, n25, n36);
734   }
735   if ( mySetElemOnShape && myShapeID > 0 )
736     meshDS->SetMeshElementOnShape( elem, myShapeID );
737
738   return elem;
739 }
740
741 //=======================================================================
742 /*!
743  * Creates quadratic or linear volume
744  */
745 //=======================================================================
746
747 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
748                                                const SMDS_MeshNode* n2,
749                                                const SMDS_MeshNode* n3,
750                                                const SMDS_MeshNode* n4,
751                                                const int id, 
752                                                const bool force3d)
753 {
754   SMESHDS_Mesh * meshDS = GetMeshDS();
755   SMDS_MeshVolume* elem = 0;
756   if(!myCreateQuadratic) {
757     if(id)
758       elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, id);
759     else
760       elem = meshDS->AddVolume(n1, n2, n3, n4);
761   }
762   else {
763     const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
764     const SMDS_MeshNode* n23 = GetMediumNode(n2,n3,force3d);
765     const SMDS_MeshNode* n31 = GetMediumNode(n3,n1,force3d);
766
767     const SMDS_MeshNode* n14 = GetMediumNode(n1,n4,force3d);
768     const SMDS_MeshNode* n24 = GetMediumNode(n2,n4,force3d);
769     const SMDS_MeshNode* n34 = GetMediumNode(n3,n4,force3d);
770
771     if(id)
772       elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n12, n23, n31, n14, n24, n34, id);
773     else
774       elem = meshDS->AddVolume(n1, n2, n3, n4, n12, n23, n31, n14, n24, n34);
775   }
776   if ( mySetElemOnShape && myShapeID > 0 )
777     meshDS->SetMeshElementOnShape( elem, myShapeID );
778
779   return elem;
780 }
781
782 //=======================================================================
783 /*!
784  * Creates quadratic or linear pyramid
785  */
786 //=======================================================================
787
788 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
789                                                const SMDS_MeshNode* n2,
790                                                const SMDS_MeshNode* n3,
791                                                const SMDS_MeshNode* n4,
792                                                const SMDS_MeshNode* n5,
793                                                const int id, 
794                                                const bool force3d)
795 {
796   SMDS_MeshVolume* elem = 0;
797   if(!myCreateQuadratic) {
798     if(id)
799       elem = GetMeshDS()->AddVolumeWithID(n1, n2, n3, n4, n5, id);
800     else
801       elem = GetMeshDS()->AddVolume(n1, n2, n3, n4, n5);
802   }
803   else {
804     const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
805     const SMDS_MeshNode* n23 = GetMediumNode(n2,n3,force3d);
806     const SMDS_MeshNode* n34 = GetMediumNode(n3,n4,force3d);
807     const SMDS_MeshNode* n41 = GetMediumNode(n4,n1,force3d);
808
809     const SMDS_MeshNode* n15 = GetMediumNode(n1,n5,force3d);
810     const SMDS_MeshNode* n25 = GetMediumNode(n2,n5,force3d);
811     const SMDS_MeshNode* n35 = GetMediumNode(n3,n5,force3d);
812     const SMDS_MeshNode* n45 = GetMediumNode(n4,n5,force3d);
813
814     if(id)
815       elem = GetMeshDS()->AddVolumeWithID ( n1,  n2,  n3,  n4,  n5,
816                                             n12, n23, n34, n41,
817                                             n15, n25, n35, n45,
818                                             id);
819     else
820       elem = GetMeshDS()->AddVolume( n1,  n2,  n3,  n4,  n5,
821                                      n12, n23, n34, n41,
822                                      n15, n25, n35, n45);
823   }
824   if ( mySetElemOnShape && myShapeID > 0 )
825     GetMeshDS()->SetMeshElementOnShape( elem, myShapeID );
826
827   return elem;
828 }
829
830 //=======================================================================
831 /*!
832  * Creates quadratic or linear hexahedron
833  */
834 //=======================================================================
835
836 SMDS_MeshVolume* SMESH_MesherHelper::AddVolume(const SMDS_MeshNode* n1,
837                                                const SMDS_MeshNode* n2,
838                                                const SMDS_MeshNode* n3,
839                                                const SMDS_MeshNode* n4,
840                                                const SMDS_MeshNode* n5,
841                                                const SMDS_MeshNode* n6,
842                                                const SMDS_MeshNode* n7,
843                                                const SMDS_MeshNode* n8,
844                                                const int id,
845                                                const bool force3d)
846 {
847   SMESHDS_Mesh * meshDS = GetMeshDS();
848   SMDS_MeshVolume* elem = 0;
849   if(!myCreateQuadratic) {
850     if(id)
851       elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, id);
852     else
853       elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
854   }
855   else {
856     const SMDS_MeshNode* n12 = GetMediumNode(n1,n2,force3d);
857     const SMDS_MeshNode* n23 = GetMediumNode(n2,n3,force3d);
858     const SMDS_MeshNode* n34 = GetMediumNode(n3,n4,force3d);
859     const SMDS_MeshNode* n41 = GetMediumNode(n4,n1,force3d);
860
861     const SMDS_MeshNode* n56 = GetMediumNode(n5,n6,force3d);
862     const SMDS_MeshNode* n67 = GetMediumNode(n6,n7,force3d);
863     const SMDS_MeshNode* n78 = GetMediumNode(n7,n8,force3d);
864     const SMDS_MeshNode* n85 = GetMediumNode(n8,n5,force3d);
865
866     const SMDS_MeshNode* n15 = GetMediumNode(n1,n5,force3d);
867     const SMDS_MeshNode* n26 = GetMediumNode(n2,n6,force3d);
868     const SMDS_MeshNode* n37 = GetMediumNode(n3,n7,force3d);
869     const SMDS_MeshNode* n48 = GetMediumNode(n4,n8,force3d);
870
871     if(id)
872       elem = meshDS->AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8,
873                                      n12, n23, n34, n41, n56, n67,
874                                      n78, n85, n15, n26, n37, n48, id);
875     else
876       elem = meshDS->AddVolume(n1, n2, n3, n4, n5, n6, n7, n8,
877                                n12, n23, n34, n41, n56, n67,
878                                n78, n85, n15, n26, n37, n48);
879   }
880   if ( mySetElemOnShape && myShapeID > 0 )
881     meshDS->SetMeshElementOnShape( elem, myShapeID );
882
883   return elem;
884 }
885
886 //=======================================================================
887   /*!
888    * \brief Load nodes bound to face into a map of node columns
889     * \param theParam2ColumnMap - map of node columns to fill
890     * \param theFace - the face on which nodes are searched for
891     * \param theBaseEdge - the edge nodes of which are columns' bases
892     * \param theMesh - the mesh containing nodes
893     * \retval bool - false if something is wrong
894    * 
895    * The key of the map is a normalized parameter of each
896    * base node on theBaseEdge.
897    * This method works in supposition that nodes on the face
898    * forms a rectangular grid and elements can be quardrangles or triangles
899    */
900 //=======================================================================
901
902 bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap & theParam2ColumnMap,
903                                          const TopoDS_Face& theFace,
904                                          const TopoDS_Edge& theBaseEdge,
905                                          SMESHDS_Mesh*      theMesh)
906 {
907   // get vertices of theBaseEdge
908   TopoDS_Vertex vfb, vlb, vft; // first and last, bottom and top vertices
909   TopoDS_Edge eFrw = TopoDS::Edge( theBaseEdge.Oriented( TopAbs_FORWARD ));
910   TopExp::Vertices( eFrw, vfb, vlb );
911
912   // find the other edges of theFace and orientation of e1
913   TopoDS_Edge e1, e2, eTop;
914   bool rev1, CumOri = false;
915   TopExp_Explorer exp( theFace, TopAbs_EDGE );
916   int nbEdges = 0;
917   for ( ; exp.More(); exp.Next() ) {
918     if ( ++nbEdges > 4 ) {
919       return false; // more than 4 edges in theFace
920     }
921     TopoDS_Edge e = TopoDS::Edge( exp.Current() );
922     if ( theBaseEdge.IsSame( e ))
923       continue;
924     TopoDS_Vertex vCommon;
925     if ( !TopExp::CommonVertex( theBaseEdge, e, vCommon ))
926       eTop = e;
927     else if ( vCommon.IsSame( vfb )) {
928       e1 = e;
929       vft = TopExp::LastVertex( e1, CumOri );
930       rev1 = vfb.IsSame( vft );
931       if ( rev1 )
932         vft = TopExp::FirstVertex( e1, CumOri );
933     }
934     else
935       e2 = e;
936   }
937   if ( nbEdges < 4 ) {
938     return false; // less than 4 edges in theFace
939   }
940   if ( e2.IsNull() && vfb.IsSame( vlb ))
941     e2 = e1;
942
943   // submeshes corresponding to shapes
944   SMESHDS_SubMesh* smFace = theMesh->MeshElements( theFace );
945   SMESHDS_SubMesh* smb = theMesh->MeshElements( theBaseEdge );
946   SMESHDS_SubMesh* smt = theMesh->MeshElements( eTop );
947   SMESHDS_SubMesh* sm1 = theMesh->MeshElements( e1 );
948   SMESHDS_SubMesh* sm2 = theMesh->MeshElements( e2 );
949   SMESHDS_SubMesh* smVfb = theMesh->MeshElements( vfb );
950   SMESHDS_SubMesh* smVlb = theMesh->MeshElements( vlb );
951   SMESHDS_SubMesh* smVft = theMesh->MeshElements( vft );
952   if (!smFace || !smb || !smt || !sm1 || !sm2 || !smVfb || !smVlb || !smVft ) {
953     RETURN_BAD_RESULT( "NULL submesh " <<smFace<<" "<<smb<<" "<<smt<<" "<<
954                        sm1<<" "<<sm2<<" "<<smVfb<<" "<<smVlb<<" "<<smVft);
955   }
956   if ( smb->NbNodes() != smt->NbNodes() || sm1->NbNodes() != sm2->NbNodes() ) {
957     RETURN_BAD_RESULT(" Diff nb of nodes on opposite edges" );
958   }
959   if (smVfb->NbNodes() != 1 || smVlb->NbNodes() != 1 || smVft->NbNodes() != 1) {
960     RETURN_BAD_RESULT("Empty submesh of vertex");
961   }
962   // define whether mesh is quadratic
963   bool isQuadraticMesh = false;
964   SMDS_ElemIteratorPtr eIt = smFace->GetElements();
965   if ( !eIt->more() ) {
966     RETURN_BAD_RESULT("No elements on the face");
967   }
968   const SMDS_MeshElement* e = eIt->next();
969   isQuadraticMesh = e->IsQuadratic();
970   
971   if ( sm1->NbNodes() * smb->NbNodes() != smFace->NbNodes() ) {
972     // check quadratic case
973     if ( isQuadraticMesh ) {
974       // what if there are quadrangles and triangles mixed?
975 //       int n1 = sm1->NbNodes()/2;
976 //       int n2 = smb->NbNodes()/2;
977 //       int n3 = sm1->NbNodes() - n1;
978 //       int n4 = smb->NbNodes() - n2;
979 //       int nf = sm1->NbNodes()*smb->NbNodes() - n3*n4;
980 //       if( nf != smFace->NbNodes() ) {
981 //         MESSAGE( "Wrong nb face nodes: " <<
982 //                 sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
983 //         return false;
984 //       }
985     }
986     else {
987       RETURN_BAD_RESULT( "Wrong nb face nodes: " <<
988                          sm1->NbNodes()<<" "<<smb->NbNodes()<<" "<<smFace->NbNodes());
989     }
990   }
991   // IJ size
992   int vsize = sm1->NbNodes() + 2;
993   int hsize = smb->NbNodes() + 2;
994   if(isQuadraticMesh) {
995     vsize = vsize - sm1->NbNodes()/2 -1;
996     hsize = hsize - smb->NbNodes()/2 -1;
997   }
998
999   // load nodes from theBaseEdge
1000
1001   std::set<const SMDS_MeshNode*> loadedNodes;
1002   const SMDS_MeshNode* nullNode = 0;
1003
1004   std::vector<const SMDS_MeshNode*> & nVecf = theParam2ColumnMap[ 0.];
1005   nVecf.resize( vsize, nullNode );
1006   loadedNodes.insert( nVecf[ 0 ] = smVfb->GetNodes()->next() );
1007
1008   std::vector<const SMDS_MeshNode*> & nVecl = theParam2ColumnMap[ 1.];
1009   nVecl.resize( vsize, nullNode );
1010   loadedNodes.insert( nVecl[ 0 ] = smVlb->GetNodes()->next() );
1011
1012   double f, l;
1013   BRep_Tool::Range( eFrw, f, l );
1014   double range = l - f;
1015   SMDS_NodeIteratorPtr nIt = smb->GetNodes();
1016   const SMDS_MeshNode* node;
1017   while ( nIt->more() ) {
1018     node = nIt->next();
1019     if(IsMedium(node, SMDSAbs_Edge))
1020       continue;
1021     const SMDS_EdgePosition* pos =
1022       dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1023     if ( !pos ) {
1024       return false;
1025     }
1026     double u = ( pos->GetUParameter() - f ) / range;
1027     std::vector<const SMDS_MeshNode*> & nVec = theParam2ColumnMap[ u ];
1028     nVec.resize( vsize, nullNode );
1029     loadedNodes.insert( nVec[ 0 ] = node );
1030   }
1031   if ( theParam2ColumnMap.size() != hsize ) {
1032     RETURN_BAD_RESULT( "Wrong node positions on theBaseEdge" );
1033   }
1034
1035   // load nodes from e1
1036
1037   std::map< double, const SMDS_MeshNode*> sortedNodes; // sort by param on edge
1038   nIt = sm1->GetNodes();
1039   while ( nIt->more() ) {
1040     node = nIt->next();
1041     if(IsMedium(node))
1042       continue;
1043     const SMDS_EdgePosition* pos =
1044       dynamic_cast<const SMDS_EdgePosition*>( node->GetPosition().get() );
1045     if ( !pos ) {
1046       return false;
1047     }
1048     sortedNodes.insert( std::make_pair( pos->GetUParameter(), node ));
1049   }
1050   loadedNodes.insert( nVecf[ vsize - 1 ] = smVft->GetNodes()->next() );
1051   std::map< double, const SMDS_MeshNode*>::iterator u_n = sortedNodes.begin();
1052   int row  = rev1 ? vsize - 1 : 0;
1053   int dRow = rev1 ? -1 : +1;
1054   for ( ; u_n != sortedNodes.end(); u_n++ ) {
1055     row += dRow;
1056     loadedNodes.insert( nVecf[ row ] = u_n->second );
1057   }
1058
1059   // try to load the rest nodes
1060
1061   // get all faces from theFace
1062   TIDSortedElemSet allFaces, foundFaces;
1063   eIt = smFace->GetElements();
1064   while ( eIt->more() ) {
1065     const SMDS_MeshElement* e = eIt->next();
1066     if ( e->GetType() == SMDSAbs_Face )
1067       allFaces.insert( e );
1068   }
1069   // Starting from 2 neighbour nodes on theBaseEdge, look for a face
1070   // the nodes belong to, and between the nodes of the found face,
1071   // look for a not loaded node considering this node to be the next
1072   // in a column of the starting second node. Repeat, starting
1073   // from nodes next to the previous starting nodes in their columns,
1074   // and so on while a face can be found. Then go the the next pair
1075   // of nodes on theBaseEdge.
1076   TParam2ColumnMap::iterator par_nVec_1 = theParam2ColumnMap.begin();
1077   TParam2ColumnMap::iterator par_nVec_2 = par_nVec_1;
1078   // loop on columns
1079   int col = 0;
1080   for ( par_nVec_2++; par_nVec_2 != theParam2ColumnMap.end(); par_nVec_1++, par_nVec_2++ ) {
1081     col++;
1082     row = 0;
1083     const SMDS_MeshNode* n1 = par_nVec_1->second[ row ];
1084     const SMDS_MeshNode* n2 = par_nVec_2->second[ row ];
1085     const SMDS_MeshElement* face = 0;
1086     bool lastColOnClosedFace = ( nVecf[ row ] == n2 );
1087     do {
1088       // look for a face by 2 nodes
1089       face = SMESH_MeshEditor::FindFaceInSet( n1, n2, allFaces, foundFaces );
1090       if ( face ) {
1091         int nbFaceNodes = face->NbNodes();
1092         if ( face->IsQuadratic() )
1093           nbFaceNodes /= 2;
1094         if ( nbFaceNodes>4 ) {
1095           RETURN_BAD_RESULT(" Too many nodes in a face: " << nbFaceNodes );
1096         }
1097         // look for a not loaded node of the <face>
1098         bool found = false;
1099         const SMDS_MeshNode* n3 = 0; // a node defferent from n1 and n2
1100         for ( int i = 0; i < nbFaceNodes && !found; ++i ) {
1101           node = face->GetNode( i );
1102           found = loadedNodes.insert( node ).second;
1103           if ( !found && node != n1 && node != n2 )
1104             n3 = node;
1105         }
1106         if ( lastColOnClosedFace && row + 1 < vsize ) {
1107           node = nVecf[ row + 1 ];
1108           found = ( face->GetNodeIndex( node ) >= 0 );
1109         }
1110         if ( found ) {
1111           if ( ++row > vsize - 1 ) {
1112             RETURN_BAD_RESULT( "Too many nodes in column "<< col <<": "<< row+1);
1113           }
1114           par_nVec_2->second[ row ] = node;
1115           foundFaces.insert( face );
1116           n2 = node;
1117           if ( nbFaceNodes==4 ) {
1118             n1 = par_nVec_1->second[ row ];
1119           }
1120         }
1121         else if ( nbFaceNodes==3 && n3 == par_nVec_1->second[ row + 1 ] ) {
1122           n1 = n3;
1123         }
1124         else  {
1125           RETURN_BAD_RESULT( "Not quad mesh, column "<< col );
1126         }
1127       }
1128     }
1129     while ( face && n1 && n2 );
1130
1131     if ( row < vsize - 1 ) {
1132       MESSAGE( "Too few nodes in column "<< col <<": "<< row+1);
1133       MESSAGE( "Base node 1: "<< par_nVec_1->second[0]);
1134       MESSAGE( "Base node 2: "<< par_nVec_2->second[0]);
1135       if ( n1 ) { MESSAGE( "Current node 1: "<< n1); }
1136       else      { MESSAGE( "Current node 1: NULL");  }
1137       if ( n2 ) { MESSAGE( "Current node 2: "<< n2); }
1138       else      { MESSAGE( "Current node 2: NULL");  }
1139       MESSAGE( "first base node: "<< theParam2ColumnMap.begin()->second[0]);
1140       MESSAGE( "last base node: "<< theParam2ColumnMap.rbegin()->second[0]);
1141       return false;
1142     }
1143   } // loop on columns
1144
1145   return true;
1146 }
1147
1148 /**
1149  * Check mesh without geometry for: if all elements on this shape are quadratic,
1150  * quadratic elements will be created.
1151  * Used then generated 3D mesh without geometry.
1152    */
1153 SMESH_MesherHelper:: MType SMESH_MesherHelper::IsQuadraticMesh()
1154 {
1155   int NbAllEdgsAndFaces=0;
1156   int NbQuadFacesAndEdgs=0;
1157   int NbFacesAndEdges=0;
1158   //All faces and edges
1159   NbAllEdgsAndFaces = myMesh->NbEdges() + myMesh->NbFaces();
1160   
1161   //Quadratic faces and edges
1162   NbQuadFacesAndEdgs = myMesh->NbEdges(ORDER_QUADRATIC) + myMesh->NbFaces(ORDER_QUADRATIC);
1163
1164   //Linear faces and edges
1165   NbFacesAndEdges = myMesh->NbEdges(ORDER_LINEAR) + myMesh->NbFaces(ORDER_LINEAR);
1166   
1167   if (NbAllEdgsAndFaces == NbQuadFacesAndEdgs) {
1168     //Quadratic mesh
1169     return SMESH_MesherHelper::QUADRATIC;
1170   }
1171   else if (NbAllEdgsAndFaces == NbFacesAndEdges) {
1172     //Linear mesh
1173     return SMESH_MesherHelper::LINEAR;
1174   }
1175   else
1176     //Mesh with both type of elements
1177     return SMESH_MesherHelper::COMP;
1178 }
1179