Files
omagoffice/OptionPanel/NestingTab/NestingTabVM.vb
T
Dario Sassi 70dca8e466 OmagOFFICE :
- aggiornamenti per conservazione pezzi nestati in modifica grezzo
- aggiunta gestione materiale per ogni gruppo di lavoro
- CsvM trasformato in modulo.
2017-05-09 11:02:42 +00:00

947 lines
33 KiB
VB.net

Imports EgtWPFLib5
Imports EgtUILib
Public Class NestingTabVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
' Flag per pezzi selezionati in tavola o fuori
Private m_nPartPos As Integer = PART_POS.NONE_TABLE
Enum PART_POS As Integer
IN_TABLE = -1
NONE_TABLE = 0
OUT_TABLE = 1
End Enum
' Identificativi per pezzo da selezionare/deselezionare
Private m_nIdToSel As Integer = GDB_ID.NULL
Private m_nIdToDesel As Integer = GDB_ID.NULL
' Dati del grezzo
Private m_dMinDist As Double = 0
' Dati movimento
Private m_dMaxStep As Double = 0
' Dati per Drag
Private m_nRestRadius As Integer = 3
Private m_bDrag As Boolean = False
Private m_bDragToStart As Boolean = False
Private m_bVerify As Boolean = False
Private m_bDragging As Boolean = False
Private m_locPrev As System.Drawing.Point
Private m_ptPrev As Point3d
Private m_vtTotMove As Vector3d
Private m_dSnapDist As Double = 0
Private m_CsvImportWindow As CsvWindowV
Friend ReadOnly Property CsvImportWindow As CsvWindowV
Get
Return m_CsvImportWindow
End Get
End Property
Private m_CsvImport_IsChecked As Boolean
Public Property CsvImport_IsChecked As Boolean
Get
Return m_CsvImport_IsChecked
End Get
Set(value As Boolean)
If value <> m_CsvImport_IsChecked Then
m_CsvImport_IsChecked = value
If m_CsvImport_IsChecked Then
m_CsvImportWindow = New CsvWindowV(Application.Current.MainWindow, New CsvWindowVM)
m_CsvImportWindow.Show()
Else
m_CsvImportWindow.Close()
m_CsvImportWindow = Nothing
End If
NotifyPropertyChanged("CsvImport_IsChecked")
End If
End Set
End Property
Private m_MaxMoveIsChecked As Boolean
Public Property MaxMoveIsChecked As Boolean
Get
Return m_MaxMoveIsChecked
End Get
Set(value As Boolean)
If value <> m_MaxMoveIsChecked Then
m_MaxMoveIsChecked = value
NotifyPropertyChanged("MaxMoveIsChecked")
End If
End Set
End Property
Private m_dStepMove As Double
Public Property StepMove As String
Get
Return LenToString(m_dStepMove, 2)
End Get
Set(value As String)
StringToLen(value, m_dStepMove)
End Set
End Property
Private m_dRotationAngle As Double
Public Property RotationAngle As String
Get
Return DoubleToString(m_dRotationAngle, 2)
End Get
Set(value As String)
StringToDouble(value, m_dRotationAngle)
End Set
End Property
Private m_bMagnetic As Boolean
Public Property MagneticIsChecked As Boolean
Get
Return m_bMagnetic
End Get
Set(value As Boolean)
If value <> m_bMagnetic Then
m_bMagnetic = value
NotifyPropertyChanged("MagneticIsChecked")
End If
End Set
End Property
#Region "Messages"
Public ReadOnly Property InsertPartMsg As String
Get
Return EgtMsg(MSG_NESTPAGEUC + 1)
End Get
End Property
Public ReadOnly Property StorePartMsg As String
Get
Return EgtMsg(MSG_NESTPAGEUC + 2)
End Get
End Property
Public ReadOnly Property RemovePartMsg As String
Get
Return EgtMsg(MSG_NESTPAGEUC + 3)
End Get
End Property
Public ReadOnly Property SelectAllMsg As String
Get
Return EgtMsg(MSG_NESTPAGEUC + 4)
End Get
End Property
Public ReadOnly Property DeselectAllMsg As String
Get
Return EgtMsg(MSG_NESTPAGEUC + 5)
End Get
End Property
Public ReadOnly Property ResetMsg As String
Get
Return EgtMsg(MSG_NESTPAGEUC + 6)
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdDraw As ICommand
Private m_cmdImportDxf As ICommand
Private m_cmdUp As ICommand
Private m_cmdLeft As ICommand
Private m_cmdRight As ICommand
Private m_cmdDown As ICommand
Private m_cmdCClockwiseRot As ICommand
Private m_cmdClockwiseRot As ICommand
Private m_cmdInsertPart As ICommand
Private m_cmdStorePart As ICommand
Private m_cmdRemovePart As ICommand
Private m_cmdSelectAll As ICommand
Private m_cmdDeselectAll As ICommand
Private m_cmdReset As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Creo riferimento a questa classe in OmagOFFICEMap
OmagOFFICEMap.SetRefNestingTabVM(Me)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Function InitNesting() As Boolean
' aggiorno dati del grezzo
EstCalc.UpdateRawPart()
' calcolo valore di minima distanza (da spessore lama corrente)
Dim dSawThick As Double = 0
If EgtTdbSetCurrTool(CurrentMachine.sCurrSaw) AndAlso
EgtTdbGetCurrToolParam(MCH_TP.THICK, dSawThick) Then
m_dMinDist = dSawThick
Else
EgtOutLog("Not found current saw for nesting mindist")
m_dMinDist = 0
End If
' carico e calcolo i parametri di movimento e drag
m_dStepMove = GetMainPrivateProfileDouble(S_NEST, K_STEP, 10)
NotifyPropertyChanged("StepMove")
Dim ptRawDiag As Vector3d = GetRawPtMax() - GetRawPtMin()
m_dMaxStep = Math.Max(ptRawDiag.x, ptRawDiag.y)
m_dRotationAngle = GetMainPrivateProfileDouble(S_NEST, K_ANGSTEP, 15)
NotifyPropertyChanged("RotationAngle")
m_nRestRadius = GetMainPrivateProfileInt(S_NEST, K_RESTRADIUS, 3)
m_dSnapDist = GetMainPrivateProfileDouble(S_NEST, K_SNAPDIST, 50)
' Garantisco visibilità pezzi parcheggiati
ShowParkedParts()
' Garantisco visibilità eventuale contorno da foto
EstPhoto.ShowContour(True)
' Se abilitato CSV ne visualizzo la finestra
If m_CsvImport_IsChecked Then
m_CsvImportWindow = New CsvWindowV(Application.Current.MainWindow, New CsvWindowVM)
m_CsvImportWindow.Show()
End If
EgtZoom(ZM.ALL)
Return True
End Function
Private Function RotateCluster(ByVal dAngRotDeg As Double) As Boolean
' Se non ci sono pezzi selezionati, esco
If EgtGetSelectedObjCount() = 0 Then
Return True
End If
' Se pezzi in parcheggio, li ruoto liberamente e li risistemo (sempre possibile)
If m_nPartPos <> PART_POS.IN_TABLE Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Calcolo il centro di rotazione come centro del pezzo
Dim ptCen As Point3d
If Not EgtGetPartPartClusterCenterGlob(nId, ptCen) Then Return False
' Rotazione del pezzo attorno al suo centro
EgtRotate(nId, ptCen, Vector3d.Z_AX(), dAngRotDeg, GDB_RT.GLOB)
' Sistemazione nel parcheggio
PackPartInStore(nId)
' Passo al successivo selezionato
nId = EgtGetNextSelectedObj()
End While
Return True
' Altrimenti li ruoto tenendo conto delle collisioni
Else
' Calcolo il centro di rotazione come centro del cluster
Dim ptCen As Point3d
If Not EgtGetPartPartClusterCenterGlob(GDB_ID.SEL, ptCen) Then Return False
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' Verifico rotazione complessiva
EgtRotate(GDB_ID.SEL, ptCen, Vector3d.Z_AX(), dAngRotDeg, GDB_RT.GLOB)
If EgtVerifyPart(GDB_ID.SEL, CurrentMachine.bReducedCut) Then Return True
' Provo rotazione parziale (dopo aver annullato la complessiva)
EgtRotate(GDB_ID.SEL, ptCen, Vector3d.Z_AX(), -dAngRotDeg, GDB_RT.GLOB)
Return EgtRotatePart(GDB_ID.SEL, CurrentMachine.bReducedCut, ptCen, dAngRotDeg)
End If
End Function
Friend Sub Refresh(PrevMeasureUnit As MeasureUnitOpt)
NotifyPropertyChanged("StepMove")
End Sub
Friend Function ExitNesting() As Boolean
If m_CsvImport_IsChecked Then
m_CsvImportWindow.Close()
m_CsvImportWindow = Nothing
End If
Return True
End Function
#End Region ' METHODS
#Region "COMMANDS"
#Region "DrawCommand"
Public ReadOnly Property DrawCommand As ICommand
Get
If m_cmdDraw Is Nothing Then
m_cmdDraw = New Command(AddressOf Draw)
End If
Return m_cmdDraw
End Get
End Property
Public Sub Draw(ByVal param As Object)
Dim CompoWindow As New CompoWindowV(Application.Current.MainWindow, New CompoWindowVM)
CompoWindow.ShowDialog()
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
End Sub
#End Region ' DrawCommand
#Region "ImportDxfCommand"
Public ReadOnly Property ImportDxfCommand As ICommand
Get
If m_cmdImportDxf Is Nothing Then
m_cmdImportDxf = New Command(AddressOf ImportDxf)
End If
Return m_cmdImportDxf
End Get
End Property
Public Sub ImportDxf(ByVal param As Object)
Dim DxfImportWindow As New DxfImportWindowV(Application.Current.MainWindow, New DxfImportWindowVM)
DxfImportWindow.ShowDialog()
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
End Sub
#End Region ' ImportDxfCommand
#Region "UpCommand"
Public ReadOnly Property UpCommand As ICommand
Get
If m_cmdUp Is Nothing Then
m_cmdUp = New Command(AddressOf Up)
End If
Return m_cmdUp
End Get
End Property
Public Sub Up(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_MaxMoveIsChecked, m_dMaxStep, m_dStepMove)
EgtMovePart(GDB_ID.SEL, CurrentMachine.bReducedCut, New Vector3d(0, dStep, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
EstCalc.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
#End Region ' UpCommand
#Region "LeftCommand"
Public ReadOnly Property LeftCommand As ICommand
Get
If m_cmdLeft Is Nothing Then
m_cmdLeft = New Command(AddressOf Left)
End If
Return m_cmdLeft
End Get
End Property
Public Sub Left(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_MaxMoveIsChecked, m_dMaxStep, m_dStepMove)
EgtMovePart(GDB_ID.SEL, CurrentMachine.bReducedCut, New Vector3d(-dStep, 0, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
EstCalc.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
#End Region ' LeftCommand
#Region "RightCommand"
Public ReadOnly Property RightCommand As ICommand
Get
If m_cmdRight Is Nothing Then
m_cmdRight = New Command(AddressOf Right)
End If
Return m_cmdRight
End Get
End Property
Public Sub Right(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_MaxMoveIsChecked, m_dMaxStep, m_dStepMove)
EgtMovePart(GDB_ID.SEL, CurrentMachine.bReducedCut, New Vector3d(dStep, 0, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
EstCalc.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
#End Region ' RightCommand
#Region "DownCommand"
Public ReadOnly Property DownCommand As ICommand
Get
If m_cmdDown Is Nothing Then
m_cmdDown = New Command(AddressOf Down)
End If
Return m_cmdDown
End Get
End Property
Public Sub Down(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_MaxMoveIsChecked, m_dMaxStep, m_dStepMove)
EgtMovePart(GDB_ID.SEL, CurrentMachine.bReducedCut, New Vector3d(0, -dStep, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, CurrentMachine.bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
EstCalc.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
#End Region ' DownCommand
#Region "CClockwiseRotCommand"
Public ReadOnly Property CClockwiseRotCommand As ICommand
Get
If m_cmdCClockwiseRot Is Nothing Then
m_cmdCClockwiseRot = New Command(AddressOf CClockwiseRot)
End If
Return m_cmdCClockwiseRot
End Get
End Property
Public Sub CClockwiseRot(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
RotateCluster(m_dRotationAngle)
EstCalc.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
#End Region ' CClockwiseRotCommand
#Region "ClockwiseRotCommand"
Public ReadOnly Property ClockwiseRotCommand As ICommand
Get
If m_cmdClockwiseRot Is Nothing Then
m_cmdClockwiseRot = New Command(AddressOf ClockwiseRot)
End If
Return m_cmdClockwiseRot
End Get
End Property
Public Sub ClockwiseRot(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
RotateCluster(-m_dRotationAngle)
EstCalc.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
#End Region ' ClockwiseRotCommand
#Region "InsertPartCommand"
Public ReadOnly Property InsertPartCommand As ICommand
Get
If m_cmdInsertPart Is Nothing Then
m_cmdInsertPart = New Command(AddressOf InsertPart)
End If
Return m_cmdInsertPart
End Get
End Property
Public Sub InsertPart(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Ciclo di inserimento in tavola dei pezzi selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero successivo selezionato
Dim nNextId = EgtGetNextSelectedObj()
' Lo metto in tavola, se possibile
If EstCalc.InsertOnePart(nId, CurrentMachine.bAligned, CurrentMachine.bReducedCut) Then
' Eventuale notifica al VeinMatching
VeinMatching.OnInsertPartInRaw(nId)
Else
VeinMatching.OnDeselectPart(nId)
End If
' Costringo ad aggiornare UI
UpdateUI()
' Passo al successivo selezionato
nId = nNextId
End While
' Aggiorno flag selezionati
m_nPartPos = If(EgtGetSelectedObjCount() > 0, PART_POS.IN_TABLE, PART_POS.NONE_TABLE)
' Aggiorno vista
EgtZoom(ZM.ALL)
End Sub
#End Region ' InsertPartCommand
#Region "StorePartCommand"
Public ReadOnly Property StorePartCommand As ICommand
Get
If m_cmdStorePart Is Nothing Then
m_cmdStorePart = New Command(AddressOf StorePart)
End If
Return m_cmdStorePart
End Get
End Property
Public Sub StorePart(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Ciclo di parcheggio dei pezzi selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero indice del successivo
Dim nNextId As Integer = EgtGetNextSelectedObj()
' Metto in parcheggio, se in grezzo
StoreOnePart(nId)
' Eventuale notifica al VeinMatching
VeinMatching.OnRemovePartFromRaw(nId)
' Passo al successivo selezionato
nId = nNextId
End While
' Imposto flag posizione pezzi su parcheggio
m_nPartPos = PART_POS.OUT_TABLE
' Aggiorno vista
EgtZoom(ZM.ALL)
End Sub
#End Region ' StorePartCommand
#Region "RemovePartCommand"
Public ReadOnly Property RemovePartCommand As ICommand
Get
If m_cmdRemovePart Is Nothing Then
m_cmdRemovePart = New Command(AddressOf RemovePart)
End If
Return m_cmdRemovePart
End Get
End Property
Public Sub RemovePart(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Verifico se ci sono pezzi provenienti da liste Csv
Dim bCsvParts As Boolean = False
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
If EgtExistsInfo(nId, INFO_CSV_PATH) Then
bCsvParts = True
Exit While
End If
nId = EgtGetNextSelectedObj()
End While
' Chiedo se si vogliono cancellare anche questi pezzi
Dim bEraseCsvParts As Boolean = False
If bCsvParts Then
' Vuoi cancellare anche i pezzi da lista Csv ?
Select Case MessageBox.Show(EgtMsg(MSG_EGTMSGBOX + 12), "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)
Case MessageBoxResult.Cancel
Return
Case MessageBoxResult.Yes
bEraseCsvParts = True
Case MessageBoxResult.No
bEraseCsvParts = False
End Select
End If
' Ciclo di cancellazione dei pezzi selezionati
nId = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero indice del successivo
Dim nNextId = EgtGetNextSelectedObj()
' Se abilitata cancellazione in ogni caso o pezzo non da Csv
If bEraseCsvParts OrElse Not EgtExistsInfo(nId, INFO_CSV_PATH) Then
' Se pezzo in parcheggio cancello direttamente
If EgtIsPart(nId) Then
' Rimuovo le lavorazioni
EraseMachinings(nId)
' Cancello
EgtErase(nId)
' Altrimenti pezzo nel grezzo
ElseIf EgtGetParent(nId) = GetRawId() Then
If EgtRemovePartFromRawPart(nId) Then
' Eventuale notifica al VeinMatching
VeinMatching.OnRemovePartFromRaw(nId)
' Rimuovo le lavorazioni
EraseMachinings(nId)
'Cancello
EgtErase(nId)
End If
End If
End If
' Passo al successivo selezionato
nId = nNextId
End While
' Imposto flag posizione pezzi
m_nPartPos = PART_POS.NONE_TABLE
' Aggiorno vista
EgtZoom(ZM.ALL)
End Sub
#End Region ' RemovePartCommand
#Region "SelectAllCommand"
Public ReadOnly Property SelectAllCommand As ICommand
Get
If m_cmdSelectAll Is Nothing Then
m_cmdSelectAll = New Command(AddressOf SelectAll)
End If
Return m_cmdSelectAll
End Get
End Property
Public Sub SelectAll(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Numero dei pezzi in tavola
Dim nPartTab As Integer = EgtGetPartInRawPartCount(GetRawId())
' Se già selezionati in tavola o non ci sono selezionati e pezzi in tavola
If m_nPartPos = PART_POS.IN_TABLE Or
(m_nPartPos = PART_POS.NONE_TABLE And nPartTab > 0) Then
' Seleziono tutti i pezzi in tavola
Dim nPartId As Integer = EgtGetFirstGroupInGroup(GetRawId())
While nPartId <> GDB_ID.NULL
EgtSelectObj(nPartId)
VeinMatching.OnSelectPart(nPartId)
nPartId = EgtGetNextGroup(nPartId)
End While
' Aggiorno flag
m_nPartPos = If(EgtGetSelectedObjCount() > 0, PART_POS.IN_TABLE, PART_POS.NONE_TABLE)
' Altrimenti
Else
' Seleziono tutti i pezzi in parcheggio
Dim nPartId As Integer = EgtGetFirstPart()
While nPartId <> GDB_ID.NULL
If PartIsFree(nPartId) Then
EgtSelectObj(nPartId)
VeinMatching.OnSelectPart(nPartId)
End If
nPartId = EgtGetNextPart(nPartId)
End While
End If
' Aggiorno vista
EgtDraw()
End Sub
#End Region ' SelectAllCommand
#Region "DeselectAllCommand"
Public ReadOnly Property DeselectAllCommand As ICommand
Get
If m_cmdDeselectAll Is Nothing Then
m_cmdDeselectAll = New Command(AddressOf DeselectAll)
End If
Return m_cmdDeselectAll
End Get
End Property
Public Sub DeselectAll(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Eseguo
EgtDeselectAll()
' Eventuale notifica al VeinMatching
VeinMatching.OnDeselectAll()
' Imposto flag posizione pezzi
m_nPartPos = PART_POS.NONE_TABLE
' Aggiorno vista
EgtDraw()
End Sub
#End Region ' DeselectAllCommand
#Region "ResetCommand"
Public ReadOnly Property ResetCommand As ICommand
Get
If m_cmdReset Is Nothing Then
m_cmdReset = New Command(AddressOf Reset)
End If
Return m_cmdReset
End Get
End Property
Public Sub Reset(ByVal param As Object)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
' Cancello eventuali messaggi
OmagOFFICEMap.refStatusBarVM.ClearOutputMessage()
' Cancello tutte le lavorazioni
CamAuto.EraseMachinings(GDB_ID.NULL)
' Reinserisco tutte le lavorazioni piane
CamAuto.AddMachinings(GDB_ID.NULL, True, False)
' Aggiorno visualizzazione
EgtDraw()
End Sub
#End Region ' ResetCommand
#End Region ' COMMANDS
#Region "EVENTS"
Friend Sub OnMouseDownScene(sender As Object, e As Windows.Forms.MouseEventArgs)
' Per default no drag
m_bDrag = False
' Verifico se selezionato indicativo di pezzo
EgtSetObjFilterForSelWin(True, True, True, True, True)
Dim nSel As Integer
EgtSelect(e.Location, Scene.DIM_SEL, Scene.DIM_SEL, nSel)
Dim nId As Integer = EgtGetFirstObjInSelWin()
While nId <> GDB_ID.NULL
' Recupero l'identificativo del pezzo cui appartiene
Dim nPartId As Integer = EgtGetParent(EgtGetParent(nId))
Dim bPartInTable As Boolean = (EgtGetParent(nPartId) = GetRawId())
If EgtIsPart(nPartId) Or bPartInTable Then
Dim nStat As Integer = GDB_ST.ON_
EgtGetStatus(nPartId, nStat)
' Se già selezionato o posizione oggetto incompatibile con flag posizione selezionati
If nStat = GDB_ST.SEL Then
' Memorizzo Id da deselezionare
m_nIdToDesel = nPartId
Else
' Memorizzo Id da selezionare
m_nIdToSel = nPartId
End If
' Drag possibile
m_bDrag = True
Exit While
End If
nId = EgtGetNextObjInSelWin()
End While
' Dati per drag
m_locPrev = e.Location
m_bDrag = m_bDrag AndAlso EgtUnProjectPoint(e.Location, m_ptPrev)
m_bDragToStart = m_bDrag
m_bVerify = m_bDrag AndAlso (Keyboard.Modifiers And ModifierKeys.Shift) > 0
m_vtTotMove = Vector3d.NULL()
End Sub
Friend Sub OnMouseMoveScene(sender As Object, e As System.Windows.Forms.MouseEventArgs)
' Se drag non abilitato o già in esecuzione, esco
If Not m_bDrag Or m_bDragging Then Return
' Se primo movimento di drag, verifico di aver superato la soglia di movimento in pixel
If m_bDragToStart Then
If Math.Abs(e.Location.X - m_locPrev.X) < m_nRestRadius And
Math.Abs(e.Location.Y - m_locPrev.Y) < m_nRestRadius Then
Return
End If
m_bDragToStart = False
End If
' Determino cosa muovere
Dim nMoveId = If(m_nIdToSel <> GDB_ID.NULL, m_nIdToSel, GDB_ID.SEL)
' Verifico se in tavola
Dim nTestId = If(nMoveId <> GDB_ID.SEL, nMoveId, EgtGetFirstSelectedObj())
If (EgtGetParent(nTestId) <> GetRawId()) Then Return
' Inizio esecuzione di drag
m_bDragging = True
' Ricavo il punto corrente in coordinate mondo
Dim ptCurr As Point3d
EgtUnProjectPoint(e.Location, ptCurr)
' Ricavo il vettore di movimento
Dim vtMove As Vector3d = ptCurr - m_ptPrev
' Muovo i pezzi selezionati di quanto possibile
If vtMove.SqLen() > EPS_SMALL * EPS_SMALL Then
' Se movimento con sola verifica finale
If m_bVerify Then
EgtMove(nMoveId, vtMove)
m_vtTotMove += vtMove
' altrimenti caso con verifica durante il movimento
Else
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' muovo il pezzo
EgtMovePart(nMoveId, CurrentMachine.bReducedCut, vtMove)
EgtSaveCollInfo()
' se movimento risultante nullo, provo con movimento tangente
Dim bTgMoved As Boolean = False
If vtMove.IsSmall() Then
' riprovo con movimento tangente
Dim vtTgMove As Vector3d = ptCurr - m_ptPrev
EgtTgMovePartOnCollision(nMoveId, CurrentMachine.bReducedCut, vtTgMove)
bTgMoved = (Not vtTgMove.IsSmall())
End If
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(nMoveId, CurrentMachine.bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(nMoveId, CurrentMachine.bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
EstCalc.ResetOrderMachiningFlag()
End If
EgtDraw()
' Eventuale notifica al VeinMatching
If nMoveId = GDB_ID.SEL Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
Else
VeinMatching.OnMovePartInRaw(nMoveId)
End If
End If
' Aggiorno il punto precedente
'm_ptPrev += vtMove
m_ptPrev = ptCurr
' Terminata esecuzione di drag
m_bDragging = False
End Sub
Friend Sub OnMouseUpScene(sender As Object, e As System.Windows.Forms.MouseEventArgs)
' Se eseguito drag
If Not m_bDragToStart Then
' Se movimento con sola verifica finale
If m_bVerify Then
' Determino cosa verificare
Dim nMoveId = If(m_nIdToSel <> GDB_ID.NULL, m_nIdToSel, GDB_ID.SEL)
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' Eseguo verifica
If EgtVerifyPart(nMoveId, CurrentMachine.bReducedCut) Then
EstCalc.ResetOrderMachiningFlag()
' Non superata riporto alla posizione iniziale
Else
EgtMove(nMoveId, -m_vtTotMove)
EgtDraw()
' Eventuale notifica al VeinMatching
If nMoveId = GDB_ID.SEL Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
Else
VeinMatching.OnMovePartInRaw(nMoveId)
End If
End If
' altrimenti caso con verifica durante il movimento
Else
' Basta reset alla fine
End If
' Se selezione da eseguire
ElseIf m_nIdToSel <> GDB_ID.NULL Then
' Determino se pezzo in tavola o in parcheggio
Dim bPartInTable As Boolean = (EgtGetParent(m_nIdToSel) = GetRawId())
' Se ci sono pezzi già selezionati nella posizione opposta, li deseleziono
If (bPartInTable And m_nPartPos = PART_POS.OUT_TABLE) Or
(Not bPartInTable And m_nPartPos = PART_POS.IN_TABLE) Then
EgtDeselectAll()
' Aggiornamento eventuale VeinMatching
VeinMatching.OnDeselectAll()
End If
' Eseguo la selezione
EgtSelectObj(m_nIdToSel)
' Eventuale aggiornamento VeinMatching
VeinMatching.OnSelectPart(m_nIdToSel)
' Set flag posizione selezionati
m_nPartPos = If(bPartInTable, PART_POS.IN_TABLE, PART_POS.OUT_TABLE)
' Se deselezione da eseguire
ElseIf m_nIdToDesel <> GDB_ID.NULL Then
EgtDeselectObj(m_nIdToDesel)
' Eventuale aggiornamento VeinMatching
VeinMatching.OnDeselectPart(m_nIdToDesel)
End If
' Reset
m_bDrag = False
m_nIdToSel = GDB_ID.NULL
m_nIdToDesel = GDB_ID.NULL
' Se nessun pezzo selezionato, reset flag posizione selezionati
If EgtGetSelectedObjCount() = 0 Then
m_nPartPos = PART_POS.NONE_TABLE
End If
EgtDraw()
End Sub
#End Region ' EVENTS
End Class