EgtMachKernel :
- correzioni alla costruzione del percorso di lavorazione per lavorazioni a 5 assi.
This commit is contained in:
+65
-16
@@ -33,6 +33,9 @@
|
||||
|
||||
using namespace std ;
|
||||
|
||||
#define COLOR5AX 0
|
||||
#define DRAWCYL 0
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
Machine::LuaEmtAddRapidStart( lua_State* L)
|
||||
@@ -616,13 +619,13 @@ typedef vector<Cyl> OFFSETCYLVECT ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
IsPointInsideCylinder( const Point3d& ptTest, const Cyl& offCyl)
|
||||
IsPointInsideCylinder( const Point3d& ptTest, const Cyl& offCyl, double dLinTol)
|
||||
{
|
||||
Point3d ptTestLoc = ptTest ; ptTestLoc.ToLoc( offCyl.frCyl) ;
|
||||
if ( ptTestLoc.z > offCyl.dH || ptTestLoc.z < 0)
|
||||
return false ;
|
||||
double dDist = ptTestLoc.x * ptTestLoc.x + ptTestLoc.y * ptTestLoc.y ;
|
||||
double dRadSq = offCyl.dRad * offCyl.dRad ;
|
||||
double dRadSq = ( offCyl.dRad - dLinTol) * ( offCyl.dRad - dLinTol) ;
|
||||
if ( dDist > dRadSq)
|
||||
return false ;
|
||||
return true ;
|
||||
@@ -645,7 +648,12 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L)
|
||||
int nId = pGeomDB->GetFirstInGroup( nPathId) ;
|
||||
int nIdCrvAux = pGeomDB->GetFirstInGroup( nAuxPathId) ;
|
||||
const ICurve* pCrvAux = GetCurve( pGeomDB->GetGeoObj(nIdCrvAux)) ;
|
||||
const double dLinTol = 5 * EPS_SMALL ;
|
||||
const double dLinTol = 10 * EPS_SMALL ;
|
||||
|
||||
#if DRAWCYL
|
||||
int nParent = pGeomDB->GetParentId( nPathId) ;
|
||||
int nTempLay = pGeomDB->AddGroup( GDB_ID_NULL, nParent, GLOB_FRM) ;
|
||||
#endif
|
||||
|
||||
while ( nId != GDB_ID_NULL) {
|
||||
if ( pGeomDB->GetGeoType( nId) == CRV_LINE) {
|
||||
@@ -666,7 +674,9 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L)
|
||||
OFFSETCYLVECT vCyl ;
|
||||
// creo un cilindro della dimensione del raggio
|
||||
for ( int i = 0 ; i < ssize( vLines) ; ++i) {
|
||||
|
||||
#if COLOR5AX
|
||||
pGeomDB->SetMaterial( vLines[i].first, GREEN) ;
|
||||
#endif
|
||||
const IGeoVector3d* pGV = GetGeoVector3d( pGeomDB->GetGeoObj( vLines[i].second)) ;
|
||||
if ( pGV == nullptr)
|
||||
return false ;
|
||||
@@ -686,13 +696,22 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L)
|
||||
// questa altezza dovrebbe coincidere con quella precedentemente calcolata come direzione della linea
|
||||
vtHeight.Normalize() ;
|
||||
vCyl.emplace_back( ptStart, vtHeight, dHeight, dRad, dLinTol) ;
|
||||
#if DRAWCYL
|
||||
pGeomDB->SetGridFrame( vCyl.back().frCyl) ;
|
||||
int nIdCrv = ExeCreateCircle( nTempLay, ORIG, dRad, GDB_ID_GRID) ;
|
||||
ExeCreateSurfTmByExtrusion( nTempLay, {nIdCrv}, Z_AX * dHeight, 0.005, GDB_ID_GRID) ;
|
||||
pGeomDB->Erase( nIdCrv) ;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if DRAWCYL
|
||||
pGeomDB->SetGridFrame( GLOB_FRM) ;
|
||||
#endif
|
||||
|
||||
// controllo l'end di ogni linea per verificare se sta nel cilindro definito da uno degli altri tratti
|
||||
// controllo tutto i punti
|
||||
bool bErasedSomePart = false ;
|
||||
bool bErasedPrev = false ;
|
||||
bool bCheckStart = false ;
|
||||
INTINTVECTOR vInters ;
|
||||
for ( int i = 0 ; i < ssize( vLines) ; ++i) {
|
||||
Point3d ptStart, ptEnd ;
|
||||
@@ -702,23 +721,37 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L)
|
||||
pCL->GetEndPoint( ptEnd) ;
|
||||
pCL->GetStartPoint( ptStart) ;
|
||||
// se stanno in uno dei cilindri degli altri tratti della zona concava
|
||||
for ( int j = 0 ; j < ssize( vLines) ; ++j) {
|
||||
bool bToErase = false ;
|
||||
for ( int j = 0 ; j < ssize( vCyl) ; ++j) {
|
||||
if ( i == j)
|
||||
continue ;
|
||||
bool bToErase = IsPointInsideCylinder( ptEnd, vCyl[j]) ;
|
||||
if ( bErasedPrev && ! bToErase)
|
||||
bToErase = bToErase || IsPointInsideCylinder( ptStart, vCyl[j]) ;
|
||||
bToErase = IsPointInsideCylinder( ptEnd, vCyl[j], dLinTol) ;
|
||||
bool bStartInsideCyl = false ;
|
||||
if ( bCheckStart && ! bToErase) {
|
||||
bStartInsideCyl = IsPointInsideCylinder( ptStart, vCyl[j], dLinTol) ;
|
||||
bToErase = bToErase || bStartInsideCyl ;
|
||||
}
|
||||
if ( bToErase) {
|
||||
bErasedSomePart = true ;
|
||||
bErasedPrev = true ;
|
||||
vInters.emplace_back(vLines[i].first,i) ;
|
||||
vInters.emplace_back(vLines[i+1].first,i+1) ;
|
||||
++i ;
|
||||
if ( ! bStartInsideCyl)
|
||||
bCheckStart = true ;
|
||||
// se avevo un'interruzione nella zona da modificare, la colmo
|
||||
if ( ! vInters.empty() && vInters.back().first != vLines[i-1].first) {
|
||||
// aggiungo tutti i precedenti che mancano
|
||||
int nLastAdded = i - ( vLines[i].first - vInters.back().first) ;
|
||||
for ( int h = nLastAdded + 1 ; h < i ; ++h)
|
||||
vInters.emplace_back( vLines[h].first, h) ;
|
||||
}
|
||||
vInters.emplace_back( vLines[i].first,i) ;
|
||||
if ( ! bStartInsideCyl) {
|
||||
vInters.emplace_back( vLines[i+1].first,i+1) ;
|
||||
++i ;
|
||||
}
|
||||
break ;
|
||||
}
|
||||
else
|
||||
bErasedPrev = false ;
|
||||
}
|
||||
}
|
||||
if ( ! bToErase)
|
||||
bCheckStart = false ;
|
||||
}
|
||||
if ( bErasedSomePart) {
|
||||
// calcolo le intersezioni effettive del primo e ultimo tratto cancellati con i cilindri che li hanno cancellati
|
||||
@@ -728,11 +761,15 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L)
|
||||
return false ;
|
||||
}
|
||||
for ( int i = 0 ; i < ssize( vInters) ; ++i) {
|
||||
#if COLOR5AX
|
||||
pGeomDB->SetMaterial( vInters[i].first, YELLOW) ;
|
||||
#endif
|
||||
// cancello i tratti intermedi
|
||||
if ( i > 0 && i < ssize( vInters) - 1) {
|
||||
pGeomDB->Erase( vInters[i].first) ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
// per il primo e ultimo controllo le intersezioni con tutti i cilindri
|
||||
ICurveLine* pCL = GetCurveLine( pGeomDB->GetGeoObj( vInters[i].first)) ;
|
||||
Point3d ptStart = pCL->GetStart() ;
|
||||
@@ -765,12 +802,18 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L)
|
||||
}
|
||||
if ( ptTrim.IsValid()) {
|
||||
if ( i == 0) {
|
||||
#if COLOR5AX
|
||||
pGeomDB->SetMaterial( vInters[i].first, RED) ;
|
||||
#endif
|
||||
pCL->ModifyEnd( ptTrim) ;
|
||||
double dNewLen ; pCL->GetLength( dNewLen) ;
|
||||
if ( dNewLen < 0.1) {
|
||||
int nPrev = pGeomDB->GetPrev( vInters[0].first) ;
|
||||
pGeomDB->Erase( vInters[0].first) ;
|
||||
vInters[0].first = nPrev ;
|
||||
#if COLOR5AX
|
||||
pGeomDB->SetMaterial( nPrev, RED) ;
|
||||
#endif
|
||||
ICurveLine* pCLPrev = GetCurveLine( pGeomDB->GetGeoObj( nPrev)) ;
|
||||
pCLPrev->ModifyEnd( ptTrim) ;
|
||||
}
|
||||
@@ -778,12 +821,18 @@ Machine::LuaEmtAdjustConcavePartsInPath( lua_State* L)
|
||||
camData->SetEndPoint( ptTrim) ;
|
||||
}
|
||||
else {
|
||||
#if COLOR5AX
|
||||
pGeomDB->SetMaterial( vInters[i].first, RED) ;
|
||||
#endif
|
||||
pCL->ModifyStart( ptTrim) ;
|
||||
double dNewLen ; pCL->GetLength( dNewLen) ;
|
||||
if ( dNewLen < 0.1) {
|
||||
int nNext = pGeomDB->GetNext( vInters[i].first) ;
|
||||
pGeomDB->Erase( vInters[i].first) ;
|
||||
vInters[i].first = nNext ;
|
||||
#if COLOR5AX
|
||||
pGeomDB->SetMaterial( nNext, RED) ;
|
||||
#endif
|
||||
ICurveLine* pCLNext = GetCurveLine( pGeomDB->GetGeoObj( nNext)) ;
|
||||
pCLNext->ModifyStart( ptTrim) ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user