Files
EgtExecutor/EXE_NstAutoNesting.cpp
T
SaraP 4a98a0a25e EgtExecutor 2.7i3 :
- aggiunte funzioni Exe e Lua per calcolo shear sequence nei nesting a ghigliottina.
2025-09-12 10:27:47 +02:00

359 lines
12 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/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() ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestSetGuillotineMode( void)
{
if ( IsNull( s_pAutoNester))
return false ;
return s_pAutoNester->SetGuillotineMode() ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestSetStartCorner( int nCorner)
{
if ( IsNull( s_pAutoNester))
return false ;
return s_pAutoNester->SetStartCorner( nCorner) ;
}
//-----------------------------------------------------------------------------
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, bool* pbIsRect)
{
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, pbIsRect) ;
}
//-----------------------------------------------------------------------------
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
ExeAutoNestAddRestrictedZoneToSheet( int nSheetId, int nRstZoneId, int nRzConstrId)
{
if ( IsNull( s_pAutoNester))
return false ;
IGeomDB* pGeomDB = GetCurrGeomDB() ;
VERIFY_GEOMDB( pGeomDB, false)
// recupero il contorno della zona ristretta
PolyArc Outline ;
if ( ! MyGetOutline( pGeomDB, nRstZoneId, Outline))
return false ;
// aggiungo la zona ristretta al pannello
return s_pAutoNester->AddRestrictedZoneToSheet( nRzConstrId, 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
ExeAutoNestSetRestrictedZoneToPart( int nPartId, int nRzConstrId)
{
if ( IsNull( s_pAutoNester))
return false ;
// aggiungo il vincolo di zona ristretta al pezzo
return s_pAutoNester->SetRestrictedZoneToPart( nPartId, nRzConstrId) ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestSetStripYconstraintToPart( int nPartId, const Point3d& ptRef, double dStripStart, double dStripRepeat)
{
if ( IsNull( s_pAutoNester))
return false ;
// aggiungo il vincolo di punto su linee parallele a Y costante (parallele ad asse X) al pezzo
return s_pAutoNester->SetStripYconstraintToPart( nPartId, ptRef, dStripStart, dStripRepeat) ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestSetStripXconstraintToPart( int nPartId, const Point3d& ptRef, double dStripStart, double dStripRepeat)
{
if ( IsNull( s_pAutoNester))
return false ;
// aggiungo il vincolo di punto su linee parallele a X costante (parallele ad asse Y) al pezzo
return s_pAutoNester->SetStripXconstraintToPart( nPartId, ptRef, dStripStart, dStripRepeat) ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestSetInterpartGap( double dGap)
{
if ( IsNull( s_pAutoNester))
return false ;
return s_pAutoNester->SetInterpartGap( dGap) ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestSetShearGap( double dShearGap)
{
if ( IsNull( s_pAutoNester))
return false ;
return s_pAutoNester->SetShearGap( dShearGap) ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestSetReportFile( const string& sReportFile)
{
if ( IsNull( s_pAutoNester))
return false ;
return s_pAutoNester->SetReportFile( sReportFile) ;
}
//-----------------------------------------------------------------------------
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 ;
}
//-----------------------------------------------------------------------------
bool
ExeAutoNestCalcShearSequence( int nNesting, PNTVECTOR& vPtStart, PNTVECTOR& vPtEnd)
{
if ( IsNull( s_pAutoNester))
return false ;
return s_pAutoNester->CalcShearSequence( nNesting, vPtStart, vPtEnd) ;
}