Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.Text.RegularExpressions Imports System.IO Imports EgtUILib Imports EgtWPFLib5 Imports EgtCAM5.Utility ''' ''' Class that represent a Tool in the treeview. ''' It's an element in the treeview that represent the child of familytooltreeviewitem, but also the class that read and write in the tool's database ''' Public Class ToolTreeViewItem Inherits InheritableTreeViewItem Implements IDataErrorInfo Private m_ErrorOnTool As Boolean Public Property ErrorOnTool As Boolean Get Return m_ErrorOnTool End Get Set(value As Boolean) If IsValid Then m_ErrorOnTool = False Application.Msn.NotifyColleagues(Application.ERRORONTOOL, Nothing) Else m_ErrorOnTool = True Application.Msn.NotifyColleagues(Application.ERRORONTOOL, Me) End If End Set End Property #Region "Tool Property" ' Variabile che indica se c'è un errore nel nome dell'utensile (ad esempio nome già utilizzato) Dim bErrorToolName As Boolean = False ''' ''' Property that read and write to the tool's database the Name ''' Public Property NamePar As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim sNamePar As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.NAME, sNamePar) Return sNamePar End Get Set(value As String) bErrorToolName = False EgtSetCurrentContext(IniFile.m_ProjectSceneContext) If EgtTdbSetCurrToolParam(MCH_TP.NAME, value) Then Name = value Else bErrorToolName = True End If End Set End Property ' Variabile che indica se l'utensile è appena stato creato Dim m_NewTool As Boolean = False Public Property NewTool As Boolean Get Return m_NewTool End Get Set(value As Boolean) m_NewTool = value End Set End Property ''' ''' Property that determines if the Tool is selected or not ''' Public Overrides Property IsSelected As Boolean Get Return m_isSelected End Get Set(value As Boolean) If (value <> m_isSelected) Then m_isSelected = value ' If Tool is selected, set it as current and notify all tool's property ' to refresh them values with those of the new selected tool If value Then EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrTool(Me.Name) 'ReadToolParam() NotifyPropertyChanged("Corr") NotifyPropertyChanged("ExitPar") NotifyPropertyChanged("Type") NotifyPropertyChanged("Coolant") NotifyPropertyChanged("CornRad") NotifyPropertyChanged("Diam") NotifyPropertyChanged("TotDiam") NotifyPropertyChanged("Feed") NotifyPropertyChanged("EndFeed") NotifyPropertyChanged("StartFeed") NotifyPropertyChanged("TipFeed") NotifyPropertyChanged("Len") NotifyPropertyChanged("TotLen") NotifyPropertyChanged("MaxMat") NotifyPropertyChanged("LonOffset") NotifyPropertyChanged("RadOffset") NotifyPropertyChanged("Speed") NotifyPropertyChanged("SideAng") NotifyPropertyChanged("MaxSpeed") NotifyPropertyChanged("Thick") NotifyPropertyChanged("MaxAbsorption") NotifyPropertyChanged("MinFeed") NotifyPropertyChanged("Draw") NotifyPropertyChanged("Head") NotifyPropertyChanged("NamePar") NotifyPropertyChanged("UserNotes") NotifyPropertyChanged("TcPos") ' Aggiorno disegno utensile UpdateSceneToolDraw(DrawUpdateSource.DRAW) ' Otherwhise Tool is deselected, so it and the database will be saved to ' keep the modify effective Else If (EgtTdbIsCurrToolModified() And Me.IsValid) Or Me.NewTool Then Select Case MsgBox(EgtMsg(MSG_TOOLSERRORS), MsgBoxStyle.YesNo, EgtMsg(MSG_TOOLSERRORS + 1)) Case MsgBoxResult.Yes m_NewTool = False EgtTdbSaveCurrTool() SaveToolDraw() EgtTdbSave() Case MsgBoxResult.No If m_NewTool Then Application.Msn.NotifyColleagues(Application.REMOVETOOL, Me) End If End Select End If End If End If End Set End Property Private m_Corr As Integer ''' ''' Property that read and write to the tool's database the Corrector ''' Public Property Corr As Integer Get Return m_Corr End Get Set(value As Integer) If value <> m_Corr Then m_Corr = value End If End Set End Property Private m_Exit As Integer ''' ''' Property that read and write to the tool's database the Exit ''' Public Property ExitPar As Integer Get Return m_Exit End Get Set(value As Integer) If value <> m_Exit Then m_Exit = value End If End Set End Property Private m_Type As Integer ''' ''' Property that read and write to the tool's database the Type ''' Public Property Type As Integer Get Return m_Type End Get Set(value As Integer) If value <> m_Type Then m_Type = value End If End Set End Property Private m_Coolant As Integer ''' ''' Property that read and write to the tool's database the Coolant ''' Public Property Coolant As Integer Get Return m_Coolant End Get Set(value As Integer) If value <> m_Coolant Then m_Coolant = value End If End Set End Property Private m_CornRad As Double ''' ''' Property that read and write to the tool's database the Corner Radius ''' Public Property CornRad As String Get Return LenToString(m_CornRad, 4) End Get Set(value As String) If value <> LenToString(m_CornRad, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_CornRad = dValue End If End Set End Property Private m_Diam As Double ''' ''' Property that read and write to the tool's database the Diameter ''' Public Property Diam As String Get Return LenToString(m_Diam, 4) End Get Set(value As String) If value <> LenToString(m_Diam, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_Diam = dValue 'UpdateSceneToolDraw(DrawUpdateSource.DIAM) End If End Set End Property Private m_TotDiam As Double ''' ''' Property that read and write to the tool's database the Total Diameter ''' Public Property TotDiam As String Get Return LenToString(m_TotDiam, 4) End Get Set(value As String) If value <> LenToString(m_TotDiam, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_TotDiam = dValue End If End Set End Property Private m_Feed As Double ''' ''' Property that read and write to the tool's database the Feed ''' Public Property Feed As String Get Return LenToString(m_Feed, 4) End Get Set(value As String) If value <> LenToString(m_Feed, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_Feed = dValue End If End Set End Property Private m_EndFeed As Double ''' ''' Property that read and write to the tool's database the End Feed ''' Public Property EndFeed As String Get Return LenToString(m_EndFeed, 4) End Get Set(value As String) If value <> LenToString(m_EndFeed, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_EndFeed = dValue End If End Set End Property Private m_StartFeed As Double ''' ''' Property that read and write to the tool's database the Start Feed ''' Public Property StartFeed As String Get Return LenToString(m_StartFeed, 4) End Get Set(value As String) If value <> LenToString(m_StartFeed, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_StartFeed = dValue End If End Set End Property Private m_TipFeed As Double ''' ''' Property that read and write to the tool's database the Tip Feed ''' Public Property TipFeed As String Get Return LenToString(m_TipFeed, 4) End Get Set(value As String) If value <> LenToString(m_TipFeed, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_TipFeed = dValue End If End Set End Property Private m_Len As Double ''' ''' Property that read and write to the tool's database the Len ''' Public Property Len As String Get Return LenToString(m_Len, 4) End Get Set(value As String) If value <> LenToString(m_Len, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_Len = dValue End If 'NotifyPropertyChanged("MaxMat") 'UpdateSceneToolDraw(DrawUpdateSource.LEN) End Set End Property Private m_TotLen As Double ''' ''' Property that read and write to the tool's database the Total Len ''' Public Property TotLen As String Get Return LenToString(m_TotLen, 4) End Get Set(value As String) If value <> LenToString(m_TotLen, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_TotLen = dValue End If 'UpdateSceneToolDraw(DrawUpdateSource.TOTLEN) End Set End Property Private m_MaxMat As Double ''' ''' Property that read and write to the tool's database the Max Material ''' Public Property MaxMat As String Get Return LenToString(m_MaxMat, 4) End Get Set(value As String) If value <> LenToString(m_MaxMat, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_MaxMat = dValue End If 'UpdateSceneToolDraw(DrawUpdateSource.MAXMAT) End Set End Property Private m_LonOffset As Double ''' ''' Property that read and write to the tool's database the Lon Offset ''' Public Property LonOffset As String Get Return LenToString(m_LonOffset, 4) End Get Set(value As String) If value <> LenToString(m_LonOffset, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_LonOffset = dValue End If End Set End Property Private m_RadOffset As Double ''' ''' Property that read and write to the tool's database the Rad Offset ''' Public Property RadOffset As String Get Return LenToString(m_RadOffset, 4) End Get Set(value As String) If value <> LenToString(m_RadOffset, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_RadOffset = dValue End If End Set End Property Private m_Speed As Double ''' ''' Property that read and write to the tool's database the Speed ''' Public Property Speed As String Get Return DoubleToString(m_Speed, 4) End Get Set(value As String) If value <> LenToString(m_Speed, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_Speed = dValue End If End Set End Property Private m_SideAng As Double ''' ''' Property that read and write to the tool's database the Side Angle ''' Public Property SideAng As String Get Return LenToString(m_SideAng, 4) End Get Set(value As String) If value <> LenToString(m_SideAng, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_SideAng = dValue End If End Set End Property Private m_MaxSpeed As Double ''' ''' Property that read and write to the tool's database the Max Speed ''' Public Property MaxSpeed As String Get Return DoubleToString(m_MaxSpeed, 4) End Get Set(value As String) If value <> LenToString(m_MaxSpeed, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_MaxSpeed = dValue End If End Set End Property Private m_Thick As Double ''' ''' Property that read and write to the tool's database the Thick ''' Public Property Thick As String Get Return LenToString(m_Thick, 4) End Get Set(value As String) If value <> LenToString(m_Thick, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_Thick = dValue End If End Set End Property Private m_MaxAbsorption As Double ''' ''' Property that read and write to the tool's database the Max Absorption ''' Public Property MaxAbsorption As String Get Return LenToString(m_MaxAbsorption, 3) End Get Set(value As String) If value <> LenToString(m_MaxAbsorption, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_MaxAbsorption = dValue End If End Set End Property Private m_MinFeed As Double ''' ''' Property that read and write to the tool's database the Min Feed ''' Public Property MinFeed As String Get Return LenToString(m_MinFeed, 3) End Get Set(value As String) If value <> LenToString(m_MinFeed, 4) Then Dim dValue As Double = 0 StringToLen(value, dValue) m_MinFeed = dValue End If End Set End Property Private m_Draw As String ''' ''' Property that read and write to the tool's database the Draw ''' Public Property Draw As String Get Return m_Draw End Get Set(value As String) 'EgtSetCurrentContext(IniFile.m_ProjectSceneContext) 'If value = ToolDrawUUIDName Then ' value = m_Draw 'ElseIf value = ToolDrawUUIDName.Substring(0, ToolDrawUUIDName.Length - 1) Then ' value = String.Empty 'End If 'm_Draw = value 'UpdateSceneToolDraw(DrawUpdateSource.DRAW) If value <> m_Draw Then m_Draw = value End If End Set End Property Private m_Head As String ''' ''' Property that read and write to the tool's database the Head ''' Public Property Head As String Get Return m_Head End Get Set(value As String) If value <> m_Head Then m_Head = value End If End Set End Property Private m_UserNotes As String ''' ''' Property that read and write to the tool's database the User Notes ''' Public Property UserNotes As String Get Return m_UserNotes End Get Set(value As String) If value <> m_UserNotes Then m_UserNotes = value End If End Set End Property Private m_TcPos As String ''' ''' Property that read and write to the tool's database the Tc Pos ''' Public Property TcPos As String Get Return m_TcPos End Get Set(value As String) If value <> m_TcPos Then m_TcPos = value End If End Set End Property Private m_Uuid As String ''' ''' Property that read and write to the tool's database the Uuid ''' Public Property Uuid As String Get Return m_Uuid End Get Set(value As String) If value <> m_Uuid Then m_Uuid = value End If End Set End Property #End Region ' Tool Property Private Sub ReadToolParam() EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim nValue As Integer = 0 Dim dValue As Double = 0 Dim sValue As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.CORR, nValue) Corr = nValue EgtTdbGetCurrToolParam(MCH_TP.EXIT_, nValue) ExitPar = nValue EgtTdbGetCurrToolParam(MCH_TP.TYPE, nValue) Type = nValue EgtTdbGetCurrToolParam(MCH_TP.COOLANT, nValue) Coolant = nValue EgtTdbGetCurrToolParam(MCH_TP.CORNRAD, dValue) CornRad = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.DIAM, dValue) Diam = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.TOTDIAM, dValue) TotDiam = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.FEED, dValue) Feed = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.ENDFEED, dValue) EndFeed = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.STARTFEED, dValue) StartFeed = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.TIPFEED, dValue) TipFeed = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.LEN, dValue) Len = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.TOTLEN, dValue) TotLen = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.MAXMAT, dValue) MaxMat = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.LONOFFSET, dValue) LonOffset = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.RADOFFSET, dValue) RadOffset = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.SPEED, dValue) Speed = DoubleToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.SIDEANG, dValue) SideAng = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.MAXSPEED, dValue) MaxSpeed = DoubleToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.THICK, dValue) Thick = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.MAXABSORPTION, dValue) MaxAbsorption = DoubleToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.MINFEED, dValue) MinFeed = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.DRAW, sValue) Draw = sValue EgtTdbGetCurrToolParam(MCH_TP.HEAD, sValue) Head = sValue EgtTdbGetCurrToolParam(MCH_TP.USERNOTES, sValue) UserNotes = sValue EgtTdbGetCurrToolParam(MCH_TP.TCPOS, sValue) TcPos = sValue EgtTdbGetCurrToolParam(MCH_TP.UUID, sValue) Uuid = sValue End Sub Private Sub WriteToolParam() EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dValue As Double = 0 EgtTdbSetCurrToolParam(MCH_TP.CORR, Corr) EgtTdbSetCurrToolParam(MCH_TP.EXIT_, ExitPar) EgtTdbSetCurrToolParam(MCH_TP.TYPE, Type) EgtTdbSetCurrToolParam(MCH_TP.COOLANT, Coolant) StringToLen(CornRad, dValue) EgtTdbSetCurrToolParam(MCH_TP.CORNRAD, dValue) StringToLen(TotDiam, dValue) EgtTdbSetCurrToolParam(MCH_TP.TOTDIAM, dValue) StringToLen(Feed, dValue) EgtTdbSetCurrToolParam(MCH_TP.FEED, dValue) StringToLen(EndFeed, dValue) EgtTdbSetCurrToolParam(MCH_TP.ENDFEED, dValue) StringToLen(StartFeed, dValue) EgtTdbSetCurrToolParam(MCH_TP.STARTFEED, dValue) StringToLen(TipFeed, dValue) EgtTdbSetCurrToolParam(MCH_TP.TIPFEED, dValue) StringToLen(Len, dValue) EgtTdbSetCurrToolParam(MCH_TP.LEN, dValue) StringToLen(TotLen, dValue) EgtTdbSetCurrToolParam(MCH_TP.TOTLEN, dValue) StringToLen(MaxMat, dValue) EgtTdbSetCurrToolParam(MCH_TP.MAXMAT, dValue) StringToLen(LonOffset, dValue) EgtTdbSetCurrToolParam(MCH_TP.LONOFFSET, dValue) StringToLen(RadOffset, dValue) EgtTdbSetCurrToolParam(MCH_TP.RADOFFSET, dValue) StringToDouble(Speed, dValue) EgtTdbSetCurrToolParam(MCH_TP.SPEED, dValue) StringToLen(SideAng, dValue) EgtTdbSetCurrToolParam(MCH_TP.SIDEANG, dValue) StringToDouble(MaxSpeed, dValue) EgtTdbSetCurrToolParam(MCH_TP.MAXSPEED, dValue) StringToLen(Thick, dValue) EgtTdbSetCurrToolParam(MCH_TP.THICK, dValue) StringToDouble(MaxAbsorption, dValue) EgtTdbSetCurrToolParam(MCH_TP.MAXABSORPTION, dValue) StringToLen(MinFeed, dValue) EgtTdbSetCurrToolParam(MCH_TP.MINFEED, dValue) EgtTdbSetCurrToolParam(MCH_TP.DRAW, Draw) EgtTdbSetCurrToolParam(MCH_TP.HEAD, Head) EgtTdbSetCurrToolParam(MCH_TP.USERNOTES, UserNotes) EgtTdbSetCurrToolParam(MCH_TP.TCPOS, TcPos) EgtTdbSetCurrToolParam(MCH_TP.UUID, Uuid) End Sub #Region "Constructors" Sub New(Name As String) MyBase.New(Name) Application.Msn.Register(Application.SAVETOOLDRAW, Sub() SaveToolDraw() End Sub) End Sub #End Region ' Constructors #Region "ToolSceneUpdate" ' Enum che indica le proprietà di disegno dell'utensile Friend Enum DrawUpdateSource DIAM = 0 LEN = 1 MAXMAT = 2 THICK = 3 DRAW = 4 TOTLEN = 5 End Enum ' Variabili che segnalano errori nel disegno dell'utensile Dim bToolMakerError As Boolean = False Dim bDrawNameExistError As Boolean = False Dim bDrawNameError As Boolean = False Dim bDrawingError As Boolean = False Dim m_bFirst As Boolean = True Private Sub UpdateSceneToolDraw(UpdateSource As DrawUpdateSource) ' Azzero errori bToolMakerError = False bDrawNameError = False bDrawNameExistError = False bDrawingError = False If m_NewTool And m_bFirst Then m_bFirst = False EgtTdbGetCurrToolParam(MCH_TP.MAXMAT, m_MaxMat) EgtTdbGetCurrToolParam(MCH_TP.THICK, m_Thick) EgtTdbGetCurrToolParam(MCH_TP.DIAM, m_Diam) EgtTdbGetCurrToolParam(MCH_TP.LEN, m_Len) EgtTdbGetCurrToolParam(MCH_TP.TOTLEN, m_TotLen) End If ' Verifico proprietà draw If m_Draw = String.Empty OrElse IsUUID(Path.GetFileNameWithoutExtension(m_Draw)) Then CreateToolDraw(UpdateSource) Else EgtSetCurrentContext(IniFile.m_ToolsDbSceneContext) If IsNgeFile(m_Draw) Then If EgtOpenFile(IniFile.m_sTdbCurrMachToolsDirPath & "\" & m_Draw) Then EgtSetView(VT.TOP, False) EgtZoom(ZM.ALL) Else ' Errore bDrawNameExistError = True EgtNewFile() EgtSetView(VT.TOP, False) EgtZoom(ZM.ALL) End If Else ' Errore bDrawNameError = True EgtNewFile() EgtSetView(VT.TOP, False) EgtZoom(ZM.ALL) End If End If NotifyPropertyChanged("Draw") NotifyPropertyChanged("MaxMat") NotifyPropertyChanged("Thick") NotifyPropertyChanged("Diam") NotifyPropertyChanged("Len") NotifyPropertyChanged("TotLen") End Sub Private Sub CreateToolDraw(UpdateSource As DrawUpdateSource) ' Carico il relativo ToolHolder Dim ToolHolder As String = String.Empty ToolHolder = LoadToolHolder() If Not LoadToolMaker() OrElse Not CreateToolDraw(ToolHolder, UpdateSource) Then EgtSetCurrentContext(IniFile.m_ToolsDbSceneContext) EgtNewFile() End If EgtSetCurrentContext(IniFile.m_ToolsDbSceneContext) ' Aggiorno visualizzazione EgtSetView(VT.TOP, False) EgtZoom(ZM.ALL) ' Salvo il End Sub ''' ''' Mathod that load the toolholder for the current tool (based on his head), or return an empty string ''' Private Function LoadToolHolder() As String Dim sHolder As String = String.Empty EgtUILib.GetPrivateProfileString(S_TOOLHOLDER, Head & "." & ExitPar.ToString(), "", sHolder, IniFile.m_sDbsCurrMachIniFilePath) If String.IsNullOrWhiteSpace(sHolder) Then Return String.Empty Else Dim sHolderPath As String = String.Empty EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbGetToolHolderDir(sHolderPath) sHolderPath += "\" & sHolder Return sHolderPath End If End Function Private Function LoadToolMaker() As Boolean Dim sMaker As String = String.Empty EgtUILib.GetPrivateProfileString(S_TOOLS, ConvertTypeToString(Type), "", sMaker, IniFile.m_sDbsCurrMachIniFilePath) If String.IsNullOrWhiteSpace(sMaker) Then bToolMakerError = True ' Acquisisce solo il file lua, ma meglio impostare contesto disegno utensili (se ci sono chiamate...) EgtSetCurrentContext(IniFile.m_ToolsDbSceneContext) Return EgtLuaExecFile(IniFile.m_sToolMakersDir & "\" & sMaker) End Function Private Function ConvertTypeToString(Type As Integer) As String Select Case Type Case MCH_TY.DRILL_STD, MCH_TY.DRILL_LONG Return "StandardDrillMaker" Case MCH_TY.SAW_STD, MCH_TY.SAW_FLAT Return "StandardSawMaker" Case MCH_TY.MILL_STD, MCH_TY.MILL_NOTIP Return "StandardMillMaker" Case MCH_TY.MORTISE_STD Return "StandardMortiseMaker" Case MCH_TY.COMPO Return "StandardCompoMaker" End Select Return Nothing End Function Private Function CreateToolDraw(ToolHolder As String, UpdateSource As DrawUpdateSource) As Boolean Select Case Type Case MCH_TY.DRILL_STD ' imposto dati utensile EgtLuaSetGlobStringVar("TOOL.TOOLHOLDER", ToolHolder) EgtLuaSetGlobNumVar("TOOL.TOTLEN", m_TotLen) EgtLuaSetGlobNumVar("TOOL.LEN", m_Len) EgtLuaSetGlobNumVar("TOOL.DIAM", m_Diam) EgtLuaSetGlobNumVar("TOOL.MAXMAT", m_MaxMat) Case MCH_TY.SAW_STD ' imposto dati utensile EgtLuaSetGlobStringVar("TOOL.TOOLHOLDER", ToolHolder) EgtLuaSetGlobNumVar("TOOL.LEN", m_Len) EgtLuaSetGlobNumVar("TOOL.DIAM", m_Diam) Dim dCore As Double = If(Len >= Thick, m_Thick - 1, 2 * m_Len - m_Thick) EgtLuaSetGlobNumVar("TOOL.CORE", dCore) EgtLuaSetGlobNumVar("TOOL.THICK", m_Thick) EgtLuaSetGlobNumVar("TOOL.MAXMAT", m_MaxMat) Case MCH_TY.MILL_STD ' imposto dati utensile EgtLuaSetGlobStringVar("TOOL.TOOLHOLDER", ToolHolder) EgtLuaSetGlobNumVar("TOOL.LEN", m_Len) EgtLuaSetGlobNumVar("TOOL.DIAM", m_Diam) EgtLuaSetGlobNumVar("TOOL.MAXMAT", m_MaxMat) Case Else bDrawingError = True Draw = String.Empty Return False End Select ' passo all'ambiente di disegno dell'utensile EgtSetCurrentContext(IniFile.m_ToolsDbSceneContext) ' eseguo creazione utensile EgtLuaExecLine("CreateTool()") ' recupero errore Dim nErr As Integer = 999 EgtLuaGetGlobIntVar("TOOL.ERR", nErr) bDrawingError = Not (nErr = 0) If bDrawingError And UpdateSource <> DrawUpdateSource.DRAW Then Draw = String.Empty Return (nErr = 0) End Function Private Function SaveToolDraw() As Boolean If m_Type = MCH_TY.DRILL_STD Or m_Type = MCH_TY.SAW_STD Or m_Type = MCH_TY.MILL_STD Then Dim x = EgtGetCurrentContext() ' nome e direttorio del file da salvare EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim sDrawName As String = Uuid sDrawName = sDrawName & ".nge" Dim sPath As String = String.Empty EgtTdbGetToolDir(sPath) sPath = sPath & "\" & sDrawName ' passo all'ambiente di disegno dell'utensile Dim r = EgtSetCurrentContext(IniFile.m_ToolsDbSceneContext) Dim y = EgtGetCurrentContext() ' nascondo layer ausiliario Dim nAuxId As Integer = GDB_ID.NULL nAuxId = EgtGetFirstNameInGroup(EgtGetFirstGroupInGroup(GDB_ID.ROOT), "AUX") EgtSetStatus(nAuxId, GDB_ST.OFF) ' se lama devo ruotare -90 deg attorno a Z+ If m_Type = MCH_TY.SAW_STD Then EgtRotate(EgtGetFirstGroupInGroup(GDB_ID.ROOT), Point3d.ORIG(), Vector3d.Z_AX(), -90, GDB_RT.GLOB) End If ' salvo il modello Dim z = EgtGetCurrentContext() Dim bOk As Boolean = EgtSaveFile(sPath, NGE.CMPTEXT) Dim e = EgtGetCurrentContext() ' eseguo controrotazione per lama If m_Type = MCH_TY.SAW_STD Then EgtRotate(EgtGetFirstGroupInGroup(GDB_ID.ROOT), Point3d.ORIG(), Vector3d.Z_AX(), 90, GDB_RT.GLOB) End If ' ripristino visualizzazione layer aux EgtSetStatus(nAuxId, GDB_ST.ON_) ' salvo nome del disegno utensile EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.DRAW, sDrawName) EgtTdbSaveCurrTool() Return bOk End If Return False End Function #End Region ' ToolSceneUpdate #Region "IDataErrorInfo Members" Private ReadOnly Property IDataErrorInfo_Error() As String Implements IDataErrorInfo.Error Get Return Nothing End Get End Property Public ReadOnly Property IDataErrorInfo_Item(ByVal propertyName As String) As String Implements IDataErrorInfo.Item Get ErrorOnTool = True Return Me.GetValidationError(propertyName) End Get End Property #End Region ' IDataErrorInfo Members #Region "Validation" ''' ''' Returns true if this object has no validation errors. ''' Public ReadOnly Property IsValid() As Boolean Get For Each [property] As String In ValidatedProperties If GetValidationError([property]) IsNot Nothing Then Return False End If Next [property] Return True End Get End Property Private Shared ReadOnly ValidatedProperties() As String = {"Draw", "MaxMat", "Thick", "Diam", "Len", "TotLen", "Speed", "NamePar"} Private Function GetValidationError(ByVal propertyName As String) As String If Array.IndexOf(ValidatedProperties, propertyName) < 0 Then Return Nothing End If Dim [error] As String = Nothing Select Case propertyName Case "Draw" [error] = Me.ValidateDraw() Case "MaxMat" [error] = Me.ValidateMaxMat() Case "Diam" [error] = Me.ValidateDiam() Case "Thick" [error] = Me.ValidateThick() Case "Len" [error] = Me.ValidateLen() Case "TotLen" [error] = Me.ValidateTotLen() Case "Speed" [error] = Me.ValidateSpeed() Case "NamePar" [error] = Me.ValidateName() Case Else 'Debug.Fail("Unexpected property being validated on Tool: " & propertyName) End Select Return [error] End Function Private Function ValidateDraw() As String If bDrawNameError Then Return EgtMsg(MSG_TOOLSERRORS + 2) End If If bDrawNameExistError Then Return EgtMsg(MSG_TOOLSERRORS + 3) End If If bToolMakerError Then Return EgtMsg(MSG_TOOLSERRORS + 4) End If If bDrawingError Then Return EgtMsg(MSG_TOOLSERRORS + 5) End If Return Nothing End Function Private Function ValidateMaxMat() As String If m_MaxMat < EPS_SMALL Then Return EgtMsg(MSG_TOOLSERRORS + 6) End If If m_MaxMat > m_Len + EPS_SMALL Then Return EgtMsg(MSG_TOOLSERRORS + 7) End If Return Nothing End Function Private Function ValidateThick() As String If (m_Type = MCH_TY.SAW_FLAT Or m_Type = MCH_TY.SAW_STD Or m_Type = MCH_TY.MORTISE_STD) And m_Thick < EPS_SMALL Then Return EgtMsg(MSG_TOOLSERRORS + 8) End If Return Nothing End Function Private Function ValidateDiam() As String If m_Diam < EPS_SMALL Then Return EgtMsg(MSG_TOOLSERRORS + 9) End If Return Nothing End Function Private Function ValidateLen() As String If m_Len < EPS_SMALL Then Return EgtMsg(MSG_TOOLSERRORS + 10) End If If m_Len > m_TotLen + EPS_SMALL Then Return "La lunghezza non può essere maggiore della lunghezza totale" End If If m_Len < m_MaxMat Then Return "La lunghezza non può essere minore del massimo materiale" End If Return Nothing End Function Private Function ValidateTotLen() As String If m_TotLen < EPS_SMALL Then Return "La lunghezza totale deve essere maggiore di zero" End If If m_TotLen < m_Len - EPS_SMALL Then Return "La lunghezza totale non può essere minore della lunghezza" End If Return Nothing End Function Private Function ValidateSpeed() As String If Math.Abs(m_Speed) > m_MaxSpeed + EPS_ZERO Then Return EgtMsg(MSG_TOOLSERRORS + 11) End If Return Nothing End Function Private Function ValidateName() As String If bErrorToolName Then Return EgtMsg(MSG_TOOLSERRORS + 12) End If Return Nothing End Function Private Shared Function IsStringMissing(ByVal value As String) As Boolean Return String.IsNullOrEmpty(value) OrElse value.Trim() = String.Empty End Function Private Shared Function IsNgeFile(FileName As String) As Boolean If IsStringMissing(FileName) Then Return False End If Dim pattern As String = "^.+\.(?:[nN][gG][eE])$" Dim x = Regex.IsMatch(FileName, pattern, RegexOptions.IgnoreCase) Return x End Function #End Region ' Validation End Class ''' ''' Class that represent a FamilyTool in the treeview. ''' It's an element in the treeview that represent a folder, but also a tool family ''' Public Class FamilyToolTreeViewItem Inherits InheritableTreeViewItem Private m_ToolType As MCH_TF ''' ''' Property that determines the tool type of the family ''' Public Property ToolType As MCH_TF Get Return m_ToolType End Get Set(value As MCH_TF) m_ToolType = value End Set End Property ''' ''' Property that determines if the Tool is selected or not ''' Public Overrides Property IsSelected As Boolean Get Return m_isSelected End Get Set(value As Boolean) If (value <> m_isSelected) Then m_isSelected = value If value Then EgtSetCurrentContext(IniFile.m_ToolsDbSceneContext) EgtNewFile() EgtSetView(VT.TOP, False) EgtZoom(ZM.ALL) End If End If End Set End Property ' Proprietà che permette di nascondere tutti i parametri utensile grazie al binding ed al converter Public ReadOnly Property Type As Integer Get Return MCH_TY.NONE End Get End Property ''' ''' Constructor that receive the name of the FamilyToolTreeViewItem, the ToolType, and set ''' the picture(Folder.png) ''' Sub New(Name As String, ToolType As MCH_TF) MyBase.New(Name) Me.ToolType = ToolType Me.PictureString = "/Resources/TreeView/Folder.png" End Sub Sub New(Name As String, PicturePath As String) MyBase.New(Name) Me.PictureString = PicturePath End Sub End Class ''' ''' Class that represent a Converter that use tool type and param type, to set the visibility state of the param type. ''' Public Class ToolParamVisibilityConverter Implements IValueConverter Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert Select Case CInt(value) Case MCH_TY.NONE Return Visibility.Hidden Case MCH_TY.DRILL_STD Return SharedFieldsClass.Drill_Std(CInt(parameter)) Case MCH_TY.DRILL_LONG Return SharedFieldsClass.Drill_Long(CInt(parameter)) Case MCH_TY.SAW_STD Return SharedFieldsClass.Saw_Std(CInt(parameter)) Case MCH_TY.SAW_FLAT Return SharedFieldsClass.Saw_Flat(CInt(parameter)) Case MCH_TY.MILL_STD Return SharedFieldsClass.Mill_Std(CInt(parameter)) Case MCH_TY.MILL_NOTIP Return SharedFieldsClass.Mill_NoTip(CInt(parameter)) Case MCH_TY.MORTISE_STD Return SharedFieldsClass.Mortise_Std(CInt(parameter)) Case MCH_TY.COMPO Return SharedFieldsClass.Compo(CInt(parameter)) Case Else Return Visibility.Hidden End Select End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack Throw New NotImplementedException End Function End Class ''' ''' Class that represent a Converter that convert UUID to ***** in Draw param ''' Public Class ToolDrawUUIDConverter Implements IValueConverter Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert If IsUUID(Path.GetFileNameWithoutExtension(value.ToString)) Then Return ToolDrawUUIDName Else Return value.ToString End If End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack Return value.ToString End Function End Class