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 ChildItem 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 Dim x = EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim y = EgtTdbSetCurrTool(Me.Name) 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 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 'EgtTdbRemoveTool(Me.Name) 'EgtTdbSave() End Select End If End If End If End Set End Property ''' ''' Property that read and write to the tool's database the Corrector ''' Public Property Corr As Integer Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim nCorr As Integer = 0 EgtTdbGetCurrToolParam(MCH_TP.CORR, nCorr) Return nCorr End Get Set(value As Integer) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.CORR, value) End Set End Property ''' ''' Property that read and write to the tool's database the Exit ''' Public Property ExitPar As Integer Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim nExitPar As Integer = 0 EgtTdbGetCurrToolParam(MCH_TP.EXIT_, nExitPar) Return nExitPar End Get Set(value As Integer) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.EXIT_, value) End Set End Property Dim m_Type As Integer ''' ''' Property that read and write to the tool's database the Type ''' Public Property Type As Integer Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dType As Integer = 0 Dim x = EgtTdbGetCurrToolParam(MCH_TP.TYPE, dType) m_Type = dType Return dType End Get Set(value As Integer) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) m_Type = value EgtTdbSetCurrToolParam(MCH_TP.TYPE, value) End Set End Property ''' ''' Property that read and write to the tool's database the Coolant ''' Public Property Coolant As Integer Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim nCoolant As Integer = 0 EgtTdbGetCurrToolParam(MCH_TP.COOLANT, nCoolant) Return nCoolant End Get Set(value As Integer) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.COOLANT, value) End Set End Property ''' ''' Property that read and write to the tool's database the Corner Radius ''' Public Property CornRad As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dCornRad As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.CORNRAD, dCornRad) Return LenToString(dCornRad, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dCornRad As Double = 0 StringToLen(value, dCornRad) EgtTdbSetCurrToolParam(MCH_TP.CORNRAD, dCornRad) End Set End Property Dim m_Diam As Double ''' ''' Property that read and write to the tool's database the Diameter ''' Public Property Diam As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dDiam As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.DIAM, dDiam) m_Diam = dDiam Return LenToString(dDiam, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dDiam As Double = 0 StringToLen(value, dDiam) m_Diam = dDiam UpdateSceneToolDraw(DrawUpdateSource.DIAM) EgtTdbSetCurrToolParam(MCH_TP.DIAM, dDiam) End Set End Property ''' ''' Property that read and write to the tool's database the Total Diameter ''' Public Property TotDiam As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dTotDiam As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.TOTDIAM, dTotDiam) Return LenToString(dTotDiam, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dTotDiam As Double = 0 StringToLen(value, dTotDiam) EgtTdbSetCurrToolParam(MCH_TP.TOTDIAM, dTotDiam) End Set End Property ''' ''' Property that read and write to the tool's database the Feed ''' Public Property Feed As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dFeed As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.FEED, dFeed) Return LenToString(dFeed, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dFeed As Double = 0 StringToLen(value, dFeed) EgtTdbSetCurrToolParam(MCH_TP.FEED, dFeed) End Set End Property ''' ''' Property that read and write to the tool's database the End Feed ''' Public Property EndFeed As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dEndFeed As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.ENDFEED, dEndFeed) Return LenToString(dEndFeed, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dEndFeed As Double = 0 StringToLen(value, dEndFeed) EgtTdbSetCurrToolParam(MCH_TP.ENDFEED, dEndFeed) End Set End Property ''' ''' Property that read and write to the tool's database the Start Feed ''' Public Property StartFeed As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dStartFeed As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.STARTFEED, dStartFeed) Return LenToString(dStartFeed, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dStartFeed As Double = 0 StringToLen(value, dStartFeed) EgtTdbSetCurrToolParam(MCH_TP.STARTFEED, dStartFeed) End Set End Property ''' ''' Property that read and write to the tool's database the Tip Feed ''' Public Property TipFeed As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dTipFeed As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.TIPFEED, dTipFeed) Return LenToString(dTipFeed, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dTipFeed As Double = 0 StringToLen(value, dTipFeed) EgtTdbSetCurrToolParam(MCH_TP.TIPFEED, dTipFeed) End Set End Property Dim m_Len As Double ''' ''' Property that read and write to the tool's database the Len ''' Public Property Len As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dLen As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.LEN, dLen) m_Len = dLen Return LenToString(dLen, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dLen As Double = 0 StringToLen(value, dLen) m_Len = dLen UpdateSceneToolDraw(DrawUpdateSource.LEN) EgtTdbSetCurrToolParam(MCH_TP.LEN, dLen) End Set End Property Dim m_TotLen As Double ''' ''' Property that read and write to the tool's database the Total Len ''' Public Property TotLen As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dTotLen As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.TOTLEN, dTotLen) m_TotLen = dTotLen Return LenToString(dTotLen, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dTotLen As Double = 0 StringToLen(value, dTotLen) m_TotLen = dTotLen UpdateSceneToolDraw(DrawUpdateSource.TOTLEN) EgtTdbSetCurrToolParam(MCH_TP.TOTLEN, dTotLen) End Set End Property Dim m_MaxMat As Double ''' ''' Property that read and write to the tool's database the Max Material ''' Public Property MaxMat As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMaxMat As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.MAXMAT, dMaxMat) m_MaxMat = dMaxMat Return LenToString(dMaxMat, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMaxMat As Double = 0 StringToLen(value, dMaxMat) m_MaxMat = dMaxMat UpdateSceneToolDraw(DrawUpdateSource.MAXMAT) EgtTdbSetCurrToolParam(MCH_TP.MAXMAT, dMaxMat) End Set End Property ''' ''' Property that read and write to the tool's database the Lon Offset ''' Public Property LonOffset As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dLonOffset As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.LONOFFSET, dLonOffset) Return LenToString(dLonOffset, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dLonOffset As Double = 0 StringToLen(value, dLonOffset) EgtTdbSetCurrToolParam(MCH_TP.LONOFFSET, dLonOffset) End Set End Property ''' ''' Property that read and write to the tool's database the Rad Offset ''' Public Property RadOffset As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dRadOffset As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.RADOFFSET, dRadOffset) Return LenToString(dRadOffset, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dRadOffset As Double = 0 StringToLen(value, dRadOffset) EgtTdbSetCurrToolParam(MCH_TP.RADOFFSET, dRadOffset) End Set End Property Dim m_Speed As Double ''' ''' Property that read and write to the tool's database the Speed ''' Public Property Speed As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dSpeed As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.SPEED, dSpeed) Return DoubleToString(dSpeed, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dSpeed As Double = 0 StringToDouble(value, dSpeed) m_Speed = dSpeed EgtTdbSetCurrToolParam(MCH_TP.SPEED, dSpeed) End Set End Property ''' ''' Property that read and write to the tool's database the Side Angle ''' Public Property SideAng As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dSideAng As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.SIDEANG, dSideAng) Return LenToString(dSideAng, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dSideAng As Double = 0 StringToLen(value, dSideAng) EgtTdbSetCurrToolParam(MCH_TP.SIDEANG, dSideAng) End Set End Property Dim m_MaxSpeed As Double ''' ''' Property that read and write to the tool's database the Max Speed ''' Public Property MaxSpeed As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMaxSpeed As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.MAXSPEED, dMaxSpeed) m_MaxSpeed = dMaxSpeed Return DoubleToString(dMaxSpeed, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMaxSpeed As Double = 0 StringToDouble(value, dMaxSpeed) m_MaxSpeed = dMaxSpeed NotifyPropertyChanged("Speed") EgtTdbSetCurrToolParam(MCH_TP.MAXSPEED, dMaxSpeed) End Set End Property Dim m_Thick As Double ''' ''' Property that read and write to the tool's database the Thick ''' Public Property Thick As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dThick As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.THICK, dThick) m_Thick = dThick Return LenToString(dThick, 4) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dThick As Double = 0 StringToLen(value, dThick) m_Thick = dThick UpdateSceneToolDraw(DrawUpdateSource.THICK) EgtTdbSetCurrToolParam(MCH_TP.THICK, dThick) End Set End Property ''' ''' Property that read and write to the tool's database the Max Absorption ''' Public Property MaxAbsorption As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMaxAbsorption As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.MAXABSORPTION, dMaxAbsorption) Return LenToString(dMaxAbsorption, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMaxAbsorption As Double = 0 StringToLen(value, dMaxAbsorption) EgtTdbSetCurrToolParam(MCH_TP.MAXABSORPTION, dMaxAbsorption) End Set End Property ''' ''' Property that read and write to the tool's database the Min Feed ''' Public Property MinFeed As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMinFeed As Double = 0 EgtTdbGetCurrToolParam(MCH_TP.MINFEED, dMinFeed) Return LenToString(dMinFeed, 3) End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim dMinFeed As Double = 0 StringToLen(value, dMinFeed) EgtTdbSetCurrToolParam(MCH_TP.MINFEED, dMinFeed) 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 EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim sDraw As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.DRAW, sDraw) m_Draw = sDraw Return sDraw 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) EgtTdbSetCurrToolParam(MCH_TP.DRAW, value) End Set End Property ''' ''' Property that read and write to the tool's database the Head ''' Public Property Head As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim sHead As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.HEAD, sHead) Return sHead End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.HEAD, value) End Set End Property ''' ''' Property that read and write to the tool's database the User Notes ''' Public Property UserNotes As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim sUserNotes As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.USERNOTES, sUserNotes) Return sUserNotes End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.USERNOTES, value) End Set End Property ''' ''' Property that read and write to the tool's database the Tc Pos ''' Public Property TcPos As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim sTcPos As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.TCPOS, sTcPos) Return sTcPos End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.TCPOS, value) End Set End Property ''' ''' Property that read and write to the tool's database the Uuid ''' Public Property Uuid As String Get EgtSetCurrentContext(IniFile.m_ProjectSceneContext) Dim sUuid As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.UUID, sUuid) Return sUuid End Get Set(value As String) EgtSetCurrentContext(IniFile.m_ProjectSceneContext) EgtTdbSetCurrToolParam(MCH_TP.UUID, value) End Set End Property #End Region ' Tool Property #Region "Constructors" Sub New(Name As String) MyBase.New(Name) Application.Msn.Register(Application.SAVETOOLDRAW, Sub() SaveToolDraw() End Sub) End Sub Sub New(Name As String, IsSelected As Boolean, IsExpanded As Boolean, IsActive As Boolean) MyBase.New(Name, IsSelected, IsExpanded, IsActive) 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 Private Sub UpdateSceneToolDraw(UpdateSource As DrawUpdateSource) ' Azzero errori bToolMakerError = False bDrawNameError = False bDrawNameExistError = False bDrawingError = False ' 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_Draw = String.Empty Then 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 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_Draw = String.Empty And m_Thick < EPS_SMALL Then Return EgtMsg(MSG_TOOLSERRORS + 8) End If Return Nothing End Function Private Function ValidateDiam() As String If m_Draw = String.Empty And m_Diam < EPS_SMALL Then Return EgtMsg(MSG_TOOLSERRORS + 9) End If Return Nothing End Function Private Function ValidateLen() As String If m_Draw = String.Empty Then 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 End If Return Nothing End Function Private Function ValidateTotLen() As String If m_Draw = String.Empty Then 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 End If Return Nothing End Function Private Function ValidateSpeed() As String If 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 ParentItem 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 Sub New(Name As String, IsSelected As Boolean, IsExpanded As Boolean, IsActive As Boolean) MyBase.New(Name, IsSelected, IsExpanded, IsActive) 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