diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index c68c1a3..74d7bb5 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/StmFromCurves.cpp b/StmFromCurves.cpp index 3e8c884..d11f146 100644 --- a/StmFromCurves.cpp +++ b/StmFromCurves.cpp @@ -328,22 +328,13 @@ GetSurfTriMeshSwept( const ICurve* pSect, const ICurve* pGuide, bool bCapEnds, d frStart.Set( ptStart, -vtStart, vtStart ^ vtExtr) ; // porto la sezione in questo riferimento if ( ! PL.ToLoc( frStart)) - return false ; + return nullptr ; // calcolo la superficie PtrOwner pSTM( CreateSurfTriMesh()) ; if ( IsNull( pSTM)) return false ; - // se richiesti caps, sezione chiusa e guida aperta, creo cap iniziale - if ( bCapEnds && bSectClosed && ! bGuideClosed) { - // creo e setto la superficie trimesh - PtrOwner pSc( CreateSurfTriMesh()) ; - if ( IsNull( pSc) || ! pSc->CreateByFlatContour( PL)) - return nullptr ; - // la porto in globale - pSc->ToGlob( frStart) ; - // aggiungo alla superficie complessiva - pSTM->DoSewing( *pSc) ; - } + // salvo tolleranza lineare usata + pSTM->SetLinearTolerance( dLinTol) ; // superficie swept PtrOwner pPrevCrv ; Point3d ptP ; @@ -352,16 +343,16 @@ GetSurfTriMeshSwept( const ICurve* pSect, const ICurve* pGuide, bool bCapEnds, d // nuova curva OffsetCurve OffsCrv ; if ( ! OffsCrv.Make( pGuide, ptP.x, ICurve::OFF_FILLET) || OffsCrv.GetCurveCount() > 1) - return false ; + return nullptr ; PtrOwner pCurrCrv( OffsCrv.GetLongerCurve()) ; if ( IsNull( pCurrCrv)) - return false ; + return nullptr ; pCurrCrv->Translate( ptP.y * frStart.VersY() + ptP.z * frStart.VersZ()) ; // se esiste la curva precedente, costruisco la rigata (di tipo minima distanza) if ( ! IsNull( pPrevCrv)) { PtrOwner pSr( GetSurfTriMeshRuled( pPrevCrv, pCurrCrv, ISurfTriMesh::RLT_MINDIST, dLinTol)) ; if ( IsNull( pSr)) - return false ; + return nullptr ; pSTM->DoSewing( *pSr) ; } // salvo la curva come prossima precedente @@ -369,8 +360,25 @@ GetSurfTriMeshSwept( const ICurve* pSect, const ICurve* pGuide, bool bCapEnds, d // prossimo punto bPoint = PL.GetNextPoint( ptP) ; } - // se richiesti caps, sezione chiusa e guida aperta, creo cap finale + // se richiesti caps e sezione chiusa e guida aperta if ( bCapEnds && bSectClosed && ! bGuideClosed) { + // verifico che le due estremità siano piatte + POLYLINEVECTOR vPL ; + if ( ! pSTM->GetLoops( vPL) || vPL.size() != 2) + return nullptr ; + int nRank ; + Point3d ptCen ; + Vector3d vtDir ; + if ( ! vPL[0].IsFlat( nRank, ptCen, vtDir, 100 * EPS_SMALL)) + return nullptr ; + if ( ! vPL[1].IsFlat( nRank, ptCen, vtDir, 100 * EPS_SMALL)) + return nullptr ; + // aggiungo il cap sull'inizio + PtrOwner pSci( CreateSurfTriMesh()) ; + if ( IsNull( pSci) || ! pSci->CreateByFlatContour( PL)) + return nullptr ; + pSci->ToGlob( frStart) ; + pSTM->DoSewing( *pSci) ; // riferimento alla fine della linea guida Frame3d frEnd ; Point3d ptEnd ; @@ -378,23 +386,18 @@ GetSurfTriMeshSwept( const ICurve* pSect, const ICurve* pGuide, bool bCapEnds, d Vector3d vtEnd ; pGuide->GetEndDir( vtEnd) ; frEnd.Set( ptEnd, -vtEnd, vtEnd ^ vtExtr) ; - // creo e setto la superficie trimesh - PtrOwner pSc( CreateSurfTriMesh()) ; - if ( IsNull( pSc) || ! pSc->CreateByFlatContour( PL)) + // aggiungo il cap sulla fine + PtrOwner pSce( CreateSurfTriMesh()) ; + if ( IsNull( pSce) || ! pSce->CreateByFlatContour( PL)) return nullptr ; - // ne inverto la normale - pSc->Invert() ; - // la porto in globale - pSc->ToGlob( frEnd) ; - // aggiungo alla superficie complessiva - pSTM->DoSewing( *pSc) ; + pSce->Invert() ; + pSce->ToGlob( frEnd) ; + pSTM->DoSewing( *pSce) ; } // se superficie risultante chiusa, verifico che la normale sia verso l'esterno double dVol ; if ( pSTM->GetVolume( dVol) && dVol < 0) pSTM->Invert() ; - // salvo tolleranza lineare usata - pSTM->SetLinearTolerance( dLinTol) ; // restituisco la superficie return Release( pSTM) ; }