Back to index

salome-smesh  6.5.0
StdMeshers_Prism_3D.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 // File      : StdMeshers_Prism_3D.cxx
00025 // Module    : SMESH
00026 // Created   : Fri Oct 20 11:37:07 2006
00027 // Author    : Edward AGAPOV (eap)
00028 //
00029 #include "StdMeshers_Prism_3D.hxx"
00030 
00031 #include "StdMeshers_ProjectionUtils.hxx"
00032 #include "SMESH_MesherHelper.hxx"
00033 #include "SMDS_VolumeTool.hxx"
00034 #include "SMDS_VolumeOfNodes.hxx"
00035 #include "SMDS_EdgePosition.hxx"
00036 #include "SMESH_Comment.hxx"
00037 
00038 #include "utilities.h"
00039 
00040 #include <BRep_Tool.hxx>
00041 #include <Bnd_B3d.hxx>
00042 #include <Geom2dAdaptor_Curve.hxx>
00043 #include <Geom2d_Line.hxx>
00044 #include <Geom_Curve.hxx>
00045 #include <TopExp.hxx>
00046 #include <TopExp_Explorer.hxx>
00047 #include <TopTools_ListIteratorOfListOfShape.hxx>
00048 #include <TopTools_MapOfShape.hxx>
00049 #include <TopTools_SequenceOfShape.hxx>
00050 #include <TopoDS.hxx>
00051 #include <gp_Ax2.hxx>
00052 #include <gp_Ax3.hxx>
00053 
00054 using namespace std;
00055 
00056 #define RETURN_BAD_RESULT(msg) { MESSAGE(")-: Error: " << msg); return false; }
00057 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
00058 #define SHOWYXZ(msg, xyz) // {\
00059 // gp_Pnt p (xyz); \
00060 // cout << msg << " ("<< p.X() << "; " <<p.Y() << "; " <<p.Z() << ") " <<endl;\
00061 // }
00062 
00063 typedef StdMeshers_ProjectionUtils TAssocTool;
00064 typedef SMESH_Comment              TCom;
00065 
00066 enum { ID_BOT_FACE = SMESH_Block::ID_Fxy0,
00067        ID_TOP_FACE = SMESH_Block::ID_Fxy1,
00068        BOTTOM_EDGE = 0, TOP_EDGE, V0_EDGE, V1_EDGE, // edge IDs in face
00069        NB_WALL_FACES = 4 }; //
00070 
00071 namespace {
00072 
00073   //================================================================================
00082   //================================================================================
00083 
00084   TParam2ColumnIt getColumn( const TParam2ColumnMap* columnsMap,
00085                              const double            parameter )
00086   {
00087     TParam2ColumnIt u_col = columnsMap->upper_bound( parameter );
00088     if ( u_col != columnsMap->begin() )
00089       --u_col;
00090     return u_col; // return left column
00091   }
00092 
00093   //================================================================================
00102   //================================================================================
00103 
00104   double getRAndNodes( const TNodeColumn*     column,
00105                        const double           param,
00106                        const SMDS_MeshNode* & node1,
00107                        const SMDS_MeshNode* & node2)
00108   {
00109     if ( param >= 1.0 || column->size() == 1) {
00110       node1 = node2 = column->back();
00111       return 0;
00112     }
00113 
00114     int i = int( param * ( column->size() - 1 ));
00115     double u0 = double( i )/ double( column->size() - 1 );
00116     double r = ( param - u0 ) * ( column->size() - 1 );
00117 
00118     node1 = (*column)[ i ];
00119     node2 = (*column)[ i + 1];
00120     return r;
00121   }
00122 
00123   //================================================================================
00130   //================================================================================
00131 
00132   void splitParams( const int               nbParts,
00133                     const TParam2ColumnMap* columnsMap,
00134                     vector< double > &      params)
00135   {
00136     params.clear();
00137     params.reserve( nbParts + 1 );
00138     TParam2ColumnIt last_par_col = --columnsMap->end();
00139     double par = columnsMap->begin()->first; // 0.
00140     double parLast = last_par_col->first;
00141     params.push_back( par );
00142     for ( int i = 0; i < nbParts - 1; ++ i )
00143     {
00144       double partSize = ( parLast - par ) / double ( nbParts - i );
00145       TParam2ColumnIt par_col = getColumn( columnsMap, par + partSize );
00146       if ( par_col->first == par ) {
00147         ++par_col;
00148         if ( par_col == last_par_col ) {
00149           while ( i < nbParts - 1 )
00150             params.push_back( par + partSize * i++ );
00151           break;
00152         }
00153       }
00154       par = par_col->first;
00155       params.push_back( par );
00156     }
00157     params.push_back( parLast ); // 1.
00158   }
00159 
00160   //================================================================================
00164   //================================================================================
00165 
00166   gp_Ax2 getLayerCoordSys(const int                           z,
00167                           const vector< const TNodeColumn* >& columns,
00168                           int&                                xColumn)
00169   {
00170     // gravity center of a layer
00171     gp_XYZ O(0,0,0);
00172     int vertexCol = -1;
00173     for ( int i = 0; i < columns.size(); ++i )
00174     {
00175       O += gpXYZ( (*columns[ i ])[ z ]);
00176       if ( vertexCol < 0 &&
00177            columns[ i ]->front()->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
00178         vertexCol = i;
00179     }
00180     O /= columns.size();
00181 
00182     // Z axis
00183     gp_Vec Z(0,0,0);
00184     int iPrev = columns.size()-1;
00185     for ( int i = 0; i < columns.size(); ++i )
00186     {
00187       gp_Vec v1( O, gpXYZ( (*columns[ iPrev ])[ z ]));
00188       gp_Vec v2( O, gpXYZ( (*columns[ i ]    )[ z ]));
00189       Z += v1 ^ v2;
00190       iPrev = i;
00191     }
00192 
00193     if ( vertexCol >= 0 )
00194     {
00195       O = gpXYZ( (*columns[ vertexCol ])[ z ]);
00196     }
00197     if ( xColumn < 0 || xColumn >= columns.size() )
00198     {
00199       // select a column for X dir
00200       double maxDist = 0;
00201       for ( int i = 0; i < columns.size(); ++i )
00202       {
00203         double dist = ( O - gpXYZ((*columns[ i ])[ z ])).SquareModulus();
00204         if ( dist > maxDist )
00205         {
00206           xColumn = i;
00207           maxDist = dist;
00208         }
00209       }
00210     }
00211 
00212     // X axis
00213     gp_Vec X( O, gpXYZ( (*columns[ xColumn ])[ z ]));
00214 
00215     return gp_Ax2( O, Z, X);
00216   }
00217 
00218   //================================================================================
00223   //================================================================================
00224 
00225   int removeQuasiQuads(list< SMESH_subMesh* >& notQuadSubMesh)
00226   {
00227     int oldNbSM = notQuadSubMesh.size();
00228     SMESHDS_Mesh* mesh = notQuadSubMesh.front()->GetFather()->GetMeshDS();
00229     list< SMESH_subMesh* >::iterator smIt = notQuadSubMesh.begin();
00230 #define __NEXT_SM { ++smIt; continue; }
00231     while ( smIt != notQuadSubMesh.end() )
00232     {
00233       SMESH_subMesh* faceSm = *smIt;
00234       SMESHDS_SubMesh* faceSmDS = faceSm->GetSubMeshDS();
00235       int nbQuads = faceSmDS->NbElements();
00236       if ( nbQuads == 0 ) __NEXT_SM;
00237 
00238       // get oredered edges
00239       list< TopoDS_Edge > orderedEdges;
00240       list< int >         nbEdgesInWires;
00241       TopoDS_Vertex       V000;
00242       int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( faceSm->GetSubShape() ),
00243                                                   V000, orderedEdges, nbEdgesInWires );
00244       if ( nbWires != 1 || nbEdgesInWires.front() <= 4 )
00245         __NEXT_SM;
00246 
00247       // get nb of segements on edges
00248       list<int> nbSegOnEdge;
00249       list< TopoDS_Edge >::iterator edge = orderedEdges.begin();
00250       for ( ; edge != orderedEdges.end(); ++edge )
00251       {
00252         if ( SMESHDS_SubMesh* edgeSmDS = mesh->MeshElements( *edge ))
00253           nbSegOnEdge.push_back( edgeSmDS->NbElements() );
00254         else
00255           nbSegOnEdge.push_back(0);
00256       }
00257 
00258       // unite nbSegOnEdge of continues edges
00259       int nbEdges = nbEdgesInWires.front();
00260       list<int>::iterator nbSegIt = nbSegOnEdge.begin();
00261       for ( edge = orderedEdges.begin(); edge != orderedEdges.end(); )
00262       {
00263         const TopoDS_Edge& e1 = *edge++;
00264         const TopoDS_Edge& e2 = ( edge == orderedEdges.end() ? orderedEdges.front() : *edge );
00265         if ( SMESH_Algo::IsContinuous( e1, e2 ))
00266         {
00267           // common vertex of continues edges must be shared by two 2D mesh elems of geom face
00268           TopoDS_Vertex vCommon = TopExp::LastVertex( e1, true );
00269           const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( vCommon, mesh );
00270           int nbF = 0;
00271           if ( vNode )
00272           {
00273             SMDS_ElemIteratorPtr fIt = vNode->GetInverseElementIterator(SMDSAbs_Face);
00274             while ( fIt->more() )
00275               nbF += faceSmDS->Contains( fIt->next() );
00276           }
00277           list<int>::iterator nbSegIt1 = nbSegIt++;
00278           if ( !vNode || nbF == 2 ) // !vNode - two edges can be meshed as one
00279           {
00280             // unite
00281             if ( nbSegIt == nbSegOnEdge.end() ) nbSegIt = nbSegOnEdge.begin();
00282             *nbSegIt += *nbSegIt1;
00283             nbSegOnEdge.erase( nbSegIt1 );
00284             --nbEdges;
00285           }
00286         }
00287         else
00288         {
00289           ++nbSegIt;
00290         }
00291       }
00292       vector<int> nbSegVec( nbSegOnEdge.begin(), nbSegOnEdge.end());
00293       if ( nbSegVec.size() == 4 &&
00294            nbSegVec[0] == nbSegVec[2] &&
00295            nbSegVec[1] == nbSegVec[3] &&
00296            nbSegVec[0] * nbSegVec[1] == nbQuads
00297            )
00298         smIt = notQuadSubMesh.erase( smIt );
00299       else
00300         __NEXT_SM;
00301     }
00302 
00303     return oldNbSM - notQuadSubMesh.size();
00304   }
00305 }
00306 
00307 //=======================================================================
00308 //function : StdMeshers_Prism_3D
00309 //purpose  : 
00310 //=======================================================================
00311 
00312 StdMeshers_Prism_3D::StdMeshers_Prism_3D(int hypId, int studyId, SMESH_Gen* gen)
00313   :SMESH_3D_Algo(hypId, studyId, gen)
00314 {
00315   _name = "Prism_3D";
00316   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit per shape type
00317   myProjectTriangles = false;
00318 }
00319 
00320 //================================================================================
00324 //================================================================================
00325 
00326 StdMeshers_Prism_3D::~StdMeshers_Prism_3D()
00327 {}
00328 
00329 //=======================================================================
00330 //function : CheckHypothesis
00331 //purpose  : 
00332 //=======================================================================
00333 
00334 bool StdMeshers_Prism_3D::CheckHypothesis(SMESH_Mesh&                          aMesh,
00335                                           const TopoDS_Shape&                  aShape,
00336                                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
00337 {
00338   // Check shape geometry
00339 /*  PAL16229
00340   aStatus = SMESH_Hypothesis::HYP_BAD_GEOMETRY;
00341 
00342   // find not quadrangle faces
00343   list< TopoDS_Shape > notQuadFaces;
00344   int nbEdge, nbWire, nbFace = 0;
00345   TopExp_Explorer exp( aShape, TopAbs_FACE );
00346   for ( ; exp.More(); exp.Next() ) {
00347     ++nbFace;
00348     const TopoDS_Shape& face = exp.Current();
00349     nbEdge = TAssocTool::Count( face, TopAbs_EDGE, 0 );
00350     nbWire = TAssocTool::Count( face, TopAbs_WIRE, 0 );
00351     if (  nbEdge!= 4 || nbWire!= 1 ) {
00352       if ( !notQuadFaces.empty() ) {
00353         if ( TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 ) != nbEdge ||
00354              TAssocTool::Count( notQuadFaces.back(), TopAbs_WIRE, 0 ) != nbWire )
00355           RETURN_BAD_RESULT("Different not quad faces");
00356       }
00357       notQuadFaces.push_back( face );
00358     }
00359   }
00360   if ( !notQuadFaces.empty() )
00361   {
00362     if ( notQuadFaces.size() != 2 )
00363       RETURN_BAD_RESULT("Bad nb not quad faces: " << notQuadFaces.size());
00364 
00365     // check total nb faces
00366     nbEdge = TAssocTool::Count( notQuadFaces.back(), TopAbs_EDGE, 0 );
00367     if ( nbFace != nbEdge + 2 )
00368       RETURN_BAD_RESULT("Bad nb of faces: " << nbFace << " but must be " << nbEdge + 2);
00369   }
00370 */
00371   // no hypothesis
00372   aStatus = SMESH_Hypothesis::HYP_OK;
00373   return true;
00374 }
00375 
00376 //=======================================================================
00377 //function : Compute
00378 //purpose  : 
00379 //=======================================================================
00380 
00381 bool StdMeshers_Prism_3D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape& theShape)
00382 {
00383   SMESH_MesherHelper helper( theMesh );
00384   myHelper = &helper;
00385 
00386   myHelper->IsQuadraticSubMesh( theShape );
00387 
00388   // Analyse mesh and geomerty to find block sub-shapes and submeshes
00389   if ( !myBlock.Init( myHelper, theShape ))
00390     return error( myBlock.GetError());
00391 
00392   SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
00393 
00394   int volumeID = meshDS->ShapeToIndex( theShape );
00395 
00396 
00397   // To compute coordinates of a node inside a block, it is necessary to know
00398   // 1. normalized parameters of the node by which
00399   // 2. coordinates of node projections on all block sub-shapes are computed
00400 
00401   // So we fill projections on vertices at once as they are same for all nodes
00402   myShapeXYZ.resize( myBlock.NbSubShapes() );
00403   for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
00404     myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
00405     SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
00406   }
00407 
00408   // Projections on the top and bottom faces are taken from nodes existing
00409   // on these faces; find correspondence between bottom and top nodes
00410   myBotToColumnMap.clear();
00411   if ( !assocOrProjBottom2Top() ) // it also fills myBotToColumnMap
00412     return false;
00413 
00414 
00415   // Create nodes inside the block
00416 
00417   // try to use transformation (issue 0020680)
00418   vector<gp_Trsf> trsf;
00419   if ( myBlock.GetLayersTransformation(trsf))
00420   {
00421     // loop on nodes inside the bottom face
00422     TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
00423     for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
00424     {
00425       const TNode& tBotNode = bot_column->first; // bottom TNode
00426       if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
00427         continue; // node is not inside face 
00428 
00429       // column nodes; middle part of the column are zero pointers
00430       TNodeColumn& column = bot_column->second;
00431       TNodeColumn::iterator columnNodes = column.begin();
00432       for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
00433       {
00434         const SMDS_MeshNode* & node = *columnNodes;
00435         if ( node ) continue; // skip bottom or top node
00436 
00437         gp_XYZ coords = tBotNode.GetCoords();
00438         trsf[z-1].Transforms( coords );
00439         node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
00440         meshDS->SetNodeInVolume( node, volumeID );
00441       }
00442     } // loop on bottom nodes
00443   }
00444   else // use block approach
00445   {
00446     // loop on nodes inside the bottom face
00447     TNode prevBNode;
00448     TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
00449     for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
00450     {
00451       const TNode& tBotNode = bot_column->first; // bottom TNode
00452       if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
00453         continue; // node is not inside face 
00454 
00455       // column nodes; middle part of the column are zero pointers
00456       TNodeColumn& column = bot_column->second;
00457 
00458       // compute bottom node parameters
00459       gp_XYZ paramHint(-1,-1,-1);
00460       if ( prevBNode.IsNeighbor( tBotNode ))
00461         paramHint = prevBNode.GetParams();
00462       if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
00463                                        ID_BOT_FACE, paramHint ))
00464         return error(TCom("Can't compute normalized parameters for node ")
00465                      << tBotNode.myNode->GetID() << " on the face #"
00466                      << myBlock.SubMesh( ID_BOT_FACE )->GetId() );
00467       prevBNode = tBotNode;
00468 
00469       myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
00470       gp_XYZ botParams          = tBotNode.GetParams();
00471 
00472       // compute top node parameters
00473       myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
00474       gp_XYZ topParams = botParams;
00475       topParams.SetZ( 1 );
00476       if ( column.size() > 2 ) {
00477         gp_Pnt topCoords = myShapeXYZ[ ID_TOP_FACE ];
00478         if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
00479           return error(TCom("Can't compute normalized parameters ")
00480                        << "for node " << column.back()->GetID()
00481                        << " on the face #"<< column.back()->getshapeId() );
00482       }
00483 
00484       // vertical loop
00485       TNodeColumn::iterator columnNodes = column.begin();
00486       for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
00487       {
00488         const SMDS_MeshNode* & node = *columnNodes;
00489         if ( node ) continue; // skip bottom or top node
00490 
00491         // params of a node to create
00492         double rz = (double) z / (double) ( column.size() - 1 );
00493         gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
00494 
00495         // set coords on all faces and nodes
00496         const int nbSideFaces = 4;
00497         int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
00498                                          SMESH_Block::ID_Fx1z,
00499                                          SMESH_Block::ID_F0yz,
00500                                          SMESH_Block::ID_F1yz };
00501         for ( int iF = 0; iF < nbSideFaces; ++iF )
00502           if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
00503             return false;
00504 
00505         // compute coords for a new node
00506         gp_XYZ coords;
00507         if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
00508           return error("Can't compute coordinates by normalized parameters");
00509 
00510         SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
00511         SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
00512         SHOWYXZ("ShellPoint ",coords);
00513 
00514         // create a node
00515         node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
00516         meshDS->SetNodeInVolume( node, volumeID );
00517       }
00518     } // loop on bottom nodes
00519   }
00520 
00521   // Create volumes
00522 
00523   SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
00524   if ( !smDS ) return error(COMPERR_BAD_INPUT_MESH, "Null submesh");
00525 
00526   // loop on bottom mesh faces
00527   SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
00528   while ( faceIt->more() )
00529   {
00530     const SMDS_MeshElement* face = faceIt->next();
00531     if ( !face || face->GetType() != SMDSAbs_Face )
00532       continue;
00533     int nbNodes = face->NbNodes();
00534     if ( face->IsQuadratic() )
00535       nbNodes /= 2;
00536 
00537     // find node columns for each node
00538     vector< const TNodeColumn* > columns( nbNodes );
00539     for ( int i = 0; i < nbNodes; ++i )
00540     {
00541       const SMDS_MeshNode* n = face->GetNode( i );
00542       if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
00543         TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
00544         if ( bot_column == myBotToColumnMap.end() )
00545           return error(TCom("No nodes found above node ") << n->GetID() );
00546         columns[ i ] = & bot_column->second;
00547       }
00548       else {
00549         columns[ i ] = myBlock.GetNodeColumn( n );
00550         if ( !columns[ i ] )
00551           return error(TCom("No side nodes found above node ") << n->GetID() );
00552       }
00553     }
00554     // create prisms
00555     AddPrisms( columns, myHelper );
00556 
00557   } // loop on bottom mesh faces
00558 
00559   // clear data
00560   myBotToColumnMap.clear();
00561   myBlock.Clear();
00562         
00563   return true;
00564 }
00565 
00566 
00567 //=======================================================================
00568 //function : Evaluate
00569 //purpose  : 
00570 //=======================================================================
00571 
00572 bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
00573                                    const TopoDS_Shape& theShape,
00574                                    MapShapeNbElems& aResMap)
00575 {
00576   // find face contains only triangles
00577   vector < SMESH_subMesh * >meshFaces;
00578   TopTools_SequenceOfShape aFaces;
00579   int NumBase = 0, i = 0, NbQFs = 0;
00580   for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
00581     i++;
00582     aFaces.Append(exp.Current());
00583     SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
00584     meshFaces.push_back(aSubMesh);
00585     MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
00586     if( anIt==aResMap.end() ) {
00587       SMESH_ComputeErrorPtr& smError = aSubMesh->GetComputeError();
00588       smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
00589       return false;
00590     }
00591     std::vector<int> aVec = (*anIt).second;
00592     int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
00593     int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
00594     if( nbtri==0 && nbqua>0 ) {
00595       NbQFs++;
00596     }
00597     if( nbtri>0 ) {
00598       NumBase = i;
00599     }
00600   }
00601 
00602   if(NbQFs<4) {
00603     std::vector<int> aResVec(SMDSEntity_Last);
00604     for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
00605     SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
00606     aResMap.insert(std::make_pair(sm,aResVec));
00607     SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
00608     smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
00609     return false;
00610   }
00611 
00612   if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
00613 
00614   // find number of 1d elems for base face
00615   int nb1d = 0;
00616   TopTools_MapOfShape Edges1;
00617   for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
00618     Edges1.Add(exp.Current());
00619     SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
00620     if( sm ) {
00621       MapShapeNbElemsItr anIt = aResMap.find(sm);
00622       if( anIt == aResMap.end() ) continue;
00623       std::vector<int> aVec = (*anIt).second;
00624       nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
00625     }
00626   }
00627   // find face opposite to base face
00628   int OppNum = 0;
00629   for(i=1; i<=6; i++) {
00630     if(i==NumBase) continue;
00631     bool IsOpposite = true;
00632     for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
00633       if( Edges1.Contains(exp.Current()) ) {
00634         IsOpposite = false;
00635         break;
00636       }
00637     }
00638     if(IsOpposite) {
00639       OppNum = i;
00640       break;
00641     }
00642   }
00643   // find number of 2d elems on side faces
00644   int nb2d = 0;
00645   for(i=1; i<=6; i++) {
00646     if( i==OppNum || i==NumBase ) continue;
00647     MapShapeNbElemsItr anIt = aResMap.find( meshFaces[i-1] );
00648     if( anIt == aResMap.end() ) continue;
00649     std::vector<int> aVec = (*anIt).second;
00650     nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
00651   }
00652   
00653   MapShapeNbElemsItr anIt = aResMap.find( meshFaces[NumBase-1] );
00654   std::vector<int> aVec = (*anIt).second;
00655   bool IsQuadratic = (aVec[SMDSEntity_Quad_Triangle]>aVec[SMDSEntity_Triangle]) ||
00656                      (aVec[SMDSEntity_Quad_Quadrangle]>aVec[SMDSEntity_Quadrangle]);
00657   int nb2d_face0_3 = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
00658   int nb2d_face0_4 = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
00659   int nb0d_face0 = aVec[SMDSEntity_Node];
00660   int nb1d_face0_int = ( nb2d_face0_3*3 + nb2d_face0_4*4 - nb1d ) / 2;
00661 
00662   std::vector<int> aResVec(SMDSEntity_Last);
00663   for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
00664   if(IsQuadratic) {
00665     aResVec[SMDSEntity_Quad_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
00666     aResVec[SMDSEntity_Quad_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
00667     aResVec[SMDSEntity_Node] = nb0d_face0 * ( 2*nb2d/nb1d - 1 ) - nb1d_face0_int * nb2d/nb1d;
00668   }
00669   else {
00670     aResVec[SMDSEntity_Node] = nb0d_face0 * ( nb2d/nb1d - 1 );
00671     aResVec[SMDSEntity_Penta] = nb2d_face0_3 * ( nb2d/nb1d );
00672     aResVec[SMDSEntity_Hexa] = nb2d_face0_4 * ( nb2d/nb1d );
00673   }
00674   SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
00675   aResMap.insert(std::make_pair(sm,aResVec));
00676 
00677   return true;
00678 }
00679 
00680 
00681 //================================================================================
00687 //================================================================================
00688 
00689 void StdMeshers_Prism_3D::AddPrisms( vector<const TNodeColumn*> & columns,
00690                                      SMESH_MesherHelper*          helper)
00691 {
00692   SMESHDS_Mesh * meshDS = helper->GetMeshDS();
00693   int shapeID = helper->GetSubShapeID();
00694 
00695   int nbNodes = columns.size();
00696   int nbZ     = columns[0]->size();
00697   if ( nbZ < 2 ) return;
00698 
00699   // find out orientation
00700   bool isForward = true;
00701   SMDS_VolumeTool vTool;
00702   int z = 1;
00703   switch ( nbNodes ) {
00704   case 3: {
00705     const SMDS_MeshNode* botNodes[3] = { (*columns[0])[z-1],
00706                                          (*columns[1])[z-1],
00707                                          (*columns[2])[z-1] };
00708     const SMDS_MeshNode* topNodes[3] = { (*columns[0])[z],
00709                                          (*columns[1])[z],
00710                                          (*columns[2])[z] };
00711     SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2],
00712                                 topNodes[0], topNodes[1], topNodes[2]);
00713     vTool.Set( &tmpVol );
00714     isForward  = vTool.IsForward();
00715     break;
00716   }
00717   case 4: {
00718     const SMDS_MeshNode* botNodes[4] = { (*columns[0])[z-1], (*columns[1])[z-1],
00719                                          (*columns[2])[z-1], (*columns[3])[z-1] };
00720     const SMDS_MeshNode* topNodes[4] = { (*columns[0])[z], (*columns[1])[z],
00721                                          (*columns[2])[z], (*columns[3])[z] };
00722     SMDS_VolumeOfNodes tmpVol ( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
00723                                 topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
00724     vTool.Set( &tmpVol );
00725     isForward  = vTool.IsForward();
00726     break;
00727   }
00728   }
00729 
00730   // vertical loop on columns
00731   for ( z = 1; z < nbZ; ++z )
00732   {
00733     SMDS_MeshElement* vol = 0;
00734     switch ( nbNodes ) {
00735 
00736     case 3: {
00737       const SMDS_MeshNode* botNodes[3] = { (*columns[0])[z-1],
00738                                            (*columns[1])[z-1],
00739                                            (*columns[2])[z-1] };
00740       const SMDS_MeshNode* topNodes[3] = { (*columns[0])[z],
00741                                            (*columns[1])[z],
00742                                            (*columns[2])[z] };
00743       if ( isForward )
00744         vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2],
00745                                  topNodes[0], topNodes[1], topNodes[2]);
00746       else
00747         vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2],
00748                                  botNodes[0], botNodes[1], botNodes[2]);
00749       break;
00750       }
00751     case 4: {
00752       const SMDS_MeshNode* botNodes[4] = { (*columns[0])[z-1], (*columns[1])[z-1],
00753                                            (*columns[2])[z-1], (*columns[3])[z-1] };
00754       const SMDS_MeshNode* topNodes[4] = { (*columns[0])[z], (*columns[1])[z],
00755                                            (*columns[2])[z], (*columns[3])[z] };
00756       if ( isForward )
00757         vol = helper->AddVolume( botNodes[0], botNodes[1], botNodes[2], botNodes[3],
00758                                  topNodes[0], topNodes[1], topNodes[2], topNodes[3]);
00759       else
00760         vol = helper->AddVolume( topNodes[0], topNodes[1], topNodes[2], topNodes[3],
00761                                  botNodes[0], botNodes[1], botNodes[2], botNodes[3]);
00762       break;
00763       }
00764     default:
00765       // polyhedron
00766       vector<const SMDS_MeshNode*> nodes( 2*nbNodes + 4*nbNodes);
00767       vector<int> quantities( 2 + nbNodes, 4 );
00768       quantities[0] = quantities[1] = nbNodes;
00769       columns.resize( nbNodes + 1 );
00770       columns[ nbNodes ] = columns[ 0 ];
00771       for ( int i = 0; i < nbNodes; ++i ) {
00772         nodes[ i         ] = (*columns[ i ])[z-1]; // bottom
00773         nodes[ i+nbNodes ] = (*columns[ i ])[z  ]; // top
00774         // side
00775         int di = 2*nbNodes + 4*i - 1;
00776         nodes[ di   ] = (*columns[i  ])[z-1];
00777         nodes[ di+1 ] = (*columns[i+1])[z-1];
00778         nodes[ di+2 ] = (*columns[i+1])[z  ];
00779         nodes[ di+3 ] = (*columns[i  ])[z  ];
00780       }
00781       vol = meshDS->AddPolyhedralVolume( nodes, quantities );
00782     }
00783     if ( vol && shapeID > 0 )
00784       meshDS->SetMeshElementOnShape( vol, shapeID );
00785   }
00786 }
00787 
00788 //================================================================================
00795 //================================================================================
00796 
00797 bool StdMeshers_Prism_3D::assocOrProjBottom2Top()
00798 {
00799   SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
00800   SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
00801 
00802   SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
00803   SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
00804 
00805   if ( !botSMDS || botSMDS->NbElements() == 0 )
00806     return error(TCom("No elememts on face #") << botSM->GetId());
00807 
00808   bool needProject = false;
00809   if ( !topSMDS || 
00810        botSMDS->NbElements() != topSMDS->NbElements() ||
00811        botSMDS->NbNodes()    != topSMDS->NbNodes())
00812   {
00813     MESSAGE("nb elem bot " << botSMDS->NbElements() << " top " << topSMDS->NbElements());
00814     MESSAGE("nb node bot " << botSMDS->NbNodes() << " top " << topSMDS->NbNodes());
00815     if ( myBlock.HasNotQuadElemOnTop() )
00816       return error(TCom("Mesh on faces #") << botSM->GetId()
00817                    <<" and #"<< topSM->GetId() << " seems different" );
00818     needProject = true;
00819   }
00820 
00821   if ( 0/*needProject && !myProjectTriangles*/ )
00822     return error(TCom("Mesh on faces #") << botSM->GetId()
00823                  <<" and #"<< topSM->GetId() << " seems different" );
00825 
00826   if ( needProject )
00827   {
00828     return projectBottomToTop();
00829   }
00830 
00831   TopoDS_Face botFace = TopoDS::Face( myBlock.Shape( ID_BOT_FACE ));
00832   TopoDS_Face topFace = TopoDS::Face( myBlock.Shape( ID_TOP_FACE ));
00833   // associate top and bottom faces
00834   TAssocTool::TShapeShapeMap shape2ShapeMap;
00835   if ( !TAssocTool::FindSubShapeAssociation( botFace, myBlock.Mesh(),
00836                                              topFace, myBlock.Mesh(),
00837                                              shape2ShapeMap) )
00838     return error(TCom("Topology of faces #") << botSM->GetId()
00839                  <<" and #"<< topSM->GetId() << " seems different" );
00840 
00841   // Find matching nodes of top and bottom faces
00842   TNodeNodeMap n2nMap;
00843   if ( ! TAssocTool::FindMatchingNodesOnFaces( botFace, myBlock.Mesh(),
00844                                                topFace, myBlock.Mesh(),
00845                                                shape2ShapeMap, n2nMap ))
00846     return error(TCom("Mesh on faces #") << botSM->GetId()
00847                  <<" and #"<< topSM->GetId() << " seems different" );
00848 
00849   // Fill myBotToColumnMap
00850 
00851   int zSize = myBlock.VerticalSize();
00852   //TNode prevTNode;
00853   TNodeNodeMap::iterator bN_tN = n2nMap.begin();
00854   for ( ; bN_tN != n2nMap.end(); ++bN_tN )
00855   {
00856     const SMDS_MeshNode* botNode = bN_tN->first;
00857     const SMDS_MeshNode* topNode = bN_tN->second;
00858     if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
00859       continue; // wall columns are contained in myBlock
00860     // create node column
00861     TNode bN( botNode );
00862     TNode2ColumnMap::iterator bN_col = 
00863       myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
00864     TNodeColumn & column = bN_col->second;
00865     column.resize( zSize );
00866     column.front() = botNode;
00867     column.back()  = topNode;
00868   }
00869   return true;
00870 }
00871 
00872 //================================================================================
00878 //================================================================================
00879 
00880 bool StdMeshers_Prism_3D::projectBottomToTop()
00881 {
00882   SMESH_subMesh * botSM = myBlock.SubMesh( ID_BOT_FACE );
00883   SMESH_subMesh * topSM = myBlock.SubMesh( ID_TOP_FACE );
00884 
00885   SMESHDS_SubMesh * botSMDS = botSM->GetSubMeshDS();
00886   SMESHDS_SubMesh * topSMDS = topSM->GetSubMeshDS();
00887 
00888   if ( topSMDS )
00889     topSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
00890 
00891   SMESHDS_Mesh* meshDS = myBlock.MeshDS();
00892   int shapeID = myHelper->GetSubShapeID();
00893   int topFaceID = meshDS->ShapeToIndex( topSM->GetSubShape() );
00894 
00895   // Fill myBotToColumnMap
00896 
00897   int zSize = myBlock.VerticalSize();
00898   TNode prevTNode;
00899   SMDS_NodeIteratorPtr nIt = botSMDS->GetNodes();
00900   while ( nIt->more() )
00901   {
00902     const SMDS_MeshNode* botNode = nIt->next();
00903     if ( botNode->GetPosition()->GetTypeOfPosition() != SMDS_TOP_FACE )
00904       continue; // strange
00905     // compute bottom node params
00906     TNode bN( botNode );
00907     gp_XYZ paramHint(-1,-1,-1);
00908     if ( prevTNode.IsNeighbor( bN ))
00909       paramHint = prevTNode.GetParams();
00910     if ( !myBlock.ComputeParameters( bN.GetCoords(), bN.ChangeParams(),
00911                                      ID_BOT_FACE, paramHint ))
00912       return error(TCom("Can't compute normalized parameters for node ")
00913                    << botNode->GetID() << " on the face #"<< botSM->GetId() );
00914     prevTNode = bN;
00915     // compute top node coords
00916     gp_XYZ topXYZ; gp_XY topUV;
00917     if ( !myBlock.FacePoint( ID_TOP_FACE, bN.GetParams(), topXYZ ) ||
00918          !myBlock.FaceUV   ( ID_TOP_FACE, bN.GetParams(), topUV ))
00919       return error(TCom("Can't compute coordinates "
00920                         "by normalized parameters on the face #")<< topSM->GetId() );
00921     SMDS_MeshNode * topNode = meshDS->AddNode( topXYZ.X(),topXYZ.Y(),topXYZ.Z() );
00922     meshDS->SetNodeOnFace( topNode, topFaceID, topUV.X(), topUV.Y() );
00923     // create node column
00924     TNode2ColumnMap::iterator bN_col = 
00925       myBotToColumnMap.insert( make_pair ( bN, TNodeColumn() )).first;
00926     TNodeColumn & column = bN_col->second;
00927     column.resize( zSize );
00928     column.front() = botNode;
00929     column.back()  = topNode;
00930   }
00931 
00932   // Create top faces
00933 
00934   // loop on bottom mesh faces
00935   SMDS_ElemIteratorPtr faceIt = botSMDS->GetElements();
00936   while ( faceIt->more() )
00937   {
00938     const SMDS_MeshElement* face = faceIt->next();
00939     if ( !face || face->GetType() != SMDSAbs_Face )
00940       continue;
00941     int nbNodes = face->NbNodes();
00942     if ( face->IsQuadratic() )
00943       nbNodes /= 2;
00944 
00945     // find top node in columns for each bottom node
00946     vector< const SMDS_MeshNode* > nodes( nbNodes );
00947     for ( int i = 0; i < nbNodes; ++i )
00948     {
00949       const SMDS_MeshNode* n = face->GetNode( nbNodes - i - 1 );
00950       if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
00951         TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
00952         if ( bot_column == myBotToColumnMap.end() )
00953           return error(TCom("No nodes found above node ") << n->GetID() );
00954         nodes[ i ] = bot_column->second.back();
00955       }
00956       else {
00957         const TNodeColumn* column = myBlock.GetNodeColumn( n );
00958         if ( !column )
00959           return error(TCom("No side nodes found above node ") << n->GetID() );
00960         nodes[ i ] = column->back();
00961       }
00962     }
00963     // create a face, with reversed orientation
00964     SMDS_MeshElement* newFace = 0;
00965     switch ( nbNodes ) {
00966 
00967     case 3: {
00968       newFace = myHelper->AddFace(nodes[0], nodes[1], nodes[2]);
00969       break;
00970       }
00971     case 4: {
00972       newFace = myHelper->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] );
00973       break;
00974       }
00975     default:
00976       newFace = meshDS->AddPolygonalFace( nodes );
00977     }
00978     if ( newFace && shapeID > 0 )
00979       meshDS->SetMeshElementOnShape( newFace, shapeID );
00980   }
00981 
00982   return true;
00983 }
00984 
00985 //================================================================================
00992 //================================================================================
00993 
00994 bool StdMeshers_Prism_3D::setFaceAndEdgesXYZ( const int faceID, const gp_XYZ& params, int z )
00995 {
00996   // find base and top edges of the face
00997   enum { BASE = 0, TOP, LEFT, RIGHT };
00998   vector< int > edgeVec; // 0-base, 1-top
00999   SMESH_Block::GetFaceEdgesIDs( faceID, edgeVec );
01000 
01001   myBlock.EdgePoint( edgeVec[ BASE ], params, myShapeXYZ[ edgeVec[ BASE ]]);
01002   myBlock.EdgePoint( edgeVec[ TOP  ], params, myShapeXYZ[ edgeVec[ TOP ]]);
01003 
01004   SHOWYXZ("\nparams ", params);
01005   SHOWYXZ("TOP is " <<edgeVec[ TOP ], myShapeXYZ[ edgeVec[ TOP]]);
01006   SHOWYXZ("BASE is "<<edgeVec[ BASE], myShapeXYZ[ edgeVec[ BASE]]);
01007 
01008   if ( faceID == SMESH_Block::ID_Fx0z || faceID == SMESH_Block::ID_Fx1z )
01009   {
01010     myBlock.EdgePoint( edgeVec[ LEFT ], params, myShapeXYZ[ edgeVec[ LEFT ]]);
01011     myBlock.EdgePoint( edgeVec[ RIGHT ], params, myShapeXYZ[ edgeVec[ RIGHT ]]);
01012 
01013     SHOWYXZ("VER "<<edgeVec[ LEFT], myShapeXYZ[ edgeVec[ LEFT]]);
01014     SHOWYXZ("VER "<<edgeVec[ RIGHT], myShapeXYZ[ edgeVec[ RIGHT]]);
01015   }
01016   myBlock.FacePoint( faceID, params, myShapeXYZ[ faceID ]);
01017   SHOWYXZ("FacePoint "<<faceID, myShapeXYZ[ faceID]);
01018 
01019   return true;
01020 }
01021 
01022 //================================================================================
01026 //================================================================================
01027 
01028 bool TNode::IsNeighbor( const TNode& other ) const
01029 {
01030   if ( !other.myNode || !myNode ) return false;
01031 
01032   SMDS_ElemIteratorPtr fIt = other.myNode->GetInverseElementIterator(SMDSAbs_Face);
01033   while ( fIt->more() )
01034     if ( fIt->next()->GetNodeIndex( myNode ) >= 0 )
01035       return true;
01036   return false;
01037 }
01038 
01039 //================================================================================
01043 //================================================================================
01044 
01045 StdMeshers_PrismAsBlock::StdMeshers_PrismAsBlock()
01046 {
01047   mySide = 0;
01048 }
01049 
01050 StdMeshers_PrismAsBlock::~StdMeshers_PrismAsBlock()
01051 {
01052   Clear();
01053 }
01054 void StdMeshers_PrismAsBlock::Clear()
01055 {
01056   myHelper = 0;
01057   myShapeIDMap.Clear();
01058   myError.reset();
01059 
01060   if ( mySide ) {
01061     delete mySide; mySide = 0;
01062   }
01063   myParam2ColumnMaps.clear();
01064   myShapeIndex2ColumnMap.clear();
01065 }
01066 
01067 //================================================================================
01074 //================================================================================
01075 
01076 bool StdMeshers_PrismAsBlock::Init(SMESH_MesherHelper* helper,
01077                                    const TopoDS_Shape& shape3D)
01078 {
01079   if ( mySide ) {
01080     delete mySide; mySide = 0;
01081   }
01082   vector< TSideFace* > sideFaces( NB_WALL_FACES, 0 );
01083   vector< pair< double, double> > params ( NB_WALL_FACES );
01084   mySide = new TSideFace( sideFaces, params );
01085 
01086   myHelper = helper;
01087   SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
01088 
01089   SMESH_Block::init();
01090   myShapeIDMap.Clear();
01091   myShapeIndex2ColumnMap.clear();
01092   
01093   int wallFaceIds[ NB_WALL_FACES ] = { // to walk around a block
01094     SMESH_Block::ID_Fx0z, SMESH_Block::ID_F1yz,
01095     SMESH_Block::ID_Fx1z, SMESH_Block::ID_F0yz
01096   };
01097 
01098   myError = SMESH_ComputeError::New();
01099 
01100   // -------------------------------------------------------------
01101   // Look for top and bottom faces: not quadrangle ones or meshed
01102   // with not quadrangle elements
01103   // -------------------------------------------------------------
01104 
01105   list< SMESH_subMesh* > notQuadGeomSubMesh;
01106   list< SMESH_subMesh* > notQuadElemSubMesh;
01107   int nbFaces = 0;
01108   //
01109   SMESH_subMesh* mainSubMesh = myHelper->GetMesh()->GetSubMeshContaining( shape3D );
01110   if ( !mainSubMesh ) return error(COMPERR_BAD_INPUT_MESH,"Null submesh of shape3D");
01111 
01112   // analyse face submeshes
01113   SMESH_subMeshIteratorPtr smIt = mainSubMesh->getDependsOnIterator(false,false);
01114   while ( smIt->more() )
01115   {
01116     SMESH_subMesh* sm = smIt->next();
01117     const TopoDS_Shape& face = sm->GetSubShape();
01118     if ( face.ShapeType() != TopAbs_FACE )
01119       continue;
01120     nbFaces++;
01121 
01122     // is quadrangle face?
01123     list< TopoDS_Edge > orderedEdges;
01124     list< int >         nbEdgesInWires;
01125     TopoDS_Vertex       V000;
01126     int nbWires = GetOrderedEdges( TopoDS::Face( face ),
01127                                    V000, orderedEdges, nbEdgesInWires );
01128     if ( nbWires != 1 || nbEdgesInWires.front() != 4 )
01129       notQuadGeomSubMesh.push_back( sm );
01130 
01131     // look for not quadrangle mesh elements
01132     if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) {
01133       bool hasNotQuad = false;
01134       SMDS_ElemIteratorPtr eIt = smDS->GetElements();
01135       while ( eIt->more() && !hasNotQuad ) {
01136         const SMDS_MeshElement* elem = eIt->next();
01137         if ( elem->GetType() == SMDSAbs_Face ) {
01138           int nbNodes = elem->NbNodes();
01139           if ( elem->IsQuadratic() )
01140             nbNodes /= 2;
01141           hasNotQuad = ( nbNodes != 4 );
01142         }
01143       }
01144       if ( hasNotQuad )
01145         notQuadElemSubMesh.push_back( sm );
01146     }
01147     else {
01148       return error(COMPERR_BAD_INPUT_MESH,TCom("Not meshed face #")<<sm->GetId());
01149     }
01150     // check if a quadrangle face is meshed with a quadranglar grid
01151     if ( notQuadGeomSubMesh.back() != sm &&
01152          notQuadElemSubMesh.back() != sm )
01153     {
01154       // count nb edges on face sides
01155       vector< int > nbEdges;
01156       nbEdges.reserve( nbEdgesInWires.front() );
01157       for ( list< TopoDS_Edge >::iterator edge = orderedEdges.begin();
01158             edge != orderedEdges.end(); ++edge )
01159       {
01160         if ( SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edge ))
01161           nbEdges.push_back ( smDS->NbElements() );
01162         else
01163           nbEdges.push_back ( 0 );
01164       }
01165       int nbQuads = sm->GetSubMeshDS()->NbElements();
01166       if ( nbEdges[0] *  nbEdges[1] != nbQuads ||
01167            nbEdges[0] != nbEdges[2] ||
01168            nbEdges[1] != nbEdges[3] )
01169         notQuadElemSubMesh.push_back( sm );
01170     }
01171   }
01172 
01173   // ----------------------------------------------------------------------
01174   // Analyse mesh and topology of faces: choose the bottom submesh.
01175   // If there are not quadrangle geom faces, they are top and bottom ones.
01176   // Not quadrangle geom faces must be only on top and bottom.
01177   // ----------------------------------------------------------------------
01178 
01179   SMESH_subMesh * botSM = 0;
01180   SMESH_subMesh * topSM = 0;
01181 
01182   int nbNotQuad       = notQuadGeomSubMesh.size();
01183   int nbNotQuadMeshed = notQuadElemSubMesh.size();
01184   bool hasNotQuad = ( nbNotQuad || nbNotQuadMeshed );
01185 
01186   // detect bad cases
01187   if ( nbNotQuadMeshed > 2 )
01188   {
01189     return error(COMPERR_BAD_INPUT_MESH,
01190                  TCom("More than 2 faces with not quadrangle elements: ")
01191                  <<nbNotQuadMeshed);
01192   }
01193   int nbQuasiQuads = 0;
01194   if ( nbNotQuad > 0 && nbNotQuad != 2 )
01195   {
01196     // Issue 0020843 - one of side faces is quasi-quadrilateral.
01197     // Remove from notQuadGeomSubMesh faces meshed with regular grid
01198     nbQuasiQuads = removeQuasiQuads( notQuadGeomSubMesh );
01199     nbNotQuad -= nbQuasiQuads;
01200     if ( nbNotQuad > 0 && nbNotQuad != 2 )
01201       return error(COMPERR_BAD_SHAPE,
01202                    TCom("More than 2 not quadrilateral faces: ")
01203                    <<nbNotQuad);
01204   }
01205 
01206   // get found submeshes
01207   if ( hasNotQuad )
01208   {
01209     if ( nbNotQuadMeshed > 0 ) botSM = notQuadElemSubMesh.front();
01210     else                       botSM = notQuadGeomSubMesh.front();
01211     if ( nbNotQuadMeshed > 1 ) topSM = notQuadElemSubMesh.back();
01212     else if ( nbNotQuad  > 1 ) topSM = notQuadGeomSubMesh.back();
01213   }
01214   // detect other bad cases
01215   if ( nbNotQuad == 2 && nbNotQuadMeshed > 0 ) {
01216     bool ok = false;
01217     if ( nbNotQuadMeshed == 1 )
01218       ok = ( find( notQuadGeomSubMesh.begin(),
01219                    notQuadGeomSubMesh.end(), botSM ) != notQuadGeomSubMesh.end() );
01220     else
01221       ok = ( notQuadGeomSubMesh == notQuadElemSubMesh );
01222     if ( !ok )
01223       return error(COMPERR_BAD_INPUT_MESH, "Side face meshed with not quadrangle elements");
01224   }
01225 
01226   myNotQuadOnTop = ( nbNotQuadMeshed > 1 );
01227   MESSAGE("myNotQuadOnTop " << myNotQuadOnTop << " nbNotQuadMeshed " << nbNotQuadMeshed);
01228  
01229   // ----------------------------------------------------------
01230 
01231   if ( nbNotQuad == 0 ) // Standard block of 6 quadrangle faces ?
01232   {
01233     // SMESH_Block will perform geometry analysis, we need just to find 2
01234     // connected vertices on top and bottom
01235 
01236     TopoDS_Vertex Vbot, Vtop;
01237     if ( nbNotQuadMeshed > 0 ) // Look for vertices
01238     {
01239       TopTools_IndexedMapOfShape edgeMap;
01240       TopExp::MapShapes( botSM->GetSubShape(), TopAbs_EDGE, edgeMap );
01241       // vertex 1 is any vertex of the bottom face
01242       Vbot = TopExp::FirstVertex( TopoDS::Edge( edgeMap( 1 )));
01243       // vertex 2 is end vertex of edge sharing Vbot and not belonging to the bottom face
01244       TopTools_ListIteratorOfListOfShape ancestIt = Mesh()->GetAncestors( Vbot );
01245       for ( ; Vtop.IsNull() && ancestIt.More(); ancestIt.Next() )
01246       {
01247         const TopoDS_Shape & ancestor = ancestIt.Value();
01248         if ( ancestor.ShapeType() == TopAbs_EDGE && !edgeMap.FindIndex( ancestor ))
01249         {
01250           TopoDS_Vertex V1, V2;
01251           TopExp::Vertices( TopoDS::Edge( ancestor ), V1, V2);
01252           if      ( Vbot.IsSame ( V1 )) Vtop = V2;
01253           else if ( Vbot.IsSame ( V2 )) Vtop = V1;
01254           // check that Vtop belongs to shape3D
01255           TopExp_Explorer exp( shape3D, TopAbs_VERTEX );
01256           for ( ; exp.More(); exp.Next() )
01257             if ( Vtop.IsSame( exp.Current() ))
01258               break;
01259           if ( !exp.More() )
01260             Vtop.Nullify();
01261         }
01262       }
01263     }
01264     // get shell from shape3D
01265     TopoDS_Shell shell;
01266     TopExp_Explorer exp( shape3D, TopAbs_SHELL );
01267     int nbShell = 0;
01268     for ( ; exp.More(); exp.Next(), ++nbShell )
01269       shell = TopoDS::Shell( exp.Current() );
01270 //     if ( nbShell != 1 )
01271 //       RETURN_BAD_RESULT("There must be 1 shell in the block");
01272 
01273     // Load geometry in SMESH_Block
01274     if ( !SMESH_Block::FindBlockShapes( shell, Vbot, Vtop, myShapeIDMap )) {
01275       if ( !hasNotQuad )
01276         return error(COMPERR_BAD_SHAPE, "Can't detect top and bottom of a prism");
01277     }
01278     else {
01279       if ( !botSM ) botSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_BOT_FACE ));
01280       if ( !topSM ) topSM = Mesh()->GetSubMeshContaining( myShapeIDMap( ID_TOP_FACE ));
01281     }
01282 
01283   } // end  Standard block of 6 quadrangle faces
01284   // --------------------------------------------------------
01285 
01286   // Here the top and bottom faces are found
01287   if ( nbNotQuadMeshed == 2 ) // roughly check correspondence of horiz meshes
01288   {
01289 //     SMESHDS_SubMesh* topSMDS = topSM->GetSubMeshDS();
01290 //     SMESHDS_SubMesh* botSMDS = botSM->GetSubMeshDS();
01291 //     if ( topSMDS->NbNodes() != botSMDS->NbNodes() ||
01292 //          topSMDS->NbElements() != botSMDS->NbElements() )
01293 //       RETURN_BAD_RESULT("Top mesh doesn't correspond to bottom one");
01294   }
01295 
01296   // ---------------------------------------------------------
01297   // If there are not quadrangle geom faces, we emulate
01298   // a block of 6 quadrangle faces.
01299   // Load SMESH_Block with faces and edges geometry
01300   // ---------------------------------------------------------
01301 
01302   
01303   // find vertex 000 - the one with smallest coordinates (for easy DEBUG :-)
01304   TopoDS_Vertex V000;
01305   double minVal = DBL_MAX, minX, val;
01306   for ( TopExp_Explorer exp( botSM->GetSubShape(), TopAbs_VERTEX );
01307         exp.More(); exp.Next() )
01308   {
01309     const TopoDS_Vertex& v = TopoDS::Vertex( exp.Current() );
01310     gp_Pnt P = BRep_Tool::Pnt( v );
01311     val = P.X() + P.Y() + P.Z();
01312     if ( val < minVal || ( val == minVal && P.X() < minX )) {
01313       V000 = v;
01314       minVal = val;
01315       minX = P.X();
01316     }
01317   }
01318 
01319   // Get ordered bottom edges
01320   list< TopoDS_Edge > orderedEdges;
01321   list< int >         nbEInW;
01322   SMESH_Block::GetOrderedEdges( TopoDS::Face( botSM->GetSubShape().Reversed() ),
01323                                 V000, orderedEdges, nbEInW );
01324 //   if ( nbEInW.size() != 1 )
01325 //     RETURN_BAD_RESULT("Wrong prism geometry");
01326 
01327   // Get Wall faces corresponding to the ordered bottom edges
01328   list< TopoDS_Face > wallFaces;
01329   if ( !GetWallFaces( Mesh(), shape3D, botSM->GetSubShape(), orderedEdges, nbEInW, wallFaces))
01330     return error(COMPERR_BAD_SHAPE, "Can't find side faces");
01331 
01332   // check that the found top and bottom faces are opposite
01333   {
01334     for (TopExp_Explorer edge(botSM->GetSubShape(), TopAbs_EDGE); edge.More(); edge.Next())
01335       if ( helper->IsSubShape( edge.Current(), topSM->GetSubShape() ))
01336         return error(notQuadGeomSubMesh.empty() ? COMPERR_BAD_INPUT_MESH : COMPERR_BAD_SHAPE,
01337                      "Non-quadrilateral faces are not opposite");
01338   }
01339 
01340   // Protect from a distorted block (test 3D_mesh_HEXA3D/B7 on 32bit platform)
01341   // check that all wall faces have an edge common with the top face
01342   {
01343     list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
01344     for ( ; faceIt != wallFaces.end(); ++faceIt )
01345     {
01346       bool hasCommon = false;
01347       for (TopExp_Explorer edge(*faceIt, TopAbs_EDGE); !hasCommon && edge.More(); edge.Next())
01348         if ( helper->IsSubShape( edge.Current(), topSM->GetSubShape() ))
01349           hasCommon = true;
01350       if ( !hasCommon )
01351         return error(COMPERR_BAD_SHAPE);
01352     }
01353   }
01354 
01355   // Find columns of wall nodes and calculate edges' lengths
01356   // --------------------------------------------------------
01357 
01358   myParam2ColumnMaps.clear();
01359   myParam2ColumnMaps.resize( orderedEdges.size() ); // total nb edges
01360 
01361   int iE, nbEdges = nbEInW.front(); // nb outer edges
01362   vector< double > edgeLength( nbEdges );
01363   map< double, int > len2edgeMap;
01364 
01365   list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
01366   list< TopoDS_Face >::iterator faceIt = wallFaces.begin();
01367   for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
01368   {
01369     TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
01370     if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
01371       return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
01372                    << "on a side face #" << MeshDS()->ShapeToIndex( *faceIt ));
01373 
01374     SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
01375     SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
01376     SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
01377 
01378     edgeLength[ iE ] = SMESH_Algo::EdgeLength( *edgeIt );
01379 
01380     if ( nbEdges < NB_WALL_FACES ) // fill map used to split faces
01381     {
01382       SMESHDS_SubMesh* smDS = meshDS->MeshElements( *edgeIt);
01383       if ( !smDS )
01384         return error(COMPERR_BAD_INPUT_MESH, TCom("Null submesh on the edge #")
01385                      << MeshDS()->ShapeToIndex( *edgeIt ));
01386       // assure length uniqueness
01387       edgeLength[ iE ] *= smDS->NbNodes() + edgeLength[ iE ] / ( 1000 + iE );
01388       len2edgeMap[ edgeLength[ iE ]] = iE;
01389     }
01390     ++iE;
01391   }
01392   // Load columns of internal edges (forming holes)
01393   // and fill map ShapeIndex to TParam2ColumnMap for them
01394   for ( ; edgeIt != orderedEdges.end() ; ++edgeIt, ++faceIt )
01395   {
01396     TParam2ColumnMap & faceColumns = myParam2ColumnMaps[ iE ];
01397     if ( !myHelper->LoadNodeColumns( faceColumns, *faceIt, *edgeIt, meshDS ))
01398       return error(COMPERR_BAD_INPUT_MESH, TCom("Can't find regular quadrangle mesh ")
01399                    << "on a side face #" << MeshDS()->ShapeToIndex( *faceIt ));
01400     // edge columns
01401     int id = MeshDS()->ShapeToIndex( *edgeIt );
01402     bool isForward = true; // meaningless for intenal wires
01403     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
01404     // columns for vertices
01405     // 1
01406     const SMDS_MeshNode* n0 = faceColumns.begin()->second.front();
01407     id = n0->getshapeId();
01408     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
01409     // 2
01410     const SMDS_MeshNode* n1 = faceColumns.rbegin()->second.front();
01411     id = n1->getshapeId();
01412     myShapeIndex2ColumnMap[ id ] = make_pair( & faceColumns, isForward );
01413 //     SHOWYXZ("\np1 F "<<iE, gpXYZ(faceColumns.begin()->second.front() ));
01414 //     SHOWYXZ("p2 F "<<iE, gpXYZ(faceColumns.rbegin()->second.front() ));
01415 //     SHOWYXZ("V First "<<iE, BRep_Tool::Pnt( TopExp::FirstVertex(*edgeIt,true )));
01416     ++iE;
01417   }
01418 
01419   // Create 4 wall faces of a block
01420   // -------------------------------
01421 
01422   if ( nbEdges <= NB_WALL_FACES ) // ************* Split faces if necessary
01423   {
01424     map< int, int > iE2nbSplit;
01425     if ( nbEdges != NB_WALL_FACES ) // define how to split
01426     {
01427       if ( len2edgeMap.size() != nbEdges )
01428         RETURN_BAD_RESULT("Uniqueness of edge lengths not assured");
01429       map< double, int >::reverse_iterator maxLen_i = len2edgeMap.rbegin();
01430       map< double, int >::reverse_iterator midLen_i = ++len2edgeMap.rbegin();
01431       double maxLen = maxLen_i->first;
01432       double midLen = ( len2edgeMap.size() == 1 ) ? 0 : midLen_i->first;
01433       switch ( nbEdges ) {
01434       case 1: // 0-th edge is split into 4 parts
01435         iE2nbSplit.insert( make_pair( 0, 4 )); break;
01436       case 2: // either the longest edge is split into 3 parts, or both edges into halves
01437         if ( maxLen / 3 > midLen / 2 ) {
01438           iE2nbSplit.insert( make_pair( maxLen_i->second, 3 ));
01439         }
01440         else {
01441           iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
01442           iE2nbSplit.insert( make_pair( midLen_i->second, 2 ));
01443         }
01444         break;
01445       case 3:
01446         // split longest into halves
01447         iE2nbSplit.insert( make_pair( maxLen_i->second, 2 ));
01448       }
01449     }
01450     // Create TSideFace's
01451     faceIt = wallFaces.begin();
01452     edgeIt = orderedEdges.begin();
01453     int iSide = 0;
01454     for ( iE = 0; iE < nbEdges; ++edgeIt, ++faceIt )
01455     {
01456      // split?
01457       map< int, int >::iterator i_nb = iE2nbSplit.find( iE );
01458       if ( i_nb != iE2nbSplit.end() ) {
01459         // split!
01460         int nbSplit = i_nb->second;
01461         vector< double > params;
01462         splitParams( nbSplit, &myParam2ColumnMaps[ iE ], params );
01463         const bool isForward =
01464           StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
01465                                                   myParam2ColumnMaps[iE],
01466                                                   *edgeIt, SMESH_Block::ID_Fx0z );
01467         for ( int i = 0; i < nbSplit; ++i ) {
01468           double f = ( isForward ? params[ i ]   : params[ nbSplit - i-1 ]);
01469           double l = ( isForward ? params[ i+1 ] : params[ nbSplit - i ]);
01470           TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
01471                                            *faceIt, *edgeIt,
01472                                            &myParam2ColumnMaps[ iE ], f, l );
01473           mySide->SetComponent( iSide++, comp );
01474         }
01475       }
01476       else {
01477         TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
01478                                          *faceIt, *edgeIt,
01479                                          &myParam2ColumnMaps[ iE ]);
01480         mySide->SetComponent( iSide++, comp );
01481       }
01482       ++iE;
01483     }
01484   }
01485   else { // **************************** Unite faces
01486 
01487     // unite first faces
01488     int nbExraFaces = nbEdges - 3;
01489     int iSide = 0, iE;
01490     double u0 = 0, sumLen = 0;
01491     for ( iE = 0; iE < nbExraFaces; ++iE )
01492       sumLen += edgeLength[ iE ];
01493 
01494     vector< TSideFace* > components( nbExraFaces );
01495     vector< pair< double, double> > params( nbExraFaces );
01496     faceIt = wallFaces.begin();
01497     edgeIt = orderedEdges.begin();
01498     for ( iE = 0; iE < nbExraFaces; ++edgeIt, ++faceIt )
01499     {
01500       components[ iE ] = new TSideFace( myHelper, wallFaceIds[ iSide ],
01501                                         *faceIt, *edgeIt,
01502                                         &myParam2ColumnMaps[ iE ]);
01503       double u1 = u0 + edgeLength[ iE ] / sumLen;
01504       params[ iE ] = make_pair( u0 , u1 );
01505       u0 = u1;
01506       ++iE;
01507     }
01508     mySide->SetComponent( iSide++, new TSideFace( components, params ));
01509 
01510     // fill the rest faces
01511     for ( ; iE < nbEdges; ++faceIt, ++edgeIt )
01512     {
01513       TSideFace* comp = new TSideFace( myHelper, wallFaceIds[ iSide ],
01514                                        *faceIt, *edgeIt,
01515                                        &myParam2ColumnMaps[ iE ]);
01516       mySide->SetComponent( iSide++, comp );
01517       ++iE;
01518     }
01519   }
01520 
01521 
01522   // Fill geometry fields of SMESH_Block
01523   // ------------------------------------
01524 
01525   TopoDS_Face botF = TopoDS::Face( botSM->GetSubShape() );
01526   TopoDS_Face topF = TopoDS::Face( topSM->GetSubShape() );
01527 
01528   vector< int > botEdgeIdVec;
01529   SMESH_Block::GetFaceEdgesIDs( ID_BOT_FACE, botEdgeIdVec );
01530 
01531   bool isForward[NB_WALL_FACES] = { true, true, true, true };
01532   Adaptor2d_Curve2d* botPcurves[NB_WALL_FACES];
01533   Adaptor2d_Curve2d* topPcurves[NB_WALL_FACES];
01534 
01535   for ( int iF = 0; iF < NB_WALL_FACES; ++iF )
01536   {
01537     TSideFace * sideFace = mySide->GetComponent( iF );
01538     if ( !sideFace )
01539       RETURN_BAD_RESULT("NULL TSideFace");
01540     int fID = sideFace->FaceID();
01541 
01542     // fill myShapeIDMap
01543     if ( sideFace->InsertSubShapes( myShapeIDMap ) != 8 &&
01544          !sideFace->IsComplex())
01545       MESSAGE( ": Warning : InsertSubShapes() < 8 on side " << iF );
01546 
01547     // side faces geometry
01548     Adaptor2d_Curve2d* pcurves[NB_WALL_FACES];
01549     if ( !sideFace->GetPCurves( pcurves ))
01550       RETURN_BAD_RESULT("TSideFace::GetPCurves() failed");
01551 
01552     SMESH_Block::TFace& tFace = myFace[ fID - ID_FirstF ];
01553     tFace.Set( fID, sideFace->Surface(), pcurves, isForward );
01554 
01555     SHOWYXZ( endl<<"F "<< iF << " id " << fID << " FRW " << sideFace->IsForward(), sideFace->Value(0,0));
01556     // edges 3D geometry
01557     vector< int > edgeIdVec;
01558     SMESH_Block::GetFaceEdgesIDs( fID, edgeIdVec );
01559     for ( int isMax = 0; isMax < 2; ++isMax ) {
01560       {
01561         int eID = edgeIdVec[ isMax ];
01562         SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE ];
01563         tEdge.Set( eID, sideFace->HorizCurve(isMax), true);
01564         SHOWYXZ(eID<<" HOR"<<isMax<<"(0)", sideFace->HorizCurve(isMax)->Value(0));
01565         SHOWYXZ(eID<<" HOR"<<isMax<<"(1)", sideFace->HorizCurve(isMax)->Value(1));
01566       }
01567       {
01568         int eID = edgeIdVec[ isMax+2 ];
01569         SMESH_Block::TEdge& tEdge = myEdge[ eID - ID_FirstE  ];
01570         tEdge.Set( eID, sideFace->VertiCurve(isMax), true);
01571         SHOWYXZ(eID<<" VER"<<isMax<<"(0)", sideFace->VertiCurve(isMax)->Value(0));
01572         SHOWYXZ(eID<<" VER"<<isMax<<"(1)", sideFace->VertiCurve(isMax)->Value(1));
01573 
01574         // corner points
01575         vector< int > vertexIdVec;
01576         SMESH_Block::GetEdgeVertexIDs( eID, vertexIdVec );
01577         myPnt[ vertexIdVec[0] - ID_FirstV ] = tEdge.GetCurve()->Value(0).XYZ();
01578         myPnt[ vertexIdVec[1] - ID_FirstV ] = tEdge.GetCurve()->Value(1).XYZ();
01579       }
01580     }
01581     // pcurves on horizontal faces
01582     for ( iE = 0; iE < NB_WALL_FACES; ++iE ) {
01583       if ( edgeIdVec[ BOTTOM_EDGE ] == botEdgeIdVec[ iE ] ) {
01584         botPcurves[ iE ] = sideFace->HorizPCurve( false, botF );
01585         topPcurves[ iE ] = sideFace->HorizPCurve( true,  topF );
01586         break;
01587       }
01588     }
01589     //sideFace->dumpNodes( 4 ); // debug
01590   }
01591   // horizontal faces geometry
01592   {
01593     SMESH_Block::TFace& tFace = myFace[ ID_BOT_FACE - ID_FirstF ];
01594     tFace.Set( ID_BOT_FACE, new BRepAdaptor_Surface( botF ), botPcurves, isForward );
01595     SMESH_Block::Insert( botF, ID_BOT_FACE, myShapeIDMap );
01596   }
01597   {
01598     SMESH_Block::TFace& tFace = myFace[ ID_TOP_FACE - ID_FirstF ];
01599     tFace.Set( ID_TOP_FACE, new BRepAdaptor_Surface( topF ), topPcurves, isForward );
01600     SMESH_Block::Insert( topF, ID_TOP_FACE, myShapeIDMap );
01601   }
01602 
01603   // Fill map ShapeIndex to TParam2ColumnMap
01604   // ----------------------------------------
01605 
01606   list< TSideFace* > fList;
01607   list< TSideFace* >::iterator fListIt;
01608   fList.push_back( mySide );
01609   for ( fListIt = fList.begin(); fListIt != fList.end(); ++fListIt)
01610   {
01611     int nb = (*fListIt)->NbComponents();
01612     for ( int i = 0; i < nb; ++i ) {
01613       if ( TSideFace* comp = (*fListIt)->GetComponent( i ))
01614         fList.push_back( comp );
01615     }
01616     if ( TParam2ColumnMap* cols = (*fListIt)->GetColumns()) {
01617       // columns for a base edge
01618       int id = MeshDS()->ShapeToIndex( (*fListIt)->BaseEdge() );
01619       bool isForward = (*fListIt)->IsForward();
01620       myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
01621 
01622       // columns for vertices
01623       const SMDS_MeshNode* n0 = cols->begin()->second.front();
01624       id = n0->getshapeId();
01625       myShapeIndex2ColumnMap[ id ] = make_pair( cols, isForward );
01626 
01627       const SMDS_MeshNode* n1 = cols->rbegin()->second.front();
01628       id = n1->getshapeId();
01629       myShapeIndex2ColumnMap[ id ] = make_pair( cols, !isForward );
01630     }
01631   }
01632 
01633 //   gp_XYZ testPar(0.25, 0.25, 0), testCoord;
01634 //   if ( !FacePoint( ID_BOT_FACE, testPar, testCoord ))
01635 //     RETURN_BAD_RESULT("TEST FacePoint() FAILED");
01636 //   SHOWYXZ("IN TEST PARAM" , testPar);
01637 //   SHOWYXZ("OUT TEST CORD" , testCoord);
01638 //   if ( !ComputeParameters( testCoord, testPar , ID_BOT_FACE))
01639 //     RETURN_BAD_RESULT("TEST ComputeParameters() FAILED");
01640 //   SHOWYXZ("OUT TEST PARAM" , testPar);
01641 
01642   return true;
01643 }
01644 
01645 //================================================================================
01651 //================================================================================
01652 
01653 const TNodeColumn* StdMeshers_PrismAsBlock::GetNodeColumn(const SMDS_MeshNode* node) const
01654 {
01655   int sID = node->getshapeId();
01656 
01657   map<int, pair< TParam2ColumnMap*, bool > >::const_iterator col_frw =
01658     myShapeIndex2ColumnMap.find( sID );
01659   if ( col_frw != myShapeIndex2ColumnMap.end() ) {
01660     const TParam2ColumnMap* cols = col_frw->second.first;
01661     TParam2ColumnIt u_col = cols->begin();
01662     for ( ; u_col != cols->end(); ++u_col )
01663       if ( u_col->second[ 0 ] == node )
01664         return & u_col->second;
01665   }
01666   return 0;
01667 }
01668 
01669 //=======================================================================
01670 //function : GetLayersTransformation
01671 //purpose  : Return transformations to get coordinates of nodes of each layer
01672 //           by nodes of the bottom. Layer is a set of nodes at a certain step
01673 //           from bottom to top.
01674 //=======================================================================
01675 
01676 bool StdMeshers_PrismAsBlock::GetLayersTransformation(vector<gp_Trsf> & trsf) const
01677 {
01678   const int zSize = VerticalSize();
01679   if ( zSize < 3 ) return true;
01680   trsf.resize( zSize - 2 );
01681 
01682   // Select some node columns by which we will define coordinate system of layers
01683 
01684   vector< const TNodeColumn* > columns;
01685   {
01686     const TopoDS_Shape& baseFace = Shape(ID_BOT_FACE);
01687     list< TopoDS_Edge > orderedEdges;
01688     list< int >         nbEdgesInWires;
01689     GetOrderedEdges( TopoDS::Face( baseFace ), TopoDS_Vertex(), orderedEdges, nbEdgesInWires );
01690     bool isReverse;
01691     list< TopoDS_Edge >::iterator edgeIt = orderedEdges.begin();
01692     for ( int iE = 0; iE < nbEdgesInWires.front(); ++iE, ++edgeIt )
01693     {
01694       if ( BRep_Tool::Degenerated( *edgeIt )) continue;
01695       const TParam2ColumnMap* u2colMap =
01696         GetParam2ColumnMap( myHelper->GetMeshDS()->ShapeToIndex( *edgeIt ), isReverse );
01697       if ( !u2colMap ) return false;
01698       isReverse = ( edgeIt->Orientation() == TopAbs_REVERSED );
01699       double f = u2colMap->begin()->first, l = u2colMap->rbegin()->first;
01700       if ( isReverse ) swap ( f, l );
01701       const int nbCol = 5;
01702       for ( int i = 0; i < nbCol; ++i )
01703       {
01704         double u = f + i/double(nbCol) * ( l - f );
01705         const TNodeColumn* col = & getColumn( u2colMap, u )->second;
01706         if ( columns.empty() || col != columns.back() )
01707           columns.push_back( col );
01708       }
01709     }
01710   }
01711 
01712   // Find tolerance to check transformations
01713 
01714   double tol2;
01715   {
01716     Bnd_B3d bndBox;
01717     for ( int i = 0; i < columns.size(); ++i )
01718       bndBox.Add( gpXYZ( columns[i]->front() ));
01719     tol2 = bndBox.SquareExtent() * 1e-5;
01720   }
01721 
01722   // Compute transformations
01723 
01724   int xCol = -1;
01725   gp_Trsf fromCsZ, toCs0;
01726   gp_Ax3 cs0 = getLayerCoordSys(0, columns, xCol );
01727   //double dist0 = cs0.Location().Distance( gpXYZ( (*columns[0])[0]));
01728   toCs0.SetTransformation( cs0 );
01729   for ( int z = 1; z < zSize-1; ++z )
01730   {
01731     gp_Ax3 csZ = getLayerCoordSys(z, columns, xCol );
01732     //double distZ = csZ.Location().Distance( gpXYZ( (*columns[0])[z]));
01733     fromCsZ.SetTransformation( csZ );
01734     fromCsZ.Invert();
01735     gp_Trsf& t = trsf[ z-1 ];
01736     t = fromCsZ * toCs0;
01737     //t.SetScaleFactor( distZ/dist0 ); - it does not work properly, wrong base point
01738 
01739     // check a transformation
01740     for ( int i = 0; i < columns.size(); ++i )
01741     {
01742       gp_Pnt p0 = gpXYZ( (*columns[i])[0] );
01743       gp_Pnt pz = gpXYZ( (*columns[i])[z] );
01744       t.Transforms( p0.ChangeCoord() );
01745       if ( p0.SquareDistance( pz ) > tol2 )
01746         return false;
01747     }
01748   }
01749   return true;
01750 }
01751 
01752 //================================================================================
01761 //================================================================================
01762 
01763 bool StdMeshers_PrismAsBlock::IsForwardEdge(SMESHDS_Mesh*           meshDS,
01764                                             const TParam2ColumnMap& columnsMap,
01765                                             const TopoDS_Edge &     bottomEdge,
01766                                             const int               sideFaceID)
01767 {
01768   bool isForward = false;
01769   if ( SMESH_MesherHelper::IsClosedEdge( bottomEdge ))
01770   {
01771     isForward = ( bottomEdge.Orientation() == TopAbs_FORWARD );
01772   }
01773   else
01774   {
01775     const TNodeColumn& firstCol = columnsMap.begin()->second;
01776     const SMDS_MeshNode* bottomNode = firstCol[0];
01777     TopoDS_Shape firstVertex = SMESH_MesherHelper::GetSubShapeByNode( bottomNode, meshDS );
01778     isForward = ( firstVertex.IsSame( TopExp::FirstVertex( bottomEdge, true )));
01779   }
01780   // on 2 of 4 sides first vertex is end
01781   if ( sideFaceID == ID_Fx1z || sideFaceID == ID_F0yz )
01782     isForward = !isForward;
01783   return isForward;
01784 }
01785 
01786 //================================================================================
01795 //================================================================================
01796 
01797 bool StdMeshers_PrismAsBlock::GetWallFaces( SMESH_Mesh*               mesh,
01798                                             const TopoDS_Shape &      mainShape,
01799                                             const TopoDS_Shape &      bottomFace,
01800                                             std::list< TopoDS_Edge >& bottomEdges,
01801                                             std::list< int > &        nbEInW,
01802                                             std::list< TopoDS_Face >& wallFaces)
01803 {
01804   wallFaces.clear();
01805 
01806   TopTools_IndexedMapOfShape faceMap;
01807   TopExp::MapShapes( mainShape, TopAbs_FACE, faceMap );
01808 
01809   list< TopoDS_Edge >::iterator edge = bottomEdges.begin();
01810   std::list< int >::iterator nbE = nbEInW.begin();
01811   int iE = 0;
01812   while ( edge != bottomEdges.end() )
01813   {
01814     ++iE;
01815     if ( BRep_Tool::Degenerated( *edge ))
01816     {
01817       edge = bottomEdges.erase( edge );
01818       --iE;
01819       --(*nbE);
01820     }
01821     else
01822     {
01823       PShapeIteratorPtr fIt = myHelper->GetAncestors( *edge, *mesh, TopAbs_FACE );
01824       while ( fIt->more() )
01825       {
01826         const TopoDS_Shape* face = fIt->next();
01827         if ( !bottomFace.IsSame( *face ) &&      // not bottom
01828              faceMap.FindIndex( *face ))         // belongs to the prism
01829         {
01830           wallFaces.push_back( TopoDS::Face( *face ));
01831           break;
01832         }
01833       }
01834       ++edge;
01835     }
01836     if ( iE == *nbE )
01837     {
01838       iE = 0;
01839       ++nbE;
01840     }
01841   }
01842   return ( wallFaces.size() == bottomEdges.size() );
01843 }
01844 
01845 //================================================================================
01854 //================================================================================
01855 
01856 StdMeshers_PrismAsBlock::TSideFace::TSideFace(SMESH_MesherHelper* helper,
01857                                               const int           faceID,
01858                                               const TopoDS_Face&  face,
01859                                               const TopoDS_Edge&  baseEdge,
01860                                               TParam2ColumnMap*   columnsMap,
01861                                               const double        first,
01862                                               const double        last):
01863   myID( faceID ),
01864   myParamToColumnMap( columnsMap ),
01865   myBaseEdge( baseEdge ),
01866   myHelper( helper )
01867 {
01868   mySurface.Initialize( face );
01869   myParams.resize( 1 );
01870   myParams[ 0 ] = make_pair( first, last );
01871   myIsForward = StdMeshers_PrismAsBlock::IsForwardEdge( myHelper->GetMeshDS(),
01872                                                         *myParamToColumnMap,
01873                                                         myBaseEdge, myID );
01874 }
01875 
01876 //================================================================================
01880 //================================================================================
01881 
01882 StdMeshers_PrismAsBlock::TSideFace::
01883 TSideFace(const vector< TSideFace* >&             components,
01884           const vector< pair< double, double> > & params)
01885   :myID( components[0] ? components[0]->myID : 0 ),
01886    myParamToColumnMap( 0 ),
01887    myParams( params ),
01888    myIsForward( true ),
01889    myComponents( components ),
01890    myHelper( components[0] ? components[0]->myHelper : 0 )
01891 {}
01892 //================================================================================
01897 //================================================================================
01898 
01899 StdMeshers_PrismAsBlock::TSideFace::TSideFace( const TSideFace& other )
01900 {
01901   myID               = other.myID;
01902   mySurface          = other.mySurface;
01903   myBaseEdge         = other.myBaseEdge;
01904   myParams           = other.myParams;
01905   myIsForward        = other.myIsForward;
01906   myHelper           = other.myHelper;
01907   myParamToColumnMap = other.myParamToColumnMap;
01908 
01909   myComponents.resize( other.myComponents.size());
01910   for (int i = 0 ; i < myComponents.size(); ++i )
01911     myComponents[ i ] = new TSideFace( *other.myComponents[ i ]);
01912 }
01913 
01914 //================================================================================
01918 //================================================================================
01919 
01920 StdMeshers_PrismAsBlock::TSideFace::~TSideFace()
01921 {
01922   for (int i = 0 ; i < myComponents.size(); ++i )
01923     if ( myComponents[ i ] )
01924       delete myComponents[ i ];
01925 }
01926 
01927 //================================================================================
01933 //================================================================================
01934 
01935 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::VertiCurve(const bool isMax) const
01936 {
01937   if ( !myComponents.empty() ) {
01938     if ( isMax )
01939       return myComponents.back()->VertiCurve(isMax);
01940     else
01941       return myComponents.front()->VertiCurve(isMax);
01942   }
01943   double f = myParams[0].first, l = myParams[0].second;
01944   if ( !myIsForward ) std::swap( f, l );
01945   return new TVerticalEdgeAdaptor( myParamToColumnMap, isMax ? l : f );
01946 }
01947 
01948 //================================================================================
01954 //================================================================================
01955 
01956 Adaptor3d_Curve* StdMeshers_PrismAsBlock::TSideFace::HorizCurve(const bool isTop) const
01957 {
01958   return new THorizontalEdgeAdaptor( this, isTop );
01959 }
01960 
01961 //================================================================================
01967 //================================================================================
01968 
01969 bool StdMeshers_PrismAsBlock::TSideFace::GetPCurves(Adaptor2d_Curve2d* pcurv[4]) const
01970 {
01971   int iEdge[ 4 ] = { BOTTOM_EDGE, TOP_EDGE, V0_EDGE, V1_EDGE };
01972 
01973   for ( int i = 0 ; i < 4 ; ++i ) {
01974     Handle(Geom2d_Line) line;
01975     switch ( iEdge[ i ] ) {
01976     case TOP_EDGE:
01977       line = new Geom2d_Line( gp_Pnt2d( 0, 1 ), gp::DX2d() ); break;
01978     case BOTTOM_EDGE:
01979       line = new Geom2d_Line( gp::Origin2d(), gp::DX2d() ); break;
01980     case V0_EDGE:
01981       line = new Geom2d_Line( gp::Origin2d(), gp::DY2d() ); break;
01982     case V1_EDGE:
01983       line = new Geom2d_Line( gp_Pnt2d( 1, 0 ), gp::DY2d() ); break;
01984     }
01985     pcurv[ i ] = new Geom2dAdaptor_Curve( line, 0, 1 );
01986   }
01987   return true;
01988 }
01989 
01990 //================================================================================
01997 //================================================================================
01998 
01999 Adaptor2d_Curve2d*
02000 StdMeshers_PrismAsBlock::TSideFace::HorizPCurve(const bool         isTop,
02001                                                 const TopoDS_Face& horFace) const
02002 {
02003   return new TPCurveOnHorFaceAdaptor( this, isTop, horFace );
02004 }
02005 
02006 //================================================================================
02013 //================================================================================
02014 
02015 StdMeshers_PrismAsBlock::TSideFace*
02016 StdMeshers_PrismAsBlock::TSideFace::GetComponent(const double U,double & localU) const
02017 {
02018   localU = U;
02019   if ( myComponents.empty() )
02020     return const_cast<TSideFace*>( this );
02021 
02022   int i;
02023   for ( i = 0; i < myComponents.size(); ++i )
02024     if ( U < myParams[ i ].second )
02025       break;
02026   if ( i >= myComponents.size() )
02027     i = myComponents.size() - 1;
02028 
02029   double f = myParams[ i ].first, l = myParams[ i ].second;
02030   localU = ( U - f ) / ( l - f );
02031   return myComponents[ i ];
02032 }
02033 
02034 //================================================================================
02042 //================================================================================
02043 
02044 double StdMeshers_PrismAsBlock::TSideFace::GetColumns(const double      U,
02045                                                       TParam2ColumnIt & col1,
02046                                                       TParam2ColumnIt & col2) const
02047 {
02048   double u = U, r = 0;
02049   if ( !myComponents.empty() ) {
02050     TSideFace * comp = GetComponent(U,u);
02051     return comp->GetColumns( u, col1, col2 );
02052   }
02053 
02054   if ( !myIsForward )
02055     u = 1 - u;
02056   double f = myParams[0].first, l = myParams[0].second;
02057   u = f + u * ( l - f );
02058 
02059   col1 = col2 = getColumn( myParamToColumnMap, u );
02060   if ( ++col2 == myParamToColumnMap->end() ) {
02061     --col2;
02062     r = 0.5;
02063   }
02064   else {
02065     double uf = col1->first;
02066     double ul = col2->first;
02067     r = ( u - uf ) / ( ul - uf );
02068   }
02069   return r;
02070 }
02071 
02072 //================================================================================
02079 //================================================================================
02080 
02081 gp_Pnt StdMeshers_PrismAsBlock::TSideFace::Value(const Standard_Real U,
02082                                                  const Standard_Real V) const
02083 {
02084   if ( !myComponents.empty() ) {
02085     double u;
02086     TSideFace * comp = GetComponent(U,u);
02087     return comp->Value( u, V );
02088   }
02089 
02090   TParam2ColumnIt u_col1, u_col2;
02091   double vR, hR = GetColumns( U, u_col1, u_col2 );
02092 
02093   const SMDS_MeshNode* n1 = 0;
02094   const SMDS_MeshNode* n2 = 0;
02095   const SMDS_MeshNode* n3 = 0;
02096   const SMDS_MeshNode* n4 = 0;
02097 
02098   // BEGIN issue 0020680: EDF 1252 SMESH: Bad cell created by Radial prism in center of torus
02099   // Workaround for a wrongly located point returned by mySurface.Value() for
02100   // UV located near boundary of BSpline surface.
02101   // To bypass the problem, we take point from 3D curve of edge.
02102   // It solves pb of the bloc_fiss_new.py
02103   const double tol = 1e-3;
02104   if ( V < tol || V+tol >= 1. )
02105   {
02106     n1 = V < tol ? u_col1->second.front() : u_col1->second.back();
02107     n3 = V < tol ? u_col2->second.front() : u_col2->second.back();
02108     TopoDS_Edge edge;
02109     if ( V < tol )
02110     {
02111       edge = myBaseEdge;
02112     }
02113     else
02114     {
02115       TopoDS_Shape s = myHelper->GetSubShapeByNode( n1, myHelper->GetMeshDS() );
02116       if ( s.ShapeType() != TopAbs_EDGE )
02117         s = myHelper->GetSubShapeByNode( n3, myHelper->GetMeshDS() );
02118       if ( s.ShapeType() == TopAbs_EDGE )
02119         edge = TopoDS::Edge( s );
02120     }
02121     if ( !edge.IsNull() )
02122     {
02123       double u1 = myHelper->GetNodeU( edge, n1 );
02124       double u3 = myHelper->GetNodeU( edge, n3 );
02125       double u = u1 * ( 1 - hR ) + u3 * hR;
02126       TopLoc_Location loc; double f,l;
02127       Handle(Geom_Curve) curve = BRep_Tool::Curve( edge,loc,f,l );
02128       return curve->Value( u ).Transformed( loc );
02129     }
02130   }
02131   // END issue 0020680: EDF 1252 SMESH: Bad cell created by Radial prism in center of torus
02132 
02133   vR = getRAndNodes( & u_col1->second, V, n1, n2 );
02134   vR = getRAndNodes( & u_col2->second, V, n3, n4 );
02135   
02136   gp_XY uv1 = myHelper->GetNodeUV( mySurface.Face(), n1, n4);
02137   gp_XY uv2 = myHelper->GetNodeUV( mySurface.Face(), n2, n3);
02138   gp_XY uv12 = uv1 * ( 1 - vR ) + uv2 * vR;
02139 
02140   gp_XY uv3 = myHelper->GetNodeUV( mySurface.Face(), n3, n2);
02141   gp_XY uv4 = myHelper->GetNodeUV( mySurface.Face(), n4, n1);
02142   gp_XY uv34 = uv3 * ( 1 - vR ) + uv4 * vR;
02143 
02144   gp_XY uv = uv12 * ( 1 - hR ) + uv34 * hR;
02145 
02146   gp_Pnt p = mySurface.Value( uv.X(), uv.Y() );
02147   return p;
02148 }
02149 
02150 
02151 //================================================================================
02157 //================================================================================
02158 
02159 TopoDS_Edge StdMeshers_PrismAsBlock::TSideFace::GetEdge(const int iEdge) const
02160 {
02161   if ( !myComponents.empty() ) {
02162     switch ( iEdge ) {
02163     case V0_EDGE : return myComponents.front()->GetEdge( iEdge );
02164     case V1_EDGE : return myComponents.back() ->GetEdge( iEdge );
02165     default: return TopoDS_Edge();
02166     }
02167   }
02168   TopoDS_Shape edge;
02169   const SMDS_MeshNode* node = 0;
02170   SMESHDS_Mesh * meshDS = myHelper->GetMesh()->GetMeshDS();
02171   TNodeColumn* column;
02172 
02173   switch ( iEdge ) {
02174   case TOP_EDGE:
02175   case BOTTOM_EDGE:
02176     column = & (( ++myParamToColumnMap->begin())->second );
02177     node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
02178     edge = myHelper->GetSubShapeByNode ( node, meshDS );
02179     if ( edge.ShapeType() == TopAbs_VERTEX ) {
02180       column = & ( myParamToColumnMap->begin()->second );
02181       node = ( iEdge == TOP_EDGE ) ? column->back() : column->front();
02182     }
02183     break;
02184   case V0_EDGE:
02185   case V1_EDGE: {
02186     bool back = ( iEdge == V1_EDGE );
02187     if ( !myIsForward ) back = !back;
02188     if ( back )
02189       column = & ( myParamToColumnMap->rbegin()->second );
02190     else
02191       column = & ( myParamToColumnMap->begin()->second );
02192     if ( column->size() > 0 )
02193       edge = myHelper->GetSubShapeByNode( (*column)[ 1 ], meshDS );
02194     if ( edge.IsNull() || edge.ShapeType() == TopAbs_VERTEX )
02195       node = column->front();
02196     break;
02197   }
02198   default:;
02199   }
02200   if ( !edge.IsNull() && edge.ShapeType() == TopAbs_EDGE )
02201     return TopoDS::Edge( edge );
02202 
02203   // find edge by 2 vertices
02204   TopoDS_Shape V1 = edge;
02205   TopoDS_Shape V2 = myHelper->GetSubShapeByNode( node, meshDS );
02206   if ( V2.ShapeType() == TopAbs_VERTEX && !V2.IsSame( V1 ))
02207   {
02208     TopoDS_Shape ancestor = myHelper->GetCommonAncestor( V1, V2, *myHelper->GetMesh(), TopAbs_EDGE);
02209     if ( !ancestor.IsNull() )
02210       return TopoDS::Edge( ancestor );
02211   }
02212   return TopoDS_Edge();
02213 }
02214 
02215 //================================================================================
02221 //================================================================================
02222 
02223 int StdMeshers_PrismAsBlock::TSideFace::InsertSubShapes(TBlockShapes& shapeMap) const
02224 {
02225   int nbInserted = 0;
02226 
02227   // Insert edges
02228   vector< int > edgeIdVec;
02229   SMESH_Block::GetFaceEdgesIDs( myID, edgeIdVec );
02230 
02231   for ( int i = BOTTOM_EDGE; i <=V1_EDGE ; ++i ) {
02232     TopoDS_Edge e = GetEdge( i );
02233     if ( !e.IsNull() ) {
02234       nbInserted += SMESH_Block::Insert( e, edgeIdVec[ i ], shapeMap);
02235     }
02236   }
02237 
02238   // Insert corner vertices
02239 
02240   TParam2ColumnIt col1, col2 ;
02241   vector< int > vertIdVec;
02242 
02243   // from V0 column
02244   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V0_EDGE ], vertIdVec);
02245   GetColumns(0, col1, col2 );
02246   const SMDS_MeshNode* node0 = col1->second.front();
02247   const SMDS_MeshNode* node1 = col1->second.back();
02248   TopoDS_Shape v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
02249   TopoDS_Shape v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
02250   if ( v0.ShapeType() == TopAbs_VERTEX ) {
02251     nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
02252   }
02253   if ( v1.ShapeType() == TopAbs_VERTEX ) {
02254     nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
02255   }
02256   
02257   // from V1 column
02258   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ V1_EDGE ], vertIdVec);
02259   GetColumns(1, col1, col2 );
02260   node0 = col2->second.front();
02261   node1 = col2->second.back();
02262   v0 = myHelper->GetSubShapeByNode( node0, myHelper->GetMeshDS());
02263   v1 = myHelper->GetSubShapeByNode( node1, myHelper->GetMeshDS());
02264   if ( v0.ShapeType() == TopAbs_VERTEX ) {
02265     nbInserted += SMESH_Block::Insert( v0, vertIdVec[ 0 ], shapeMap);
02266   }
02267   if ( v1.ShapeType() == TopAbs_VERTEX ) {
02268     nbInserted += SMESH_Block::Insert( v1, vertIdVec[ 1 ], shapeMap);
02269   }
02270 
02271 //   TopoDS_Vertex V0, V1, Vcom;
02272 //   TopExp::Vertices( myBaseEdge, V0, V1, true );
02273 //   if ( !myIsForward ) std::swap( V0, V1 );
02274 
02275 //   // bottom vertex IDs
02276 //   SMESH_Block::GetEdgeVertexIDs( edgeIdVec[ _u0 ], vertIdVec);
02277 //   SMESH_Block::Insert( V0, vertIdVec[ 0 ], shapeMap);
02278 //   SMESH_Block::Insert( V1, vertIdVec[ 1 ], shapeMap);
02279 
02280 //   TopoDS_Edge sideEdge = GetEdge( V0_EDGE );
02281 //   if ( sideEdge.IsNull() || !TopExp::CommonVertex( botEdge, sideEdge, Vcom ))
02282 //     return false;
02283 
02284 //   // insert one side edge
02285 //   int edgeID;
02286 //   if ( Vcom.IsSame( V0 )) edgeID = edgeIdVec[ _v0 ];
02287 //   else                    edgeID = edgeIdVec[ _v1 ];
02288 //   SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
02289 
02290 //   // top vertex of the side edge
02291 //   SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec);
02292 //   TopoDS_Vertex Vtop = TopExp::FirstVertex( sideEdge );
02293 //   if ( Vcom.IsSame( Vtop ))
02294 //     Vtop = TopExp::LastVertex( sideEdge );
02295 //   SMESH_Block::Insert( Vtop, vertIdVec[ 1 ], shapeMap);
02296 
02297 //   // other side edge
02298 //   sideEdge = GetEdge( V1_EDGE );
02299 //   if ( sideEdge.IsNull() )
02300 //     return false;
02301 //   if ( edgeID = edgeIdVec[ _v1 ]) edgeID = edgeIdVec[ _v0 ];
02302 //   else                            edgeID = edgeIdVec[ _v1 ];
02303 //   SMESH_Block::Insert( sideEdge, edgeID, shapeMap);
02304   
02305 //   // top edge
02306 //   TopoDS_Edge topEdge = GetEdge( TOP_EDGE );
02307 //   SMESH_Block::Insert( topEdge, edgeIdVec[ _u1 ], shapeMap);
02308 
02309 //   // top vertex of the other side edge
02310 //   if ( !TopExp::CommonVertex( topEdge, sideEdge, Vcom ))
02311 //     return false;
02312 //   SMESH_Block::GetEdgeVertexIDs( edgeID, vertIdVec );
02313 //   SMESH_Block::Insert( Vcom, vertIdVec[ 1 ], shapeMap);
02314 
02315   return nbInserted;
02316 }
02317 
02318 //================================================================================
02322 //================================================================================
02323 
02324 void StdMeshers_PrismAsBlock::TSideFace::dumpNodes(int nbNodes) const
02325 {
02326 #ifdef _DEBUG_
02327   cout << endl << "NODES OF FACE "; SMESH_Block::DumpShapeID( myID, cout ) << endl;
02328   THorizontalEdgeAdaptor* hSize0 = (THorizontalEdgeAdaptor*) HorizCurve(0);
02329   cout << "Horiz side 0: "; hSize0->dumpNodes(nbNodes); cout << endl;
02330   THorizontalEdgeAdaptor* hSize1 = (THorizontalEdgeAdaptor*) HorizCurve(1);
02331   cout << "Horiz side 1: "; hSize1->dumpNodes(nbNodes); cout << endl;
02332   TVerticalEdgeAdaptor* vSide0 = (TVerticalEdgeAdaptor*) VertiCurve(0);
02333   cout << "Verti side 0: "; vSide0->dumpNodes(nbNodes); cout << endl;
02334   TVerticalEdgeAdaptor* vSide1 = (TVerticalEdgeAdaptor*) VertiCurve(1);
02335   cout << "Verti side 1: "; vSide1->dumpNodes(nbNodes); cout << endl;
02336   delete hSize0; delete hSize1; delete vSide0; delete vSide1;
02337 #endif
02338 }
02339 
02340 //================================================================================
02346 //================================================================================
02347 
02348 StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::
02349 TVerticalEdgeAdaptor( const TParam2ColumnMap* columnsMap, const double parameter)
02350 {
02351   myNodeColumn = & getColumn( columnsMap, parameter )->second;
02352 }
02353 
02354 //================================================================================
02360 //================================================================================
02361 
02362 gp_Pnt StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::Value(const Standard_Real U) const
02363 {
02364   const SMDS_MeshNode* n1;
02365   const SMDS_MeshNode* n2;
02366   double r = getRAndNodes( myNodeColumn, U, n1, n2 );
02367   return gpXYZ(n1) * ( 1 - r ) + gpXYZ(n2) * r;
02368 }
02369 
02370 //================================================================================
02374 //================================================================================
02375 
02376 void StdMeshers_PrismAsBlock::TVerticalEdgeAdaptor::dumpNodes(int nbNodes) const
02377 {
02378 #ifdef _DEBUG_
02379   for ( int i = 0; i < nbNodes && i < myNodeColumn->size(); ++i )
02380     cout << (*myNodeColumn)[i]->GetID() << " ";
02381   if ( nbNodes < myNodeColumn->size() )
02382     cout << myNodeColumn->back()->GetID();
02383 #endif
02384 }
02385 
02386 //================================================================================
02392 //================================================================================
02393 
02394 gp_Pnt StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::Value(const Standard_Real U) const
02395 {
02396   return mySide->TSideFace::Value( U, myV );
02397 }
02398 
02399 //================================================================================
02403 //================================================================================
02404 
02405 void StdMeshers_PrismAsBlock::THorizontalEdgeAdaptor::dumpNodes(int nbNodes) const
02406 {
02407 #ifdef _DEBUG_
02408   // Not bedugged code. Last node is sometimes incorrect
02409   const TSideFace* side = mySide;
02410   double u = 0;
02411   if ( mySide->IsComplex() )
02412     side = mySide->GetComponent(0,u);
02413 
02414   TParam2ColumnIt col, col2;
02415   TParam2ColumnMap* u2cols = side->GetColumns();
02416   side->GetColumns( u , col, col2 );
02417   
02418   int j, i = myV ? mySide->ColumnHeight()-1 : 0;
02419 
02420   const SMDS_MeshNode* n = 0;
02421   const SMDS_MeshNode* lastN
02422     = side->IsForward() ? u2cols->rbegin()->second[ i ] : u2cols->begin()->second[ i ];
02423   for ( j = 0; j < nbNodes && n != lastN; ++j )
02424   {
02425     n = col->second[ i ];
02426     cout << n->GetID() << " ";
02427     if ( side->IsForward() )
02428       ++col;
02429     else
02430       --col;
02431   }
02432 
02433   // last node
02434   u = 1;
02435   if ( mySide->IsComplex() )
02436     side = mySide->GetComponent(1,u);
02437 
02438   side->GetColumns( u , col, col2 );
02439   if ( n != col->second[ i ] )
02440     cout << col->second[ i ]->GetID();
02441 #endif
02442 }
02443 //================================================================================
02449 //================================================================================
02450 
02451 gp_Pnt2d StdMeshers_PrismAsBlock::TPCurveOnHorFaceAdaptor::Value(const Standard_Real U) const
02452 {
02453   TParam2ColumnIt u_col1, u_col2;
02454   double r = mySide->GetColumns( U, u_col1, u_col2 );
02455   gp_XY uv1 = mySide->GetNodeUV( myFace, u_col1->second[ myZ ]);
02456   gp_XY uv2 = mySide->GetNodeUV( myFace, u_col2->second[ myZ ]);
02457   return uv1 * ( 1 - r ) + uv2 * r;
02458 }