216 lines
7.9 KiB
Lua
216 lines
7.9 KiB
Lua
-- 2021/03/14 10:30:00
|
|
-- Creazione di una lama
|
|
-- 2021/03/14 Aggiunta gestione parte mobile del porta-utensile (ThMobile).
|
|
|
|
-- Intestazioni
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( false)
|
|
|
|
require("EgtDimension")
|
|
|
|
-- Dati utensile : dichiarazione e valori standard
|
|
local TOOL = {}
|
|
TOOL.TOOLHOLDER = ''
|
|
TOOL.SPEED = nil
|
|
TOOL.LEN = 80
|
|
TOOL.DIAM = 400
|
|
TOOL.CORE = 4
|
|
TOOL.THICK = 5
|
|
TOOL.CORNRAD = 0
|
|
TOOL.MAXMAT = 40
|
|
TOOL.ERR = 0
|
|
_G.TOOL = TOOL
|
|
|
|
function CreateTool()
|
|
|
|
TOOL.ERR = 999
|
|
|
|
-- Parametri utensile
|
|
local sFilePath = TOOL.TOOLHOLDER
|
|
local dSawHeight = TOOL.LEN
|
|
local dSawRad = TOOL.DIAM / 2
|
|
local dSawCornRad = TOOL.CORNRAD
|
|
local bCornRad = ( dSawCornRad > GEO.EPS_SMALL)
|
|
local dBodyThickness = TOOL.CORE
|
|
local dToothThickness = TOOL.THICK
|
|
local dToothRadLen = min( 20, dSawRad / 2)
|
|
local dToothOffs = ( dToothThickness - dBodyThickness) / 2
|
|
-- Parametri portautensile
|
|
local dThHeight = 0
|
|
local dThTotHeight = 0
|
|
-- Rotazione
|
|
local dSpeed = TOOL.SPEED
|
|
|
|
-- Progetto vuoto
|
|
EgtNewFile()
|
|
local Pz = GDB_ID.NULL
|
|
|
|
-- 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
|
|
Pz = EgtGetFirstInGroup( GDB_ID.ROOT)
|
|
dThHeight = EgtGetInfo( Pz, "H", 'd') or 0
|
|
-- recupero ingombro portautensile
|
|
local b3Th = EgtGetBBoxGlob( Pz, GDB_BB.STANDARD)
|
|
if b3Th then
|
|
dThTotHeight = abs( b3Th:getMin():getY())
|
|
end
|
|
-- eventuale visualizzazione senso di rotazione
|
|
local Ly = EgtGetFirstInGroup( Pz or GDB_ID.NULL)
|
|
local RotId = EgtGetFirstNameInGroup( Ly or GDB_ID.NULL, 'Rot')
|
|
if RotId then
|
|
if dSpeed and abs( dSpeed) > 1 then
|
|
-- se rotazione opposta, devo invertire
|
|
if dSpeed < 0 then
|
|
EgtMirror( RotId, ORIG(), X_AX(), GDB_RT.GLOB)
|
|
end
|
|
else
|
|
EgtSetStatus( RotId, GDB_ST.OFF)
|
|
end
|
|
end
|
|
-- posizionamento eventuale parte mobile
|
|
local ThMobId = EgtGetFirstNameInGroup( Ly or GDB_ID.NULL, 'ThMobile')
|
|
if ThMobId then
|
|
EgtMove( ThMobId, Vector3d( 0, -dSawHeight, 0))
|
|
end
|
|
-- Altrimenti creo pezzo e layer opportuni
|
|
else
|
|
-- Creo pezzo e layer
|
|
Pz = EgtGroup( GDB_ID.ROOT)
|
|
EgtGroup( Pz)
|
|
-- altezza portautensile rimane nulla
|
|
end
|
|
|
|
-- Ruoto la lama per ragioni di visualizzazione
|
|
EgtRotate( Pz, ORIG(), Z_AX(), 90, GDB_RT.GRID)
|
|
|
|
-- Calcolo dimensione quote
|
|
local dMaxLinDim
|
|
if dSawHeight > 2 * dSawRad + GEO.EPS_SMALL then
|
|
dMaxLinDim = dSawHeight
|
|
else
|
|
dMaxLinDim = 2 * dSawRad
|
|
end
|
|
local dLenghtArrow = 0.005 * dMaxLinDim
|
|
local dDistQuote = 40
|
|
local dTextSize = 15
|
|
local dTextDist = 5
|
|
|
|
-- Layers
|
|
local SawLayer = EgtGetFirstGroupInGroup( Pz)
|
|
EgtSetName( SawLayer, 'SOLID')
|
|
local QuoteLayer = EgtGroup( Pz)
|
|
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
|
|
|
|
-- Controllo se i valori passati degli spessori sono validi (dToothThickness deve essere maggiore di dBodyThickness)
|
|
if dToothOffs < - GEO.EPS_SMALL or dBodyThickness < 0.1 then
|
|
TOOL.ERR = 2
|
|
return
|
|
end
|
|
|
|
-- Raggio corner non deve essere superiore a metà spessore
|
|
dSawCornRad = min( dSawCornRad, 0.5 * dToothThickness)
|
|
|
|
-- Determino l'altezza del gambo e fisso i parametri geometrici diametro gambo e lunghezza radiale dei denti
|
|
local dStemHeight = dSawHeight - dThHeight - dToothThickness + dToothOffs
|
|
local dStemRad = max( min( dSawRad / 8, 60), 1)
|
|
|
|
-- Controllo: se il gambo è di lunghezza negativa errore
|
|
if dStemHeight < - GEO.EPS_SMALL then
|
|
TOOL.ERR = 3
|
|
return
|
|
end
|
|
|
|
-- Gambo, se previsto
|
|
local vStem = {}
|
|
if dStemHeight > 0.1 then
|
|
vStem[1] = Point3d( dThHeight, 0, 0)
|
|
vStem[2] = Point3d( dThHeight, dStemRad, 0)
|
|
vStem[3] = Point3d( dThHeight + dStemHeight, dStemRad, 0)
|
|
local StemLine = EgtCurveCompoFromPoints( SawLayer, vStem, GDB_RT.GRID)
|
|
local StemSurf = EgtSurfTmByRevolve( SawLayer, StemLine, ORIG(), X_AX(), false, 0.05, GDB_RT.GRID)
|
|
EgtSetColor( StemSurf, LGRAY())
|
|
EgtErase( StemLine)
|
|
else
|
|
dStemHeight = 0
|
|
vStem[3] = Point3d( dThHeight, 0, 0)
|
|
end
|
|
|
|
-- Corpo
|
|
local vBody = {}
|
|
vBody[1] = Point3d( vStem[3])
|
|
vBody[2] = Point3d( dThHeight + dStemHeight, dSawRad - dToothRadLen, 0)
|
|
vBody[3] = Point3d( dThHeight + dStemHeight + dBodyThickness, dSawRad - dToothRadLen, 0)
|
|
vBody[4] = Point3d( dThHeight + dStemHeight + dBodyThickness, 0, 0)
|
|
local BodyLineUp = EgtLine( SawLayer, vBody[1], vBody[2], GDB_RT.GRID)
|
|
local BodyLineDw = EgtLine( SawLayer, vBody[3], vBody[4], GDB_RT.GRID)
|
|
local BodySurfUp = EgtSurfTmByRevolve( SawLayer, BodyLineUp, ORIG(), X_AX(), false, 0.05, GDB_RT.GRID)
|
|
local BodySurfDw = EgtSurfTmByRevolve( SawLayer, BodyLineDw, ORIG(), X_AX(), false, 0.05, GDB_RT.GRID)
|
|
EgtSetColor( { BodySurfUp, BodySurfDw}, Color3d( 224, 32, 32))
|
|
EgtErase( { BodyLineUp, BodyLineDw})
|
|
|
|
-- Denti
|
|
local vTooth = {}
|
|
table.insert( vTooth, Point4d( vBody[2], 0))
|
|
table.insert( vTooth, Point4d( dThHeight + dStemHeight - dToothOffs, dSawRad - dToothRadLen, 0, 0))
|
|
local ptLeft = Point3d( dThHeight + dStemHeight - dToothOffs, dSawRad, 0)
|
|
if bCornRad then
|
|
table.insert( vTooth, Point4d( ptLeft - Y_AX() * dSawCornRad, -0.414213562))
|
|
table.insert( vTooth, Point4d( ptLeft + X_AX() * dSawCornRad, 0))
|
|
else
|
|
table.insert( vTooth, Point4d( ptLeft, 0))
|
|
end
|
|
local ptRight = Point3d( dSawHeight, dSawRad, 0)
|
|
if bCornRad then
|
|
table.insert( vTooth, Point4d( ptRight - X_AX() * dSawCornRad, -0.414213562))
|
|
table.insert( vTooth, Point4d( ptRight - Y_AX() * dSawCornRad, 0))
|
|
else
|
|
table.insert( vTooth, Point4d( ptRight, 0))
|
|
end
|
|
table.insert( vTooth, Point4d( dSawHeight, dSawRad - dToothRadLen, 0, 0))
|
|
table.insert( vTooth, Point4d( vBody[3], 0))
|
|
--local ToothLine = EgtCurveCompoFromPoints( SawLayer, vTooth, GDB_RT.GRID)
|
|
local ToothLine = EgtCurveCompoFromPointBulges( SawLayer, vTooth, GDB_RT.GRID)
|
|
local ToothSurf = EgtSurfTmByRevolve( SawLayer, ToothLine, ORIG(), X_AX(), false, 0.05, GDB_RT.GRID)
|
|
EgtSetColor( ToothSurf, Color3d( 224, 0, 0))
|
|
EgtErase( ToothLine)
|
|
|
|
-- Quotature
|
|
-- creo punto diametralmente opposto a ptRight
|
|
local ptToothDw = Point3d( dSawHeight, -dSawRad, 0)
|
|
local dDistAdd = max( dThTotHeight - dSawHeight, 0)
|
|
local sLenTxt = EgtNumToString( EgtToUiUnits( dSawHeight), 3)
|
|
CreateLinearDimensionOnX( QuoteLayer, ORIG(), ptToothDw, sLenTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, false, "LEN", GDB_RT.GRID)
|
|
local sThickTxt = EgtNumToString( EgtToUiUnits( dToothThickness), 3)
|
|
CreateLinearDimensionOnX( QuoteLayer, ptLeft, ptRight, sThickTxt, dTextSize, dDistQuote, dLenghtArrow, dTextDist, true, "THICK", GDB_RT.GRID)
|
|
local sDiamTxt = EgtNumToString( EgtToUiUnits( 2 * dSawRad), 3)
|
|
CreateLinearDimensionOnY( QuoteLayer, ptRight, ptToothDw, sDiamTxt, dTextSize, dDistQuote + dDistAdd, dLenghtArrow, dTextDist, true, "DIAM", GDB_RT.GRID)
|
|
if bCornRad then
|
|
local sCradTxt = EgtNumToString( EgtToUiUnits( dSawCornRad), 3)
|
|
local ptC = ptToothDw + Vector3d( -dSawCornRad, dSawCornRad, 0)
|
|
local ptOn = ptC + VectorFromPolar( dSawCornRad + 0.05 * dDistQuote, -45)
|
|
local ptText = ptOn + VectorFromPolar( 0.5 * dDistQuote, -45)
|
|
CreateRadialDimension( QuoteLayer, ptText, ptOn, sCradTxt, dTextSize, dDistQuote + dDistAdd, dLenghtArrow, dTextDist, nil, "CRAD", GDB_RT.GRID)
|
|
end
|
|
|
|
TOOL.ERR = 0
|
|
|
|
end
|
|
_G.CreateTool = CreateTool
|