d87b349788
- primo commit per CAv tra Regioni Piane con loop interni e Interferenza tra Regioni Piane.
305 lines
12 KiB
C++
305 lines
12 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2016
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_NstMachining.cpp Data : 31.08.16 Versione : 1.6t4
|
|
// Contenuto : Funzioni Nesting di lavorazione per EXE.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 08.02.16 DS Creazione modulo.
|
|
// 31.08.16 DS Corretta ExeVerifyCutAsSplitting con un lato già allungato.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EXE.h"
|
|
#include "EXE_Const.h"
|
|
#include "EXE_Macro.h"
|
|
#include "EXE_Nst.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EXeConst.h"
|
|
#include "/EgtDev/Include/EGkCAvSimpleSurfFrMove.h"
|
|
#include "/EgtDev/Include/EMkOperationConst.h"
|
|
#include "/EgtDev/Include/EMkMachiningConst.h"
|
|
#include "/EgtDev/Include/EMkMachiningGeoConst.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeVerifyMachining( int nMchId, int& nResult)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
|
|
// Flag per calcolo box
|
|
const int BBF_MCH_MY_FLAG = BBF_STANDARD ;
|
|
const int BBF_PART_MY_FLAG = BBF_ONLY_VISIBLE | BBF_IGNORE_TEXT | BBF_IGNORE_DIM ;
|
|
|
|
// Recupero il box e le regioni della lavorazione
|
|
BBox3d b3Mch ;
|
|
INTVECTOR vMchRReg, vMchLiReg, vMchLoReg ;
|
|
INTVECTOR vMchDwnRReg, vMchDwnLiReg, vMchDwnLoReg ;
|
|
// recupero gruppo preview lavorazioni nella lavorazione
|
|
int nPVGrp = pGeomDB->GetFirstNameInGroup( nMchId, MCH_PV) ;
|
|
if ( nPVGrp == GDB_ID_NULL)
|
|
return false ;
|
|
// se vuoto, cerco il rimando al preview nel pezzo
|
|
if ( pGeomDB->GetGroupObjs( nPVGrp) == 0 &&
|
|
! pGeomDB->GetInfo( nPVGrp, MCH_PV_KEY_RELOCATE, nPVGrp))
|
|
return false ;
|
|
// ciclo sui percorsi utensile (CL)
|
|
int nClId = pGeomDB->GetFirstGroupInGroup( nPVGrp) ;
|
|
while ( nClId != GDB_ID_NULL) {
|
|
// tagli ridotti
|
|
int nCrId = pGeomDB->GetFirstNameInGroup( nClId, MCH_PV_RRCUT) ;
|
|
int nDwnCrId = pGeomDB->GetFirstNameInGroup( nClId, MCH_PV_DOWN_RRCUT) ;
|
|
while ( nCrId != GDB_ID_NULL) {
|
|
BBox3d b3Reg ;
|
|
if ( ! pGeomDB->GetGlobalBBox( nCrId, b3Reg, BBF_MCH_MY_FLAG))
|
|
return false ;
|
|
b3Mch.Add( b3Reg) ;
|
|
vMchRReg.emplace_back( nCrId) ;
|
|
vMchDwnRReg.emplace_back( nDwnCrId) ;
|
|
nCrId = pGeomDB->GetNextName( nCrId, MCH_PV_RRCUT) ;
|
|
nDwnCrId = pGeomDB->GetNextName( nDwnCrId, MCH_PV_DOWN_RRCUT) ;
|
|
}
|
|
// ingressi
|
|
int nLiId = pGeomDB->GetFirstNameInGroup( nClId, MCH_PV_RLICUT) ;
|
|
int nDwnLiId = pGeomDB->GetFirstNameInGroup( nClId, MCH_PV_DOWN_RLICUT) ;
|
|
while ( nLiId != GDB_ID_NULL) {
|
|
BBox3d b3Reg ;
|
|
if ( ! pGeomDB->GetGlobalBBox( nLiId, b3Reg, BBF_MCH_MY_FLAG))
|
|
return false ;
|
|
b3Mch.Add( b3Reg) ;
|
|
vMchLiReg.emplace_back( nLiId) ;
|
|
vMchDwnLiReg.emplace_back( nDwnLiId) ;
|
|
nLiId = pGeomDB->GetNextName( nLiId, MCH_PV_RLICUT) ;
|
|
nDwnLiId = pGeomDB->GetNextName( nDwnLiId, MCH_PV_DOWN_RLICUT) ;
|
|
}
|
|
// uscite
|
|
int nLoId = pGeomDB->GetFirstNameInGroup( nClId, MCH_PV_RLOCUT) ;
|
|
int nDwnLoId = pGeomDB->GetFirstNameInGroup( nClId, MCH_PV_DOWN_RLOCUT) ;
|
|
while ( nLoId != GDB_ID_NULL) {
|
|
BBox3d b3Reg ;
|
|
if ( ! pGeomDB->GetGlobalBBox( nLoId, b3Reg, BBF_MCH_MY_FLAG))
|
|
return false ;
|
|
b3Mch.Add( b3Reg) ;
|
|
vMchLoReg.emplace_back( nLoId) ;
|
|
vMchDwnLoReg.emplace_back( nDwnLoId) ;
|
|
nLoId = pGeomDB->GetNextName( nLoId, MCH_PV_RLOCUT) ;
|
|
nDwnLoId = pGeomDB->GetNextName( nDwnLoId, MCH_PV_DOWN_RLOCUT) ;
|
|
}
|
|
// passo al successivo percorso utensile
|
|
nClId = pGeomDB->GetNextGroup( nClId) ;
|
|
}
|
|
|
|
// Recupero il pezzo cui è associata la lavorazione
|
|
int nMchPartId = GDB_ID_NULL ;
|
|
SELVECTOR vIds ;
|
|
if ( ExeSetCurrMachining( nMchId) && ExeGetMachiningGeometry( vIds) && ! vIds.empty())
|
|
nMchPartId = pGeomDB->GetParentId( pGeomDB->GetParentId( vIds[0].nId)) ;
|
|
|
|
// Recupero la fase di appartenenza della lavorazione
|
|
int nPhase = ExeGetOperationPhase( nMchId) ;
|
|
|
|
// Determino le regioni di tutti gli altri pezzi compresi nella regione della lavorazione
|
|
INTVECTOR vOthReg ;
|
|
INTVECTOR vOthDwnReg ;
|
|
int nRawId = ExeGetFirstRawPart() ;
|
|
while ( nRawId != GDB_ID_NULL) {
|
|
// se il grezzo appartiene alla fase di lavorazione
|
|
if ( ExeVerifyRawPartPhase( nRawId, nPhase)) {
|
|
// ciclo sui pezzi presenti nel grezzo
|
|
int nId = ExeGetFirstPartInRawPart( nRawId) ;
|
|
while ( nId != GDB_ID_NULL) {
|
|
if ( nId != nMchPartId) {
|
|
BBox3d b3Part ;
|
|
if ( pGeomDB->GetGlobalBBox( nId, b3Part, BBF_PART_MY_FLAG) &&
|
|
b3Mch.OverlapsXY( b3Part)) {
|
|
// 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
|
|
return false ;
|
|
// recupero eventuale regione sotto del pezzo
|
|
int nDwnRegId = GetFlatPartDownRegion( pGeomDB, nId) ;
|
|
vOthDwnReg.emplace_back( nDwnRegId) ;
|
|
}
|
|
}
|
|
nId = ExeGetNextPartInRawPart( nId) ;
|
|
}
|
|
}
|
|
nRawId = ExeGetNextRawPart( nRawId) ;
|
|
}
|
|
|
|
// Eseguo verifiche
|
|
nResult = FMI_NONE ;
|
|
const double VERIF_TOLER = 20 * EPS_SMALL ;
|
|
// confronto la regione di attacco della lavorazione con le regioni degli altri pezzi
|
|
for ( int nMchRegId : vMchLiReg) {
|
|
for ( int nOthRegId : vOthReg) {
|
|
if ( ExeSurfFlatRegionInterference( nOthRegId, 0, nMchRegId, 0, VERIF_TOLER) != REGC_OUT)
|
|
nResult |= FMI_LI ;
|
|
}
|
|
}
|
|
for ( size_t i = 0 ; i < vMchDwnLiReg.size() ; ++ i) {
|
|
for ( size_t j = 0 ; j < vOthDwnReg.size() ; ++ j) {
|
|
if ( vMchDwnLiReg[i] != GDB_ID_NULL || vOthDwnReg[j] != GDB_ID_NULL) {
|
|
int nMchRegId = ( ( vMchDwnLiReg[i] != GDB_ID_NULL) ? vMchDwnLiReg[i] : vMchLiReg[i]) ;
|
|
int nOthRegId = ( ( vOthDwnReg[j] != GDB_ID_NULL) ? vOthDwnReg[j] : vOthReg[j]) ;
|
|
if ( ExeSurfFlatRegionInterference( nOthRegId, 0, nMchRegId, 0, VERIF_TOLER) != REGC_OUT)
|
|
nResult |= FMI_LI ;
|
|
}
|
|
}
|
|
}
|
|
// confronto la regione ridotta della lavorazione con le regioni degli altri pezzi
|
|
for ( int nMchRegId : vMchRReg) {
|
|
for ( int nOthRegId : vOthReg) {
|
|
if ( ExeSurfFlatRegionInterference( nOthRegId, 0, nMchRegId, 0, VERIF_TOLER) != REGC_OUT)
|
|
nResult |= FMI_RM ;
|
|
}
|
|
}
|
|
for ( size_t i = 0 ; i < vMchDwnRReg.size() ; ++ i) {
|
|
for ( size_t j = 0 ; j < vOthDwnReg.size() ; ++ j) {
|
|
if ( vMchDwnRReg[i] != GDB_ID_NULL || vOthDwnReg[j] != GDB_ID_NULL) {
|
|
int nMchRegId = ( ( vMchDwnRReg[i] != GDB_ID_NULL) ? vMchDwnRReg[i] : vMchRReg[i]) ;
|
|
int nOthRegId = ( ( vOthDwnReg[j] != GDB_ID_NULL) ? vOthDwnReg[j] : vOthReg[j]) ;
|
|
if ( ExeSurfFlatRegionInterference( nOthRegId, 0, nMchRegId, 0, VERIF_TOLER) != REGC_OUT)
|
|
nResult |= FMI_RM ;
|
|
}
|
|
}
|
|
}
|
|
// confronto la regione di uscita della lavorazione con le regioni degli altri pezzi
|
|
for ( int nMchRegId : vMchLoReg) {
|
|
for ( int nOthRegId : vOthReg) {
|
|
if ( ExeSurfFlatRegionInterference( nOthRegId, 0, nMchRegId, 0, VERIF_TOLER) != REGC_OUT)
|
|
nResult |= FMI_LO ;
|
|
}
|
|
}
|
|
for ( size_t i = 0 ; i < vMchDwnLoReg.size() ; ++ i) {
|
|
for ( size_t j = 0 ; j < vOthDwnReg.size() ; ++ j) {
|
|
if ( vMchDwnLoReg[i] != GDB_ID_NULL || vOthDwnReg[j] != GDB_ID_NULL) {
|
|
int nMchRegId = ( ( vMchDwnLoReg[i] != GDB_ID_NULL) ? vMchDwnLoReg[i] : vMchLoReg[i]) ;
|
|
int nOthRegId = ( ( vOthDwnReg[j] != GDB_ID_NULL) ? vOthDwnReg[j] : vOthReg[j]) ;
|
|
if ( ExeSurfFlatRegionInterference( nOthRegId, 0, nMchRegId, 0, VERIF_TOLER) != REGC_OUT)
|
|
nResult |= FMI_LO ;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static bool
|
|
GetRawBottomHeight( int nMchId, double& dRbHeight)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
|
|
// recupero gruppo preview lavorazioni nella lavorazione
|
|
int nPVGrp = pGeomDB->GetFirstNameInGroup( nMchId, MCH_PV) ;
|
|
if ( nPVGrp == GDB_ID_NULL)
|
|
return false ;
|
|
// se vuoto, cerco il rimando al preview nel pezzo
|
|
if ( pGeomDB->GetGroupObjs( nPVGrp) == 0 &&
|
|
! pGeomDB->GetInfo( nPVGrp, MCH_PV_KEY_RELOCATE, nPVGrp))
|
|
return false ;
|
|
// recupero il primo percorso utensile (CL)
|
|
int nClId = pGeomDB->GetFirstGroupInGroup( nPVGrp) ;
|
|
return pGeomDB->GetInfo( nClId, MCH_PV_KEY_RBH, dRbHeight) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeVerifyCutAsSplitting( int nMchId)
|
|
{
|
|
GseContext* pGseCtx = GetCurrGseContext() ;
|
|
VERIFY_CTX_MACHMGR( pGseCtx, CAR_INTERF)
|
|
IMachMgr* pMachMgr = pGseCtx->m_pMachMgr ;
|
|
|
|
// verifico che la lavorazione indicata sia veramente un taglio con lama
|
|
if ( pMachMgr->GetOperationType( nMchId) != OPER_SAWING)
|
|
return CAR_INTERF ;
|
|
|
|
// determino se passante (solo se preview già calcolato)
|
|
double dRbHeight = 0 ;
|
|
if ( GetRawBottomHeight( nMchId, dRbHeight) && dRbHeight > EPS_SMALL)
|
|
return CAR_INTERF ;
|
|
|
|
// recupero la lavorazione corrente
|
|
int nCurrMch = pGseCtx->m_pMachMgr->GetCurrMachining() ;
|
|
// imposto la nuova lavorazione corrente
|
|
pMachMgr->SetCurrMachining( nMchId) ;
|
|
// determino se ha preview nella lavorazione
|
|
bool bIsPV = pMachMgr->ExistsMachiningPreview() ;
|
|
// risultato
|
|
int nResult = CAR_INTERF ;
|
|
// recupero attacco e uscita correnti della lavorazione
|
|
int nLiType ;
|
|
pMachMgr->GetMachiningParam( MPA_LEADINTYPE, nLiType) ;
|
|
int nLoType ;
|
|
pMachMgr->GetMachiningParam( MPA_LEADOUTTYPE, nLoType) ;
|
|
// verifico se posso portare attacco al bordo grezzo
|
|
bool bLiToModif = ( nLiType != SAW_LI_EXT_CENT && nLiType != SAW_LI_EXT_OUT) ;
|
|
if ( bLiToModif) {
|
|
// cambio attacco
|
|
pMachMgr->SetMachiningParam( MPA_LEADINTYPE, SAW_LI_EXT_CENT) ;
|
|
// aggiorno preview
|
|
pMachMgr->MachiningPreview( true) ;
|
|
// verifico interferenza
|
|
int nRes ;
|
|
if ( ExeVerifyMachining( nMchId, nRes) && ( nRes == FMI_NONE || nRes == FMI_LO))
|
|
nResult += CAR_LI_OK ;
|
|
// ripristino attacco originale
|
|
pMachMgr->SetMachiningParam( MPA_LEADINTYPE, nLiType) ;
|
|
// ripristino preview originale
|
|
pMachMgr->MachiningPreview( true) ;
|
|
}
|
|
// altrimenti verifico con già al bordo grezzo
|
|
else {
|
|
// verifico interferenza
|
|
int nRes ;
|
|
if ( ExeVerifyMachining( nMchId, nRes) && ( nRes == FMI_NONE || nRes == FMI_LO))
|
|
nResult += CAR_LI_OK ;
|
|
}
|
|
// verifico se posso portare uscita al bordo grezzo
|
|
bool bLoToModif = ( nLoType != SAW_LO_EXT_CENT && nLoType != SAW_LO_EXT_OUT) ;
|
|
if ( bLoToModif) {
|
|
pMachMgr->SetMachiningParam( MPA_LEADOUTTYPE, SAW_LO_EXT_CENT) ;
|
|
// aggiorno preview
|
|
pMachMgr->MachiningPreview( true) ;
|
|
// verifico interferenza
|
|
int nRes ;
|
|
if ( ExeVerifyMachining( nMchId, nRes) && ( nRes == FMI_NONE || nRes == FMI_LI))
|
|
nResult += CAR_LO_OK ;
|
|
// ripristino uscita originale
|
|
pMachMgr->SetMachiningParam( MPA_LEADOUTTYPE, nLoType) ;
|
|
// ripristino preview originale
|
|
pMachMgr->MachiningPreview( true) ;
|
|
}
|
|
// altrimenti verifico con già al bordo grezzo
|
|
else {
|
|
// verifico interferenza
|
|
int nRes ;
|
|
if ( ExeVerifyMachining( nMchId, nRes) && ( nRes == FMI_NONE || nRes == FMI_LI))
|
|
nResult += CAR_LO_OK ;
|
|
}
|
|
// verifico se taglio non passante
|
|
if ( ! GetRawBottomHeight( nMchId, dRbHeight) || dRbHeight > EPS_SMALL)
|
|
nResult = CAR_INTERF ;
|
|
// se non c'era preview nella lavorazione, lo cancello
|
|
if ( ! bIsPV)
|
|
pMachMgr->RemoveMachiningPreview() ;
|
|
// ripristino lavorazione corrente
|
|
pMachMgr->SetCurrMachining( nCurrMch) ;
|
|
|
|
// restituisco il risultato
|
|
return nResult ;
|
|
}
|