+ // below in the loop we try to find source FACEs somehow
+
+ // project mesh from source FACEs of computed prisms to
+ // prisms sharing wall FACEs
+ list< Prism_3D::TPrismTopo >::iterator prismIt = meshedPrism.begin();
+ for ( ; prismIt != meshedPrism.end(); ++prismIt )
+ {
+ for ( size_t iW = 0; iW < prismIt->myWallQuads.size(); ++iW )
+ {
+ Prism_3D::TQuadList::iterator wQuad = prismIt->myWallQuads[iW].begin();
+ for ( ; wQuad != prismIt->myWallQuads[iW].end(); ++ wQuad )
+ {
+ const TopoDS_Face& wFace = (*wQuad)->face;
+ TopTools_ListOfShape& solidList = faceToSolids.ChangeFromKey( wFace );
+ solidIt.Initialize( solidList );
+ while ( solidIt.More() )
+ {
+ const TopoDS_Shape& solid = solidIt.Value();
+ if ( meshedSolids.Contains( solid )) {
+ solidList.Remove( solidIt );
+ continue; // already computed prism
+ }
+ // find a source FACE of the SOLID: it's a FACE sharing a bottom EDGE with wFace
+ const TopoDS_Edge& wEdge = (*wQuad)->side[ QUAD_TOP_SIDE ].grid->Edge(0);
+ PShapeIteratorPtr faceIt = myHelper->GetAncestors( wEdge, *myHelper->GetMesh(),
+ TopAbs_FACE);
+ while ( const TopoDS_Shape* f = faceIt->next() )
+ {
+ const TopoDS_Face& candidateF = TopoDS::Face( *f );
+ prism.Clear();
+ prism.myBottom = candidateF;
+ mySetErrorToSM = false;
+ if ( !myHelper->IsSubShape( candidateF, prismIt->myShape3D ) &&
+ !myHelper->GetMesh()->GetSubMesh( candidateF )->IsMeshComputed() &&
+ initPrism( prism, solid ) &&
+ project2dMesh( prismIt->myBottom, candidateF))
+ {
+ mySetErrorToSM = true;
+ if ( !compute( prism ))
+ return false;
+ meshedFaces.push_front( prism.myTop );
+ meshedFaces.push_front( prism.myBottom );
+ meshedPrism.push_back( prism );
+ meshedSolids.Add( solid );
+ }
+ InitComputeError();
+ }
+ mySetErrorToSM = true;
+ InitComputeError();
+ if ( meshedSolids.Contains( solid ))
+ solidList.Remove( solidIt );
+ else
+ solidIt.Next();
+ }
+ }
+ }
+ if ( !meshedFaces.empty() )
+ break; // to compute prisms with avident sources
+ }
+
+ // find FACEs with local 1D hyps, which has to be computed by now,
+ // or at least any computed FACEs
+ for ( int iF = 1; ( meshedFaces.empty() && iF < faceToSolids.Extent() ); ++iF )
+ {
+ const TopoDS_Face& face = TopoDS::Face( faceToSolids.FindKey( iF ));
+ const TopTools_ListOfShape& solidList = faceToSolids.FindFromKey( face );
+ if ( solidList.IsEmpty() ) continue;
+ SMESH_subMesh* faceSM = theMesh.GetSubMesh( face );
+ if ( !faceSM->IsEmpty() )
+ {
+ meshedFaces.push_back( face ); // lower priority
+ }
+ else
+ {
+ bool allSubMeComputed = true;
+ SMESH_subMeshIteratorPtr smIt = faceSM->getDependsOnIterator(false,true);
+ while ( smIt->more() && allSubMeComputed )
+ allSubMeComputed = smIt->next()->IsMeshComputed();
+ if ( allSubMeComputed )
+ {
+ faceSM->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+ if ( !faceSM->IsEmpty() )
+ meshedFaces.push_front( face ); // higher priority
+ else
+ faceSM->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ }
+ }
+ }
+
+
+ // TODO. there are other ways to find out the source FACE:
+ // propagation, topological similarity, ect.
+
+ // simply try to mesh all not meshed SOLIDs
+ if ( meshedFaces.empty() )
+ {
+ for ( TopExp_Explorer solid( theShape, TopAbs_SOLID ); solid.More(); solid.Next() )
+ {
+ mySetErrorToSM = false;
+ prism.Clear();
+ if ( !meshedSolids.Contains( solid.Current() ) &&
+ initPrism( prism, solid.Current() ))
+ {
+ mySetErrorToSM = true;
+ if ( !compute( prism ))
+ return false;
+ meshedFaces.push_front( prism.myTop );
+ meshedFaces.push_front( prism.myBottom );
+ meshedPrism.push_back( prism );
+ meshedSolids.Add( solid.Current() );
+ }
+ mySetErrorToSM = true;
+ }
+ }
+
+ if ( meshedFaces.empty() ) // set same error to 10 not-computed solids
+ {
+ SMESH_ComputeErrorPtr err = SMESH_ComputeError::New
+ ( COMPERR_BAD_INPUT_MESH, "No meshed source face found", this );
+
+ const int maxNbErrors = 10; // limit nb errors not to overload the Compute dialog
+ TopExp_Explorer solid( theShape, TopAbs_SOLID );
+ for ( int i = 0; ( i < maxNbErrors && solid.More() ); ++i, solid.Next() )
+ if ( !meshedSolids.Contains( solid.Current() ))
+ {
+ SMESH_subMesh* sm = theMesh.GetSubMesh( solid.Current() );
+ sm->GetComputeError() = err;
+ }
+ return error( err );
+ }
+ }
+ return true;
+}
+
+//================================================================================
+/*!
+ * \brief Find wall faces by bottom edges
+ */
+//================================================================================
+
+bool StdMeshers_Prism_3D::getWallFaces( Prism_3D::TPrismTopo & thePrism,
+ const int totalNbFaces)
+{
+ thePrism.myWallQuads.clear();
+
+ SMESH_Mesh* mesh = myHelper->GetMesh();
+
+ StdMeshers_Quadrangle_2D* quadAlgo = TQuadrangleAlgo::instance( this, myHelper );
+
+ TopTools_MapOfShape faceMap;
+ TopTools_IndexedDataMapOfShapeListOfShape edgeToFaces;
+ TopExp::MapShapesAndAncestors( thePrism.myShape3D,
+ TopAbs_EDGE, TopAbs_FACE, edgeToFaces );
+
+ // ------------------------------
+ // Get the 1st row of wall FACEs
+ // ------------------------------
+
+ list< TopoDS_Edge >::iterator edge = thePrism.myBottomEdges.begin();
+ std::list< int >::iterator nbE = thePrism.myNbEdgesInWires.begin();
+ int iE = 0;
+ double f,l;
+ while ( edge != thePrism.myBottomEdges.end() )
+ {
+ ++iE;
+ if ( BRep_Tool::Curve( *edge, f,l ).IsNull() )
+ {
+ edge = thePrism.myBottomEdges.erase( edge );
+ --iE;
+ --(*nbE);
+ }
+ else
+ {
+ TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( *edge ));
+ for ( ; faceIt.More(); faceIt.Next() )
+ {
+ const TopoDS_Face& face = TopoDS::Face( faceIt.Value() );
+ if ( !thePrism.myBottom.IsSame( face ))
+ {
+ Prism_3D::TQuadList quadList( 1, quadAlgo->CheckNbEdges( *mesh, face ));
+ if ( !quadList.back() )
+ return toSM( error(TCom("Side face #") << shapeID( face )
+ << " not meshable with quadrangles"));
+ if ( ! setBottomEdge( *edge, quadList.back(), face ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ thePrism.myWallQuads.push_back( quadList );
+ faceMap.Add( face );
+ break;
+ }
+ }
+ ++edge;
+ }
+ if ( iE == *nbE )
+ {
+ iE = 0;
+ ++nbE;
+ }
+ }
+
+ // -------------------------
+ // Find the rest wall FACEs
+ // -------------------------
+
+ // Compose a vector of indixes of right neighbour FACE for each wall FACE
+ // that is not so evident in case of several WIREs in the bottom FACE
+ thePrism.myRightQuadIndex.clear();
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ thePrism.myRightQuadIndex.push_back( i+1 );
+ list< int >::iterator nbEinW = thePrism.myNbEdgesInWires.begin();
+ for ( int iLeft = 0; nbEinW != thePrism.myNbEdgesInWires.end(); ++nbEinW )
+ {
+ thePrism.myRightQuadIndex[ iLeft + *nbEinW - 1 ] = iLeft; // 1st EDGE index of a current WIRE
+ iLeft += *nbEinW;
+ }
+
+ while ( totalNbFaces - faceMap.Extent() > 2 )
+ {
+ // find wall FACEs adjacent to each of wallQuads by the right side EDGE
+ int nbKnownFaces;
+ do {
+ nbKnownFaces = faceMap.Extent();
+ StdMeshers_FaceSidePtr rightSide, topSide; // sides of the quad
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ rightSide = thePrism.myWallQuads[i].back()->side[ QUAD_RIGHT_SIDE ];
+ for ( int iE = 0; iE < rightSide->NbEdges(); ++iE ) // rightSide can be composite
+ {
+ const TopoDS_Edge & rightE = rightSide->Edge( iE );
+ TopTools_ListIteratorOfListOfShape face( edgeToFaces.FindFromKey( rightE ));
+ for ( ; face.More(); face.Next() )
+ if ( faceMap.Add( face.Value() ))
+ {
+ // a new wall FACE encountered, store it in thePrism.myWallQuads
+ const int iRight = thePrism.myRightQuadIndex[i];
+ topSide = thePrism.myWallQuads[ iRight ].back()->side[ QUAD_TOP_SIDE ];
+ const TopoDS_Edge& newBotE = topSide->Edge(0);
+ const TopoDS_Shape& newWallF = face.Value();
+ thePrism.myWallQuads[ iRight ].push_back( quadAlgo->CheckNbEdges( *mesh, newWallF ));
+ if ( !thePrism.myWallQuads[ iRight ].back() )
+ return toSM( error(TCom("Side face #") << shapeID( newWallF ) <<
+ " not meshable with quadrangles"));
+ if ( ! setBottomEdge( newBotE, thePrism.myWallQuads[ iRight ].back(), newWallF ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ }
+ }
+ }
+ } while ( nbKnownFaces != faceMap.Extent() );
+
+ // find wall FACEs adjacent to each of thePrism.myWallQuads by the top side EDGE
+ if ( totalNbFaces - faceMap.Extent() > 2 )
+ {
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
+ const TopoDS_Edge & topE = topSide->Edge( 0 );
+ if ( topSide->NbEdges() > 1 )
+ return toSM( error(COMPERR_BAD_SHAPE, TCom("Side face #") <<
+ shapeID( thePrism.myWallQuads[i].back()->face )
+ << " has a composite top edge"));
+ TopTools_ListIteratorOfListOfShape faceIt( edgeToFaces.FindFromKey( topE ));
+ for ( ; faceIt.More(); faceIt.Next() )
+ if ( faceMap.Add( faceIt.Value() ))
+ {
+ // a new wall FACE encountered, store it in wallQuads
+ thePrism.myWallQuads[ i ].push_back( quadAlgo->CheckNbEdges( *mesh, faceIt.Value() ));
+ if ( !thePrism.myWallQuads[ i ].back() )
+ return toSM( error(TCom("Side face #") << shapeID( faceIt.Value() ) <<
+ " not meshable with quadrangles"));
+ if ( ! setBottomEdge( topE, thePrism.myWallQuads[ i ].back(), faceIt.Value() ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ if ( totalNbFaces - faceMap.Extent() == 2 )
+ {
+ i = thePrism.myWallQuads.size(); // to quit from the outer loop
+ break;
+ }
+ }
+ }
+ }
+ } // while ( totalNbFaces - faceMap.Extent() > 2 )
+
+ // ------------------
+ // Find the top FACE
+ // ------------------
+
+ if ( thePrism.myTop.IsNull() )
+ {
+ // now only top and bottom FACEs are not in the faceMap
+ faceMap.Add( thePrism.myBottom );
+ for ( TopExp_Explorer f( thePrism.myShape3D, TopAbs_FACE );f.More(); f.Next() )
+ if ( !faceMap.Contains( f.Current() )) {
+ thePrism.myTop = TopoDS::Face( f.Current() );
+ break;
+ }
+ if ( thePrism.myTop.IsNull() )
+ return toSM( error("Top face not found"));
+ }
+
+ // Check that the top FACE shares all the top EDGEs
+ for ( size_t i = 0; i < thePrism.myWallQuads.size(); ++i )
+ {
+ StdMeshers_FaceSidePtr topSide = thePrism.myWallQuads[i].back()->side[ QUAD_TOP_SIDE ];
+ const TopoDS_Edge & topE = topSide->Edge( 0 );
+ if ( !myHelper->IsSubShape( topE, thePrism.myTop ))
+ return toSM( error( TCom("Wrong source face (#") << shapeID( thePrism.myBottom )));
+ }
+
+ return true;
+}
+
+//=======================================================================
+//function : compute
+//purpose : Compute mesh on a SOLID
+//=======================================================================
+
+bool StdMeshers_Prism_3D::compute(const Prism_3D::TPrismTopo& thePrism)
+{
+ myHelper->IsQuadraticSubMesh( thePrism.myShape3D );
+ if ( _computeCanceled )
+ return toSM( error( SMESH_ComputeError::New(COMPERR_CANCELED)));
+
+ // Make all side FACEs of thePrism meshed with quads
+ if ( !computeWalls( thePrism ))
+ return false;
+
+ // Analyse mesh and geometry to find all block sub-shapes and submeshes
+ if ( !myBlock.Init( myHelper, thePrism ))
+ return toSM( error( myBlock.GetError()));
+
+ SMESHDS_Mesh* meshDS = myHelper->GetMeshDS();
+
+ int volumeID = meshDS->ShapeToIndex( thePrism.myShape3D );
+
+ // Try to get gp_Trsf to get all nodes from bottom ones
+ vector<gp_Trsf> trsf;
+ gp_Trsf bottomToTopTrsf;
+ if ( !myBlock.GetLayersTransformation( trsf, thePrism ))
+ trsf.clear();
+ else if ( !trsf.empty() )
+ bottomToTopTrsf = trsf.back();