Salome HOME
fix failures of non-regression tests
[modules/smesh.git] / src / StdMeshers / StdMeshers_Prism_3D.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File      : StdMeshers_Prism_3D.cxx
24 // Module    : SMESH
25 // Created   : Fri Oct 20 11:37:07 2006
26 // Author    : Edward AGAPOV (eap)
27 //
28 #include "StdMeshers_Prism_3D.hxx"
29
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_VolumeOfNodes.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_MesherHelper.hxx"
37 #include "StdMeshers_FaceSide.hxx"
38 #include "StdMeshers_ProjectionSource1D.hxx"
39 #include "StdMeshers_ProjectionSource2D.hxx"
40 #include "StdMeshers_ProjectionUtils.hxx"
41 #include "StdMeshers_Projection_1D.hxx"
42 #include "StdMeshers_Projection_1D2D.hxx"
43 #include "StdMeshers_Quadrangle_2D.hxx"
44
45 #include "utilities.h"
46
47 #include <BRepAdaptor_CompCurve.hxx>
48 #include <BRep_Tool.hxx>
49 #include <Bnd_B3d.hxx>
50 #include <Geom2dAdaptor_Curve.hxx>
51 #include <Geom2d_Line.hxx>
52 #include <Geom_Curve.hxx>
53 #include <TopExp.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopTools_MapOfShape.hxx>
58 #include <TopTools_SequenceOfShape.hxx>
59 #include <TopoDS.hxx>
60 #include <gp_Ax2.hxx>
61 #include <gp_Ax3.hxx>
62
63 using namespace std;
64
65 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
66 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
67 #define SHOWYXZ(msg, xyz) // {\
68 // gp_Pnt p (xyz); \
69 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl;\
70 // }
71
72 namespace TAssocTool = StdMeshers_ProjectionUtils;
73
74 typedef SMESH_Comment TCom;
75
76 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
77        ID_TOP_FACE = SMESH_Block::ID_Fxy1,
78        BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
79        NB_WALL_FACES = 4 }; //
80
81 namespace {
82
83   //=======================================================================
84   /*!
85    * \brief Quadrangle algorithm
86    */
87   struct TQuadrangleAlgo : public StdMeshers_Quadrangle_2D
88   {
89     TQuadrangleAlgo(int studyId, SMESH_Gen* gen)
90       : StdMeshers_Quadrangle_2D( gen->GetANewId(), studyId, gen)
91     {
92     }
93     static StdMeshers_Quadrangle_2D* instance( SMESH_Algo*         fatherAlgo,
94                                                SMESH_MesherHelper* helper=0)
95     {
96       static TQuadrangleAlgo* algo = new TQuadrangleAlgo( fatherAlgo->GetStudyId(),
97                                                           fatherAlgo->GetGen() );
98       if ( helper &&
99            algo->myProxyMesh &&
100            algo->myProxyMesh->GetMesh() != helper->GetMesh() )
101         algo->myProxyMesh.reset( new SMESH_ProxyMesh( *helper->GetMesh() ));
102
103       algo->myQuadStruct.reset();
104
105       if ( helper )
106         algo->_quadraticMesh = helper->GetIsQuadratic();
107
108       return algo;
109     }
110   };
111   //=======================================================================
112   /*!
113    * \brief Algorithm projecting 1D mesh
114    */
115   struct TProjction1dAlgo : public StdMeshers_Projection_1D
116   {
117     StdMeshers_ProjectionSource1D myHyp;
118
119     TProjction1dAlgo(int studyId, SMESH_Gen* gen)
120       : StdMeshers_Projection_1D( gen->GetANewId(), studyId, gen),
121         myHyp( gen->GetANewId(), studyId, gen)
122     {
123       StdMeshers_Projection_1D::_sourceHypo = & myHyp;
124     }
125     static TProjction1dAlgo* instance( SMESH_Algo* fatherAlgo )
126     {
127       static TProjction1dAlgo* algo = new TProjction1dAlgo( fatherAlgo->GetStudyId(),
128                                                             fatherAlgo->GetGen() );
129       return algo;
130     }
131   };
132   //=======================================================================
133   /*!
134    * \brief Algorithm projecting 2D mesh
135    */
136   struct TProjction2dAlgo : public StdMeshers_Projection_1D2D
137   {
138     StdMeshers_ProjectionSource2D myHyp;
139
140     TProjction2dAlgo(int studyId, SMESH_Gen* gen)
141       : StdMeshers_Projection_1D2D( gen->GetANewId(), studyId, gen),
142         myHyp( gen->GetANewId(), studyId, gen)
143     {
144       StdMeshers_Projection_2D::_sourceHypo = & myHyp;
145     }
146     static TProjction2dAlgo* instance( SMESH_Algo* fatherAlgo )
147     {
148       static TProjction2dAlgo* algo = new TProjction2dAlgo( fatherAlgo->GetStudyId(),
149                                                             fatherAlgo->GetGen() );
150       return algo;
151     }
152   };
153
154   //================================================================================
155   /*!
156    * \brief Make \a botE be the BOTTOM_SIDE of \a quad.
157    *        Return false if the BOTTOM_SIDE is composite
158    */
159   //================================================================================
160
161   bool setBottomEdge( const TopoDS_Edge&   botE,
162                       faceQuadStruct::Ptr& quad,
163                       const TopoDS_Shape&  face)
164   {
165     quad->side[ QUAD_TOP_SIDE  ]->Reverse();
166     quad->side[ QUAD_LEFT_SIDE ]->Reverse();
167     int edgeIndex = 0;
168     for ( size_t i = 0; i < quad->side.size(); ++i )
169     {
170       StdMeshers_FaceSide* quadSide = quad->side[i];
171       for ( int iE = 0; iE < quadSide->NbEdges(); ++iE )
172         if ( botE.IsSame( quadSide->Edge( iE )))
173         {
174           if ( quadSide->NbEdges() > 1 )
175             return false;
176           edgeIndex = i;
177           i = quad->side.size(); // to quit from the outer loop
178           break;
179         }
180     }
181     if ( edgeIndex != QUAD_BOTTOM_SIDE )
182       quad->shift( quad->side.size() - edgeIndex, /*keepUnitOri=*/false );
183
184     quad->face = TopoDS::Face( face );
185
186     return true;
187   }
188
189   //================================================================================
190   /*!
191    * \brief Return iterator pointing to node column for the given parameter
192    * \param columnsMap - node column map
193    * \param parameter - parameter
194    * \retval TParam2ColumnMap::iterator - result
195    *
196    * it returns closest left column
197    */
198   //================================================================================
199
200   TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
201                              const double            parameter )
202   {
203     TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
204     if ( u_col != columnsMap->begin() )
205       --u_col;
206     return u_col; // return left column
207   }
208
209   //================================================================================
210   /*!
211    * \brief Return nodes around given parameter and a ratio
212    * \param column - node column
213    * \param param - parameter
214    * \param node1 - lower node
215    * \param node2 - upper node
216    * \retval double - ratio
217    */
218   //================================================================================
219
220   double getRAndNodes( const TNodeColumn*     column,
221                        const double           param,
222                        const SMDS_MeshNode* & node1,
223                        const SMDS_MeshNode* & node2)
224   {
225     if ( param >= 1.0 || column->size() == 1) {
226       node1 = node2 = column->back();
227       return 0;
228     }
229
230     int i = int( param * ( column->size() - 1 ));
231     double u0 = double( i )/ double( column->size() - 1 );
232     double r = ( param - u0 ) * ( column->size() - 1 );
233
234     node1 = (*column)[ i ];
235     node2 = (*column)[ i + 1];
236     return r;
237   }
238
239   //================================================================================
240   /*!
241    * \brief Compute boundary parameters of face parts
242     * \param nbParts - nb of parts to split columns into
243     * \param columnsMap - node columns of the face to split
244     * \param params - computed parameters
245    */
246   //================================================================================
247
248   void splitParams( const int               nbParts,
249                     const TParam2ColumnMap* columnsMap,
250                     vector< double > &      params)
251   {
252     params.clear();
253     params.reserve( nbParts + 1 );
254     TParam2ColumnIt last_par_col = --columnsMap->end();
255     double par = columnsMap->begin()->first; // 0.
256     double parLast = last_par_col->first;
257     params.push_back( par );
258     for ( int i = 0; i < nbParts - 1; ++ i )
259     {
260       double partSize = ( parLast - par ) / double ( nbParts - i );
261       TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
262       if ( par_col->first == par ) {
263         ++par_col;
264         if ( par_col == last_par_col ) {
265           while ( i < nbParts - 1 )
266             params.push_back( par + partSize * i++ );
267           break;
268         }
269       }
270       par = par_col->first;
271       params.push_back( par );
272     }
273     params.push_back( parLast ); // 1.
274   }
275
276   //================================================================================
277   /*!
278    * \brief Return coordinate system for z-th layer of nodes
279    */
280   //================================================================================
281
282   gp_Ax2 getLayerCoordSys(const int                           z,
283                           const vector< const TNodeColumn* >& columns,
284                           int&                                xColumn)
285   {
286     // gravity center of a layer
287     gp_XYZ O(0,0,0);
288     int vertexCol = -1;
289     for ( int i = 0; i < columns.size(); ++i )
290     {
291       O += gpXYZ( (*columns[ i ])[ z ]);
292       if ( vertexCol < 0 &&
293            columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
294         vertexCol = i;
295     }
296     O /= columns.size();
297
298     // Z axis
299     gp_Vec Z(0,0,0);
300     int iPrev = columns.size()-1;
301     for ( int i = 0; i < columns.size(); ++i )
302     {
303       gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
304       gp_Vec v2( O, gpXYZ( (*columns[ i ]    )[ z ]));
305       Z += v1 ^ v2;
306       iPrev = i;
307     }
308
309     if ( vertexCol >= 0 )
310     {
311       O = gpXYZ( (*columns[ vertexCol ])[ z ]);
312     }
313     if ( xColumn < 0 || xColumn >= columns.size() )
314     {
315       // select a column for X dir
316       double maxDist = 0;
317       for ( int i = 0; i < columns.size(); ++i )
318       {
319         double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
320         if ( dist > maxDist )
321         {
322           xColumn = i;
323           maxDist = dist;
324         }
325       }
326     }
327
328     // X axis
329     gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
330
331     return gp_Ax2( O, Z, X);
332   }
333
334   //================================================================================
335   /*!
336    * \brief Removes submeshes that are or can be meshed with regular grid from given list
337    *  \retval int - nb of removed submeshes
338    */
339   //================================================================================
340
341   int removeQuasiQuads(list< SMESH_subMesh* >&   notQuadSubMesh,
342                        SMESH_MesherHelper*       helper,
343                        StdMeshers_Quadrangle_2D* quadAlgo)
344   {
345     int nbRemoved = 0;
346     //SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
347     list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
348     while ( smIt != notQuadSubMesh.end() )
349     {
350       SMESH_subMesh* faceSm = *smIt;
351       SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
352       int nbQuads = faceSmDS ? faceSmDS->NbElements() : 0;
353       bool toRemove;
354       if ( nbQuads > 0 )
355         toRemove = helper->IsStructured( faceSm );
356       else
357         toRemove = quadAlgo->CheckNbEdges( *helper->GetMesh(),
358                                            faceSm->GetSubShape() );
359       nbRemoved += toRemove;
360       if ( toRemove )
361         smIt = notQuadSubMesh.erase( smIt );
362       else
363         ++smIt;
364     }
365
366     return nbRemoved;
367   }
368
369 } // namespace
370
371 //=======================================================================
372 //function : StdMeshers_Prism_3D
373 //purpose  : 
374 //=======================================================================
375
376 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
377   :SMESH_3D_Algo(hypId, studyId, gen)
378 {
379   _name                    = "Prism_3D";
380   _shapeType               = (1 << TopAbs_SOLID); // 1 bit per shape type
381   _onlyUnaryInput          = false; // accept all SOLIDs at once
382   _requireDiscreteBoundary = false; // mesh FACEs and EDGEs by myself
383   _supportSubmeshes        = true;  // "source" FACE must be meshed by other algo
384   _neededLowerHyps[ 1 ]    = true;  // suppress warning on hiding a global 1D algo
385   _neededLowerHyps[ 2 ]    = true;  // suppress warning on hiding a global 2D algo
386
387   //myProjectTriangles       = false;
388   mySetErrorToSM           = true;  // to pass an error to a sub-mesh of a current solid or not
389 }
390
391 //================================================================================
392 /*!
393  * \brief Destructor
394  */
395 //================================================================================
396
397 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
398 {}
399
400 //=======================================================================
401 //function : CheckHypothesis
402 //purpose  : 
403 //=======================================================================
404
405 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh&                          aMesh,
406                                           const TopoDS_Shape&                  aShape,
407                                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
408 {
409   // Check shape geometry
410 /*  PAL16229
411   aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
412
413   // find not quadrangle faces
414   list< TopoDS_Shape > notQuadFaces;
415   int nbEdge, nbWire, nbFace = 0;
416   TopExp_Explorer exp( aShape, TopAbs_FACE );
417   for ( ; exp.More(); exp.Next() ) {
418     ++nbFace;
419     const TopoDS_Shape& face = exp.Current();
420     nbEdge = TAssocTool::Count( face, TopAbs_EDGE, 0 );
421     nbWire = TAssocTool::Count( face, TopAbs_WIRE, 0 );
422     if (  nbEdge!= 4 || nbWire!= 1 ) {
423       if ( !notQuadFaces.empty() ) {
424         if ( TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
425              TAssocTool::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
426           RETURN_BAD_RESULT("Different not quad faces");
427       }
428       notQuadFaces.push_back( face );
429     }
430   }
431   if ( !notQuadFaces.empty() )
432   {
433     if ( notQuadFaces.size() != 2 )
434       RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
435
436     // check total nb faces
437     nbEdge = TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
438     if ( nbFace != nbEdge + 2 )
439       RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
440   }
441 */
442   // no hypothesis
443   aStatus = SMESH_Hypothesis::HYP_OK;
444   return true;
445 }
446
447 //=======================================================================
448 //function : Compute
449 //purpose  : Compute mesh on a COMPOUND of SOLIDs
450 //=======================================================================
451
452 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
453 {
454   SMESH_MesherHelper helper( theMesh );
455   myHelper = &helper;
456
457   int nbSolids = helper.Count( theShape, TopAbs_SOLID, /*skipSame=*/false );
458   if ( nbSolids < 1 )
459     return true;
460
461   Prism_3D::TPrismTopo prism;
462
463   if ( nbSolids == 1 )
464   {
465     return ( initPrism( prism, TopExp_Explorer( theShape, TopAbs_SOLID ).Current() ) &&
466              compute( prism ));
467   }
468
469   TopTools_IndexedDataMapOfShapeListOfShape faceToSolids;
470   TopExp::MapShapesAndAncestors( theShape, TopAbs_FACE, TopAbs_SOLID, faceToSolids );
471
472   // look for meshed FACEs ("source" FACEs) that must be prism bottoms
473   list< TopoDS_Face > meshedFaces, notQuadMeshedFaces;//, notQuadFaces;
474   const bool meshHasQuads = ( theMesh.NbQuadrangles() > 0 );
475   for ( int iF = 1; iF < faceToSolids.Extent(); ++iF )
476   {
477     const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
478     SMESH_subMesh*   faceSM = theMesh.GetSubMesh( face );
479     if ( !faceSM->IsEmpty() )
480     {
481       if ( !meshHasQuads ||
482            !helper.IsSameElemGeometry( faceSM->GetSubMeshDS(), SMDSGeom_QUADRANGLE ) ||
483            !helper.IsStructured( faceSM )
484            )
485         notQuadMeshedFaces.push_front( face );
486       else if ( myHelper->Count( face, TopAbs_EDGE, /*ignoreSame=*/false ) != 4 )
487         meshedFaces.push_front( face );
488       else
489         meshedFaces.push_back( face );
490     }
491   }
492   // notQuadMeshedFaces are of highest priority
493   meshedFaces.splice( meshedFaces.begin(), notQuadMeshedFaces );
494
495   // if ( meshedFaces.empty() )
496   //   return error( COMPERR_BAD_INPUT_MESH, "No meshed source faces found" );
497
498   TopTools_MapOfShape meshedSolids;
499   list< Prism_3D::TPrismTopo > meshedPrism;
500   TopTools_ListIteratorOfListOfShape solidIt;
501
502   while ( meshedSolids.Extent() < nbSolids )
503   {
504     if ( _computeCanceled )
505       return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
506
507     // compute prisms having avident computed source FACE
508     while ( !meshedFaces.empty() )
509     {
510       TopoDS_Face face = meshedFaces.front();
511       meshedFaces.pop_front();
512       TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( face );
513       while ( !solidList.IsEmpty() )
514       {
515         TopoDS_Shape solid = solidList.First();
516         solidList.RemoveFirst();
517         if ( meshedSolids.Add( solid ))
518         {
519           prism.Clear();
520           prism.myBottom = face;
521           if ( !initPrism( prism, solid ) ||
522                !compute( prism ))
523             return false;
524
525           meshedFaces.push_front( prism.myTop );
526           meshedPrism.push_back( prism );
527         }
528       }
529     }
530     if ( meshedSolids.Extent() == nbSolids )
531       break;
532
533     // below in the loop we try to find source FACEs somehow
534
535     // project mesh from source FACEs of computed prisms to
536     // prisms sharing wall FACEs
537     list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
538     for ( ; prismIt != meshedPrism.end(); ++prismIt )
539     {
540       for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
541       {
542         Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
543         for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
544         {
545           const TopoDS_Face& wFace = (*wQuad)->face;
546           TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
547           solidIt.Initialize( solidList );
548           while ( solidIt.More() )
549           {
550             const TopoDS_Shape& solid = solidIt.Value();
551             if ( meshedSolids.Contains( solid )) {
552               solidList.Remove( solidIt );
553               continue; // already computed prism
554             }
555             // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
556             const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ]->Edge(0);
557             PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
558                                                                TopAbs_FACE);
559             while ( const TopoDS_Shape* f = faceIt->next() )
560             {
561               const TopoDS_Face& candidateF = TopoDS::Face( *f );
562               prism.Clear();
563               prism.myBottom  = candidateF;
564               mySetErrorToSM = false;
565               if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
566                    !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
567                    initPrism( prism, solid ) &&
568                    project2dMesh( prismIt->myBottom, candidateF))
569               {
570                 mySetErrorToSM = true;
571                 if ( !compute( prism ))
572                   return false;
573                 meshedFaces.push_front( prism.myTop );
574                 meshedFaces.push_front( prism.myBottom );
575                 meshedPrism.push_back( prism );
576                 meshedSolids.Add( solid );
577               }
578               InitComputeError();
579             }
580             mySetErrorToSM = true;
581             InitComputeError();
582             if ( meshedSolids.Contains( solid ))
583               solidList.Remove( solidIt );
584             else
585               solidIt.Next();
586           }
587         }
588       }
589       if ( !meshedFaces.empty() )
590         break; // to compute prisms with avident sources
591     }
592
593     // find FACEs with local 1D hyps, which has to be computed by now,
594     // or at least any computed FACEs
595     for ( int iF = 1; ( meshedFaces.empty() && iF < faceToSolids.Extent() ); ++iF )
596     {
597       const TopoDS_Face&               face = TopoDS::Face( faceToSolids.FindKey( iF ));
598       const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
599       if ( solidList.IsEmpty() ) continue;
600       SMESH_subMesh*                 faceSM = theMesh.GetSubMesh( face );
601       if ( !faceSM->IsEmpty() )
602       {
603         meshedFaces.push_back( face ); // lower priority
604       }
605       else
606       {
607         bool allSubMeComputed = true;
608         SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
609         while ( smIt->more() && allSubMeComputed )
610           allSubMeComputed = smIt->next()->IsMeshComputed();
611         if ( allSubMeComputed )
612         {
613           faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
614           if ( !faceSM->IsEmpty() )
615             meshedFaces.push_front( face ); // higher priority
616           else
617             faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
618         }
619       }
620     }
621
622
623     // TODO. there are other ways to find out the source FACE:
624     // propagation, topological similarity, ect.
625
626
627     if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
628     {
629       SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
630         ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
631
632       const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
633       TopExp_Explorer solid( theShape, TopAbs_SOLID );
634       for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
635         if ( !meshedSolids.Contains( solid.Current() ))
636         {
637           SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
638           sm->GetComputeError() = err;
639         }
640       return false;
641     }
642   }
643   return true;
644 }
645
646 //================================================================================
647 /*!
648  * \brief Find wall faces by bottom edges
649  */
650 //================================================================================
651
652 bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
653                                         const int              totalNbFaces)
654 {
655   thePrism.myWallQuads.clear();
656
657   SMESH_Mesh* mesh = myHelper->GetMesh();
658
659   StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
660
661   TopTools_MapOfShape faceMap;
662   TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;   
663   TopExp::MapShapesAndAncestors( thePrism.myShape3D,
664                                  TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
665
666   // ------------------------------
667   // Get the 1st row of wall FACEs
668   // ------------------------------
669
670   list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
671   std::list< int >::iterator     nbE = thePrism.myNbEdgesInWires.begin();
672   int iE = 0;
673   while ( edge != thePrism.myBottomEdges.end() )
674   {
675     ++iE;
676     if ( BRep_Tool::Degenerated( *edge ))
677     {
678       edge = thePrism.myBottomEdges.erase( edge );
679       --iE;
680       --(*nbE);
681     }
682     else
683     {
684       TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
685       for ( ; faceIt.More(); faceIt.Next() )
686       {
687         const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
688         if ( !thePrism.myBottom.IsSame( face ))
689         {
690           Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
691           if ( !quadList.back() )
692             return toSM( error(TCom("Side face #") << shapeID( face )
693                                << " not meshable with quadrangles"));
694           if ( ! setBottomEdge( *edge, quadList.back(), face ))
695             return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
696           thePrism.myWallQuads.push_back( quadList );
697           faceMap.Add( face );
698           break;
699         }
700       }
701       ++edge;
702     }
703     if ( iE == *nbE )
704     {
705       iE = 0;
706       ++nbE;
707     }
708   }
709
710   // -------------------------
711   // Find the rest wall FACEs
712   // -------------------------
713
714   // Compose a vector of indixes of right neighbour FACE for each wall FACE
715   // that is not so evident in case of several WIREs in the bottom FACE
716   thePrism.myRightQuadIndex.clear();
717   for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
718     thePrism.myRightQuadIndex.push_back( i+1 );
719   list< int >::iterator nbEinW = thePrism.myNbEdgesInWires.begin();
720   for ( int iLeft = 0; nbEinW != thePrism.myNbEdgesInWires.end(); ++nbEinW )
721   {
722     thePrism.myRightQuadIndex[ iLeft + *nbEinW - 1 ] = iLeft; // 1st EDGE index of a current WIRE
723     iLeft += *nbEinW;
724   }
725
726   while ( totalNbFaces - faceMap.Extent() > 2 )
727   {
728     // find wall FACEs adjacent to each of wallQuads by the right side EDGE
729     int nbKnownFaces;
730     do {
731       nbKnownFaces = faceMap.Extent();
732       StdMeshers_FaceSide *rightSide, *topSide; // sides of the quad
733       for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
734       {
735         rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
736         for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
737         {
738           const TopoDS_Edge & rightE = rightSide->Edge( iE );
739           TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
740           for ( ; face.More(); face.Next() )
741             if ( faceMap.Add( face.Value() ))
742             {
743               // a new wall FACE encountered, store it in thePrism.myWallQuads
744               const int iRight = thePrism.myRightQuadIndex[i];
745               topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
746               const TopoDS_Edge&   newBotE = topSide->Edge(0);
747               const TopoDS_Shape& newWallF = face.Value();
748               thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
749               if ( !thePrism.myWallQuads[ iRight ].back() )
750                 return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
751                                    " not meshable with quadrangles"));
752               if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
753                 return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
754             }
755         }
756       }
757     } while ( nbKnownFaces != faceMap.Extent() );
758
759     // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
760     if ( totalNbFaces - faceMap.Extent() > 2 )
761     {
762       for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
763       {
764         StdMeshers_FaceSide* topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
765         const TopoDS_Edge &     topE = topSide->Edge( 0 );
766         if ( topSide->NbEdges() > 1 )
767           return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
768                              shapeID( thePrism.myWallQuads[i].back()->face )
769                              << " has a composite top edge"));
770         TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
771         for ( ; faceIt.More(); faceIt.Next() )
772           if ( faceMap.Add( faceIt.Value() ))
773           {
774             // a new wall FACE encountered, store it in wallQuads
775             thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
776             if ( !thePrism.myWallQuads[ i ].back() )
777               return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
778                                  " not meshable with quadrangles"));
779             if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
780               return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
781             if ( totalNbFaces - faceMap.Extent() == 2 )
782             {
783               i = thePrism.myWallQuads.size(); // to quit from the outer loop
784               break;
785             }
786           }
787       }
788     }
789   } // while ( totalNbFaces - faceMap.Extent() > 2 )
790
791   // ------------------
792   // Find the top FACE
793   // ------------------
794
795   if ( thePrism.myTop.IsNull() )
796   {
797     // now only top and bottom FACEs are not in the faceMap
798     faceMap.Add( thePrism.myBottom );
799     for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE );f.More(); f.Next() )
800       if ( !faceMap.Contains( f.Current() )) {
801         thePrism.myTop = TopoDS::Face( f.Current() );
802         break;
803       }
804     if ( thePrism.myTop.IsNull() )
805       return toSM( error("Top face not found"));
806   }
807
808   // Check that the top FACE shares all the top EDGEs
809   for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
810   {
811     StdMeshers_FaceSide* topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
812     const TopoDS_Edge &     topE = topSide->Edge( 0 );
813     if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
814       return toSM( error( TCom("Wrong source face (#") << shapeID( thePrism.myBottom )));
815   }
816
817   return true;
818 }
819
820 //=======================================================================
821 //function : compute
822 //purpose  : Compute mesh on a SOLID
823 //=======================================================================
824
825 bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
826 {
827   myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
828   if ( _computeCanceled )
829     return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
830
831   // Make all side FACEs of thePrism meshed with quads
832   if ( !computeWalls( thePrism ))
833     return false;
834
835   // Analyse mesh and geometry to find block sub-shapes and submeshes
836   if ( !myBlock.Init( myHelper, thePrism ))
837     return toSM( error( myBlock.GetError()));
838
839   SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
840
841   int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
842
843
844   // To compute coordinates of a node inside a block, it is necessary to know
845   // 1. normalized parameters of the node by which
846   // 2. coordinates of node projections on all block sub-shapes are computed
847
848   // So we fill projections on vertices at once as they are same for all nodes
849   myShapeXYZ.resize( myBlock.NbSubShapes() );
850   for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
851     myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
852     SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
853   }
854
855   // Projections on the top and bottom faces are taken from nodes existing
856   // on these faces; find correspondence between bottom and top nodes
857   myBotToColumnMap.clear();
858   if ( !assocOrProjBottom2Top() ) // it also fills myBotToColumnMap
859     return false;
860
861
862   // Create nodes inside the block
863
864   // try to use transformation (issue 0020680)
865   vector<gp_Trsf> trsf;
866   if ( myBlock.GetLayersTransformation( trsf, thePrism ))
867   {
868     // loop on nodes inside the bottom face
869     TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
870     for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
871     {
872       const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
873       if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
874         continue; // node is not inside face 
875
876       // column nodes; middle part of the column are zero pointers
877       TNodeColumn& column = bot_column->second;
878       TNodeColumn::iterator columnNodes = column.begin();
879       for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
880       {
881         const SMDS_MeshNode* & node = *columnNodes;
882         if ( node ) continue; // skip bottom or top node
883
884         gp_XYZ coords = tBotNode.GetCoords();
885         trsf[z-1].Transforms( coords );
886         node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
887         meshDS->SetNodeInVolume( node, volumeID );
888       }
889     } // loop on bottom nodes
890   }
891   else // use block approach
892   {
893     // loop on nodes inside the bottom face
894     Prism_3D::TNode prevBNode;
895     TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
896     for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
897     {
898       const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
899       if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
900         continue; // node is not inside face 
901
902       // column nodes; middle part of the column are zero pointers
903       TNodeColumn& column = bot_column->second;
904
905       // compute bottom node parameters
906       gp_XYZ paramHint(-1,-1,-1);
907       if ( prevBNode.IsNeighbor( tBotNode ))
908         paramHint = prevBNode.GetParams();
909       if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
910                                        ID_BOT_FACE, paramHint ))
911         return toSM( error(TCom("Can't compute normalized parameters for node ")
912                            << tBotNode.myNode->GetID() << " on the face #"
913                            << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
914       prevBNode = tBotNode;
915
916       myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
917       gp_XYZ botParams          = tBotNode.GetParams();
918
919       // compute top node parameters
920       myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
921       gp_XYZ topParams = botParams;
922       topParams.SetZ( 1 );
923       if ( column.size() > 2 ) {
924         gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
925         if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
926           return toSM( error(TCom("Can't compute normalized parameters ")
927                              << "for node " << column.back()->GetID()
928                              << " on the face #"<< column.back()->getshapeId() ));
929       }
930
931       // vertical loop
932       TNodeColumn::iterator columnNodes = column.begin();
933       for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
934       {
935         const SMDS_MeshNode* & node = *columnNodes;
936         if ( node ) continue; // skip bottom or top node
937
938         // params of a node to create
939         double rz = (double) z / (double) ( column.size() - 1 );
940         gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
941
942         // set coords on all faces and nodes
943         const int nbSideFaces = 4;
944         int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
945                                          SMESH_Block::ID_Fx1z,
946                                          SMESH_Block::ID_F0yz,
947                                          SMESH_Block::ID_F1yz };
948         for ( int iF = 0; iF < nbSideFaces; ++iF )
949           if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
950             return false;
951
952         // compute coords for a new node
953         gp_XYZ coords;
954         if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
955           return toSM( error("Can't compute coordinates by normalized parameters"));
956
957         SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
958         SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
959         SHOWYXZ("ShellPoint ",coords);
960
961         // create a node
962         node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
963         meshDS->SetNodeInVolume( node, volumeID );
964       }
965     } // loop on bottom nodes
966   }
967
968   // Create volumes
969
970   SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
971   if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
972
973   // loop on bottom mesh faces
974   SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
975   while ( faceIt->more() )
976   {
977     const SMDS_MeshElement* face = faceIt->next();
978     if ( !face || face->GetType() != SMDSAbs_Face )
979       continue;
980
981     // find node columns for each node
982     int nbNodes = face->NbCornerNodes();
983     vector< const TNodeColumn* > columns( nbNodes );
984     for ( int i = 0; i < nbNodes; ++i )
985     {
986       const SMDS_MeshNode* n = face->GetNode( i );
987       if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
988         TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
989         if ( bot_column == myBotToColumnMap.end() )
990           return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
991         columns[ i ] = & bot_column->second;
992       }
993       else {
994         columns[ i ] = myBlock.GetNodeColumn( n );
995         if ( !columns[ i ] )
996           return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
997       }
998     }
999     // create prisms
1000     AddPrisms( columns, myHelper );
1001
1002   } // loop on bottom mesh faces
1003
1004   // clear data
1005   myBotToColumnMap.clear();
1006   myBlock.Clear();
1007         
1008   return true;
1009 }
1010
1011 //=======================================================================
1012 //function : computeWalls
1013 //purpose  : Compute 2D mesh on walls FACEs of a prism
1014 //=======================================================================
1015
1016 bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
1017 {
1018   SMESH_Mesh*     mesh = myHelper->GetMesh();
1019   SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
1020
1021   TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
1022   StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
1023
1024   SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
1025   hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
1026   hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
1027
1028   // Discretize equally 'vertical' EDGEs
1029   // -----------------------------------
1030   // find source FACE sides for projection: either already computed ones or
1031   // the 'most composite' ones
1032   multimap< int, int > wgt2quad;
1033   for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1034   {
1035     Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1036     int wgt = 0; // "weight"
1037     for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1038     {
1039       StdMeshers_FaceSide* lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
1040       for ( int i = 0; i < lftSide->NbEdges(); ++i )
1041       {
1042         ++wgt;
1043         const TopoDS_Edge& E = lftSide->Edge(i);
1044         if ( mesh->GetSubMesh( E )->IsMeshComputed() )
1045           wgt += 10;
1046         else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
1047           wgt += 100;
1048       }
1049     }
1050     wgt2quad.insert( make_pair( wgt, iW ));
1051
1052     // in quadratic mesh, pass ignoreMediumNodes to quad sides
1053     if ( myHelper->GetIsQuadratic() )
1054     {
1055       quad = thePrism.myWallQuads[iW].begin();
1056       for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1057         for ( int i = 0; i < NB_QUAD_SIDES; ++i )
1058           (*quad)->side[ i ]->SetIgnoreMediumNodes( true );
1059     }
1060   }
1061
1062   // Project 'vertical' EDGEs, from left to right
1063   multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
1064   for ( ; w2q != wgt2quad.rend(); ++w2q )
1065   {
1066     const int iW = w2q->second;
1067     const Prism_3D::TQuadList&         quads = thePrism.myWallQuads[ iW ];
1068     Prism_3D::TQuadList::const_iterator quad = quads.begin();
1069     for ( ; quad != quads.end(); ++quad )
1070     {
1071       StdMeshers_FaceSide* rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
1072       StdMeshers_FaceSide* lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];  // src
1073       bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
1074                              rgtSide->NbSegments( /*update=*/true )  > 0 );
1075       if ( swapLeftRight )
1076         std::swap( lftSide, rgtSide );
1077
1078       // assure that all the source (left) EDGEs are meshed
1079       int nbSrcSegments = 0;
1080       for ( int i = 0; i < lftSide->NbEdges(); ++i )
1081       {
1082         const TopoDS_Edge& srcE = lftSide->Edge(i);
1083         SMESH_subMesh*    srcSM = mesh->GetSubMesh( srcE );
1084         if ( !srcSM->IsMeshComputed() ) {
1085           srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1086           srcSM->ComputeStateEngine       ( SMESH_subMesh::COMPUTE );
1087           if ( !srcSM->IsMeshComputed() )
1088             return false;
1089         }
1090         nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
1091       }
1092       // check target EDGEs
1093       int nbTgtMeshed = 0, nbTgtSegments = 0;
1094       vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
1095       for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1096       {
1097         const TopoDS_Edge& tgtE = rgtSide->Edge(i);
1098         SMESH_subMesh*    tgtSM = mesh->GetSubMesh( tgtE );
1099         if (( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
1100           ++nbTgtMeshed;
1101           nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
1102         }
1103       }
1104       if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
1105       {
1106         if ( nbTgtSegments != nbSrcSegments )
1107         {
1108           for ( int i = 0; i < lftSide->NbEdges(); ++i )
1109             addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
1110           for ( int i = 0; i < rgtSide->NbEdges(); ++i )
1111             addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
1112           return toSM( error( TCom("Different nb of segment on logically vertical edges #")
1113                               << shapeID( lftSide->Edge(0) ) << " and #"
1114                               << shapeID( rgtSide->Edge(0) ) << ": "
1115                               << nbSrcSegments << " != " << nbTgtSegments ));
1116         }
1117         continue;
1118       }
1119       // Compute
1120       if ( nbTgtMeshed == 0 )
1121       {
1122         // compute nodes on target VERTEXes
1123         const UVPtStructVec&  srcNodeStr = lftSide->GetUVPtStruct();
1124         if ( srcNodeStr.size() == 0 )
1125           return toSM( error( TCom("Invalid node positions on edge #") <<
1126                               shapeID( lftSide->Edge(0) )));
1127         vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
1128         for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
1129         {
1130           const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
1131           TopoDS_Vertex      v = myHelper->IthVertex( is2ndV, E );
1132           mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
1133           const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
1134           newNodes[ is2ndV ? 0 : newNodes.size()-1 ] = (SMDS_MeshNode*) n;
1135         }
1136
1137         // compute nodes on target EDGEs
1138         rgtSide->Reverse(); // direct it same as the lftSide
1139         myHelper->SetElementsOnShape( false );
1140         TopoDS_Edge tgtEdge;
1141         for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
1142         {
1143           gp_Pnt       p = rgtSide->Value3d  ( srcNodeStr[ iN ].normParam );
1144           double       u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
1145           newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
1146           meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
1147         }
1148         for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
1149         {
1150           SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
1151           std::pair<int, TopAbs_ShapeEnum> id2type = 
1152             myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
1153           if ( id2type.second == TopAbs_EDGE )
1154           {
1155             meshDS->SetMeshElementOnShape( newEdge, id2type.first );
1156           }
1157           else // new nodes are on different EDGEs; put one of them on VERTEX
1158           {
1159             const int      edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
1160             const double vertexParam = rgtSide->LastParameter( edgeIndex );
1161             const gp_Pnt           p = BRep_Tool::Pnt( rgtSide->LastVertex( edgeIndex ));
1162             const int         isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
1163                                          Abs( srcNodeStr[ iN   ].normParam - vertexParam ));
1164             meshDS->SetMeshElementOnShape( newEdge, newNodes[ iN-(1-isPrev) ]->getshapeId() );
1165             meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
1166             meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], rgtSide->LastVertex( edgeIndex ));
1167             meshDS->MoveNode( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
1168           }
1169         }
1170         myHelper->SetElementsOnShape( true );
1171         for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
1172         {
1173           const TopoDS_Edge& E = rgtSide->Edge( i );
1174           SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
1175           tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1176         }
1177
1178         // to continue projection from the just computed side as a source
1179         if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
1180         {
1181           std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
1182           wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
1183           wgt2quad.insert( wgt2quadKeyVal );
1184           w2q = wgt2quad.rbegin();
1185         }
1186       }
1187       else
1188       {
1189         // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
1190         //return toSM( error("Partial projection not implemented"));
1191       }
1192     } // loop on quads of a composite wall side
1193   } // loop on the ordered wall sides
1194
1195
1196
1197   for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
1198   {
1199     Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
1200     for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
1201     {
1202       // Top EDGEs must be projections from the bottom ones
1203       // to compute stuctured quad mesh on wall FACEs
1204       // ---------------------------------------------------
1205       const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ]->Edge(0);
1206       const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE    ]->Edge(0);
1207
1208       projector1D->myHyp.SetSourceEdge( botE );
1209
1210       SMESH_subMesh* tgtEdgeSm = mesh->GetSubMesh( topE );
1211       if ( !tgtEdgeSm->IsMeshComputed() )
1212       {
1213         // compute nodes on VERTEXes
1214         tgtEdgeSm->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1215         // project segments
1216         projector1D->InitComputeError();
1217         bool ok = projector1D->Compute( *mesh, topE );
1218         if ( !ok )
1219         {
1220           SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
1221           if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
1222           tgtEdgeSm->GetComputeError() = err;
1223           return false;
1224         }
1225       }
1226       tgtEdgeSm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1227
1228       // Compute quad mesh on wall FACEs
1229       // -------------------------------
1230       const TopoDS_Face& face = (*quad)->face;
1231       SMESH_subMesh* fSM = mesh->GetSubMesh( face );
1232       if ( ! fSM->IsMeshComputed() )
1233       {
1234         // make all EDGES meshed
1235         fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
1236         if ( !fSM->SubMeshesComputed() )
1237           return toSM( error( COMPERR_BAD_INPUT_MESH,
1238                               "Not all edges have valid algorithm and hypothesis"));
1239         // mesh the <face>
1240         quadAlgo->InitComputeError();
1241         bool ok = quadAlgo->Compute( *mesh, face );
1242         fSM->GetComputeError() = quadAlgo->GetComputeError();
1243         if ( !ok )
1244           return false;
1245         fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1246       }
1247       if ( myHelper->GetIsQuadratic() )
1248       {
1249         // fill myHelper with medium nodes built by quadAlgo
1250         SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements();
1251         while ( fIt->more() )
1252           myHelper->AddTLinks( dynamic_cast<const SMDS_MeshFace*>( fIt->next() ));
1253       }
1254     }
1255   }
1256
1257   return true;
1258 }
1259
1260 //=======================================================================
1261 //function : Evaluate
1262 //purpose  : 
1263 //=======================================================================
1264
1265 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh&         theMesh,
1266                                    const TopoDS_Shape& theShape,
1267                                    MapShapeNbElems&    aResMap)
1268 {
1269   if ( theShape.ShapeType() == TopAbs_COMPOUND )
1270   {
1271     bool ok = true;
1272     for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
1273       ok &= Evaluate( theMesh, it.Value(), aResMap );
1274     return ok;
1275   }
1276   SMESH_MesherHelper helper( theMesh );
1277   myHelper = &helper;
1278   myHelper->SetSubShape( theShape );
1279
1280   // find face contains only triangles
1281   vector < SMESH_subMesh * >meshFaces;
1282   TopTools_SequenceOfShape aFaces;
1283   int NumBase = 0, i = 0, NbQFs = 0;
1284   for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
1285     i++;
1286     aFaces.Append(exp.Current());
1287     SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
1288     meshFaces.push_back(aSubMesh);
1289     MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
1290     if( anIt==aResMap.end() )
1291       return toSM( error( "Submesh can not be evaluated"));
1292
1293     std::vector<int> aVec = (*anIt).second;
1294     int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1295     int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1296     if( nbtri==0 && nbqua>0 ) {
1297       NbQFs++;
1298     }
1299     if( nbtri>0 ) {
1300       NumBase = i;
1301     }
1302   }
1303
1304   if(NbQFs<4) {
1305     std::vector<int> aResVec(SMDSEntity_Last);
1306     for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1307     SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1308     aResMap.insert(std::make_pair(sm,aResVec));
1309     return toSM( error( "Submesh can not be evaluated" ));
1310   }
1311
1312   if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
1313
1314   // find number of 1d elems for base face
1315   int nb1d = 0;
1316   TopTools_MapOfShape Edges1;
1317   for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
1318     Edges1.Add(exp.Current());
1319     SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
1320     if( sm ) {
1321       MapShapeNbElemsItr anIt = aResMap.find(sm);
1322       if( anIt == aResMap.end() ) continue;
1323       std::vector<int> aVec = (*anIt).second;
1324       nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
1325     }
1326   }
1327   // find face opposite to base face
1328   int OppNum = 0;
1329   for(i=1; i<=6; i++) {
1330     if(i==NumBase) continue;
1331     bool IsOpposite = true;
1332     for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
1333       if( Edges1.Contains(exp.Current()) ) {
1334         IsOpposite = false;
1335         break;
1336       }
1337     }
1338     if(IsOpposite) {
1339       OppNum = i;
1340       break;
1341     }
1342   }
1343   // find number of 2d elems on side faces
1344   int nb2d = 0;
1345   for(i=1; i<=6; i++) {
1346     if( i==OppNum || i==NumBase ) continue;
1347     MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
1348     if( anIt == aResMap.end() ) continue;
1349     std::vector<int> aVec = (*anIt).second;
1350     nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1351   }
1352   
1353   MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
1354   std::vector<int> aVec = (*anIt).second;
1355   bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
1356                      (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
1357   int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
1358   int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
1359   int nb0d_face0 = aVec[SMDSEntity_Node];
1360   int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
1361
1362   std::vector<int> aResVec(SMDSEntity_Last);
1363   for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
1364   if(IsQuadratic) {
1365     aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1366     aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1367     aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
1368   }
1369   else {
1370     aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
1371     aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
1372     aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
1373   }
1374   SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1375   aResMap.insert(std::make_pair(sm,aResVec));
1376
1377   return true;
1378 }
1379
1380 //================================================================================
1381 /*!
1382  * \brief Create prisms
1383  * \param columns - columns of nodes generated from nodes of a mesh face
1384  * \param helper - helper initialized by mesh and shape to add prisms to
1385  */
1386 //================================================================================
1387
1388 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
1389                                      SMESH_MesherHelper*          helper)
1390 {
1391   int nbNodes = columns.size();
1392   int nbZ     = columns[0]->size();
1393   if ( nbZ < 2 ) return;
1394
1395   // find out orientation
1396   bool isForward = true;
1397   SMDS_VolumeTool vTool;
1398   int z = 1;
1399   switch ( nbNodes ) {
1400   case 3: {
1401     SMDS_VolumeOfNodes tmpPenta ( (*columns[0])[z-1], // bottom
1402                                   (*columns[1])[z-1],
1403                                   (*columns[2])[z-1],
1404                                   (*columns[0])[z],   // top
1405                                   (*columns[1])[z],
1406                                   (*columns[2])[z] );
1407     vTool.Set( &tmpPenta );
1408     isForward  = vTool.IsForward();
1409     break;
1410   }
1411   case 4: {
1412     SMDS_VolumeOfNodes tmpHex( (*columns[0])[z-1], (*columns[1])[z-1], // bottom
1413                                (*columns[2])[z-1], (*columns[3])[z-1],
1414                                (*columns[0])[z],   (*columns[1])[z],   // top
1415                                (*columns[2])[z],   (*columns[3])[z] );
1416     vTool.Set( &tmpHex );
1417     isForward  = vTool.IsForward();
1418     break;
1419   }
1420   default:
1421     const int di = (nbNodes+1) / 3;
1422     SMDS_VolumeOfNodes tmpVol ( (*columns[0]   )[z-1],
1423                                 (*columns[di]  )[z-1],
1424                                 (*columns[2*di])[z-1],
1425                                 (*columns[0]   )[z],
1426                                 (*columns[di]  )[z],
1427                                 (*columns[2*di])[z] );
1428     vTool.Set( &tmpVol );
1429     isForward  = vTool.IsForward();
1430   }
1431
1432   // vertical loop on columns
1433
1434   helper->SetElementsOnShape( true );
1435
1436   switch ( nbNodes ) {
1437
1438   case 3: { // ---------- pentahedra
1439     const int i1 = isForward ? 1 : 2;
1440     const int i2 = isForward ? 2 : 1;
1441     for ( z = 1; z < nbZ; ++z )
1442       helper->AddVolume( (*columns[0 ])[z-1], // bottom
1443                          (*columns[i1])[z-1],
1444                          (*columns[i2])[z-1],
1445                          (*columns[0 ])[z],   // top
1446                          (*columns[i1])[z],
1447                          (*columns[i2])[z] );
1448     break;
1449   }
1450   case 4: { // ---------- hexahedra
1451     const int i1 = isForward ? 1 : 3;
1452     const int i3 = isForward ? 3 : 1;
1453     for ( z = 1; z < nbZ; ++z )
1454       helper->AddVolume( (*columns[0])[z-1], (*columns[i1])[z-1], // bottom
1455                          (*columns[2])[z-1], (*columns[i3])[z-1],
1456                          (*columns[0])[z],   (*columns[i1])[z],     // top
1457                          (*columns[2])[z],   (*columns[i3])[z] );
1458     break;
1459   }
1460   case 6: { // ---------- octahedra
1461     const int iBase1 = isForward ? -1 : 0;
1462     const int iBase2 = isForward ?  0 :-1;
1463     for ( z = 1; z < nbZ; ++z )
1464       helper->AddVolume( (*columns[0])[z+iBase1], (*columns[1])[z+iBase1], // bottom or top
1465                          (*columns[2])[z+iBase1], (*columns[3])[z+iBase1],
1466                          (*columns[4])[z+iBase1], (*columns[5])[z+iBase1],
1467                          (*columns[0])[z+iBase2], (*columns[1])[z+iBase2], // top or bottom
1468                          (*columns[2])[z+iBase2], (*columns[3])[z+iBase2],
1469                          (*columns[4])[z+iBase2], (*columns[5])[z+iBase2] );
1470     break;
1471   }
1472   default: // ---------- polyhedra
1473     vector<int> quantities( 2 + nbNodes, 4 );
1474     quantities[0] = quantities[1] = nbNodes;
1475     columns.resize( nbNodes + 1 );
1476     columns[ nbNodes ] = columns[ 0 ];
1477     const int i1 = isForward ? 1 : 3;
1478     const int i3 = isForward ? 3 : 1;
1479     const int iBase1 = isForward ? -1 : 0;
1480     const int iBase2 = isForward ?  0 :-1;
1481     vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
1482     for ( z = 1; z < nbZ; ++z )
1483     {
1484       for ( int i = 0; i < nbNodes; ++i ) {
1485         nodes[ i             ] = (*columns[ i ])[z+iBase1]; // bottom or top
1486         nodes[ 2*nbNodes-i-1 ] = (*columns[ i ])[z+iBase2]; // top or bottom
1487         // side
1488         int di = 2*nbNodes + 4*i;
1489         nodes[ di+0 ] = (*columns[i  ])[z  ];
1490         nodes[ di+i1] = (*columns[i+1])[z  ];
1491         nodes[ di+2 ] = (*columns[i+1])[z-1];
1492         nodes[ di+i3] = (*columns[i  ])[z-1];
1493       }
1494       helper->AddPolyhedralVolume( nodes, quantities );
1495     }
1496
1497   } // switch ( nbNodes )
1498 }
1499
1500 //================================================================================
1501 /*!
1502  * \brief Find correspondence between bottom and top nodes
1503  *  If elements on the bottom and top faces are topologically different,
1504  *  and projection is possible and allowed, perform the projection
1505  *  \retval bool - is a success or not
1506  */
1507 //================================================================================
1508
1509 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
1510 {
1511   SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
1512   SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
1513
1514   SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1515   SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1516
1517   if ( !botSMDS || botSMDS->NbElements() == 0 )
1518   {
1519     _gen->Compute( *myHelper->GetMesh(), botSM->GetSubShape() );
1520     botSMDS = botSM->GetSubMeshDS();
1521     if ( !botSMDS || botSMDS->NbElements() == 0 )
1522       return toSM( error(TCom("No elememts on face #") << botSM->GetId() ));
1523   }
1524
1525   bool needProject = !topSM->IsMeshComputed();
1526   if ( !needProject && 
1527        (botSMDS->NbElements() != topSMDS->NbElements() ||
1528         botSMDS->NbNodes()    != topSMDS->NbNodes()))
1529   {
1530     MESSAGE("nb elem bot " << botSMDS->NbElements() <<
1531             " top " << ( topSMDS ? topSMDS->NbElements() : 0 ));
1532     MESSAGE("nb node bot " << botSMDS->NbNodes() <<
1533             " top " << ( topSMDS ? topSMDS->NbNodes() : 0 ));
1534     return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1535                        <<" and #"<< topSM->GetId() << " seems different" ));
1536   }
1537
1538   if ( 0/*needProject && !myProjectTriangles*/ )
1539     return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1540                        <<" and #"<< topSM->GetId() << " seems different" ));
1541   ///RETURN_BAD_RESULT("Need to project but not allowed");
1542
1543   if ( needProject )
1544   {
1545     return projectBottomToTop();
1546   }
1547
1548   TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
1549   TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
1550   // associate top and bottom faces
1551   TAssocTool::TShapeShapeMap shape2ShapeMap;
1552   if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
1553                                              topFace, myBlock.Mesh(),
1554                                              shape2ShapeMap) )
1555     return toSM( error(TCom("Topology of faces #") << botSM->GetId()
1556                        <<" and #"<< topSM->GetId() << " seems different" ));
1557
1558   // Find matching nodes of top and bottom faces
1559   TNodeNodeMap n2nMap;
1560   if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
1561                                                topFace, myBlock.Mesh(),
1562                                                shape2ShapeMap, n2nMap ))
1563     return toSM( error(TCom("Mesh on faces #") << botSM->GetId()
1564                        <<" and #"<< topSM->GetId() << " seems different" ));
1565
1566   // Fill myBotToColumnMap
1567
1568   int zSize = myBlock.VerticalSize();
1569   //TNode prevTNode;
1570   TNodeNodeMap::iterator bN_tN = n2nMap.begin();
1571   for ( ; bN_tN != n2nMap.end(); ++bN_tN )
1572   {
1573     const SMDS_MeshNode* botNode = bN_tN->first;
1574     const SMDS_MeshNode* topNode = bN_tN->second;
1575     if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1576       continue; // wall columns are contained in myBlock
1577     // create node column
1578     Prism_3D::TNode bN( botNode );
1579     TNode2ColumnMap::iterator bN_col = 
1580       myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
1581     TNodeColumn & column = bN_col->second;
1582     column.resize( zSize );
1583     column.front() = botNode;
1584     column.back()  = topNode;
1585   }
1586   return true;
1587 }
1588
1589 //================================================================================
1590 /*!
1591  * \brief Remove quadrangles from the top face and
1592  * create triangles there by projection from the bottom
1593  * \retval bool - a success or not
1594  */
1595 //================================================================================
1596
1597 bool StdMeshers_Prism_3D::projectBottomToTop()
1598 {
1599   SMESHDS_Mesh*  meshDS = myBlock.MeshDS();
1600   SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
1601   SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
1602
1603   SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
1604   SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
1605
1606   if ( topSMDS && topSMDS->NbElements() > 0 )
1607     topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
1608
1609   const TopoDS_Shape& botFace = myBlock.Shape( ID_BOT_FACE ); // oriented within the 3D SHAPE
1610   const TopoDS_Shape& topFace = myBlock.Shape( ID_TOP_FACE);
1611   int topFaceID = meshDS->ShapeToIndex( topFace );
1612
1613   // Fill myBotToColumnMap
1614
1615   int zSize = myBlock.VerticalSize();
1616   Prism_3D::TNode prevTNode;
1617   SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
1618   while ( nIt->more() )
1619   {
1620     const SMDS_MeshNode* botNode = nIt->next();
1621     if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
1622       continue; // strange
1623     // compute bottom node params
1624     Prism_3D::TNode bN( botNode );
1625     gp_XYZ paramHint(-1,-1,-1);
1626     if ( prevTNode.IsNeighbor( bN ))
1627       paramHint = prevTNode.GetParams();
1628     if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
1629                                      ID_BOT_FACE, paramHint ))
1630       return toSM( error(TCom("Can't compute normalized parameters for node ")
1631                          << botNode->GetID() << " on the face #"<< botSM->GetId() ));
1632     prevTNode = bN;
1633     // compute top node coords
1634     gp_XYZ topXYZ; gp_XY topUV;
1635     if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
1636          !myBlock.FaceUV   ( ID_TOP_FACE, bN.GetParams(), topUV ))
1637       return toSM( error(TCom("Can't compute coordinates "
1638                               "by normalized parameters on the face #")<< topSM->GetId() ));
1639     SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
1640     meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
1641     // create node column
1642     TNode2ColumnMap::iterator bN_col = 
1643       myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
1644     TNodeColumn & column = bN_col->second;
1645     column.resize( zSize );
1646     column.front() = botNode;
1647     column.back()  = topNode;
1648   }
1649
1650   // Create top faces
1651
1652   const bool oldSetElemsOnShape = myHelper->SetElementsOnShape( false );
1653
1654   // care of orientation;
1655   // if the bottom faces is orienetd OK then top faces must be reversed
1656   bool reverseTop = true;
1657   if ( myHelper->NbAncestors( botFace, *myBlock.Mesh(), TopAbs_SOLID ) > 1 )
1658     reverseTop = ! myHelper->IsReversedSubMesh( TopoDS::Face( botFace ));
1659   int iFrw, iRev, *iPtr = &( reverseTop ? iRev : iFrw );
1660
1661   // loop on bottom mesh faces
1662   SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
1663   vector< const SMDS_MeshNode* > nodes;
1664   while ( faceIt->more() )
1665   {
1666     const SMDS_MeshElement* face = faceIt->next();
1667     if ( !face || face->GetType() != SMDSAbs_Face )
1668       continue;
1669
1670     // find top node in columns for each bottom node
1671     int nbNodes = face->NbCornerNodes();
1672     nodes.resize( nbNodes );
1673     for ( iFrw = 0, iRev = nbNodes-1; iFrw < nbNodes; ++iFrw, --iRev )
1674     {
1675       const SMDS_MeshNode* n = face->GetNode( *iPtr );
1676       if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
1677         TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
1678         if ( bot_column == myBotToColumnMap.end() )
1679           return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
1680         nodes[ iFrw ] = bot_column->second.back();
1681       }
1682       else {
1683         const TNodeColumn* column = myBlock.GetNodeColumn( n );
1684         if ( !column )
1685           return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
1686         nodes[ iFrw ] = column->back();
1687       }
1688     }
1689     SMDS_MeshElement* newFace = 0;
1690     switch ( nbNodes ) {
1691
1692     case 3: {
1693       newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
1694       break;
1695       }
1696     case 4: {
1697       newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
1698       break;
1699       }
1700     default:
1701       newFace = meshDS->AddPolygonalFace( nodes );
1702     }
1703     if ( newFace )
1704       meshDS->SetMeshElementOnShape( newFace, topFaceID );
1705   }
1706
1707   myHelper->SetElementsOnShape( oldSetElemsOnShape );  
1708
1709   return true;
1710 }
1711
1712 //=======================================================================
1713 //function : project2dMesh
1714 //purpose  : Project mesh faces from a source FACE of one prism (theSrcFace)
1715 //           to a source FACE of another prism (theTgtFace)
1716 //=======================================================================
1717
1718 bool StdMeshers_Prism_3D::project2dMesh(const TopoDS_Face& theSrcFace,
1719                                         const TopoDS_Face& theTgtFace)
1720 {
1721   TProjction2dAlgo* projector2D = TProjction2dAlgo::instance( this );
1722   projector2D->myHyp.SetSourceFace( theSrcFace );
1723   bool ok = projector2D->Compute( *myHelper->GetMesh(), theTgtFace );
1724
1725   SMESH_subMesh* tgtSM = myHelper->GetMesh()->GetSubMesh( theTgtFace );
1726   tgtSM->ComputeStateEngine       ( SMESH_subMesh::CHECK_COMPUTE_STATE );
1727   tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
1728
1729   return ok;
1730 }
1731
1732 //================================================================================
1733 /*!
1734  * \brief Set projection coordinates of a node to a face and it's sub-shapes
1735  * \param faceID - the face given by in-block ID
1736  * \param params - node normalized parameters
1737  * \retval bool - is a success
1738  */
1739 //================================================================================
1740
1741 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
1742 {
1743   // find base and top edges of the face
1744   enum { BASE = 0, TOP, LEFT, RIGHT };
1745   vector< int > edgeVec; // 0-base, 1-top
1746   SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
1747
1748   myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
1749   myBlock.EdgePoint( edgeVec[ TOP  ], params, myShapeXYZ[ edgeVec[ TOP ]]);
1750
1751   SHOWYXZ("\nparams ", params);
1752   SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
1753   SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
1754
1755   if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
1756   {
1757     myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
1758     myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
1759
1760     SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
1761     SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
1762   }
1763   myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
1764   SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
1765
1766   return true;
1767 }
1768
1769 //=======================================================================
1770 //function : toSM
1771 //purpose  : If (!isOK), sets the error to a sub-mesh of a current SOLID
1772 //=======================================================================
1773
1774 bool StdMeshers_Prism_3D::toSM( bool isOK )
1775 {
1776   if ( mySetErrorToSM &&
1777        !isOK &&
1778        myHelper &&
1779        !myHelper->GetSubShape().IsNull() &&
1780        myHelper->GetSubShape().ShapeType() == TopAbs_SOLID)
1781   {
1782     SMESH_subMesh* sm = myHelper->GetMesh()->GetSubMesh( myHelper->GetSubShape() );
1783     sm->GetComputeError() = this->GetComputeError();
1784     // clear error in order not to return it twice
1785     _error = COMPERR_OK;
1786     _comment.clear();
1787   }
1788   return isOK;
1789 }
1790
1791 //=======================================================================
1792 //function : shapeID
1793 //purpose  : Return index of a shape
1794 //=======================================================================
1795
1796 int StdMeshers_Prism_3D::shapeID( const TopoDS_Shape& S )
1797 {
1798   if ( S.IsNull() ) return 0;
1799   if ( !myHelper  ) return -3;
1800   return myHelper->GetMeshDS()->ShapeToIndex( S );
1801 }
1802
1803 namespace Prism_3D
1804 {
1805   //================================================================================
1806   /*!
1807    * \brief Return true if this node and other one belong to one face
1808    */
1809   //================================================================================
1810
1811   bool Prism_3D::TNode::IsNeighbor( const Prism_3D::TNode& other ) const
1812   {
1813     if ( !other.myNode || !myNode ) return false;
1814
1815     SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
1816     while ( fIt->more() )
1817       if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
1818         return true;
1819     return false;
1820   }
1821
1822   //================================================================================
1823   /*!
1824    * \brief Prism initialization
1825    */
1826   //================================================================================
1827
1828   void TPrismTopo::Clear()
1829   {
1830     myShape3D.Nullify();
1831     myTop.Nullify();
1832     myBottom.Nullify();
1833     myWallQuads.clear();
1834     myBottomEdges.clear();
1835     myNbEdgesInWires.clear();
1836     myWallQuads.clear();
1837   }
1838
1839 } // namespace Prism_3D
1840
1841 //================================================================================
1842 /*!
1843  * \brief Constructor. Initialization is needed
1844  */
1845 //================================================================================
1846
1847 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
1848 {
1849   mySide = 0;
1850 }
1851
1852 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
1853 {
1854   Clear();
1855 }
1856 void StdMeshers_PrismAsBlock::Clear()
1857 {
1858   myHelper = 0;
1859   myShapeIDMap.Clear();
1860   myError.reset();
1861
1862   if ( mySide ) {
1863     delete mySide; mySide = 0;
1864   }
1865   myParam2ColumnMaps.clear();
1866   myShapeIndex2ColumnMap.clear();
1867 }
1868
1869 //=======================================================================
1870 //function : initPrism
1871 //purpose  : Analyse shape geometry and mesh.
1872 //           If there are triangles on one of faces, it becomes 'bottom'.
1873 //           thePrism.myBottom can be already set up.
1874 //=======================================================================
1875
1876 bool StdMeshers_Prism_3D::initPrism(Prism_3D::TPrismTopo& thePrism,
1877                                     const TopoDS_Shape&   shape3D)
1878 {
1879   myHelper->SetSubShape( shape3D );
1880
1881   SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
1882   if ( !mainSubMesh ) return toSM( error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D"));
1883
1884   // detect not-quad FACE sub-meshes of the 3D SHAPE
1885   list< SMESH_subMesh* > notQuadGeomSubMesh;
1886   list< SMESH_subMesh* > notQuadElemSubMesh;
1887   int nbFaces = 0;
1888   //
1889   SMESH_subMesh* anyFaceSM = 0;
1890   SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,true);
1891   while ( smIt->more() )
1892   {
1893     SMESH_subMesh* sm = smIt->next();
1894     const TopoDS_Shape& face = sm->GetSubShape();
1895     if      ( face.ShapeType() > TopAbs_FACE ) break;
1896     else if ( face.ShapeType() < TopAbs_FACE ) continue;
1897     nbFaces++;
1898     anyFaceSM = sm;
1899
1900     // is quadrangle FACE?
1901     list< TopoDS_Edge > orderedEdges;
1902     list< int >         nbEdgesInWires;
1903     int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( face ), orderedEdges,
1904                                                 nbEdgesInWires );
1905     if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
1906       notQuadGeomSubMesh.push_back( sm );
1907
1908     // look for not quadrangle mesh elements
1909     if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() )
1910       if ( !myHelper->IsSameElemGeometry( smDS, SMDSGeom_QUADRANGLE ))
1911         notQuadElemSubMesh.push_back( sm );
1912   }
1913
1914   int nbNotQuadMeshed = notQuadElemSubMesh.size();
1915   int       nbNotQuad = notQuadGeomSubMesh.size();
1916   bool     hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
1917
1918   // detect bad cases
1919   if ( nbNotQuadMeshed > 2 )
1920   {
1921     return toSM( error(COMPERR_BAD_INPUT_MESH,
1922                        TCom("More than 2 faces with not quadrangle elements: ")
1923                        <<nbNotQuadMeshed));
1924   }
1925   if ( nbNotQuad > 2 || !thePrism.myBottom.IsNull() )
1926   {
1927     // Issue 0020843 - one of side FACEs is quasi-quadrilateral (not 4 EDGEs).
1928     // Remove from notQuadGeomSubMesh faces meshed with regular grid
1929     int nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh, myHelper,
1930                                          TQuadrangleAlgo::instance(this,myHelper) );
1931     nbNotQuad -= nbQuasiQuads;
1932     if ( nbNotQuad > 2 )
1933       return toSM( error(COMPERR_BAD_SHAPE,
1934                          TCom("More than 2 not quadrilateral faces: ") <<nbNotQuad));
1935     hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
1936   }
1937
1938   // Analyse mesh and topology of FACEs: choose the bottom sub-mesh.
1939   // If there are not quadrangle FACEs, they are top and bottom ones.
1940   // Not quadrangle FACEs must be only on top and bottom.
1941
1942   SMESH_subMesh * botSM = 0;
1943   SMESH_subMesh * topSM = 0;
1944
1945   if ( hasNotQuad ) // can chose a bottom FACE
1946   {
1947     if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
1948     else                       botSM = notQuadGeomSubMesh.front();
1949     if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
1950     else if ( nbNotQuad  > 1 ) topSM = notQuadGeomSubMesh.back();
1951
1952     if ( topSM == botSM ) {
1953       if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.front();
1954       else                       topSM = notQuadGeomSubMesh.front();
1955     }
1956
1957     // detect mesh triangles on wall FACEs
1958     if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
1959       bool ok = false;
1960       if ( nbNotQuadMeshed == 1 )
1961         ok = ( find( notQuadGeomSubMesh.begin(),
1962                      notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
1963       else
1964         ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
1965       if ( !ok )
1966         return toSM( error(COMPERR_BAD_INPUT_MESH,
1967                            "Side face meshed with not quadrangle elements"));
1968     }
1969   }
1970
1971   thePrism.myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
1972
1973   // use thePrism.myBottom
1974   if ( !thePrism.myBottom.IsNull() )
1975   {
1976     if ( botSM ) {
1977       if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom )) {
1978         std::swap( botSM, topSM );
1979         if ( ! botSM->GetSubShape().IsSame( thePrism.myBottom ))
1980           return toSM( error( COMPERR_BAD_INPUT_MESH,
1981                               "Incompatible non-structured sub-meshes"));
1982       }
1983     }
1984     else {
1985       botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
1986     }
1987   }
1988   else if ( !botSM ) // find a proper bottom
1989   {
1990     // composite walls or not prism shape
1991     for ( TopExp_Explorer f( shape3D, TopAbs_FACE ); f.More(); f.Next() )
1992     {
1993       int minNbFaces = 2 + myHelper->Count( f.Current(), TopAbs_EDGE, false);
1994       if ( nbFaces >= minNbFaces)
1995       {
1996         thePrism.Clear();
1997         thePrism.myBottom = TopoDS::Face( f.Current() );
1998         if ( initPrism( thePrism, shape3D ))
1999           return true;
2000       }
2001       return toSM( error( COMPERR_BAD_SHAPE ));
2002     }
2003   }
2004
2005   // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
2006   TopoDS_Vertex V000;
2007   double minVal = DBL_MAX, minX, val;
2008   for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
2009         exp.More(); exp.Next() )
2010   {
2011     const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
2012     gp_Pnt P = BRep_Tool::Pnt( v );
2013     val = P.X() + P.Y() + P.Z();
2014     if ( val < minVal || ( val == minVal && P.X() < minX )) {
2015       V000 = v;
2016       minVal = val;
2017       minX = P.X();
2018     }
2019   }
2020
2021   thePrism.myShape3D = shape3D;
2022   if ( thePrism.myBottom.IsNull() )
2023     thePrism.myBottom  = TopoDS::Face( botSM->GetSubShape() );
2024   thePrism.myBottom.Orientation( myHelper->GetSubShapeOri( shape3D,
2025                                                            thePrism.myBottom ));
2026   // Get ordered bottom edges
2027   TopoDS_Face reverseBottom = // to have order of top EDGEs as in the top FACE
2028     TopoDS::Face( thePrism.myBottom.Reversed() );
2029   SMESH_Block::GetOrderedEdges( reverseBottom,
2030                                 thePrism.myBottomEdges,
2031                                 thePrism.myNbEdgesInWires, V000 );
2032
2033   // Get Wall faces corresponding to the ordered bottom edges and the top FACE
2034   if ( !getWallFaces( thePrism, nbFaces ))
2035     return false; //toSM( error(COMPERR_BAD_SHAPE, "Can't find side faces"));
2036
2037   if ( topSM )
2038   {
2039     if ( !thePrism.myTop.IsSame( topSM->GetSubShape() ))
2040       return toSM( error
2041                    (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
2042                     "Non-quadrilateral faces are not opposite"));
2043
2044     // check that the found top and bottom FACEs are opposite
2045     list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
2046     for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
2047       if ( myHelper->IsSubShape( *edge, thePrism.myTop ))
2048         return toSM( error
2049                      (notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
2050                       "Non-quadrilateral faces are not opposite"));
2051   }
2052
2053   return true;
2054 }
2055
2056 //================================================================================
2057 /*!
2058  * \brief Initialization.
2059  * \param helper - helper loaded with mesh and 3D shape
2060  * \param thePrism - a prosm data
2061  * \retval bool - false if a mesh or a shape are KO
2062  */
2063 //================================================================================
2064
2065 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper*         helper,
2066                                    const Prism_3D::TPrismTopo& thePrism)
2067 {
2068   if ( mySide ) {
2069     delete mySide; mySide = 0;
2070   }
2071   vector< TSideFace* >         sideFaces( NB_WALL_FACES, 0 );
2072   vector< pair< double, double> > params( NB_WALL_FACES );
2073   mySide = new TSideFace( sideFaces, params );
2074
2075   myHelper = helper;
2076   SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2077
2078   SMESH_Block::init();
2079   myShapeIDMap.Clear();
2080   myShapeIndex2ColumnMap.clear();
2081   
2082   int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
2083     SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
2084     SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
2085   };
2086
2087   myError = SMESH_ComputeError::New();
2088
2089   myNotQuadOnTop = thePrism.myNotQuadOnTop;
2090
2091   // Find columns of wall nodes and calculate edges' lengths
2092   // --------------------------------------------------------
2093
2094   myParam2ColumnMaps.clear();
2095   myParam2ColumnMaps.resize( thePrism.myBottomEdges.size() ); // total nb edges
2096
2097   size_t iE, nbEdges = thePrism.myNbEdgesInWires.front(); // nb outer edges
2098   vector< double >    edgeLength( nbEdges );
2099   multimap< double, int > len2edgeMap;
2100
2101   list< TopoDS_Edge >::const_iterator edgeIt = thePrism.myBottomEdges.begin();
2102   for ( iE = 0; iE < nbEdges; ++iE, ++edgeIt )
2103   {
2104     TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
2105
2106     Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
2107     for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
2108     {
2109       const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ]->Edge( 0 );
2110       if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
2111         return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
2112                      << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
2113     }
2114     SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
2115     SHOWYXZ("p2 F "   <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
2116     SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
2117
2118     edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
2119
2120     if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
2121     {
2122       SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
2123       if ( !smDS )
2124         return error(COMPERR_BAD_INPUT_MESH, TCom("Null submesh on the edge #")
2125                      << MeshDS()->ShapeToIndex( *edgeIt ));
2126       len2edgeMap.insert( make_pair( edgeLength[ iE ], iE ));
2127     }
2128   }
2129   // Load columns of internal edges (forming holes)
2130   // and fill map ShapeIndex to TParam2ColumnMap for them
2131   for ( ; edgeIt != thePrism.myBottomEdges.end() ; ++edgeIt, ++iE )
2132   {
2133     TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
2134
2135     Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iE ].begin();
2136     for ( ; quad != thePrism.myWallQuads[ iE ].end(); ++quad )
2137     {
2138       const TopoDS_Edge& quadBot = (*quad)->side[ QUAD_BOTTOM_SIDE ]->Edge( 0 );
2139       if ( !myHelper->LoadNodeColumns( faceColumns, (*quad)->face, quadBot, meshDS ))
2140         return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
2141                      << "on a side face #" << MeshDS()->ShapeToIndex( (*quad)->face ));
2142     }
2143     // edge columns
2144     int id = MeshDS()->ShapeToIndex( *edgeIt );
2145     bool isForward = true; // meaningless for intenal wires
2146     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
2147     // columns for vertices
2148     // 1
2149     const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
2150     id = n0->getshapeId();
2151     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
2152     // 2
2153     const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
2154     id = n1->getshapeId();
2155     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
2156
2157     // SHOWYXZ("\np1 F " <<iE, gpXYZ(faceColumns.begin()->second.front() ));
2158     // SHOWYXZ("p2 F "   <<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
2159     // SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
2160   }
2161
2162   // Create 4 wall faces of a block
2163   // -------------------------------
2164
2165   if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
2166   {
2167     map< int, int > iE2nbSplit;
2168     if ( nbEdges != NB_WALL_FACES ) // define how to split
2169     {
2170       if ( len2edgeMap.size() != nbEdges )
2171         RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
2172       map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
2173       map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
2174       double maxLen = maxLen_i->first;
2175       double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
2176       switch ( nbEdges ) {
2177       case 1: // 0-th edge is split into 4 parts
2178         iE2nbSplit.insert( make_pair( 0, 4 )); break;
2179       case 2: // either the longest edge is split into 3 parts, or both edges into halves
2180         if ( maxLen / 3 > midLen / 2 ) {
2181           iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
2182         }
2183         else {
2184           iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
2185           iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
2186         }
2187         break;
2188       case 3:
2189         // split longest into halves
2190         iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
2191       }
2192     }
2193     // Create TSideFace's
2194     int iSide = 0;
2195     list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
2196     for ( iE = 0; iE < nbEdges; ++iE, ++botE )
2197     {
2198       TFaceQuadStructPtr quad = thePrism.myWallQuads[ iE ].front();
2199       // split?
2200       map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
2201       if ( i_nb != iE2nbSplit.end() ) {
2202         // split!
2203         int nbSplit = i_nb->second;
2204         vector< double > params;
2205         splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
2206         const bool isForward =
2207           StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
2208                                                   myParam2ColumnMaps[iE],
2209                                                   *botE, SMESH_Block::ID_Fx0z );
2210         for ( int i = 0; i < nbSplit; ++i ) {
2211           double f = ( isForward ? params[ i ]   : params[ nbSplit - i-1 ]);
2212           double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
2213           TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
2214                                            thePrism.myWallQuads[ iE ], *botE,
2215                                            &myParam2ColumnMaps[ iE ], f, l );
2216           mySide->SetComponent( iSide++, comp );
2217         }
2218       }
2219       else {
2220         TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
2221                                          thePrism.myWallQuads[ iE ], *botE,
2222                                          &myParam2ColumnMaps[ iE ]);
2223         mySide->SetComponent( iSide++, comp );
2224       }
2225     }
2226   }
2227   else { // **************************** Unite faces
2228
2229     // unite first faces
2230     int nbExraFaces = nbEdges - 3;
2231     int iSide = 0, iE;
2232     double u0 = 0, sumLen = 0;
2233     for ( iE = 0; iE < nbExraFaces; ++iE )
2234       sumLen += edgeLength[ iE ];
2235
2236     vector< TSideFace* >        components( nbExraFaces );
2237     vector< pair< double, double> > params( nbExraFaces );
2238     list< TopoDS_Edge >::const_iterator botE = thePrism.myBottomEdges.begin();
2239     for ( iE = 0; iE < nbExraFaces; ++iE, ++botE )
2240     {
2241       components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
2242                                         thePrism.myWallQuads[ iE ], *botE,
2243                                         &myParam2ColumnMaps[ iE ]);
2244       double u1 = u0 + edgeLength[ iE ] / sumLen;
2245       params[ iE ] = make_pair( u0 , u1 );
2246       u0 = u1;
2247     }
2248     mySide->SetComponent( iSide++, new TSideFace( components, params ));
2249
2250     // fill the rest faces
2251     for ( ; iE < nbEdges; ++iE, ++botE )
2252     {
2253       TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
2254                                        thePrism.myWallQuads[ iE ], *botE,
2255                                        &myParam2ColumnMaps[ iE ]);
2256       mySide->SetComponent( iSide++, comp );
2257     }
2258   }
2259
2260
2261   // Fill geometry fields of SMESH_Block
2262   // ------------------------------------
2263
2264   vector< int > botEdgeIdVec;
2265   SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
2266
2267   bool isForward[NB_WALL_FACES] = { true, true, true, true };
2268   Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
2269   Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
2270
2271   for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
2272   {
2273     TSideFace * sideFace = mySide->GetComponent( iF );
2274     if ( !sideFace )
2275       RETURN_BAD_RESULT("NULL TSideFace");
2276     int fID = sideFace->FaceID(); // in-block ID
2277
2278     // fill myShapeIDMap
2279     if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
2280          !sideFace->IsComplex())
2281       MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
2282
2283     // side faces geometry
2284     Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
2285     if ( !sideFace->GetPCurves( pcurves ))
2286       RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
2287
2288     SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
2289     tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
2290
2291     SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
2292     // edges 3D geometry
2293     vector< int > edgeIdVec;
2294     SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
2295     for ( int isMax = 0; isMax < 2; ++isMax ) {
2296       {
2297         int eID = edgeIdVec[ isMax ];
2298         SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
2299         tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
2300         SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
2301         SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
2302       }
2303       {
2304         int eID = edgeIdVec[ isMax+2 ];
2305         SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE  ];
2306         tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
2307         SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
2308         SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
2309
2310         // corner points
2311         vector< int > vertexIdVec;
2312         SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
2313         myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
2314         myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
2315       }
2316     }
2317     // pcurves on horizontal faces
2318     for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
2319       if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
2320         botPcurves[ iE ] = sideFace->HorizPCurve( false, thePrism.myBottom );
2321         topPcurves[ iE ] = sideFace->HorizPCurve( true,  thePrism.myTop );
2322         break;
2323       }
2324     }
2325     //sideFace->dumpNodes( 4 ); // debug
2326   }
2327   // horizontal faces geometry
2328   {
2329     SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
2330     tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( thePrism.myBottom ), botPcurves, isForward );
2331     SMESH_Block::Insert( thePrism.myBottom, ID_BOT_FACE, myShapeIDMap );
2332   }
2333   {
2334     SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
2335     tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( thePrism.myTop ), topPcurves, isForward );
2336     SMESH_Block::Insert( thePrism.myTop, ID_TOP_FACE, myShapeIDMap );
2337   }
2338
2339   // Fill map ShapeIndex to TParam2ColumnMap
2340   // ----------------------------------------
2341
2342   list< TSideFace* > fList;
2343   list< TSideFace* >::iterator fListIt;
2344   fList.push_back( mySide );
2345   for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
2346   {
2347     int nb = (*fListIt)->NbComponents();
2348     for ( int i = 0; i < nb; ++i ) {
2349       if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
2350         fList.push_back( comp );
2351     }
2352     if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
2353       // columns for a base edge
2354       int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
2355       bool isForward = (*fListIt)->IsForward();
2356       myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
2357
2358       // columns for vertices
2359       const SMDS_MeshNode* n0 = cols->begin()->second.front();
2360       id = n0->getshapeId();
2361       myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
2362
2363       const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
2364       id = n1->getshapeId();
2365       myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
2366     }
2367   }
2368
2369 //   gp_XYZ testPar(0.25, 0.25, 0), testCoord;
2370 //   if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
2371 //     RETURN_BAD_RESULT("TEST FacePoint() FAILED");
2372 //   SHOWYXZ("IN TEST PARAM" , testPar);
2373 //   SHOWYXZ("OUT TEST CORD" , testCoord);
2374 //   if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
2375 //     RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
2376 //   SHOWYXZ("OUT TEST PARAM" , testPar);
2377
2378   return true;
2379 }
2380
2381 //================================================================================
2382 /*!
2383  * \brief Return pointer to column of nodes
2384  * \param node - bottom node from which the returned column goes up
2385  * \retval const TNodeColumn* - the found column
2386  */
2387 //================================================================================
2388
2389 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
2390 {
2391   int sID = node->getshapeId();
2392
2393   map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
2394     myShapeIndex2ColumnMap.find( sID );
2395   if ( col_frw != myShapeIndex2ColumnMap.end() ) {
2396     const TParam2ColumnMap* cols = col_frw->second.first;
2397     TParam2ColumnIt u_col = cols->begin();
2398     for ( ; u_col != cols->end(); ++u_col )
2399       if ( u_col->second[ 0 ] == node )
2400         return & u_col->second;
2401   }
2402   return 0;
2403 }
2404
2405 //=======================================================================
2406 //function : GetLayersTransformation
2407 //purpose  : Return transformations to get coordinates of nodes of each layer
2408 //           by nodes of the bottom. Layer is a set of nodes at a certain step
2409 //           from bottom to top.
2410 //=======================================================================
2411
2412 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> &           trsf,
2413                                                       const Prism_3D::TPrismTopo& prism) const
2414 {
2415   const int zSize = VerticalSize();
2416   if ( zSize < 3 ) return true;
2417   trsf.resize( zSize - 2 );
2418
2419   // Select some node columns by which we will define coordinate system of layers
2420
2421   vector< const TNodeColumn* > columns;
2422   {
2423     bool isReverse;
2424     list< TopoDS_Edge >::const_iterator edgeIt = prism.myBottomEdges.begin();
2425     for ( int iE = 0; iE < prism.myNbEdgesInWires.front(); ++iE, ++edgeIt )
2426     {
2427       if ( BRep_Tool::Degenerated( *edgeIt )) continue;
2428       const TParam2ColumnMap* u2colMap =
2429         GetParam2ColumnMap( MeshDS()->ShapeToIndex( *edgeIt ), isReverse );
2430       if ( !u2colMap ) return false;
2431       double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
2432       //isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
2433       //if ( isReverse ) swap ( f, l ); -- u2colMap takes orientation into account
2434       const int nbCol = 5;
2435       for ( int i = 0; i < nbCol; ++i )
2436       {
2437         double u = f + i/double(nbCol) * ( l - f );
2438         const TNodeColumn* col = & getColumn( u2colMap, u )->second;
2439         if ( columns.empty() || col != columns.back() )
2440           columns.push_back( col );
2441       }
2442     }
2443   }
2444
2445   // Find tolerance to check transformations
2446
2447   double tol2;
2448   {
2449     Bnd_B3d bndBox;
2450     for ( int i = 0; i < columns.size(); ++i )
2451       bndBox.Add( gpXYZ( columns[i]->front() ));
2452     tol2 = bndBox.SquareExtent() * 1e-5;
2453   }
2454
2455   // Compute transformations
2456
2457   int xCol = -1;
2458   gp_Trsf fromCsZ, toCs0;
2459   gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
2460   //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
2461   toCs0.SetTransformation( cs0 );
2462   for ( int z = 1; z < zSize-1; ++z )
2463   {
2464     gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
2465     //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
2466     fromCsZ.SetTransformation( csZ );
2467     fromCsZ.Invert();
2468     gp_Trsf& t = trsf[ z-1 ];
2469     t = fromCsZ * toCs0;
2470     //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
2471
2472     // check a transformation
2473     for ( int i = 0; i < columns.size(); ++i )
2474     {
2475       gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
2476       gp_Pnt pz = gpXYZ( (*columns[i])[z] );
2477       t.Transforms( p0.ChangeCoord() );
2478       if ( p0.SquareDistance( pz ) > tol2 )
2479         return false;
2480     }
2481   }
2482   return true;
2483 }
2484
2485 //================================================================================
2486 /*!
2487  * \brief Check curve orientation of a bootom edge
2488   * \param meshDS - mesh DS
2489   * \param columnsMap - node columns map of side face
2490   * \param bottomEdge - the bootom edge
2491   * \param sideFaceID - side face in-block ID
2492   * \retval bool - true if orientation coinside with in-block forward orientation
2493  */
2494 //================================================================================
2495
2496 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh*           meshDS,
2497                                             const TParam2ColumnMap& columnsMap,
2498                                             const TopoDS_Edge &     bottomEdge,
2499                                             const int               sideFaceID)
2500 {
2501   bool isForward = false;
2502   if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
2503   {
2504     isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
2505   }
2506   else
2507   {
2508     const TNodeColumn&     firstCol = columnsMap.begin()->second;
2509     const SMDS_MeshNode* bottomNode = firstCol[0];
2510     TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
2511     isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
2512   }
2513   // on 2 of 4 sides first vertex is end
2514   if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
2515     isForward = !isForward;
2516   return isForward;
2517 }
2518
2519 //================================================================================
2520 /*!
2521  * \brief Constructor
2522   * \param faceID - in-block ID
2523   * \param face - geom FACE
2524   * \param baseEdge - EDGE proreply oriented in the bottom EDGE !!!
2525   * \param columnsMap - map of node columns
2526   * \param first - first normalized param
2527   * \param last - last normalized param
2528  */
2529 //================================================================================
2530
2531 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper*        helper,
2532                                               const int                  faceID,
2533                                               const Prism_3D::TQuadList& quadList,
2534                                               const TopoDS_Edge&         baseEdge,
2535                                               TParam2ColumnMap*          columnsMap,
2536                                               const double               first,
2537                                               const double               last):
2538   myID( faceID ),
2539   myParamToColumnMap( columnsMap ),
2540   myHelper( helper )
2541 {
2542   myParams.resize( 1 );
2543   myParams[ 0 ] = make_pair( first, last );
2544   mySurface     = PSurface( new BRepAdaptor_Surface( quadList.front()->face ));
2545   myBaseEdge    = baseEdge;
2546   myIsForward   = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
2547                                                           *myParamToColumnMap,
2548                                                           myBaseEdge, myID );
2549   if ( quadList.size() > 1 ) // side is vertically composite
2550   {
2551     // fill myShapeID2Surf map to enable finding a right surface by any sub-shape ID
2552
2553     SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2554
2555     TopTools_IndexedDataMapOfShapeListOfShape subToFaces;
2556     Prism_3D::TQuadList::const_iterator quad = quadList.begin();
2557     for ( ; quad != quadList.end(); ++quad )
2558     {
2559       const TopoDS_Face& face = (*quad)->face;
2560       TopExp::MapShapesAndAncestors( face, TopAbs_VERTEX, TopAbs_FACE, subToFaces );
2561       TopExp::MapShapesAndAncestors( face, TopAbs_EDGE,   TopAbs_FACE, subToFaces );
2562       myShapeID2Surf.insert( make_pair( meshDS->ShapeToIndex( face ),
2563                                         PSurface( new BRepAdaptor_Surface( face ))));
2564     }
2565     for ( int i = 1; i <= subToFaces.Extent(); ++i )
2566     {
2567       const TopoDS_Shape&     sub = subToFaces.FindKey( i );
2568       TopTools_ListOfShape& faces = subToFaces( i );
2569       int subID  = meshDS->ShapeToIndex( sub );
2570       int faceID = meshDS->ShapeToIndex( faces.First() );
2571       myShapeID2Surf.insert ( make_pair( subID, myShapeID2Surf[ faceID ]));
2572     }
2573   }
2574 }
2575
2576 //================================================================================
2577 /*!
2578  * \brief Constructor of complex side face
2579  */
2580 //================================================================================
2581
2582 StdMeshers_PrismAsBlock::TSideFace::
2583 TSideFace(const vector< TSideFace* >&             components,
2584           const vector< pair< double, double> > & params)
2585   :myID( components[0] ? components[0]->myID : 0 ),
2586    myParamToColumnMap( 0 ),
2587    myParams( params ),
2588    myIsForward( true ),
2589    myComponents( components ),
2590    myHelper( components[0] ? components[0]->myHelper : 0 )
2591 {}
2592 //================================================================================
2593 /*!
2594  * \brief Copy constructor
2595   * \param other - other side
2596  */
2597 //================================================================================
2598
2599 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
2600 {
2601   myID               = other.myID;
2602   mySurface          = other.mySurface;
2603   myBaseEdge         = other.myBaseEdge;
2604   myParams           = other.myParams;
2605   myIsForward        = other.myIsForward;
2606   myHelper           = other.myHelper;
2607   myParamToColumnMap = other.myParamToColumnMap;
2608
2609   myComponents.resize( other.myComponents.size());
2610   for (int i = 0 ; i < myComponents.size(); ++i )
2611     myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
2612 }
2613
2614 //================================================================================
2615 /*!
2616  * \brief Deletes myComponents
2617  */
2618 //================================================================================
2619
2620 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
2621 {
2622   for (int i = 0 ; i < myComponents.size(); ++i )
2623     if ( myComponents[ i ] )
2624       delete myComponents[ i ];
2625 }
2626
2627 //================================================================================
2628 /*!
2629  * \brief Return geometry of the vertical curve
2630   * \param isMax - true means curve located closer to (1,1,1) block point
2631   * \retval Adaptor3d_Curve* - curve adaptor
2632  */
2633 //================================================================================
2634
2635 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
2636 {
2637   if ( !myComponents.empty() ) {
2638     if ( isMax )
2639       return myComponents.back()->VertiCurve(isMax);
2640     else
2641       return myComponents.front()->VertiCurve(isMax);
2642   }
2643   double f = myParams[0].first, l = myParams[0].second;
2644   if ( !myIsForward ) std::swap( f, l );
2645   return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
2646 }
2647
2648 //================================================================================
2649 /*!
2650  * \brief Return geometry of the top or bottom curve
2651   * \param isTop - 
2652   * \retval Adaptor3d_Curve* - 
2653  */
2654 //================================================================================
2655
2656 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
2657 {
2658   return new THorizontalEdgeAdaptor( this, isTop );
2659 }
2660
2661 //================================================================================
2662 /*!
2663  * \brief Return pcurves
2664   * \param pcurv - array of 4 pcurves
2665   * \retval bool - is a success
2666  */
2667 //================================================================================
2668
2669 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
2670 {
2671   int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
2672
2673   for ( int i = 0 ; i < 4 ; ++i ) {
2674     Handle(Geom2d_Line) line;
2675     switch ( iEdge[ i ] ) {
2676     case TOP_EDGE:
2677       line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
2678     case BOTTOM_EDGE:
2679       line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
2680     case V0_EDGE:
2681       line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
2682     case V1_EDGE:
2683       line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
2684     }
2685     pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
2686   }
2687   return true;
2688 }
2689
2690 //================================================================================
2691 /*!
2692  * \brief Returns geometry of pcurve on a horizontal face
2693   * \param isTop - is top or bottom face
2694   * \param horFace - a horizontal face
2695   * \retval Adaptor2d_Curve2d* - curve adaptor
2696  */
2697 //================================================================================
2698
2699 Adaptor2d_Curve2d*
2700 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool         isTop,
2701                                                 const TopoDS_Face& horFace) const
2702 {
2703   return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
2704 }
2705
2706 //================================================================================
2707 /*!
2708  * \brief Return a component corresponding to parameter
2709   * \param U - parameter along a horizontal size
2710   * \param localU - parameter along a horizontal size of a component
2711   * \retval TSideFace* - found component
2712  */
2713 //================================================================================
2714
2715 StdMeshers_PrismAsBlock::TSideFace*
2716 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
2717 {
2718   localU = U;
2719   if ( myComponents.empty() )
2720     return const_cast<TSideFace*>( this );
2721
2722   int i;
2723   for ( i = 0; i < myComponents.size(); ++i )
2724     if ( U < myParams[ i ].second )
2725       break;
2726   if ( i >= myComponents.size() )
2727     i = myComponents.size() - 1;
2728
2729   double f = myParams[ i ].first, l = myParams[ i ].second;
2730   localU = ( U - f ) / ( l - f );
2731   return myComponents[ i ];
2732 }
2733
2734 //================================================================================
2735 /*!
2736  * \brief Find node columns for a parameter
2737   * \param U - parameter along a horizontal edge
2738   * \param col1 - the 1st found column
2739   * \param col2 - the 2nd found column
2740   * \retval r - normalized position of U between the found columns
2741  */
2742 //================================================================================
2743
2744 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double      U,
2745                                                       TParam2ColumnIt & col1,
2746                                                       TParam2ColumnIt & col2) const
2747 {
2748   double u = U, r = 0;
2749   if ( !myComponents.empty() ) {
2750     TSideFace * comp = GetComponent(U,u);
2751     return comp->GetColumns( u, col1, col2 );
2752   }
2753
2754   if ( !myIsForward )
2755     u = 1 - u;
2756   double f = myParams[0].first, l = myParams[0].second;
2757   u = f + u * ( l - f );
2758
2759   col1 = col2 = getColumn( myParamToColumnMap, u );
2760   if ( ++col2 == myParamToColumnMap->end() ) {
2761     --col2;
2762     r = 0.5;
2763   }
2764   else {
2765     double uf = col1->first;
2766     double ul = col2->first;
2767     r = ( u - uf ) / ( ul - uf );
2768   }
2769   return r;
2770 }
2771
2772 //================================================================================
2773 /*!
2774  * \brief Return coordinates by normalized params
2775   * \param U - horizontal param
2776   * \param V - vertical param
2777   * \retval gp_Pnt - result point
2778  */
2779 //================================================================================
2780
2781 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
2782                                                  const Standard_Real V) const
2783 {
2784   if ( !myComponents.empty() ) {
2785     double u;
2786     TSideFace * comp = GetComponent(U,u);
2787     return comp->Value( u, V );
2788   }
2789
2790   TParam2ColumnIt u_col1, u_col2;
2791   double vR, hR = GetColumns( U, u_col1, u_col2 );
2792
2793   const SMDS_MeshNode* nn[4];
2794
2795   // BEGIN issue 0020680: Bad cell created by Radial prism in center of torus
2796   // Workaround for a wrongly located point returned by mySurface.Value() for
2797   // UV located near boundary of BSpline surface.
2798   // To bypass the problem, we take point from 3D curve of EDGE.
2799   // It solves pb of the bloc_fiss_new.py
2800   const double tol = 1e-3;
2801   if ( V < tol || V+tol >= 1. )
2802   {
2803     nn[0] = V < tol ? u_col1->second.front() : u_col1->second.back();
2804     nn[2] = V < tol ? u_col2->second.front() : u_col2->second.back();
2805     TopoDS_Edge edge;
2806     if ( V < tol )
2807     {
2808       edge = myBaseEdge;
2809     }
2810     else
2811     {
2812       TopoDS_Shape s = myHelper->GetSubShapeByNode( nn[0], myHelper->GetMeshDS() );
2813       if ( s.ShapeType() != TopAbs_EDGE )
2814         s = myHelper->GetSubShapeByNode( nn[2], myHelper->GetMeshDS() );
2815       if ( s.ShapeType() == TopAbs_EDGE )
2816         edge = TopoDS::Edge( s );
2817     }
2818     if ( !edge.IsNull() )
2819     {
2820       double u1 = myHelper->GetNodeU( edge, nn[0] );
2821       double u3 = myHelper->GetNodeU( edge, nn[2] );
2822       double u = u1 * ( 1 - hR ) + u3 * hR;
2823       TopLoc_Location loc; double f,l;
2824       Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
2825       return curve->Value( u ).Transformed( loc );
2826     }
2827   }
2828   // END issue 0020680: Bad cell created by Radial prism in center of torus
2829
2830   vR = getRAndNodes( & u_col1->second, V, nn[0], nn[1] );
2831   vR = getRAndNodes( & u_col2->second, V, nn[2], nn[3] );
2832
2833   if ( !myShapeID2Surf.empty() ) // side is vertically composite
2834   {
2835     // find a FACE on which the 4 nodes lie
2836     TSideFace* me = (TSideFace*) this;
2837     int notFaceID1 = 0, notFaceID2 = 0;
2838     for ( int i = 0; i < 4; ++i )
2839       if ( nn[i]->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) // node on FACE
2840       {
2841         me->mySurface = me->myShapeID2Surf[ nn[i]->getshapeId() ];
2842         notFaceID2 = 0;
2843         break;
2844       }
2845       else if ( notFaceID1 == 0 ) // node on EDGE or VERTEX
2846       {
2847         me->mySurface  = me->myShapeID2Surf[ nn[i]->getshapeId() ];
2848         notFaceID1 = nn[i]->getshapeId();
2849       }
2850       else if ( notFaceID1 != nn[i]->getshapeId() ) // node on other EDGE or VERTEX
2851       {
2852         if ( mySurface != me->myShapeID2Surf[ nn[i]->getshapeId() ])
2853           notFaceID2 = nn[i]->getshapeId();
2854       }
2855     if ( notFaceID2 ) // no nodes of FACE and nodes are on different FACEs
2856     {
2857       SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
2858       TopoDS_Shape face = myHelper->GetCommonAncestor( meshDS->IndexToShape( notFaceID1 ),
2859                                                        meshDS->IndexToShape( notFaceID2 ),
2860                                                        *myHelper->GetMesh(),
2861                                                        TopAbs_FACE );
2862       if ( face.IsNull() ) 
2863         throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() face.IsNull()");
2864       int faceID = meshDS->ShapeToIndex( face );
2865       me->mySurface = me->myShapeID2Surf[ faceID ];
2866       if ( !mySurface )
2867         throw SALOME_Exception("StdMeshers_PrismAsBlock::TSideFace::Value() !mySurface");
2868     }
2869   }
2870   
2871   gp_XY uv1 = myHelper->GetNodeUV( mySurface->Face(), nn[0], nn[2]);
2872   gp_XY uv2 = myHelper->GetNodeUV( mySurface->Face(), nn[1], nn[3]);
2873   gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
2874
2875   gp_XY uv3 = myHelper->GetNodeUV( mySurface->Face(), nn[2], nn[0]);
2876   gp_XY uv4 = myHelper->GetNodeUV( mySurface->Face(), nn[3], nn[1]);
2877   gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
2878
2879   gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
2880
2881   gp_Pnt p = mySurface->Value( uv.X(), uv.Y() );
2882   return p;
2883 }
2884
2885
2886 //================================================================================
2887 /*!
2888  * \brief Return boundary edge
2889   * \param edge - edge index
2890   * \retval TopoDS_Edge - found edge
2891  */
2892 //================================================================================
2893
2894 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
2895 {
2896   if ( !myComponents.empty() ) {
2897     switch ( iEdge ) {
2898     case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
2899     case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
2900     default: return TopoDS_Edge();
2901     }
2902   }
2903   TopoDS_Shape edge;
2904   const SMDS_MeshNode* node = 0;
2905   SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
2906   TNodeColumn* column;
2907
2908   switch ( iEdge ) {
2909   case TOP_EDGE:
2910   case BOTTOM_EDGE:
2911     column = & (( ++myParamToColumnMap->begin())->second );
2912     node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
2913     edge = myHelper->GetSubShapeByNode ( node, meshDS );
2914     if ( edge.ShapeType() == TopAbs_VERTEX ) {
2915       column = & ( myParamToColumnMap->begin()->second );
2916       node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
2917     }
2918     break;
2919   case V0_EDGE:
2920   case V1_EDGE: {
2921     bool back = ( iEdge == V1_EDGE );
2922     if ( !myIsForward ) back = !back;
2923     if ( back )
2924       column = & ( myParamToColumnMap->rbegin()->second );
2925     else
2926       column = & ( myParamToColumnMap->begin()->second );
2927     if ( column->size() > 0 )
2928       edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
2929     if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
2930       node = column->front();
2931     break;
2932   }
2933   default:;
2934   }
2935   if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
2936     return TopoDS::Edge( edge );
2937
2938   // find edge by 2 vertices
2939   TopoDS_Shape V1 = edge;
2940   TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
2941   if ( !V2.IsNull() && V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
2942   {
2943     TopoDS_Shape ancestor = myHelper->GetCommonAncestor( V1, V2, *myHelper->GetMesh(), TopAbs_EDGE);
2944     if ( !ancestor.IsNull() )
2945       return TopoDS::Edge( ancestor );
2946   }
2947   return TopoDS_Edge();
2948 }
2949
2950 //================================================================================
2951 /*!
2952  * \brief Fill block sub-shapes
2953   * \param shapeMap - map to fill in
2954   * \retval int - nb inserted sub-shapes
2955  */
2956 //================================================================================
2957
2958 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
2959 {
2960   int nbInserted = 0;
2961
2962   // Insert edges
2963   vector< int > edgeIdVec;
2964   SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
2965
2966   for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
2967     TopoDS_Edge e = GetEdge( i );
2968     if ( !e.IsNull() ) {
2969       nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
2970     }
2971   }
2972
2973   // Insert corner vertices
2974
2975   TParam2ColumnIt col1, col2 ;
2976   vector< int > vertIdVec;
2977
2978   // from V0 column
2979   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
2980   GetColumns(0, col1, col2 );
2981   const SMDS_MeshNode* node0 = col1->second.front();
2982   const SMDS_MeshNode* node1 = col1->second.back();
2983   TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
2984   TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
2985   if ( v0.ShapeType() == TopAbs_VERTEX ) {
2986     nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
2987   }
2988   if ( v1.ShapeType() == TopAbs_VERTEX ) {
2989     nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
2990   }
2991   
2992   // from V1 column
2993   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
2994   GetColumns(1, col1, col2 );
2995   node0 = col2->second.front();
2996   node1 = col2->second.back();
2997   v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
2998   v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
2999   if ( v0.ShapeType() == TopAbs_VERTEX ) {
3000     nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
3001   }
3002   if ( v1.ShapeType() == TopAbs_VERTEX ) {
3003     nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
3004   }
3005
3006 //   TopoDS_Vertex V0, V1, Vcom;
3007 //   TopExp::Vertices( myBaseEdge, V0, V1, true );
3008 //   if ( !myIsForward ) std::swap( V0, V1 );
3009
3010 //   // bottom vertex IDs
3011 //   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
3012 //   SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
3013 //   SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
3014
3015 //   TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
3016 //   if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
3017 //     return false;
3018
3019 //   // insert one side edge
3020 //   int edgeID;
3021 //   if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
3022 //   else                    edgeID = edgeIdVec[ _v1 ];
3023 //   SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
3024
3025 //   // top vertex of the side edge
3026 //   SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
3027 //   TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
3028 //   if ( Vcom.IsSame( Vtop ))
3029 //     Vtop = TopExp::LastVertex( sideEdge );
3030 //   SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
3031
3032 //   // other side edge
3033 //   sideEdge = GetEdge( V1_EDGE );
3034 //   if ( sideEdge.IsNull() )
3035 //     return false;
3036 //   if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
3037 //   else                            edgeID = edgeIdVec[ _v1 ];
3038 //   SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
3039   
3040 //   // top edge
3041 //   TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
3042 //   SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
3043
3044 //   // top vertex of the other side edge
3045 //   if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
3046 //     return false;
3047 //   SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
3048 //   SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
3049
3050   return nbInserted;
3051 }
3052
3053 //================================================================================
3054 /*!
3055  * \brief Dump ids of nodes of sides
3056  */
3057 //================================================================================
3058
3059 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
3060 {
3061 #ifdef _DEBUG_
3062   cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
3063   THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
3064   cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
3065   THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
3066   cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
3067   TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
3068   cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
3069   TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
3070   cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
3071   delete hSize0; delete hSize1; delete vSide0; delete vSide1;
3072 #endif
3073 }
3074
3075 //================================================================================
3076 /*!
3077  * \brief Creates TVerticalEdgeAdaptor 
3078   * \param columnsMap - node column map
3079   * \param parameter - normalized parameter
3080  */
3081 //================================================================================
3082
3083 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
3084 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
3085 {
3086   myNodeColumn = & getColumn( columnsMap, parameter )->second;
3087 }
3088
3089 //================================================================================
3090 /*!
3091  * \brief Return coordinates for the given normalized parameter
3092   * \param U - normalized parameter
3093   * \retval gp_Pnt - coordinates
3094  */
3095 //================================================================================
3096
3097 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
3098 {
3099   const SMDS_MeshNode* n1;
3100   const SMDS_MeshNode* n2;
3101   double r = getRAndNodes( myNodeColumn, U, n1, n2 );
3102   return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
3103 }
3104
3105 //================================================================================
3106 /*!
3107  * \brief Dump ids of nodes
3108  */
3109 //================================================================================
3110
3111 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
3112 {
3113 #ifdef _DEBUG_
3114   for ( int i = 0; i < nbNodes && i < myNodeColumn->size(); ++i )
3115     cout << (*myNodeColumn)[i]->GetID() << " ";
3116   if ( nbNodes < myNodeColumn->size() )
3117     cout << myNodeColumn->back()->GetID();
3118 #endif
3119 }
3120
3121 //================================================================================
3122 /*!
3123  * \brief Return coordinates for the given normalized parameter
3124   * \param U - normalized parameter
3125   * \retval gp_Pnt - coordinates
3126  */
3127 //================================================================================
3128
3129 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
3130 {
3131   return mySide->TSideFace::Value( U, myV );
3132 }
3133
3134 //================================================================================
3135 /*!
3136  * \brief Dump ids of <nbNodes> first nodes and the last one
3137  */
3138 //================================================================================
3139
3140 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
3141 {
3142 #ifdef _DEBUG_
3143   // Not bedugged code. Last node is sometimes incorrect
3144   const TSideFace* side = mySide;
3145   double u = 0;
3146   if ( mySide->IsComplex() )
3147     side = mySide->GetComponent(0,u);
3148
3149   TParam2ColumnIt col, col2;
3150   TParam2ColumnMap* u2cols = side->GetColumns();
3151   side->GetColumns( u , col, col2 );
3152   
3153   int j, i = myV ? mySide->ColumnHeight()-1 : 0;
3154
3155   const SMDS_MeshNode* n = 0;
3156   const SMDS_MeshNode* lastN
3157     = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
3158   for ( j = 0; j < nbNodes && n != lastN; ++j )
3159   {
3160     n = col->second[ i ];
3161     cout << n->GetID() << " ";
3162     if ( side->IsForward() )
3163       ++col;
3164     else
3165       --col;
3166   }
3167
3168   // last node
3169   u = 1;
3170   if ( mySide->IsComplex() )
3171     side = mySide->GetComponent(1,u);
3172
3173   side->GetColumns( u , col, col2 );
3174   if ( n != col->second[ i ] )
3175     cout << col->second[ i ]->GetID();
3176 #endif
3177 }
3178 //================================================================================
3179 /*!
3180  * \brief Return UV on pcurve for the given normalized parameter
3181   * \param U - normalized parameter
3182   * \retval gp_Pnt - coordinates
3183  */
3184 //================================================================================
3185
3186 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
3187 {
3188   TParam2ColumnIt u_col1, u_col2;
3189   double r = mySide->GetColumns( U, u_col1, u_col2 );
3190   gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
3191   gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
3192   return uv1 * ( 1 - r ) + uv2 * r;
3193 }