Salome HOME
PAL13473 (Build repetitive mesh):
[modules/smesh.git] / src / StdMeshers / StdMeshers_Prism_3D.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  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 //
24 // File      : StdMeshers_Prism_3D.cxx
25 // Module    : SMESH
26 // Created   : Fri Oct 20 11:37:07 2006
27 // Author    : Edward AGAPOV (eap)
28
29
30 #include "StdMeshers_Prism_3D.hxx"
31
32 #include "StdMeshers_ProjectionUtils.hxx"
33 #include "SMESH_MeshEditor.hxx"
34 #include "SMDS_VolumeTool.hxx"
35 #include "SMDS_VolumeOfNodes.hxx"
36 #include "SMDS_EdgePosition.hxx"
37
38 #include "utilities.h"
39
40 #include <BRepAdaptor_Curve.hxx>
41 #include <BRepAdaptor_Curve2d.hxx>
42 #include <BRep_Builder.hxx>
43 #include <BRep_Tool.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
45 #include <Geom2d_Line.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
47
48 using namespace std;
49
50 #define RETURN_BAD_RESULT(msg) { MESSAGE(msg); return false; }
51 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
52 #define SHOWYXZ(msg, xyz) // {\
53 // gp_Pnt p (xyz); \
54 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl;\
55 // }
56
57 typedef StdMeshers_ProjectionUtils TAssocTool;
58
59 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
60        ID_TOP_FACE = SMESH_Block::ID_Fxy1,
61        BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
62        NB_WALL_FACES = 4 }; //
63
64 namespace {
65
66   //================================================================================
67   /*!
68    * \brief Return iterator pointing to node column for the given parameter
69    * \param columnsMap - node column map
70    * \param parameter - parameter
71    * \retval TParam2ColumnMap::iterator - result
72    *
73    * it returns closest left column
74    */
75   //================================================================================
76
77   TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
78                              const double            parameter )
79   {
80     TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
81     if ( u_col != columnsMap->begin() )
82       --u_col;
83     return u_col; // return left column
84   }
85
86   //================================================================================
87   /*!
88    * \brief Return nodes around given parameter and a ratio
89    * \param column - node column
90    * \param param - parameter
91    * \param node1 - lower node
92    * \param node2 - upper node
93    * \retval double - ratio
94    */
95   //================================================================================
96
97   double getRAndNodes( const TNodeColumn*     column,
98                        const double           param,
99                        const SMDS_MeshNode* & node1,
100                        const SMDS_MeshNode* & node2)
101   {
102     if ( param == 1.0 || column->size() == 1) {
103       node1 = node2 = column->back();
104       return 0;
105     }
106
107     int i = int( param * ( column->size() - 1 ));
108     double u0 = double( i )/ double( column->size() - 1 );
109     double r = ( param - u0 ) * ( column->size() - 1 );
110
111     node1 = (*column)[ i ];
112     node2 = (*column)[ i + 1];
113     return r;
114   }
115
116   //================================================================================
117   /*!
118    * \brief Compute boundary parameters of face parts
119     * \param nbParts - nb of parts to split columns into
120     * \param columnsMap - node columns of the face to split
121     * \param params - computed parameters
122    */
123   //================================================================================
124
125   void splitParams( const int               nbParts,
126                     const TParam2ColumnMap* columnsMap,
127                     vector< double > &      params)
128   {
129     params.clear();
130     params.reserve( nbParts + 1 );
131     TParam2ColumnIt last_par_col = --columnsMap->end();
132     double par = columnsMap->begin()->first; // 0.
133     double parLast = last_par_col->first;
134     params.push_back( par );
135     for ( int i = 0; i < nbParts - 1; ++ i )
136     {
137       double partSize = ( parLast - par ) / double ( nbParts - i );
138       TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
139       if ( par_col->first == par ) {
140         ++par_col;
141         if ( par_col == last_par_col ) {
142           while ( i < nbParts - 1 )
143             params.push_back( par + partSize * i++ );
144           break;
145         }
146       }
147       par = par_col->first;
148       params.push_back( par );
149     }
150     params.push_back( parLast ); // 1.
151   }
152 }
153
154 //=======================================================================
155 //function : StdMeshers_Prism_3D
156 //purpose  : 
157 //=======================================================================
158
159 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
160   :SMESH_3D_Algo(hypId, studyId, gen)
161 {
162   _name = "Prism_3D";
163   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit per shape type
164   myProjectTriangles = false;
165 }
166
167 //================================================================================
168 /*!
169  * \brief Destructor
170  */
171 //================================================================================
172
173 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
174 {}
175
176 //=======================================================================
177 //function : CheckHypothesis
178 //purpose  : 
179 //=======================================================================
180
181 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh&                          aMesh,
182                                           const TopoDS_Shape&                  aShape,
183                                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
184 {
185   // no hypothesis
186   aStatus = SMESH_Hypothesis::HYP_OK;
187   return true;
188 }
189
190 //=======================================================================
191 //function : Compute
192 //purpose  : 
193 //=======================================================================
194
195 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
196 {
197   myHelper = new SMESH_MesherHelper( theMesh );
198   // to delete helper at exit from Compute()
199   std::auto_ptr<SMESH_MesherHelper> helperDeleter( myHelper );
200
201   myHelper->IsQuadraticSubMesh( theShape );
202
203   // Analyse mesh and geomerty to find block subshapes and submeshes
204   if ( !myBlock.Init( myHelper, theShape ))
205     return false;
206
207   SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
208
209   int volumeID = meshDS->ShapeToIndex( theShape );
210
211
212   // To compute coordinates of a node inside a block, it is necessary to know
213   // 1. normalized parameters of the node by which
214   // 2. coordinates of node projections on all block sub-shapes are computed
215
216   // So we fill projections on vertices at once as they are same for all nodes
217   myShapeXYZ.resize( myBlock.NbSubShapes() );
218   for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
219     myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
220     SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
221   }
222
223   // Projections on the top and bottom faces are taken from nodes existing
224   // on these faces; find correspondence between bottom and top nodes
225   myBotToColumnMap.clear();
226   if ( !assocOrProjBottom2Top() ) // it also fill myBotToColumnMap
227     return false;
228
229
230   // Create nodes inside the block
231
232   // loop on nodes inside the bottom face
233   TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
234   for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
235   {
236     const TNode& tBotNode = bot_column->first; // bottom TNode
237     if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
238       continue; // node is not inside face 
239
240     // column nodes; middle part of the column are zero pointers
241     TNodeColumn& column = bot_column->second;
242
243     // bottom node parameters and coords
244     gp_XYZ botParams          = tBotNode.GetParams();
245     myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
246
247     // compute top node parameters
248     gp_XYZ topParams;
249     myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
250     gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
251     if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE ))
252       RETURN_BAD_RESULT("ComputeParameters() on the top face failed");
253
254     // vertical loop
255     TNodeColumn::iterator columnNodes = column.begin();
256     for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
257     {
258       const SMDS_MeshNode* & node = *columnNodes;
259       if ( node ) continue; // skip bottom or top node
260
261       // params of a node to create
262       double rz = (double) z / (double) ( column.size() - 1 );
263       gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
264
265       // set coords on all faces and nodes
266       const int nbSideFaces = 4;
267       int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
268                                        SMESH_Block::ID_Fx1z,
269                                        SMESH_Block::ID_F0yz,
270                                        SMESH_Block::ID_F1yz };
271       for ( int iF = 0; iF < nbSideFaces; ++iF )
272         if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
273           return false;
274
275       // compute coords for a new node
276       gp_XYZ coords;
277       if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
278         RETURN_BAD_RESULT("SMESH_Block::ShellPoint() failed");
279
280       // create a node
281       node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
282       meshDS->SetNodeInVolume( node, volumeID );
283     }
284   } // loop on bottom nodes
285
286
287   // Create volumes
288
289   SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
290   if ( !smDS ) RETURN_BAD_RESULT("Null submesh");
291
292   // loop on bottom mesh faces
293   SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
294   while ( faceIt->more() )
295   {
296     const SMDS_MeshElement* face = faceIt->next();
297     if ( !face || face->GetType() != SMDSAbs_Face )
298       continue;
299     int nbNodes = face->NbNodes();
300     if ( face->IsQuadratic() )
301       nbNodes /= 2;
302
303     // find node columns for each node
304     vector< const TNodeColumn* > columns( nbNodes );
305     for ( int i = 0; i < nbNodes; ++i )
306     {
307       const SMDS_MeshNode* n = face->GetNode( i );
308       if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
309         bot_column = myBotToColumnMap.find( n );
310         if ( bot_column == myBotToColumnMap.end() )
311           RETURN_BAD_RESULT(" node column for a node not found");
312         columns[ i ] = & bot_column->second;
313       }
314       else {
315         columns[ i ] = myBlock.GetNodeColumn( n );
316         if ( !columns[ i ] )
317           RETURN_BAD_RESULT(" node column not found for a node " << n->GetID() );
318       }
319     }
320     // create prisms
321     AddPrisms( columns, myHelper );
322
323   } // loop on bottom mesh faces
324         
325   return true;
326 }
327
328 //================================================================================
329 /*!
330  * \brief Create prisms
331  * \param columns - columns of nodes generated from nodes of a mesh face
332  * \param helper - helper initialized by mesh and shape to add prisms to
333  */
334 //================================================================================
335
336 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
337                                      SMESH_MesherHelper*          helper)
338 {
339   SMESHDS_Mesh * meshDS = helper->GetMeshDS();
340   int shapeID = helper->GetSubShapeID();
341
342   int nbNodes = columns.size();
343
344   // vertical loop on columns
345   for ( int z = 1; z < columns[0]->size(); ++z)
346   {
347     SMDS_MeshElement* vol = 0;
348     SMDS_VolumeTool vTool;
349     switch ( nbNodes ) {
350
351     case 3: {
352       const SMDS_MeshNode* botNodes[3] = { (*columns[0])[z-1],
353                                            (*columns[1])[z-1],
354                                            (*columns[2])[z-1] };
355       const SMDS_MeshNode* topNodes[3] = { (*columns[0])[z],
356                                            (*columns[1])[z],
357                                            (*columns[2])[z] };
358       // assure good orientation
359       SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2],
360                                   topNodes[0], topNodes[1], topNodes[2]);
361       vTool.Set( &tmpVol );
362       if ( vTool.IsForward() )
363         vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2],
364                                  topNodes[0], topNodes[1], topNodes[2]);
365       else
366         vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2],
367                                  botNodes[0], botNodes[1], botNodes[2]);
368       break;
369       }
370     case 4: {
371       const SMDS_MeshNode* botNodes[4] = { (*columns[0])[z-1], (*columns[1])[z-1],
372                                            (*columns[2])[z-1], (*columns[3])[z-1] };
373       const SMDS_MeshNode* topNodes[4] = { (*columns[0])[z], (*columns[1])[z],
374                                            (*columns[2])[z], (*columns[3])[z] };
375       // assure good orientation
376       SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
377                                   topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
378       vTool.Set( &tmpVol );
379       if ( vTool.IsForward() )
380         vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
381                                  topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
382       else
383         vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2], topNodes[3],
384                                  botNodes[0], botNodes[1], botNodes[2], botNodes[3]);
385       break;
386       }
387     default:
388       // polyhedron
389       vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
390       vector<int> quantities( 2 + nbNodes, 4 );
391       quantities[0] = quantities[1] = nbNodes;
392       columns.resize( nbNodes + 1 );
393       columns[ nbNodes ] = columns[ 0 ];
394       for ( int i = 0; i < nbNodes; ++i ) {
395         nodes[ i         ] = (*columns[ i ])[z-1]; // bottom
396         nodes[ i+nbNodes ] = (*columns[ i ])[z  ]; // top
397         // side
398         int di = 2*nbNodes + 4*i - 1;
399         nodes[ di   ] = (*columns[i  ])[z-1];
400         nodes[ di+1 ] = (*columns[i+1])[z-1];
401         nodes[ di+2 ] = (*columns[i+1])[z  ];
402         nodes[ di+3 ] = (*columns[i  ])[z  ];
403       }
404       vol = meshDS->AddPolyhedralVolume( nodes, quantities );
405     }
406     if ( vol && shapeID > 0 )
407       meshDS->SetMeshElementOnShape( vol, shapeID );
408   }
409 }
410
411 //================================================================================
412 /*!
413  * \brief Find correspondence between bottom and top nodes
414  *  If elements on the bottom and top faces are topologically different,
415  *  and projection is possible and allowed, perform the projection
416  *  \retval bool - is a success or not
417  */
418 //================================================================================
419
420 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
421 {
422   SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
423   SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
424
425   SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
426   SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
427
428   if ( !botSMDS || botSMDS->NbElements() == 0 )
429     RETURN_BAD_RESULT("Empty horiz submesh");
430
431   bool needProject = false;
432   if ( !topSMDS || 
433        botSMDS->NbElements() != topSMDS->NbElements() ||
434        botSMDS->NbNodes()    != topSMDS->NbNodes())
435   {
436     if ( myBlock.HasNotQuadElemOnTop() )
437       RETURN_BAD_RESULT("Different triangles on 2 sides");
438     needProject = true;
439   }
440
441   if ( 0/*needProject && !myProjectTriangles*/ )
442     RETURN_BAD_RESULT("Need to project but not allowed");
443
444   if ( needProject )
445   {
446     return projectBottomToTop();
447   }
448
449   TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
450   TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
451   // associate top and bottom faces
452   TAssocTool::TShapeShapeMap shape2ShapeMap;
453   if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
454                                              topFace, myBlock.Mesh(),
455                                              shape2ShapeMap) )
456     RETURN_BAD_RESULT("FindSubShapeAssociation failed");
457
458   // Find matching nodes of in and out faces
459   TNodeNodeMap n2nMap;
460   if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
461                                                topFace, myBlock.Mesh(),
462                                                shape2ShapeMap, n2nMap ))
463     RETURN_BAD_RESULT("Different mesh on top and bottom faces");
464
465   // Fill myBotToColumnMap
466
467   int zSize = myBlock.VerticalSize();
468   TNodeNodeMap::iterator bN_tN = n2nMap.begin();
469   for ( ; bN_tN != n2nMap.end(); ++bN_tN )
470   {
471     const SMDS_MeshNode* botNode = bN_tN->first;
472     const SMDS_MeshNode* topNode = bN_tN->second;
473     if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
474       continue; // wall columns are contained in myBlock
475     // compute bottom node params
476     TNode bN( botNode );
477     if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
478       RETURN_BAD_RESULT("ComputeParameters() on the bottom face failed");
479     // create node column
480     TNode2ColumnMap::iterator bN_col = 
481       myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
482     TNodeColumn & column = bN_col->second;
483     column.resize( zSize );
484     column.front() = botNode;
485     column.back()  = topNode;
486   }
487   return true;
488 }
489
490 //================================================================================
491 /*!
492  * \brief Remove quadrangles from the top face and
493  * create triangles there by projection from the bottom
494  * \retval bool - a success or not
495  */
496 //================================================================================
497
498 bool StdMeshers_Prism_3D::projectBottomToTop()
499 {
500   SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
501   SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
502
503   SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
504   SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
505
506   if ( topSMDS )
507     topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
508
509   SMESHDS_Mesh* meshDS = myBlock.MeshDS();
510   int shapeID = myHelper->GetSubShapeID();
511   int topFaceID = meshDS->ShapeToIndex( topSM->GetSubShape() );
512
513   // Fill myBotToColumnMap
514
515   int zSize = myBlock.VerticalSize();
516   SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
517   while ( nIt->more() )
518   {
519     const SMDS_MeshNode* botNode = nIt->next();
520     if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
521       continue; // strange
522     // compute bottom node params
523     TNode bN( botNode );
524     if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(), ID_BOT_FACE ))
525       RETURN_BAD_RESULT("ComputeParameters() on the bottom face failed");
526     // compute top node coords
527     gp_XYZ topXYZ; gp_XY topUV;
528     if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
529          !myBlock.FaceUV   ( ID_TOP_FACE, bN.GetParams(), topUV ))
530       RETURN_BAD_RESULT("SMESH_Block::FacePoint() on the top face failed");
531     SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
532     meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
533     // create node column
534     TNode2ColumnMap::iterator bN_col = 
535       myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
536     TNodeColumn & column = bN_col->second;
537     column.resize( zSize );
538     column.front() = botNode;
539     column.back()  = topNode;
540   }
541
542   // Create top faces
543
544   // loop on bottom mesh faces
545   SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
546   while ( faceIt->more() )
547   {
548     const SMDS_MeshElement* face = faceIt->next();
549     if ( !face || face->GetType() != SMDSAbs_Face )
550       continue;
551     int nbNodes = face->NbNodes();
552     if ( face->IsQuadratic() )
553       nbNodes /= 2;
554
555     // find top node in columns for each bottom node
556     vector< const SMDS_MeshNode* > nodes( nbNodes );
557     for ( int i = 0; i < nbNodes; ++i )
558     {
559       const SMDS_MeshNode* n = face->GetNode( nbNodes - i - 1 );
560       if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
561         TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
562         if ( bot_column == myBotToColumnMap.end() )
563           RETURN_BAD_RESULT(" node column for a node not found");
564         nodes[ i ] = bot_column->second.back();
565       }
566       else {
567         const TNodeColumn* column = myBlock.GetNodeColumn( n );
568         if ( !column )
569           RETURN_BAD_RESULT(" node column not found for a node " << n->GetID() );
570         nodes[ i ] = column->back();
571       }
572     }
573     // create a face, with reversed orientation
574     SMDS_MeshElement* newFace = 0;
575     switch ( nbNodes ) {
576
577     case 3: {
578       newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
579       break;
580       }
581     case 4: {
582       newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
583       break;
584       }
585     default:
586       newFace = meshDS->AddPolygonalFace( nodes );
587     }
588     if ( newFace && shapeID > 0 )
589       meshDS->SetMeshElementOnShape( newFace, shapeID );
590   }
591
592   return true;
593 }
594
595 //================================================================================
596 /*!
597  * \brief Set projection coordinates of a node to a face and it's subshapes
598  * \param faceID - the face given by in-block ID
599  * \param params - node normalized parameters
600  * \retval bool - is a success
601  */
602 //================================================================================
603
604 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
605 {
606   // find base and top edges of the face
607   enum { BASE = 0, TOP, LEFT, RIGHT };
608   vector< int > edgeVec; // 0-base, 1-top
609   SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
610
611   myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
612   myBlock.EdgePoint( edgeVec[ TOP ], params, myShapeXYZ[ edgeVec[ TOP ]]);
613
614   SHOWYXZ("\nparams ", params);
615   SHOWYXZ("TOP is "<<edgeVec[ TOP], myShapeXYZ[ edgeVec[ TOP]]);
616   SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
617
618   if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
619   {
620     myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
621     myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
622
623     SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
624     SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
625   }
626   myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
627   SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
628
629   return true;
630 }
631
632 //================================================================================
633 /*!
634  * \brief Constructor. Initialization is needed
635  */
636 //================================================================================
637
638 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
639 {
640   mySide = 0;
641 }
642
643 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
644 {
645   if ( mySide ) {
646     delete mySide; mySide = 0;
647   }
648 }
649
650 //================================================================================
651 /*!
652  * \brief Initialization.
653  * \param helper - helper loaded with mesh and 3D shape
654  * \param shape3D - a closed shell or solid
655  * \retval bool - false if a mesh or a shape are KO
656  */
657 //================================================================================
658
659 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
660                                    const TopoDS_Shape& shape3D)
661 {
662   if ( mySide ) {
663     delete mySide; mySide = 0;
664   }
665   vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
666   vector< pair< double, double> > params ( NB_WALL_FACES );
667   mySide = new TSideFace( sideFaces, params );
668
669   myHelper = helper;
670   SMESHDS_Mesh* meshDS = myHelper->GetMesh()->GetMeshDS();
671
672   int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
673     SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
674     SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
675   };
676   SMESH_Block::init();
677
678   // -------------------------------------------------------------
679   // Look for top and bottom faces: not quadrangle ones or meshed
680   // with not quadrangle elements
681   // -------------------------------------------------------------
682
683   list< SMESH_subMesh* > notQuadGeomSubMesh;
684   list< SMESH_subMesh* > notQuadElemSubMesh;
685   int nbFaces = 0;
686   //
687   SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
688   if ( !mainSubMesh ) RETURN_BAD_RESULT("Null submesh of shape3D");
689   //
690   const map< int, SMESH_subMesh * >& subSM = mainSubMesh->DependsOn();
691   map< int, SMESH_subMesh * >::const_iterator i_subSM = subSM.begin();
692   for ( ; i_subSM != subSM.end(); ++i_subSM )
693   {
694     SMESH_subMesh* sm = i_subSM->second;
695     const TopoDS_Shape& face = sm->GetSubShape();
696     if ( face.ShapeType() != TopAbs_FACE )
697       continue;
698     nbFaces++;
699
700     // is quadrangle face?
701     if ( TAssocTool::Count( face, TopAbs_EDGE, 0 ) != 4 ||
702          TAssocTool::Count( face, TopAbs_WIRE, 0 ) != 1 )
703       notQuadGeomSubMesh.push_back( sm );
704
705     // count not quadrangle mesh elements
706     if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) {
707       SMDS_ElemIteratorPtr eIt = smDS->GetElements();
708       bool hasNotQuad = false;
709       while ( eIt->more() && !hasNotQuad ) {
710         const SMDS_MeshElement* elem = eIt->next();
711         if ( elem->GetType() == SMDSAbs_Face ) {
712           int nbNodes = elem->NbNodes();
713           if ( elem->IsQuadratic() )
714             nbNodes /= 2;
715           hasNotQuad = ( nbNodes != 4 );
716         }
717       }
718       if ( hasNotQuad )
719         notQuadElemSubMesh.push_back( sm );
720     }
721     else {
722       RETURN_BAD_RESULT("not meshed face");
723     }
724   }
725
726   // ----------------------------------------------------------------------
727   // Analyse faces mesh and topology: choose the bottom submesh.
728   // If there are not quadrangle geom faces, they are top and bottom ones.
729   // Not quadrangle geom faces must be only on top and bottom.
730   // ----------------------------------------------------------------------
731
732   SMESH_subMesh * botSM = 0;
733   SMESH_subMesh * topSM = 0;
734
735   int nbNotQuad       = notQuadGeomSubMesh.size();
736   int nbNotQuadMeshed = notQuadElemSubMesh.size();
737   bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
738
739   // detect bad cases
740   if ( nbNotQuad > 0 && nbNotQuad != 2 )
741     RETURN_BAD_RESULT("Wrong shape geometry");
742   if ( nbNotQuadMeshed > 2 )
743     RETURN_BAD_RESULT("More then 2 faces meshed with not quadrangle elements");
744
745   // get found submeshes
746   if ( hasNotQuad )
747   {
748     if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
749     else                       botSM = notQuadGeomSubMesh.front();
750     if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
751     else if ( nbNotQuad  > 1 ) topSM = notQuadGeomSubMesh.back();
752   }
753   // detect other bad cases
754   if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
755     bool ok = false;
756     if ( nbNotQuadMeshed == 1 )
757       ok = ( find( notQuadGeomSubMesh.begin(),
758                    notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
759     else
760       ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
761     if ( !ok )
762       RETURN_BAD_RESULT("Side face meshed with not quadrangle elements");
763   }
764
765   myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
766     
767   // ----------------------------------------------------------
768
769   if ( nbNotQuad == 0 ) // Standard block of 6 quadrangle faces ?
770   {
771     // SMESH_Block will perform geometry analysis, we need just to find 2
772     // connected vertices on top and bottom
773
774     TopoDS_Vertex Vbot, Vtop;
775     if ( nbNotQuadMeshed > 0 ) // Look for vertices
776     {
777       TopTools_IndexedMapOfShape edgeMap;
778       TopExp::MapShapes( botSM->GetSubShape(), TopAbs_EDGE, edgeMap );
779       // vertex 1 is any vertex of the bottom face
780       Vbot = TopExp::FirstVertex( TopoDS::Edge( edgeMap( 1 )));
781       // vertex 2 is end vertex of edge sharing Vbot and not belonging to the bottom face
782       TopTools_ListIteratorOfListOfShape ancestIt = Mesh()->GetAncestors( Vbot );
783       for ( ; Vtop.IsNull() && ancestIt.More(); ancestIt.Next() )
784       {
785         const TopoDS_Shape & ancestor = ancestIt.Value();
786         if ( ancestor.ShapeType() == TopAbs_EDGE && !edgeMap.FindIndex( ancestor ))
787         {
788           Vtop = TopExp::LastVertex( TopoDS::Edge( ancestor ));
789           if ( Vbot.IsSame ( Vtop ))
790             Vtop = TopExp::FirstVertex( TopoDS::Edge( ancestor ));
791         }
792       }
793     }
794     // get shell from shape3D
795     TopoDS_Shell shell;
796     TopExp_Explorer exp( shape3D, TopAbs_SHELL );
797     int nbShell = 0;
798     for ( ; exp.More(); exp.Next(), ++nbShell )
799       shell = TopoDS::Shell( exp.Current() );
800 //     if ( nbShell != 1 )
801 //       RETURN_BAD_RESULT("There must be 1 shell in the block");
802
803     // Load geometry in SMESH_Block
804     myShapeIDMap.Clear();
805     if ( !SMESH_Block::FindBlockShapes( shell, Vbot, Vtop, myShapeIDMap )) {
806       if ( !hasNotQuad )
807         RETURN_BAD_RESULT("Can not detect top and bottom");
808     }
809     else {
810       if ( !botSM ) botSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_BOT_FACE ));
811       if ( !topSM ) topSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_TOP_FACE ));
812     }
813
814   } // end  Standard block of 6 quadrangle faces
815   // --------------------------------------------------------
816
817   // Here the top and bottom faces are found
818   if ( nbNotQuadMeshed == 2 ) // roughly check correspondence of horiz meshes
819   {
820 //     SMESHDS_SubMesh* topSMDS = topSM->GetSubMeshDS();
821 //     SMESHDS_SubMesh* botSMDS = botSM->GetSubMeshDS();
822 //     if ( topSMDS->NbNodes() != botSMDS->NbNodes() ||
823 //          topSMDS->NbElements() != botSMDS->NbElements() )
824 //       RETURN_BAD_RESULT("Top mesh doesn't correspond to bottom one");
825   }
826
827   // ---------------------------------------------------------
828   // If there are not quadrangle geom faces, we emulate
829   // a block of 6 quadrangle faces.
830   // Load SMESH_Block with faces and edges geometry
831   // ---------------------------------------------------------
832
833   
834   // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
835   TopoDS_Vertex V000;
836   double minVal = DBL_MAX, minX, val;
837   for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
838         exp.More(); exp.Next() )
839   {
840     const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
841     gp_Pnt P = BRep_Tool::Pnt( v );
842     val = P.X() + P.Y() + P.Z();
843     if ( val < minVal || ( val == minVal && P.X() < minX )) {
844       V000 = v;
845       minVal = val;
846       minX = P.X();
847     }
848   }
849
850   // Get ordered bottom edges
851   list< TopoDS_Edge > orderedEdges;
852   list< int >         nbVertexInWires;
853   SMESH_Block::GetOrderedEdges( TopoDS::Face( botSM->GetSubShape().Reversed() ),
854                                 V000, orderedEdges, nbVertexInWires );
855 //   if ( nbVertexInWires.size() != 1 )
856 //     RETURN_BAD_RESULT("Wrong prism geometry");
857
858   // Get Wall faces corresponding to the ordered bottom edges
859   list< TopoDS_Face > wallFaces;
860   if ( !GetWallFaces( Mesh(), shape3D, botSM->GetSubShape(), orderedEdges, wallFaces))
861     RETURN_BAD_RESULT("GetWallFaces() failed");
862
863   // Find columns of wall nodes and calculate edges' lengths
864   // --------------------------------------------------------
865
866   myParam2ColumnMaps.clear();
867   myParam2ColumnMaps.resize( orderedEdges.size() ); // total nb edges
868
869   int iE, nbEdges = nbVertexInWires.front(); // nb outer edges
870   vector< double > edgeLength( nbEdges );
871   map< double, int > len2edgeMap;
872
873   list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
874   list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
875   for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
876   {
877     TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
878     if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
879       RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
880
881     SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
882     SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
883     SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
884
885     edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
886
887     if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
888     {
889       SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
890       if ( !smDS )
891         RETURN_BAD_RESULT("Null submesh on a bottom edge");
892       // assure length uniqueness
893       edgeLength[ iE ] *= smDS->NbNodes() + edgeLength[ iE ] / ( 1000 + iE );
894       len2edgeMap[ edgeLength[ iE ]] = iE;
895     }
896     ++iE;
897   }
898   // Load columns of internal edges (forming holes)
899   // and fill map ShapeIndex to TParam2ColumnMap for them
900   for ( ; edgeIt != orderedEdges.end() ; ++edgeIt, ++faceIt )
901   {
902     TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
903     if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
904       RETURN_BAD_RESULT("SMESH_MesherHelper::LoadNodeColumns() failed");
905     // edge columns
906     int id = MeshDS()->ShapeToIndex( *edgeIt );
907     bool isForward = true; // meaningless for intenal wires
908     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
909     // columns for vertices
910     // 1
911     const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
912     id = n0->GetPosition()->GetShapeId();
913     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
914     // 2
915     const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
916     id = n1->GetPosition()->GetShapeId();
917     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
918 //     SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
919 //     SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
920 //     SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
921     ++iE;
922   }
923
924   // Create 4 wall faces of a block
925   // -------------------------------
926
927   if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
928   {
929     map< int, int > iE2nbSplit;
930     if ( nbEdges != NB_WALL_FACES ) // define how to split
931     {
932       if ( len2edgeMap.size() != nbEdges )
933         RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
934       map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
935       map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
936       double maxLen = maxLen_i->first;
937       double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
938       switch ( nbEdges ) {
939       case 1: // 0-th edge is split into 4 parts
940         iE2nbSplit.insert( make_pair( 0, 4 )); break;
941       case 2: // either the longest edge is split into 3 parts, or both edges into halves
942         if ( maxLen / 3 > midLen / 2 ) {
943           iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
944         }
945         else {
946           iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
947           iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
948         }
949         break;
950       case 3:
951         // split longest into halves
952         iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
953       }
954     }
955     // Create TSideFace's
956     faceIt = wallFaces.begin();
957     edgeIt = orderedEdges.begin();
958     int iSide = 0;
959     for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
960     {
961      // split?
962       map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
963       if ( i_nb != iE2nbSplit.end() ) {
964         // split!
965         int nbSplit = i_nb->second;
966         vector< double > params;
967         splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
968         bool isForward = ( edgeIt->Orientation() == TopAbs_FORWARD );
969         for ( int i = 0; i < nbSplit; ++i ) {
970           double f = ( isForward ? params[ i ] : params[ nbSplit - i-1 ]);
971           double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
972           TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
973                                            *faceIt, *edgeIt,
974                                            &myParam2ColumnMaps[ iE ], f, l );
975           mySide->SetComponent( iSide++, comp );
976         }
977       }
978       else {
979         TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
980                                          *faceIt, *edgeIt,
981                                          &myParam2ColumnMaps[ iE ]);
982         mySide->SetComponent( iSide++, comp );
983       }
984       ++iE;
985     }
986   }
987   else { // **************************** Unite faces
988
989     // unite first faces
990     int nbExraFaces = nbEdges - 3;
991     int iSide = 0, iE;
992     double u0 = 0, sumLen = 0;
993     for ( iE = 0; iE < nbExraFaces; ++iE )
994       sumLen += edgeLength[ iE ];
995
996     vector< TSideFace* > components( nbExraFaces );
997     vector< pair< double, double> > params( nbExraFaces );
998     faceIt = wallFaces.begin();
999     edgeIt = orderedEdges.begin();
1000     for ( iE = 0; iE < nbExraFaces; ++edgeIt, ++faceIt )
1001     {
1002       components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
1003                                         *faceIt, *edgeIt,
1004                                         &myParam2ColumnMaps[ iE ]);
1005       double u1 = u0 + edgeLength[ iE ] / sumLen;
1006       params[ iE ] = make_pair( u0 , u1 );
1007       u0 = u1;
1008       ++iE;
1009     }
1010     mySide->SetComponent( iSide++, new TSideFace( components, params ));
1011
1012     // fill the rest faces
1013     for ( ; iE < nbEdges; ++faceIt, ++edgeIt )
1014     {
1015       TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
1016                                        *faceIt, *edgeIt,
1017                                        &myParam2ColumnMaps[ iE ]);
1018       mySide->SetComponent( iSide++, comp );
1019       ++iE;
1020     }
1021   }
1022
1023
1024   // Fill geometry fields of SMESH_Block
1025   // ------------------------------------
1026
1027   TopoDS_Face botF = TopoDS::Face( botSM->GetSubShape() );
1028   TopoDS_Face topF = TopoDS::Face( topSM->GetSubShape() );
1029
1030   vector< int > botEdgeIdVec;
1031   SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
1032
1033   bool isForward[NB_WALL_FACES] = { true, true, true, true };
1034   Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
1035   Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
1036
1037   for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
1038   {
1039     TSideFace * sideFace = mySide->GetComponent( iF );
1040     if ( !sideFace )
1041       RETURN_BAD_RESULT("NULL TSideFace");
1042     int fID = sideFace->FaceID();
1043
1044     // fill myShapeIDMap
1045     if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
1046          !sideFace->IsComplex())
1047       MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
1048
1049     // side faces geometry
1050     Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
1051     if ( !sideFace->GetPCurves( pcurves ))
1052       RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
1053
1054     SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
1055     tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
1056
1057     SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), );
1058     // edges 3D geometry
1059     vector< int > edgeIdVec;
1060     SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
1061     for ( int isMax = 0; isMax < 2; ++isMax ) {
1062       {
1063         int eID = edgeIdVec[ isMax ];
1064         SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
1065         tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
1066         SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
1067         SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
1068       }
1069       {
1070         int eID = edgeIdVec[ isMax+2 ];
1071         SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE  ];
1072         tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
1073         SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
1074         SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
1075
1076         // corner points
1077         vector< int > vertexIdVec;
1078         SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
1079         myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
1080         myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
1081       }
1082     }
1083     // pcurves on horizontal faces
1084     for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
1085       if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
1086         botPcurves[ iE ] = sideFace->HorizPCurve( false, botF );
1087         topPcurves[ iE ] = sideFace->HorizPCurve( true,  topF );
1088         break;
1089       }
1090     }
1091   }
1092   // horizontal faces geometry
1093   {
1094     SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
1095     tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( botF ), botPcurves, isForward );
1096     SMESH_Block::Insert( botF, ID_BOT_FACE, myShapeIDMap );
1097   }
1098   {
1099     SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
1100     tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( topF ), topPcurves, isForward );
1101     SMESH_Block::Insert( topF, ID_TOP_FACE, myShapeIDMap );
1102   }
1103
1104   // Fill map ShapeIndex to TParam2ColumnMap
1105   // ----------------------------------------
1106
1107   list< TSideFace* > fList;
1108   list< TSideFace* >::iterator fListIt;
1109   fList.push_back( mySide );
1110   for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
1111   {
1112     int nb = (*fListIt)->NbComponents();
1113     for ( int i = 0; i < nb; ++i ) {
1114       if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
1115         fList.push_back( comp );
1116     }
1117     if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
1118       // columns for a base edge
1119       int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
1120       bool isForward = (*fListIt)->IsForward();
1121       myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1122
1123       // columns for vertices
1124       const SMDS_MeshNode* n0 = cols->begin()->second.front();
1125       id = n0->GetPosition()->GetShapeId();
1126       myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
1127
1128       const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
1129       id = n1->GetPosition()->GetShapeId();
1130       myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
1131     }
1132   }
1133
1134 //   gp_XYZ testPar(0.25, 0.25, 0), testCoord;
1135 //   if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
1136 //     RETURN_BAD_RESULT("TEST FacePoint() FAILED");
1137 //   SHOWYXZ("IN TEST PARAM" , testPar);
1138 //   SHOWYXZ("OUT TEST CORD" , testCoord);
1139 //   if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
1140 //     RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
1141 //   SHOWYXZ("OUT TEST PARAM" , testPar);
1142
1143   return true;
1144 }
1145
1146 //================================================================================
1147 /*!
1148  * \brief Return pointer to column of nodes
1149  * \param node - bottom node from which the returned column goes up
1150  * \retval const TNodeColumn* - the found column
1151  */
1152 //================================================================================
1153
1154 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
1155 {
1156   int sID = node->GetPosition()->GetShapeId();
1157
1158   map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
1159     myShapeIndex2ColumnMap.find( sID );
1160   if ( col_frw != myShapeIndex2ColumnMap.end() ) {
1161     const TParam2ColumnMap* cols = col_frw->second.first;
1162     TParam2ColumnIt u_col = cols->begin();
1163     for ( ; u_col != cols->end(); ++u_col )
1164       if ( u_col->second[ 0 ] == node )
1165         return & u_col->second;
1166   }
1167   return 0;
1168 }
1169
1170 //================================================================================
1171 /*!
1172  * \brief Check curve orientation of a bootom edge
1173   * \param meshDS - mesh DS
1174   * \param columnsMap - node columns map of side face
1175   * \param bottomEdge - the bootom edge
1176   * \param sideFaceID - side face in-block ID
1177   * \retval bool - true if orientation coinside with in-block froward orientation
1178  */
1179 //================================================================================
1180
1181 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh*           meshDS,
1182                                             const TParam2ColumnMap& columnsMap,
1183                                             const TopoDS_Edge &     bottomEdge,
1184                                             const int               sideFaceID)
1185 {
1186   bool isForward = false;
1187   if ( TAssocTool::IsClosedEdge( bottomEdge ))
1188   {
1189     isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
1190   }
1191   else
1192   {
1193     const TNodeColumn& firstCol = columnsMap.begin()->second;
1194     const SMDS_MeshNode* bottomNode = firstCol[0];
1195     TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
1196     isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
1197   }
1198   // on 2 of 4 sides first vertex is end
1199   if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
1200     isForward = !isForward;
1201   return isForward;
1202 }
1203
1204 //================================================================================
1205   /*!
1206    * \brief Find wall faces by bottom edges
1207     * \param mesh - the mesh
1208     * \param mainShape - the prism
1209     * \param bottomFace - the bottom face
1210     * \param bottomEdges - edges bounding the bottom face
1211     * \param wallFaces - faces list to fill in
1212    */
1213 //================================================================================
1214
1215 bool StdMeshers_PrismAsBlock::GetWallFaces( SMESH_Mesh*                     mesh,
1216                                             const TopoDS_Shape &            mainShape,
1217                                             const TopoDS_Shape &            bottomFace,
1218                                             const std::list< TopoDS_Edge >& bottomEdges,
1219                                             std::list< TopoDS_Face >&       wallFaces)
1220 {
1221   wallFaces.clear();
1222
1223   TopTools_IndexedMapOfShape faceMap;
1224   TopExp::MapShapes( mainShape, TopAbs_FACE, faceMap );
1225
1226   list< TopoDS_Edge >::const_iterator edge = bottomEdges.begin();
1227   for ( ; edge != bottomEdges.end(); ++edge )
1228   {
1229     TopTools_ListIteratorOfListOfShape ancestIt = mesh->GetAncestors( *edge );
1230     for ( ; ancestIt.More(); ancestIt.Next() )
1231     {
1232       const TopoDS_Shape& ancestor = ancestIt.Value();
1233       if ( ancestor.ShapeType() == TopAbs_FACE && // face
1234            !bottomFace.IsSame( ancestor ) &&      // not bottom
1235            faceMap.FindIndex( ancestor ))         // belongs to the prism
1236       {
1237         wallFaces.push_back( TopoDS::Face( ancestor ));
1238         break;
1239       }
1240     }
1241   }
1242   return ( wallFaces.size() == bottomEdges.size() );
1243 }
1244
1245 //================================================================================
1246 /*!
1247  * \brief Constructor
1248   * \param faceID - in-block ID
1249   * \param face - geom face
1250   * \param columnsMap - map of node columns
1251   * \param first - first normalized param
1252   * \param last - last normalized param
1253  */
1254 //================================================================================
1255
1256 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
1257                                               const int           faceID,
1258                                               const TopoDS_Face&  face,
1259                                               const TopoDS_Edge&  baseEdge,
1260                                               TParam2ColumnMap*   columnsMap,
1261                                               const double        first,
1262                                               const double        last):
1263   myID( faceID ),
1264   myParamToColumnMap( columnsMap ),
1265   myBaseEdge( baseEdge ),
1266   myHelper( helper )
1267 {
1268   mySurface.Initialize( face );
1269   myParams.resize( 1 );
1270   myParams[ 0 ] = make_pair( first, last );
1271   myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
1272                                                         *myParamToColumnMap,
1273                                                         myBaseEdge, myID );
1274 }
1275
1276 //================================================================================
1277 /*!
1278  * \brief Constructor of complex side face
1279  */
1280 //================================================================================
1281
1282 StdMeshers_PrismAsBlock::TSideFace::
1283 TSideFace(const vector< TSideFace* >&             components,
1284           const vector< pair< double, double> > & params)
1285   :myID( components[0] ? components[0]->myID : 0 ),
1286    myParamToColumnMap( 0 ),
1287    myParams( params ),
1288    myIsForward( true ),
1289    myComponents( components ),
1290    myHelper( components[0] ? components[0]->myHelper : 0 )
1291 {}
1292 //================================================================================
1293 /*!
1294  * \brief Copy constructor
1295   * \param other - other side
1296  */
1297 //================================================================================
1298
1299 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
1300 {
1301   myID               = other.myID;
1302   mySurface          = other.mySurface;
1303   myBaseEdge         = other.myBaseEdge;
1304   myParams           = other.myParams;
1305   myIsForward        = other.myIsForward;
1306   myHelper           = other.myHelper;
1307   myParamToColumnMap = other.myParamToColumnMap;
1308
1309   myComponents.resize( other.myComponents.size());
1310   for (int i = 0 ; i < myComponents.size(); ++i )
1311     myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
1312 }
1313
1314 //================================================================================
1315 /*!
1316  * \brief Deletes myComponents
1317  */
1318 //================================================================================
1319
1320 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
1321 {
1322   for (int i = 0 ; i < myComponents.size(); ++i )
1323     if ( myComponents[ i ] )
1324       delete myComponents[ i ];
1325 }
1326
1327 //================================================================================
1328 /*!
1329  * \brief Return geometry of the vertical curve
1330   * \param isMax - true means curve located closer to (1,1,1) block point
1331   * \retval Adaptor3d_Curve* - curve adaptor
1332  */
1333 //================================================================================
1334
1335 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
1336 {
1337   if ( !myComponents.empty() ) {
1338     if ( isMax )
1339       return myComponents.back()->VertiCurve(isMax);
1340     else
1341       return myComponents.front()->VertiCurve(isMax);
1342   }
1343   double f = myParams[0].first, l = myParams[0].second;
1344   if ( !myIsForward ) std::swap( f, l );
1345   return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
1346 }
1347
1348 //================================================================================
1349 /*!
1350  * \brief Return geometry of the top or bottom curve
1351   * \param isTop - 
1352   * \retval Adaptor3d_Curve* - 
1353  */
1354 //================================================================================
1355
1356 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
1357 {
1358   return new THorizontalEdgeAdaptor( this, isTop );
1359 }
1360
1361 //================================================================================
1362 /*!
1363  * \brief Return pcurves
1364   * \param pcurv - array of 4 pcurves
1365   * \retval bool - is a success
1366  */
1367 //================================================================================
1368
1369 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
1370 {
1371   int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
1372
1373   for ( int i = 0 ; i < 4 ; ++i ) {
1374     Handle(Geom2d_Line) line;
1375     switch ( iEdge[ i ] ) {
1376     case TOP_EDGE:
1377       line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
1378     case BOTTOM_EDGE:
1379       line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
1380     case V0_EDGE:
1381       line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
1382     case V1_EDGE:
1383       line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
1384     }
1385     pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
1386   }
1387   return true;
1388 }
1389
1390 //================================================================================
1391 /*!
1392  * \brief Returns geometry of pcurve on a horizontal face
1393   * \param isTop - is top or bottom face
1394   * \param horFace - a horizontal face
1395   * \retval Adaptor2d_Curve2d* - curve adaptor
1396  */
1397 //================================================================================
1398
1399 Adaptor2d_Curve2d*
1400 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool         isTop,
1401                                                 const TopoDS_Face& horFace) const
1402 {
1403   return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
1404 }
1405
1406 //================================================================================
1407 /*!
1408  * \brief Return a component corresponding to parameter
1409   * \param U - parameter along a horizontal size
1410   * \param localU - parameter along a horizontal size of a component
1411   * \retval TSideFace* - found component
1412  */
1413 //================================================================================
1414
1415 StdMeshers_PrismAsBlock::TSideFace*
1416 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
1417 {
1418   localU = U;
1419   if ( myComponents.empty() )
1420     return const_cast<TSideFace*>( this );
1421
1422   int i;
1423   for ( i = 0; i < myComponents.size(); ++i )
1424     if ( U < myParams[ i ].second )
1425       break;
1426   if ( i >= myComponents.size() )
1427     i = myComponents.size() - 1;
1428
1429   double f = myParams[ i ].first, l = myParams[ i ].second;
1430   localU = ( U - f ) / ( l - f );
1431   return myComponents[ i ];
1432 }
1433
1434 //================================================================================
1435 /*!
1436  * \brief Find node columns for a parameter
1437   * \param U - parameter along a horizontal edge
1438   * \param col1 - the 1st found column
1439   * \param col2 - the 2nd found column
1440   * \retval r - normalized position of U between the found columns
1441  */
1442 //================================================================================
1443
1444 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double      U,
1445                                                       TParam2ColumnIt & col1,
1446                                                       TParam2ColumnIt & col2) const
1447 {
1448   double u = U, r = 0;
1449   if ( !myComponents.empty() ) {
1450     TSideFace * comp = GetComponent(U,u);
1451     return comp->GetColumns( u, col1, col2 );
1452   }
1453
1454   if ( !myIsForward )
1455     u = 1 - u;
1456   double f = myParams[0].first, l = myParams[0].second;
1457   u = f + u * ( l - f );
1458
1459   col1 = col2 = getColumn( myParamToColumnMap, u );
1460   if ( ++col2 == myParamToColumnMap->end() ) {
1461     --col2;
1462     r = 0.5;
1463   }
1464   else {
1465 //     if ( !myIsForward )
1466 //       std::swap( col1, col2 );
1467     double uf = col1->first;
1468     double ul = col2->first;
1469     r = ( u - uf ) / ( ul - uf );
1470   }
1471   return r;
1472 }
1473
1474 //================================================================================
1475 /*!
1476  * \brief Return coordinates by normalized params
1477   * \param U - horizontal param
1478   * \param V - vertical param
1479   * \retval gp_Pnt - result point
1480  */
1481 //================================================================================
1482
1483 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
1484                                                  const Standard_Real V) const
1485 {
1486   double u;
1487   if ( !myComponents.empty() ) {
1488     TSideFace * comp = GetComponent(U,u);
1489     return comp->Value( u, V );
1490   }
1491
1492   TParam2ColumnIt u_col1, u_col2;
1493   double vR, hR = GetColumns( U, u_col1, u_col2 );
1494
1495   const SMDS_MeshNode* n1 = 0;
1496   const SMDS_MeshNode* n2 = 0;
1497   const SMDS_MeshNode* n3 = 0;
1498   const SMDS_MeshNode* n4 = 0;
1499   gp_XYZ pnt;
1500
1501   vR = getRAndNodes( & u_col1->second, V, n1, n2 );
1502   vR = getRAndNodes( & u_col2->second, V, n3, n4 );
1503   
1504   gp_XY uv1 = myHelper->GetNodeUV( mySurface.Face(), n1, n4);
1505   gp_XY uv2 = myHelper->GetNodeUV( mySurface.Face(), n2, n3);
1506   gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
1507
1508   gp_XY uv3 = myHelper->GetNodeUV( mySurface.Face(), n3, n2);
1509   gp_XY uv4 = myHelper->GetNodeUV( mySurface.Face(), n4, n1);
1510   gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
1511
1512   gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
1513   
1514   return mySurface.Value( uv.X(), uv.Y() );
1515 }
1516
1517
1518 //================================================================================
1519 /*!
1520  * \brief Return boundary edge
1521   * \param edge - edge index
1522   * \retval TopoDS_Edge - found edge
1523  */
1524 //================================================================================
1525
1526 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
1527 {
1528   if ( !myComponents.empty() ) {
1529     switch ( iEdge ) {
1530     case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
1531     case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
1532     default: return TopoDS_Edge();
1533     }
1534   }
1535   TopoDS_Shape edge;
1536   const SMDS_MeshNode* node = 0;
1537   SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
1538   TNodeColumn* column;
1539
1540   switch ( iEdge ) {
1541   case TOP_EDGE:
1542   case BOTTOM_EDGE:
1543     column = & (( ++myParamToColumnMap->begin())->second );
1544     node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1545     edge = myHelper->GetSubShapeByNode ( node, meshDS );
1546     if ( edge.ShapeType() == TopAbs_VERTEX ) {
1547       column = & ( myParamToColumnMap->begin()->second );
1548       node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
1549     }
1550     break;
1551   case V0_EDGE:
1552   case V1_EDGE: {
1553     bool back = ( iEdge == V1_EDGE );
1554     if ( !myIsForward ) back = !back;
1555     if ( back )
1556       column = & ( myParamToColumnMap->rbegin()->second );
1557     else
1558       column = & ( myParamToColumnMap->begin()->second );
1559     if ( column->size() > 0 )
1560       edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
1561     if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
1562       node = column->front();
1563     break;
1564   }
1565   default:;
1566   }
1567   if ( !edge.IsNull() || edge.ShapeType() == TopAbs_EDGE )
1568     return TopoDS::Edge( edge );
1569
1570   // find edge by 2 vertices
1571   TopoDS_Shape V1 = edge;
1572   TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
1573   if ( V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
1574   {
1575     TopTools_ListIteratorOfListOfShape ancestIt =
1576       myHelper->GetMesh()->GetAncestors( V1 );
1577     for ( ; ancestIt.More(); ancestIt.Next() )
1578     {
1579       const TopoDS_Shape & ancestor = ancestIt.Value();
1580       if ( ancestor.ShapeType() == TopAbs_EDGE )
1581         for ( TopExp_Explorer e( ancestor, TopAbs_VERTEX ); e.More(); e.Next() )
1582           if ( V2.IsSame( e.Current() ))
1583             return TopoDS::Edge( ancestor );
1584     }
1585   }
1586   return TopoDS_Edge();
1587 }
1588
1589 //================================================================================
1590 /*!
1591  * \brief Fill block subshapes
1592   * \param shapeMap - map to fill in
1593   * \retval int - nb inserted subshapes
1594  */
1595 //================================================================================
1596
1597 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
1598 {
1599   int nbInserted = 0;
1600
1601   // Insert edges
1602   vector< int > edgeIdVec;
1603   SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
1604
1605   for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
1606     TopoDS_Edge e = GetEdge( i );
1607     if ( !e.IsNull() ) {
1608       nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
1609     }
1610   }
1611
1612   // Insert corner vertices
1613
1614   TParam2ColumnIt col1, col2 ;
1615   vector< int > vertIdVec;
1616
1617   // from V0 column
1618   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
1619   GetColumns(0, col1, col2 );
1620   const SMDS_MeshNode* node0 = col1->second.front();
1621   const SMDS_MeshNode* node1 = col1->second.back();
1622   TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1623   TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1624   if ( v0.ShapeType() == TopAbs_VERTEX ) {
1625     nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1626   }
1627   if ( v1.ShapeType() == TopAbs_VERTEX ) {
1628     nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1629   }
1630   
1631   // from V1 column
1632   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
1633   GetColumns(1, col1, col2 );
1634   node0 = col2->second.front();
1635   node1 = col2->second.back();
1636   v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
1637   v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
1638   if ( v0.ShapeType() == TopAbs_VERTEX ) {
1639     nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
1640   }
1641   if ( v1.ShapeType() == TopAbs_VERTEX ) {
1642     nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
1643   }
1644
1645 //   TopoDS_Vertex V0, V1, Vcom;
1646 //   TopExp::Vertices( myBaseEdge, V0, V1, true );
1647 //   if ( !myIsForward ) std::swap( V0, V1 );
1648
1649 //   // bottom vertex IDs
1650 //   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
1651 //   SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
1652 //   SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
1653
1654 //   TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
1655 //   if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
1656 //     return false;
1657
1658 //   // insert one side edge
1659 //   int edgeID;
1660 //   if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
1661 //   else                    edgeID = edgeIdVec[ _v1 ];
1662 //   SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1663
1664 //   // top vertex of the side edge
1665 //   SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
1666 //   TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
1667 //   if ( Vcom.IsSame( Vtop ))
1668 //     Vtop = TopExp::LastVertex( sideEdge );
1669 //   SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
1670
1671 //   // other side edge
1672 //   sideEdge = GetEdge( V1_EDGE );
1673 //   if ( sideEdge.IsNull() )
1674 //     return false;
1675 //   if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
1676 //   else                            edgeID = edgeIdVec[ _v1 ];
1677 //   SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
1678   
1679 //   // top edge
1680 //   TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
1681 //   SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
1682
1683 //   // top vertex of the other side edge
1684 //   if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
1685 //     return false;
1686 //   SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
1687 //   SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
1688
1689   return nbInserted;
1690 }
1691
1692 //================================================================================
1693 /*!
1694  * \brief Creates TVerticalEdgeAdaptor 
1695   * \param columnsMap - node column map
1696   * \param parameter - normalized parameter
1697  */
1698 //================================================================================
1699
1700 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
1701 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
1702 {
1703   myNodeColumn = & getColumn( columnsMap, parameter )->second;
1704 }
1705
1706 //================================================================================
1707 /*!
1708  * \brief Return coordinates for the given normalized parameter
1709   * \param U - normalized parameter
1710   * \retval gp_Pnt - coordinates
1711  */
1712 //================================================================================
1713
1714 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
1715 {
1716   const SMDS_MeshNode* n1;
1717   const SMDS_MeshNode* n2;
1718   double r = getRAndNodes( myNodeColumn, U, n1, n2 );
1719   return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
1720 }
1721
1722 //================================================================================
1723 /*!
1724  * \brief Return coordinates for the given normalized parameter
1725   * \param U - normalized parameter
1726   * \retval gp_Pnt - coordinates
1727  */
1728 //================================================================================
1729
1730 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
1731 {
1732   return mySide->TSideFace::Value( U, myV );
1733 }
1734
1735 //================================================================================
1736 /*!
1737  * \brief Return UV on pcurve for the given normalized parameter
1738   * \param U - normalized parameter
1739   * \retval gp_Pnt - coordinates
1740  */
1741 //================================================================================
1742
1743 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
1744 {
1745   TParam2ColumnIt u_col1, u_col2;
1746   double r = mySide->GetColumns( U, u_col1, u_col2 );
1747   gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
1748   gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
1749   return uv1 * ( 1 - r ) + uv2 * r;
1750 }