diff --git a/EXE_Const.h b/EXE_Const.h index 6e26fdb..115a6a0 100644 --- a/EXE_Const.h +++ b/EXE_Const.h @@ -28,6 +28,7 @@ const std::string CRV_ORIG = "ORIG" ; // Per FlatParts (Nesting) const std::string NST_PARTREG_LAYER = "Region" ; +const std::string NST_PARTUPREG_LAYER = "UpReg" ; const std::string NST_PARTDOWNREG_LAYER = "DwnReg" ; const std::string NST_EXT_LAYER = "OutLoop" ; const std::string NST_EXT_ORIG_LAYER = "OutLoop.orig" ; @@ -35,6 +36,10 @@ const std::string NST_IN_LAYER = "InLoop" ; const std::string NST_ON_LAYER = "OnPath" ; const std::string NST_KEY_SIDEANG = "SideAng" ; const std::string NST_KEY_OFFSET = "Offset" ; +const std::string NST_KEY_DEPTH = "Depth" ; +const std::string NST_KEY_SIDEANG2 = "SideAng2" ; +const std::string NST_KEY_OFFSET2 = "Offset2" ; +const std::string NST_KEY_DEPTH2 = "Depth2" ; // Per Sheets (Nesting) const std::string NST_SHEET_OUTREG = "SheetOut" ; diff --git a/EXE_GdbModifyVol.cpp b/EXE_GdbModifyVol.cpp index 963aead..a61e396 100644 --- a/EXE_GdbModifyVol.cpp +++ b/EXE_GdbModifyVol.cpp @@ -476,7 +476,6 @@ ExeVolZmapAvoidBox( int nId, const Frame3d& frBox, const Vector3d& vtDiag, int n // recupero lo Zmap e calcolo collisione IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ; bOk = bOk && ( pVZM != nullptr && pVZM->AvoidBox( frBoxL, vtDiag)) ; - ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtVolZmapAvoidBox(" + IdToString( nId) + ",{" + @@ -491,4 +490,31 @@ ExeVolZmapAvoidBox( int nId, const Frame3d& frBox, const Vector3d& vtDiag, int n } // restituisco risultato return bOk ; -} \ No newline at end of file +} + +//---------------------------------------------------------------------------- +bool +ExeVolZmapAvoidSphere( int nId, const Point3d& ptCen, double dRad, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero il riferimento locale + Frame3d frLoc ; + bool bOk = pGeomDB->GetGlobFrame( nId, frLoc) ; + // porto in locale il centro della sfera + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frLoc) ; + // recupero lo Zmap e calcolo collisione + IVolZmap* pVZM = GetVolZmap( pGeomDB->GetGeoObj( nId)) ; + bOk = bOk && ( pVZM != nullptr && pVZM->AvoidSphere( ptCenL, dRad)) ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtVolZmapAvoidSphere(" + IdToString( nId) + ",{" + + ToString( ptCen) + "}," + + ToString( dRad) + "," + + RefTypeToString( nRefType) + ")" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; +} diff --git a/EXE_Nst.h b/EXE_Nst.h index d04fe52..492d323 100644 --- a/EXE_Nst.h +++ b/EXE_Nst.h @@ -17,6 +17,7 @@ class IGeomDB ; //---------------------------------------------------------------------------- int GetFlatPartRegion( IGeomDB* pGeomDB, int nId) ; +int GetFlatPartUpRegion( IGeomDB* pGeomDB, int nId) ; int GetFlatPartDownRegion( IGeomDB* pGeomDB, int nId) ; bool GetFlatPartCutRegions( IGeomDB* pGeomDB, int nId, bool bReduced, INTVECTOR& vCrId) ; bool GetFlatPartDownCutRegions( IGeomDB* pGeomDB, int nId, bool bReduced, INTVECTOR& vCrId) ; diff --git a/EXE_NstCreateFlatParts.cpp b/EXE_NstCreateFlatParts.cpp index 849b465..e460013 100644 --- a/EXE_NstCreateFlatParts.cpp +++ b/EXE_NstCreateFlatParts.cpp @@ -818,6 +818,113 @@ AdjustCurves( ICurve* pCrv1, ICurve* pCrv2) return ( pCrv1->ModifyEnd( ptNew) && pCrv2->ModifyStart( ptNew)) ; } +//---------------------------------------------------------------------------- +bool +ExeCalcFlatPartUpRegion( int nPartId, bool bCalc) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + + // ripristino lo stato originale + pGeomDB->Erase( pGeomDB->GetFirstNameInGroup( nPartId, NST_PARTUPREG_LAYER)) ; + // se non richiesto calcolo, non devo fare altro + if ( ! bCalc) + return true ; + + // recupero il layer esterno + int nOlId = pGeomDB->GetFirstNameInGroup( nPartId, NST_EXT_LAYER) ; + if ( nOlId == GDB_ID_NULL) + return false ; + // se il pezzo non ha lati esterni con offset negativo non devo fare alcunchè + bool bAllFixSides = true ; + int nCrvId = pGeomDB->GetFirstInGroup( nOlId) ; + while ( nCrvId != GDB_ID_NULL) { + double dOffset, dOffset2 ; + if ( ( pGeomDB->GetInfo( nCrvId, NST_KEY_OFFSET, dOffset) && dOffset < - EPS_SMALL) || + ( pGeomDB->GetInfo( nCrvId, NST_KEY_OFFSET2, dOffset2) && dOffset2 < - EPS_SMALL)) { + bAllFixSides = false ; + break ; + } + nCrvId = pGeomDB->GetNext( nCrvId) ; + } + if ( bAllFixSides) + return true ; + + // creo il layer per la regione sopra (con il medesimo riferimento del layer esterno) + Frame3d frOl ; + pGeomDB->GetGroupFrame( nOlId, frOl) ; + int nUpRegId = pGeomDB->AddGroup( GDB_ID_NULL, nPartId, frOl) ; + if ( nUpRegId == GDB_ID_NULL) + return false ; + pGeomDB->SetName( nUpRegId, NST_PARTUPREG_LAYER) ; + + // copio le entità del contorno esterno e le offsetto opportunamente + nCrvId = pGeomDB->GetFirstInGroup( nOlId) ; + while ( nCrvId != GDB_ID_NULL) { + // copio la curva nel gruppo temporaneo + int nNewId = pGeomDB->CopyGlob( nCrvId, GDB_ID_NULL, nUpRegId) ; + if ( nNewId == GDB_ID_NULL) + return false ; + // determino ed eseguo offset + double dOffset, dOffset2 ; + if ( ( pGeomDB->GetInfo( nCrvId, NST_KEY_OFFSET, dOffset) && dOffset < - EPS_SMALL) || + ( pGeomDB->GetInfo( nCrvId, NST_KEY_OFFSET2, dOffset2) && dOffset2 < - EPS_SMALL)) { + double dCalcOffset = min( dOffset, dOffset2) ; + ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nNewId)) ; + if ( pCrv == nullptr) + return false ; + pCrv->SimpleOffset( dCalcOffset) ; + } + // passo alla successiva + nCrvId = pGeomDB->GetNext( nCrvId) ; + } + // aggiusto tra loro le entità offsettate + int nFirstCrvId = pGeomDB->GetFirstInGroup( nUpRegId) ; + ICurve* pCrv1 = GetCurve( pGeomDB->GetGeoObj( nFirstCrvId)) ; + int nNextCrvId = pGeomDB->GetNext( nFirstCrvId) ; + ICurve* pCrv2 = GetCurve( pGeomDB->GetGeoObj( nNextCrvId)) ; + while ( nNextCrvId != GDB_ID_NULL) { + // sistemo le curve + pCrv2 = GetCurve( pGeomDB->GetGeoObj( nNextCrvId)) ; + if ( pCrv1 == nullptr || pCrv2 == nullptr || ! AdjustCurves( pCrv1, pCrv2)) + return false ; + // passo alla successiva + pCrv1 = pCrv2 ; + nNextCrvId = pGeomDB->GetNext( nNextCrvId) ; + } + // anche prima e ultima + pCrv2 = GetCurve( pGeomDB->GetGeoObj( nFirstCrvId)) ; + if ( pCrv1 == nullptr || pCrv2 == nullptr || ! AdjustCurves( pCrv1, pCrv2)) + return false ; + + // creo la regione + PtrOwner pCompo( CreateCurveComposite()) ; + if ( IsNull( pCompo)) + return false ; + for ( int nCrvId = pGeomDB->GetFirstInGroup( nUpRegId) ; + nCrvId != GDB_ID_NULL ; + nCrvId = pGeomDB->GetFirstInGroup( nUpRegId)) { + ICurve* pCrv = GetCurve( pGeomDB->RemoveGeoObjAndErase( nCrvId)) ; + if ( pCrv != nullptr) { + pCompo->AddCurve( pCrv) ; + pGeomDB->RemoveGeoObjAndErase( nCrvId) ; + } + else + pGeomDB->Erase( nCrvId) ; + } + SurfFlatRegionByContours SfrCntr( false) ; + SfrCntr.AddCurve( Release( pCompo)) ; + int nSfrId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nUpRegId, GDB_FIRST_SON, SfrCntr.GetSurf()) ; + if ( nSfrId == GDB_ID_NULL) + return false ; + // assegno il colore + Color cCol = AQUA ; + cCol.SetAlpha( 0.25) ; + pGeomDB->SetMaterial( nSfrId, cCol) ; + + return true ; +} + //---------------------------------------------------------------------------- bool ExeCalcFlatPartDownRegion( int nPartId, double dH) @@ -831,9 +938,9 @@ ExeCalcFlatPartDownRegion( int nPartId, double dH) if ( nOlOrigId != GDB_ID_NULL) { pGeomDB->Erase( pGeomDB->GetFirstNameInGroup( nPartId, NST_EXT_LAYER)) ; pGeomDB->SetName( nOlOrigId, NST_EXT_LAYER) ; - pGeomDB->SetStatus( nOlOrigId, GDB_ST_ON) ; + pGeomDB->SetStatus( nOlOrigId, GDB_ST_ON) ; } - // se spessore nullo, non devo fare alcunché + // se spessore nullo, non devo fare altro if ( dH < EPS_SMALL) return true ; // recupero il layer esterno @@ -1000,7 +1107,7 @@ GetFlatPartRegion( IGeomDB* pGeomDB, int nId) { if ( pGeomDB == nullptr) return GDB_ID_NULL ; - // recupero regione del pezzo (è la prima del sottogruppo di nome Region) + // recupero regione totale del pezzo (è la prima del sottogruppo di nome Region) int nRegGrp = pGeomDB->GetFirstNameInGroup( nId, NST_PARTREG_LAYER) ; int nRegId = pGeomDB->GetFirstInGroup( nRegGrp) ; while ( nRegId != GDB_ID_NULL) { @@ -1011,13 +1118,30 @@ GetFlatPartRegion( IGeomDB* pGeomDB, int nId) return nRegId ; } +//---------------------------------------------------------------------------- +int +GetFlatPartUpRegion( IGeomDB* pGeomDB, int nId) +{ + if ( pGeomDB == nullptr) + return GDB_ID_NULL ; + // recupero regione sopra del pezzo (è la prima del sottogruppo di nome UpReg) + int nRegGrp = pGeomDB->GetFirstNameInGroup( nId, NST_PARTUPREG_LAYER) ; + int nRegId = pGeomDB->GetFirstInGroup( nRegGrp) ; + while ( nRegId != GDB_ID_NULL) { + if ( pGeomDB->GetGeoType( nRegId) == SRF_FLATRGN) + break ; + nRegId = pGeomDB->GetNext( nRegId) ; + } + return nRegId ; +} + //---------------------------------------------------------------------------- int GetFlatPartDownRegion( IGeomDB* pGeomDB, int nId) { if ( pGeomDB == nullptr) return GDB_ID_NULL ; - // recupero regione del pezzo (è la prima del sottogruppo di nome DwnReg) + // recupero regione sotto del pezzo (è la prima del sottogruppo di nome DwnReg) int nRegGrp = pGeomDB->GetFirstNameInGroup( nId, NST_PARTDOWNREG_LAYER) ; int nRegId = pGeomDB->GetFirstInGroup( nRegGrp) ; while ( nRegId != GDB_ID_NULL) { diff --git a/EXE_NstMachining.cpp b/EXE_NstMachining.cpp index 8ad776b..b4abdb5 100644 --- a/EXE_NstMachining.cpp +++ b/EXE_NstMachining.cpp @@ -118,8 +118,10 @@ ExeVerifyMachining( int nMchId, int& nResult) BBox3d b3Part ; if ( pGeomDB->GetGlobalBBox( nId, b3Part, BBF_PART_MY_FLAG) && b3Mch.OverlapsXY( b3Part)) { - // recupero regione del pezzo - int nRegId = GetFlatPartRegion( pGeomDB, nId) ; + // recupero eventuale regione sopra del pezzo oppure regione del pezzo + int nRegId = GetFlatPartUpRegion( pGeomDB, nId) ; + if ( nRegId == GDB_ID_NULL) + nRegId = GetFlatPartRegion( pGeomDB, nId) ; if ( nRegId != GDB_ID_NULL) vOthReg.emplace_back( nRegId) ; else diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 6d47398..e2b25f0 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/LUA_GdbModifyVol.cpp b/LUA_GdbModifyVol.cpp index 807175d..5093891 100644 --- a/LUA_GdbModifyVol.cpp +++ b/LUA_GdbModifyVol.cpp @@ -337,13 +337,34 @@ LuaVolZmapAvoidBox( lua_State* L) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 4, nRefType) ; LuaClearStack( L) ; - // eseguo calcolo profondità dal punto lungo la direzione + // verifico non interferenza bool bOk = ExeVolZmapAvoidBox( nId, frBox, vtDiag, nRefType) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaVolZmapAvoidSphere( lua_State* L) +{ + // 3 o 4 parametri : nId, ptCen, dRad [, nRefType] + int nId ; + LuaCheckParam( L, 1, nId) + Point3d ptCen ; + LuaCheckParam( L, 2, ptCen) + double dRad ; + LuaCheckParam( L, 3, dRad) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 4, nRefType) ; + LuaClearStack( L) ; + // verifico non interferenza + bool bOk = ExeVolZmapAvoidSphere( nId, ptCen, dRad, nRefType) ; + // restituisco il risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //------------------------------------------------------------------------------- bool LuaInstallGdbModifyVol( LuaMgr& luaMgr) @@ -361,6 +382,7 @@ LuaInstallGdbModifyVol( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetDepth", LuaVolZmapGetDepth) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapIntersPlane", LuaVolZmapIntersPlane) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapAvoidBox", LuaVolZmapAvoidBox) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapAvoidSphere", LuaVolZmapAvoidSphere) ; return bOk ; } \ No newline at end of file diff --git a/LUA_GeomDB.cpp b/LUA_GeomDB.cpp index ad0e3c1..afa8a02 100644 --- a/LUA_GeomDB.cpp +++ b/LUA_GeomDB.cpp @@ -114,7 +114,7 @@ LuaSetGridFrame( lua_State* L) LuaCheckParam( L, 1, frFrame) ; LuaClearStack( L) ; // imposto il riferimento della Griglia (o CPlane) - bool bOk = ( ExeSetGridFrame( frFrame)) ; + bool bOk = ExeSetGridFrame( frFrame) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ; @@ -155,6 +155,21 @@ LuaGetGridVersZ( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaSetCurrFilePath( lua_State* L) +{ + // 1 parametro : sFilePath + string sFilePath ; + LuaCheckParam( L, 1, sFilePath) + LuaClearStack( L) ; + // imposto la path del file corrente + bool bOk = ExeSetCurrFilePath( sFilePath) ; + // restituisco il risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaGetCurrFilePath( lua_State* L) @@ -319,6 +334,7 @@ LuaInstallGeomDB( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSetGridFrame", LuaSetGridFrame) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetGridFrame", LuaGetGridFrame) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetGridVersZ", LuaGetGridVersZ) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSetCurrFilePath", LuaSetCurrFilePath) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetCurrFilePath", LuaGetCurrFilePath) ; bOk = bOk && luaMgr.RegisterFunction( "EgtEnableModified", LuaEnableModified) ; bOk = bOk && luaMgr.RegisterFunction( "EgtDisableModified", LuaDisableModified) ;