284 lines
10 KiB
Lua
284 lines
10 KiB
Lua
-- 2019/09/23 18:30:00
|
|
-- Creazione di un foretto
|
|
|
|
-- 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
|
|
|
|
function CreateTool()
|
|
|
|
TOOL.ERR = 999
|
|
|
|
-- Parametri utensile
|
|
local sFilePath = TOOL.TOOLHOLDER
|
|
local dDrillHeight = TOOL.LEN
|
|
local dDrillDiameter = TOOL.DIAM
|
|
local dMaxMat = TOOL.MAXMAT
|
|
local dCutterHeight = dMaxMat
|
|
local bDrillType = true
|
|
|
|
-- progetto vuoto
|
|
EgtNewFile()
|
|
|
|
local dToolHolderHeight = 0
|
|
|
|
-- 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
|
|
local P = EgtGetFirstInGroup(GDB_ID.ROOT)
|
|
dToolHolderHeight = tonumber(EgtGetInfo(P,"H"))
|
|
-- 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
|
|
|
|
-- Calcolo dimensione quote
|
|
local dMaxLinDim
|
|
if dDrillHeight > dDrillDiameter + GEO.EPS_SMALL then
|
|
dMaxLinDim = dDrillHeight
|
|
else
|
|
dMaxLinDim = dDrillDiameter
|
|
end
|
|
local dLenghtArrow = 0.05 * dMaxLinDim
|
|
local dDistQuote = 20
|
|
local dTextSize = 15
|
|
local dTextDist = 5
|
|
|
|
-- Layer
|
|
local Part = EgtGetFirstGroupInGroup(GDB_ID.ROOT)
|
|
local DrillLayer = (EgtGetFirstInGroup(Part))
|
|
EgtSetName(DrillLayer,'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
|
|
|
|
-- Se foretto periferico
|
|
if bDrillType then
|
|
|
|
local dDrillInnerHeight = dMaxMat + 5
|
|
local dSpessore = min( 3, dDrillDiameter / 4)
|
|
local dDrillInnerDiameter = dDrillDiameter - 2 * dSpessore
|
|
local dNoCutterHeight = dDrillHeight - dToolHolderHeight - dCutterHeight
|
|
local dInnNoCutterHeight = dDrillInnerHeight - dCutterHeight
|
|
|
|
if dDrillHeight - dToolHolderHeight < dDrillInnerHeight - GEO.EPS_SMALL then
|
|
TOOL.ERR = 12
|
|
return
|
|
end
|
|
|
|
if dDrillDiameter < 1 then
|
|
TOOL.ERR = 19
|
|
return
|
|
end
|
|
|
|
if dNoCutterHeight > 0.1 then
|
|
|
|
local ptP1 = Point3d(dDrillDiameter/2, - dToolHolderHeight, 0)
|
|
local ptP2 = Point3d(dDrillDiameter/2, - (dNoCutterHeight + dToolHolderHeight), 0)
|
|
local ptP3 = Point3d(dDrillInnerDiameter/2, - (dNoCutterHeight + dToolHolderHeight), 0)
|
|
local ptP4 = Point3d(dDrillInnerDiameter/2, - dDrillHeight + dDrillInnerHeight, 0)
|
|
local ptP5 = Point3d(0, - dDrillHeight + dDrillInnerHeight, 0)
|
|
|
|
local NoCutLineExt = EgtLine(DrillLayer, ptP1, ptP2, GDB_RT.GRID)
|
|
|
|
local NoCutterSurfExt = EgtSurfTmByRevolve(DrillLayer, NoCutLineExt, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(NoCutterSurfExt, LGRAY())
|
|
EgtErase(NoCutLineExt)
|
|
|
|
if dInnNoCutterHeight > 0.1 then
|
|
|
|
local NoCutIn = EgtLine(DrillLayer, ptP3, ptP4, GDB_RT.GRID)
|
|
local CeilingLine = EgtLine(DrillLayer, ptP4, ptP5, GDB_RT.GRID)
|
|
|
|
local NoCutCurve = EgtCurveCompo(DrillLayer,{NoCutIn,CeilingLine})
|
|
local NoCutterSurfInn = EgtSurfTmByRevolve(DrillLayer, NoCutCurve, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(NoCutterSurfInn, LGRAY())
|
|
EgtErase(NoCutCurve)
|
|
|
|
else
|
|
|
|
local NewCeilLine = EgtLine(DrillLayer, ptP3, ptP5, GDB_RT.GRID)
|
|
|
|
local NewCeiling = EgtSurfTmByRevolve(DrillLayer, NewCeilLine, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(NewCeiling, LGRAY())
|
|
EgtErase(NewCeilLine)
|
|
|
|
end
|
|
|
|
local ptP6 = Point3d(dDrillDiameter/2, - dDrillHeight, 0)
|
|
local ptP7 = Point3d(dDrillInnerDiameter/2, -dDrillHeight, 0)
|
|
|
|
local sLenTxt = EgtNumToString(EgtToUiUnits(dDrillHeight),3)
|
|
CreateLinearDimensionOnY(QuoteLayer, Point3d(40,0,0), ptP6, sLenTxt, dTextSize, 2*dDistQuote, dLenghtArrow, dTextDist, true, 'LEN', GDB_RT.GRID)
|
|
|
|
local ptP8 = Point3d(-dDrillDiameter/2, -dDrillHeight, 0)
|
|
|
|
local sDiamTxt = EgtNumToString(EgtToUiUnits(dDrillDiameter),3)
|
|
CreateLinearDimensionOnX(QuoteLayer, ptP8, ptP6, sDiamTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
|
|
|
|
local ptP6M = Point3d( ptP6)
|
|
ptP6M:mirror(ORIG(),X_AX())
|
|
local ptP2M = Point3d( ptP2)
|
|
ptP2M:mirror(ORIG(),X_AX())
|
|
local sMaxMatTxt = EgtNumToString(EgtToUiUnits(dMaxMat),3)
|
|
CreateLinearDimensionOnY(QuoteLayer, ptP2M, ptP6M, sMaxMatTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'MAXMAT', GDB_RT.GRID)
|
|
|
|
local CutLineExt = EgtLine(DrillLayer, ptP2, ptP6, GDB_RT.GRID)
|
|
local CutLineBot = EgtLine(DrillLayer, ptP6, ptP7, GDB_RT.GRID)
|
|
local CutLineInn = EgtLine(DrillLayer, ptP7, ptP3, GDB_RT.GRID)
|
|
|
|
local CutLin = EgtCurveCompo(DrillLayer,{CutLineExt,CutLineBot,CutLineInn})
|
|
|
|
local CutterSurf = EgtSurfTmByRevolve(DrillLayer, CutLin, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(CutterSurf, ORANGE())
|
|
EgtErase(CutLin)
|
|
|
|
else
|
|
|
|
local ptP1 = Point3d(dDrillDiameter/2, - dToolHolderHeight, 0)
|
|
local ptP2 = Point3d(dDrillDiameter/2, - dDrillHeight, 0)
|
|
local ptP3 = Point3d(dDrillInnerDiameter/2, - dDrillHeight, 0)
|
|
local ptP4 = Point3d(dDrillInnerDiameter/2, - dToolHolderHeight, 0)
|
|
local ptP5 = Point3d(0, - dToolHolderHeight, 0)
|
|
local ptP6 = Point3d(-dDrillDiameter/2, - dDrillHeight, 0)
|
|
|
|
local sLenTxt = EgtNumToString(EgtToUiUnits(dDrillHeight),3)
|
|
CreateLinearDimensionOnY(QuoteLayer, ORIG(), ptP2, sLenTxt, dTextSize, 2*dDistQuote, dLenghtArrow, dTextDist, true, 'LEN', GDB_RT.GRID)
|
|
|
|
local sDiamTxt = EgtNumToString(EgtToUiUnits(dDrillDiameter),3)
|
|
CreateLinearDimensionOnX(QuoteLayer, ptP2, ptP6, sDiamTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
|
|
|
|
local ptP1M = Point3d( ptP1)
|
|
ptP1M:mirror(ORIG(),X_AX())
|
|
local ptP2M = Point3d( ptP2)
|
|
ptP2M:mirror(ORIG(),X_AX())
|
|
local sMaxMatTxt = EgtNumToString(EgtToUiUnits(dMaxMat),3)
|
|
CreateLinearDimensionOnY(QuoteLayer, ptP1M, ptP2M, sMaxMatTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'MAXMAT', GDB_RT.GRID)
|
|
|
|
local Ext = EgtLine(DrillLayer, ptP1, ptP2, GDB_RT.GRID)
|
|
local Bot = EgtLine(DrillLayer, ptP2, ptP3, GDB_RT.GRID)
|
|
local Inn = EgtLine(DrillLayer, ptP3, ptP4, GDB_RT.GRID)
|
|
|
|
local CutCurve = EgtCurveCompo(DrillLayer,{Ext,Bot,Inn})
|
|
|
|
local CutSurf = EgtSurfTmByRevolve(DrillLayer, CutCurve, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(CutSurf, ORANGE())
|
|
|
|
EgtErase(CutCurve)
|
|
|
|
local Cei = EgtLine(DrillLayer, ptP4, ptP5, GDB_RT.GRID)
|
|
|
|
local CeiSurf = EgtSurfTmByRevolve(DrillLayer, Cei, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(CeiSurf, LGRAY())
|
|
|
|
EgtErase(Cei)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local dNoCutterHeight = dDrillHeight - dToolHolderHeight - dCutterHeight
|
|
|
|
if dNoCutterHeight < - GEO.EPS_SMALL then
|
|
TOOL.ERR = 12
|
|
return
|
|
end
|
|
|
|
if dNoCutterHeight > 0.1 then
|
|
|
|
local ptP1 = Point3d(dDrillDiameter/2, - dToolHolderHeight, 0)
|
|
local ptP2 = Point3d(dDrillDiameter/2, - (dNoCutterHeight + dToolHolderHeight), 0)
|
|
local ptP3 = Point3d(dDrillDiameter/2, - dDrillHeight, 0)
|
|
local ptP4 = Point3d(0, - dDrillHeight, 0)
|
|
local ptP5 = Point3d(-dDrillDiameter/2, -dDrillHeight, 0)
|
|
|
|
local sLenTxt = EgtNumToString(EgtToUiUnits(dDrillHeight),3)
|
|
CreateLinearDimensionOnY(QuoteLayer, ORIG(), ptP3, sLenTxt, dTextSize, 2*dDistQuote, dLenghtArrow, dTextDist, true, 'LEN', GDB_RT.GRID)
|
|
|
|
local sDiamTxt = EgtNumToString(EgtToUiUnits(dDrillDiameter),3)
|
|
CreateLinearDimensionOnX(QuoteLayer, ptP5, ptP3, sDiamTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
|
|
|
|
local NoCutterLine = EgtLine(DrillLayer, ptP1, ptP2, GDB_RT.GRID)
|
|
local CutterLine = EgtLine(DrillLayer, ptP2, ptP3, GDB_RT.GRID)
|
|
local TipLine = EgtLine(DrillLayer, ptP3, ptP4, GDB_RT.GRID)
|
|
|
|
local NoCutterSurf = EgtSurfTmByRevolve(DrillLayer, NoCutterLine, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(NoCutterSurf, LGRAY())
|
|
EgtErase(NoCutterLine)
|
|
|
|
local CutLin = EgtCurveCompo(DrillLayer,{CutterLine,TipLine})
|
|
|
|
local CutterSurf = EgtSurfTmByRevolve(DrillLayer, CutLin, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(CutterSurf, ORANGE())
|
|
EgtErase(CutLin)
|
|
|
|
else
|
|
|
|
local ptP1 = Point3d(dDrillDiameter/2, - dToolHolderHeight, 0)
|
|
local ptP2 = Point3d(dDrillDiameter/2, - dDrillHeight, 0)
|
|
local ptP3 = Point3d(0, - dDrillHeight, 0)
|
|
|
|
local sLenTxt = EgtNumToString(EgtToUiUnits(dDrillHeight),3)
|
|
CreateLinearDimensionOnY(QuoteLayer,ORIG(), ptP2, sLenTxt, dTextSize, 2*dDistQuote, dLenghtArrow, dTextDist, true, 'LEN', GDB_RT.GRID)
|
|
|
|
local ptP4 = Point3d(-dDrillDiameter/2, -dDrillHeight, 0)
|
|
|
|
local sDiamTxt = EgtNumToString(EgtToUiUnits(dDrillDiameter),3)
|
|
CreateLinearDimensionOnX(QuoteLayer, ptP2, ptP4, sDiamTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
|
|
|
|
local Curve1 = EgtLine(DrillLayer, ptP1, ptP2, GDB_RT.GRID)
|
|
local Curve2 = EgtLine(DrillLayer, ptP2, ptP3, GDB_RT.GRID)
|
|
|
|
local CutCurve = EgtCurveCompo(DrillLayer, {Curve1, Curve2})
|
|
|
|
local CutSurf = EgtSurfTmByRevolve(DrillLayer, CutCurve, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID)
|
|
|
|
EgtSetColor(CutSurf, ORANGE())
|
|
|
|
EgtErase(CutCurve)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
TOOL.ERR = 0
|
|
end
|
|
_G.CreateTool = CreateTool
|