Salome HOME
#19926 [CEA 19782] renumbering meshes
[modules/smesh.git] / src / StdMeshers / StdMeshers_CompositeHexa_3D.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMESH : implementation of SMESH idl descriptions
21 // File      : StdMeshers_CompositeHexa_3D.cxx
22 // Module    : SMESH
23 // Created   : Tue Nov 25 11:04:59 2008
24 // Author    : Edward AGAPOV (eap)
25
26 #include "StdMeshers_CompositeHexa_3D.hxx"
27
28 #include "SMDS_Mesh.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_SetIterator.hxx"
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESHDS_SubMesh.hxx"
33 #include "SMESH_Block.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_ComputeError.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_Mesh.hxx"
38 #include "SMESH_MeshAlgos.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41 #include "StdMeshers_BlockRenumber.hxx"
42 #include "StdMeshers_FaceSide.hxx"
43 #include "StdMeshers_ViscousLayers.hxx"
44
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRep_Tool.hxx>
47 #include <Standard_ErrorHandler.hxx>
48 #include <Standard_Failure.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_MapIteratorOfMapOfShape.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopTools_SequenceOfShape.hxx>
54 #include <TopoDS.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <gp_Pnt.hxx>
59 #include <gp_Pnt2d.hxx>
60 #include <gp_Vec.hxx>
61 #include <gp_XYZ.hxx>
62
63 #include <list>
64 #include <set>
65 #include <vector>
66 #include <Bnd_B3d.hxx>
67
68 using namespace std;
69
70 #ifdef _DEBUG_
71 // #define DEB_FACES
72 // #define DEB_GRID
73 // #define DUMP_VERT(msg,V) { TopoDS_Vertex v = V; gp_Pnt p = BRep_Tool::Pnt(v); cout << msg << "( "<< p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl; }
74 #endif
75
76 #ifndef DUMP_VERT
77 #define DUMP_VERT(msg,v)
78 #endif
79
80 //================================================================================
81 // text for message about an internal error
82 #define ERR_LI(txt) SMESH_Comment(txt) << ":" << __LINE__
83
84 // order corresponds to right order of edges in CASCADE face
85 enum EQuadSides{ Q_BOTTOM=0, Q_RIGHT, Q_TOP, Q_LEFT,   Q_CHILD, Q_PARENT };
86
87 enum EBoxSides{ B_BOTTOM=0, B_RIGHT, B_TOP, B_LEFT, B_FRONT, B_BACK, B_UNDEFINED };
88
89 enum EAxes{ COO_X=1, COO_Y, COO_Z };
90
91 //================================================================================
92 /*!
93  * \brief Converter of a pair of integers to a sole index
94  */
95 struct _Indexer
96 {
97   int _xSize, _ySize;
98   _Indexer( int xSize, int ySize ): _xSize(xSize), _ySize(ySize) {}
99   int size() const { return _xSize * _ySize; }
100   int operator()(const int x, const int y) const { return y * _xSize + x; }
101 };
102
103 //================================================================================
104 /*!
105  * \brief Wrapper of a composite or an ordinary edge.
106  */
107 class _FaceSide
108 {
109 public:
110   _FaceSide(const _FaceSide& other);
111   _FaceSide(const TopoDS_Edge& edge=TopoDS_Edge());
112   _FaceSide(const list<TopoDS_Edge>& edges);
113   _FaceSide* GetSide(const int i);
114   const _FaceSide* GetSide(const int i) const;
115   int size() const { return myChildren.size(); }
116   int NbVertices() const;
117   int NbCommonVertices( const TopTools_MapOfShape& VV ) const;
118   TopoDS_Vertex FirstVertex() const;
119   TopoDS_Vertex LastVertex() const;
120   TopoDS_Vertex Vertex(int i) const;
121   TopoDS_Edge   Edge(int i) const;
122   bool Contain( const _FaceSide& side, int* which=0 ) const;
123   bool Contain( const TopoDS_Vertex& vertex ) const;
124   void AppendSide( const _FaceSide& side );
125   void SetBottomSide( int i );
126   int GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges=0) const;
127   bool StoreNodes(SMESH_ProxyMesh& mesh, vector<const SMDS_MeshNode*>& myGrid,
128                   bool reverse, bool isProxy, const SMESHDS_SubMesh* smToCheckEdges=0 );
129   void SetID(EQuadSides id) { myID = id; }
130   static inline const TopoDS_TShape* ptr(const TopoDS_Shape& theShape)
131   { return theShape.TShape().operator->(); }
132   void Dump() const;
133
134 private:
135
136
137   TopoDS_Edge       myEdge;
138   list< _FaceSide > myChildren;
139   int               myNbChildren;
140
141   TopTools_MapOfShape myVertices;
142
143   EQuadSides        myID; // debug
144 };
145 //================================================================================
146 /*!
147  * \brief Class corresponding to a meshed composite face of a box.
148  *        Provides simplified access to it's sub-mesh data.
149  */
150 class _QuadFaceGrid
151 {
152   typedef list< _QuadFaceGrid > TChildren;
153 public:
154   _QuadFaceGrid();
155
156 public: //** Methods to find and orient faces of 6 sides of the box **//
157   
158   //!< initialization
159   bool Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh );
160
161   //!< try to unite self with other face
162   bool AddContinuousFace( const _QuadFaceGrid& f, const TopTools_MapOfShape& internalEdges );
163
164   //!< Try to set the side as bottom hirizontal side
165   bool SetBottomSide(const _FaceSide& side, int* sideIndex=0);
166
167   //!< Return face adjacent to zero-based i-th side of this face
168   _QuadFaceGrid* FindAdjacentForSide(int i, list<_QuadFaceGrid>& faces, EBoxSides id) const;
169
170   //!< Reverse edges in order to have the bottom edge going along axes of the unit box
171   void ReverseEdges();
172
173   bool IsComplex() const { return !myChildren.empty(); }
174
175   int NbChildren() const { return myChildren.size(); }
176
177   typedef SMDS_SetIterator< const _QuadFaceGrid&,
178                             TChildren::const_iterator,
179                             SMDS::SimpleAccessor<const _QuadFaceGrid&,TChildren::const_iterator>,
180                             SMDS::PassAllValueFilter<_QuadFaceGrid> >
181     TChildIterator;
182
183   TChildIterator GetChildren() const
184   { return TChildIterator( myChildren.begin(), myChildren.end()); }
185
186   bool Contain( const TopoDS_Vertex& vertex ) const { return mySides.Contain( vertex ); }
187
188 public: //** Loading and access to mesh **//
189
190   //!< Load nodes of a mesh
191   bool LoadGrid( SMESH_ProxyMesh& mesh );
192
193   //!< Computes normalized parameters of nodes of myGrid
194   void ComputeIJK( int i1, int i2, double v3 );
195
196   //!< Return number of segments on the hirizontal sides
197   int GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
198
199   //!< Return number of segments on the vertical sides
200   int GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers=false) const;
201
202   //!< Return edge on the hirizontal bottom sides
203   int GetHoriEdges(vector<TopoDS_Edge> & edges) const;
204
205   //!< Return a node by its position
206   const SMDS_MeshNode* GetNode(int iHori, int iVert) const;
207
208   //!< Return node coordinates by its position
209   gp_XYZ GetXYZ(int iHori, int iVert) const;
210
211   //!< Return normalized parameters of nodes within the unitary cube
212   gp_XYZ& GetIJK(int iCol, int iRow) { return myIJK[ myIndexer( iCol, iRow )]; }
213
214 public: //** Access to member fields **//
215
216   //!< Return i-th face side (0<i<4)
217   const _FaceSide& GetSide(int i) const;
218
219   //!< Return it's face, NULL if it is composite
220   TopoDS_Face GetFace() const { return myFace; }
221
222   //!< Return normal to the face at vertex v
223   bool GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const;
224
225   SMESH_ComputeErrorPtr GetError() const { return myError; }
226
227   void SetID(EBoxSides id) { myID = id; }
228
229   void DumpGrid() const;
230
231   void DumpVertices() const;
232
233 private:
234
235   bool error(const std::string& text, int code = COMPERR_ALGO_FAILED)
236   { myError = SMESH_ComputeError::New( code, text ); return false; }
237
238   bool error(const SMESH_ComputeErrorPtr& err)
239   { myError = err; return ( !myError || myError->IsOK() ); }
240
241   bool loadCompositeGrid(SMESH_ProxyMesh& mesh);
242
243   bool fillGrid(SMESH_ProxyMesh&               theMesh,
244                 vector<const SMDS_MeshNode*> & theGrid,
245                 const _Indexer&                theIndexer,
246                 int                            theX,
247                 int                            theY);
248
249   bool locateChildren();
250
251   void setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers );
252
253   TopoDS_Face myFace;
254   _FaceSide   mySides;
255   bool        myReverse;
256
257   TChildren   myChildren;
258
259   _QuadFaceGrid* myLeftBottomChild;
260   _QuadFaceGrid* myRightBrother;
261   _QuadFaceGrid* myUpBrother;
262
263   _Indexer                      myIndexer;
264   vector<const SMDS_MeshNode*>  myGrid;
265   vector<gp_XYZ>                myIJK; // normalized parameters of nodes
266
267   SMESH_ComputeErrorPtr         myError;
268
269   EBoxSides   myID; // debug
270 };
271
272 //================================================================================
273 /*!
274  * \brief Constructor
275  */
276 //================================================================================
277
278 StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, SMESH_Gen* gen)
279   :SMESH_3D_Algo(hypId, gen), _blockRenumberHyp( nullptr )
280 {
281   _name = "CompositeHexa_3D";
282   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit /shape type
283 }
284
285 //================================================================================
286 /*!
287  * \brief always return true
288  */
289 //================================================================================
290
291 bool StdMeshers_CompositeHexa_3D::CheckHypothesis(SMESH_Mesh&         aMesh,
292                                                   const TopoDS_Shape& aShape,
293                                                   Hypothesis_Status&  aStatus)
294 {
295   _blockRenumberHyp = nullptr;
296   aStatus = HYP_OK;
297   return true;
298 }
299
300 namespace
301 {
302
303   //================================================================================
304   /*!
305    * \brief Checks structure of a quadrangular mesh at the common VERTEX of two EDGEs.
306    *        Returns true if there are two quadrangles near the VERTEX.
307    */
308   //================================================================================
309
310   bool isContinuousMesh(TopoDS_Edge            E1,
311                         TopoDS_Edge            E2,
312                         const TopoDS_Face&     F,
313                         const SMESH_ProxyMesh& mesh)
314   {
315     if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
316       E1.Orientation( TopAbs_FORWARD );
317     if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
318       E2.Orientation( TopAbs_FORWARD );
319
320     TopoDS_Vertex V;
321     if ( !TopExp::CommonVertex( E1, E2, V )) return false;
322
323     const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
324     if ( !n ) return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
325
326     n = mesh.GetProxyNode( n );
327
328     const SMESHDS_SubMesh* sm = mesh.GetSubMesh( F );
329     if ( !sm ) return false;
330
331     int nbQuads = 0;
332     SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
333     if ( !fIt->more() )
334       return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
335     while ( fIt->more() )
336     {
337       const SMDS_MeshElement* f = fIt->next();
338       if ( !sm->Contains( f )) continue;
339
340       if ( f->NbCornerNodes() == 4 )
341         ++nbQuads;
342       else
343         return false;
344     }
345     return nbQuads == 2;
346   }
347
348   //================================================================================
349   /*!
350    * \brief Return true if a vertex holds a node and this node is used by some quadrangle
351    */
352   //================================================================================
353
354   // bool isMeshedVertex( TopoDS_Vertex&     V,
355   //                      const SMESH_Mesh&  mesh )
356   // {
357   //   const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
358   //   if ( !n ) return false;
359     
360   //   SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
361   //   while ( fIt->more() )
362   //   {
363   //     const SMDS_MeshElement* f = fIt->next();
364   //     if ( f->NbCornerNodes() == 4 )
365   //       return true;
366   //   }
367   //   return false;
368   // }
369
370   //================================================================================
371   /*!
372    * \brief Finds VERTEXes located at block corners
373    */
374   //================================================================================
375
376   void getBlockCorners( SMESH_ProxyMesh&     mesh,
377                         const TopoDS_Shape&  shape,
378                         TopTools_MapOfShape& cornerVV)
379   {
380     std::set<int> faceIDs; // ids of FACEs in the shape
381     TopExp_Explorer exp;
382     for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next() )
383       faceIDs.insert( mesh.GetMeshDS()->ShapeToIndex( exp.Current() ));
384
385     TopTools_MapOfShape checkedVV;
386     for ( exp.Init( shape, TopAbs_VERTEX ); exp.More(); exp.Next() )
387     {
388       TopoDS_Vertex V = TopoDS::Vertex( exp.Current() );
389       if ( !checkedVV.Add( V )) continue;
390
391       const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
392       if ( !n ) continue;
393
394       const SMDS_MeshNode* nProxy = mesh.GetProxyNode( n );
395       bool isProxy = ( nProxy != n );
396       n = nProxy;
397
398       int nbQuads = 0;
399       SMDS_ElemIteratorPtr fIt = mesh.GetInverseElementIterator( n, SMDSAbs_Face );
400       while ( fIt->more() )
401       {
402         const SMDS_MeshElement* f = fIt->next();
403         if ( !faceIDs.count( f->getshapeId() )) continue;
404
405         if ( isProxy && !mesh.GetSubMesh( f->getshapeId() )->Contains( f ))
406           continue;
407
408         if ( f->NbCornerNodes() == 4 )
409           ++nbQuads;
410         else
411           nbQuads = 100;
412       }
413       if ( nbQuads == 3 )
414         cornerVV.Add( V );
415     }
416   }
417
418   //================================================================================
419   /*!
420    * \brief Return EDGEs dividing one box side
421    */
422   //================================================================================
423
424   bool getInternalEdges( SMESH_Mesh&                mesh,
425                          const TopoDS_Shape&        shape,
426                          const TopTools_MapOfShape& cornerVV,
427                          TopTools_MapOfShape&       internEE)
428   {
429     TopTools_IndexedMapOfShape subEE, subFF;
430     TopExp::MapShapes( shape, TopAbs_EDGE, subEE );
431     TopExp::MapShapes( shape, TopAbs_FACE, subFF );
432
433     TopoDS_Vertex VV[2];
434     TopTools_MapOfShape subChecked, ridgeEE;
435     TopTools_MapIteratorOfMapOfShape vIt( cornerVV );
436     for ( ; vIt.More(); vIt.Next() )
437     {
438       TopoDS_Shape V0 = vIt.Key();
439       // walk from one corner VERTEX to another along ridge EDGEs
440       PShapeIteratorPtr riIt = SMESH_MesherHelper::GetAncestors( V0, mesh, TopAbs_EDGE );
441       while ( const TopoDS_Shape* riE = riIt->next() )
442       {
443         if ( !subEE.Contains( *riE ) || !subChecked.Add( *riE ))
444           continue;
445         TopoDS_Edge ridgeE = TopoDS::Edge( *riE );
446         while ( !ridgeE.IsNull() )
447         {
448           if ( !ridgeEE.Add( ridgeE ))
449             break;
450           TopExp::Vertices( ridgeE, VV[0], VV[1] );
451           TopoDS_Shape V1 = VV[ V0.IsSame( VV[0] )];
452           if ( cornerVV.Contains( V1 ) )
453             break; // ridgeE reached a corner VERTEX
454
455           // detect internal EDGEs among those sharing V1. There can be 2, 3 or 4 EDGEs and
456           // number of internal EDGEs is N-2
457           TopoDS_Shape nextRidgeE;
458           PShapeIteratorPtr eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
459           while ( const TopoDS_Shape* E = eIt->next() )
460           {
461             if ( E->IsSame( ridgeE ) || !subEE.Contains( *E ) || !subChecked.Add( *E ))
462               continue;
463             // look for FACEs sharing both E and ridgeE
464             PShapeIteratorPtr fIt = SMESH_MesherHelper::GetAncestors( *E, mesh, TopAbs_FACE );
465             while ( const TopoDS_Shape* F = fIt->next() )
466             {
467               if ( !SMESH_MesherHelper::IsSubShape( ridgeE, *F ))
468                 continue;
469               if ( !subFF.Contains( *F ))
470                 continue;
471               if ( isContinuousMesh( ridgeE, TopoDS::Edge( *E ), TopoDS::Face( *F ), mesh ))
472               {
473                 nextRidgeE = *E;
474               }
475               else
476               {
477                 internEE.Add( *E );
478               }
479               break;
480             }
481           }
482           // look for the next ridge EDGE ending at V1
483           if ( nextRidgeE.IsNull() )
484           {
485             eIt = SMESH_MesherHelper::GetAncestors( V1, mesh, TopAbs_EDGE );
486             while ( const TopoDS_Shape* E = eIt->next() )
487               if ( !ridgeE.IsSame( *E ) && !internEE.Contains( *E ) && subEE.Contains( *E ))
488               {
489                 nextRidgeE = *E;
490                 break;
491               }
492           }
493           ridgeE = TopoDS::Edge( nextRidgeE );
494           V0 = V1;
495
496           if ( ridgeE.IsNull() )
497             return false;
498         } // check EDGEs around the last VERTEX of ridgeE 
499       } // loop on ridge EDGEs around a corner VERTEX
500     } // loop on on corner VERTEXes
501
502     if ( subEE.Extent() > ridgeEE.Extent() + internEE.Extent() ) // PAL23269
503       for ( int i = 1; i < subEE.Extent(); ++i )
504         if ( !ridgeEE.Contains( subEE(i) ))
505           internEE.Add( subEE(i) );
506
507     return true;
508   } // getInternalEdges()
509
510   //================================================================================
511   /*!
512    * \brief Find a face including two given nodes
513    */
514   //================================================================================
515
516   const SMDS_MeshElement* FindFaceByNodes( const SMDS_MeshNode* n1,
517                                            const SMDS_MeshNode* n2,
518                                            TIDSortedElemSet     avoidSet,
519                                            SMESH_ProxyMesh&     mesh)
520   {
521     SMDS_ElemIteratorPtr faceIt = mesh.GetInverseElementIterator( n1, SMDSAbs_Face );
522     while ( faceIt->more() )
523     {
524       const SMDS_MeshElement* f = faceIt->next();
525       if ( !avoidSet.count( f ) && f->GetNodeIndex( n2 ) >= 0 )
526         return f;
527     }
528     return 0;
529   }
530
531   //================================================================================
532   /*!
533    * \brief Check that a segment bounds a face belonging to smOfFaces
534    */
535   //================================================================================
536
537   bool IsSegmentOnSubMeshBoundary( const SMDS_MeshNode*   n1,
538                                    const SMDS_MeshNode*   n2,
539                                    const SMESHDS_SubMesh* smOfFaces,
540                                    SMESH_ProxyMesh&       mesh)
541   {
542     TIDSortedElemSet avoidSet;
543     bool faceFound = false;
544
545     while ( const SMDS_MeshElement* f = FindFaceByNodes( n1, n2, avoidSet, mesh ))
546     {
547       if (( faceFound = smOfFaces->Contains( f )))
548         break;
549       avoidSet.insert( f );
550     }
551     return faceFound;
552   }
553
554     //================================================================================
555   /*!
556    * \brief Rearrange block sides according to StdMeshers_BlockRenumber hypothesis
557    */
558   //================================================================================
559
560   bool arrangeForRenumber( list< _QuadFaceGrid >&     blockSides,
561                            const TopTools_MapOfShape& cornerVertices,
562                            SMESH_Mesh*                mesh,
563                            TopoDS_Vertex&             v000,
564                            TopoDS_Vertex&             v001 )
565   {
566     if ( v000.IsNull() )
567     {
568       // block CS is not defined;
569       // renumber only if the block has an edge parallel to an axis of global CS
570
571       v000 = StdMeshers_RenumberHelper::GetVertex000( cornerVertices );
572     }
573
574     Bnd_B3d bbox;
575     for ( auto it = cornerVertices.cbegin(); it != cornerVertices.cend(); ++it )
576       bbox.Add( BRep_Tool::Pnt( TopoDS::Vertex( *it )));
577     double tol = 1e-5 * Sqrt( bbox.SquareExtent() );
578
579     // get block edges starting at v000
580
581     std::vector< const _FaceSide* > edgesAtV000;
582     std::vector< gp_Vec >           edgeDir;
583     std::vector< int >              iParallel; // 0 - none, 1 - X, 2 - Y, 3 - Z
584     TopTools_MapOfShape             lastVertices;
585     for ( _QuadFaceGrid & quad: blockSides )
586     {
587       for ( int iS = 0; iS < 4 &&  edgesAtV000.size() < 3; ++iS )
588       {
589         const _FaceSide* side = & quad.GetSide( iS );
590         TopoDS_Vertex v1 = side->FirstVertex(), v2 = side->LastVertex();
591         if (( v1.IsSame( v000 ) && !lastVertices.Contains( v2 )) ||
592             ( v2.IsSame( v000 ) && !lastVertices.Contains( v1 )))
593         {
594           bool reverse = v2.IsSame( v000 );
595           if ( reverse )
596             std::swap( v1, v2 );
597           lastVertices.Add( v2 );
598
599           edgesAtV000.push_back( side );
600
601           gp_Pnt pf = BRep_Tool::Pnt( v1 );
602           gp_Pnt pl = BRep_Tool::Pnt( v2 );
603           gp_Vec vec( pf, pl );
604           edgeDir.push_back( vec );
605
606           iParallel.push_back( 0 );
607           if ( !v001.IsNull() )
608           {
609             if ( quad.IsComplex() )
610               for ( _QuadFaceGrid::TChildIterator chIt = quad.GetChildren(); chIt.more(); )
611               {
612                 const _QuadFaceGrid& child = chIt.next();
613                 if ( child.GetSide( iS ).Contain( v001 ))
614                 {
615                   iParallel.back() = 3;
616                   break;
617                 }
618               }
619             else if ( side->Contain( v001 ))
620               iParallel.back() = 3;
621           }
622           else
623           {
624             bool isStraight = true;
625             std::list< TopoDS_Edge > edges;
626             for ( int iE = 0; true; ++iE )
627             {
628               TopoDS_Edge edge = side->Edge( iE );
629               if ( edge.IsNull() )
630                 break;
631               edges.push_back( edge );
632               if ( isStraight )
633                 isStraight = SMESH_Algo::IsStraight( edge );
634             }
635             // is parallel to a GCS axis?
636             if ( isStraight )
637             {
638               int nbDiff = (( Abs( vec.X() ) > tol ) +
639                             ( Abs( vec.Y() ) > tol ) +
640                             ( Abs( vec.Z() ) > tol ) );
641               if ( nbDiff == 1 )
642                 iParallel.back() = ( Abs( vec.X() ) > tol ) ? 1 : ( Abs( vec.Y() ) > tol ) ? 2 : 3;
643             }
644             else
645             {
646               TopoDS_Face nullFace;
647               StdMeshers_FaceSide fSide( nullFace, edges, mesh, true, true );
648               edgeDir.back() = gp_Vec( pf, fSide.Value3d( reverse ? 0.99 : 0.01 ));
649             }
650           }
651         }
652       }
653     }
654     if ( std::accumulate( iParallel.begin(), iParallel.end(), 0 ) == 0 )
655       return false;
656
657     // find edge OZ and edge OX
658     const _FaceSide* edgeOZ = nullptr, *edgeOY = nullptr, *edgeOX = nullptr;
659     auto iZIt = std::find( iParallel.begin(), iParallel.end(), 3 );
660     if ( iZIt != iParallel.end() )
661     {
662       int i = std::distance( iParallel.begin(), iZIt );
663       edgeOZ = edgesAtV000[ i ];
664       int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
665       int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
666       if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
667         std::swap( iE1, iE2 );
668       edgeOX = edgesAtV000[ iE1 ];
669       edgeOY = edgesAtV000[ iE2 ];
670     }
671     else
672     {
673       for ( size_t i = 0; i < edgesAtV000.size(); ++i )
674       {
675         if ( !iParallel[ i ] )
676           continue;
677         int iE1 = SMESH_MesherHelper::WrapIndex( i + 1, edgesAtV000.size() );
678         int iE2 = SMESH_MesherHelper::WrapIndex( i + 2, edgesAtV000.size() );
679         if (( edgeDir[ iE1 ] ^ edgeDir[ iE2 ] ) * edgeDir[ i ] < 0 )
680           std::swap( iE1, iE2 );
681         edgeOZ = edgesAtV000[ iParallel[i] == 1 ? iE2 : iE1 ];
682         edgeOX = edgesAtV000[ iParallel[i] == 1 ? i : iE1 ];
683         edgeOY = edgesAtV000[ iParallel[i] == 1 ? iE1 : i ];
684         break;
685       }
686     }
687
688     if ( !edgeOZ || !edgeOX || !edgeOY )
689       return false;
690
691     TopoDS_Vertex v100 = edgeOX->LastVertex();
692     if ( v100.IsSame( v000 ))
693       v100 = edgeOX->FirstVertex();
694
695     // Find the left quad, one including v000 but not v100
696
697     for ( auto quad = blockSides.begin(); quad != blockSides.end(); ++quad )
698     {
699       if ( quad->Contain( v000 ) && !quad->Contain( v100 )) // it's a left quad
700       {
701         if ( quad != blockSides.begin() )
702           blockSides.splice( blockSides.begin(), blockSides, quad );
703         blockSides.front().SetBottomSide( *edgeOZ ); // edgeOY
704
705         return true;
706       }
707     }
708     return false;
709   }
710
711 } // namespace
712
713 //================================================================================
714 /*!
715  * \brief Tries to find 6 sides of a box
716  */
717 //================================================================================
718
719 bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
720                                                 list< _QuadFaceGrid >& boxFaces,
721                                                 SMESH_Mesh&            mesh,
722                                                 SMESH_ProxyMesh&       proxyMesh,
723                                                 bool&                  toRenumber,
724                                                 _QuadFaceGrid * &      fBottom,
725                                                 _QuadFaceGrid * &      fTop,
726                                                 _QuadFaceGrid * &      fFront,
727                                                 _QuadFaceGrid * &      fBack,
728                                                 _QuadFaceGrid * &      fLeft,
729                                                 _QuadFaceGrid * &      fRight)
730 {
731   TopTools_MapOfShape cornerVertices;
732   getBlockCorners( proxyMesh, shape, cornerVertices );
733   if ( cornerVertices.Extent() != 8 )
734     return error( COMPERR_BAD_INPUT_MESH, "Can't find 8 corners of a block by 2D mesh" );
735   TopTools_MapOfShape internalEdges;
736   if ( !getInternalEdges( mesh, shape, cornerVertices, internalEdges ))
737     return error( COMPERR_BAD_INPUT_MESH, "2D mesh is not suitable for i,j,k hexa meshing" );
738
739   list< _QuadFaceGrid >::iterator boxFace;
740   TopExp_Explorer exp;
741   int nbFaces = 0;
742   for ( exp.Init( shape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFaces )
743   {
744     _QuadFaceGrid f;
745     if ( !f.Init( TopoDS::Face( exp.Current() ), proxyMesh ))
746       return error (COMPERR_BAD_SHAPE);
747
748     _QuadFaceGrid* prevContinuous = 0;
749     for ( boxFace = boxFaces.begin(); boxFace != boxFaces.end(); ++boxFace )
750     {
751       if ( prevContinuous )
752       {
753         if ( prevContinuous->AddContinuousFace( *boxFace, internalEdges ))
754           boxFace = --boxFaces.erase( boxFace );
755       }
756       else if ( boxFace->AddContinuousFace( f, internalEdges ))
757       {
758         prevContinuous = & (*boxFace);
759       }
760     }
761     if ( !prevContinuous )
762       boxFaces.push_back( f );
763   }
764   // Check what we have
765   if ( boxFaces.size() != 6 && nbFaces != 6)
766     return error
767       (COMPERR_BAD_SHAPE,
768        SMESH_Comment("Can't find 6 sides of a box. Number of found sides - ")<<boxFaces.size());
769
770   if ( boxFaces.size() != 6 && nbFaces == 6 ) { // strange ordinary box with continuous faces
771     boxFaces.resize( 6 );
772     boxFace = boxFaces.begin();
773     for ( exp.Init( shape, TopAbs_FACE); exp.More(); exp.Next(), ++boxFace )
774       boxFace->Init( TopoDS::Face( exp.Current() ), proxyMesh );
775   }
776
777   toRenumber = _blockRenumberHyp;
778   if ( toRenumber )
779   {
780     TopoDS_Vertex v000, v001;
781     _blockRenumberHyp->IsSolidIncluded( mesh, shape, v000, v001 );
782
783     toRenumber = arrangeForRenumber( boxFaces, cornerVertices, &mesh, v000, v001 );
784
785     if ( toRenumber )
786     {
787       mesh.GetMeshDS()->Modified();
788       mesh.GetMeshDS()->CompactMesh(); // remove numbering holes
789     }
790   }
791   
792   // ----------------------------------------
793   // Find out position of faces within a box
794   // ----------------------------------------
795   // start from a bottom face
796   fBottom = &boxFaces.front();
797   fBottom->SetID( B_BOTTOM );
798   // find vertical faces
799   fFront = fBottom->FindAdjacentForSide( Q_BOTTOM, boxFaces, B_FRONT );
800   fLeft  = fBottom->FindAdjacentForSide( Q_RIGHT,  boxFaces, B_LEFT  );
801   fBack  = fBottom->FindAdjacentForSide( Q_TOP,    boxFaces, B_BACK  );
802   fRight = fBottom->FindAdjacentForSide( Q_LEFT,   boxFaces, B_RIGHT );
803   // check the found
804   if ( !fFront || !fBack || !fLeft || !fRight )
805     return error(COMPERR_BAD_SHAPE);
806   // find a top face
807   fTop = 0;
808   for ( boxFace = ++boxFaces.begin(); boxFace != boxFaces.end() && !fTop; ++boxFace )
809   {
810     fTop = & (*boxFace);
811     fTop->SetID( B_TOP );
812     if ( fTop==fFront || fTop==fLeft || fTop==fBack || fTop==fRight )
813       fTop = 0;
814   }
815   // set bottom of the top side
816   if ( !fTop->SetBottomSide( fFront->GetSide( Q_TOP ) )) {
817     if ( !fFront->IsComplex() )
818       return error( ERR_LI("Error in StdMeshers_CompositeHexa_3D::Compute()"));
819     else {
820       _QuadFaceGrid::TChildIterator chIt = fFront->GetChildren();
821       while ( chIt.more() ) {
822         const _QuadFaceGrid& frontChild = chIt.next();
823         if ( fTop->SetBottomSide( frontChild.GetSide( Q_TOP )))
824           break;
825       }
826     }
827   }
828   if ( !fTop )
829     return error(COMPERR_BAD_SHAPE);
830
831   // orient bottom edge of faces along axes of the unit box
832   fBottom->ReverseEdges();
833   fBack  ->ReverseEdges();
834   fLeft  ->ReverseEdges();
835
836   return true;
837 }
838
839 //================================================================================
840 /*!
841  * \brief Computes hexahedral mesh on a box with composite sides
842  *  \param aMesh - mesh to compute
843  *  \param aShape - shape to mesh
844  *  \retval bool - success sign
845  */
846 //================================================================================
847
848 bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh&         theMesh,
849                                           const TopoDS_Shape& theShape)
850 {
851   SMESH_MesherHelper helper( theMesh );
852   _quadraticMesh = helper.IsQuadraticSubMesh( theShape );
853   helper.SetElementsOnShape( true );
854
855   // get Viscous Mesh
856   SMESH_ProxyMesh::Ptr proxyMesh;
857   SMESH_HypoFilter vlFilter( SMESH_HypoFilter::HasName( StdMeshers_ViscousLayers::GetHypType() ));
858   const SMESH_Hypothesis *          hyp = theMesh.GetHypothesis( theShape, vlFilter, true );
859   const StdMeshers_ViscousLayers* vlHyp = static_cast< const StdMeshers_ViscousLayers* >( hyp );
860   if ( vlHyp )
861     proxyMesh = vlHyp->Compute( theMesh, theShape, /*toMakeN2NMap=*/true );
862   else
863     proxyMesh.reset( new SMESH_ProxyMesh( theMesh ));
864
865   // -------------------------
866   // Try to find 6 side faces
867   // -------------------------
868   list< _QuadFaceGrid > boxFaceContainer;
869   bool toRenumber = false;
870   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
871   if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
872                        fBottom, fTop, fFront, fBack, fLeft, fRight))
873     return false;
874
875   // ------------------------------------------
876   // Fill columns of nodes with existing nodes
877   // ------------------------------------------
878
879   // let faces load their grids
880   if ( !fBottom->LoadGrid( *proxyMesh )) return error( fBottom->GetError() );
881   if ( !fBack  ->LoadGrid( *proxyMesh )) return error( fBack  ->GetError() );
882   if ( !fLeft  ->LoadGrid( *proxyMesh )) return error( fLeft  ->GetError() );
883   if ( !fFront ->LoadGrid( *proxyMesh )) return error( fFront ->GetError() );
884   if ( !fRight ->LoadGrid( *proxyMesh )) return error( fRight ->GetError() );
885   if ( !fTop   ->LoadGrid( *proxyMesh )) return error( fTop   ->GetError() );
886
887   // compute normalized parameters of nodes on sides (PAL23189)
888   fBottom->ComputeIJK( COO_X, COO_Y, /*z=*/0. );
889   fBack  ->ComputeIJK( COO_X, COO_Z, /*y=*/1. );
890   fLeft  ->ComputeIJK( COO_Y, COO_Z, /*x=*/0. );
891   fFront ->ComputeIJK( COO_X, COO_Z, /*y=*/0. );
892   fRight ->ComputeIJK( COO_Y, COO_Z, /*x=*/1. );
893   fTop   ->ComputeIJK( COO_X, COO_Y, /*z=*/1. );
894
895   StdMeshers_RenumberHelper renumHelper( theMesh, _blockRenumberHyp );
896
897   int x, xSize = fBottom->GetNbHoriSegments(*proxyMesh) + 1, X = xSize - 1;
898   int y, ySize = fBottom->GetNbVertSegments(*proxyMesh) + 1, Y = ySize - 1;
899   int z, zSize = fFront ->GetNbVertSegments(*proxyMesh) + 1, Z = zSize - 1;
900   _Indexer colIndex( xSize, ySize );
901   vector< vector< const SMDS_MeshNode* > > columns( colIndex.size() );
902
903   // fill node columns by front and back box sides
904   for ( x = 0; x < xSize; ++x ) {
905     vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( x, 0 )];
906     vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( x, Y )];
907     column0.resize( zSize );
908     column1.resize( zSize );
909     for ( z = 0; z < zSize; ++z ) {
910       column0[ z ] = fFront->GetNode( x, z );
911       column1[ z ] = fBack ->GetNode( x, z );
912     }
913   }
914   // fill node columns by left and right box sides
915   for ( y = 1; y < ySize-1; ++y ) {
916     vector< const SMDS_MeshNode* >& column0 = columns[ colIndex( 0, y )];
917     vector< const SMDS_MeshNode* >& column1 = columns[ colIndex( X, y )];
918     column0.resize( zSize );
919     column1.resize( zSize );
920     for ( z = 0; z < zSize; ++z ) {
921       column0[ z ] = fLeft ->GetNode( y, z );
922       column1[ z ] = fRight->GetNode( y, z );
923     }
924   }
925   // get nodes from top and bottom box sides
926   for ( x = 1; x < xSize-1; ++x ) {
927     for ( y = 1; y < ySize-1; ++y ) {
928       vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
929       column.resize( zSize );
930       column.front() = fBottom->GetNode( x, y );
931       column.back()  = fTop   ->GetNode( x, y );
932     }
933   }
934
935   // ----------------------------
936   // Add internal nodes of a box
937   // ----------------------------
938   // projection points of internal nodes on box sub-shapes by which
939   // coordinates of internal nodes are computed
940   vector<gp_XYZ> pointsOnShapes( SMESH_Block::ID_Shell );
941
942   // projections on vertices are constant
943   pointsOnShapes[ SMESH_Block::ID_V000 ] = fBottom->GetXYZ( 0, 0 );
944   pointsOnShapes[ SMESH_Block::ID_V100 ] = fBottom->GetXYZ( X, 0 );
945   pointsOnShapes[ SMESH_Block::ID_V010 ] = fBottom->GetXYZ( 0, Y );
946   pointsOnShapes[ SMESH_Block::ID_V110 ] = fBottom->GetXYZ( X, Y );
947   pointsOnShapes[ SMESH_Block::ID_V001 ] = fTop->GetXYZ( 0, 0 );
948   pointsOnShapes[ SMESH_Block::ID_V101 ] = fTop->GetXYZ( X, 0 );
949   pointsOnShapes[ SMESH_Block::ID_V011 ] = fTop->GetXYZ( 0, Y );
950   pointsOnShapes[ SMESH_Block::ID_V111 ] = fTop->GetXYZ( X, Y );
951
952   gp_XYZ params; // normalized parameters of an internal node within the unit box
953
954   if ( toRenumber )
955     for ( y = 0; y < ySize; ++y )
956     {
957       vector< const SMDS_MeshNode* >& columnXy = columns[ colIndex( X, y )];
958       for ( z = 0; z < zSize; ++z )
959         renumHelper.AddReplacingNode( columnXy[ z ] );
960     }
961
962   for ( x = X-1; x > 0; --x )
963   {
964     if ( toRenumber )
965     {
966       vector< const SMDS_MeshNode* >& columnX0 = columns[ colIndex( x, 0 )];
967       for ( z = 0; z < zSize; ++z )
968         renumHelper.AddReplacingNode( columnX0[ z ] );
969     }
970
971     const double rX = x / double(X);
972     for ( y = 1; y < ySize-1; ++y )
973     {
974       const double rY = y / double(Y);
975       // column to fill during z loop
976       vector< const SMDS_MeshNode* >& column = columns[ colIndex( x, y )];
977       // points projections on horizontal edges
978       pointsOnShapes[ SMESH_Block::ID_Ex00 ] = fBottom->GetXYZ( x, 0 );
979       pointsOnShapes[ SMESH_Block::ID_Ex10 ] = fBottom->GetXYZ( x, Y );
980       pointsOnShapes[ SMESH_Block::ID_E0y0 ] = fBottom->GetXYZ( 0, y );
981       pointsOnShapes[ SMESH_Block::ID_E1y0 ] = fBottom->GetXYZ( X, y );
982       pointsOnShapes[ SMESH_Block::ID_Ex01 ] = fTop->GetXYZ( x, 0 );
983       pointsOnShapes[ SMESH_Block::ID_Ex11 ] = fTop->GetXYZ( x, Y );
984       pointsOnShapes[ SMESH_Block::ID_E0y1 ] = fTop->GetXYZ( 0, y );
985       pointsOnShapes[ SMESH_Block::ID_E1y1 ] = fTop->GetXYZ( X, y );
986       // points projections on horizontal faces
987       pointsOnShapes[ SMESH_Block::ID_Fxy0 ] = fBottom->GetXYZ( x, y );
988       pointsOnShapes[ SMESH_Block::ID_Fxy1 ] = fTop   ->GetXYZ( x, y );
989
990       if ( toRenumber )
991         renumHelper.AddReplacingNode( column[ 0 ] );
992
993       for ( z = 1; z < zSize-1; ++z ) // z loop
994       {
995         // compute normalized parameters of an internal node within the unit box
996         const double   rZ = z / double(Z);
997         const gp_XYZ& pBo = fBottom->GetIJK( x, y );
998         const gp_XYZ& pTo = fTop   ->GetIJK( x, y );
999         const gp_XYZ& pFr = fFront ->GetIJK( x, z );
1000         const gp_XYZ& pBa = fBack  ->GetIJK( x, z );
1001         const gp_XYZ& pLe = fLeft  ->GetIJK( y, z );
1002         const gp_XYZ& pRi = fRight ->GetIJK( y, z );
1003         params.SetCoord( 1, 0.5 * ( pBo.X() * ( 1. - rZ ) + pTo.X() * rZ  +
1004                                     pFr.X() * ( 1. - rY ) + pBa.X() * rY ));
1005         params.SetCoord( 2, 0.5 * ( pBo.Y() * ( 1. - rZ ) + pTo.Y() * rZ  +
1006                                     pLe.Y() * ( 1. - rX ) + pRi.Y() * rX ));
1007         params.SetCoord( 3, 0.5 * ( pFr.Z() * ( 1. - rY ) + pBa.Z() * rY  +
1008                                     pLe.Z() * ( 1. - rX ) + pRi.Z() * rX ));
1009
1010         // point projections on vertical edges
1011         pointsOnShapes[ SMESH_Block::ID_E00z ] = fFront->GetXYZ( 0, z );
1012         pointsOnShapes[ SMESH_Block::ID_E10z ] = fFront->GetXYZ( X, z );
1013         pointsOnShapes[ SMESH_Block::ID_E01z ] = fBack->GetXYZ( 0, z );
1014         pointsOnShapes[ SMESH_Block::ID_E11z ] = fBack->GetXYZ( X, z );
1015         // point projections on vertical faces
1016         pointsOnShapes[ SMESH_Block::ID_Fx0z ] = fFront->GetXYZ( x, z );
1017         pointsOnShapes[ SMESH_Block::ID_Fx1z ] = fBack ->GetXYZ( x, z );    
1018         pointsOnShapes[ SMESH_Block::ID_F0yz ] = fLeft ->GetXYZ( y, z );    
1019         pointsOnShapes[ SMESH_Block::ID_F1yz ] = fRight->GetXYZ( y, z );
1020
1021         // compute internal node coordinates
1022         gp_XYZ coords;
1023         SMESH_Block::ShellPoint( params, pointsOnShapes, coords );
1024         column[ z ] = helper.AddNode( coords.X(), coords.Y(), coords.Z() );
1025
1026 #ifdef DEB_GRID
1027         // debug
1028         //cout << "----------------------------------------------------------------------"<<endl;
1029         //for ( int id = SMESH_Block::ID_V000; id < SMESH_Block::ID_Shell; ++id)
1030         //{
1031         //  gp_XYZ p = pointsOnShapes[ id ];
1032         //  SMESH_Block::DumpShapeID( id,cout)<<" ( "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<" )"<<endl;
1033         //}
1034         //cout << "Params: ( "<< params.X()<<", "<<params.Y()<<", "<<params.Z()<<" )"<<endl;
1035         //cout << "coords: ( "<< coords.X()<<", "<<coords.Y()<<", "<<coords.Z()<<" )"<<endl;
1036 #endif
1037       } // z loop
1038       if ( toRenumber )
1039         renumHelper.AddReplacingNode( column[ Z ] );
1040
1041     } // y loop
1042     if ( toRenumber )
1043     {
1044       vector< const SMDS_MeshNode* >& columnXY = columns[ colIndex( x, Y )];
1045       for ( z = 0; z < zSize; ++z )
1046         renumHelper.AddReplacingNode( columnXY[ z ] );
1047     }
1048   } // for ( x = X-1; x > 0; --x )
1049
1050   if ( toRenumber )
1051     for ( y = 0; y < ySize; ++y )
1052     {
1053       vector< const SMDS_MeshNode* >& column0Y = columns[ colIndex( 0, y )];
1054       for ( z = 0; z < zSize; ++z )
1055         renumHelper.AddReplacingNode( column0Y[ z ] );
1056     }
1057
1058
1059   // faces no more needed, free memory
1060   boxFaceContainer.clear();
1061
1062   // ----------------
1063   // Add hexahedrons
1064   // ----------------
1065   for ( x = xSize-2; true; --x ) {
1066     for ( y = 0; y < ySize-1; ++y ) {
1067       vector< const SMDS_MeshNode* >& col00 = columns[ colIndex( x, y )];
1068       vector< const SMDS_MeshNode* >& col10 = columns[ colIndex( x+1, y )];
1069       vector< const SMDS_MeshNode* >& col01 = columns[ colIndex( x, y+1 )];
1070       vector< const SMDS_MeshNode* >& col11 = columns[ colIndex( x+1, y+1 )];
1071       for ( z = 0; z < zSize-1; ++z )
1072       {
1073         // bottom face normal of a hexa mush point outside the volume
1074         helper.AddVolume(col10[z], col11[z], col11[z+1], col10[z+1],
1075                          col00[z], col01[z], col01[z+1], col00[z+1]);
1076       }
1077     }
1078     if ( x == 0)
1079       break;
1080
1081   }
1082   if ( toRenumber )
1083     renumHelper.DoReplaceNodes();
1084
1085   if ( _blockRenumberHyp )
1086   {
1087     return error( _blockRenumberHyp->CheckHypothesis( theMesh, theShape ));
1088   }
1089
1090   return true;
1091 }
1092
1093 //================================================================================
1094 /*!
1095  *  Evaluate
1096  */
1097 //================================================================================
1098
1099 bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh&         theMesh,
1100                                            const TopoDS_Shape& theShape,
1101                                            MapShapeNbElems&    aResMap)
1102 {
1103   SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh ));
1104
1105   // -------------------------
1106   // Try to find 6 side faces
1107   // -------------------------
1108   list< _QuadFaceGrid > boxFaceContainer;
1109   _QuadFaceGrid *fBottom, *fTop, *fFront, *fBack, *fLeft, *fRight;
1110   bool toRenumber = false;
1111   if ( ! findBoxFaces( theShape, boxFaceContainer, theMesh, *proxyMesh, toRenumber,
1112                        fBottom, fTop, fFront, fBack, fLeft, fRight))
1113     return false;
1114
1115   // Find a less complex side
1116   _QuadFaceGrid * lessComplexSide = & boxFaceContainer.front();
1117   list< _QuadFaceGrid >::iterator face = boxFaceContainer.begin();
1118   for ( ++face; face != boxFaceContainer.end() && lessComplexSide->IsComplex(); ++face )
1119     if ( face->NbChildren() < lessComplexSide->NbChildren() )
1120       lessComplexSide = & *face;
1121
1122   // Get an 1D size of lessComplexSide
1123   int nbSeg1 = 0;
1124   vector<TopoDS_Edge> edges;
1125   if ( !lessComplexSide->GetHoriEdges(edges) )
1126     return false;
1127   for ( size_t i = 0; i < edges.size(); ++i )
1128   {
1129     const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1130     if ( !nbElems.empty() )
1131       nbSeg1 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1132   }
1133
1134   // Get an 1D size of a box side orthogonal to lessComplexSide
1135   int nbSeg2 = 0;
1136   _QuadFaceGrid* ortoSide =
1137     lessComplexSide->FindAdjacentForSide( Q_LEFT, boxFaceContainer, B_UNDEFINED );
1138   edges.clear();
1139   if ( !ortoSide || !ortoSide->GetHoriEdges(edges) ) return false;
1140   for ( size_t i = 0; i < edges.size(); ++i )
1141   {
1142     const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( edges[i] )];
1143     if ( !nbElems.empty() )
1144       nbSeg2 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
1145   }
1146
1147   // Get an 2D size of a box side orthogonal to lessComplexSide
1148   int nbFaces = 0, nbQuadFace = 0;
1149   list< TopoDS_Face > sideFaces;
1150   if ( ortoSide->IsComplex() )
1151     for ( _QuadFaceGrid::TChildIterator child = ortoSide->GetChildren(); child.more(); )
1152       sideFaces.push_back( child.next().GetFace() );
1153   else
1154     sideFaces.push_back( ortoSide->GetFace() );
1155   //
1156   list< TopoDS_Face >::iterator f = sideFaces.begin();
1157   for ( ; f != sideFaces.end(); ++f )
1158   {
1159     const vector<int>& nbElems = aResMap[ theMesh.GetSubMesh( *f )];
1160     if ( !nbElems.empty() )
1161     {
1162       nbFaces    = nbElems[ SMDSEntity_Quadrangle ];
1163       nbQuadFace = nbElems[ SMDSEntity_Quad_Quadrangle ];
1164     }
1165   }
1166
1167   // Fill nb of elements
1168   vector<int> aResVec(SMDSEntity_Last,0);
1169   int nbSeg3 = ( nbFaces + nbQuadFace ) / nbSeg2;
1170   aResVec[SMDSEntity_Node]       = (nbSeg1-1) * (nbSeg2-1) * (nbSeg3-1);
1171   aResVec[SMDSEntity_Hexa]       = nbSeg1 * nbFaces;
1172   aResVec[SMDSEntity_Quad_Hexa]  = nbSeg1 * nbQuadFace;
1173
1174   aResMap.insert( make_pair( theMesh.GetSubMesh(theShape), aResVec ));
1175
1176   return true;
1177 }
1178
1179
1180 //================================================================================
1181 /*!
1182  * \brief constructor of non-initialized _QuadFaceGrid
1183  */
1184 //================================================================================
1185
1186 _QuadFaceGrid::_QuadFaceGrid():
1187   myReverse(false), myRightBrother(0), myUpBrother(0), myIndexer(0,0), myID(B_UNDEFINED)
1188 {
1189 }
1190
1191 //================================================================================
1192 /*!
1193  * \brief Initialization
1194  */
1195 //================================================================================
1196
1197 bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_ProxyMesh& mesh)
1198 {
1199   myFace         = f;
1200   mySides        = _FaceSide();
1201   myReverse      = false;
1202   myLeftBottomChild = myRightBrother = myUpBrother = 0;
1203   myChildren.clear();
1204   myGrid.clear();
1205   //if ( myFace.Orientation() != TopAbs_FORWARD )
1206     //myFace.Reverse();
1207
1208   list< TopoDS_Edge > edges;
1209   list< int > nbEdgesInWire;
1210   int nbWire = SMESH_Block::GetOrderedEdges (myFace, edges, nbEdgesInWire);
1211   if ( nbWire != 1 )
1212     return false;
1213
1214   list< TopoDS_Edge >::iterator edgeIt = edges.begin();
1215   if ( nbEdgesInWire.front() == 4 ) // exactly 4 edges
1216   {
1217     for ( ; edgeIt != edges.end(); ++edgeIt )
1218       mySides.AppendSide( _FaceSide( *edgeIt ));
1219   }
1220   else if ( nbEdgesInWire.front() > 4 ) { // more than 4 edges - try to unite some
1221     list< TopoDS_Edge > sideEdges;
1222     while ( !edges.empty()) {
1223       sideEdges.clear();
1224       sideEdges.splice( sideEdges.end(), edges, edges.begin());// edges.front()->sideEdges.back()
1225       if ( SMESH_Algo::isDegenerated( sideEdges.back() ))
1226         continue;
1227       while ( !edges.empty() ) {
1228         if ( isContinuousMesh( sideEdges.back(), edges.front(), f, mesh )) {
1229           sideEdges.splice( sideEdges.end(), edges, edges.begin());
1230         }
1231         else if ( isContinuousMesh( sideEdges.front(), edges.back(), f, mesh )) {
1232           sideEdges.splice( sideEdges.begin(), edges, --edges.end());
1233         }
1234         else {
1235           break;
1236         }
1237       }
1238       mySides.AppendSide( _FaceSide( sideEdges ));
1239     }
1240   }
1241   if (mySides.size() != 4)
1242     return false;
1243
1244 #ifdef _DEBUG_
1245   mySides.GetSide( Q_BOTTOM )->SetID( Q_BOTTOM );
1246   mySides.GetSide( Q_RIGHT  )->SetID( Q_RIGHT );
1247   mySides.GetSide( Q_TOP    )->SetID( Q_TOP );
1248   mySides.GetSide( Q_LEFT   )->SetID( Q_LEFT );
1249 #endif
1250
1251   return true;
1252 }
1253
1254 //================================================================================
1255 /*!
1256  * \brief Try to unite self with other ordinary face
1257  */
1258 //================================================================================
1259
1260 bool _QuadFaceGrid::AddContinuousFace( const _QuadFaceGrid&       other,
1261                                        const TopTools_MapOfShape& internalEdges)
1262 {
1263   for ( int i = 0; i < 4; ++i )
1264   {
1265     const _FaceSide& otherSide = other.GetSide( i );
1266     int iMyCommon;
1267     if ( mySides.Contain( otherSide, &iMyCommon ))
1268     {
1269       if ( internalEdges.Contains( otherSide.Edge( 0 )))
1270       {
1271         DUMP_VERT("Cont 1", mySides.GetSide(iMyCommon)->FirstVertex());
1272         DUMP_VERT("Cont 2", mySides.GetSide(iMyCommon)->LastVertex());
1273         DUMP_VERT("Cont 3", otherSide.FirstVertex());
1274         DUMP_VERT("Cont 4", otherSide.LastVertex());
1275
1276         if ( myChildren.empty() )
1277         {
1278           myChildren.push_back( *this );
1279           myFace.Nullify();
1280         }
1281         else // find iMyCommon in myChildren
1282         {
1283           for ( TChildIterator children = GetChildren(); children.more(); ) {
1284             const _QuadFaceGrid& child = children.next();
1285             if ( child.mySides.Contain( otherSide, &iMyCommon ))
1286               break;
1287           }
1288         }
1289
1290         // orient new children equally
1291         int otherBottomIndex = SMESH_MesherHelper::WrapIndex( i - iMyCommon + 2, 4 );
1292         if ( other.IsComplex() )
1293           for ( TChildIterator children = other.GetChildren(); children.more(); ) {
1294             myChildren.push_back( children.next() );
1295             myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1296           }
1297         else {
1298           myChildren.push_back( other );
1299           myChildren.back().SetBottomSide( myChildren.back().GetSide( otherBottomIndex ));
1300         }
1301
1302         myLeftBottomChild = 0;
1303
1304         // collect vertices in mySides
1305         if ( other.IsComplex() )
1306           for ( TChildIterator children = other.GetChildren(); children.more(); )
1307           {
1308             const _QuadFaceGrid& child = children.next();
1309             for ( int i = 0; i < 4; ++i )
1310               mySides.AppendSide( child.GetSide(i) );
1311           }
1312         else
1313           for ( int i = 0; i < 4; ++i )
1314             mySides.AppendSide( other.GetSide(i) );
1315
1316         return true;
1317       }
1318     }
1319   }
1320   return false;
1321 }
1322
1323 //================================================================================
1324 /*!
1325  * \brief Try to set the side as bottom hirizontal side
1326  */
1327 //================================================================================
1328
1329 bool _QuadFaceGrid::SetBottomSide(const _FaceSide& bottom, int* sideIndex)
1330 {
1331   myLeftBottomChild = myRightBrother = myUpBrother = 0;
1332
1333   int myBottomIndex;
1334   if ( myChildren.empty() )
1335   {
1336     if ( mySides.Contain( bottom, &myBottomIndex )) {
1337       mySides.SetBottomSide( myBottomIndex );
1338       if ( sideIndex )
1339         *sideIndex = myBottomIndex;
1340       return true;
1341     }
1342   }
1343   else
1344   {
1345     TChildren::iterator childFace = myChildren.begin(), childEnd = myChildren.end();
1346     for ( ; childFace != childEnd; ++childFace )
1347     {
1348       if ( childFace->SetBottomSide( bottom, &myBottomIndex ))
1349       {
1350         TChildren::iterator orientedChild = childFace;
1351         for ( childFace = myChildren.begin(); childFace != childEnd; ++childFace ) {
1352           if ( childFace != orientedChild )
1353             childFace->SetBottomSide( childFace->GetSide( myBottomIndex ));
1354         }
1355         if ( sideIndex )
1356           *sideIndex = myBottomIndex;
1357         return true;
1358       }
1359     }
1360   }
1361   return false;
1362 }
1363
1364 //================================================================================
1365 /*!
1366  * \brief Return face adjacent to i-th side of this face, (0<i<4)
1367  */
1368 //================================================================================
1369
1370 _QuadFaceGrid* _QuadFaceGrid::FindAdjacentForSide(int                  i,
1371                                                   list<_QuadFaceGrid>& faces,
1372                                                   EBoxSides            id) const
1373 {
1374   const _FaceSide & iSide = GetSide( i );
1375   list< _QuadFaceGrid >::iterator boxFace = faces.begin();
1376   for ( ; boxFace != faces.end(); ++boxFace )
1377   {
1378     _QuadFaceGrid* f  = & (*boxFace);
1379     if ( f != this && f->SetBottomSide( iSide ))
1380       return f->SetID( id ), f;
1381   }
1382   return (_QuadFaceGrid*) 0;
1383 }
1384
1385 //================================================================================
1386 /*!
1387  * \brief Return i-th side
1388  */
1389 //================================================================================
1390
1391 const _FaceSide& _QuadFaceGrid::GetSide(int i) const
1392 {
1393   if ( myChildren.empty() )
1394     return *mySides.GetSide(i);
1395
1396   _QuadFaceGrid* me = const_cast<_QuadFaceGrid*>(this);
1397   if ( !me->locateChildren() || !myLeftBottomChild )
1398     return *mySides.GetSide(i);
1399
1400   const _QuadFaceGrid* child = myLeftBottomChild;
1401   switch ( i ){
1402   case Q_BOTTOM:
1403   case Q_LEFT:
1404     break;
1405   case Q_RIGHT:
1406     while ( child->myRightBrother )
1407       child = child->myRightBrother;
1408     break;
1409   case Q_TOP:
1410     while ( child->myUpBrother )
1411       child = child->myUpBrother;
1412     break;
1413   default: ;
1414   }
1415   return child->GetSide( i );
1416 }
1417
1418 //================================================================================
1419 /*!
1420  * \brief Reverse edges in order to have them oriented along axes of the unit box
1421  */
1422 //================================================================================
1423
1424 void _QuadFaceGrid::ReverseEdges()
1425 {
1426   myReverse = !myReverse;
1427
1428 // #ifdef DEB_FACES
1429 //   if ( !myFace.IsNull() )
1430 //     TopAbs::Print(myFace.Orientation(), cout);
1431 // #endif
1432
1433   if ( myChildren.empty() )
1434   {
1435     DumpVertices();
1436   }
1437   else
1438   {
1439     DumpVertices();
1440     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1441     for ( ; child != childEnd; ++child )
1442       child->ReverseEdges();
1443   }
1444 }
1445
1446 //================================================================================
1447 /*!
1448  * \brief Load nodes of a mesh
1449  */
1450 //================================================================================
1451
1452 bool _QuadFaceGrid::LoadGrid( SMESH_ProxyMesh& mesh )
1453 {
1454   if ( !myChildren.empty() )
1455   {
1456     // Let child faces load their grids
1457     TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1458     for ( ; child != childEnd; ++child ) {
1459       child->SetID( myID );
1460       if ( !child->LoadGrid( mesh ) )
1461         return error( child->GetError() );
1462     }
1463     // Fill myGrid with nodes of patches
1464     return loadCompositeGrid( mesh );
1465   }
1466
1467   // ---------------------------------------
1468   // Fill myGrid with nodes bound to myFace
1469   // ---------------------------------------
1470
1471   if ( !myGrid.empty() )
1472     return true;
1473
1474   const SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace );
1475
1476   // check that all faces are quadrangular
1477   SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
1478   while ( fIt->more() )
1479     if ( fIt->next()->NbNodes() % 4 > 0 )
1480       return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
1481
1482   bool isProxy, isTmpElem;
1483   if ( faceSubMesh && faceSubMesh->NbElements() > 0 )
1484   {
1485     isProxy   = dynamic_cast< const SMESH_ProxyMesh::SubMesh* >( faceSubMesh );
1486     isTmpElem = mesh.IsTemporary( faceSubMesh->GetElements()->next() );
1487   }
1488   const SMESHDS_SubMesh* smToCheckEdges = ( isProxy && !isTmpElem ) ? faceSubMesh : 0;
1489
1490   myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh, smToCheckEdges );
1491   myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT   )->GetNbSegments( mesh, smToCheckEdges );
1492
1493   myGrid.resize( myIndexer.size() );
1494
1495   // store nodes bound to the bottom edge
1496   mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse, isProxy, smToCheckEdges );
1497
1498   // store the rest nodes row by row
1499
1500   TIDSortedElemSet avoidSet;
1501   const SMDS_MeshElement* firstQuad = 0; // most left face above the last row of found nodes
1502
1503   size_t nbFoundNodes = myIndexer._xSize;
1504   while ( nbFoundNodes != myGrid.size() )
1505   {
1506     // first and last nodes of the last filled row of nodes
1507     const SMDS_MeshNode* n1down = myGrid[ nbFoundNodes - myIndexer._xSize ];
1508     const SMDS_MeshNode* n2down = myGrid[ nbFoundNodes - myIndexer._xSize + 1];
1509     const SMDS_MeshNode* n1downLast = myGrid[ nbFoundNodes-1 ];
1510
1511     // find the first face above the row by the first two left nodes
1512     //
1513     // n1up     n2up
1514     //     o---o
1515     //     |   |
1516     //     o---o  o  o  o  o
1517     //n1down    n2down
1518     //
1519     firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh );
1520     while ( firstQuad && !faceSubMesh->Contains( firstQuad )) {
1521       avoidSet.insert( firstQuad );
1522       firstQuad = FindFaceByNodes( n1down, n2down, avoidSet, mesh);
1523     }
1524     if ( !firstQuad || !faceSubMesh->Contains( firstQuad ))
1525       return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1526
1527     // find the node of quad bound to the left geom edge
1528     int i2down = firstQuad->GetNodeIndex( n2down );
1529     const SMDS_MeshNode* n1up = firstQuad->GetNode(( i2down+2 ) % 4 );
1530     myGrid[ nbFoundNodes++ ] = n1up;
1531     // the 4-the node of the first quad
1532     int i1down = firstQuad->GetNodeIndex( n1down );
1533     const SMDS_MeshNode* n2up = firstQuad->GetNode(( i1down+2 ) % 4 );
1534     myGrid[ nbFoundNodes++ ] = n2up;
1535
1536     n1down = n2down;
1537     n1up   = n2up;
1538     const SMDS_MeshElement* quad = firstQuad;
1539
1540     // find the rest nodes by remaining faces above the row
1541     //
1542     //             n1up
1543     //     o---o--o
1544     //     |   |  | ->
1545     //     o---o--o  o  o  o
1546     //                      n1downLast
1547     //
1548     while ( n1down != n1downLast )
1549     {
1550       // next face
1551       avoidSet.clear(); avoidSet.insert( quad );
1552       quad = FindFaceByNodes( n1down, n1up, avoidSet, mesh );
1553       if ( !quad || quad->NbNodes() % 4 > 0)
1554         return error(ERR_LI("Error in _QuadFaceGrid::LoadGrid()"));
1555
1556       // next node
1557       if ( quad->GetNode( i1down ) != n1down ) // check already found index
1558         i1down = quad->GetNodeIndex( n1down );
1559       n2up = quad->GetNode(( i1down+2 ) % 4 );
1560       myGrid[ nbFoundNodes++ ] = n2up;
1561
1562       n1down = myGrid[ nbFoundNodes - myIndexer._xSize - 1 ];
1563       n1up   = n2up;
1564     }
1565     avoidSet.clear(); avoidSet.insert( firstQuad );
1566   }
1567   DumpGrid(); // debug
1568
1569   return true;
1570 }
1571
1572 //================================================================================
1573 /*!
1574  * \brief Fill myIJK with normalized parameters of nodes in myGrid
1575  *  \param [in] i1 - coordinate index along rows of myGrid
1576  *  \param [in] i2 - coordinate index along columns of myGrid
1577  *  \param [in] v3 - value of the constant parameter
1578  */
1579 //================================================================================
1580
1581 void _QuadFaceGrid::ComputeIJK( int i1, int i2, double v3 )
1582 {
1583   gp_XYZ ijk( v3, v3, v3 );
1584   myIJK.resize( myIndexer.size(), ijk );
1585
1586   const size_t nbCol = myIndexer._xSize;
1587   const size_t nbRow = myIndexer._ySize;
1588
1589   vector< double > len( nbRow );
1590   len[0] = 0;
1591   for ( size_t i = 0; i < nbCol; ++i )
1592   {
1593     gp_Pnt pPrev = GetXYZ( i, 0 );
1594     for ( size_t j = 1; j < nbRow; ++j )
1595     {
1596       gp_Pnt p = GetXYZ( i, j );
1597       len[ j ] = len[ j-1 ] + p.Distance( pPrev );
1598       pPrev = p;
1599     }
1600     for ( size_t j = 0; j < nbRow; ++j )
1601       GetIJK( i, j ).SetCoord( i2, len[ j ]/len.back() );
1602   }
1603
1604   len.resize( nbCol );
1605   for ( size_t j = 0; j < nbRow; ++j )
1606   {
1607     gp_Pnt pPrev = GetXYZ( 0, j );
1608     for ( size_t i = 1; i < nbCol; ++i )
1609     {
1610       gp_Pnt p = GetXYZ( i, j );
1611       len[ i ] = len[ i-1 ] + p.Distance( pPrev );
1612       pPrev = p;
1613     }
1614     for ( size_t i = 0; i < nbCol; ++i )
1615       GetIJK( i, j ).SetCoord( i1, len[ i ]/len.back() );
1616   }
1617 }
1618
1619 //================================================================================
1620 /*!
1621  * \brief Find out mutual location of children: find their right and up brothers
1622  */
1623 //================================================================================
1624
1625 bool _QuadFaceGrid::locateChildren()
1626 {
1627   if ( myLeftBottomChild )
1628     return true;
1629
1630   TChildren::iterator child = myChildren.begin(), childEnd = myChildren.end();
1631
1632   // find a child sharing it's first bottom vertex with no other brother
1633   myLeftBottomChild = 0;
1634   for ( ; !myLeftBottomChild && child != childEnd; ++child )
1635   {
1636     TopoDS_Vertex leftVertex = child->GetSide( Q_BOTTOM ).FirstVertex();
1637     bool sharedVertex = false;
1638     TChildren::iterator otherChild = myChildren.begin();
1639     for ( ; otherChild != childEnd && !sharedVertex; ++otherChild )
1640       if ( otherChild != child )
1641         sharedVertex = otherChild->mySides.Contain( leftVertex );
1642     if ( !sharedVertex ) {
1643       myLeftBottomChild = & (*child);
1644       DUMP_VERT("0 left bottom Vertex: ",leftVertex );
1645     }
1646   }
1647   if (!myLeftBottomChild)
1648     return error(ERR_LI("Error in locateChildren()"));
1649
1650   set< _QuadFaceGrid* > notLocatedChilren;
1651   for (child = myChildren.begin() ; child != childEnd; ++child )
1652     notLocatedChilren.insert( & (*child));
1653
1654   // connect myLeftBottomChild to it's right and upper brothers
1655   notLocatedChilren.erase( myLeftBottomChild );
1656   myLeftBottomChild->setBrothers( notLocatedChilren );
1657   if ( !notLocatedChilren.empty() )
1658     return error(ERR_LI("Error in locateChildren()"));
1659
1660   return true;
1661 }
1662
1663 //================================================================================
1664 /*!
1665  * \brief Fill myGrid with nodes of patches
1666  */
1667 //================================================================================
1668
1669 bool _QuadFaceGrid::loadCompositeGrid(SMESH_ProxyMesh& mesh)
1670 {
1671   // Find out mutual location of children: find their right and up brothers
1672   if ( !locateChildren() )
1673     return false;
1674
1675   // Load nodes according to mutual location of children
1676
1677   // grid size
1678   myIndexer._xSize = 1 + myLeftBottomChild->GetNbHoriSegments( mesh, /*withBrothers=*/true );
1679   myIndexer._ySize = 1 + myLeftBottomChild->GetNbVertSegments( mesh, /*withBrothers=*/true );
1680
1681   myGrid.resize( myIndexer.size() );
1682
1683   int fromX = myReverse ? myIndexer._xSize : 0;
1684   if ( !myLeftBottomChild->fillGrid( mesh, myGrid, myIndexer, fromX, 0 ))
1685     return error( myLeftBottomChild->GetError() );
1686
1687   DumpGrid();
1688
1689   return true;
1690 }
1691
1692 //================================================================================
1693 /*!
1694  * \brief Find right an upper brothers among notLocatedBrothers
1695  */
1696 //================================================================================
1697
1698 void _QuadFaceGrid::setBrothers( set< _QuadFaceGrid* >& notLocatedBrothers )
1699 {
1700   if ( !notLocatedBrothers.empty() )
1701   {
1702     // find right brother
1703     TopoDS_Vertex rightVertex = GetSide( Q_BOTTOM ).LastVertex();
1704     DUMP_VERT("1 right bottom Vertex: ",rightVertex );
1705     set< _QuadFaceGrid* >::iterator brIt, brEnd = notLocatedBrothers.end();
1706     for ( brIt = notLocatedBrothers.begin(); brIt != brEnd; ++brIt )
1707     {
1708       _QuadFaceGrid* brother = *brIt;
1709       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1710       DUMP_VERT( "brother left bottom: ", brotherLeftVertex );
1711       if ( rightVertex.IsSame( brotherLeftVertex )) {
1712         myRightBrother = brother;
1713         notLocatedBrothers.erase( brIt );
1714         break;
1715       }
1716     }
1717     // find upper brother
1718     TopoDS_Vertex upVertex = GetSide( Q_LEFT ).FirstVertex();
1719     DUMP_VERT("1 left up Vertex: ",upVertex);
1720     brIt = notLocatedBrothers.begin(), brEnd = notLocatedBrothers.end();
1721     for ( ; brIt != brEnd; ++brIt )
1722     {
1723       _QuadFaceGrid* brother = *brIt;
1724       TopoDS_Vertex brotherLeftVertex = brother->GetSide( Q_BOTTOM ).FirstVertex();
1725       DUMP_VERT("brother left bottom: ", brotherLeftVertex);
1726       if ( upVertex.IsSame( brotherLeftVertex )) {
1727         myUpBrother = brother;
1728         notLocatedBrothers.erase( myUpBrother );
1729         break;
1730       }
1731     }
1732     // recursive call
1733     if ( myRightBrother )
1734       myRightBrother->setBrothers( notLocatedBrothers );
1735     if ( myUpBrother )
1736       myUpBrother->setBrothers( notLocatedBrothers );
1737   }
1738 }
1739
1740 //================================================================================
1741 /*!
1742  * \brief Store nodes of a simple face into grid starting from (x,y) position
1743  */
1744 //================================================================================
1745
1746 bool _QuadFaceGrid::fillGrid(SMESH_ProxyMesh&               theMesh,
1747                              vector<const SMDS_MeshNode*> & theGrid,
1748                              const _Indexer&                theIndexer,
1749                              int                            theX,
1750                              int                            theY)
1751 {
1752   if ( myGrid.empty() && !LoadGrid( theMesh ))
1753     return false;
1754
1755   // store my own grid in the global grid
1756
1757   int fromX = myReverse ? theX - myIndexer._xSize: theX;
1758
1759   for ( int i = 0, x = fromX; i < myIndexer._xSize; ++i, ++x )
1760     for ( int j = 0, y = theY; j < myIndexer._ySize; ++j, ++y )
1761       theGrid[ theIndexer( x, y )] = myGrid[ myIndexer( i, j )];
1762
1763   // store grids of my right and upper brothers
1764
1765   if ( myRightBrother )
1766   {
1767     if ( myReverse )
1768       fromX += 1;
1769     else
1770       fromX += myIndexer._xSize - 1;
1771     if ( !myRightBrother->fillGrid( theMesh, theGrid, theIndexer, fromX, theY ))
1772       return error( myRightBrother->GetError() );
1773   }
1774   if ( myUpBrother )
1775   {
1776     if ( !myUpBrother->fillGrid( theMesh, theGrid, theIndexer,
1777                                  theX, theY + myIndexer._ySize - 1))
1778       return error( myUpBrother->GetError() );
1779   }
1780   return true;
1781 }
1782
1783 //================================================================================
1784 /*!
1785  * \brief Return number of segments on the hirizontal sides
1786  */
1787 //================================================================================
1788
1789 int _QuadFaceGrid::GetNbHoriSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1790 {
1791   int nbSegs = 0;
1792   if ( myLeftBottomChild )
1793   {
1794     nbSegs += myLeftBottomChild->GetNbHoriSegments( mesh, true );
1795   }
1796   else
1797   {
1798     nbSegs = mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
1799     if ( withBrothers && myRightBrother )
1800       nbSegs += myRightBrother->GetNbHoriSegments( mesh, withBrothers );
1801   }
1802   return nbSegs;
1803 }
1804
1805 //================================================================================
1806 /*!
1807  * \brief Return number of segments on the vertical sides
1808  */
1809 //================================================================================
1810
1811 int _QuadFaceGrid::GetNbVertSegments(SMESH_ProxyMesh& mesh, bool withBrothers) const
1812 {
1813   int nbSegs = 0;
1814   if ( myLeftBottomChild )
1815   {
1816     nbSegs += myLeftBottomChild->GetNbVertSegments( mesh, true );
1817   }
1818   else
1819   {
1820     nbSegs = mySides.GetSide( Q_LEFT )->GetNbSegments(mesh,0);
1821     if ( withBrothers && myUpBrother )
1822       nbSegs += myUpBrother->GetNbVertSegments( mesh, withBrothers );
1823   }
1824   return nbSegs;
1825 }
1826
1827 //================================================================================
1828 /*!
1829  * \brief Return edge on the hirizontal bottom sides
1830  */
1831 //================================================================================
1832
1833 int _QuadFaceGrid::GetHoriEdges(vector<TopoDS_Edge> & edges) const
1834 {
1835   if ( myLeftBottomChild )
1836   {
1837     return myLeftBottomChild->GetHoriEdges( edges );
1838   }
1839   else
1840   {
1841     const _FaceSide* bottom  = mySides.GetSide( Q_BOTTOM );
1842     int i = 0;
1843     while ( true ) {
1844       TopoDS_Edge e = bottom->Edge( i++ );
1845       if ( e.IsNull() )
1846         break;
1847       else
1848         edges.push_back( e );
1849     }
1850     if ( myRightBrother )
1851       myRightBrother->GetHoriEdges( edges );
1852   }
1853   return edges.size();
1854 }
1855
1856 //================================================================================
1857 /*!
1858  * \brief Return a node by its position
1859  */
1860 //================================================================================
1861
1862 const SMDS_MeshNode* _QuadFaceGrid::GetNode(int iHori, int iVert) const
1863 {
1864   return myGrid[ myIndexer( iHori, iVert )];
1865 }
1866
1867 //================================================================================
1868 /*!
1869  * \brief Return node coordinates by its position
1870  */
1871 //================================================================================
1872
1873 gp_XYZ _QuadFaceGrid::GetXYZ(int iHori, int iVert) const
1874 {
1875   SMESH_TNodeXYZ xyz = myGrid[ myIndexer( iHori, iVert )];
1876   return xyz;
1877 }
1878
1879 //================================================================================
1880 /*!
1881  * \brief Return normal to the face at vertex v
1882  */
1883 //================================================================================
1884
1885 bool _QuadFaceGrid::GetNormal( const TopoDS_Vertex& v, gp_Vec& n ) const
1886 {
1887   if ( myChildren.empty() )
1888   {
1889     if ( mySides.Contain( v )) {
1890       try {
1891         gp_Pnt2d uv = BRep_Tool::Parameters( v, myFace );
1892         BRepAdaptor_Surface surface( myFace );
1893         gp_Pnt p; gp_Vec d1u, d1v;
1894         surface.D1( uv.X(), uv.Y(), p, d1u, d1v );
1895         n = d1u.Crossed( d1v );
1896         return true;
1897       }
1898       catch (Standard_Failure) {
1899         return false;
1900       }
1901     }
1902   }
1903   else
1904   {
1905     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1906     for ( ; child != childEnd; ++child )
1907       if ( child->GetNormal( v, n ))
1908         return true;
1909   }
1910   return false;
1911 }
1912
1913 //================================================================================
1914 /*!
1915  * \brief Dumps coordinates of grid nodes
1916  */
1917 //================================================================================
1918
1919 void _QuadFaceGrid::DumpGrid() const
1920 {
1921 #ifdef DEB_GRID
1922   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1923   cout << "****** Face " << names[ myID ] << endl;
1924
1925   if ( myChildren.empty() || !myGrid.empty() )
1926   {
1927     cout << "x size: " << myIndexer._xSize << "; y size: " << myIndexer._ySize << endl;
1928     for ( int y = 0; y < myIndexer._ySize; ++y ) {
1929       cout << "-- row " << y << endl;
1930       for ( int x = 0; x < myIndexer._xSize; ++x ) {
1931         const SMDS_MeshNode* n = myGrid[ myIndexer( x, y ) ];
1932         cout << x << " ( " << n->X() << ", " << n->Y() << ", " << n->Z() << " )" << endl;
1933       }
1934     }
1935   }
1936   else
1937   {
1938     cout << "Nb children: " << myChildren.size() << endl;
1939     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1940     for ( int i=0; child != childEnd; ++child, ++i ) {
1941       cout << "   *** SUBFACE " << i+1 << endl;
1942       ((_QuadFaceGrid&)(*child)).SetID( myID );
1943       child->DumpGrid();
1944     }
1945   }
1946 #endif
1947 }
1948
1949 //================================================================================
1950 /*!
1951  * \brief Dump vertices
1952  */
1953 //================================================================================
1954
1955 void _QuadFaceGrid::DumpVertices() const
1956 {
1957 #ifdef DEB_FACES
1958   cout << "****** Face ";
1959   const char* names[] = { "B_BOTTOM", "B_RIGHT", "B_TOP", "B_LEFT", "B_FRONT", "B_BACK" };
1960   if ( myID >= B_BOTTOM && myID < B_BACK )
1961     cout << names[ myID ] << endl;
1962   else
1963     cout << "UNDEFINED" << endl;
1964
1965   if ( myChildren.empty() )
1966   {
1967     for ( int i = 0; i < 4; ++i )
1968     {
1969       cout << "  Side "; mySides.GetSide( i )->Dump();
1970     }
1971   }
1972   else
1973   {
1974     cout << "-- Nb children: " << myChildren.size() << endl;
1975     TChildren::const_iterator child = myChildren.begin(), childEnd = myChildren.end();
1976     for ( int i=0; child != childEnd; ++child, ++i ) {
1977       cout << "   *** SUBFACE " << i+1 << endl;
1978       ((_QuadFaceGrid&)(*child)).SetID( myID );
1979       child->DumpVertices();
1980     }
1981   }
1982 #endif
1983 }
1984
1985 //=======================================================================
1986 //function : _FaceSide
1987 //purpose  : copy constructor
1988 //=======================================================================
1989
1990 _FaceSide::_FaceSide(const _FaceSide& other)
1991 {
1992   myEdge = other.myEdge;
1993   myChildren = other.myChildren;
1994   myNbChildren = other.myNbChildren;
1995   myVertices.Assign( other.myVertices );
1996   myID = other.myID;
1997 }
1998
1999 //================================================================================
2000 /*!
2001  * \brief Construct a face side of one edge
2002  */
2003 //================================================================================
2004
2005 _FaceSide::_FaceSide(const TopoDS_Edge& edge):
2006   myEdge( edge ), myNbChildren(0)
2007 {
2008   if ( !edge.IsNull() )
2009     for ( TopExp_Explorer exp( edge, TopAbs_VERTEX ); exp.More(); exp.Next() )
2010       //myVertices.insert( ptr ( exp.Current() ));
2011       myVertices.Add( exp.Current() );
2012 }
2013
2014 //================================================================================
2015 /*!
2016  * \brief Construct a face side of several edges
2017  */
2018 //================================================================================
2019
2020 _FaceSide::_FaceSide(const list<TopoDS_Edge>& edges):
2021   myNbChildren(0)
2022 {
2023   list<TopoDS_Edge>::const_iterator edge = edges.begin(), eEnd = edges.end();
2024   for ( ; edge != eEnd; ++edge ) {
2025     myChildren.push_back( _FaceSide( *edge ));
2026     myNbChildren++;
2027     myVertices.Add( myChildren.back().FirstVertex() );
2028     myVertices.Add( myChildren.back().LastVertex() );
2029     myChildren.back().SetID( Q_CHILD ); // not to splice them
2030   }
2031 }
2032
2033 //=======================================================================
2034 //function : GetSide
2035 //purpose  :
2036 //=======================================================================
2037
2038 _FaceSide* _FaceSide::GetSide(const int i)
2039 {
2040   if ( i >= myNbChildren )
2041     return 0;
2042
2043   list< _FaceSide >::iterator side = myChildren.begin();
2044   if ( i )
2045     std::advance( side, i );
2046   return & (*side);
2047 }
2048
2049 //=======================================================================
2050 //function : GetSide
2051 //purpose  : 
2052 //=======================================================================
2053
2054 const _FaceSide* _FaceSide::GetSide(const int i) const
2055 {
2056   return const_cast< _FaceSide* >(this)->GetSide(i);
2057 }
2058
2059 //=======================================================================
2060 //function : NbVertices
2061 //purpose  : return nb of vertices in the side
2062 //=======================================================================
2063
2064 int _FaceSide::NbVertices() const
2065 {
2066   if ( myChildren.empty() )
2067     return myVertices.Extent();
2068
2069   return myNbChildren + 1;
2070 }
2071
2072 //=======================================================================
2073 //function : NbCommonVertices
2074 //purpose  : Returns number of my vertices common with the given ones
2075 //=======================================================================
2076
2077 int _FaceSide::NbCommonVertices( const TopTools_MapOfShape& VV ) const
2078 {
2079   int nbCommon = 0;
2080   TopTools_MapIteratorOfMapOfShape vIt ( myVertices );
2081   for ( ; vIt.More(); vIt.Next() )
2082     nbCommon += ( VV.Contains( vIt.Key() ));
2083
2084   return nbCommon;
2085 }
2086
2087 //=======================================================================
2088 //function : FirstVertex
2089 //purpose  :
2090 //=======================================================================
2091
2092 TopoDS_Vertex _FaceSide::FirstVertex() const
2093 {
2094   if ( myChildren.empty() )
2095     return TopExp::FirstVertex( myEdge, Standard_True );
2096
2097   return myChildren.front().FirstVertex();
2098 }
2099
2100 //=======================================================================
2101 //function : LastVertex
2102 //purpose  : 
2103 //=======================================================================
2104
2105 TopoDS_Vertex _FaceSide::LastVertex() const
2106 {
2107   if ( myChildren.empty() )
2108     return TopExp::LastVertex( myEdge, Standard_True );
2109
2110   return myChildren.back().LastVertex();
2111 }
2112
2113 //=======================================================================
2114 //function : Vertex
2115 //purpose  : 
2116 //=======================================================================
2117
2118 TopoDS_Vertex _FaceSide::Vertex(int i) const
2119 {
2120   if ( myChildren.empty() )
2121     return i ? LastVertex() : FirstVertex();
2122       
2123   if ( i >= myNbChildren )
2124     return myChildren.back().LastVertex();
2125   
2126   return GetSide(i)->FirstVertex();
2127 }
2128
2129 //================================================================================
2130 /*!
2131  * \brief Return i-the zero-based edge of the side
2132  */
2133 //================================================================================
2134
2135 TopoDS_Edge _FaceSide::Edge(int i) const
2136 {
2137   if ( i == 0 && !myEdge.IsNull() )
2138     return myEdge;
2139
2140   if ( const _FaceSide* iSide = GetSide( i ))
2141     return iSide->myEdge;
2142
2143   return TopoDS_Edge();
2144 }
2145
2146 //=======================================================================
2147 //function : Contain
2148 //purpose  : 
2149 //=======================================================================
2150
2151 bool _FaceSide::Contain( const _FaceSide& side, int* which ) const
2152 {
2153   if ( !which || myChildren.empty() )
2154   {
2155     if ( which )
2156       *which = 0;
2157     int nbCommon = 0;
2158     TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2159     for ( ; vIt.More(); vIt.Next() )
2160       nbCommon += ( myVertices.Contains( vIt.Key() ));
2161     return (nbCommon > 1);
2162   }
2163   list< _FaceSide >::const_iterator mySide = myChildren.begin(), sideEnd = myChildren.end();
2164   for ( int i = 0; mySide != sideEnd; ++mySide, ++i ) {
2165     if ( mySide->Contain( side )) {
2166       *which = i;
2167       return true;
2168     }
2169   }
2170   return false;
2171 }
2172
2173 //=======================================================================
2174 //function : Contain
2175 //purpose  : 
2176 //=======================================================================
2177
2178 bool _FaceSide::Contain( const TopoDS_Vertex& vertex ) const
2179 {
2180   return myVertices.Contains( vertex );
2181 }
2182
2183 //=======================================================================
2184 //function : AppendSide
2185 //purpose  : 
2186 //=======================================================================
2187
2188 void _FaceSide::AppendSide( const _FaceSide& side )
2189 {
2190   if ( !myEdge.IsNull() )
2191   {
2192     myChildren.push_back( *this );
2193     myNbChildren = 1;
2194     myEdge.Nullify();
2195   }
2196   myChildren.push_back( side );
2197   myNbChildren++;
2198   TopTools_MapIteratorOfMapOfShape vIt ( side.myVertices );
2199   for ( ; vIt.More(); vIt.Next() )
2200     myVertices.Add( vIt.Key() );
2201
2202   myID = Q_PARENT;
2203   myChildren.back().SetID( EQuadSides( myNbChildren-1 ));
2204 }
2205
2206 //=======================================================================
2207 //function : SetBottomSide
2208 //purpose  : 
2209 //=======================================================================
2210
2211 void _FaceSide::SetBottomSide( int i )
2212 {
2213   if ( i > 0 && myID == Q_PARENT ) {
2214     list< _FaceSide >::iterator sideEnd, side = myChildren.begin();
2215     std::advance( side, i );
2216     myChildren.splice( myChildren.begin(), myChildren, side, myChildren.end() );
2217
2218     side = myChildren.begin(), sideEnd = myChildren.end();
2219     for ( int i = 0; side != sideEnd; ++side, ++i ) {
2220       side->SetID( EQuadSides(i) );
2221       side->SetBottomSide(i);
2222     }
2223   }
2224 }
2225
2226 //=======================================================================
2227 //function : GetNbSegments
2228 //purpose  : 
2229 //=======================================================================
2230
2231 int _FaceSide::GetNbSegments(SMESH_ProxyMesh& mesh, const SMESHDS_SubMesh* smToCheckEdges) const
2232 {
2233   int nb = 0;
2234   if ( myChildren.empty() )
2235   {
2236     nb = mesh.GetSubMesh(myEdge)->NbElements();
2237
2238     if ( smToCheckEdges )
2239     {
2240       // check that segments bound faces belonging to smToCheckEdges
2241       SMDS_ElemIteratorPtr segIt = mesh.GetSubMesh(myEdge)->GetElements();
2242       while ( segIt->more() )
2243       {
2244         const SMDS_MeshElement* seg = segIt->next();
2245         if ( !IsSegmentOnSubMeshBoundary( mesh.GetProxyNode( seg->GetNode(0) ),
2246                                           mesh.GetProxyNode( seg->GetNode(1) ),
2247                                           smToCheckEdges, mesh ))
2248           --nb;
2249       }
2250     }
2251   }
2252   else
2253   {
2254     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2255     for ( ; side != sideEnd; ++side )
2256       nb += side->GetNbSegments( mesh, smToCheckEdges );
2257   }
2258   return nb;
2259 }
2260
2261 //=======================================================================
2262 //function : StoreNodes
2263 //purpose  :
2264 //=======================================================================
2265
2266 bool _FaceSide::StoreNodes(SMESH_ProxyMesh&              mesh,
2267                            vector<const SMDS_MeshNode*>& myGrid,
2268                            bool                          reverse,
2269                            bool                          isProxy,
2270                            const SMESHDS_SubMesh*        smToCheckEdges)
2271 {
2272   list< TopoDS_Edge > edges;
2273   if ( myChildren.empty() )
2274   {
2275     edges.push_back( myEdge );
2276   }
2277   else
2278   {
2279     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2280     for ( ; side != sideEnd; ++side )
2281       if ( reverse )
2282         edges.push_front( side->myEdge );
2283       else
2284         edges.push_back ( side->myEdge );
2285   }
2286   int nbNodes = 0;
2287   list< TopoDS_Edge >::iterator edge = edges.begin(), eEnd = edges.end();
2288   for ( ; edge != eEnd; ++edge )
2289   {
2290     typedef map< double, const SMDS_MeshNode* > TParamNodeMap;
2291     TParamNodeMap nodes;
2292     bool ok = SMESH_Algo::GetSortedNodesOnEdge( mesh.GetMeshDS(),
2293                                                 *edge,
2294                                                 /*ignoreMediumNodes=*/true,
2295                                                 nodes);
2296     if ( !ok ) return false;
2297
2298     // skip nodes on VERTEXes not included in faces
2299     if ( !nodes.begin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2300       nodes.erase( nodes.begin() );
2301     if ( !nodes.empty() &&
2302          !nodes.rbegin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
2303       nodes.erase( --nodes.end() );
2304
2305     if ( isProxy )
2306     {
2307       TParamNodeMap::iterator u_node, nEnd = nodes.end();
2308       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2309         u_node->second = mesh.GetProxyNode( u_node->second );
2310     }
2311
2312     if ( smToCheckEdges ) // erase nodes of segments not bounding faces of smToCheckEdges
2313     {
2314       {
2315         TParamNodeMap::iterator u_node1, u_node2 = nodes.begin(), nEnd = nodes.end();
2316         for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2317           if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2318                                            smToCheckEdges, mesh ))
2319             break;
2320           else
2321             nodes.erase( u_node1 );
2322       }
2323       {
2324         TParamNodeMap::reverse_iterator u_node1, u_node2 = nodes.rbegin(), nEnd = nodes.rend();
2325         for ( u_node1 = u_node2++; u_node2 != nEnd; u_node1 = u_node2++ )
2326           if ( IsSegmentOnSubMeshBoundary( u_node1->second, u_node2->second,
2327                                            smToCheckEdges, mesh ))
2328             break;
2329           else
2330             nodes.erase( --(( u_node2 = u_node1 ).base() ));
2331       }
2332     }
2333
2334     bool forward = ( edge->Orientation() == TopAbs_FORWARD );
2335     if ( reverse ) forward = !forward;
2336     if ( forward )
2337     {
2338       TParamNodeMap::iterator u_node, nEnd = nodes.end();
2339       for ( u_node = nodes.begin(); u_node != nEnd; ++u_node )
2340         myGrid[ nbNodes++ ] = u_node->second;
2341     }
2342     else
2343     {
2344       TParamNodeMap::reverse_iterator u_node, nEnd = nodes.rend();
2345       for ( u_node = nodes.rbegin(); u_node != nEnd; ++u_node )
2346         myGrid[ nbNodes++ ] = u_node->second;
2347     }
2348     nbNodes--; // node on vertex present in two adjacent edges
2349   }
2350   return nbNodes > 0;
2351 }
2352
2353 //=======================================================================
2354 //function : Dump
2355 //purpose  : dump end vertices
2356 //=======================================================================
2357
2358 void _FaceSide::Dump() const
2359 {
2360   if ( myChildren.empty() )
2361   {
2362     const char* sideNames[] = { "Q_BOTTOM", "Q_RIGHT", "Q_TOP", "Q_LEFT", "Q_CHILD", "Q_PARENT" };
2363     if ( myID >= Q_BOTTOM && myID < Q_PARENT )
2364       cout << sideNames[ myID ] << endl;
2365     else
2366       cout << "<UNDEFINED ID>" << endl;
2367     TopoDS_Vertex f = FirstVertex();
2368     TopoDS_Vertex l = LastVertex();
2369     gp_Pnt pf = BRep_Tool::Pnt(f);
2370     gp_Pnt pl = BRep_Tool::Pnt(l);
2371     cout << "\t ( "<< ptr( f ) << " - " << ptr( l )<< " )"
2372          << "\t ( "<< pf.X()<<", "<<pf.Y()<<", "<<pf.Z()<<" ) - "
2373          << " ( "<< pl.X()<<", "<<pl.Y()<<", "<<pl.Z()<<" )"<<endl;
2374   }
2375   else
2376   {
2377     list< _FaceSide >::const_iterator side = myChildren.begin(), sideEnd = myChildren.end();
2378     for ( ; side != sideEnd; ++side ) {
2379       side->Dump();
2380       cout << "\t";
2381     }
2382   }
2383 }