104 lines
3.3 KiB
Lua
104 lines
3.3 KiB
Lua
-- 2019/02/07 09:30:00
|
|
-- Gestione di lunghezza e diametro utensile variabili
|
|
-- (tramite spostameno delle parti identificate con Info 'mobile' = 1
|
|
-- Ver.2.1b1 2019/02/13
|
|
|
|
-- Intestazioni
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( false)
|
|
|
|
require("EgtDimension")
|
|
|
|
-- Dati utensile : dichiarazione e valori standard
|
|
local TOOL = {}
|
|
TOOL.LEN = nil
|
|
TOOL.DIAM = nil
|
|
TOOL.ERR = 999
|
|
_G.TOOL = TOOL
|
|
|
|
function AdjustCustomTool()
|
|
|
|
TOOL.ERR = 999
|
|
|
|
local dToolNewL = TOOL.LEN
|
|
local dToolNewD = TOOL.DIAM
|
|
if not dToolNewL or not dToolNewD then
|
|
TOOL.ERR = 1
|
|
return
|
|
end
|
|
|
|
-- Dati utensile dal disegno
|
|
local PartId = EgtGetFirstPart()
|
|
local SolidId = EgtGetFirstNameInGroup( PartId, 'SOLID')
|
|
local dToolL = EgtGetInfo( SolidId, 'Le') -- lunghezza da disegno utensile
|
|
local dToolD = EgtGetInfo( SolidId, 'De') -- diametro da disegno utensile
|
|
|
|
-- raccolta delle parti da adattare in base alle nuove quote di input
|
|
local MobilePart = {}
|
|
local ObjId = EgtGetFirstInGroup( SolidId)
|
|
while ObjId do
|
|
if EgtExistsInfo( ObjId, 'Mobile') then
|
|
table.insert( MobilePart, ObjId)
|
|
end
|
|
ObjId = EgtGetNext( ObjId)
|
|
end
|
|
|
|
-- adattamento della lunghezza utensile in base al dato di input
|
|
if dToolL and abs ( dToolNewL - dToolL) > 10 * GEO.EPS_SMALL then
|
|
local dDeltaL = dToolNewL - dToolL
|
|
EgtMove( MobilePart, Vector3d( 0, -dDeltaL, 0))
|
|
EgtSetInfo( SolidId, 'Le', dToolNewL)
|
|
-- riporto in posizione inizio di Outline
|
|
local OutlineId = EgtGetFirstNameInGroup( SolidId, 'Outline')
|
|
if OutlineId then
|
|
EgtModifyCurveStartPoint( OutlineId, ORIG(), GDB_RT.GLOB)
|
|
end
|
|
end
|
|
|
|
-- adattamento della larghezza utensile in base al dato di input
|
|
if dToolD and abs ( dToolNewD - dToolD) > 10 * GEO.EPS_SMALL then
|
|
local dRatioD = dToolNewD / dToolD
|
|
EgtScale( MobilePart, Frame3d( 0,0,0), dRatioD, 1, dRatioD)
|
|
EgtSetInfo( SolidId, 'De', dToolNewD)
|
|
end
|
|
|
|
-- posizioni per linee di quota
|
|
local BBoxSolid = EgtGetBBoxGlob( SolidId, 0)
|
|
local dSolidMinY = BBoxSolid:getMin():getY()
|
|
local dSolidMaxX = BBoxSolid:getMax():getX()
|
|
local ptP1 = Point3d( - 0.5 * dToolNewD, - dToolNewL, 0)
|
|
local ptP2 = Point3d( 0.5 * dToolNewD, - dToolNewL, 0)
|
|
|
|
-- quotatura
|
|
local DimsId = EgtGetFirstNameInGroup( PartId, 'DIMS')
|
|
if DimsId then
|
|
EgtEmptyGroup( DimsId)
|
|
EgtSetStatus( DimsId, GDB_ST.ON)
|
|
else
|
|
DimsId = EgtGroup( PartId)
|
|
EgtSetName( DimsId, 'DIMS')
|
|
EgtSetColor( DimsId, BLACK())
|
|
end
|
|
|
|
local dDistQuoteD = -( dSolidMinY - ptP1:getY()) + 10
|
|
local dDistQuoteL = dSolidMaxX - ptP2:getX() + 10
|
|
local dTextSize = min( 20, 0.1 * max( dToolNewL, dToolNewD))
|
|
local dLenghtArrow = 0.03 * max( dToolNewL, dToolNewD)
|
|
local dTextDist = 3
|
|
|
|
local sDiamTxt = EgtNumToString( EgtToUiUnits( dToolNewD), 3)
|
|
CreateLinearDimensionOnX( DimsId, ptP1, ptP2, sDiamTxt, dTextSize, dDistQuoteD, dLenghtArrow, dTextDist, false, 'DIAM', GDB_RT.GRID)
|
|
|
|
local sLenTxt = EgtNumToString( EgtToUiUnits( dToolNewL),3)
|
|
CreateLinearDimensionOnY( DimsId, ORIG(), ptP2, sLenTxt, dTextSize, dDistQuoteL, dLenghtArrow, dTextDist, true, 'LEN', GDB_RT.GRID)
|
|
|
|
local Dims = EgtGetAllInGroup( DimsId)
|
|
if Dims then
|
|
EgtMove( Dims, Vector3d( 0, 0, BBoxSolid:getMax():getZ()+10))
|
|
end
|
|
|
|
TOOL.ERR = 0
|
|
end
|
|
_G.AdjustCustomTool = AdjustCustomTool
|