diff --git a/EXE_NstAutoNesting.cpp b/EXE_NstAutoNesting.cpp index 3a9ab4c..81db9f2 100644 --- a/EXE_NstAutoNesting.cpp +++ b/EXE_NstAutoNesting.cpp @@ -48,6 +48,43 @@ ExeAutoNestStart( void) return s_pAutoNester->Start() ; } +//----------------------------------------------------------------------------- +static bool +MyGetOutline( IGeomDB* pGeomDB, int nOutlineId, PolyArc& Outline) +{ + // recupero riferimento dell'Outline + Frame3d frOutl ; + if ( ! pGeomDB->GetGlobFrame( nOutlineId, frOutl)) + return false ; + // recupero il tipo di oggetto + int nType = pGeomDB->GetGeoType( nOutlineId) ; + // recupero la curva di contorno + if ( ( nType & GEO_CURVE) != 0) { + const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nOutlineId)) ; + if ( pCrv == nullptr || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) + return false ; + } + else if ( nType == SRF_FLATRGN) { + const ISurfFlatRegion* pSfr = GetSurfFlatRegion( pGeomDB->GetGeoObj( nOutlineId)) ; + if ( pSfr == nullptr) + return false ; + PtrOwner pCrv( pSfr->GetLoop( 0, 0)) ; + if ( IsNull( pCrv) || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) + return false ; + } + // la porto in globale + Outline.ToGlob( frOutl) ; + // verifico direzione di estrusione + Vector3d vtExtr = Outline.GetExtrusion() ; + if ( vtExtr.IsZplus()) + ; + else if ( vtExtr.IsZminus()) + Outline.Mirror( ORIG, Z_AX) ; + else + return false ; + return true ; +} + //----------------------------------------------------------------------------- bool ExeAutoNestAddSheet( int nSheetId, int nOutlineId, double dKerf, int nPriority, int nCount) @@ -56,101 +93,33 @@ ExeAutoNestAddSheet( int nSheetId, int nOutlineId, double dKerf, int nPriority, return false ; IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) - // recupero riferimento dell'Outline - Frame3d frOutl ; - if ( ! pGeomDB->GetGlobFrame( nOutlineId, frOutl)) - return false ; - // recupero il tipo di oggetto - int nType = pGeomDB->GetGeoType( nOutlineId) ; + // recupero il contorno PolyArc Outline ; - // recupero la curva di contorno - if ( ( nType & GEO_CURVE) != 0) { - const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nOutlineId)) ; - if ( pCrv == nullptr || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) - return false ; - } - else if ( nType == SRF_FLATRGN) { - const ISurfFlatRegion* pSfr = GetSurfFlatRegion( pGeomDB->GetGeoObj( nOutlineId)) ; - if ( pSfr == nullptr) - return false ; - PtrOwner pCrv( pSfr->GetLoop( 0, 0)) ; - if ( IsNull( pCrv) || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) - return false ; - } - // la porto in globale - Outline.ToGlob( frOutl) ; - // verifico direzione di estrusione - Vector3d vtExtr = Outline.GetExtrusion() ; - if ( vtExtr.IsZplus()) - ; - else if ( vtExtr.IsZminus()) - Outline.Mirror( ORIG, Z_AX) ; - else + if ( ! MyGetOutline( pGeomDB, nOutlineId, Outline)) return false ; - // se richiesto kerf ( sempre nullo o positivo) - if ( dKerf > 10 * EPS_SMALL) { - // curva di contorno - PtrOwner pCompo( CreateCurveComposite()) ; - if ( IsNull( pCompo) || ! pCompo->FromPolyArc( Outline)) - return false ; - // verifico sia CCW - double dArea ; pCompo->GetAreaXY( dArea) ; - if ( dArea < 0) - pCompo->Invert() ; - // eseguo offset - OffsetCurve OffsCrv ; - if ( ! OffsCrv.Make( pCompo, - dKerf, ICurve::OFF_FILLET)) - return false ; - PtrOwner pOffs( OffsCrv.GetLongerCurve()) ; - // riassegno a PolyArc - if ( IsNull( pOffs) || ! pOffs->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) - return false ; - } // aggiungo il pannello - return s_pAutoNester->AddSheet( nSheetId, Outline, nPriority, nCount) ; + return s_pAutoNester->AddSheet( nSheetId, Outline, dKerf, nPriority, nCount) ; } //----------------------------------------------------------------------------- bool -ExeAutoNestAddPart( int nPartId, int nOutlineId, bool bCanFlip, bool bCanRotate, int nPriority, int nCount) +ExeAutoNestAddPart( int nPartId, int nOutlineId, int nToolOutlineId, + bool bCanFlip, bool bCanRotate, double dRotStep, int nPriority, int nCount) { if ( IsNull( s_pAutoNester)) return false ; IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) - // recupero riferimento dell'Outline - Frame3d frOutl ; - if ( ! pGeomDB->GetGlobFrame( nOutlineId, frOutl)) - return false ; - // recupero il tipo di oggetto - int nType = pGeomDB->GetGeoType( nOutlineId) ; + // recupero il contorno PolyArc Outline ; - // recupero la curva di contorno - if ( ( nType & GEO_CURVE) != 0) { - const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nOutlineId)) ; - if ( pCrv == nullptr || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) - return false ; - } - else if ( nType == SRF_FLATRGN) { - const ISurfFlatRegion* pSfr = GetSurfFlatRegion( pGeomDB->GetGeoObj( nOutlineId)) ; - if ( pSfr == nullptr) - return false ; - PtrOwner pCrv( pSfr->GetLoop( 0, 0)) ; - if ( IsNull( pCrv) || ! pCrv->ApproxWithArcs( LIN_TOL_FINE, ANG_TOL_STD_DEG, Outline)) - return false ; - } - // la porto in globale - Outline.ToGlob( frOutl) ; - // verifico direzione di estrusione - Vector3d vtExtr = Outline.GetExtrusion() ; - if ( vtExtr.IsZplus()) - ; - else if ( vtExtr.IsZminus()) - Outline.Mirror( ORIG, Z_AX) ; - else + if ( ! MyGetOutline( pGeomDB, nOutlineId, Outline)) + return false ; + // recupero evntuale contorno della lavorazione + PolyArc ToolOutline ; + if ( nToolOutlineId != GDB_ID_NULL && ! MyGetOutline( pGeomDB, nToolOutlineId, ToolOutline)) return false ; // aggiungo il pezzo - if ( ! s_pAutoNester->AddPart( nPartId, Outline, bCanFlip, bCanRotate, nPriority, nCount)) + if ( ! s_pAutoNester->AddPart( nPartId, Outline, ToolOutline, bCanFlip, bCanRotate, dRotStep, nPriority, nCount)) return false ; // incremento contatore pezzi s_nTotParts += nCount ; diff --git a/LUA_Nesting.cpp b/LUA_Nesting.cpp index 5ec0647..12ca828 100644 --- a/LUA_Nesting.cpp +++ b/LUA_Nesting.cpp @@ -131,22 +131,26 @@ LuaAutoNestAddSheet( lua_State* L) static int LuaAutoNestAddPart( lua_State* L) { - // 6 parametri : nPartId, nOutlineId, bCanFlip, bCanRotate, nPriority, nCount + // 7 parametri : nPartId, nOutlineId, nToolOutlineId, bCanFlip, bCanRotate, dRotStep, nPriority, nCount int nPartId ; LuaCheckParam( L, 1, nPartId) int nOutlineId ; LuaCheckParam( L, 2, nOutlineId) + int nToolOutlineId ; + LuaCheckParam( L, 3, nToolOutlineId) bool bCanFlip ; - LuaCheckParam( L, 3, bCanFlip) + LuaCheckParam( L, 4, bCanFlip) bool bCanRotate ; - LuaCheckParam( L, 4, bCanRotate) + LuaCheckParam( L, 5, bCanRotate) + double dRotStep ; + LuaCheckParam( L, 6, dRotStep) int nPriority ; - LuaCheckParam( L, 5, nPriority) + LuaCheckParam( L, 7, nPriority) int nCount ; - LuaCheckParam( L, 6, nCount) + LuaCheckParam( L, 8, nCount) LuaClearStack( L) ; // aggiungo un pezzo al nesting corrente - bool bOk = ExeAutoNestAddPart( nPartId, nOutlineId, bCanFlip, bCanRotate, nPriority, nCount) ; + bool bOk = ExeAutoNestAddPart( nPartId, nOutlineId, nToolOutlineId, bCanFlip, bCanRotate, dRotStep, nPriority, nCount) ; // restituisco il risultato LuaSetParam( L, bOk) ; return 1 ;