From 621bd11b3d117cbf34bb4b0af9b5a8a1abde3bb9 Mon Sep 17 00:00:00 2001 From: Nicola Pievani Date: Fri, 4 Oct 2024 13:32:08 +0200 Subject: [PATCH] Avvio programma con Args esterno --- Application.xaml.vb | 2 +- Assembly/Assembly.vb | 7 ++++-- Assembly/PartDoor.vb | 10 ++++++++ AssemblyManager/AssemblyManagerVM.vb | 4 ++++ DoorParameters/Part.vb | 9 +++++++ MainWindow/MainWindowV.xaml.vb | 35 ++++++++++++++++++++++++++++ MainWindow/MainWindowVM.vb | 4 ++++ My Project/AssemblyInfo.vb | 4 ++-- OptionsWindow/OptionModule.vb | 5 ++++ 9 files changed, 75 insertions(+), 5 deletions(-) diff --git a/Application.xaml.vb b/Application.xaml.vb index 9d4aa15..997fb74 100644 --- a/Application.xaml.vb +++ b/Application.xaml.vb @@ -9,7 +9,7 @@ Class Application MyBase.OnStartup(e) ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose ' Creo la View principale - Me.MainWindow = New MainWindowV + Me.MainWindow = New MainWindowV(e.Args) System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(Me.MainWindow) ' Mostro la View principale Me.MainWindow.Show() diff --git a/Assembly/Assembly.vb b/Assembly/Assembly.vb index e129ac4..14f97b2 100644 --- a/Assembly/Assembly.vb +++ b/Assembly/Assembly.vb @@ -1058,6 +1058,8 @@ Public Class Assembly If Not File.Exists(sPathDDF) Then Return End If + ' verifico se il file è un template + Dim bIsTemplate As Boolean = (Path.GetExtension(sPathDDF).ToLower = ".ddt") ReadAssembly.FileContent = File.ReadAllLines(sPathDDF) ' se il file esiste ma è vuoto If ReadAssembly.FileContent.Count = 0 Then @@ -1080,7 +1082,7 @@ Public Class Assembly Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nNothingSelected Else Map.refSceneManagerVM.EnableRefresh = False - If ReadAssembly.GetDDFDoor(IndexLine, sErrorInfo) = -1 Then + If ReadAssembly.GetDDFDoor(IndexLine, sErrorInfo, bIsTemplate) = -1 Then ' errore nella lettura di un part: blocco tutto ReadAssembly = Nothing Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False @@ -1468,10 +1470,11 @@ Public Class Assembly End Function ' dopo la lettura delle informazioni dell'assemblato - Private Function GetDDFDoor(IndexLine As Integer, ByRef sErrorInfo As String) As Integer + Private Function GetDDFDoor(IndexLine As Integer, ByRef sErrorInfo As String, Optional ByVal bIsTemplate As Boolean = False) As Integer Dim Line As Integer = IndexLine While Line < FileContent.Count - 1 AndAlso Not Search3Dots(FileContent(Line)) Dim Local_PartDoor As New PartDoor + Local_PartDoor.IsTemplate = bIsTemplate Dim Local_Door As New Part(Local_PartDoor) ' carcio la liste delle propiretà 'CreateNewPropertiesList(Local_Door.PropertiesList, Local_Door.SelectedMaterial) diff --git a/Assembly/PartDoor.vb b/Assembly/PartDoor.vb index a6baec5..07c3e86 100644 --- a/Assembly/PartDoor.vb +++ b/Assembly/PartDoor.vb @@ -7,6 +7,16 @@ Imports EgtWPFLib5 Public Class PartDoor Inherits VMBase + Private m_IsTemplate As Boolean = False + Public Property IsTemplate As Boolean + Get + Return m_IsTemplate + End Get + Set(value As Boolean) + m_IsTemplate = value + End Set + End Property + Private m_Door As Part Public Property Door As Part Get diff --git a/AssemblyManager/AssemblyManagerVM.vb b/AssemblyManager/AssemblyManagerVM.vb index 3cf651c..83077c4 100644 --- a/AssemblyManager/AssemblyManagerVM.vb +++ b/AssemblyManager/AssemblyManagerVM.vb @@ -981,6 +981,10 @@ Public Class AssemblyManagerVM OpenedAssName.IsModified = Part.FirstReadingEdge If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then DdfFile.WriteDDFPart(OpenedAssName.SelAssembly.ListPartDoor(0).Door, sTempFile, True, False) + If OptionModule.AdjustDDT Then + DdfFile.WriteDDFPart(OpenedAssName.SelAssembly.ListPartDoor(0).Door, OptionModule.SaveFileNameFromArgs, True, False) + End + End If ' aggiorno elenco quotature Map.refDimensioningPanelVM.LoadHardwareDimList() ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False) diff --git a/DoorParameters/Part.vb b/DoorParameters/Part.vb index 4ba0443..af928ca 100644 --- a/DoorParameters/Part.vb +++ b/DoorParameters/Part.vb @@ -2034,6 +2034,9 @@ Public Class Part If Index > FileContent.Count() - 1 Then Return -1 Dim sLine As String = RemoveComment(FileContent(Index)) Dim Width As String = GetValueWithKey(sLine, K_WIDTH) + If m_refPartDoor.IsTemplate And OptionModule.AdjustDDT Then + Width = OptionModule.m_Width + End If If String.IsNullOrWhiteSpace(Width) Then If Not SearchKey(sLine, K_WIDTH) Then Return -1 ' altrimenti @@ -2051,6 +2054,9 @@ Public Class Part If Index > FileContent.Count() - 1 Then Return -1 sLine = RemoveComment(FileContent(Index)) Dim Height As String = GetValueWithKey(sLine, K_HEIGHT) + If m_refPartDoor.IsTemplate And OptionModule.AdjustDDT Then + Height = OptionModule.m_Height + End If If String.IsNullOrWhiteSpace(Height) Then If Not SearchKey(sLine, K_HEIGHT) Then Return -1 ' altrimenti @@ -2068,6 +2074,9 @@ Public Class Part If Index > FileContent.Count() - 1 Then Return -1 sLine = RemoveComment(FileContent(Index)) Dim Thickness As String = GetValueWithKey(sLine, K_THICKNESS) + If m_refPartDoor.IsTemplate And OptionModule.AdjustDDT Then + Height = OptionModule.m_Thickness + End If If String.IsNullOrWhiteSpace(Thickness) Then If Not SearchKey(sLine, K_THICKNESS) Then Return -1 ' altrimenti diff --git a/MainWindow/MainWindowV.xaml.vb b/MainWindow/MainWindowV.xaml.vb index eec1fc6..639d5c7 100644 --- a/MainWindow/MainWindowV.xaml.vb +++ b/MainWindow/MainWindowV.xaml.vb @@ -2,8 +2,21 @@ Class MainWindowV + Private m_args() As String = Nothing + #Region "EVENTS" + Public Sub New(args As String()) + + ' La chiamata è richiesta dalla finestra di progettazione. + InitializeComponent() + If args.Length > 0 Then + m_args = args + End If + ' Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent(). + + End Sub + Private Sub MainWindowV_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded ' Carico e imposto posizione finestra WinPosFromIniToWindow(S_GENERAL, K_WINPLACE, Me) @@ -12,6 +25,28 @@ Class MainWindowV Private Sub MainWindowV_ContentRendered(sender As Object, e As EventArgs) Handles Me.ContentRendered ' se è assente la chiave di protezione non mostro la finestra Launcher If Map.refSceneManagerVM.bProtectKey Then + If Not IsNothing(m_args) Then + ' leggo gli argomenti + Dim Items() As String = m_args(0).Split(";"c) + If Items.Length = 5 Then + ' Avvio progetto - LauncherOpt.Open_last_project (1) + OptionModule.m_bLauncherOpenOnce = True + ' Indico il percorso del file + OptionModule.FileNameFromArgs = Items(0) + ' Assegno i valore Width, Height, Thickness + OptionModule.m_Width = Items(1) + OptionModule.m_Height = Items(2) + OptionModule.m_Thickness = Items(3) + ' Indico il percoso di salvataggio file DDF + OptionModule.SaveFileNameFromArgs = Items(4) + ' abilito lettura dati + OptionModule.AdjustDDT = True + Else + ' blocco lettura dati + OptionModule.AdjustDDT = False + End If + + End If Map.refMainWindowVM.SetLauncher() Map.refMainWindowVM.ShowErrorCompoLoad() End If diff --git a/MainWindow/MainWindowVM.vb b/MainWindow/MainWindowVM.vb index 83225d5..02c51d4 100644 --- a/MainWindow/MainWindowVM.vb +++ b/MainWindow/MainWindowVM.vb @@ -366,6 +366,10 @@ Public Class MainWindowVM Case LauncherOpt.Open_last_project ' se definito ultimo progetto, lo apro If GetMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, "", m_sLastProject) > 0 Then + ' se caricato il nome in avvio del programma allora sovrascrivo + If OptionModule.AdjustDDT Then + m_sLastProject = OptionModule.FileNameFromArgs + End If Map.refProjectManagerVM.OpenLastProject() End If Case Else diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb index 9404990..f217e91 100644 --- a/My Project/AssemblyInfo.vb +++ b/My Project/AssemblyInfo.vb @@ -72,5 +72,5 @@ Imports System.Windows ' by using the '*' as shown below: ' - - + + diff --git a/OptionsWindow/OptionModule.vb b/OptionsWindow/OptionModule.vb index d032779..d29a8ab 100644 --- a/OptionsWindow/OptionModule.vb +++ b/OptionsWindow/OptionModule.vb @@ -7,6 +7,11 @@ Friend Module OptionModule ' flag per modalità di visualizzazione file (solo lettura) Friend ReadOnlyDDF As Boolean = False + ' flag per forzare l'aggiornamento delle dimensioni anta dei file DDT + Friend AdjustDDT As Boolean = False + Friend FileNameFromArgs As String = String.Empty + Friend SaveFileNameFromArgs As String = String.Empty + ' Parametri che contengono lista delle lingue disponibili e lingua selezionata Friend m_LanguageList As New ObservableCollection(Of Language) Friend m_SelectedLanguage As Language