Files
EgtCAM5/MachGroupPanel/MachGroupPanelVM.vb
T
Emmanuele Sassi a4b5cd4834 EgtCAM5 :
- Cambiati nomi classi e file.
2018-04-10 17:08:35 +00:00

279 lines
11 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Namespace EgtCAM5
Public Class MachGroupPanelVM
Inherits ViewModelBase
#Region "FIELDS & PROPERTIES"
Private m_MachGroupList As New ObservableCollection(Of String)
Public Property MachGroupList As ObservableCollection(Of String)
Get
Return m_MachGroupList
End Get
Set(value As ObservableCollection(Of String))
If value IsNot m_MachGroupList Then
m_MachGroupList = value
End If
End Set
End Property
Private m_SelectedMachGroup As String
Public Property SelectedMachGroup As String
Get
Return m_SelectedMachGroup
End Get
Set(value As String)
m_SelectedMachGroup = value
OnPropertyChanged("SelectedMachGroup")
End Set
End Property
Private m_IsEnabled As Boolean = True
Public Property MachGroupPanelIsEnabled As Boolean
Get
Return m_IsEnabled
End Get
Set(value As Boolean)
m_IsEnabled = value
OnPropertyChanged("MachGroupPanelIsEnabled")
End Set
End Property
' Definizione comandi
Private m_cmdSetCurrMachGroup As ICommand
Private m_cmdAddMachGroup As ICommand
Private m_cmdRemoveMachGroup As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
Application.Msn.Register(Application.INITIALIZEMACHGROUPS, Sub()
InitializeMachGroups()
End Sub)
Application.Msn.Register(Application.MACHGROUPSISENABLED, Sub(MgpIsEnabled As Boolean)
Me.MachGroupPanelIsEnabled = MgpIsEnabled
End Sub)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Private Sub InitializeMachGroups()
' calcolo bbox di tutti i pezzi disegnati
'Dim bboxAllParts As New BBox3d
'CalculateAllPartsBbox(bboxAllParts)
Dim bOk As Boolean = False
Dim nId = EgtGetLastMachGroup()
If nId <> GDB_ID.NULL Then
bOk = EgtSetCurrMachGroup(nId)
Else
bOk = AddNewMachGroup()
End If
If bOk Then
'CalculatePartsTranslationVt(bboxAllParts)
'TraslateParts()
LoadMachGroups()
SelectedMachGroup = MachGroupList(MachGroupList.Count() - 1)
End If
If IniFile.m_bShowOnlyTable Then EgtShowOnlyTable(True)
Application.Msn.NotifyColleagues(Application.MACHGROUPSRESULT, bOk)
End Sub
Private Sub CalculateAllPartsBbox(ByRef bboxAllParts As BBox3d)
Dim nPart As Integer = EgtGetFirstPart()
While nPart <> GDB_ID.NULL
Dim bboxPart As New BBox3d
EgtGetBBoxGlob(nPart, GDB_BB.STANDARD, bboxPart)
bboxAllParts.Add(bboxPart)
nPart = EgtGetNextPart(nPart)
End While
End Sub
Private Sub CalculatePartsTranslationVt(bboxAllParts As BBox3d)
' recupero area della tavola
Dim ptTableMin As Point3d
Dim ptTableMax As Point3d
Dim X = EgtGetTableArea(1, ptTableMin, ptTableMax)
IniFile.m_vtMachPartsPos = (New Point3d(ptTableMin.x, ptTableMin.y - 250, ptTableMin.z) - New Point3d(bboxAllParts.Min.x, bboxAllParts.Max.y, bboxAllParts.Min.z))
End Sub
Private Sub TraslateParts()
Dim nPart As Integer = EgtGetFirstPart()
While nPart <> GDB_ID.NULL
EgtMove(nPart, IniFile.m_vtMachPartsPos)
nPart = EgtGetNextPart(nPart)
End While
nPart = EgtGetFirstGhostPart()
While nPart <> GDB_ID.NULL
EgtMove(nPart, IniFile.m_vtMachPartsPos)
nPart = EgtGetNextGhostPart(nPart)
End While
End Sub
Private Sub LoadMachGroups()
' Pulisco la lista
MachGroupList.Clear()
' Carico i gruppi di lavorazione nella lista
Dim nId = EgtGetFirstMachGroup()
While nId <> GDB_ID.NULL
Dim sName As String = String.Empty
EgtGetMachGroupName(nId, sName)
MachGroupList.Add(sName)
nId = EgtGetNextMachGroup(nId)
End While
End Sub
Private Function AddNewMachGroup() As Boolean
' Creazione nuovo gruppo di lavorazione
Dim sNewMachName As String = "Mach_1"
EgtGetMachGroupNewName(sNewMachName)
Dim bOk As Boolean = (EgtAddMachGroup(sNewMachName) <> GDB_ID.NULL)
' leggo nome script di disposizione automatica
Dim sInitScriptPath As String = String.Empty
EgtUILib.GetPrivateProfileString(S_DISPOSITION, K_INITSCRIPT, "", sInitScriptPath, IniFile.m_sCurrMachIniFilePath)
' se è attivo, uso lo script di disposizione
If bOk AndAlso OptionModule.m_bUseDispositionScript And Not String.IsNullOrEmpty(sInitScriptPath) Then
sInitScriptPath = IniFile.m_sCurrMachScriptsDirPath & "\" & sInitScriptPath
If Not File.Exists(sInitScriptPath) OrElse Not EgtLuaExecFile(sInitScriptPath) Then
EgtOutLog("Error executing disposition init script " & sInitScriptPath)
MessageBox.Show(EgtMsg(MSG_DISPOSITIONERRORS + 2) & " " & sInitScriptPath, EgtMsg(MSG_DISPOSITIONERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Exclamation)
End If
End If
' leggo nome attrezzaggio di default
Dim sDefaultSetUpName As String = String.Empty
EgtUILib.GetPrivateProfileString(S_SETUP, K_DEFAULT, "", sDefaultSetUpName, IniFile.m_sCurrMachIniFilePath)
' se è attiva l'opzione, rendo corrente l'attrezzaggio di default
If bOk And Not String.IsNullOrEmpty(sDefaultSetUpName) Then
If Not EgtImportSetup(String.Empty) Then
EgtOutLog("Error loading default setup " & sDefaultSetUpName)
MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 9) & " " & sDefaultSetUpName, EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Exclamation)
End If
End If
Return bOk
End Function
#End Region
#Region "COMMANDS"
#Region "SetCurrMachGroupCommand"
''' <summary>
''' Returns a command that set the selected MachGroup as the Current one.
''' </summary>
Public ReadOnly Property SetCurrMachGroupCommand As ICommand
Get
If m_cmdSetCurrMachGroup Is Nothing Then
m_cmdSetCurrMachGroup = New RelayCommand(AddressOf SetCurrMachGroup)
End If
Return m_cmdSetCurrMachGroup
End Get
End Property
Public Sub SetCurrMachGroup(ByVal param As Object)
EgtSetCurrMachGroup(EgtGetMachGroupId(DirectCast(param, String)))
If IniFile.m_bShowOnlyTable Then EgtShowOnlyTable(True)
EgtZoom(ZM.ALL)
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, -1)
Application.Msn.NotifyColleagues(Application.UPDATECURRENTMACHINE)
End Sub
#End Region ' SetCurrMachGroupCommand
#Region "AddMachGroupCommand"
''' <summary>
''' Returns a command that set the selected MachGroup as the Current one.
''' </summary>
Public ReadOnly Property AddMachGroupCommand As ICommand
Get
If m_cmdAddMachGroup Is Nothing Then
m_cmdAddMachGroup = New RelayCommand(AddressOf AddMachGroup)
End If
Return m_cmdAddMachGroup
End Get
End Property
Public Sub AddMachGroup()
If AddNewMachGroup() Then
Dim sMachName As String = String.Empty
EgtGetMachGroupName(EgtGetCurrMachGroup(), sMachName)
MachGroupList.Add(sMachName)
SelectedMachGroup = sMachName
EgtDraw()
Application.Msn.NotifyColleagues(Application.LOADOPERATIONLIST, -1)
Application.Msn.NotifyColleagues(Application.UPDATECURRENTMACHINE)
End If
End Sub
#End Region ' AddMachGroupCommand
#Region "RemoveMachGroupCommand"
''' <summary>
''' Returns a command that set the selected MachGroup as the Current one.
''' </summary>
Public ReadOnly Property RemoveMachGroupCommand As ICommand
Get
If m_cmdRemoveMachGroup Is Nothing Then
m_cmdRemoveMachGroup = New RelayCommand(AddressOf RemoveMachGroup)
End If
Return m_cmdRemoveMachGroup
End Get
End Property
Public Sub RemoveMachGroup()
' Calcolo indice del gruppo da cancellare
Dim nSelectedMachGroupIndex As Integer = MachGroupList.IndexOf(SelectedMachGroup)
If nSelectedMachGroupIndex = 0 And MachGroupList.Count = 1 Then
' chiedo conferma prima di cancellare il gruppo di lavorazione
Select Case MessageBox.Show(EgtMsg(MSG_MACHGROUP + 2), "", MessageBoxButton.YesNo, MessageBoxImage.Question)
Case MessageBoxResult.Yes
' cancello il gruppo corrente
EgtRemoveMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex)))
' aggiorno la lista dei gruppi
MachGroupList.RemoveAt(nSelectedMachGroupIndex)
' ritorno alla modalità disegno
Map.refTopCommandBarVM.DrawIsChecked = True
Case MessageBoxResult.No
Return
End Select
Else
' chiedo conferma prima di cancellare il gruppo di lavorazione
Select Case MessageBox.Show(EgtMsg(MSG_MACHGROUP + 2), "", MessageBoxButton.YesNo, MessageBoxImage.Question)
Case MessageBoxResult.Yes
If nSelectedMachGroupIndex = 0 And MachGroupList.Count > 1 Then
' rendo corrente il gruppo di lavorazione successivo a quello da cancellare
EgtSetCurrMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex + 1)))
SelectedMachGroup = MachGroupList(nSelectedMachGroupIndex + 1)
ElseIf nSelectedMachGroupIndex > 0 Then
' rendo corrente il gruppo di lavorazione precedente a quello da cancellare
EgtSetCurrMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex - 1)))
SelectedMachGroup = MachGroupList(nSelectedMachGroupIndex - 1)
End If
EgtDraw()
' cancello quello selezionato
EgtRemoveMachGroup(EgtGetMachGroupId(MachGroupList(nSelectedMachGroupIndex)))
' aggiorno la lista dei gruppi
MachGroupList.RemoveAt(nSelectedMachGroupIndex)
Case MessageBoxResult.No
Return
End Select
End If
End Sub
#End Region ' RemoveMachGroupCommand
#End Region ' COMMANDS
End Class
End Namespace