+ // ------------------------------
+ // 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"));
+ bool isCompositeBase = ! setBottomEdge( *edge, quadList.back(), face );
+ if ( isCompositeBase )
+ {
+ // it's OK if all EDGEs of the bottom side belongs to the bottom FACE
+ StdMeshers_FaceSidePtr botSide = quadList.back()->side[ QUAD_BOTTOM_SIDE ];
+ for ( int iE = 0; iE < botSide->NbEdges(); ++iE )
+ if ( !myHelper->IsSubShape( botSide->Edge(iE), thePrism.myBottom ))
+ return toSM( error(TCom("Composite 'horizontal' edges are not supported")));
+ }
+ if ( faceMap.Add( face ))
+ thePrism.myWallQuads.push_back( quadList );
+ 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 )
+ {
+ const int nbFoundWalls = faceMap.Extent();
+ 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;
+ }
+ }
+ }
+ if ( nbFoundWalls == faceMap.Extent() )
+ return toSM( error("Failed to find wall faces"));
+
+ }
+ } // 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)));
+
+ // Assure the bottom is meshed
+ SMESH_subMesh * botSM = myHelper->GetMesh()->GetSubMesh( thePrism.myBottom );
+ if (( botSM->IsEmpty() ) &&
+ ( ! botSM->GetAlgo() ||
+ ! _gen->Compute( *botSM->GetFather(), botSM->GetSubShape(), /*shapeOnly=*/true )))
+ return error( COMPERR_BAD_INPUT_MESH,
+ TCom( "No mesher defined to compute the face #")
+ << shapeID( thePrism.myBottom ));
+
+ // 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
+ // (after fixing IPAL52499 myBlock is used as a holder of boundary nodes
+ // and for 2D projection in hard cases where StdMeshers_Projection_2D fails;
+ // location of internal nodes is usually computed by StdMeshers_Sweeper)
+ 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();
+
+ // To compute coordinates of a node inside a block, it is necessary to know
+ // 1. normalized parameters of the node by which
+ // 2. coordinates of node projections on all block sub-shapes are computed
+
+ // So we fill projections on vertices at once as they are same for all nodes
+ myShapeXYZ.resize( myBlock.NbSubShapes() );
+ for ( int iV = SMESH_Block::ID_FirstV; iV < SMESH_Block::ID_FirstE; ++iV ) {
+ myBlock.VertexPoint( iV, myShapeXYZ[ iV ]);
+ SHOWYXZ("V point " <<iV << " ", myShapeXYZ[ iV ]);
+ }
+
+ // Projections on the top and bottom faces are taken from nodes existing
+ // on these faces; find correspondence between bottom and top nodes
+ myUseBlock = false;
+ myBotToColumnMap.clear();
+ if ( !assocOrProjBottom2Top( bottomToTopTrsf, thePrism ) ) // it also fills myBotToColumnMap
+ return false;
+
+
+ // Create nodes inside the block
+
+ // use transformation (issue 0020680, IPAL0052499)
+ StdMeshers_Sweeper sweeper;
+ double tol;
+ bool allowHighBndError;
+
+ if ( !myUseBlock )
+ {
+ // load boundary nodes into sweeper
+ bool dummy;
+ list< TopoDS_Edge >::const_iterator edge = thePrism.myBottomEdges.begin();
+ for ( ; edge != thePrism.myBottomEdges.end(); ++edge )
+ {
+ int edgeID = meshDS->ShapeToIndex( *edge );
+ TParam2ColumnMap* u2col = const_cast<TParam2ColumnMap*>
+ ( myBlock.GetParam2ColumnMap( edgeID, dummy ));
+ TParam2ColumnMap::iterator u2colIt = u2col->begin();
+ for ( ; u2colIt != u2col->end(); ++u2colIt )
+ sweeper.myBndColumns.push_back( & u2colIt->second );
+ }
+ // load node columns inside the bottom face
+ TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
+ for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
+ sweeper.myIntColumns.push_back( & bot_column->second );
+
+ tol = getSweepTolerance( thePrism );
+ allowHighBndError = !isSimpleBottom( thePrism );
+ }
+
+ if ( !myUseBlock && sweeper.ComputeNodes( *myHelper, tol, allowHighBndError ))
+ {
+ }
+ else // use block approach
+ {
+ // loop on nodes inside the bottom face
+ Prism_3D::TNode prevBNode;
+ TNode2ColumnMap::iterator bot_column = myBotToColumnMap.begin();
+ for ( ; bot_column != myBotToColumnMap.end(); ++bot_column )
+ {
+ const Prism_3D::TNode& tBotNode = bot_column->first; // bottom TNode
+ if ( tBotNode.GetPositionType() != SMDS_TOP_FACE )
+ continue; // node is not inside the FACE
+
+ // column nodes; middle part of the column are zero pointers
+ TNodeColumn& column = bot_column->second;
+
+ gp_XYZ botParams, topParams;
+ if ( !tBotNode.HasParams() )
+ {
+ // compute bottom node parameters
+ gp_XYZ paramHint(-1,-1,-1);
+ if ( prevBNode.IsNeighbor( tBotNode ))
+ paramHint = prevBNode.GetParams();
+ if ( !myBlock.ComputeParameters( tBotNode.GetCoords(), tBotNode.ChangeParams(),
+ ID_BOT_FACE, paramHint ))
+ return toSM( error(TCom("Can't compute normalized parameters for node ")
+ << tBotNode.myNode->GetID() << " on the face #"
+ << myBlock.SubMesh( ID_BOT_FACE )->GetId() ));
+ prevBNode = tBotNode;
+
+ botParams = topParams = tBotNode.GetParams();
+ topParams.SetZ( 1 );
+
+ // compute top node parameters
+ if ( column.size() > 2 ) {
+ gp_Pnt topCoords = gpXYZ( column.back() );
+ if ( !myBlock.ComputeParameters( topCoords, topParams, ID_TOP_FACE, topParams ))
+ return toSM( error(TCom("Can't compute normalized parameters ")
+ << "for node " << column.back()->GetID()
+ << " on the face #"<< column.back()->getshapeId() ));
+ }
+ }
+ else // top nodes are created by projection using parameters
+ {
+ botParams = topParams = tBotNode.GetParams();
+ topParams.SetZ( 1 );
+ }
+
+ myShapeXYZ[ ID_BOT_FACE ] = tBotNode.GetCoords();
+ myShapeXYZ[ ID_TOP_FACE ] = gpXYZ( column.back() );
+
+ // vertical loop
+ TNodeColumn::iterator columnNodes = column.begin();
+ for ( int z = 0; columnNodes != column.end(); ++columnNodes, ++z)
+ {
+ const SMDS_MeshNode* & node = *columnNodes;
+ if ( node ) continue; // skip bottom or top node
+
+ // params of a node to create
+ double rz = (double) z / (double) ( column.size() - 1 );
+ gp_XYZ params = botParams * ( 1 - rz ) + topParams * rz;
+
+ // set coords on all faces and nodes
+ const int nbSideFaces = 4;
+ int sideFaceIDs[nbSideFaces] = { SMESH_Block::ID_Fx0z,
+ SMESH_Block::ID_Fx1z,
+ SMESH_Block::ID_F0yz,
+ SMESH_Block::ID_F1yz };
+ for ( int iF = 0; iF < nbSideFaces; ++iF )
+ if ( !setFaceAndEdgesXYZ( sideFaceIDs[ iF ], params, z ))
+ return false;
+
+ // compute coords for a new node
+ gp_XYZ coords;
+ if ( !SMESH_Block::ShellPoint( params, myShapeXYZ, coords ))
+ return toSM( error("Can't compute coordinates by normalized parameters"));
+
+ // if ( !meshDS->MeshElements( volumeID ) ||
+ // meshDS->MeshElements( volumeID )->NbNodes() == 0 )
+ // pointsToPython(myShapeXYZ);
+ SHOWYXZ("TOPFacePoint ",myShapeXYZ[ ID_TOP_FACE]);
+ SHOWYXZ("BOT Node "<< tBotNode.myNode->GetID(),gpXYZ(tBotNode.myNode));
+ SHOWYXZ("ShellPoint ",coords);
+
+ // create a node
+ node = meshDS->AddNode( coords.X(), coords.Y(), coords.Z() );
+ meshDS->SetNodeInVolume( node, volumeID );
+
+ if ( _computeCanceled )
+ return false;
+ }
+ } // loop on bottom nodes
+ }
+
+ // Create volumes
+
+ SMESHDS_SubMesh* smDS = myBlock.SubMeshDS( ID_BOT_FACE );
+ if ( !smDS ) return toSM( error(COMPERR_BAD_INPUT_MESH, "Null submesh"));
+
+ // loop on bottom mesh faces
+ SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
+ while ( faceIt->more() )
+ {
+ const SMDS_MeshElement* face = faceIt->next();
+ if ( !face || face->GetType() != SMDSAbs_Face )
+ continue;
+
+ // find node columns for each node
+ int nbNodes = face->NbCornerNodes();
+ vector< const TNodeColumn* > columns( nbNodes );
+ for ( int i = 0; i < nbNodes; ++i )
+ {
+ const SMDS_MeshNode* n = face->GetNode( i );
+ if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_FACE ) {
+ TNode2ColumnMap::iterator bot_column = myBotToColumnMap.find( n );
+ if ( bot_column == myBotToColumnMap.end() )
+ return toSM( error(TCom("No nodes found above node ") << n->GetID() ));
+ columns[ i ] = & bot_column->second;
+ }
+ else {
+ columns[ i ] = myBlock.GetNodeColumn( n );
+ if ( !columns[ i ] )
+ return toSM( error(TCom("No side nodes found above node ") << n->GetID() ));
+ }
+ }
+ // create prisms
+ AddPrisms( columns, myHelper );
+
+ } // loop on bottom mesh faces
+
+ // clear data
+ myBotToColumnMap.clear();
+ myBlock.Clear();
+
+ 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 ];
+ 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 ));
+
+ // 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 );
+
+ // assure that all the source (left) EDGEs are meshed
+ int nbSrcSegments = 0;
+ for ( int i = 0; i < lftSide->NbEdges(); ++i )
+ {
+ 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 #") <<
+ shapeID( lftSide->Edge(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 ? 0 : newNodes.size()-1 ] = (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();
+ }