dbda122216
- aggiunta funzione Exe e Lua AutoNestAddHoleToPart - corretto nome funzione ExeAddAnotherOutlineToPart in ExeAutoNestAddAnotherOutlineToPart.
268 lines
8.7 KiB
C++
268 lines
8.7 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2019-2019
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_NstAutoNesting.cpp Data : 28.11.19 Versione : 2.1k6
|
|
// Contenuto : Funzioni Automatic Nesting per EXE.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 28.11.19 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EXE.h"
|
|
#include "EXE_Macro.h"
|
|
#include "EXE_Const.h"
|
|
#include "DllNesting.h"
|
|
#include "/EgtDev/Include/EGkCurve.h"
|
|
#include "/EgtDev/Include/EGkCurveComposite.h"
|
|
#include "/EgtDev/Include/EGkOffsetCurve.h"
|
|
#include "/EgtDev/Include/EGkSurfFlatRegion.h"
|
|
#include "/EgtDev/Include/ENsAutoNester.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
#include "/EgtDev/Include/SELkLockId.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
static PtrOwner<IAutoNester> s_pAutoNester ;
|
|
static int s_nTotParts ;
|
|
static double s_dTotFillRatio ;
|
|
static ANIVECT s_vANestInfo ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestStart( void)
|
|
{
|
|
s_nTotParts = 0 ;
|
|
s_dTotFillRatio = 0 ;
|
|
if ( IsNull( s_pAutoNester)) {
|
|
s_pAutoNester.Set( MyCreateAutoNester()) ;
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
}
|
|
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<ICurve> 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)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il contorno
|
|
PolyArc Outline ;
|
|
if ( ! MyGetOutline( pGeomDB, nOutlineId, Outline))
|
|
return false ;
|
|
// aggiungo il pannello
|
|
return s_pAutoNester->AddSheet( nSheetId, Outline, dKerf, nPriority, nCount) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestAddDefectToSheet( int nSheetId, int nDefectId)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il contorno del difetto
|
|
PolyArc Outline ;
|
|
if ( ! MyGetOutline( pGeomDB, nDefectId, Outline))
|
|
return false ;
|
|
// aggiungo il difetto al pannello
|
|
return s_pAutoNester->AddDefectToSheet( nSheetId, Outline) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestAddPart( int nPartId, int nOutlineId, bool bCanFlip, bool bCanRotate, double dRotStep, int nPriority, int nCount)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il contorno
|
|
PolyArc Outline ;
|
|
if ( ! MyGetOutline( pGeomDB, nOutlineId, Outline))
|
|
return false ;
|
|
// aggiungo il pezzo
|
|
if ( ! s_pAutoNester->AddPart( nPartId, Outline, bCanFlip, bCanRotate, dRotStep, nPriority, nCount))
|
|
return false ;
|
|
// incremento contatore pezzi
|
|
s_nTotParts += nCount ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestAddHoleToPart( int nPartId, int nHoleId)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero un buco del pezzo
|
|
PolyArc Hole ;
|
|
if ( ! MyGetOutline( pGeomDB, nHoleId, Hole))
|
|
return false ;
|
|
// aggiungo un buco al pezzo
|
|
return s_pAutoNester->AddHoleToPart( nPartId, Hole) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestAddAnotherOutlineToPart( int nPartId, int nAnotherOutlineId)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero un contorno aggiuntivo del pezzo
|
|
PolyArc AnotherOutline ;
|
|
if ( ! MyGetOutline( pGeomDB, nAnotherOutlineId, AnotherOutline))
|
|
return false ;
|
|
// aggiungo un contorno aggiuntivo al pezzo
|
|
return s_pAutoNester->AddAnotherOutlineToPart( nPartId, AnotherOutline) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestAddToolOutlineToPart( int nPartId, int nToolOutlineId)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero il contorno della lavorazione
|
|
PolyArc ToolOutline ;
|
|
if ( ! MyGetOutline( pGeomDB, nToolOutlineId, ToolOutline))
|
|
return false ;
|
|
// aggiungo la lavorazione al pezzo
|
|
return s_pAutoNester->AddToolOutlineToPart( nPartId, ToolOutline) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestSetInterpartGap( double dGap)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
return s_pAutoNester->SetInterpartGap( dGap) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestCompute( bool bMinimizeOnXvsY, int nMaxTime)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
return s_pAutoNester->Compute( bMinimizeOnXvsY, nMaxTime) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestCancelComputation( void)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
return s_pAutoNester->CancelComputation() ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestGetComputationStatus( int& nStatus)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
return s_pAutoNester->GetComputationStatus( nStatus) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestPrintResults( const string& sHtmlFile)
|
|
{
|
|
if ( IsNull( s_pAutoNester))
|
|
return false ;
|
|
return s_pAutoNester->PrintResults( sHtmlFile) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestGetResults( int& nNestedParts, int& nParts, int& nSheets, int& nNestings, double& dTotFillRatio)
|
|
{
|
|
if ( IsNull( s_pAutoNester) || ! s_pAutoNester->GetResults( s_dTotFillRatio, s_vANestInfo))
|
|
return false ;
|
|
nNestedParts = 0 ;
|
|
nParts = s_nTotParts ;
|
|
nSheets = 0 ;
|
|
nNestings = 0 ;
|
|
dTotFillRatio = s_dTotFillRatio ;
|
|
for ( int i = 0 ; i < int( s_vANestInfo.size()) ; ++ i) {
|
|
// se sheet
|
|
if ( s_vANestInfo[i].nType > 0) {
|
|
++ nNestings ;
|
|
nSheets += s_vANestInfo[i].nType ;
|
|
nNestedParts += s_vANestInfo[i].nFlag * s_vANestInfo[i].nType ;
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeAutoNestGetOneResult( int nInd, int& nType, int& nId, int& nFlag, double& dX, double& dY, double& dAngRot)
|
|
{
|
|
if ( nInd < 0 || nInd >= int( s_vANestInfo.size()))
|
|
return false ;
|
|
nType = s_vANestInfo[nInd].nType ;
|
|
nId = s_vANestInfo[nInd].nId ;
|
|
nFlag = s_vANestInfo[nInd].nFlag ;
|
|
dX = s_vANestInfo[nInd].dX ;
|
|
dY = s_vANestInfo[nInd].dY ;
|
|
dAngRot = s_vANestInfo[nInd].dAngRot ;
|
|
return true ;
|
|
} |