Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 063b0f5cc4 |
+533
-1
@@ -16,6 +16,8 @@
|
||||
#include "DllExchange.h"
|
||||
#include "GeoTools.h"
|
||||
#include "AuxTools.h"
|
||||
#include "/EgtDev/Include/EGkGeoVector3d.h"
|
||||
#include "/EgtDev/Include/EGkCurveAux.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "/EgtDev/Include/EXeExecutor.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
@@ -24,9 +26,12 @@
|
||||
#include "/EgtDev/Include/EGkTrimming.h"
|
||||
#include "/EgtDev/Include/EGkStmFromTriangleSoup.h"
|
||||
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
||||
#include "/EgtDev/Include/EGkDistPointSurfBz.h"
|
||||
#include "/EgtDev/Include/EGkSbzFromCurves.h"
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using namespace std ;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -867,11 +872,538 @@ ExeTrimmingGetSurfBzSyncPoints( int nParentId, int nEdge1Id, int nEdge2Id, doubl
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
bool
|
||||
ExeTrimmingGetToolOrientationLines( int nParentId, int nMainEdgeId, int nOtherEdgeId, int nSyncLayerId, int nLineSId, int nLineEId,
|
||||
double dThetaStart, double dPhiStart, double dThetaEnd, double dPhiEnd, double dInterpLenS,
|
||||
double dInterpLenE, double dLinTol,
|
||||
int& nInterpStartId, int& nStartId, int& nEndId, int& nInterpEndId)
|
||||
{
|
||||
// Verifica database geometrico
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, false)
|
||||
|
||||
// Imposto i parametri di ritorno
|
||||
nInterpStartId = GDB_ID_NULL, nStartId = GDB_ID_NULL, nEndId = GDB_ID_NULL, nInterpEndId = GDB_ID_NULL ;
|
||||
|
||||
// Se necessario aggiusto le tolleranze
|
||||
double dMyLinTol = Clamp( dLinTol, EPS_SMALL, 1e5 * EPS_SMALL) ;
|
||||
const double TOL = dMyLinTol ;
|
||||
// Definisco costanti per interpolazione
|
||||
const double INTERPOLATION_DIST = 0.5 ; // alzare
|
||||
const double ISO_PAR_SAMPLE = 20.0 ;
|
||||
|
||||
// Recupero il riferimento del gruppo di destinazione
|
||||
Frame3d frDest ;
|
||||
bool bOk = ( pGeomDB->GetGlobFrame( nParentId, frDest)) ;
|
||||
|
||||
// Recupero le due Curve di bordo
|
||||
const ICurve* pCrvMainEdge = GetCurve( pGeomDB->GetGeoObj( nMainEdgeId)) ;
|
||||
const ICurve* pCrvOtherEdge = GetCurve( pGeomDB->GetGeoObj( nOtherEdgeId)) ;
|
||||
bOk = bOk && ( pCrvMainEdge != nullptr && pCrvMainEdge->IsValid() && pCrvOtherEdge != nullptr && pCrvOtherEdge->IsValid()) ;
|
||||
|
||||
// Verifico che le curve siano entrambe Aperte o entrambe Chiuse e memorizzo il risultato
|
||||
bOk = bOk && ( pCrvMainEdge->IsClosed() == pCrvOtherEdge->IsClosed()) ;
|
||||
bool bBorderClosed = ( pCrvMainEdge->IsClosed()) ;
|
||||
|
||||
// Recupero le Linee di Sincronizzazione iniziali e finali e verifico che giacciano sulle Curve di Bordo
|
||||
ICurve* pCrvSyncS = GetCurve( pGeomDB->GetGeoObj( nLineSId)) ;
|
||||
ICurve* pCrvSyncE = GetCurve( pGeomDB->GetGeoObj( nLineEId)) ;
|
||||
bOk = bOk && ( pCrvSyncS != nullptr && pCrvSyncS->IsValid() && pCrvSyncE != nullptr && pCrvSyncE->IsValid()) ;
|
||||
BIPOINT Line1, Line2 ;
|
||||
bOk = bOk && ( pCrvSyncS->GetStartPoint( Line1.first)) && ( pCrvSyncS->GetEndPoint( Line1.second)) ;
|
||||
bOk = bOk && ( pCrvSyncE->GetStartPoint( Line2.first)) && ( pCrvSyncE->GetEndPoint( Line2.second)) ;
|
||||
// --- se necessario oriento le linee di Sync in modo che inizino entrambe dal Bordo Main
|
||||
if ( bOk) {
|
||||
if ( pCrvMainEdge->IsPointOn( Line1.first, TOL))
|
||||
bOk = ( pCrvOtherEdge->IsPointOn( Line1.second, TOL)) ;
|
||||
else if ( pCrvOtherEdge->IsPointOn( Line1.first, TOL)) {
|
||||
bOk = ( pCrvMainEdge->IsPointOn( Line1.second, TOL)) ;
|
||||
if ( bOk) {
|
||||
swap( Line1.first, Line1.second) ;
|
||||
pCrvSyncS->Invert() ;
|
||||
}
|
||||
}
|
||||
else
|
||||
bOk = false ;
|
||||
}
|
||||
if ( bOk) {
|
||||
if ( pCrvMainEdge->IsPointOn( Line2.first, TOL))
|
||||
bOk = ( pCrvOtherEdge->IsPointOn( Line2.second, TOL)) ;
|
||||
else if ( pCrvOtherEdge->IsPointOn( Line2.first, TOL)) {
|
||||
bOk = ( pCrvMainEdge->IsPointOn( Line2.second, TOL)) ;
|
||||
if ( bOk) {
|
||||
swap( Line2.first, Line2.second) ;
|
||||
pCrvSyncE->Invert() ;
|
||||
}
|
||||
}
|
||||
else bOk = false ;
|
||||
}
|
||||
// Il percorso selezionato è il minore tra le due possibilità di percorrenza
|
||||
if ( bOk && bBorderClosed) {
|
||||
double dParS = 0. ;
|
||||
PtrOwner<ICurveComposite> pCompoMainCL( ConvertCurveToComposite( pCrvMainEdge->Clone())) ;
|
||||
bOk = ( ! IsNull( pCompoMainCL) && pCompoMainCL->IsValid() &&
|
||||
pCompoMainCL->GetParamAtPoint( Line1.first, dParS, TOL)) ;
|
||||
if ( bOk) {
|
||||
pCompoMainCL->ChangeStartPoint( dParS) ;
|
||||
double dLenE = 0., dLenMain = 0. ;
|
||||
bOk = ( pCompoMainCL->GetLengthAtPoint( Line2.first, dLenE, TOL) &&
|
||||
pCompoMainCL->GetLength( dLenMain)) ;
|
||||
if ( dLenE > dLenMain / 2. + EPS_SMALL) {
|
||||
swap( Line1, Line2) ;
|
||||
swap( pCrvSyncS, pCrvSyncE) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calcolo la lunghezza delle due curve di Bordo
|
||||
double dLenMain = 0., dLenOther = 0. ;
|
||||
bOk = bOk && ( pCrvMainEdge->GetLength( dLenMain) && pCrvOtherEdge->GetLength( dLenOther) &&
|
||||
dLenMain > 2. * TOL + dInterpLenS + dInterpLenE + EPS_SMALL &&
|
||||
dLenOther > 2. * TOL + dInterpLenS + dInterpLenE + EPS_SMALL) ;
|
||||
|
||||
// Recupero i punti di sincronizzazione (se presenti)
|
||||
BIPNTVECTOR vSyncPoints ; vSyncPoints.reserve( pGeomDB->GetGroupObjs( nSyncLayerId)) ;
|
||||
int nLineId = pGeomDB->GetFirstInGroup( nSyncLayerId) ;
|
||||
while ( bOk && nLineId != GDB_ID_NULL) {
|
||||
// Recupero la Curva
|
||||
const ICurve* pLine = GetCurve( pGeomDB->GetGeoObj( nLineId)) ;
|
||||
bOk = bOk && ( pLine != nullptr && pLine->IsValid()) ;
|
||||
if ( bOk) {
|
||||
// Recupero gli Estremi
|
||||
Point3d ptStart ; pLine->GetStartPoint( ptStart) ;
|
||||
Point3d ptEnd ; pLine->GetEndPoint( ptEnd) ;
|
||||
// Mi assicuro che gli estremi siano sulle curve di Bordo e orientati correttamente ( nel caso inverto)
|
||||
double dDistS1 = INFINITO ;
|
||||
if ( ! DistPointCurve( ptStart, *pCrvMainEdge).GetDist( dDistS1)) {
|
||||
nLineId = pGeomDB->GetNext( nLineId) ;
|
||||
continue ;
|
||||
}
|
||||
if ( dDistS1 < dLinTol) {
|
||||
double dDistE2 = INFINITO ;
|
||||
if ( ! DistPointCurve( ptEnd, *pCrvOtherEdge).GetDist( dDistE2) || dDistE2 > dLinTol) {
|
||||
nLineId = pGeomDB->GetNext( nLineId) ;
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
double dDistS2 = INFINITO ;
|
||||
if ( ! DistPointCurve( ptStart, *pCrvMainEdge).GetDist( dDistS2) || dDistS2 > dLinTol) {
|
||||
nLineId = pGeomDB->GetNext( nLineId) ;
|
||||
continue ;
|
||||
}
|
||||
double dDistE1 = INFINITO ;
|
||||
if ( ! DistPointCurve( ptEnd, *pCrvOtherEdge).GetDist( dDistE1) || dDistE1 > dLinTol) {
|
||||
nLineId = pGeomDB->GetNext( nLineId) ;
|
||||
continue ;
|
||||
}
|
||||
swap( ptStart, ptEnd) ;
|
||||
}
|
||||
vSyncPoints.emplace_back( make_pair( ptStart, ptEnd)) ;
|
||||
}
|
||||
nLineId = pGeomDB->GetNext( nLineId) ;
|
||||
}
|
||||
|
||||
// Recupero la superficie Bezier rigata
|
||||
PtrOwner<ISurfBezier> pSurfBzRuled ;
|
||||
if ( bOk) {
|
||||
// Se non ho linee di sincronizzazione
|
||||
if ( vSyncPoints.empty())
|
||||
pSurfBzRuled.Set( GetSurfBezierRuledSmooth( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, ISO_PAR_SAMPLE)) ;
|
||||
// Se ho linee di sincronizzazione
|
||||
else
|
||||
pSurfBzRuled.Set( GetSurfBezierRuledGuided( pCrvMainEdge, pCrvOtherEdge, vSyncPoints, dMyLinTol)) ;
|
||||
bOk = bOk && ( ! IsNull( pSurfBzRuled) && pSurfBzRuled->IsValid()) ;
|
||||
}
|
||||
|
||||
// --- Calcolo delle Linee di Orientamento ---
|
||||
if ( bOk) {
|
||||
|
||||
// Rotazione delle curve di Bordo rispetto al Bordo Main
|
||||
double dLenS ; pCrvSyncS->GetLength( dLenS) ;
|
||||
Line1.second = Line1.first + FromSpherical( dLenS, dThetaStart, dPhiStart) ;
|
||||
double dLenE ; pCrvSyncE->GetLength( dLenE) ;
|
||||
Line2.second = Line2.first + FromSpherical( dLenE, dThetaEnd, dPhiEnd) ;
|
||||
|
||||
// --- Eventuale Interpolazione Lineare di Raccordo all'Inizio ---
|
||||
if ( dInterpLenS > TOL) {
|
||||
double dExtension = dInterpLenS ;
|
||||
double dLen = -1. ; pCrvMainEdge->GetLengthAtPoint( Line1.first, dLen, TOL) ;
|
||||
if ( bBorderClosed) {
|
||||
dLen -= dInterpLenS ;
|
||||
if ( dLen < EPS_SMALL)
|
||||
dLen = dLenMain + dLen ;
|
||||
}
|
||||
else {
|
||||
if ( dLen < dInterpLenS - EPS_SMALL) {
|
||||
dExtension = dLen ;
|
||||
dLen = 0 ;
|
||||
}
|
||||
}
|
||||
double dU = - 1;
|
||||
bOk = pCrvMainEdge->GetParamAtLength( dLen, dU) ;
|
||||
if ( bOk) {
|
||||
// Definisco la linea si sincronizzazione
|
||||
Point3d ptInterpS ; double dParU, dParV ;
|
||||
PtrOwner<ICurveComposite> pCompoIso( nullptr) ;
|
||||
BIPOINT LineInterpS ;
|
||||
bOk = ( pCrvMainEdge->GetPointD1D2( dU, ICurve::FROM_MINUS, ptInterpS) &&
|
||||
DistPointSurfBz( ptInterpS, *pSurfBzRuled).GetParamsAtMinDistPoint( dParU, dParV) &&
|
||||
pCompoIso.Set( pSurfBzRuled->GetCurveOnV( dParU)) &&
|
||||
pCompoIso->IsValid() &&
|
||||
pCompoIso->GetStartPoint( LineInterpS.first) &&
|
||||
pCompoIso->GetEndPoint( LineInterpS.second)) ;
|
||||
if ( bOk) {
|
||||
bool bFirst = true ;
|
||||
// Interpolo
|
||||
double dLenLineInterpS = Dist( LineInterpS.first, LineInterpS.second) ;
|
||||
double dLenLine1 = Dist( Line1.first, Line1.second) ;
|
||||
int nStep = max( 1, int( ceil( dExtension / INTERPOLATION_DIST))) ;
|
||||
Vector3d vtInterpStart = ( LineInterpS.second - LineInterpS.first) ; vtInterpStart.Normalize() ;
|
||||
Vector3d vtInterpEnd = ( Line1.second - Line1.first) ; vtInterpEnd.Normalize() ;
|
||||
Vector3d vtDiff = vtInterpEnd - vtInterpStart ;
|
||||
for ( int i = 0 ; bOk && i < ( nStep - 1) ; ++ i) { // ( nStep - 1) per evitare sovrapposizione con la Copia del vettore
|
||||
double dI = double( i) ;
|
||||
Vector3d vtInterp = vtInterpStart + ( dI / ( nStep - 1)) * vtDiff ;
|
||||
double dUInterpMain = 0. ; Point3d ptInterpOnMain ;
|
||||
double dCurrLen = dLen + ( dI * dExtension / ( nStep - 1)) ;
|
||||
if ( dCurrLen > dLenMain)
|
||||
dCurrLen -= dLenMain ;
|
||||
bOk = ( pCrvMainEdge->GetParamAtLength( dCurrLen, dUInterpMain) &&
|
||||
pCrvMainEdge->GetPointD1D2( dUInterpMain, ICurve::FROM_MINUS, ptInterpOnMain)) ;
|
||||
if ( bOk) {
|
||||
double dMagnitude = dLenLineInterpS + ( dI / ( nStep - 1)) * ( dLenLine1 - dLenLineInterpS) ;
|
||||
PtrOwner<ICurveLine> pLine( CreateCurveLine()) ;
|
||||
bOk = ( ! IsNull( pLine) && pLine->Set( ptInterpOnMain, ptInterpOnMain + vtInterp * dMagnitude)) ;
|
||||
if ( bOk) {
|
||||
int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) ;
|
||||
bOk = ( nNewId != GDB_ID_NULL) ;
|
||||
if ( bOk) {
|
||||
if ( bFirst) {
|
||||
nInterpStartId = nNewId ;
|
||||
bFirst = false ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Interpolazione tra le due Linee di Sincronizzazione ---
|
||||
if ( bOk) {
|
||||
double dLenS = -1., dLenE = -1 ;
|
||||
bOk = ( pCrvMainEdge->GetLengthAtPoint( Line1.first, dLenS, TOL) &&
|
||||
pCrvMainEdge->GetLengthAtPoint( Line2.first, dLenE, TOL)) ;
|
||||
if ( bOk) {
|
||||
double dToTDist = 0. ;
|
||||
if ( dLenS < dLenE)
|
||||
dToTDist = dLenE - dLenS ;
|
||||
else
|
||||
dToTDist = ( dLenMain - dLenS) + dLenE ;
|
||||
if ( dToTDist > TOL) {
|
||||
bool bFirst = true ;
|
||||
// Interpolo
|
||||
double dLenLine1 = Dist( Line1.first, Line1.second) ;
|
||||
double dLenLine2 = Dist( Line2.first, Line2.second) ;
|
||||
int nStep = max( 1, int( ceil( dToTDist / INTERPOLATION_DIST))) ;
|
||||
Vector3d vtLineS = ( Line1.second - Line1.first) ; vtLineS.Normalize() ;
|
||||
Vector3d vtLineE = ( Line2.second - Line2.first) ; vtLineE.Normalize() ;
|
||||
Vector3d vtDiff = ( vtLineE - vtLineS) ;
|
||||
for ( int i = 0 ; bOk && i <= nStep ; ++ i) {
|
||||
double dI = double( i) ;
|
||||
Vector3d vtInterp = vtLineS + ( dI / nStep) * vtDiff ;
|
||||
double dUInterpMain = 0. ; Point3d ptInterpOnMain ;
|
||||
double dCurrLen = dLenS + ( dI * dToTDist / nStep) ;
|
||||
if ( dCurrLen > dLenMain)
|
||||
dCurrLen -= dLenMain ;
|
||||
bOk = ( pCrvMainEdge->GetParamAtLength( dCurrLen, dUInterpMain) &&
|
||||
pCrvMainEdge->GetPointD1D2( dUInterpMain, ICurve::FROM_MINUS, ptInterpOnMain)) ;
|
||||
if ( bOk) {
|
||||
double dMagnitude = dLenLine1 + ( dI / nStep) * ( dLenLine2 - dLenLine1) ;
|
||||
PtrOwner<ICurveLine> pLine( CreateCurveLine()) ;
|
||||
bOk = ( ! IsNull( pLine) && pLine->Set( ptInterpOnMain, ptInterpOnMain + vtInterp * dMagnitude)) ;
|
||||
if ( bOk) {
|
||||
int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) ;
|
||||
bOk = ( nNewId != GDB_ID_NULL) ;
|
||||
if ( bOk) {
|
||||
if ( bFirst) {
|
||||
nStartId = nNewId ;
|
||||
bFirst = false ;
|
||||
}
|
||||
nEndId = nNewId ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Eventuale Interpolazione Lineare di Raccordo alla Fine ---
|
||||
if ( bOk && dInterpLenE > TOL) {
|
||||
double dExtension = dInterpLenE ;
|
||||
double dLen = -1. ; pCrvMainEdge->GetLengthAtPoint( Line2.first, dLen, TOL) ;
|
||||
if ( bBorderClosed) {
|
||||
dLen += dInterpLenE ;
|
||||
if ( dLen > dLenMain - EPS_SMALL)
|
||||
dLen -= dLenMain ;
|
||||
}
|
||||
else {
|
||||
if ( dLen > dLenMain - dInterpLenE - EPS_SMALL) {
|
||||
dExtension = dLenMain - dLen ;
|
||||
dLen = dLenMain ;
|
||||
}
|
||||
}
|
||||
double dU = - 1 ;
|
||||
bOk = pCrvMainEdge->GetParamAtLength( dLen, dU) ;
|
||||
if ( bOk) {
|
||||
// Definisco la linea si sincronizzazione
|
||||
Point3d ptInterpE ; double dParU, dParV ;
|
||||
PtrOwner<ICurveComposite> pCompoIso( nullptr) ;
|
||||
BIPOINT LineInterpE ;
|
||||
bOk = ( pCrvMainEdge->GetPointD1D2( dU, ICurve::FROM_MINUS, ptInterpE) &&
|
||||
DistPointSurfBz( ptInterpE, *pSurfBzRuled).GetParamsAtMinDistPoint( dParU, dParV) &&
|
||||
pCompoIso.Set( pSurfBzRuled->GetCurveOnV( dParU)) &&
|
||||
pCompoIso->IsValid() &&
|
||||
pCompoIso->GetStartPoint( LineInterpE.first) &&
|
||||
pCompoIso->GetEndPoint( LineInterpE.second)) ;
|
||||
if ( bOk) {
|
||||
// Interpolo
|
||||
double dLenLineInterpE = Dist( LineInterpE.first, LineInterpE.second) ;
|
||||
double dLenLine2 = Dist( Line2.first, Line2.second) ;
|
||||
int nStep = max( 1, int( ceil( dExtension / INTERPOLATION_DIST))) ;
|
||||
Vector3d vtInterpStart = ( Line2.second - Line2.first) ; vtInterpStart.Normalize() ;
|
||||
Vector3d vtInterpEnd = ( LineInterpE.second - LineInterpE.first) ; vtInterpEnd.Normalize() ;
|
||||
Vector3d vtDiff = vtInterpEnd - vtInterpStart ;
|
||||
for ( int i = 1 ; bOk && i < nStep ; ++ i) { // i = 1 per evitare la sopvrapposizione con la Copia del vettore
|
||||
double dI = double( i) ;
|
||||
Vector3d vtInterp = vtInterpStart + ( dI / ( nStep - 1)) * vtDiff ;
|
||||
double dUInterpMain = 0. ; Point3d ptInterpOnMain ;
|
||||
double dCurrLen = ( dLen - dExtension) + ( dI * dExtension / ( nStep - 1)) ;
|
||||
if ( dCurrLen > dLenMain)
|
||||
dCurrLen -= dLenMain ;
|
||||
bOk = ( pCrvMainEdge->GetParamAtLength( dCurrLen, dUInterpMain) &&
|
||||
pCrvMainEdge->GetPointD1D2( dUInterpMain, ICurve::FROM_MINUS, ptInterpOnMain)) ;
|
||||
if ( bOk) {
|
||||
double dMagnitude = dLenLine2 + ( dI / ( nStep - 1)) * ( dLenLineInterpE - dLenLine2) ;
|
||||
PtrOwner<ICurveLine> pLine( CreateCurveLine()) ;
|
||||
bOk = ( ! IsNull( pLine) && pLine->Set( ptInterpOnMain, ptInterpOnMain + vtInterp * dMagnitude)) ;
|
||||
if ( bOk) {
|
||||
int nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pLine)) ;
|
||||
bOk = ( nNewId != GDB_ID_NULL) ;
|
||||
if ( bOk)
|
||||
nInterpEndId = nNewId ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExeSetModified() ;
|
||||
// Se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtTrimmingGetToolOrientationLines(" + ToString( nParentId) + "," +
|
||||
ToString( nMainEdgeId) + "," +
|
||||
ToString( nOtherEdgeId) + "," +
|
||||
ToString( nLineSId) + "," +
|
||||
ToString( nLineEId) + "," +
|
||||
ToString( dThetaStart) + "," +
|
||||
ToString( dPhiStart) + "," +
|
||||
ToString( dThetaEnd) + "," +
|
||||
ToString( dPhiEnd) + "," +
|
||||
ToString( dLinTol) + "," +
|
||||
ToString( dInterpLenS) + "," +
|
||||
ToString( dInterpLenE) + "," +
|
||||
" -- bOk=" + ToString( bOk) +
|
||||
" -- nInterpStartId=" + ToString( nInterpStartId) + ", nStartId=" + ToString( nStartId) +
|
||||
", nEndId=" + ToString( nEndId) + ", nInterpEndId=" + ToString( nInterpEndId) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
struct TrimmingInterval {
|
||||
double dLenStart ;
|
||||
double dLenEnd ;
|
||||
Vector3d vtStart ;
|
||||
Vector3d vtEnd ;
|
||||
TrimmingInterval()
|
||||
: dLenStart( - EPS_SMALL), dLenEnd( - EPS_SMALL), vtStart( V_INVALID), vtEnd( V_INVALID) {} ;
|
||||
TrimmingInterval( double dLenS, double dLenE, const Vector3d& vtS, const Vector3d& vtE)
|
||||
: dLenStart( dLenS), dLenEnd( dLenE), vtStart( vtS), vtEnd( vtE) {} ;
|
||||
} ;
|
||||
typedef vector<TrimmingInterval> TRIMMINGINTERVALVECTOR ;
|
||||
// ---------------------------------------------------------------------------
|
||||
bool
|
||||
GetTrimmingInterval( const IGeomDB* pGeomDB, const ICurveComposite* pCompo, const Frame3d& frCompo, int nIdS, int nIdE, TrimmingInterval& TrimmingInt)
|
||||
{
|
||||
// Verifico validità dei parametri
|
||||
VERIFY_GEOMDB( pGeomDB, false)
|
||||
if ( pCompo == nullptr || ! pCompo->IsValid() || ! frCompo.IsValid())
|
||||
return false ;
|
||||
|
||||
// Recupero le linee di Orienting
|
||||
const ICurve* pGeoCrvS = GetCurve( pGeomDB->GetGeoObj( nIdS)) ;
|
||||
const ICurve* pGeoCrvE = GetCurve( pGeomDB->GetGeoObj( nIdE)) ;
|
||||
if ( pGeoCrvS != nullptr && pGeoCrvE != nullptr && pGeoCrvS->IsValid() && pGeoCrvE->IsValid()) {
|
||||
// Recupero i punti base e i vettori direzioni ( sono ICurveLine*, ma le tratto come ICurve* generiche)
|
||||
Point3d ptS = P_INVALID ; pGeoCrvS->GetStartPoint( ptS) ; // Line1.ptStart
|
||||
Point3d ptE = P_INVALID ; pGeoCrvE->GetStartPoint( ptE) ; // Line2.ptStart
|
||||
Vector3d vtS = V_INVALID ; pGeoCrvS->GetStartDir( vtS) ; // Line1.vtStart
|
||||
Vector3d vtE = V_INVALID ; pGeoCrvE->GetStartDir( vtE) ; // Line2.vtStart
|
||||
if ( ptS.IsValid() && ptE.IsValid() && vtS.IsValid() && vtE.IsValid()) {
|
||||
// Recupero il Frame delle Linee
|
||||
Frame3d frCrv1, frCrv2 ;
|
||||
if ( ! pGeomDB->GetGlobFrame( nIdS, frCrv1) || ! pGeomDB->GetGlobFrame( nIdE, frCrv2))
|
||||
return false ;
|
||||
// Porto Tali valori nel riferimento dalla Composita
|
||||
Point3d ptSLoc = GetLocToLoc( ptS, frCrv1, frCompo) ;
|
||||
Point3d ptELoc = GetLocToLoc( ptE, frCrv2, frCompo) ;
|
||||
Vector3d vtSLoc = GetLocToLoc( vtS, frCrv1, frCompo) ;
|
||||
Vector3d vtELoc = GetLocToLoc( vtE, frCrv2, frCompo) ;
|
||||
// Recupero il parametro sulla curva
|
||||
double dParS = - EPS_PARAM, dParE = - EPS_PARAM ;
|
||||
int nFlag = 0 ;
|
||||
if ( DistPointCurve( ptSLoc, *pCompo).GetParamAtMinDistPoint( EPS_SMALL, dParS, nFlag) &&
|
||||
DistPointCurve( ptELoc, *pCompo).GetParamAtMinDistPoint( EPS_SMALL, dParE, nFlag)) {
|
||||
// Recupero la lunghezza su tale curva
|
||||
double dLenS = - EPS_SMALL, dLenE = - EPS_SMALL ;
|
||||
if ( pCompo->GetLengthAtParam( dParS, dLenS) && pCompo->GetLengthAtParam( dParE, dLenE)) {
|
||||
TrimmingInt = TrimmingInterval( dLenS, dLenE, vtSLoc, vtELoc) ;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
bool
|
||||
Exe5AxTrimmingModifyToolDir( int nCrvId, int nPathId, int nTrimLayId, const INTVECTOR& vnOrientingId, const INTVECTOR& vnOrientingISId,
|
||||
const INTVECTOR& vnOrientingSId, const INTVECTOR& vnOrientingEId, const INTVECTOR& vnOrientingIEId)
|
||||
{
|
||||
// Verifica database geometrico
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, false)
|
||||
|
||||
// Verifico validità dei parametri
|
||||
bool bOk = ( nCrvId != GDB_ID_NULL && nPathId != GDB_ID_NULL && nTrimLayId != GDB_ID_NULL &&
|
||||
ssize( vnOrientingId) == ssize( vnOrientingISId) && ssize( vnOrientingISId) == ssize( vnOrientingSId) &&
|
||||
ssize( vnOrientingSId) == ssize( vnOrientingEId) && ssize( vnOrientingEId) == ssize( vnOrientingIEId)) ;
|
||||
|
||||
// Recupero la curva di Bordo e la sua composit associata
|
||||
const ICurve* pCrvBorder = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
|
||||
bOk = bOk && ( pCrvBorder != nullptr && pCrvBorder->IsValid()) ;
|
||||
PtrOwner<ICurveComposite> pCompoBorder( nullptr) ;
|
||||
if ( bOk)
|
||||
bOk = ( pCompoBorder.Set( ConvertCurveToComposite( pCrvBorder->Clone())) && pCompoBorder->IsValid()) ;
|
||||
double dLen = - EPS_SMALL ;
|
||||
if ( bOk)
|
||||
bOk = pCompoBorder->GetLength( dLen) ;
|
||||
|
||||
// Recupero il Frame della curva corrente
|
||||
Frame3d frCompo ;
|
||||
bOk = bOk && ( pGeomDB->GetGlobFrame( nCrvId, frCompo)) ;
|
||||
|
||||
// Recupero i versori di interpolazione e creo dei gruppi
|
||||
TRIMMINGINTERVALVECTOR vInterval ; vInterval.reserve( 3 * ssize( vnOrientingId)) ;
|
||||
for ( int i = 0 ; bOk && i < ssize( vnOrientingId) ; ++ i) {
|
||||
// Se presente Interpolazione iniziale
|
||||
if ( vnOrientingISId[i] != GDB_ID_NULL && vnOrientingSId[i] != GDB_ID_NULL) {
|
||||
TrimmingInterval myTrimInt ;
|
||||
if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingISId[i], vnOrientingSId[i], myTrimInt))
|
||||
vInterval.emplace_back( myTrimInt) ;
|
||||
}
|
||||
// Interpolazione ( deve essere sempre presente, ma per scrupolo si controlla lo stesso)
|
||||
if ( vnOrientingSId[i] != GDB_ID_NULL && vnOrientingEId[i] != GDB_ID_NULL) {
|
||||
TrimmingInterval myTrimInt ;
|
||||
if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingSId[i], vnOrientingEId[i], myTrimInt))
|
||||
vInterval.emplace_back( myTrimInt) ;
|
||||
}
|
||||
// Se presente Interpolazione finale
|
||||
if ( vnOrientingEId[i] != GDB_ID_NULL && vnOrientingIEId[i] != GDB_ID_NULL) {
|
||||
TrimmingInterval myTrimInt ;
|
||||
if ( GetTrimmingInterval( pGeomDB, pCompoBorder, frCompo, vnOrientingEId[i], vnOrientingIEId[i], myTrimInt))
|
||||
vInterval.emplace_back( myTrimInt) ;
|
||||
}
|
||||
}
|
||||
|
||||
// Se ho degli intervalli di Interpolazione
|
||||
if ( ! vInterval.empty()) {
|
||||
// Scorro i vettori presenti nel Layer ausiliario della lavorazione
|
||||
int nId = pGeomDB->GetFirstInGroup( nPathId) ;
|
||||
while ( bOk && nId != GDB_ID_NULL) {
|
||||
IGeoVector3d* vGeo = GetGeoVector3d( pGeomDB->GetGeoObj( nId)) ;
|
||||
if ( vGeo != nullptr && vGeo->IsValid()) {
|
||||
// Recupero i parametri di tale vettore
|
||||
Point3d ptBase = vGeo->GetBase() ;
|
||||
Vector3d vtDirV = V_INVALID ; ;
|
||||
if ( pGeomDB->GetInfo( nId, "DirV", vtDirV) && vtDirV.IsValid()) {
|
||||
// Recupero la lunghezza associata al Punto di Base sulla Compo
|
||||
double dCurrPar = - EPS_SMALL ;
|
||||
int nFlag = 0 ;
|
||||
if ( DistPointCurve( ptBase, *pCompoBorder).GetParamAtMinDistPoint( 0., dCurrPar, nFlag)) {
|
||||
double dCurrLen = - EPS_SMALL ;
|
||||
if ( pCompoBorder->GetLengthAtParam( dCurrPar, dCurrLen)) {
|
||||
for ( const TrimmingInterval& CurrInterval : vInterval) {
|
||||
// Controlli per Intervalli a cavallo dei punti iniziali e finali della curva
|
||||
double dLenA = CurrInterval.dLenStart ;
|
||||
double dLenB = CurrInterval.dLenEnd ;
|
||||
double dLenC = dCurrLen ;
|
||||
if ( dLenA > dLenB) {
|
||||
dLenB += dLen ;
|
||||
if ( dLenC < CurrInterval.dLenStart - EPS_SMALL)
|
||||
dLenC += dLen ;
|
||||
}
|
||||
// Se l'intervallo non è troppo piccolo e se sono all'interno di tale Intervallo
|
||||
if ( dLenB - dLenA > 10. * EPS_SMALL && /* bastava anche 2 * EPS_SMALL */
|
||||
dLenA + EPS_SMALL < dLenC && dLenC < dLenB + EPS_SMALL /* estremi esclusi, va bene ? */) {
|
||||
// Media pesata dei due vettori
|
||||
double dMeanPar = ( dLenC - dLenA) / ( dLenB - dLenA) ;
|
||||
Vector3d vtMean = Media( CurrInterval.vtStart, CurrInterval.vtEnd, dMeanPar) ;
|
||||
// Assegno la Info a tale vettore
|
||||
pGeomDB->SetInfo( nId, "DirV", vtMean) ;
|
||||
break ; // non controllo altri intervalli
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nId = pGeomDB->GetNext( nId) ;
|
||||
}
|
||||
}
|
||||
|
||||
ExeSetModified() ;
|
||||
// Se richiesto, salvo il comando Lua equivalente
|
||||
if ( IsCmdLog()) {
|
||||
string sLua = "EgtTrimmingGetToolOrientationLines(" + ToString( nCrvId) + "," +
|
||||
ToString( nPathId) + "," +
|
||||
ToString( nTrimLayId) + "," +
|
||||
ToString( vnOrientingId) + "," +
|
||||
ToString( vnOrientingISId) + "," +
|
||||
ToString( vnOrientingSId) + "," +
|
||||
ToString( vnOrientingEId) + "," +
|
||||
ToString( vnOrientingIEId) + "," +
|
||||
" -- bOk=" + ToString( bOk) ;
|
||||
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
|
||||
}
|
||||
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
int
|
||||
ExeRegolarizeSurfaceLocally( int nParentId, int nSurfId, int nSyncStartId, int nSyncEndId, double dLinTol, int nType)
|
||||
{
|
||||
bool bOk = true ;
|
||||
// Verifica database geometrico
|
||||
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
||||
VERIFY_GEOMDB( pGeomDB, false)
|
||||
|
||||
@@ -283,6 +283,80 @@ LuaTrimmingGetSurfBzSyncPoints( lua_State* L)
|
||||
return 3 ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
static int
|
||||
LuaTrimmingGetToolOrientationLines( lua_State* L)
|
||||
{
|
||||
// 13 parametri : nParentId, nMainEdgeId, nOtherEdgeId, nSyncLayerId, nLineSId, nLineEId,
|
||||
// dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol
|
||||
int nParentId ;
|
||||
LuaCheckParam( L, 1, nParentId)
|
||||
int nMainEdgeId ;
|
||||
LuaCheckParam( L, 2, nMainEdgeId)
|
||||
int nOtherEdgeId ;
|
||||
LuaCheckParam( L, 3, nOtherEdgeId)
|
||||
int nLineSId ;
|
||||
LuaCheckParam( L, 4, nLineSId)
|
||||
int nLineEId ;
|
||||
LuaCheckParam( L, 5, nLineEId)
|
||||
int nSyncLayerId ;
|
||||
LuaCheckParam( L, 6, nSyncLayerId)
|
||||
double dThetaStart ;
|
||||
LuaCheckParam( L, 7, dThetaStart)
|
||||
double dPhiStart ;
|
||||
LuaCheckParam( L, 8, dPhiStart)
|
||||
double dThetaEnd ;
|
||||
LuaCheckParam( L, 9, dThetaEnd)
|
||||
double dPhiEnd ;
|
||||
LuaCheckParam( L, 10, dPhiEnd) ;
|
||||
double dInterpLenS ;
|
||||
LuaCheckParam( L, 11, dInterpLenS)
|
||||
double dInterpLenE ;
|
||||
LuaCheckParam( L, 12, dInterpLenE)
|
||||
double dLinTol ;
|
||||
LuaCheckParam( L, 13, dLinTol)
|
||||
LuaClearStack( L) ;
|
||||
// Inserisco i tratti lineari associati calcolati lungo il percorso
|
||||
int nInterpStartId = GDB_ID_NULL, nStartId = GDB_ID_NULL, nEndId = GDB_ID_NULL, nInterpEndId = GDB_ID_NULL ;
|
||||
bool bOk = ExeTrimmingGetToolOrientationLines( nParentId, nMainEdgeId, nOtherEdgeId, nSyncLayerId, nLineSId, nLineEId,
|
||||
dThetaStart, dPhiStart, dThetaEnd, dPhiEnd, dInterpLenS, dInterpLenE, dLinTol,
|
||||
nInterpStartId, nStartId, nEndId, nInterpEndId) ;
|
||||
LuaSetParam( L, bOk) ;
|
||||
LuaSetParam( L, nInterpStartId) ;
|
||||
LuaSetParam( L, nStartId) ;
|
||||
LuaSetParam( L, nEndId) ;
|
||||
LuaSetParam( L, nInterpEndId) ;
|
||||
return 5 ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
static int
|
||||
Lua5AxTrimmingModifyToolDir( lua_State* L)
|
||||
{
|
||||
// 8 parametri : nCrvId, nAuxId, nTrimLayId, vnOrientingId, vnOrientingISId, vnOrientingSId, vnOrientingEId, vnOrientingIEId
|
||||
int nCrvId ;
|
||||
LuaCheckParam( L, 1, nCrvId)
|
||||
int nPathId ;
|
||||
LuaCheckParam( L, 2, nPathId)
|
||||
int nTrimLayId ;
|
||||
LuaCheckParam( L, 3, nTrimLayId)
|
||||
INTVECTOR vnOrientingId ;
|
||||
LuaCheckParam( L, 4, vnOrientingId)
|
||||
INTVECTOR vnOrientingISId ;
|
||||
LuaCheckParam( L, 5, vnOrientingISId)
|
||||
INTVECTOR vnOrientingSId ;
|
||||
LuaCheckParam( L, 6, vnOrientingSId)
|
||||
INTVECTOR vnOrientingEId ;
|
||||
LuaCheckParam( L, 7, vnOrientingEId)
|
||||
INTVECTOR vnOrientingIEId ;
|
||||
LuaCheckParam( L, 8, vnOrientingIEId) ;
|
||||
LuaClearStack( L) ;
|
||||
// Modifico le Direzioni utensile
|
||||
bool bOk = Exe5AxTrimmingModifyToolDir( nCrvId, nPathId, nTrimLayId, vnOrientingId, vnOrientingISId, vnOrientingSId, vnOrientingEId, vnOrientingIEId) ;
|
||||
LuaSetParam( L, bOk) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
static int
|
||||
LuaRegolarizeSurfaceLocally( lua_State* L)
|
||||
@@ -324,6 +398,9 @@ LuaInstallTrimming( LuaMgr& luaMgr)
|
||||
// --- Recupero linee di sincronizzazione
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingInterpolateSyncLines", LuaTrimmingInterpolateSyncLines) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingGetSurfBzSyncPoints", LuaTrimmingGetSurfBzSyncPoints) ;
|
||||
// --- Recupero linee di Orientamento dell'Utensile e Modifica della lavorazione 5Ax
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingGetToolOrientationLines", LuaTrimmingGetToolOrientationLines) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "Egt5AxTrimmingModifyToolDir", Lua5AxTrimmingModifyToolDir) ;
|
||||
// --- Modifica della superficie
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtRegolarizeSurfaceLocally", LuaRegolarizeSurfaceLocally) ;
|
||||
return bOk ;
|
||||
|
||||
Reference in New Issue
Block a user