EgtMachKernel 1.6k10 :

- sistemazioni varie in grezzi, lavorazioni, ....
This commit is contained in:
Dario Sassi
2015-12-07 08:03:39 +00:00
parent 5eb5cb387f
commit 42e1a696a1
33 changed files with 1354 additions and 277 deletions
+353 -3
View File
@@ -19,6 +19,7 @@
#include "CamData.h"
#include "/EgtDev/Include/EGkGeoPoint3d.h"
#include "/EgtDev/Include/EGkCurveLine.h"
#include "/EgtDev/Include/EgkIntersCurves.h"
#include "/EgtDev/Include/EGkIntersLineSurfTm.h"
#include "/EgtDev/Include/EGkGeomDB.h"
#include "/EgtDev/Include/EgtPointerOwner.h"
@@ -197,6 +198,76 @@ Machining::GetElevation( const Point3d& ptP1, const Point3d& ptP2, const Vector3
return bFound ;
}
//----------------------------------------------------------------------------
bool
Machining::GetDistanceFromRawSide( const Point3d& ptP, const Vector3d& vtDir, double& dDist)
{
// recupero il grezzo in cui è incluso il punto
BBox3d b3Pnt( ptP) ;
b3Pnt.Expand( 10, 10, 0) ;
int nRawId = m_pMchMgr->GetFirstRawPart() ;
while ( nRawId != GDB_ID_NULL) {
BBox3d b3Raw ;
int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ;
if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3Raw) && b3Pnt.OverlapsXY( b3Raw)) {
break ;
}
nRawId = m_pMchMgr->GetNextRawPart( nRawId) ;
}
// se il punto non è interno ad alcun grezzo, distanza nulla
if ( nRawId == GDB_ID_NULL) {
dDist = 0 ;
return true ;
}
// recupero il contorno del grezzo
int nOutId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ;
ICurve* pOut = ::GetCurve( m_pGeomDB->GetGeoObj( nOutId)) ;
if ( pOut == nullptr)
return false ;
// recupero il riferimento del contorno e verifico che abbia Z verticale
Frame3d frStm ;
if ( ! m_pGeomDB->GetGlobFrame( nOutId, frStm) ||
( frStm.GetZType() != Frame3d::TOP && frStm.GetZType() != Frame3d::BOTTOM))
return false ;
// interseco il raggio di test (portato nel riferimento del contorno) con il contorno del grezzo
const double RAY_LEN = 10000 ;
PtrOwner<ICurveLine> pRay( CreateCurveLine()) ;
if ( IsNull( pRay) || ! pRay->SetPVL( ptP, vtDir, RAY_LEN))
return false ;
pRay->ToLoc( frStm) ;
IntersCurveCurve intCC( *Get( pRay), *pOut) ;
IntCrvCrvInfo aInfo ;
if ( intCC.GetIntCrvCrvInfo( 0, aInfo))
dDist = aInfo.IciA[0].dU * RAY_LEN ;
else
dDist = 0 ;
return true ;
}
//----------------------------------------------------------------------------
bool
Machining::GetDistanceFromRawBottom( int nPathId, double dToler, double& dRbDist)
{
// recupero distanza da fondo dei grezzi interessati dal percorso
dRbDist = 0 ;
BBox3d b3Compo ;
if ( ! m_pGeomDB->GetGlobalBBox( nPathId, b3Compo))
return false ;
b3Compo.Expand( dToler, dToler, 0) ;
int nRawId = m_pMchMgr->GetFirstRawPart() ;
while ( nRawId != GDB_ID_NULL) {
BBox3d b3Raw ;
int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ;
if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3Raw) && b3Compo.OverlapsXY( b3Raw)) {
double dDist = b3Compo.GetMax().z - b3Raw.GetMin().z ;
if ( dDist > dRbDist)
dRbDist = dDist ;
}
nRawId = m_pMchMgr->GetNextRawPart( nRawId) ;
}
return true ;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool
@@ -248,7 +319,7 @@ Machining::SetFlag( int nFlag)
//----------------------------------------------------------------------------
int
Machining::AddStart( const Point3d& ptP)
Machining::AddRapidStart( const Point3d& ptP)
{
// verifico di essere in uno stato valido per inizio
if ( m_vtTool.IsSmall())
@@ -272,6 +343,8 @@ Machining::AddStart( const Point3d& ptP)
pCam->SetCorrDir( m_vtCorr) ;
pCam->SetAuxDir( m_vtAux) ;
pCam->SetBasePoint( ptP) ;
pCam->SetFeed( 0) ;
pCam->SetFlag( m_nFlag) ;
// associo questo oggetto a quello geometrico
m_pGeomDB->SetUserObj( nId, Release( pCam)) ;
// salvo la posizione corrente
@@ -280,6 +353,42 @@ Machining::AddStart( const Point3d& ptP)
return nId ;
}
//----------------------------------------------------------------------------
int
Machining::AddRapidMove( const Point3d& ptP)
{
// verifico di essere in uno stato valido per un movimento in rapido
if ( ! m_bCurr || m_vtTool.IsSmall())
return GDB_ID_NULL ;
// creo oggetto linea per DB geometrico
PtrOwner<ICurveLine> pLine( CreateCurveLine()) ;
if ( IsNull( pLine))
return GDB_ID_NULL ;
// assegno le coordinate degli estremi
if ( ! pLine->Set( m_ptCurr, ptP))
return GDB_ID_NULL ;
// inserisco l'oggetto nel DB geometrico
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pLine)) ;
if ( nId == GDB_ID_NULL)
return GDB_ID_NULL ;
// creo oggetto dati Cam
PtrOwner<CamData> pCam( new( nothrow) CamData) ;
if ( IsNull( pCam))
return GDB_ID_NULL ;
// assegno valori
pCam->SetToolDir( m_vtTool) ;
pCam->SetCorrDir( m_vtCorr) ;
pCam->SetAuxDir( m_vtAux) ;
pCam->SetBasePoint( ptP) ;
pCam->SetFeed( 0) ;
pCam->SetFlag( m_nFlag) ;
// associo questo oggetto a quello geometrico
m_pGeomDB->SetUserObj( nId, Release( pCam)) ;
// salvo la posizione corrente
m_ptCurr = ptP ;
return nId ;
}
//----------------------------------------------------------------------------
int
Machining::AddLinearMove( const Point3d& ptP)
@@ -331,16 +440,53 @@ Machining::ResetMoveData( void)
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool
Machining::GetInitialAxesValues( DBLVECTOR& vAxVal)
{
// recupero gruppo per geometria di lavorazione (Cutter Location)
int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ;
if ( nClId == GDB_ID_NULL)
return false ;
// recupero il primo percorso CL
int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ;
// restituisco i valori iniziali degli assi di questo percorso di lavorazione
return GetClPathInitialAxesValues( nClPathId, vAxVal) ;
}
//----------------------------------------------------------------------------
bool
Machining::GetClPathInitialAxesValues( int nClPathId, DBLVECTOR& vAxVal)
{
// recupero la prima entità di questo percorso
int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ;
// recupero i dati Cam dell'entità
CamData* pCamData = dynamic_cast<CamData*>( m_pGeomDB->GetUserObj( nEntId)) ;
if ( pCamData == nullptr)
return false ;
// assegno i valori degli assi
vAxVal = pCamData->GetAxisVal() ;
return ( vAxVal.size() > 0) ;
}
//----------------------------------------------------------------------------
bool
Machining::GetFinalAxesValues( DBLVECTOR& vAxVal)
{
// recupero gruppo per geometria di lavorazione (Cutter Location)
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ;
int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ;
if ( nClId == GDB_ID_NULL)
return false ;
// recupero l'ultimo percorso CL
int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ;
// restituisco i valori finali degli assi di questo percorso di lavorazione
return GetClPathFinalAxesValues( nClPathId, vAxVal) ;
}
//----------------------------------------------------------------------------
bool
Machining::GetClPathFinalAxesValues( int nClPathId, DBLVECTOR& vAxVal)
{
// recupero l'ultima entità di questo percorso
int nEntId = m_pGeomDB->GetLastInGroup( nClPathId) ;
// recupero i dati Cam dell'entità
@@ -397,7 +543,7 @@ Machining::CalculateAxesValues( void)
double dRot1W = m_pMchMgr->GetCalcRot1W() ;
// recupero gruppo della geometria di lavorazione (Cutter Location)
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ;
int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ;
if ( nClId == GDB_ID_NULL)
return false ;
@@ -497,3 +643,207 @@ Machining::CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes,
return bOk ;
}
//----------------------------------------------------------------------------
bool
Machining::AdjustStartMovements(void)
{
// recupero gruppo della geometria di lavorazione (Cutter Location)
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ;
if ( nClId == GDB_ID_NULL)
return false ;
// recupero la lavorazione precedente
int nPrevOpId = m_pMchMgr->GetPrevOperation( m_nOwnerId) ;
Machining* pPrevMch = dynamic_cast<Machining*>( m_pGeomDB->GetUserObj( nPrevOpId)) ;
// recupero l'utensile precedente e i dati della sua testa
string sPrevTool ;
if ( pPrevMch != nullptr)
pPrevMch->GetParam( MPA_TOOL, sPrevTool) ;
// imposto l'utensile per i calcoli macchina
if ( ! m_pMchMgr->SetCalcTool( GetToolData().m_sName, GetToolData().m_sHead, GetToolData().m_nExit))
return false ;
// determino posizione precedente assi
DBLVECTOR vAxVal ;
// se primo utensile, uso la posizione home
if ( sPrevTool.empty()) {
if ( ! m_pMchMgr->GetAllCalcAxesHomePos( vAxVal))
return false ;
}
// se utensile non cambiato o su diversa uscita della stessa testa, uso posizione finale della lavorazione precedente
else if ( ! ToolChangeNeeded( pPrevMch->GetToolData(), GetToolData())) {
pPrevMch->RemoveRise() ;
DBLVECTOR vAxIni ;
if ( ! pPrevMch->GetFinalAxesValues( vAxVal) || ! GetInitialAxesValues( vAxIni))
return false ;
if ( vAxVal.size() >= 5 && vAxIni.size() >= 5 &&
fabs( vAxVal[4] - vAxIni[4]) > 15) {
double dDelta = max( vAxVal[2], vAxIni[2]) - vAxVal[2] + 200 ;
if ( ! pPrevMch->AddRise( vAxVal, dDelta))
return false ;
}
}
// altrimenti aggiungo uscita per cambio utensile alla lavorazione precedente e parto da questa
else {
pPrevMch->RemoveRise() ;
if ( ! pPrevMch->AddRise( vAxVal))
return false ;
}
// aggiusto l'inizio di ogni percorso di lavoro
bool bOk = true ;
int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ;
while ( bOk && nClPathId != GDB_ID_NULL) {
// sistemo inizio
if ( ! AdjustOneStartMovement( nClPathId, vAxVal))
bOk = false ;
// recupero nuovi finali
if ( ! GetClPathFinalAxesValues( nClPathId, vAxVal))
bOk = false ;
// passo al successivo
nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ;
}
// aggiungo risalita finale
AddRise( vAxVal) ;
return bOk ;
}
//----------------------------------------------------------------------------
bool
Machining::AdjustOneStartMovement( int nClPathId, const DBLVECTOR& vAxPrev)
{
// recupero la prima entità di questo percorso
int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ;
// recupero i dati Cam dell'entità
CamData* pCamData = dynamic_cast<CamData*>( m_pGeomDB->GetUserObj( nEntId)) ;
if ( pCamData == nullptr)
return false ;
// recupero i valori degli assi
DBLVECTOR vAxCurr ;
vAxCurr = pCamData->GetAxisVal() ;
// se Z pressochè uguali non devo fare alcunché
if ( fabs( vAxCurr[2] - vAxPrev[2]) < 10 * EPS_SMALL)
return true ;
// se Z corrente maggiore della precedente
else if ( vAxCurr[2] > vAxPrev[2]) {
// copio l'entità
if ( m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_AFTER) == GDB_ID_NULL)
return false ;
// modifico quella originale (è la prima del percorso)
DBLVECTOR vAxNew = vAxPrev ;
vAxNew[2] = vAxCurr[2] ;
pCamData->SetAxes( CamData::AS_OK, vAxNew) ;
pCamData->ChangeAxesMask( CamData::MSK_L3) ;
pCamData->SetFlag( 0) ;
}
// altrimenti Z corrente minore della precedente
else {
// copio l'entità
if ( m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_AFTER) == GDB_ID_NULL)
return false ;
// modifico quella originale (è la prima del percorso)
DBLVECTOR vAxNew = vAxCurr ;
vAxNew[2] = vAxPrev[2] ;
pCamData->SetAxes( CamData::AS_OK, vAxNew) ;
pCamData->ChangeAxesMask( CamData::MSK_L1 | CamData::MSK_L2 | CamData::MSK_R1 | CamData::MSK_R2) ;
pCamData->SetFlag( 2) ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
Machining::ToolChangeNeeded( const ToolData& T1, const ToolData& T2)
{
// se non cambia l'utensile, non cambia la testa fisica
if ( EqualNoCase( T1.m_sName, T2.m_sName))
return false ;
// se non hanno TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica
if ( T1.m_sTcPos.empty() && T2.m_sTcPos.empty() &&
EqualNoCase( T1.m_sHead, T2.m_sHead) && T1.m_nExit != T2.m_nExit)
return false ;
// se hanno lo stesso TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica
if ( EqualNoCase( T1.m_sTcPos, T2.m_sTcPos) &&
EqualNoCase( T1.m_sHead, T2.m_sHead) && T1.m_nExit != T2.m_nExit)
return false ;
// altrimenti necessario un cambio
return true ;
}
//----------------------------------------------------------------------------
bool
Machining::AddRise( DBLVECTOR& vAxVal, double dDelta)
{
// recupero gruppo per geometria di lavorazione (Cutter Location)
int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ;
if ( nClId == GDB_ID_NULL)
return false ;
// recupero l'ultimo percorso
int nLastPxClId = m_pGeomDB->GetLastGroupInGroup( nClId) ;
// recupero l'ultima entità del percorso
int nEntId = m_pGeomDB->GetLastInGroup( nLastPxClId) ;
if ( nEntId == GDB_ID_NULL)
return false ;
// ne recupero i dati Cam
CamData* pCamData = dynamic_cast<CamData*>( m_pGeomDB->GetUserObj( nEntId)) ;
if ( pCamData == nullptr)
return false ;
// creo oggetto punto per DB geometrico
PtrOwner<IGeoPoint3d> pGP( CreateGeoPoint3d()) ;
if ( IsNull( pGP))
return false ;
// assegno le coordinate del punto
pGP->Set( pCamData->GetBasePoint()) ;
// inserisco l'oggetto nel DB geometrico
int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLastPxClId, Release( pGP)) ;
if ( nId == GDB_ID_NULL)
return false ;
m_pGeomDB->SetName( nId, MCH_RISE) ;
// creo oggetto dati Cam
PtrOwner<CamData> pCam( pCamData->Clone()) ;
if ( IsNull( pCam))
return false ;
// recupero i valori degli assi
vAxVal = pCam->GetAxisVal() ;
// se delta positivo lo uso come incremeto di Z
if ( dDelta > 0)
vAxVal[2] += dDelta ;
// altrimenti uso la Z home
else {
DBLVECTOR vAxHome ;
m_pMchMgr->GetAllCalcAxesHomePos( vAxHome) ;
vAxVal[2] = vAxHome[2] ;
}
pCam->SetAxes( CamData::AS_OK, vAxVal) ;
pCam->SetFeed( 0) ;
pCam->SetFlag( 3) ;
// associo questo oggetto a quello geometrico
m_pGeomDB->SetUserObj( nId, Release( pCam)) ;
return true ;
}
//----------------------------------------------------------------------------
bool
Machining::RemoveRise( void)
{
// recupero gruppo per geometria di lavorazione (Cutter Location)
int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ;
if ( nClId == GDB_ID_NULL)
return false ;
// recupero l'ultimo percorso CL
int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ;
// elimino tutte le entità RISE alla fine del percorso
int nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_RISE) ;
while ( nId != GDB_ID_NULL) {
m_pGeomDB->Erase( nId) ;
nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_RISE) ;
}
return true ;
}