EgtGeomKernel 1.9g1 :
- migliorata CollisionAvoidance con utensili generici - gestione Tool potenziata con possibilità di restituire il profilo.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2015-2016
|
||||
// EgalTech 2015-2018
|
||||
//----------------------------------------------------------------------------
|
||||
// File : VolZmap.cpp Data : 22.01.15 Versione : 1.6a4
|
||||
// File : Tool.cpp Data : 04.07.18 Versione : 1.9g1
|
||||
// Contenuto : Implementazione della classe Tool
|
||||
//
|
||||
//
|
||||
@@ -25,10 +25,11 @@
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Tool::Tool( void)
|
||||
Tool::Tool( bool bApproxWithLines)
|
||||
: m_dLinTol( LIN_TOL_STD), m_dAngTolDeg( ANG_TOL_APPROX_DEG), m_nType( UNDEF), m_nCurrentNum( 0), m_dHeight( 0),
|
||||
m_dTipHeight( 0), m_dRadius( 0), m_dRCorner( 0), m_dTipRadius( 0), m_dMrtChsWidth( 0), m_dMrtChsThickness( 0)
|
||||
{
|
||||
m_dTipHeight( 0), m_dRadius( 0), m_dRCorner( 0), m_dTipRadius( 0), m_dMrtChsWidth( 0), m_dMrtChsThickness( 0),
|
||||
m_bApproxWithLines( bApproxWithLines)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -50,15 +51,16 @@ Tool::SetTolerances( double dLinTol, double dAngTolDeg)
|
||||
bool
|
||||
Tool::SetStdTool( const string& sToolName, double dH, double dR, double dCornR, int nToolNum)
|
||||
{
|
||||
// assegno il nome
|
||||
// Impostazioni generali
|
||||
m_sName = sToolName ;
|
||||
// Aggiorno il numero dell'utensile corrente
|
||||
m_nCurrentNum = nToolNum ;
|
||||
// Imposto il tipo di utensile a indefinito
|
||||
m_nType = UNDEF ;
|
||||
m_Outline.Clear() ;
|
||||
|
||||
// verifica sulle minime dimensioni globali
|
||||
if ( dH < EPS_SMALL || dR < EPS_SMALL)
|
||||
return false ;
|
||||
if ( dH < EPS_SMALL || dR < EPS_SMALL || dCornR < - EPS_SMALL)
|
||||
return false ;
|
||||
|
||||
// utensile cilindrico
|
||||
if ( dCornR < EPS_SMALL) {
|
||||
m_nType = CYLMILL ;
|
||||
@@ -67,28 +69,40 @@ Tool::SetStdTool( const string& sToolName, double dH, double dR, double dCornR,
|
||||
m_dTipHeight = 0 ;
|
||||
m_dTipRadius = m_dRadius ;
|
||||
m_dRCorner = 0 ;
|
||||
// profilo
|
||||
Point3d pt0( 0, 0, 0) ;
|
||||
Point3d pt1( m_dRadius, 0, 0) ;
|
||||
Point3d pt3( m_dRadius, - m_dHeight, 0) ;
|
||||
Point3d pt4( 0, - m_dHeight, 0) ;
|
||||
m_Outline.Clear() ;
|
||||
m_Outline.AddPoint( pt0) ;
|
||||
m_Outline.AddLine( pt1);
|
||||
m_Outline.AddLine( pt3) ;
|
||||
m_Outline.AddLine( pt4) ;
|
||||
}
|
||||
// utensile naso di toro
|
||||
else if ( dCornR < dR - EPS_SMALL) {
|
||||
else if ( dCornR < dR - EPS_SMALL) {
|
||||
m_nType = BULLNOSEMILL ;
|
||||
m_dHeight = dH ;
|
||||
m_dRadius = dR ;
|
||||
m_dTipHeight = dCornR ;
|
||||
m_dTipRadius = dR - dCornR ;
|
||||
m_dTipRadius = dR - dCornR ;
|
||||
m_dRCorner = dCornR ;
|
||||
// come profilo
|
||||
// profilo
|
||||
Point3d pt0( 0, 0, 0) ;
|
||||
Point3d pt1( m_dRadius, 0, 0) ;
|
||||
Point3d pt2( m_dRadius, - m_dHeight + m_dTipHeight, 0) ;
|
||||
Point3d pt3( m_dTipRadius, - m_dHeight, 0) ;
|
||||
Point3d pt4( 0, - m_dHeight, 0) ;
|
||||
m_Outline.Clear() ;
|
||||
CurveLine Line ;
|
||||
Line.Set( pt0, pt1) ;
|
||||
m_Outline.AddCurve( Line) ;
|
||||
m_Outline.AddPoint( pt0) ;
|
||||
m_Outline.AddLine( pt1);
|
||||
m_Outline.AddLine( pt2);
|
||||
m_Outline.AddArcTg( pt3) ;
|
||||
m_Outline.AddLine( pt4) ;
|
||||
return SetGenTool( sToolName, & m_Outline, nToolNum) ;
|
||||
// se da approosimare
|
||||
if ( m_bApproxWithLines)
|
||||
return SetGenTool( sToolName, &m_Outline, nToolNum) ;
|
||||
}
|
||||
// utensile sferico
|
||||
else if ( dCornR < dR + EPS_SMALL) {
|
||||
@@ -98,11 +112,21 @@ Tool::SetStdTool( const string& sToolName, double dH, double dR, double dCornR,
|
||||
m_dTipHeight = m_dRadius ;
|
||||
m_dTipRadius = 0 ;
|
||||
m_dRCorner = m_dRadius ;
|
||||
// profilo
|
||||
Point3d pt0( 0, 0, 0) ;
|
||||
Point3d pt1( m_dRadius, 0, 0) ;
|
||||
Point3d pt2( m_dRadius, - m_dHeight + m_dTipHeight, 0) ;
|
||||
Point3d pt4( 0, - m_dHeight, 0) ;
|
||||
m_Outline.Clear() ;
|
||||
m_Outline.AddPoint( pt0) ;
|
||||
m_Outline.AddLine( pt1);
|
||||
m_Outline.AddLine( pt2);
|
||||
m_Outline.AddArcTg( pt4) ;
|
||||
}
|
||||
// impossibile
|
||||
else
|
||||
return false ;
|
||||
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -111,115 +135,140 @@ bool
|
||||
Tool::SetAdvTool( const string& sToolName, double dH, double dR,
|
||||
double dTipH, double dTipR, double dCornR, int nToolNum)
|
||||
{
|
||||
// Setto il nome
|
||||
// Impostazioni generali
|
||||
m_sName = sToolName ;
|
||||
m_nCurrentNum = nToolNum ;
|
||||
m_nType = UNDEF ;
|
||||
m_Outline.Clear() ;
|
||||
|
||||
// Verifica dimensioni globali
|
||||
if ( dH < EPS_SMALL || dR < EPS_SMALL)
|
||||
if ( dH < EPS_SMALL || dR < EPS_SMALL || dTipH < - EPS_SMALL || dTipR < - EPS_SMALL || dCornR < - EPS_SMALL)
|
||||
return false ;
|
||||
|
||||
// Se altezza punta nulla, ricado nel caso standard
|
||||
if ( dTipH < EPS_SMALL || abs( dTipR - dR) < EPS_SMALL)
|
||||
return SetStdTool( sToolName, dH, dR, dCornR, nToolNum) ;
|
||||
|
||||
// Caso avanzato
|
||||
// Caso avanzato
|
||||
m_dHeight = dH ;
|
||||
m_dRadius = dR ;
|
||||
m_dTipHeight = dTipH ;
|
||||
m_dTipHeight = min( max( dTipH, 0.), m_dHeight) ;
|
||||
m_dTipRadius = max( dTipR, 0.) ;
|
||||
|
||||
// Se raggio corner nullo, allora utensile conico
|
||||
if ( dCornR < EPS_SMALL) {
|
||||
m_nType = CONEMILL ;
|
||||
m_dRCorner = 0 ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
// Altrimenti utensile generico.
|
||||
m_dRCorner = dCornR ;
|
||||
m_Outline.Clear() ;
|
||||
|
||||
// Definisco il profilo
|
||||
Point3d pt0( 0, 0, 0) ;
|
||||
Point3d pt1( m_dRadius, 0, 0) ;
|
||||
Point3d pt2( m_dRadius, - m_dHeight + m_dTipHeight, 0) ;
|
||||
Point3d pt5( 0, - m_dHeight, 0) ;
|
||||
|
||||
if ( m_dTipRadius < m_dRadius) {
|
||||
|
||||
CurveLine LineSt ;
|
||||
LineSt.Set( pt0, pt1) ;
|
||||
|
||||
Point3d ptInt( dTipR, - dH, 0) ;
|
||||
Point3d ptLast( 0, - dH, 0) ;
|
||||
|
||||
CurveLine cLine1 ;
|
||||
cLine1.Set( pt2, ptInt) ;
|
||||
CurveLine cLine2 ;
|
||||
cLine2.Set( ptInt, ptLast) ;
|
||||
|
||||
Point3d ptIn1 = ptInt + Y_AX * dCornR ;
|
||||
Point3d ptIn2 = ptInt - X_AX * dCornR ;
|
||||
|
||||
double dTrim1, dTrim2 ;
|
||||
PtrOwner< ICurveArc> pArc( CreateFillet( cLine1, ptIn1, cLine2, ptIn2, Z_AX, dCornR, dTrim1, dTrim2)) ;
|
||||
if ( IsNull( pArc))
|
||||
return false ;
|
||||
cLine1.TrimEndAtParam( abs( dTrim1)) ;
|
||||
cLine2.TrimStartAtParam( abs( dTrim2)) ;
|
||||
|
||||
Point3d pt3, pt4 ;
|
||||
cLine1.GetEndPoint( pt3) ;
|
||||
cLine2.GetStartPoint( pt4) ;
|
||||
|
||||
Point3d ptC = pArc->GetCenter() ;
|
||||
|
||||
CurveArc cvArc ;
|
||||
cvArc.SetC2P( ptC, pt3, pt4) ;
|
||||
|
||||
m_Outline.AddCurve( LineSt) ;
|
||||
m_Outline.AddLine( pt2);
|
||||
m_Outline.AddLine( pt3);
|
||||
m_Outline.AddCurve( cvArc) ;
|
||||
m_Outline.AddLine( ptLast) ;
|
||||
// Se raggio corner nullo, allora utensile conico
|
||||
if ( m_dRCorner < EPS_SMALL) {
|
||||
m_nType = CONEMILL ;
|
||||
m_dRCorner = 0 ;
|
||||
// profilo
|
||||
m_Outline.AddPoint( pt0) ;
|
||||
m_Outline.AddLine( pt1) ;
|
||||
m_Outline.AddLine( pt2) ;
|
||||
m_Outline.AddLine( Point3d( m_dTipRadius, - m_dHeight, 0)) ;
|
||||
m_Outline.AddLine( pt5) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
else {
|
||||
// Altrimenti utensile generico
|
||||
|
||||
// se Tip a punta ( TipRadius è raggio teorico della parte finale dell'utensile senza raccordo)
|
||||
if ( m_dTipRadius < m_dRadius) {
|
||||
// se punta a sfera
|
||||
if ( m_dTipRadius < EPS_SMALL) {
|
||||
// circonferenza del corner
|
||||
Point3d ptC( 0, - m_dHeight + m_dRCorner, 0) ;
|
||||
CurveArc cvCirc ;
|
||||
cvCirc.SetXY( ptC, m_dRCorner) ;
|
||||
// segmento tangente al corner da sopra o intersezione del gambo con il corner
|
||||
Point3d pt3 ;
|
||||
Point3d ptNear( ptC.x + m_dRCorner, ptC.y + m_dRCorner, 0) ;
|
||||
PtrOwner<ICurveLine> pLine( GetLinePointTgCurve( pt2, cvCirc, ptNear)) ;
|
||||
if ( ! IsNull( pLine))
|
||||
pLine->GetEndPoint( pt3) ;
|
||||
else {
|
||||
double dSqDelta = m_dRCorner * m_dRCorner - m_dRadius * m_dRadius ;
|
||||
double dDelta = ( dSqDelta > DBL_EPSILON ? sqrt( dSqDelta) : 0.) ;
|
||||
pt2 = Point3d( m_dRadius, - m_dHeight + m_dRCorner + dDelta, 0) ;
|
||||
pt3 = pt2 ;
|
||||
}
|
||||
// creazione del corner
|
||||
Point3d pt4( 0, - m_dHeight, 0) ;
|
||||
CurveArc cvArc ;
|
||||
cvArc.SetC2P( ptC, pt3, pt4) ;
|
||||
// creazione curva composita
|
||||
m_Outline.AddPoint( pt0) ;
|
||||
m_Outline.AddLine( pt1) ;
|
||||
m_Outline.AddLine( pt2) ;
|
||||
m_Outline.AddLine( pt3) ;
|
||||
m_Outline.AddCurve( cvArc) ;
|
||||
m_Outline.AddLine( pt5) ;
|
||||
}
|
||||
// altrimenti punta a naso di toro
|
||||
else {
|
||||
// punto da smussare con corner
|
||||
Point3d ptInt( m_dTipRadius, - m_dHeight, 0) ;
|
||||
// linea sopra il corner
|
||||
CurveLine cLine1 ;
|
||||
cLine1.Set( pt2, ptInt) ;
|
||||
// linea sotto il corner
|
||||
CurveLine cLine2 ;
|
||||
cLine2.Set( ptInt, pt5) ;
|
||||
// calcolo del corner
|
||||
Point3d ptIn1 = Media( pt2, ptInt, 0.5) ;
|
||||
Point3d ptIn2 = Media( ptInt, pt5, 0.5) ;
|
||||
double dTrim1, dTrim2 ;
|
||||
PtrOwner< ICurveArc> pArc( CreateFillet( cLine1, ptIn1, cLine2, ptIn2, Z_AX, m_dRCorner, dTrim1, dTrim2)) ;
|
||||
if ( IsNull( pArc))
|
||||
return false ;
|
||||
Point3d pt3 ;
|
||||
pArc->GetStartPoint( pt3) ;
|
||||
// creazione curva composita
|
||||
m_Outline.AddPoint( pt0) ;
|
||||
m_Outline.AddLine( pt1) ;
|
||||
m_Outline.AddLine( pt2) ;
|
||||
m_Outline.AddLine( pt3) ;
|
||||
m_Outline.AddCurve( Release( pArc)) ;
|
||||
m_Outline.AddLine( pt5) ;
|
||||
}
|
||||
}
|
||||
|
||||
// altrimenti Tip a coda di rondine ( TipRadius è raggio misurabile della parte finale dell'utensile)
|
||||
else {
|
||||
// il raggio della punta non può essere inferiore al raggio corner
|
||||
if ( m_dTipRadius < m_dRCorner)
|
||||
return false ;
|
||||
|
||||
CurveLine LineSt ;
|
||||
LineSt.Set( pt0, pt1) ;
|
||||
|
||||
Point3d ptC( dTipR - dCornR, - dH + dCornR, 0) ;
|
||||
|
||||
// circonferenza del corner
|
||||
Point3d ptC( m_dTipRadius - m_dRCorner, - m_dHeight + m_dRCorner, 0) ;
|
||||
CurveArc cvCirc ;
|
||||
cvCirc.SetXY( ptC, dCornR) ;
|
||||
|
||||
Point3d ptNear( ptC.x + dCornR, ptC.y + dCornR, 0) ;
|
||||
cvCirc.SetXY( ptC, m_dRCorner) ;
|
||||
// segmento tangente al corner da sopra
|
||||
Point3d ptNear( ptC.x + m_dRCorner, ptC.y + m_dRCorner, 0) ;
|
||||
PtrOwner<ICurveLine> pLine( GetLinePointTgCurve( pt2, cvCirc, ptNear)) ;
|
||||
if ( IsNull( pLine))
|
||||
return false ;
|
||||
|
||||
// creazione del corner
|
||||
Point3d pt3 ;
|
||||
pLine->GetEndPoint( pt3) ;
|
||||
|
||||
Point3d pt4( ptC.x, - dH, 0) ;
|
||||
|
||||
Point3d pt4( ptC.x, - m_dHeight, 0) ;
|
||||
CurveArc cvArc ;
|
||||
cvArc.SetC2P( ptC, pt3, pt4) ;
|
||||
|
||||
Point3d pt5( 0, - dH, 0) ;
|
||||
|
||||
m_Outline.AddCurve( LineSt) ;
|
||||
m_Outline.AddLine( pt2);
|
||||
m_Outline.AddLine( pt3);
|
||||
if ( cvArc.GetAngCenter() > 0)
|
||||
cvArc.ToExplementary() ;
|
||||
// creazione curva composita
|
||||
m_Outline.AddPoint( pt0) ;
|
||||
m_Outline.AddLine( pt1) ;
|
||||
m_Outline.AddLine( pt2) ;
|
||||
m_Outline.AddLine( pt3) ;
|
||||
m_Outline.AddCurve( cvArc) ;
|
||||
m_Outline.AddLine( pt5) ;
|
||||
}
|
||||
|
||||
|
||||
return SetGenTool( sToolName, &m_Outline, nToolNum) ;
|
||||
}
|
||||
|
||||
@@ -227,10 +276,12 @@ Tool::SetAdvTool( const string& sToolName, double dH, double dR,
|
||||
bool
|
||||
Tool::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutline, int nToolNum)
|
||||
{
|
||||
// Assegno nome, tipo e id dell'utensile
|
||||
// Impostazioni generali
|
||||
m_sName = sToolName ;
|
||||
m_nType = UNDEF ;
|
||||
m_nCurrentNum = nToolNum ;
|
||||
if ( pToolOutline != &m_Outline)
|
||||
m_Outline.Clear() ;
|
||||
|
||||
// Copio il profilo e garantisco sia di soli archi e rette (converto eventuali curve di Bezier)
|
||||
if ( ! m_Outline.CopyFrom( pToolOutline) ||
|
||||
@@ -244,8 +295,9 @@ Tool::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutline,
|
||||
const ICurve* pCurve = m_Outline.GetFirstCurve() ;
|
||||
while ( pCurve != nullptr) {
|
||||
|
||||
// Se la curva è un arco verifico se approssimarlo
|
||||
if ( pCurve->GetType() == CRV_ARC) {
|
||||
// Se la curva è un arco ed è richiesto la verifica per l'approssimazione,
|
||||
// verifico se approssimarlo
|
||||
if ( m_bApproxWithLines && pCurve->GetType() == CRV_ARC) {
|
||||
|
||||
// Centro e raggio dell'arco
|
||||
Point3d ptO = GetBasicCurveArc( pCurve)->GetCenter() ;
|
||||
@@ -269,7 +321,7 @@ Tool::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutline,
|
||||
if ( bCurrApprox) {
|
||||
// Creo la polyline approssimante
|
||||
PolyLine plyApprox ;
|
||||
if ( ! pCurve->ApproxWithLines( m_dLinTol, m_dAngTolDeg, ICurve::APL_SPECIAL, plyApprox))
|
||||
if ( ! pCurve->ApproxWithLines( m_dLinTol, m_dAngTolDeg, ICurve::APL_SPECIAL, plyApprox))
|
||||
return false ;
|
||||
// Aggiungo i segmenti di retta alla approssimazione
|
||||
Point3d ptEnd ;
|
||||
@@ -284,7 +336,7 @@ Tool::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutline,
|
||||
m_ArcLineApprox.AddCurve( *pCurve, true) ;
|
||||
}
|
||||
// altrimenti è segmento e lo aggiungo semplicemente
|
||||
else
|
||||
else
|
||||
m_ArcLineApprox.AddCurve( *pCurve, true) ;
|
||||
|
||||
pCurve = m_Outline.GetNextCurve() ;
|
||||
@@ -297,27 +349,28 @@ Tool::SetGenTool( const string& sToolName, const ICurveComposite* pToolOutline,
|
||||
m_nType = GEN ;
|
||||
|
||||
// Il profilo dell'utensile deve stare nel 4° quadrante del piano XY
|
||||
BBox3d Bounding ;
|
||||
m_Outline.GetLocalBBox( Bounding) ;
|
||||
BBox3d Bounding ;
|
||||
m_Outline.GetLocalBBox( Bounding) ;
|
||||
if ( Bounding.GetMin().x < - 10 * EPS_SMALL || Bounding.GetMax().y > 10 * EPS_SMALL)
|
||||
return false ;
|
||||
// Assegno le dimensioni dell'utensile
|
||||
m_dHeight = - Bounding.GetMin().y ;
|
||||
m_dRadius = Bounding.GetMax().x ;
|
||||
m_dHeight = - Bounding.GetMin().y ;
|
||||
m_dRadius = Bounding.GetMax().x ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Tool::SetMortiserTool( const std::string& sToolName, double dH, double dW, double dTh, double dRc, int nToolNum)
|
||||
Tool::SetMortiserTool( const string& sToolName, double dH, double dW, double dTh, double dRc, int nToolNum)
|
||||
{
|
||||
// Setto il nome e il numero dell'utensile
|
||||
// Impostazioni generali
|
||||
m_sName = sToolName ;
|
||||
m_nCurrentNum = nToolNum ;
|
||||
// Imposto a indefinito il tipo
|
||||
m_nType = UNDEF ;
|
||||
m_Outline.Clear() ;
|
||||
|
||||
// Verifica dimensioni globali
|
||||
if ( dH < EPS_SMALL || dW < EPS_SMALL ||
|
||||
dTh < EPS_SMALL || dRc < 0 || dW - 2 * dRc < 0)
|
||||
return false ;
|
||||
@@ -337,13 +390,13 @@ Tool::SetMortiserTool( const std::string& sToolName, double dH, double dW, doubl
|
||||
bool
|
||||
Tool::SetChiselTool( const string& sToolName, double dH, double dW, double dTh, int nToolNum)
|
||||
{
|
||||
|
||||
// Setto il nome e il numero dell'utensile
|
||||
// Impostazioni generali
|
||||
m_sName = sToolName ;
|
||||
m_nCurrentNum = nToolNum ;
|
||||
// Imposto a indefinito il tipo
|
||||
m_nType = UNDEF ;
|
||||
m_Outline.Clear() ;
|
||||
|
||||
// Verifica dimensioni globali
|
||||
if ( dH < EPS_SMALL || dW < EPS_SMALL || dTh < 0)
|
||||
return false ;
|
||||
|
||||
@@ -353,6 +406,6 @@ Tool::SetChiselTool( const string& sToolName, double dH, double dW, double dTh,
|
||||
|
||||
// Imposto il tipo
|
||||
m_nType = CHISEL ;
|
||||
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user