f9a9b59338
- sistemato inizio simulazione - corretta seleziona tutto riferita ai pezzi in parcheggio - migliorata gestione eliminazione gruppo di lavoro.
379 lines
15 KiB
VB.net
379 lines
15 KiB
VB.net
Imports System.Globalization
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Module EstCalc
|
|
|
|
'--------------------------------------------------------------------------------------------------
|
|
Friend Function DoubleToString(ByVal dVal As Double, ByVal nNumDec As Integer) As String
|
|
Dim sFormat As String = "F" + Math.Abs(nNumDec).ToString()
|
|
Dim sVal As String = dVal.ToString(sFormat, CultureInfo.InvariantCulture)
|
|
If nNumDec > 0 Then
|
|
Return sVal.TrimEnd("0".ToCharArray()).TrimEnd(".".ToCharArray)
|
|
Else
|
|
Return sVal
|
|
End If
|
|
End Function
|
|
|
|
Friend Function StringToDouble(ByVal sVal As String, ByRef dVal As Double) As Boolean
|
|
If String.IsNullOrEmpty(sVal) Then Return False
|
|
Return EgtLuaEvalNumExpr(sVal, dVal)
|
|
End Function
|
|
|
|
Friend Function StringToInt(sVal As String, ByRef nVal As Integer) As Boolean
|
|
Dim dVal As Double = 0
|
|
If Not StringToDouble(sVal, dVal) Then Return False
|
|
nVal = CInt(Math.Round(dVal))
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function LenToString(ByVal dVal As Double, ByVal nNumDec As Integer) As String
|
|
Return DoubleToString(EgtToUiUnits(dVal), nNumDec)
|
|
End Function
|
|
|
|
Friend Function StringToLen(ByVal sVal As String, ByRef dVal As Double) As Boolean
|
|
If String.IsNullOrEmpty(sVal) Then Return False
|
|
If EgtLuaEvalNumExpr(sVal, dVal) Then
|
|
dVal = EgtFromUiUnits(dVal)
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
'--------------------------------------------------------------------------------------------------
|
|
Private m_nRawId As Integer = GDB_ID.NULL
|
|
Public Function GetRawId() As Integer
|
|
Return m_nRawId
|
|
End Function
|
|
|
|
Private m_ptRawMin As Point3d
|
|
Public Function GetRawPtMin() As Point3d
|
|
Return m_ptRawMin
|
|
End Function
|
|
|
|
Private m_ptRawMax As Point3d
|
|
Public Function GetRawPtMax() As Point3d
|
|
Return m_ptRawMax
|
|
End Function
|
|
|
|
Private m_dRawLength As Double
|
|
Public Function GetRawLength() As Double
|
|
Return m_dRawLength
|
|
End Function
|
|
|
|
Private m_dRawWidth As Double
|
|
Public Function GetRawWidth() As Double
|
|
Return m_dRawWidth
|
|
End Function
|
|
|
|
Private m_dRawHeight As Double
|
|
Public Function GetRawHeight() As Double
|
|
Return m_dRawHeight
|
|
End Function
|
|
|
|
Public Sub UpdateRawPart()
|
|
' determino il grezzo (è il primo con fase 1)
|
|
m_nRawId = EgtGetFirstRawPart()
|
|
While m_nRawId <> GDB_ID.NULL And Not EgtVerifyRawPartPhase(m_nRawId, 1)
|
|
m_nRawId = EgtGetNextRawPart(m_nRawId)
|
|
End While
|
|
If GetRawBox(m_nRawId, m_ptRawMin, m_ptRawMax) Then
|
|
m_dRawLength = m_ptRawMax.x - m_ptRawMin.x
|
|
m_dRawWidth = m_ptRawMax.y - m_ptRawMin.y
|
|
m_dRawHeight = m_ptRawMax.z - m_ptRawMin.z
|
|
Else
|
|
m_dRawLength = 0
|
|
m_dRawWidth = 0
|
|
m_dRawHeight = 0
|
|
End If
|
|
End Sub
|
|
|
|
'--------------------------------------------------------------------------------------------------
|
|
Public Function SetOrderMachiningFlag() As Boolean
|
|
Dim nMGrpId As Integer = EgtGetCurrMachGroup()
|
|
Return EgtSetInfo(nMGrpId, INFO_MACHORDER, 1)
|
|
End Function
|
|
|
|
Friend Function ResetOrderMachiningFlag() As Boolean
|
|
Dim nMGrpId As Integer = EgtGetCurrMachGroup()
|
|
Return EgtRemoveInfo(nMGrpId, INFO_MACHORDER)
|
|
End Function
|
|
|
|
Friend Function GetOrderMachiningFlag() As Boolean
|
|
Dim nMGrpId As Integer = EgtGetCurrMachGroup()
|
|
Dim nFlag As Integer = 0
|
|
EgtGetInfo(nMGrpId, INFO_MACHORDER, nFlag)
|
|
Return (nFlag <> 0)
|
|
End Function
|
|
|
|
Public Function AdjustAdditionalTable() As Boolean
|
|
' Recupero altezza sottotavola corrente
|
|
Dim nFixtId As Integer = EgtGetFirstNameInGroup(EgtGetFirstMachGroup(), MACH_FIXT_GROUP)
|
|
Dim nAddTabId As Integer = EgtGetFirstNameInGroup(nFixtId, MACH_ADD_TABLE)
|
|
Dim dCurrAddTab As Double = 0
|
|
If nAddTabId <> GDB_ID.NULL And Not EgtGetInfo(nAddTabId, KEY_ADD_TABLE, dCurrAddTab) Then
|
|
Dim b3AddTab As New BBox3d
|
|
EgtGetBBoxGlob(nAddTabId, GDB_BB.STANDARD, b3AddTab)
|
|
dCurrAddTab = b3AddTab.DimZ()
|
|
End If
|
|
' Se valore cambiato, aggiorno...
|
|
Dim dDeltaZ As Double = dAdditionalTable - dCurrAddTab
|
|
If Math.Abs(dDeltaZ) > EPS_SMALL Then
|
|
AddAdditionalTable()
|
|
UpdateAllRawsZ(dDeltaZ)
|
|
' !!! FOTO DA GESTIRE !!!
|
|
'If GetPhoto() <> GDB_ID.NULL Then
|
|
' UpdatePhoto()
|
|
' UpdateContour()
|
|
' If EgtGetRawPartCount() > 0 Then
|
|
' ShowPhoto(False)
|
|
' End If
|
|
'End If
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Public Function AddAdditionalTable() As Boolean
|
|
' Gruppo dei sottopezzi
|
|
Dim nFixtId As Integer = EgtGetFirstNameInGroup(EgtGetFirstMachGroup(), MACH_FIXT_GROUP)
|
|
' Elimino eventuale vecchia tavola dal gruppo dei bloccaggi
|
|
EgtErase(EgtGetFirstNameInGroup(nFixtId, MACH_ADD_TABLE))
|
|
' Altezza eventuale tavola aggiuntiva
|
|
Dim dAddTable As Double = dAdditionalTable
|
|
' Se non esiste sovratavola, esco subito
|
|
If dAddTable < 10 * EPS_SMALL Then Return True
|
|
' Recupero box tavola
|
|
Dim ptMin, ptMax As Point3d
|
|
EgtGetTableArea(1, ptMin, ptMax)
|
|
' Aggiungo sovratavola nel gruppo dei bloccaggi
|
|
ptMax.z -= DELTAZ_ADDTAB
|
|
ptMin.z = ptMax.z
|
|
ptMax.z += dAddTable
|
|
Dim nAddTabId As Integer = EgtCreateSurfTmBBox(nFixtId, ptMin, ptMax, GDB_RT.GLOB)
|
|
If nAddTabId = GDB_ID.NULL Then Return False
|
|
EgtSetName(nAddTabId, MACH_ADD_TABLE)
|
|
EgtSetColor(nAddTabId, New Color3d(150, 75, 0, 100), True)
|
|
EgtSetInfo(nAddTabId, KEY_ADD_TABLE, dAddTable)
|
|
Return True
|
|
End Function
|
|
|
|
Public Function SetWashingFlag(bWash As Boolean) As Boolean
|
|
Dim nMGrpId As Integer = EgtGetCurrMachGroup()
|
|
Return EgtSetInfo(nMGrpId, INFO_WASHING, bWash)
|
|
End Function
|
|
|
|
Public Function GetWashingFlag() As Boolean
|
|
Dim nMGrpId As Integer = EgtGetCurrMachGroup()
|
|
Dim nFlag As Integer = 1
|
|
EgtGetInfo(nMGrpId, INFO_WASHING, nFlag)
|
|
Return (nFlag <> 0)
|
|
End Function
|
|
|
|
Public Function UpdateWashingFlag() As Boolean
|
|
Dim bCurrWash As Boolean =
|
|
(GetMainPrivateProfileInt(S_MACH_NEST, K_MACH_WASHING, 1) <> 0)
|
|
Dim bProjWash As Boolean = GetWashingFlag()
|
|
If bCurrWash <> bProjWash Then Return SetWashingFlag(bCurrWash)
|
|
Return True
|
|
End Function
|
|
|
|
'--------------------------------------------------------------------------------------------------
|
|
Public Function PartIsFree(nId As Integer) As Boolean
|
|
' Deve essere un pezzo
|
|
If Not EgtIsPart(nId) Then Return False
|
|
' Non deve essere inserito in grezzi della prima fase di qualche gruppo di lavoro
|
|
Dim sList As String = String.Empty
|
|
If Not EgtGetInfo(nId, "!LST", sList) Then Return True
|
|
Dim sItems() As String = sList.Split(",".ToCharArray)
|
|
If sItems.Count() = 0 Then Return True
|
|
For Each sLstId In sItems
|
|
Dim nLstId As Integer = GDB_ID.NULL
|
|
StringToInt(sLstId, nLstId)
|
|
Dim nRawId = EgtGetParent(nLstId)
|
|
Dim nPhase As Integer = 1
|
|
EgtGetInfo(nRawId, "Ph", nPhase)
|
|
If nPhase = 1 Then
|
|
Dim sName As String = String.Empty
|
|
If EgtGetName(EgtGetParent(nRawId), sName) AndAlso sName = MACH_RAWS_GROUP Then Return False
|
|
End If
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Public Sub HideParkedParts(Optional bDisableModified As Boolean = True)
|
|
' Se richiesto, disabilito impostazione modificato
|
|
Dim bOldEnMod As Boolean = False
|
|
If bDisableModified Then
|
|
bOldEnMod = EgtGetEnableModified()
|
|
If bOldEnMod Then EgtDisableModified()
|
|
End If
|
|
' Nascondo pezzi parcheggiati
|
|
Dim nPartId As Integer = EgtGetFirstPart()
|
|
While nPartId <> GDB_ID.NULL
|
|
EgtSetStatus(nPartId, GDB_ST.OFF)
|
|
nPartId = EgtGetNextPart(nPartId)
|
|
End While
|
|
' Se necessario, ripristino precedente impostazione modificato
|
|
If bOldEnMod Then EgtEnableModified()
|
|
End Sub
|
|
|
|
Public Sub ShowParkedParts(Optional bDisableModified As Boolean = True)
|
|
' Se richiesto, disabilito impostazione modificato
|
|
Dim bOldEnMod As Boolean = False
|
|
If bDisableModified Then
|
|
bOldEnMod = EgtGetEnableModified()
|
|
If bOldEnMod Then EgtDisableModified()
|
|
End If
|
|
' Visualizzo pezzi parcheggiati che non appartengano a grezzi di altri gruppi
|
|
Dim nPartId As Integer = EgtGetFirstPart()
|
|
While nPartId <> GDB_ID.NULL
|
|
If PartIsFree(nPartId) Then
|
|
EgtSetStatus(nPartId, GDB_ST.ON_)
|
|
Else
|
|
EgtSetStatus(nPartId, GDB_ST.OFF)
|
|
End If
|
|
nPartId = EgtGetNextPart(nPartId)
|
|
End While
|
|
' Se necessario, ripristino precedente impostazione modificato
|
|
If bOldEnMod Then EgtEnableModified()
|
|
End Sub
|
|
|
|
Public Function AdjustFlatPart(nPartId As Integer) As Boolean
|
|
' Ciclo sui layer
|
|
Dim nLayerId As Integer = EgtGetFirstLayer(nPartId)
|
|
While nLayerId <> GDB_ID.NULL
|
|
' Recupero il layer successivo
|
|
Dim nNextLayerId As Integer = EgtGetNextLayer(nLayerId)
|
|
' Recupero il nome del layer
|
|
Dim sLayName As String = String.Empty
|
|
If EgtGetName(nLayerId, sLayName) Then
|
|
' Se layer OutLoop o InLoop
|
|
If String.Compare(sLayName, NAME_OUTLOOP, True) = 0 Or
|
|
String.Compare(sLayName, NAME_INLOOP, True) = 0 Then
|
|
' Sistemo i layer per applicare facilmente le lavorazioni
|
|
EgtAdjustFlatPartLayer(nLayerId)
|
|
End If
|
|
' Se senza nome, lo elimino
|
|
Else
|
|
EgtErase(nLayerId)
|
|
End If
|
|
' Passo al layer successivo
|
|
nLayerId = nNextLayerId
|
|
End While
|
|
Return True
|
|
End Function
|
|
|
|
'--------------------------------------------------------------------------------------------------
|
|
Public Function InsertOnePart(nId As Integer, bAligned As Boolean, bReducedCut As Boolean) As Boolean
|
|
' Se esiste grezzo e pezzo in parcheggio, lo metto nella tavola
|
|
If m_nRawId <> GDB_ID.NULL AndAlso EgtIsPart(nId) Then
|
|
' Sistemazioni per eventuali lati esterni inclinati
|
|
EgtCalcFlatPartDownRegion(nId, m_ptRawMax.z - m_ptRawMin.z)
|
|
' Dimensioni del pezzo
|
|
Dim ptPartMin, ptPartMax As Point3d
|
|
If Not EgtGetBBoxGlob(nId, GDB_BB.IGNORE_DIM + GDB_BB.IGNORE_TEXT, ptPartMin, ptPartMax) Then Return False
|
|
Dim dPartLen As Double = ptPartMax.x - ptPartMin.x
|
|
Dim dPartHeight As Double = ptPartMax.y - ptPartMin.y
|
|
' Centro del grezzo
|
|
Dim nRawCenId = EgtGetFirstNameInGroup(m_nRawId, NAME_RAW_CENTER)
|
|
Dim ptRawCenter As Point3d
|
|
EgtStartPoint(nRawCenId, GDB_ID.ROOT, ptRawCenter)
|
|
Dim dRawCenX = ptRawCenter.x - m_ptRawMin.x
|
|
Dim dRawCenY = ptRawCenter.y - m_ptRawMin.y
|
|
' Inserisco il pezzo nel grezzo, in centro in XY e in alto in Z
|
|
Dim ptP As New Point3d(dRawCenX - 0.5 * dPartLen, dRawCenY - 0.5 * dPartHeight, m_ptRawMax.z - m_ptRawMin.z)
|
|
If EgtAddPartToRawPart(nId, ptP, m_nRawId) Then
|
|
' Aggiungo le lavorazioni standard
|
|
AddMachinings(nId, True, False)
|
|
' Eseguo nesting
|
|
Dim bFit As Boolean = False
|
|
If UpdateNestRegions() Then
|
|
EnableReferenceRegion(bAligned)
|
|
If Not EgtExistsInfo(m_nRawId, KEY_RAWBYPOINTS) Then
|
|
bFit = EgtPackPartInRectangle(nId, bReducedCut, True)
|
|
End If
|
|
If Not bFit Then
|
|
bFit = EgtPackPart(nId, bReducedCut, True)
|
|
End If
|
|
End If
|
|
' Gestione risultato nesting
|
|
If bFit Then
|
|
Return True
|
|
Else
|
|
EraseMachinings(nId)
|
|
EgtRemovePartFromRawPart(nId)
|
|
EgtSetStatus(nId, GDB_ST.ON_)
|
|
End If
|
|
End If
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Public Function StoreOnePart(ByVal nId As Integer, Optional ByVal bForced As Boolean = False) As Boolean
|
|
' Se pezzo in grezzo, metto in parcheggio (sempre possibile)
|
|
If bForced OrElse
|
|
(m_nRawId <> GDB_ID.NULL AndAlso EgtGetParent(nId) = m_nRawId) Then
|
|
' Rimuovo le lavorazioni
|
|
EraseMachinings(nId)
|
|
' Elimino eventuali modifiche per lati esterni inclinati
|
|
EgtCalcFlatPartDownRegion(nId, 0)
|
|
' Parcheggio
|
|
EgtRemovePartFromRawPart(nId)
|
|
EgtSetStatus(nId, GDB_ST.ON_)
|
|
PackPartInStore(nId)
|
|
' Aggiusto la posizione in Z
|
|
Dim ptPartMin, ptPartMax As Point3d
|
|
If EgtGetBBoxGlob(nId, GDB_BB.IGNORE_DIM + GDB_BB.IGNORE_TEXT, ptPartMin, ptPartMax) Then
|
|
EgtMove(nId, New Vector3d(0, 0, m_ptRawMax.z - ptPartMax.z), GDB_RT.GLOB)
|
|
End If
|
|
Return True
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Public Function PackPartInStore(nId As Integer) As Boolean
|
|
' Recupero box tavola
|
|
Dim b3Tab As New BBox3d
|
|
If Not EgtGetTableArea(1, b3Tab) Then
|
|
b3Tab.Add(New Point3d(0, 0, 0))
|
|
b3Tab.Add(New Point3d(-3600, -2600, 0))
|
|
End If
|
|
' Parcheggio
|
|
Const STORE_LARGH As Double = 6000
|
|
Const STORE_DIST As Double = 200
|
|
Const STORE_OFFS As Double = 20
|
|
Dim dStXmin As Double = b3Tab.Min().x - 0.5 * (STORE_LARGH - b3Tab.DimX())
|
|
Return EgtPackBox(nId, dStXmin, -INFINITO, dStXmin + STORE_LARGH, b3Tab.Min().y - STORE_DIST, STORE_OFFS, False)
|
|
End Function
|
|
|
|
Public Function UpdateNestRegions() As Boolean
|
|
' Se necessario, creo la regione fuori kerf
|
|
Dim nKerfId As Integer = EgtGetFirstNameInGroup(GetRawId(), NAME_KERF)
|
|
EgtCreateOutRegion(GetRawId(), nKerfId)
|
|
' Se necessario, creo la regione di riferimento
|
|
EgtCreateReferenceRegion(GetRawId(), nKerfId, True)
|
|
' Se necessario, creo le regioni per le aree danneggiate
|
|
Dim nId As Integer = EgtGetFirstNameInGroup(GetRawId(), NAME_DAMAGED)
|
|
While nId <> GDB_ID.NULL
|
|
EgtCreateDamagedRegion(GetRawId(), nId)
|
|
nId = EgtGetNextName(nId, NAME_DAMAGED)
|
|
End While
|
|
Return True
|
|
End Function
|
|
|
|
Public Function EnableReferenceRegion(bEnable As Boolean) As Boolean
|
|
' Recupero identificativo della regione di riferimento
|
|
Dim nRegId As Integer = EgtGetFirstNameInGroup(GetRawId(), NAME_REF_REG)
|
|
If nRegId = GDB_ID.NULL Then Return False
|
|
' Imposto l'abilitazione voluta
|
|
If bEnable Then
|
|
EgtRemoveInfo(nRegId, KEY_REF_REG_OFF)
|
|
Else
|
|
EgtSetInfo(nRegId, KEY_REF_REG_OFF, 1)
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
End Module
|