Files
Carlo Baronchelli 741791a0e4 Copia locale Iniziale
2022-05-19 16:04:07 +02:00

142 lines
4.3 KiB
Lua

-- 2019/09/23 09:30:00
-- Creazione di fresa cilindrica
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
require("EgtDimension")
-- Dati utensile : dichiarazione e valori standard
local TOOL = {}
TOOL.TOOLHOLDER = ''
TOOL.LEN = 80
TOOL.DIAM = 20
TOOL.MAXMAT = 40
TOOL.ERR = 0
_G.TOOL = TOOL
-- Creazione utensile cilindrico
function CreateTool()
TOOL.ERR = 999
-- Parametri utensile
local nType = TOOL.TYPE
local sFilePath = TOOL.TOOLHOLDER
local dMillHeight = TOOL.LEN
local dMillDiameter = TOOL.DIAM
local dCutterHeight = TOOL.MAXMAT
-- progetto vuoto
EgtNewFile()
local dToolHolderHeight = 0
local dStemDiam = 40
-- Se richiesto inserisco porta utensile
if sFilePath and sFilePath ~= "" then
-- eseguo inserimento
if not EgtInsertFile(sFilePath) then
TOOL.ERR = 1
return
end
-- recupero altezza portautensile e diametro gambo
local P = EgtGetFirstInGroup( GDB_ID.ROOT)
dToolHolderHeight = tonumber( EgtGetInfo( P, "H") or '0')
dStemDiam = tonumber( EgtGetInfo( P, "D_STEM") or '40')
-- Altrimenti creo pezzo e layer opportuni
else
-- Creo pezzo e layer
local P = EgtGroup(GDB_ID.ROOT)
local L = EgtGroup(P)
-- altezza portautensile rimane nulla
end
-- Controllo lunghezza utensile
if dMillHeight - dToolHolderHeight - dCutterHeight < 0 then
TOOL.ERR = 12
return
end
-- Calcolo dimensione quote
local dMaxLinDim
if dMillHeight > dMillDiameter then
dMaxLinDim = dMillHeight
else
dMaxLinDim = dMillDiameter
end
local dLenghtArrow = 0.05 * dMaxLinDim
local dDistQuote = 20
local dTextSize = 15
local dTextDist = 5
-- Layer
local Part = EgtGetFirstGroupInGroup(GDB_ID.ROOT)
local MillLayer = (EgtGetFirstInGroup(Part))
EgtSetName(MillLayer,'SOLID')
local QuoteLayer = EgtGroup(Part)
EgtSetName(QuoteLayer,'AUX')
EgtSetColor(QuoteLayer,BLACK())
if EgtGetBackground then
local colTop, colBot = EgtGetBackground()
if colTop and colBot then
local nInt = colTop:getRed() + colTop:getGreen() + colTop:getBlue() + colBot:getRed() + colBot:getGreen() + colBot:getBlue()
if nInt < 769 then
EgtSetColor( QuoteLayer, WHITE())
end
end
end
-- Disegno utensile
local dTopDiam = min( dStemDiam, dMillDiameter)
local ptP1 = Point3d( dTopDiam/2, - dToolHolderHeight, 0)
local ptP2 = Point3d( dMillDiameter/2, -(dMillHeight - dCutterHeight), 0)
if dMillHeight - dToolHolderHeight - dCutterHeight > 0.1 then
local NoCutterLine = EgtLine(MillLayer, ptP1, ptP2, GDB_RT.GRID)
local NoCutterHeight = dMillHeight - dToolHolderHeight - dCutterHeight
local NoCutterSurf = EgtSurfTmByRevolve(MillLayer, NoCutterLine, Point3d(0,0,0), Vector3d(0,-1,0), false, 0.05, GDB_RT.GRID)
EgtSetColor(NoCutterSurf, LGRAY())
EgtErase(NoCutterLine)
else
ptP2 = Point3d( ptP1)
end
local ptP3 = Point3d(dMillDiameter/2, -dMillHeight, 0)
local CutterLine = EgtLine(MillLayer, ptP2, ptP3, GDB_RT.GRID)
local sLenTxt = EgtNumToString(EgtToUiUnits(dMillHeight),3)
CreateLinearDimensionOnY(QuoteLayer, Point3d(0,0,0), ptP3, sLenTxt, dTextSize, 2.5 * dDistQuote, dLenghtArrow, dTextDist, true, 'LEN', GDB_RT.GRID)
local ptP2M = Point3d( ptP2)
ptP2M:mirror(ORIG(),X_AX())
local ptP3M = Point3d( ptP3)
ptP3M:mirror(ORIG(),X_AX())
local sMaxMatTxt = EgtNumToString(EgtToUiUnits(dCutterHeight),3)
CreateLinearDimensionOnY(QuoteLayer, ptP2M, ptP3M, sMaxMatTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'MAXMAT', GDB_RT.GRID)
local ptP4 = Point3d(0, -dMillHeight, 0)
local TipLine = EgtLine(MillLayer, ptP3, ptP4, GDB_RT.GRID)
local ptP5 = Point3d(-dMillDiameter/2,-dMillHeight, 0)
local sDiamTxt = EgtNumToString(EgtToUiUnits(dMillDiameter),3)
CreateLinearDimensionOnX(QuoteLayer, ptP3, ptP5, sDiamTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
CutterLine = EgtCurveCompo(MillLayer,{CutterLine, TipLine})
local CutterSurf = EgtSurfTmByRevolve(MillLayer, CutterLine, Point3d(0,0,0), Vector3d(0,-1,0), false, 0.05, GDB_RT.GRID)
EgtSetColor(CutterSurf,ORANGE())
EgtErase(CutterLine)
TOOL.ERR = 0
end
_G.CreateTool = CreateTool