diff --git a/EgtCAM5.vbproj b/EgtCAM5.vbproj index fb5fbad..ca75f36 100644 --- a/EgtCAM5.vbproj +++ b/EgtCAM5.vbproj @@ -151,6 +151,10 @@ + + SelMachGroupWndV.xaml + + @@ -357,6 +361,10 @@ MainWindowV.xaml Code + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/MachGroupPanel/MachGroupPanelVM.vb b/MachGroupPanel/MachGroupPanelVM.vb index 0d9cea7..09f39e8 100644 --- a/MachGroupPanel/MachGroupPanelVM.vb +++ b/MachGroupPanel/MachGroupPanelVM.vb @@ -64,26 +64,177 @@ Public Class MachGroupPanelVM #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 + Dim nGroupId As Integer = GDB_ID.NULL + bOk = ManageDisposition(nGroupId) If bOk Then - 'CalculatePartsTranslationVt(bboxAllParts) - 'TraslateParts() LoadMachGroups() - SelectedMachGroup = MachGroupList(MachGroupList.Count() - 1) + Dim MachGroupName As String = "" + EgtGetMachGroupName(nGroupId, MachGroupName) + SelectedMachGroup = MachGroupList(MachGroupList.IndexOf(MachGroupName)) End If If IniFile.m_bShowOnlyTable Then EgtShowOnlyTable(True) Application.Msn.NotifyColleagues(Application.MACHGROUPSRESULT, bOk) End Sub + Private Function ManageDisposition(ByRef nGroupId As Integer) As Boolean + ' Ricerca pezzi selezionati + Dim bSelPart As Boolean = False + Dim vPart As New List(Of Integer) + Dim nId As Integer = EgtGetFirstSelectedObj() + While nId <> GDB_ID.NULL + Dim nPartId As Integer = EgtGetParent(EgtGetParent(nId)) + If nPartId <> GDB_ID.NULL Then + If Not vPart.Contains(nPartId) Then + vPart.Add(nPartId) + End If + End If + nId = EgtGetNextSelectedObj() + End While + bSelPart = vPart.Count > 0 + EgtDeselectAll() + ' Verifica esistenza gruppi di lavorazione + Dim bMachGroup As Boolean = (EgtGetMachGroupCount() > 0) + ' Se ci sono pezzi selezionati + If bSelPart Then + ' se ci sono gruppi di lavorazione + If bMachGroup Then + ' Creo lista dei gruppi di lavorazione + Dim MachGroupList As New List(Of Integer) + Dim GrpId As Integer = EgtGetFirstMachGroup() + While GrpId <> GDB_ID.NULL + MachGroupList.Add(GrpId) + GrpId = EgtGetNextMachGroup(GrpId) + End While + ' Elimino gruppi che contengono già un pezzo selezionato + For Index = MachGroupList.Count - 1 To 0 Step -1 + If PartsInMachGroup(vPart, MachGroupList(Index)) Then MachGroupList.Remove(MachGroupList(Index)) + Next + ' se la lista gruppi è vuota creo un nuovo gruppo + If MachGroupList.Count = 0 Then + AddNewMachGroup(nGroupId, vPart) + Return True + End If + ' altrimenti creo dialogo per scelta gruppi esistenti o nuovo gruppo + Dim SelMachGroupWndVM As New SelMachGroupWndVM(MachGroupList) + Dim SelMachGroupWndV As New SelMachGroupWndV(Application.Current.MainWindow, SelMachGroupWndVM) + If SelMachGroupWndV.ShowDialog() = False Then Return False + ' Verifico selezione in dialogo + Dim bOk As Boolean = False + Select Case SelMachGroupWndVM.MachGroupType + Case EgtCAM5.SelMachGroupWndVM.MGroupType.CHOOSEMGROUP + nGroupId = SelMachGroupWndVM.SelMachGroupId + bOk = AddToMachGroup(nGroupId, vPart) + Case EgtCAM5.SelMachGroupWndVM.MGroupType.NEWMGROUP + bOk = AddNewMachGroup(nGroupId, vPart) + End Select + Return bOk + ' altrimenti creo il primo gruppo + Else + Return AddNewMachGroup(nGroupId, vPart) + End If + ' Se non ci sono pezzi selezionati + Else + ' se ci sono gruppi di lavorazione + If bMachGroup Then + nGroupId = EgtGetLastMachGroup() + Return EgtSetCurrMachGroup(nGroupId) + ' altrimenti esco + Else + Return False + End If + End If + End Function + + Private Function ExecScript(sScriptPath As String, nGroupId As Integer, nPartId As Integer) As Boolean + EgtLuaCreateGlobTable("DISP") + EgtLuaSetGlobIntVar("DISP.GROUPID", nGroupId) + EgtLuaSetGlobIntVar("DISP.PARTID", nPartId) + If Not EgtLuaExecFile(sScriptPath) Then + EgtOutLog("Error executing disposition init script " & sScriptPath) + MessageBox.Show(EgtMsg(MSG_DISPOSITIONERRORS + 2) & " " & sScriptPath, EgtMsg(MSG_DISPOSITIONERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Exclamation) + Return False + End If + Dim nErr As Integer = 999 + EgtLuaGetGlobIntVar("DISP.ERR", nErr) + EgtLuaResetGlobVar("DISP") + Return nErr = 0 + End Function + + Private Function PartsInMachGroup(SelPartList As List(Of Integer), nGroupId As Integer) As Boolean + If Not EgtSetCurrMachGroup(nGroupId) Then Return False + Dim nRawId As Integer = EgtGetFirstRawPart() + While nRawId <> GDB_ID.NULL + Dim nPartId As Integer = EgtGetFirstPartInRawPart(nRawId) + While nPartId <> GDB_ID.NULL + If SelPartList.Contains(nPartId) Then + EgtResetCurrMachGroup() + Return True + End If + nPartId = EgtGetNextPartInRawPart(nPartId) + End While + nRawId = EgtGetNextRawPart(nRawId) + End While + EgtResetCurrMachGroup() + Return False + End Function + + Private Function AddToMachGroup(ByRef nGroupId As Integer, PartList As List(Of Integer)) As Boolean + ' leggo nome script di disposizione automatica + Dim bWithScript As Boolean = False + Dim sInitScriptPath As String = String.Empty + EgtUILib.GetPrivateProfileString(S_DISPOSITION, K_INITSCRIPT, "", sInitScriptPath, IniFile.m_sCurrMachIniFilePath) + ' se è attivo, uso lo script di disposizione + If OptionModule.m_bUseDispositionScript And Not String.IsNullOrEmpty(sInitScriptPath) Then + sInitScriptPath = IniFile.m_sCurrMachScriptsDirPath & "\" & sInitScriptPath + bWithScript = File.Exists(sInitScriptPath) + End If + If bWithScript Then + ' Rendo corrente il gruppo di lavoro + EgtSetCurrMachGroup(nGroupId) + ' Creo grezzo e posiziono i pezzi + For Each Part In PartList + ExecScript(sInitScriptPath, nGroupId, Part) + Next + Else + EgtOutLog("Machine without InitDisp script.") + Return False + End If + Return True + End Function + + Private Function AddNewMachGroup(ByRef nGroupId As Integer, PartList As List(Of Integer)) As Boolean + ' leggo nome script di disposizione automatica + Dim bWithScript As Boolean = False + Dim sInitScriptPath As String = String.Empty + EgtUILib.GetPrivateProfileString(S_DISPOSITION, K_INITSCRIPT, "", sInitScriptPath, IniFile.m_sCurrMachIniFilePath) + ' se è attivo, uso lo script di disposizione + If OptionModule.m_bUseDispositionScript And Not String.IsNullOrEmpty(sInitScriptPath) Then + sInitScriptPath = IniFile.m_sCurrMachScriptsDirPath & "\" & sInitScriptPath + bWithScript = File.Exists(sInitScriptPath) + End If + If bWithScript Then + Dim sMgName As String = "Mach_1" + EgtGetMachGroupNewName(sMgName) + nGroupId = EgtAddMachGroup(sMgName) + If nGroupId = GDB_ID.NULL Then + EgtOutLog("Errore nella creazione del gruppo di lavoro " & sMgName) + MessageBox.Show("Errore nella creazione del gruppo di lavoro", "Lavora", MessageBoxButton.OK, MessageBoxImage.Error) + Return False + End If + ' Creo grezzo e posiziono i pezzi + For Each Part In PartList + ExecScript(sInitScriptPath, nGroupId, Part) + Next + Else + EgtOutLog("Machine without InitDisp script.") + Return False + End If + ' Gestisco eventuale attrezzaggio di default + ManageDefaultSetUp() + Return True + End Function + Private Sub CalculateAllPartsBbox(ByRef bboxAllParts As BBox3d) Dim nPart As Integer = EgtGetFirstPart() While nPart <> GDB_ID.NULL @@ -128,34 +279,18 @@ Public Class MachGroupPanelVM 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 + Private Sub ManageDefaultSetUp() ' 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 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 Sub #End Region @@ -200,15 +335,15 @@ Public Class MachGroupPanelVM 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 + '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 diff --git a/SelMachGroupWnd/SelMachGroupWndV.xaml b/SelMachGroupWnd/SelMachGroupWndV.xaml new file mode 100644 index 0000000..e3354f4 --- /dev/null +++ b/SelMachGroupWnd/SelMachGroupWndV.xaml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +