147 lines
4.7 KiB
Lua
147 lines
4.7 KiB
Lua
-- 2021/04/06 09:30:00
|
|
-- Creazione di una sega a catena per legno
|
|
-- Intestazioni
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( false)
|
|
|
|
require( "EgtDimension")
|
|
|
|
-- Dati utensile : dichiarazione e valori standard
|
|
local TOOL = {}
|
|
TOOL.TOOLHOLDER = ''
|
|
TOOL.SPEED = nil
|
|
TOOL.LEN = 400
|
|
TOOL.DIAM = 100
|
|
TOOL.THICK = 10
|
|
TOOL.CORNRAD = 50
|
|
TOOL.DIST = 90
|
|
TOOL.MAXMAT = 300
|
|
TOOL.ERR = 0
|
|
_G.TOOL = TOOL
|
|
|
|
--------------------------------------------------------------------------------
|
|
function CreateTool()
|
|
|
|
TOOL.ERR = 999
|
|
|
|
-- Parametri utensile
|
|
local sFilePath = TOOL.TOOLHOLDER
|
|
local dHeight = TOOL.LEN
|
|
local dDiameter = TOOL.DIAM
|
|
local dThick = TOOL.THICK
|
|
local dCornR = TOOL.CORNRAD
|
|
local dDist = TOOL.DIST
|
|
local dMaxMat = TOOL.MAXMAT
|
|
local dSpeed = TOOL.SPEED
|
|
|
|
-- Cancello tutto
|
|
EgtNewFile()
|
|
|
|
-- Se richiesto inserisco porta utensile
|
|
local dToolHolderHeight = 0
|
|
local dToolHolderDiameter = 0
|
|
if sFilePath and sFilePath ~= "" then
|
|
-- eseguo inserimento
|
|
if not EgtInsertFile( sFilePath) then
|
|
TOOL.ERR = 1
|
|
return
|
|
end
|
|
-- recupero dimensioniuportautensile
|
|
local Pz = EgtGetFirstInGroup( GDB_ID.ROOT)
|
|
dToolHolderHeight = EgtGetInfo( Pz, "H", 'd') or 0
|
|
dToolHolderDiameter = EgtGetInfo( Pz, "D", 'd') or 0
|
|
-- 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
|
|
-- Altrimenti creo pezzo e layer opportuni
|
|
else
|
|
-- Creo pezzo e layer
|
|
local Pz = EgtGroup( GDB_ID.ROOT)
|
|
local Ly = EgtGroup( Pz)
|
|
-- altezza portautensile rimane nulla
|
|
end
|
|
|
|
-- Layer
|
|
local Part = EgtGetFirstGroupInGroup( GDB_ID.ROOT)
|
|
local Layer = EgtGetFirstInGroup( Part)
|
|
EgtSetName( Layer, '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
|
|
|
|
-- verifico altezza parte non tagliente
|
|
local dNoCutHeight = dHeight - dMaxMat
|
|
if dNoCutHeight < dToolHolderHeight then
|
|
TOOL.ERR = 12
|
|
return
|
|
end
|
|
|
|
-- Pseudo raggio
|
|
local dRad = 0.5 * dDiameter
|
|
|
|
-- Creazione parte non tagliente
|
|
if dNoCutHeight > 0.1 then
|
|
local NoCutRect = EgtRectangle2P( Layer, { -dRad, -dNoCutHeight, 0}, { dRad, 0, 0}, GDB_RT.GRID)
|
|
local NoCutSurf = EgtSurfTmByRegionExtrusion( Layer, NoCutRect, { 0, 0, dThick}, 0.05, GDB_RT.GRID)
|
|
EgtSetColor( NoCutSurf, LGRAY())
|
|
EgtErase( NoCutRect)
|
|
end
|
|
|
|
-- Creazione parte tagliente
|
|
local Pts = {{-dRad, -dNoCutHeight, 0, 0},
|
|
{-dRad, -dHeight+dCornR, 0, 0.41421356},
|
|
{-dRad+dCornR, -dHeight, 0, 0},
|
|
{dRad-dCornR, -dHeight, 0, 0.41421356},
|
|
{dRad, -dHeight+dCornR, 0, 0},
|
|
{dRad, -dNoCutHeight, 0, 0}}
|
|
local CutShape = EgtCurveCompoFromPointBulges( Layer, Pts)
|
|
EgtCloseCurveCompo( CutShape)
|
|
local CutSurf = EgtSurfTmByRegionExtrusion( Layer, CutShape, { 0, 0, dThick}, 0.05, GDB_RT.GRID)
|
|
EgtSetColor( CutSurf, Color3d( 224, 0, 0))
|
|
EgtErase( CutShape)
|
|
|
|
-- Quotatura
|
|
local ptP2 = Point3d( dRad, - dHeight, 0)
|
|
local ptP4 = Point3d( - dRad, - dHeight, 0)
|
|
local dLenghtArrow = 0.05 * dHeight
|
|
local dDistQuoteX = 40
|
|
local dDistQuoteY = max( dToolHolderDiameter, dDiameter) / 2 + 10
|
|
local dTextSize = min( 15, max( 0.1 * dDiameter, 0.1 * dHeight))
|
|
local dTextDist = 5
|
|
local sLenTxt = EgtNumToString( EgtToUiUnits( dHeight), 3)
|
|
CreateLinearDimensionOnY( QuoteLayer, ORIG(), ptP4, sLenTxt, dTextSize, dDistQuoteY,
|
|
dLenghtArrow, dTextDist, false, 'LEN', GDB_RT.GRID)
|
|
local sDiamTxt = EgtNumToString( EgtToUiUnits( dDiameter), 3)
|
|
CreateLinearDimensionOnX( QuoteLayer, ptP2, ptP4, sDiamTxt, dTextSize, dDistQuoteX,
|
|
dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
|
|
if dDist > 1 then
|
|
local ptP5 = Point3d( -150, 50, 0)
|
|
local sDistTxt = 'D=' .. EgtNumToString( EgtToUiUnits( dDist), 3)
|
|
EgtText( QuoteLayer, ptP5, sDistTxt, dTextSize, GDB_RT.GRID)
|
|
end
|
|
|
|
TOOL.ERR = 0
|
|
end
|
|
|
|
_G.CreateTool = CreateTool
|