7872c90d2e
- aggiunta gestione lame con raggio corner.
182 lines
7.4 KiB
VB.net
182 lines
7.4 KiB
VB.net
Imports System.Globalization
|
|
Imports EgtUILib
|
|
|
|
|
|
Module ToolDraw
|
|
|
|
' Dati generali
|
|
Friend nToolContext As Integer = 0
|
|
Friend nError As Integer = 0
|
|
' Dati utensile
|
|
Friend sHeadName As String = ""
|
|
Friend sExitName As String = ""
|
|
Friend nType As Integer = MCH_TY.NONE
|
|
Friend dTotLen As Double = 0
|
|
Friend dLen As Double = 0
|
|
Friend dTotDiam As Double = 0
|
|
Friend dDiam As Double = 0
|
|
Friend dThick As Double = 0
|
|
Friend dMaxMat As Double = 0
|
|
Friend dSideAng As Double = 0
|
|
Friend dCornRad As Double = 0
|
|
|
|
Friend Function Create() As Boolean
|
|
' Reset stato di errore
|
|
nError = 0
|
|
' Verifico esistenza creatore utensili
|
|
If Not LoadToolMaker() Then Return False
|
|
' Recupero nome eventuale portautensile
|
|
Dim sToolHolder As String = GetToolHolderPath()
|
|
' Assegno i dati utensile a seconda del tipo
|
|
Select Case nType
|
|
Case MCH_TY.DRILL_STD, MCH_TY.DRILL_LONG, MCH_TY.CHISEL_STD
|
|
' imposto dati utensile
|
|
EgtLuaSetGlobStringVar("TOOL.TOOLHOLDER", sToolHolder)
|
|
EgtLuaSetGlobNumVar("TOOL.TOTLEN", dTotLen)
|
|
EgtLuaSetGlobNumVar("TOOL.LEN", dLen)
|
|
EgtLuaSetGlobNumVar("TOOL.DIAM", dDiam)
|
|
EgtLuaSetGlobNumVar("TOOL.MAXMAT", dMaxMat)
|
|
Case MCH_TY.SAW_STD, MCH_TY.SAW_FLAT
|
|
' imposto dati utensile
|
|
EgtLuaSetGlobStringVar("TOOL.TOOLHOLDER", sToolHolder)
|
|
EgtLuaSetGlobNumVar("TOOL.LEN", dLen)
|
|
EgtLuaSetGlobNumVar("TOOL.DIAM", dDiam)
|
|
Dim dCore As Double = If(dLen >= dThick, dThick - 1, 2 * dLen - dThick)
|
|
EgtLuaSetGlobNumVar("TOOL.CORE", dCore)
|
|
EgtLuaSetGlobNumVar("TOOL.THICK", dThick)
|
|
EgtLuaSetGlobNumVar("TOOL.MAXMAT", dMaxMat)
|
|
EgtLuaSetGlobNumVar("TOOL.CORNRAD", dCornRad)
|
|
Case MCH_TY.MILL_STD, MCH_TY.MILL_NOTIP
|
|
' imposto dati utensile
|
|
EgtLuaSetGlobStringVar("TOOL.TOOLHOLDER", sToolHolder)
|
|
EgtLuaSetGlobNumVar("TOOL.TOTLEN", dTotLen)
|
|
EgtLuaSetGlobNumVar("TOOL.LEN", dLen)
|
|
EgtLuaSetGlobNumVar("TOOL.TOTDIAM", dTotDiam)
|
|
EgtLuaSetGlobNumVar("TOOL.DIAM", dDiam)
|
|
EgtLuaSetGlobNumVar("TOOL.MAXMAT", dMaxMat)
|
|
EgtLuaSetGlobNumVar("TOOL.HEIGHT", dThick)
|
|
EgtLuaSetGlobNumVar("TOOL.SIDEANG", dSideAng)
|
|
EgtLuaSetGlobNumVar("TOOL.CORNRAD", dCornRad)
|
|
Case MCH_TY.MORTISE_STD
|
|
' imposto dati utensile
|
|
EgtLuaSetGlobStringVar("TOOL.TOOLHOLDER", sToolHolder)
|
|
EgtLuaSetGlobNumVar("TOOL.LEN", dLen)
|
|
EgtLuaSetGlobNumVar("TOOL.DIAM", dDiam)
|
|
EgtLuaSetGlobNumVar("TOOL.MAXMAT", dMaxMat)
|
|
EgtLuaSetGlobNumVar("TOOL.THICK", dThick)
|
|
EgtLuaSetGlobNumVar("TOOL.CORNRAD", dCornRad)
|
|
Case Else
|
|
nError = 999
|
|
Return False
|
|
End Select
|
|
' passo all'ambiente di disegno dell'utensile
|
|
EgtSetCurrentContext(nToolContext)
|
|
' eseguo creazione utensile
|
|
EgtLuaCallFunction("CreateTool")
|
|
' recupero errore
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("TOOL.ERR", nErr)
|
|
nError = nErr
|
|
Return (nError = 0)
|
|
End Function
|
|
|
|
Private Function LoadToolMaker() As Boolean
|
|
Dim sMaker As String = String.Empty
|
|
EgtUILib.GetPrivateProfileString(S_TOOLS, ConvertTypeToString(nType), "", sMaker, IniFile.m_sCurrMachIniFilePath)
|
|
If String.IsNullOrWhiteSpace(sMaker) Then
|
|
nError = 1
|
|
Return False
|
|
End If
|
|
' Acquisisce solo il file lua, ma meglio impostare contesto disegno utensili (se ci sono chiamate...)
|
|
EgtSetCurrentContext(nToolContext)
|
|
If Not EgtLuaExecFile(IniFile.m_sToolMakersDir & "\" & sMaker) Then
|
|
nError = 2
|
|
Return False
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Private Function ConvertTypeToString(Type As Integer) As String
|
|
Select Case Type
|
|
Case MCH_TY.DRILL_STD, MCH_TY.DRILL_LONG
|
|
Return K_DRILLMAKER
|
|
Case MCH_TY.SAW_STD, MCH_TY.SAW_FLAT
|
|
Return K_SAWBLADEMAKER
|
|
Case MCH_TY.MILL_STD, MCH_TY.MILL_NOTIP
|
|
Return K_MILLMAKER
|
|
Case MCH_TY.MORTISE_STD
|
|
Return K_MORTISEMAKER
|
|
Case MCH_TY.CHISEL_STD
|
|
Return K_CHISELMAKER
|
|
Case MCH_TY.COMPO
|
|
Return Nothing
|
|
End Select
|
|
Return Nothing
|
|
End Function
|
|
|
|
Private Function GetToolHolderPath() As String
|
|
Dim sHolder As String = String.Empty
|
|
If Not IsNothing(sHeadName) Then
|
|
Dim sTempExit As String = String.Empty
|
|
Dim nExit As Integer
|
|
If Integer.TryParse(sExitName, NumberStyles.Integer, CultureInfo.InvariantCulture, nExit) Then
|
|
sTempExit = sExitName
|
|
Else
|
|
sTempExit = "1"
|
|
End If
|
|
If nType = MCH_TY.SAW_STD Then
|
|
EgtUILib.GetPrivateProfileString(S_TOOLHOLDER, sHeadName & "." & sTempExit & ":SAW_STD", "", sHolder, IniFile.m_sCurrMachIniFilePath)
|
|
ElseIf nType = MCH_TY.SAW_FLAT Then
|
|
EgtUILib.GetPrivateProfileString(S_TOOLHOLDER, sHeadName & "." & sTempExit & ":SAW_FLAT", "", sHolder, IniFile.m_sCurrMachIniFilePath)
|
|
End If
|
|
If String.IsNullOrEmpty(sHolder) Then
|
|
EgtUILib.GetPrivateProfileString(S_TOOLHOLDER, sHeadName & "." & sTempExit, "", sHolder, IniFile.m_sCurrMachIniFilePath)
|
|
End If
|
|
End If
|
|
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
|
|
|
|
Friend Function Save(sName As String) As Boolean
|
|
' Verifico sia di tipo costruibile
|
|
If nType <> MCH_TY.DRILL_STD And nType <> MCH_TY.DRILL_LONG And
|
|
nType <> MCH_TY.SAW_STD And nType <> MCH_TY.SAW_FLAT And
|
|
nType <> MCH_TY.MILL_STD And nType <> MCH_TY.MILL_NOTIP And
|
|
nType <> MCH_TY.CHISEL_STD And nType <> MCH_TY.MORTISE_STD Then
|
|
Return False
|
|
End If
|
|
' Path del file da salvare
|
|
EgtSetCurrentContext(IniFile.m_ProjectSceneContext)
|
|
Dim sPath As String = String.Empty
|
|
EgtTdbGetToolDir(sPath)
|
|
sPath = sPath & "\" & sName
|
|
' passo all'ambiente di disegno dell'utensile
|
|
EgtSetCurrentContext(nToolContext)
|
|
' 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 nType = MCH_TY.SAW_STD Or nType = MCH_TY.SAW_FLAT Then
|
|
EgtRotate(EgtGetFirstGroupInGroup(GDB_ID.ROOT), Point3d.ORIG(), Vector3d.Z_AX(), -90, GDB_RT.GLOB)
|
|
End If
|
|
' salvo il modello
|
|
Dim bOk As Boolean = EgtSaveFile(sPath, NGE.CMPTEXT)
|
|
' eseguo controrotazione per lama
|
|
If nType = MCH_TY.SAW_STD Or nType = MCH_TY.SAW_FLAT 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_)
|
|
Return bOk
|
|
End Function
|
|
|
|
End Module
|