Merge commit '12081cec286176e5b9067a1fa81cf6eb1c57a0b6'

This commit is contained in:
Dario Sassi
2024-01-09 17:46:53 +01:00
11 changed files with 448 additions and 10 deletions
+1
View File
@@ -53,6 +53,7 @@ Public Module ConstGen
' Abilitazioni licenza
Friend Enum KEY_OPT As UInteger
BASE = 1 ' Prodotto Icarus
MACHINE_EXPORT = 2 ' opzione per esportare file icrx per macchina
End Enum
' File di log generale
+4
View File
@@ -87,6 +87,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\EgtProg\DllD32\EgtWPFLib5.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework.Aero2" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
@@ -320,6 +323,7 @@
<Compile Include="Utility\DisableModifiedMgr.vb" />
<Compile Include="Utility\EgwCrypto.vb" />
<Compile Include="Utility\GeomEntityColors.vb" />
<Compile Include="Utility\JsonUtility.vb" />
<Compile Include="Utility\LuaExec.vb" />
<Compile Include="Utility\Map.vb" />
<Compile Include="Utility\MyMachine.vb" />
+30 -1
View File
@@ -2,6 +2,7 @@
Imports System.IO
Imports EgtWPFLib5
Imports EgtUILib
Imports Newtonsoft.Json
Public Class ProjManagerVM
Inherits VMBase
@@ -247,9 +248,37 @@ Public Class ProjManagerVM
''' Execute the Save. This method is invoked by the SaveCommand.
''' </summary>
Public Sub Save()
If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then
CreateJson()
End If
Map.refSceneHostVM.SaveProject()
End Sub
Private Function CreateJson() As Boolean
' creo json
Dim LayerList As New List(Of JsonLayer)
For Each Layer In Map.refTFSEditorVM.LayerList
LayerList.Add(Layer.ConvertToJsonLayer())
Next
Dim json As String = JsonConvert.SerializeObject(LayerList, Formatting.Indented)
Dim sProjName As String = ""
EgtGetCurrFilePath(sProjName)
If Not String.IsNullOrWhiteSpace(sProjName) Then
sProjName = Path.ChangeExtension(sProjName, ".json")
If File.Exists(sProjName) Then
Try
File.Delete(sProjName)
Catch ex As Exception
End Try
End If
Try
File.AppendAllText(sProjName, json)
Catch ex As Exception
EgtOutLog("Json writing error!")
End Try
End If
End Function
#End Region ' SaveCommand
#Region "SaveAsCommand"
@@ -385,7 +414,7 @@ Public Class ProjManagerVM
Map.refSceneHostVM.SaveProject()
End If
EgtGetCurrFilePath(sCurrProject)
' se modificato, chiedo se si vuole salvare
' se modificato, chiedo se si vuole salvare
Else
If EgtGetModified() Then
If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
+20
View File
@@ -675,6 +675,26 @@ Public Class MySceneHostVM
Return MainController.ExportProject(SaveFileDialog.FileName, False)
End Function
Public Function ExportProjectForMachine(sFilePath As String) As Boolean
' Reset controller e scena
MainController.ResetStatus()
MainController.SetDefaultFilterForExport(EEX_FLT.MODE_HIDDEN + EEX_FLT.MODE_STD + EEX_FLT.STAT_ON + EEX_FLT.STAT_OFF + EEX_FLT.LEV_TEMP)
Return MainController.ExportGeomId(Map.refTopPanelVM.SelPart.nPartId, sFilePath, False)
End Function
Public Function ExportProjectForMachine(sDirPath As String, b3dm As Boolean, ByRef sFilePath As String) As Boolean
sFilePath = sDirPath & "\ProjectSlice" & If(b3dm, ".3dm", ".3mf")
' Reset controller e scena
MainController.ResetStatus()
MainController.SetDefaultFilterForExport(EEX_FLT.MODE_HIDDEN + EEX_FLT.MODE_STD + EEX_FLT.STAT_ON + EEX_FLT.STAT_OFF + EEX_FLT.LEV_TEMP)
Dim nExportGeomId As Integer = 0
If b3dm Then
If Not ExecPrepare3dmExport(nExportGeomId) Then Return False
Else
nExportGeomId = Map.refTopPanelVM.SelPart.nPartId
End If
Return MainController.ExportGeomId(nExportGeomId, sFilePath, False)
End Function
Public Overrides Function ExecScript(sFilePath As String) As Boolean
Dim bOk As Boolean = False
If String.IsNullOrEmpty(sFilePath) Then
+162 -7
View File
@@ -2,6 +2,8 @@
Imports EgtUILib
Imports Microsoft.Win32
Imports System.IO
Imports Ionic.Zip
Imports Newtonsoft.Json
Public Class SliceManagerVM
Inherits VMBase
@@ -705,17 +707,34 @@ Public Class SliceManagerVM
End If
End If
' eseguo calcoli
CalcSlice(True, True)
Dim bOk As Boolean = CalcSlice(True, True)
' se non ho interrotto calcoli
If Not m_bStopScriptToManage Then
If bShiftPressed Then
' Se esiste ne lancio l'editing
If File.Exists(sIsoFilePath) Then
If bOk AndAlso Not m_bStopScriptToManage Then
' Se esiste l'iso
If File.Exists(sIsoFilePath) Then
If bShiftPressed Then
' Se esiste ne lancio l'editing
Process.Start("Notepad.exe", sIsoFilePath)
' altrimenti lo segnalo
Else
MessageBox.Show("Edit failed, missing part program file" & " (" & sIsoFilePath & ")")
End If
' verifico se creare pacchetto
If Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.MACHINE_EXPORT) Then
'If True Then
If Not CreateProjectForMachine(sIsoFilePath) Then
MessageBox.Show("Icrx file generation failed!!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error)
End If
' riabilito ProjManager, TopPanel e uscita dal programma
Map.refProjManagerVM.SetProjCmdIsEnabled(True)
Map.refTopPanelVM.SetTopPanelIsEnabled(True)
Map.refViewLayerManagerVM.SetViewLayerManagerIsEnabled(True)
Map.refTFSEditorVM.SetTFSEditorIsEnabled(True)
Map.refSliderManagerVM.SetLayerIndexIsEnabled(True)
Map.refSliderManagerVM.SetLayerAdvancementIsEnabled(True)
SetButtonsIsEnabled(True)
End If
Else
' altrimenti lo segnalo
MessageBox.Show("Part program generation failed!!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End If
NotifyPropertyChanged(NameOf(Time_Visibility))
NotifyPropertyChanged(NameOf(Mass_Visibility))
@@ -725,6 +744,142 @@ Public Class SliceManagerVM
m_bCalculating = False
End Sub
Private Function CreateProjectForMachine(sIsoFilePath As String) As Boolean
' disabilito ProjManager, TopPanel, TFS, Slider, bottoni e uscita dal programma
Map.refProjManagerVM.SetProjCmdIsEnabled(False)
Map.refTopPanelVM.SetTopPanelIsEnabled(False)
Map.refViewLayerManagerVM.SetViewLayerManagerIsEnabled(False)
Map.refTFSEditorVM.SetTFSEditorIsEnabled(False)
Map.refSliderManagerVM.SetLayerIndexIsEnabled(False)
Map.refSliderManagerVM.SetLayerAdvancementIsEnabled(False)
SetButtonsIsEnabled(False)
' creo cartella file da esportare in Temp
Dim sExportTempFolderPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\MachineExport"
If Directory.Exists(sExportTempFolderPath) Then
Try
Directory.Delete(sExportTempFolderPath, True)
Catch ex As Exception
EgtOutLog("Error! Impossible deleting folder " & sExportTempFolderPath & "!")
Return False
End Try
End If
Try
Directory.CreateDirectory(sExportTempFolderPath)
Catch ex As Exception
EgtOutLog("Error! Impossible creating folder " & sExportTempFolderPath & "!")
Return False
End Try
' mostro solido per eportazione
Dim SolidCheck As ViewLayer = Map.refViewLayerManagerVM.LayerList.FirstOrDefault(Function(x) x.Type = ViewLayer.ViewLayerType.SOLID_SLICE)
Dim CurrSolidCheckValue As Boolean? = SolidCheck.bIsVisible
If IsNothing(SolidCheck.bIsVisible) OrElse Not SolidCheck.bIsVisible Then
SolidCheck.bIsVisible = True
End If
' esporto file progetto
Dim sFileExtension As String
If True Then
sFileExtension = ".3dm"
Else
sFileExtension = ".3mf"
End If
Dim s3dFilePath As String = ""
If Not Map.refSceneHostVM.ExportProjectForMachine(sExportTempFolderPath, True, s3dFilePath) Then
EgtOutLog("Error! Impossible exporting 3mf file!")
Return False
End If
'' esporto file 3mf
'Dim s3mfPath As String = sExportTempFolderPath & "\ProjectSlice.3mf"
'If Not Map.refSceneHostVM.ExportProjectForMachine(s3mfPath) Then
' EgtOutLog("Error! Impossible exporting 3mf file!")
' Return False
'End If
' creo file json
Dim sProjName As String = ""
EgtGetCurrFilePath(sProjName)
Dim sJsonPath As String = sExportTempFolderPath & "\ProjectSlice.json"
CreateJson(sJsonPath)
' creo immagine preview
Dim sPreviewImagePath As String = sExportTempFolderPath & "\ProjectSlice.png"
CreatePreviewImage(sPreviewImagePath)
' nascondo solido
If IsNothing(CurrSolidCheckValue) OrElse Not CurrSolidCheckValue Then
SolidCheck.bIsVisible = CurrSolidCheckValue
End If
' creo path dello zip
Dim sZipPath As String = Path.ChangeExtension(sProjName, ".icrx")
' se esiste gia' lo cancello
If File.Exists(sZipPath) Then
Try
File.Delete(sZipPath)
Catch ex As Exception
EgtOutLog("Error! Impossible deleting old icrx file!")
Return False
End Try
End If
Try
Using zip As New Ionic.Zip.ZipFile(sZipPath, Console.Out)
zip.AlternateEncodingUsage = ZipOption.Always
zip.AlternateEncoding = Text.Encoding.UTF8
zip.CompressionMethod = CompressionMethod.None
' aggiungo file Iso
zip.AddItem(sIsoFilePath, "").FileName = "ProjectSlice" & Path.GetExtension(sIsoFilePath)
' aggiungo file 3mf
zip.AddItem(s3dFilePath, "")
' aggiungo json
zip.AddItem(sJsonPath, "")
' aggiungo immagine preview
zip.AddItem(sPreviewImagePath, "")
' salvo lo zip
zip.Save()
End Using
Catch ex As Exception
EgtOutLog("Error! Icrx file generation failed!!")
Return False
End Try
' elimino tutti i file temporanei creati
If Directory.Exists(sExportTempFolderPath) Then
Directory.Delete(sExportTempFolderPath, True)
End If
Return True
End Function
Private Function CreateJson(sJsonPath As String) As Boolean
' creo json
Dim JsonMain As New JsonMain(m_dTime, m_dMass)
Dim json As String = JsonConvert.SerializeObject(JsonMain, Formatting.Indented)
If File.Exists(sJsonPath) Then
Try
File.Delete(sJsonPath)
Catch ex As Exception
EgtOutLog("Error! Impossible deleting file " & sJsonPath & "!")
Return False
End Try
End If
Try
File.AppendAllText(sJsonPath, json)
Catch ex As Exception
EgtOutLog("Error! Impossible writing json file " & sJsonPath & "!")
Return False
End Try
Return True
End Function
Private Function CreatePreviewImage(sPreviewImagePath As String) As Boolean
' recupero posizione vista corrente
Dim nCurrAngVertDeg As Integer = 0
Dim nCurrAngHorizDeg As Integer = 0
EgtGetGenericView(nCurrAngVertDeg, nCurrAngHorizDeg)
EgtSetView(VT.ISO_SW, False)
SetTableVisibility(False)
EgtZoom(ZM.ALL, False)
'EgtExportSvg(GDB_ID.ROOT, sPreviewImagePath)
EgtGetImage(SM.SHADING, New Color3d(255, 255, 255, 255), New Color3d(255, 255, 255, 255), 3000, 3000, sPreviewImagePath)
EgtSetGenericView(nCurrAngVertDeg, nCurrAngHorizDeg, False)
SetTableVisibility(True)
EgtZoom(ZM.ALL, True)
Return True
End Function
#End Region ' Generate
#Region "Simulate"
+5 -1
View File
@@ -962,4 +962,8 @@ Public Class TFSLayer
Return If(dHours > 0, dHours.ToString("00") & ":", "") & If(dHours > 0, dMinutes.ToString("00"), dMinutes.ToString()) & ":" & dSeconds.ToString("00")
End Function
End Class
Friend Function ConvertToJsonLayer() As JsonLayer
Return New JsonLayer(nIndex, dLength, dTMin, m_dTTrg, dTMax, dTCurr, m_dTWait, dFCurr, m_dFTrg, m_dFMax, m_dFCurr, dSpeed)
End Function
End Class
+5
View File
@@ -158,6 +158,11 @@ Public Module CurrentMachine
DisableMgr.ReEnable()
End Sub
Public Sub SetTableVisibility(IsVisible As Boolean)
Dim nTableLayerId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, TABLE)
EgtSetStatus(nTableLayerId, If(IsVisible, GDB_ST.ON_, GDB_ST.OFF))
End Sub
Public Sub UpdateExtrusionArea()
Dim DisableMgr As New DisableModifiedMgr
' recupero eventuale vecchia area di estrusione
+205
View File
@@ -0,0 +1,205 @@
Imports EgtUILib.EgtInterface
Imports EgtWPFLib5
Public Class JsonMain
Private m_StrandW As Double
Public ReadOnly Property StrandW As Double
Get
Return m_StrandW
End Get
End Property
Private m_StrandH As Double
Public ReadOnly Property StrandH As Double
Get
Return m_StrandH
End Get
End Property
Private m_BoxX As Double
Public ReadOnly Property BoxX As Double
Get
Return m_BoxX
End Get
End Property
Private m_BoxY As Double
Public ReadOnly Property BoxY As Double
Get
Return m_BoxY
End Get
End Property
Private m_BoxZ As Double
Public ReadOnly Property BoxZ As Double
Get
Return m_BoxZ
End Get
End Property
Private m_dTime As Double
Public ReadOnly Property dTime As Double
Get
Return m_dTime
End Get
End Property
Private m_dMass As Double = 0
Public ReadOnly Property dMass As Double
Get
Return m_dMass
End Get
End Property
Private m_LayerQty As Double
Public ReadOnly Property LayerQty As Double
Get
Return m_LayerQty
End Get
End Property
Private m_MaterialName As String
Public ReadOnly Property MaterialName As String
Get
Return m_MaterialName
End Get
End Property
Private m_JsonLayerList As New List(Of JsonLayer)
Public ReadOnly Property JsonLayerList As List(Of JsonLayer)
Get
Return m_JsonLayerList
End Get
End Property
Sub New(dTime As Double, dMass As Double)
For Each Layer In Map.refTFSEditorVM.LayerList
m_JsonLayerList.Add(Layer.ConvertToJsonLayer())
Next
m_MaterialName = Map.refTopPanelVM.SelMaterial.sName
Dim GeneralCathegory As MachiningCathegory = Map.refCurrMachiningPanelVM.CurrMachining.CathegoryList.FirstOrDefault(Function(x) x.Type = MachiningCathegory.Cathegories.GENERAL)
If Not IsNothing(GeneralCathegory) Then
Dim StrandW As CurrNumericMachiningParam = GeneralCathegory.MachiningParamList.FirstOrDefault(Function(y) y.Type = MachiningParam.Params.STRANDW)
Dim StrandH As CurrNumericMachiningParam = GeneralCathegory.MachiningParamList.FirstOrDefault(Function(y) y.Type = MachiningParam.Params.STRANDH)
If Not IsNothing(StrandW) Then
m_StrandW = StrandW.dValue
End If
If Not IsNothing(StrandH) Then
m_StrandH = StrandH.dValue
End If
End If
m_dTime = dTime
m_dMass = dMass
If Not IsNothing(Map.refTopPanelVM.SelPart) Then
Dim b3Print As BBox3d = Map.refDispositionPanelVM.GetSolidForReferenceBBox(Map.refTopPanelVM.SelPart)
m_BoxX = b3Print.DimX
m_BoxY = b3Print.DimY
m_BoxZ = b3Print.DimZ
End If
m_LayerQty = Map.refSliderManagerVM.nLayerIndex_Maximum
End Sub
End Class
Public Class JsonLayer
Private m_nIndex As Integer
Public ReadOnly Property Index As Integer
Get
Return m_nIndex
End Get
End Property
Private m_dLength As Double
Public ReadOnly Property Length As Double
Get
Return m_dLength
End Get
End Property
Private m_dTMin As Double
Public ReadOnly Property TMin As Double
Get
Return m_dTMin
End Get
End Property
Private m_dTTrg As Double
Public ReadOnly Property TTrg As Double
Get
Return m_dTTrg
End Get
End Property
Private m_dTMax As Double
Public ReadOnly Property TMax As Double
Get
Return m_dTMax
End Get
End Property
Private m_dTCurr As Double
Public ReadOnly Property TCurr As Double
Get
Return m_dTCurr
End Get
End Property
Private m_dTWait As Double
Public ReadOnly Property TWait As Double
Get
Return m_dTWait
End Get
End Property
Private m_dFMin As Double
Public ReadOnly Property FMin As Double
Get
Return m_dFMin
End Get
End Property
Private m_dFTrg As Double
Public ReadOnly Property FTrg As Double
Get
Return m_dFTrg
End Get
End Property
Private m_dFMax As Double
Public ReadOnly Property FMax As Double
Get
Return m_dFMax
End Get
End Property
Private m_dFCurr As Double
Public ReadOnly Property FCurr As Double
Get
Return m_dFCurr
End Get
End Property
Private m_dSpeed As Double
Public ReadOnly Property Speed As Double
Get
Return m_dSpeed
End Get
End Property
Sub New(nIndex As Integer, dLength As Double, dTMin As Double, dTTrg As Double, dTMax As Double, dTCurr As Double, dTWait As Double, dFMin As Double, dFTrg As Double, dFMax As Double, dFCurr As Double, dSpeed As Double)
m_nIndex = nIndex
m_dLength = dLength
m_dTMin = dTMin
m_dTTrg = dTTrg
m_dTMax = dTMax
m_dTCurr = dTCurr
m_dTWait = dTWait
m_dFMin = dFMin
m_dFTrg = dFTrg
m_dFMax = dFMax
m_dFCurr = dFCurr
m_dSpeed = dSpeed
End Sub
End Class
+14
View File
@@ -115,4 +115,18 @@ Module LuaExec
Return bOk
End Function
Friend Function ExecPrepare3dmExport(ByRef nExportGeomId As Integer) As Boolean
Dim bOk As Boolean = True
EgtLuaCreateGlobTable("PRINT")
EgtLuaSetGlobStringVar("PRINT.BASEDIR", Map.refMainWindowVM.MainWindowM.s3dPrintingDir)
bOk = EgtLuaExecFile(Map.refMainWindowVM.MainWindowM.s3dPrintingDir & "\PrepareExport.lua")
If bOk Then
EgtLuaGetGlobIntVar("PRINT.EXPORTLAYER", nExportGeomId)
End If
' Cancello tavola globale
EgtLuaResetGlobVar("PRINT")
Return bOk
End Function
End Module
@@ -35,7 +35,7 @@ Public Class ViewLayerManagerVM
End Sub
Sub New()
' Creo riferimento a questa classe in EgtCAM5Map
' Creo riferimento a questa classe in Map
Map.SetRefViewLayerManagerVM(Me)
m_LayerList = New ObservableCollection(Of ViewLayer)({New ViewLayer(ViewLayer.ViewLayerType.PRINT_SOLID, "Print", True),
New ViewLayer(ViewLayer.ViewLayerType.REFERENCE, "Origin Point", True),
+1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Ionic.Zip" version="1.9.1.8" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net472" />
</packages>