+
+ if ( botSM->IsEmpty() )
+ return error( COMPERR_BAD_INPUT_MESH,
+ TCom( "No mesher defined to compute the base face #")
+ << shapeID( thePrism.myBottom ));
+
+ if ( botSM->GetAlgo() )
+ myPrevBottomSM = botSM;
+
+ return true;
+}
+
+//=======================================================================
+//function : computeWalls
+//purpose : Compute 2D mesh on walls FACEs of a prism
+//=======================================================================
+
+bool StdMeshers_Prism_3D::computeWalls(const Prism_3D::TPrismTopo& thePrism)
+{
+ SMESH_Mesh* mesh = myHelper->GetMesh();
+ SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
+ DBGOUT( endl << "COMPUTE Prism " << meshDS->ShapeToIndex( thePrism.myShape3D ));
+
+ TProjction1dAlgo* projector1D = TProjction1dAlgo::instance( this );
+ StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
+
+ // SMESH_HypoFilter hyp1dFilter( SMESH_HypoFilter::IsAlgo(),/*not=*/true);
+ // hyp1dFilter.And( SMESH_HypoFilter::HasDim( 1 ));
+ // hyp1dFilter.And( SMESH_HypoFilter::IsMoreLocalThan( thePrism.myShape3D, *mesh ));
+
+ // Discretize equally 'vertical' EDGEs
+ // -----------------------------------
+ // find source FACE sides for projection: either already computed ones or
+ // the 'most composite' ones
+ const size_t nbWalls = thePrism.myWallQuads.size();
+ vector< int > wgt( nbWalls, 0 ); // "weight" of a wall
+ for ( size_t iW = 0; iW != nbWalls; ++iW )
+ {
+ Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
+ for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
+ {
+ StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
+ lftSide->Reverse(); // to go up
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ {
+ ++wgt[ iW ];
+ const TopoDS_Edge& E = lftSide->Edge(i);
+ if ( mesh->GetSubMesh( E )->IsMeshComputed() )
+ {
+ wgt[ iW ] += 100;
+ wgt[ myHelper->WrapIndex( iW+1, nbWalls)] += 10;
+ wgt[ myHelper->WrapIndex( iW-1, nbWalls)] += 10;
+ }
+ // else if ( mesh->GetHypothesis( E, hyp1dFilter, true )) // local hypothesis!
+ // wgt += 100;
+ }
+ }
+ // in quadratic mesh, pass ignoreMediumNodes to quad sides
+ if ( myHelper->GetIsQuadratic() )
+ {
+ quad = thePrism.myWallQuads[iW].begin();
+ for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
+ for ( int i = 0; i < NB_QUAD_SIDES; ++i )
+ (*quad)->side[ i ].grid->SetIgnoreMediumNodes( true );
+ }
+ }
+ multimap< int, int > wgt2quad;
+ for ( size_t iW = 0; iW != nbWalls; ++iW )
+ wgt2quad.insert( make_pair( wgt[ iW ], iW ));
+
+ // artificial quads to do outer <-> inner wall projection
+ std::map< int, FaceQuadStruct > iW2oiQuads;
+ std::map< int, FaceQuadStruct >::iterator w2oiq;
+ makeQuadsForOutInProjection( thePrism, wgt2quad, iW2oiQuads );
+
+ // Project 'vertical' EDGEs, from left to right
+ multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
+ for ( ; w2q != wgt2quad.rend(); ++w2q )
+ {
+ const int iW = w2q->second;
+ const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iW ];
+ Prism_3D::TQuadList::const_iterator quad = quads.begin();
+ for ( ; quad != quads.end(); ++quad )
+ {
+ StdMeshers_FaceSidePtr rgtSide = (*quad)->side[ QUAD_RIGHT_SIDE ]; // tgt
+ StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ]; // src
+ bool swapLeftRight = ( lftSide->NbSegments( /*update=*/true ) == 0 &&
+ rgtSide->NbSegments( /*update=*/true ) > 0 );
+ if ( swapLeftRight )
+ std::swap( lftSide, rgtSide );
+
+ bool isArtificialQuad = (( w2oiq = iW2oiQuads.find( iW )) != iW2oiQuads.end() );
+ if ( isArtificialQuad )
+ {
+ // reset sides to perform the outer <-> inner projection
+ FaceQuadStruct& oiQuad = w2oiq->second;
+ rgtSide = oiQuad.side[ QUAD_RIGHT_SIDE ];
+ lftSide = oiQuad.side[ QUAD_LEFT_SIDE ];
+ iW2oiQuads.erase( w2oiq );
+ }
+
+ // assure that all the source (left) EDGEs are meshed
+ int nbSrcSegments = 0;
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ {
+ if ( isArtificialQuad )
+ {
+ nbSrcSegments = lftSide->NbPoints()-1;
+ continue;
+ }
+ const TopoDS_Edge& srcE = lftSide->Edge(i);
+ SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
+ if ( !srcSM->IsMeshComputed() ) {
+ DBGOUT( "COMPUTE V edge " << srcSM->GetId() );
+ TopoDS_Edge prpgSrcE = findPropagationSource( srcE );
+ if ( !prpgSrcE.IsNull() ) {
+ srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ projector1D->myHyp.SetSourceEdge( prpgSrcE );
+ projector1D->Compute( *mesh, srcE );
+ srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+ else {
+ srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
+ }
+ if ( !srcSM->IsMeshComputed() )
+ return toSM( error( "Can't compute 1D mesh" ));
+ }
+ nbSrcSegments += srcSM->GetSubMeshDS()->NbElements();
+ }
+ // check target EDGEs
+ int nbTgtMeshed = 0, nbTgtSegments = 0;
+ vector< bool > isTgtEdgeComputed( rgtSide->NbEdges() );
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i )
+ {
+ const TopoDS_Edge& tgtE = rgtSide->Edge(i);
+ SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
+ if ( !( isTgtEdgeComputed[ i ] = tgtSM->IsMeshComputed() )) {
+ tgtSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ tgtSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
+ }
+ if ( tgtSM->IsMeshComputed() ) {
+ ++nbTgtMeshed;
+ nbTgtSegments += tgtSM->GetSubMeshDS()->NbElements();
+ }
+ }
+ if ( rgtSide->NbEdges() == nbTgtMeshed ) // all tgt EDGEs meshed
+ {
+ if ( nbTgtSegments != nbSrcSegments )
+ {
+ bool badMeshRemoved = false;
+ // remove just computed segments
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i )
+ if ( !isTgtEdgeComputed[ i ])
+ {
+ const TopoDS_Edge& tgtE = rgtSide->Edge(i);
+ SMESH_subMesh* tgtSM = mesh->GetSubMesh( tgtE );
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
+ badMeshRemoved = true;
+ nbTgtMeshed--;
+ }
+ if ( !badMeshRemoved )
+ {
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ addBadInputElements( meshDS->MeshElements( lftSide->Edge( i )));
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i )
+ addBadInputElements( meshDS->MeshElements( rgtSide->Edge( i )));
+ return toSM( error( TCom("Different nb of segment on logically vertical edges #")
+ << shapeID( lftSide->Edge(0) ) << " and #"
+ << shapeID( rgtSide->Edge(0) ) << ": "
+ << nbSrcSegments << " != " << nbTgtSegments ));
+ }
+ }
+ else // if ( nbTgtSegments == nbSrcSegments )
+ {
+ continue;
+ }
+ }
+ // Compute 'vertical projection'
+ if ( nbTgtMeshed == 0 )
+ {
+ // compute nodes on target VERTEXes
+ const UVPtStructVec& srcNodeStr = lftSide->GetUVPtStruct();
+ if ( srcNodeStr.size() == 0 )
+ return toSM( error( TCom("Invalid node positions on edge #") <<
+ lftSide->EdgeID(0) ));
+ vector< SMDS_MeshNode* > newNodes( srcNodeStr.size() );
+ for ( int is2ndV = 0; is2ndV < 2; ++is2ndV )
+ {
+ const TopoDS_Edge& E = rgtSide->Edge( is2ndV ? rgtSide->NbEdges()-1 : 0 );
+ TopoDS_Vertex v = myHelper->IthVertex( is2ndV, E );
+ mesh->GetSubMesh( v )->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+ const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, meshDS );
+ newNodes[ is2ndV ? newNodes.size()-1 : 0 ] = (SMDS_MeshNode*) n;
+ }
+
+ // compute nodes on target EDGEs
+ DBGOUT( "COMPUTE V edge (proj) " << shapeID( lftSide->Edge(0)));
+ //rgtSide->Reverse(); // direct it same as the lftSide
+ myHelper->SetElementsOnShape( false ); // myHelper holds the prism shape
+ TopoDS_Edge tgtEdge;
+ for ( size_t iN = 1; iN < srcNodeStr.size()-1; ++iN ) // add nodes
+ {
+ gp_Pnt p = rgtSide->Value3d ( srcNodeStr[ iN ].normParam );
+ double u = rgtSide->Parameter( srcNodeStr[ iN ].normParam, tgtEdge );
+ newNodes[ iN ] = meshDS->AddNode( p.X(), p.Y(), p.Z() );
+ meshDS->SetNodeOnEdge( newNodes[ iN ], tgtEdge, u );
+ }
+ for ( size_t iN = 1; iN < srcNodeStr.size(); ++iN ) // add segments
+ {
+ // find an EDGE to set a new segment
+ std::pair<int, TopAbs_ShapeEnum> id2type =
+ myHelper->GetMediumPos( newNodes[ iN-1 ], newNodes[ iN ] );
+ if ( id2type.second != TopAbs_EDGE )
+ {
+ // new nodes are on different EDGEs; put one of them on VERTEX
+ const int edgeIndex = rgtSide->EdgeIndex( srcNodeStr[ iN-1 ].normParam );
+ const double vertexParam = rgtSide->LastParameter( edgeIndex );
+ TopoDS_Vertex vertex = rgtSide->LastVertex( edgeIndex );
+ const SMDS_MeshNode* vn = SMESH_Algo::VertexNode( vertex, meshDS );
+ const gp_Pnt p = BRep_Tool::Pnt( vertex );
+ const int isPrev = ( Abs( srcNodeStr[ iN-1 ].normParam - vertexParam ) <
+ Abs( srcNodeStr[ iN ].normParam - vertexParam ));
+ meshDS->UnSetNodeOnShape( newNodes[ iN-isPrev ] );
+ meshDS->SetNodeOnVertex ( newNodes[ iN-isPrev ], vertex );
+ meshDS->MoveNode ( newNodes[ iN-isPrev ], p.X(), p.Y(), p.Z() );
+ id2type.first = newNodes[ iN-(1-isPrev) ]->getshapeId();
+ if ( vn )
+ {
+ SMESH_MeshEditor::TListOfListOfNodes lln( 1, list< const SMDS_MeshNode* >() );
+ lln.back().push_back ( vn );
+ lln.back().push_front( newNodes[ iN-isPrev ] ); // to keep
+ SMESH_MeshEditor( mesh ).MergeNodes( lln );
+ }
+ }
+ SMDS_MeshElement* newEdge = myHelper->AddEdge( newNodes[ iN-1 ], newNodes[ iN ] );
+ meshDS->SetMeshElementOnShape( newEdge, id2type.first );
+ }
+ myHelper->SetElementsOnShape( true );
+ for ( int i = 0; i < rgtSide->NbEdges(); ++i ) // update state of sub-meshes
+ {
+ const TopoDS_Edge& E = rgtSide->Edge( i );
+ SMESH_subMesh* tgtSM = mesh->GetSubMesh( E );
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+
+ // to continue projection from the just computed side as a source
+ if ( !swapLeftRight && rgtSide->NbEdges() > 1 && w2q->second == iW )
+ {
+ std::pair<int,int> wgt2quadKeyVal( w2q->first + 1, thePrism.myRightQuadIndex[ iW ]);
+ wgt2quad.insert( wgt2quadKeyVal ); // it will be skipped by ++w2q
+ wgt2quad.insert( wgt2quadKeyVal );
+ w2q = wgt2quad.rbegin();
+ }
+ }
+ else
+ {
+ // HOPE assigned hypotheses are OK, so that equal nb of segments will be generated
+ //return toSM( error("Partial projection not implemented"));
+ }
+ } // loop on quads of a composite wall side
+ } // loop on the ordered wall sides
+
+
+
+ for ( size_t iW = 0; iW != thePrism.myWallQuads.size(); ++iW )
+ {
+ Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[iW].begin();
+ for ( ; quad != thePrism.myWallQuads[iW].end(); ++quad )
+ {
+ const TopoDS_Face& face = (*quad)->face;
+ SMESH_subMesh* fSM = mesh->GetSubMesh( face );
+ if ( ! fSM->IsMeshComputed() )
+ {
+ // Top EDGEs must be projections from the bottom ones
+ // to compute structured quad mesh on wall FACEs
+ // ---------------------------------------------------
+ const TopoDS_Edge& botE = (*quad)->side[ QUAD_BOTTOM_SIDE ].grid->Edge(0);
+ const TopoDS_Edge& topE = (*quad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
+ SMESH_subMesh* botSM = mesh->GetSubMesh( botE );
+ SMESH_subMesh* topSM = mesh->GetSubMesh( topE );
+ SMESH_subMesh* srcSM = botSM;
+ SMESH_subMesh* tgtSM = topSM;
+ srcSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ if ( !srcSM->IsMeshComputed() && tgtSM->IsMeshComputed() )
+ std::swap( srcSM, tgtSM );
+
+ if ( !srcSM->IsMeshComputed() )
+ {
+ DBGOUT( "COMPUTE H edge " << srcSM->GetId());
+ srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE ); // nodes on VERTEXes
+ srcSM->ComputeStateEngine( SMESH_subMesh::COMPUTE ); // segments on the EDGE
+ }
+
+ if ( tgtSM->IsMeshComputed() &&
+ tgtSM->GetSubMeshDS()->NbNodes() != srcSM->GetSubMeshDS()->NbNodes() )
+ {
+ // the top EDGE is computed differently than the bottom one,
+ // try to clear a wrong mesh
+ bool isAdjFaceMeshed = false;
+ PShapeIteratorPtr fIt = myHelper->GetAncestors( tgtSM->GetSubShape(),
+ *mesh, TopAbs_FACE );
+ while ( const TopoDS_Shape* f = fIt->next() )
+ if (( isAdjFaceMeshed = mesh->GetSubMesh( *f )->IsMeshComputed() ))
+ break;
+ if ( isAdjFaceMeshed )
+ return toSM( error( TCom("Different nb of segment on logically horizontal edges #")
+ << shapeID( botE ) << " and #"
+ << shapeID( topE ) << ": "
+ << tgtSM->GetSubMeshDS()->NbElements() << " != "
+ << srcSM->GetSubMeshDS()->NbElements() ));
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
+ }
+ if ( !tgtSM->IsMeshComputed() )
+ {
+ // compute nodes on VERTEXes
+ SMESH_subMeshIteratorPtr smIt = tgtSM->getDependsOnIterator(/*includeSelf=*/false);
+ while ( smIt->more() )
+ smIt->next()->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+ // project segments
+ DBGOUT( "COMPUTE H edge (proj) " << tgtSM->GetId());
+ projector1D->myHyp.SetSourceEdge( TopoDS::Edge( srcSM->GetSubShape() ));
+ projector1D->InitComputeError();
+ bool ok = projector1D->Compute( *mesh, tgtSM->GetSubShape() );
+ if ( !ok )
+ {
+ SMESH_ComputeErrorPtr err = projector1D->GetComputeError();
+ if ( err->IsOK() ) err->myName = COMPERR_ALGO_FAILED;
+ tgtSM->GetComputeError() = err;
+ return false;
+ }
+ }
+ tgtSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+
+
+ // Compute quad mesh on wall FACEs
+ // -------------------------------
+
+ // make all EDGES meshed
+ fSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ if ( !fSM->SubMeshesComputed() )
+ return toSM( error( COMPERR_BAD_INPUT_MESH,
+ "Not all edges have valid algorithm and hypothesis"));
+ // mesh the <face>
+ quadAlgo->InitComputeError();
+ DBGOUT( "COMPUTE Quad face " << fSM->GetId());
+ bool ok = quadAlgo->Compute( *mesh, face );
+ fSM->GetComputeError() = quadAlgo->GetComputeError();
+ if ( !ok )
+ return false;
+ fSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+ if ( myHelper->GetIsQuadratic() )
+ {
+ // fill myHelper with medium nodes built by quadAlgo
+ for ( SMDS_ElemIteratorPtr fIt = fSM->GetSubMeshDS()->GetElements(); fIt->more(); )
+ myHelper->AddTLinks( SMDS_Mesh::DownCast<SMDS_MeshFace>( fIt->next() ));
+ }
+ }
+ }
+
+ return true;
+}
+
+//=======================================================================
+//function : findPropagationSource
+//purpose : Returns a source EDGE of propagation to a given EDGE
+//=======================================================================
+
+TopoDS_Edge StdMeshers_Prism_3D::findPropagationSource( const TopoDS_Edge& E )
+{
+ if ( myPropagChains )
+ for ( size_t i = 0; !myPropagChains[i].IsEmpty(); ++i )
+ if ( myPropagChains[i].Contains( E ))
+ return TopoDS::Edge( myPropagChains[i].FindKey( 1 ));
+
+ return TopoDS_Edge();
+}
+
+//=======================================================================
+//function : makeQuadsForOutInProjection
+//purpose : Create artificial wall quads for vertical projection between
+// the outer and inner walls
+//=======================================================================
+
+void StdMeshers_Prism_3D::makeQuadsForOutInProjection( const Prism_3D::TPrismTopo& thePrism,
+ multimap< int, int >& wgt2quad,
+ map< int, FaceQuadStruct >& iQ2oiQuads)
+{
+ if ( thePrism.NbWires() <= 1 )
+ return;
+
+ std::set< int > doneWires; // processed wires
+
+ SMESH_Mesh* mesh = myHelper->GetMesh();
+ const bool isForward = true;
+ const bool skipMedium = myHelper->GetIsQuadratic();
+
+ // make a source side for all projections
+
+ multimap< int, int >::reverse_iterator w2q = wgt2quad.rbegin();
+ const int iQuad = w2q->second;
+ const int iWire = getWireIndex( thePrism.myWallQuads[ iQuad ].front() );
+ doneWires.insert( iWire );
+
+ UVPtStructVec srcNodes;
+
+ Prism_3D::TQuadList::const_iterator quad = thePrism.myWallQuads[ iQuad ].begin();
+ for ( ; quad != thePrism.myWallQuads[ iQuad ].end(); ++quad )
+ {
+ StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
+
+ // assure that all the source (left) EDGEs are meshed
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ {
+ const TopoDS_Edge& srcE = lftSide->Edge(i);
+ SMESH_subMesh* srcSM = mesh->GetSubMesh( srcE );
+ if ( !srcSM->IsMeshComputed() ) {
+ srcSM->ComputeSubMeshStateEngine( SMESH_subMesh::COMPUTE );
+ srcSM->ComputeStateEngine ( SMESH_subMesh::COMPUTE );
+ }
+ if ( !srcSM->IsMeshComputed() )
+ return;
+ }
+ const UVPtStructVec& subNodes = lftSide->GetUVPtStruct();
+ UVPtStructVec::const_iterator subBeg = subNodes.begin(), subEnd = subNodes.end();
+ if ( !srcNodes.empty() ) ++subBeg;
+ srcNodes.insert( srcNodes.end(), subBeg, subEnd );
+ }
+ StdMeshers_FaceSidePtr srcSide = StdMeshers_FaceSide::New( srcNodes );
+
+ // make the quads
+
+ list< TopoDS_Edge > sideEdges;
+ TopoDS_Face face;
+ for ( ++w2q; w2q != wgt2quad.rend(); ++w2q )
+ {
+ const int iQuad = w2q->second;
+ const Prism_3D::TQuadList& quads = thePrism.myWallQuads[ iQuad ];
+ const int iWire = getWireIndex( quads.front() );
+ if ( !doneWires.insert( iWire ).second )
+ continue;
+
+ sideEdges.clear();
+ for ( quad = quads.begin(); quad != quads.end(); ++quad )
+ {
+ StdMeshers_FaceSidePtr lftSide = (*quad)->side[ QUAD_LEFT_SIDE ];
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ sideEdges.push_back( lftSide->Edge( i ));
+ face = lftSide->Face();
+ }
+ StdMeshers_FaceSidePtr tgtSide =
+ StdMeshers_FaceSide::New( face, sideEdges, mesh, isForward, skipMedium, myHelper );
+
+ FaceQuadStruct& newQuad = iQ2oiQuads[ iQuad ];
+ newQuad.side.resize( 4 );
+ newQuad.side[ QUAD_LEFT_SIDE ] = srcSide;
+ newQuad.side[ QUAD_RIGHT_SIDE ] = tgtSide;
+
+ wgt2quad.insert( *w2q ); // to process this quad after processing the newQuad
+ }
+}
+
+//=======================================================================
+//function : Evaluate
+//purpose :
+//=======================================================================
+
+bool StdMeshers_Prism_3D::Evaluate(SMESH_Mesh& theMesh,
+ const TopoDS_Shape& theShape,
+ MapShapeNbElems& aResMap)
+{
+ if ( theShape.ShapeType() == TopAbs_COMPOUND )
+ {
+ bool ok = true;
+ for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
+ ok &= Evaluate( theMesh, it.Value(), aResMap );
+ return ok;
+ }
+ SMESH_MesherHelper helper( theMesh );
+ myHelper = &helper;
+ myHelper->SetSubShape( theShape );
+
+ // find face contains only triangles
+ vector < SMESH_subMesh * >meshFaces;
+ TopTools_SequenceOfShape aFaces;
+ int NumBase = 0, i = 0, NbQFs = 0;
+ for (TopExp_Explorer exp(theShape, TopAbs_FACE); exp.More(); exp.Next()) {
+ i++;
+ aFaces.Append(exp.Current());
+ SMESH_subMesh *aSubMesh = theMesh.GetSubMesh(exp.Current());
+ meshFaces.push_back(aSubMesh);
+ MapShapeNbElemsItr anIt = aResMap.find(meshFaces[i-1]);
+ if( anIt==aResMap.end() )
+ return toSM( error( "Submesh can not be evaluated"));
+
+ std::vector<int> aVec = (*anIt).second;
+ int nbtri = Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
+ int nbqua = Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
+ if( nbtri==0 && nbqua>0 ) {
+ NbQFs++;
+ }
+ if( nbtri>0 ) {
+ NumBase = i;
+ }
+ }
+
+ if(NbQFs<4) {
+ std::vector<int> aResVec(SMDSEntity_Last);
+ for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
+ SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
+ aResMap.insert(std::make_pair(sm,aResVec));
+ return toSM( error( "Submesh can not be evaluated" ));
+ }
+
+ if(NumBase==0) NumBase = 1; // only quads => set 1 faces as base
+
+ // find number of 1d elems for base face
+ int nb1d = 0;
+ TopTools_MapOfShape Edges1;
+ for (TopExp_Explorer exp(aFaces.Value(NumBase), TopAbs_EDGE); exp.More(); exp.Next()) {
+ Edges1.Add(exp.Current());
+ SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
+ if( sm ) {
+ MapShapeNbElemsItr anIt = aResMap.find(sm);
+ if( anIt == aResMap.end() ) continue;
+ std::vector<int> aVec = (*anIt).second;
+ nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
+ }
+ }
+ // find face opposite to base face
+ int OppNum = 0;
+ for(i=1; i<=6; i++) {
+ if(i==NumBase) continue;
+ bool IsOpposite = true;
+ for(TopExp_Explorer exp(aFaces.Value(i), TopAbs_EDGE); exp.More(); exp.Next()) {
+ if( Edges1.Contains(exp.Current()) ) {
+ IsOpposite = false;
+ break;