Copia locale Iniziale
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
-- 2019/09/23 11:30:00
|
||||
-- Creazione di uno scalpello per legno
|
||||
|
||||
-- Intestazioni
|
||||
require( 'EgtBase')
|
||||
_ENV = EgtProtectGlobal()
|
||||
EgtEnableDebug( false)
|
||||
|
||||
require( "EgtDimension")
|
||||
|
||||
-- Dati utensile : dichiarazione e valori standard
|
||||
local TOOL = {}
|
||||
TOOL.TOOLHOLDER = ''
|
||||
TOOL.TOTLEN = 110
|
||||
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 dWDHeight = TOOL.TOTLEN
|
||||
local dWDCylHeight = TOOL.LEN
|
||||
local dWDDiameter = TOOL.DIAM
|
||||
local dMaxMat = TOOL.MAXMAT
|
||||
local dCutterHeight = dMaxMat
|
||||
|
||||
-- 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 altezza portautensile
|
||||
local P = EgtGetFirstInGroup( GDB_ID.ROOT)
|
||||
dToolHolderHeight = tonumber( EgtGetInfo( P, "H")) or 0
|
||||
dToolHolderDiameter = tonumber( EgtGetInfo (P, "D")) or 0
|
||||
-- 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
|
||||
|
||||
-- Layer
|
||||
local Part = EgtGetFirstGroupInGroup( GDB_ID.ROOT)
|
||||
local WDLayer = EgtGetFirstInGroup( Part)
|
||||
EgtSetName( WDLayer, '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 = dWDCylHeight - dMaxMat
|
||||
if dNoCutHeight < dToolHolderHeight then
|
||||
TOOL.ERR = 12
|
||||
return
|
||||
end
|
||||
|
||||
-- Pseudo raggio
|
||||
local dRad = 0.5 * dWDDiameter
|
||||
|
||||
-- Creazione parte non tagliente
|
||||
if dNoCutHeight > 0.1 then
|
||||
local dRadP = dRad + 0.5
|
||||
local NoCutRect = EgtRectangle2P( WDLayer, { -dRadP, -dRadP, 0}, { dRadP, dRadP, 0}, GDB_RT.GRID)
|
||||
local NoCutSurf = EgtSurfTmByRegionExtrusion( WDLayer, NoCutRect, {0,0,dNoCutHeight}, 0.05, GDB_RT.GRID)
|
||||
EgtRotate( NoCutSurf, ORIG(), X_AX(), 90, GDB_RT.GRID)
|
||||
EgtSetColor( NoCutSurf, LGRAY())
|
||||
EgtErase( NoCutRect)
|
||||
end
|
||||
|
||||
-- Creazione parte tagliente
|
||||
local CutRect1 = EgtRectangle2P( WDLayer, { -dRad, -dRad, 0}, { dRad, dRad, 0}, GDB_RT.GRID)
|
||||
local dRadM = dRad - 0.5
|
||||
local CutRect2 = EgtRectangle2P( WDLayer, { -dRadM, -dRadM, 0}, { dRadM, dRadM, 0}, GDB_RT.GRID)
|
||||
local dH = dWDCylHeight - dNoCutHeight
|
||||
local CutSurf = EgtSurfTmByRegionExtrusion( WDLayer, {CutRect1, CutRect2}, { 0, 0, dH}, 0.05, GDB_RT.GRID)
|
||||
EgtMove( CutSurf, Vector3d( 0, 0, dNoCutHeight), GDB_RT.GRID)
|
||||
EgtRotate( CutSurf, ORIG(), X_AX(), 90, GDB_RT.GRID)
|
||||
EgtSetColor( CutSurf, RED())
|
||||
EgtErase( {CutRect1, CutRect2})
|
||||
|
||||
-- Quotatura
|
||||
local ptP2 = Point3d( dRad, - dWDCylHeight, 0)
|
||||
local ptP4 = Point3d( - dRad, - dWDCylHeight, 0)
|
||||
local dLenghtArrow = 0.05 * dWDHeight
|
||||
local dDistQuoteX = 10
|
||||
local dDistQuoteY = max( dToolHolderDiameter, dWDDiameter) / 2 + 10
|
||||
local dTextSize = min( 15, max( 0.1 * dWDDiameter, 0.1 * dWDHeight))
|
||||
local dTextDist = 5
|
||||
local sLenTxt = EgtNumToString( EgtToUiUnits( dWDCylHeight), 3)
|
||||
CreateLinearDimensionOnY( QuoteLayer, ORIG(), ptP4, sLenTxt, dTextSize, dDistQuoteY,
|
||||
dLenghtArrow, dTextDist, false, 'LEN', GDB_RT.GRID)
|
||||
local sDiamTxt = EgtNumToString( EgtToUiUnits( dWDDiameter), 3)
|
||||
CreateLinearDimensionOnX( QuoteLayer, ptP2, ptP4, sDiamTxt, dTextSize, dDistQuoteX,
|
||||
dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
|
||||
|
||||
TOOL.ERR = 0
|
||||
|
||||
end
|
||||
|
||||
_G.CreateTool = CreateTool
|
||||
Reference in New Issue
Block a user