diff --git a/EXE_Const.h b/EXE_Const.h index 241183f..1b5fcdd 100644 --- a/EXE_Const.h +++ b/EXE_Const.h @@ -1,8 +1,8 @@ //---------------------------------------------------------------------------- // EgalTech 2014-2015 //---------------------------------------------------------------------------- -// File : EXE.h Data : 05.05.15 Versione : 1.6e2 -// Contenuto : Dichiarazioni locali per moduli EXE. +// File : EXE_Const.h Data : 05.05.15 Versione : 1.6e2 +// Contenuto : Costanti locali per moduli EXE. // // // @@ -16,8 +16,16 @@ #include //---------------------------------------------------------------------------- +// Costanti per tolleranze di appossimazione +const double LIN_TOL_STD = 0.1 ; +const double LIN_TOL_FINE = 0.01 ; +const double LIN_FEA_STD = 20 ; +const double ANG_TOL_STD_DEG = 15 ; +const double ANG_TOL_MAX_DEG = 90 ; + // Curve originali di composite o curva originale di area danneggiata const std::string CRV_ORIG = "ORIG" ; + // Per FlatParts (Nesting) const std::string NST_PARTREG_LAYER = "Region" ; const std::string NST_PARTDOWNREG_LAYER = "DwnReg" ; @@ -26,6 +34,7 @@ const std::string NST_EXT_ORIG_LAYER = "OutLoop.orig" ; const std::string NST_IN_LAYER = "InLoop" ; const std::string NST_ON_LAYER = "OnPath" ; const std::string NST_KEY_SIDEANG = "SideAng" ; + // Per Sheets (Nesting) const std::string NST_SHEET_OUTREG = "SheetOut" ; const std::string NST_DAMAGED_REG = "DmgReg" ; diff --git a/EXE_GdbCreateCurve.cpp b/EXE_GdbCreateCurve.cpp index 2b9b9c1..c5d69a5 100644 --- a/EXE_GdbCreateCurve.cpp +++ b/EXE_GdbCreateCurve.cpp @@ -1671,7 +1671,7 @@ MyCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds, if ( IsNull( pCrvCompo)) return GDB_ID_NULL ; // estrusione e spessore - Vector3d vtExtr = CalcExtrusion( pGeomDB, nParentId, nRefType) ; + Vector3d vtExtr ; double dThick = 0 ; // vettore con elenco Id curve originali INTVECTOR vOrig ; @@ -1699,7 +1699,8 @@ MyCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds, // recupero eventuali estrusione (già nel riferimento destinazione) e spessore Vector3d vtTemp ; if ( pCopCrv->GetExtrusion( vtTemp)) { - vtExtr = vtTemp ; + if ( vtExtr.IsSmall()) + vtExtr = vtTemp ; double dTemp ; if ( pCopCrv->GetThickness( dTemp) && fabs( dTemp) > fabs( dThick)) dThick = dTemp ; @@ -1721,6 +1722,8 @@ MyCreateCurveCompoByChain( int nParentId, const INTVECTOR& vIds, pCrvCompo->ModifyEnd( ptStart) ; } // imposto estrusione e spessore + if ( vtExtr.IsSmall()) + vtExtr = CalcExtrusion( pGeomDB, nParentId, nRefType) ; pCrvCompo->SetExtrusion( vtExtr) ; pCrvCompo->SetThickness( dThick) ; // aggiorno il nuovo punto vicino @@ -1875,8 +1878,6 @@ ExeCreateCurveCompoByApproximation( int nParentId, const PolyLine& PL, int nType Frame3d frDest ; bOk = bOk && pGeomDB->GetGroupGlobFrame( nParentId, frDest) ; // eseguo approssimazione - const double ANG_TOL_STD_DEG = 15 ; - const double LIN_FEA_STD = 20 ; CurveByApprox crvByApprox ; Point3d ptP ; for ( bool bFound = PL.GetFirstPoint( ptP) ; diff --git a/EXE_GdbModifyCurve.cpp b/EXE_GdbModifyCurve.cpp index 37ccf92..a7d4ecd 100644 --- a/EXE_GdbModifyCurve.cpp +++ b/EXE_GdbModifyCurve.cpp @@ -14,6 +14,7 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" +#include "EXE_Const.h" #include "EXE_Macro.h" #include "AuxTools.h" #include "GeoTools.h" @@ -149,9 +150,6 @@ ExeApproxCurve( int nId, int nApprType, double dLinTol) ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; bool bOk = ( pCurve != nullptr) ; // eseguo l'approssimazione - const double ANG_TOL_MAX_DEG = 90 ; - const double ANG_TOL_STD_DEG = 15 ; - const double LIN_FEA_LEN_STD = 20 ; PtrOwner pCC( CreateCurveComposite()) ; bOk = bOk && ! IsNull( pCC) ; if ( nApprType == APP_LINES || nApprType == APP_SPECIAL_LINES || @@ -162,7 +160,7 @@ ExeApproxCurve( int nId, int nApprType, double dLinTol) } else { // con bi-archi PolyArc PA ; - bOk = bOk && pCurve->ApproxWithArcsEx( dLinTol, ANG_TOL_STD_DEG, LIN_FEA_LEN_STD, PA) && pCC->FromPolyArc( PA) ; + bOk = bOk && pCurve->ApproxWithArcsEx( dLinTol, ANG_TOL_STD_DEG, LIN_FEA_STD, PA) && pCC->FromPolyArc( PA) ; // merge di archi identici di biarchi bOk = bOk && pCC->MergeCurves( 0.5 * dLinTol, ANG_TOL_STD_DEG) ; } @@ -1018,6 +1016,60 @@ ExeSplitCurveAtSelfInters( int nId, int* pnCount) return nFirstId ; } +//---------------------------------------------------------------------------- +int +ExeGetCurveLinearConvexHullXY( int nId, double dLinTol, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pCurve != nullptr) ; + // recupero il riferimento della curva + Frame3d frCrv ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frCrv) ; + // derivo la polilinea di approssimazione della curva entro la tolleranza data + PolyLine PL ; + bOk = bOk && pCurve->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, APP_LINES, PL) ; + // eventuale trasformazione per riferimento di espressione + if ( bOk && nRefType == RTY_GLOB) + PL.ToGlob( frCrv) ; + else if ( bOk && nRefType == RTY_GRID) + PL.LocToLoc( frCrv, pGeomDB->GetGridFrame()) ; + // derivo il convex hull lineare di questa + PNTVECTOR vCH ; + bOk = bOk && PL.GetConvexHullXY( vCH) ; + PolyLine PLCH ; + for ( size_t i = 0 ; i < vCH.size() ; ++ i) + PLCH.AddUPoint( double( i), vCH[i]) ; + PLCH.Close() ; + // creo la curva composita + PtrOwner pCrvCompo( CreateCurveComposite()) ; + bOk = bOk && ! IsNull( pCrvCompo) ; + // inserisco i segmenti che uniscono i punti + bOk = bOk && pCrvCompo->FromPolyLine( PLCH) ; + // assegno il versore estrusione + bOk = bOk && pCrvCompo->SetExtrusion( Z_AX) ; + // eventuale trasformazione per riferimento di espressione + if ( bOk && nRefType == RTY_GLOB) + pCrvCompo->ToLoc( frCrv) ; + else if ( bOk && nRefType == RTY_GRID) + pCrvCompo->LocToLoc( pGeomDB->GetGridFrame(), frCrv) ; + // inserisco la curva composita nel DB + int nNewId = ( bOk ? pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_AFTER, Release( pCrvCompo)) : GDB_ID_NULL) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtGetCurveLinearConvexHullXY(" + IdToString( nId) + "," + + ToString( dLinTol) + "," + + RefTypeToString( nRefType) + ")" + + " -- Id=" + ToString( nNewId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco l'identificativo della nuova entità + return nNewId ; +} + //------------------------------------------------------------------------------- bool ExeModifyCircleCP( int nId, const Point3d& ptOn, int nRefType) @@ -1421,7 +1473,6 @@ ExeMergeCurvesInCurveCompo( int nId, double dLinTol, bool bStartEnd) ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ; bool bOk = ( pCompo != nullptr) ; // lancio il merge delle curve componenti - const double ANG_TOL_STD_DEG = 15 ; bOk = bOk && pCompo->MergeCurves( dLinTol, ANG_TOL_STD_DEG, bStartEnd) ; ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente @@ -1445,7 +1496,6 @@ ExeRemoveCurveCompoUndercutOnY( int nId, double dLinTol) ICurveComposite* pCompo = GetCurveComposite( pGeomDB->GetGeoObj( nId)) ; bool bOk = ( pCompo != nullptr) ; // lancio l'eliminazione delle parti sotto rispetto alla direzione Y+ - const double ANG_TOL_STD_DEG = 15 ; bOk = bOk && pCompo->RemoveUndercutOnY( dLinTol, ANG_TOL_STD_DEG) ; ExeSetModified() ; // se richiesto, salvo il comando Lua equivalente diff --git a/EXE_GeoSnap.cpp b/EXE_GeoSnap.cpp index a022dd9..7103ad5 100644 --- a/EXE_GeoSnap.cpp +++ b/EXE_GeoSnap.cpp @@ -14,6 +14,7 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" +#include "EXE_Const.h" #include "EXE_Macro.h" #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" @@ -681,17 +682,57 @@ ExeCurveSelfIntersCount( int nId, int* pnCount) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) + // verifico il parametro + if ( pnCount == nullptr) + return false ; // recupero la curva ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; - bool bOk = ( pCurve != nullptr) ; + if ( pCurve == nullptr) + return false ; // calcolo le auto-intersezioni SelfIntersCurve sintC( *pCurve) ; // ne recupero il numero - if ( pnCount != nullptr) - *pnCount = sintC.GetIntersCount() ; + *pnCount = sintC.GetIntersCount() ; return true ; } +//---------------------------------------------------------------------------- +bool +ExeCurveMinAreaRectangleXY( int nId, int nRefId, Frame3d& frRect, double& dDimX, double& dDimY) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la curva + ICurve* pCurve = GetCurve( pGeomDB->GetGeoObj( nId)) ; + bool bOk = ( pCurve != nullptr) ; + // recupero il riferimento della curva + Frame3d frCrv ; + bOk = bOk && pGeomDB->GetGlobFrame( nId, frCrv) ; + // derivo la polilinea di approssimazione della curva entro la tolleranza standard + PolyLine PL ; + bOk = bOk && pCurve->ApproxWithLines( LIN_TOL_FINE, ANG_TOL_STD_DEG, APP_LINES, PL) ; + // eventuale trasformazione per riferimento di espressione + if ( bOk && nRefId == GDB_ID_ROOT) + PL.ToGlob( frCrv) ; + else if ( bOk && nRefId == GDB_ID_GRID) + PL.LocToLoc( frCrv, pGeomDB->GetGridFrame()) ; + else if ( bOk && nRefId != nId) { + Frame3d frDest ; + // nRefId può essere un gruppo o una entità + if ( pGeomDB->GetGroupGlobFrame( nRefId, frDest) || + pGeomDB->GetGlobFrame( nRefId, frDest)) + PL.LocToLoc( frCrv, frDest) ; + else + bOk = false ; + } + // derivo il rettangolo in XY di area minima di questa + Point3d ptCen ; + Vector3d vtAx ; + bOk = bOk && PL.GetMinAreaRectangleXY( ptCen, vtAx, dDimX, dDimY) && + frRect.Set( ptCen, Z_AX, vtAx) ; + return bOk ; +} + //---------------------------------------------------------------------------- int ExeClosedCurveClassify( int nId1, int nId2) @@ -921,7 +962,8 @@ ExeSurfFrChunkSimpleClassify( int nId1, int nChunk1, int nId2, int nChunk2) pSfr2L = pTmp ; } // classifico il chunk della prima regione rispetto a quello della seconda - return pSfr1->GetChunkSimpleClassification( nChunk1, *pSfr2L, nChunk2) ; + int nRes = ( bOk ? pSfr1->GetChunkSimpleClassification( nChunk1, *pSfr2L, nChunk2) : REGC_NULL) ; + return nRes ; } //---------------------------------------------------------------------------- diff --git a/EXE_NstCreateFlatParts.cpp b/EXE_NstCreateFlatParts.cpp index 25e73c0..cb74b29 100644 --- a/EXE_NstCreateFlatParts.cpp +++ b/EXE_NstCreateFlatParts.cpp @@ -35,9 +35,6 @@ using namespace std ; static bool ApproxCurveIfNeeded( IGdbIterator* pEnt) { - const double LIN_TOL_STD = 0.25 ; - const double ANG_TOL_STD_DEG = 15 ; - const double LIN_FEA_STD = 20 ; // deve essere una curva int nGeoType = pEnt->GetGeoType() ; if ( (nGeoType & GEO_CURVE) == 0) @@ -464,7 +461,7 @@ VerifyAndAdjustFlatParts( void) bOk = bOk && nNewId != GDB_ID_NULL ; // assegno il colore Color cCol = AQUA ; - cCol.SetAlpha( 0.2) ; + cCol.SetAlpha( 0.25) ; bOk = bOk && pGeomDB->SetMaterial( nNewId, cCol) ; // scrittura delle dimensioni nel layer della regione if ( bOk) { @@ -948,7 +945,7 @@ ExeCalcFlatPartDownRegion( int nPartId, double dH) return false ; // assegno il colore Color cCol = AQUA ; - cCol.SetAlpha( 0.2) ; + cCol.SetAlpha( 0.25) ; pGeomDB->SetMaterial( nSfrId, cCol) ; return true ; diff --git a/EXE_NstMachining.cpp b/EXE_NstMachining.cpp index 1f24599..9f6c421 100644 --- a/EXE_NstMachining.cpp +++ b/EXE_NstMachining.cpp @@ -167,7 +167,7 @@ ExeVerifyMachining( int nMchId, int& nResult) int nMchRegId = ( ( vMchDwnRReg[i] != GDB_ID_NULL) ? vMchDwnRReg[i] : vMchRReg[i]) ; int nOthRegId = ( ( vOthDwnReg[j] != GDB_ID_NULL) ? vOthDwnReg[j] : vOthReg[j]) ; if ( ExeSurfFrChunkSimpleClassify( nMchRegId, 0, nOthRegId, 0) != REGC_OUT) - nResult |= FMI_LO ; + nResult |= FMI_RM ; } } } diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 127789b..eb58aab 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/GeoTools.cpp b/GeoTools.cpp index 68b5267..1b1a7d7 100644 --- a/GeoTools.cpp +++ b/GeoTools.cpp @@ -80,7 +80,7 @@ TrasformPoint( IGeomDB* pGeomDB, int nId, int nRefId, Point3d& ptP) // nRefId può essere un gruppo o una entità if ( ! pGeomDB->GetGroupGlobFrame( nRefId, frDest) && ! pGeomDB->GetGlobFrame( nRefId, frDest)) - return false ; + return false ; } // eseguo la trasformazione return ptP.LocToLoc( frSou, frDest) ; diff --git a/LUA_GdbCreateCurve.cpp b/LUA_GdbCreateCurve.cpp index 6a197a3..3f25a6d 100644 --- a/LUA_GdbCreateCurve.cpp +++ b/LUA_GdbCreateCurve.cpp @@ -770,9 +770,9 @@ LuaCreateCurveCompoByApproximation( lua_State* L) PNTVECTOR vPnt ; LuaCheckParam( L, 2, vPnt) int nType ; - LuaGetParam( L, 3, nType) ; + LuaCheckParam( L, 3, nType) double dLinTol ; - LuaGetParam( L, 4, dLinTol) ; + LuaCheckParam( L, 4, dLinTol) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 5, nRefType) ; LuaClearStack( L) ; @@ -805,7 +805,7 @@ LuaCreateCurveCompoFromPoints( lua_State* L) PolyLine PL ; // creo una polilinea a partire dai punti for ( size_t i = 0 ; i < vPnt.size() ; ++ i) - PL.AddUPoint( 0, vPnt[i]) ; + PL.AddUPoint( double( i), vPnt[i]) ; // creo la curva composita int nId = ExeCreateCurveCompoFromPoints( nParentId, PL, nRefType) ; // restituisco il risultato @@ -831,7 +831,7 @@ LuaCreateCurveCompoFromPointBulges( lua_State* L) // creo un poliarco a partire dai punti con bulge PolyArc PA ; for ( size_t i = 0 ; i < vPntB.size() ; ++ i) - PA.AddUPoint( 0, vPntB[i].first, vPntB[i].second) ; + PA.AddUPoint( double( i), vPntB[i].first, vPntB[i].second) ; // creo la curva composita int nId = ExeCreateCurveCompoFromPointBulges( nParentId, PA, nRefType) ; // restituisco il risultato diff --git a/LUA_GdbModifyCurve.cpp b/LUA_GdbModifyCurve.cpp index de5bc87..b818cf3 100644 --- a/LUA_GdbModifyCurve.cpp +++ b/LUA_GdbModifyCurve.cpp @@ -13,6 +13,7 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" +#include "EXE_Const.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" @@ -434,6 +435,27 @@ LuaSplitCurveAtSelfInters( lua_State* L) return 2 ; } +//---------------------------------------------------------------------------- +static int +LuaGetCurveLinearConvexHullXY( lua_State* L) +{ + // 1 o 2 o 3 parametri : Id, [dLinTol [, nRefType]] + int nId ; + LuaCheckParam( L, 1, nId) + double dLinTol = LIN_TOL_STD ; + LuaGetParam( L, 2, dLinTol) ; + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 3, nRefType) ; + LuaClearStack( L) ; + // calcolo il convex hull nel piano XY del riferimento indicato + int nNewId = ExeGetCurveLinearConvexHullXY( nId, dLinTol, nRefType) ; + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaModifyArcRadius( lua_State* L) @@ -718,6 +740,7 @@ LuaInstallGdbModifyCurve( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtParam", LuaSplitCurveAtParam) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtCorners", LuaSplitCurveAtCorners) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSplitCurveAtSelfInters", LuaSplitCurveAtSelfInters) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCurveLinearConvexHullXY", LuaGetCurveLinearConvexHullXY) ; bOk = bOk && luaMgr.RegisterFunction( "EgtModifyArcRadius", LuaModifyArcRadius) ; bOk = bOk && luaMgr.RegisterFunction( "EgtModifyArcToExplementary", LuaModifyArcToExplementary) ; bOk = bOk && luaMgr.RegisterFunction( "EgtModifyArcByFlip", LuaModifyArcByFlip) ; diff --git a/LUA_GeoSnap.cpp b/LUA_GeoSnap.cpp index aa82bc9..bd36d02 100644 --- a/LUA_GeoSnap.cpp +++ b/LUA_GeoSnap.cpp @@ -463,6 +463,33 @@ LuaCurveSelfIntersCount( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaCurveMinAreaRectangleXY( lua_State* L) +{ + // 1 o 2 parametri : Id [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nRefId = nId ; + LuaGetParam( L, 2, nRefId) ; + LuaClearStack( L) ; + // recupero i dati del rettangolo + Frame3d frRect ; + double dDimX ; + double dDimY ; + bool bOk = ExeCurveMinAreaRectangleXY( nId, nRefId, frRect, dDimX, dDimY) ; + if ( bOk) { + LuaSetParam( L, frRect) ; + LuaSetParam( L, dDimX) ; + LuaSetParam( L, dDimY) ; + return 3 ; + } + else { + LuaSetParam( L) ; + return 1 ; + } +} + //---------------------------------------------------------------------------- static int LuaArcRadius( lua_State* L) @@ -771,6 +798,7 @@ LuaInstallGeoSnap( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtCurveExtrusion", LuaCurveExtrusion) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveThickness", LuaCurveThickness) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCurveSelfIntersCount", LuaCurveSelfIntersCount) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveMinAreaRectangleXY", LuaCurveMinAreaRectangleXY) ; bOk = bOk && luaMgr.RegisterFunction( "EgtArcRadius", LuaArcRadius) ; bOk = bOk && luaMgr.RegisterFunction( "EgtArcAngCenter", LuaArcAngCenter) ; bOk = bOk && luaMgr.RegisterFunction( "EgtArcDeltaN", LuaArcDeltaN) ;