236 lines
7.4 KiB
Lua
236 lines
7.4 KiB
Lua
-- Intestazioni
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( true)
|
|
|
|
-- recupro il primo oggeto (da modificare)
|
|
local nId = EgtGetFirstSelectedObj()
|
|
-- recupero il secondo oggetto (rispetto al quale riferirsi)
|
|
local nId2 = EgtGetNextSelectedObj()
|
|
|
|
local PAR = {}
|
|
|
|
_G.PAR = PAR
|
|
|
|
PAR.nId1 = -1
|
|
PAR.Pt1 = Point3d(0,0,0)
|
|
PAR.dU1 = 0.0
|
|
PAR.nId2 = -1
|
|
PAR.Pt2 = Point3d(0,0,0)
|
|
PAR.dU2 = 0.0
|
|
PAR.nSubCrv1 = 0
|
|
PAR.nSubCrv2 = 0
|
|
|
|
PAR.Len = 0.0
|
|
|
|
PAR.vtMove = Vector3d(0,0,0)
|
|
|
|
local function ErasePoint( Id)
|
|
local IdPt1 = EgtGetInfo(Id, 'DrawPoint', 'i')
|
|
EgtErase( IdPt1)
|
|
end
|
|
--
|
|
local function DrawPoint( Id, Pt, sCol)
|
|
if Id > -1 then
|
|
ErasePoint( Id)
|
|
local Lay = EgtGetParent( Id)
|
|
local IdPt1 = EgtPoint( Lay, Pt, GDB_RT.GLOB)
|
|
EgtSetColor( {IdPt1}, EgtStdColor( sCol))
|
|
EgtSetInfo( Id, 'DrawPoint', IdPt1)
|
|
EgtSelectObj( IdPt1)
|
|
EgtDraw()
|
|
end
|
|
end
|
|
--
|
|
function PAR.DrawFirstPoint()
|
|
if PAR.nId1 > -1 then
|
|
DrawPoint( PAR.nId1, PAR.Pt1, 'RED')
|
|
end
|
|
end
|
|
--
|
|
function PAR.DrawSecondPoint()
|
|
if PAR.nId2 > -1 then
|
|
DrawPoint( PAR.nId2, PAR.Pt2, 'BLUE')
|
|
end
|
|
end
|
|
--
|
|
-- Accosto due linee
|
|
function PAR.LinksLine()
|
|
local vtMove = Point3d(PAR.Pt2) - Point3d(PAR.Pt1)
|
|
PAR.vtMove = vtMove
|
|
EgtMove( {PAR.nId1}, vtMove, GDB_RT.GLOB)
|
|
ErasePoint( PAR.nId1)
|
|
ErasePoint( PAR.nId2)
|
|
EgtDraw()
|
|
end
|
|
--
|
|
-- Ottenco una curva compisita (non posso tornare indietro)
|
|
function PAR.JointLine()
|
|
EgtCurveCompoByChain( EgtGetParent(PAR.nId1), {PAR.nId1,PAR.nId2}, Point3d(PAR.Pt2), true, GDB_RT.GLOB)
|
|
PAR.Reset()
|
|
EgtDraw()
|
|
end
|
|
--
|
|
-- Riposiziono il primo segmento nel punto di partenza
|
|
function PAR.UndoLinksLine()
|
|
if PAR.nId1 > -1 then
|
|
EgtMove( {PAR.nId1}, PAR.vtMove*(-1), GDB_RT.GLOB)
|
|
end
|
|
end
|
|
--
|
|
|
|
local function EraseLinearDimension()
|
|
local IdDimension = EgtGetInfo( PAR.nId1, 'LinearDim'..tostring(PAR.nSubCrv1), 'i')
|
|
EgtErase( IdDimension)
|
|
end
|
|
--
|
|
|
|
function PAR.DrawLinearDimension()
|
|
EraseLinearDimension()
|
|
local vtDir = EgtSV( PAR.nId1, GDB_RT.GLOB)
|
|
vtDir:rotate({0,0,1}, 90)
|
|
|
|
local ptStart = EgtUP( PAR.nId1, PAR.nSubCrv1, GDB_RT.GLOB)
|
|
local ptEnd = EgtUP( PAR.nId1, (PAR.dU1 == PAR.nSubCrv1 and PAR.nSubCrv1 + 1 or PAR.dU1), GDB_RT.GLOB)
|
|
local IdDimension = EgtAlignedDimension( EgtGetParent(PAR.nId1), ptStart, ptEnd,vtDir * 50,'<>',GDB_RT.GLOB)
|
|
EgtSetInfo( PAR.nId1, 'LinearDim'..tostring(PAR.nSubCrv1), IdDimension)
|
|
ErasePoint( PAR.nId1)
|
|
EgtDraw()
|
|
end
|
|
--
|
|
|
|
function PAR.LinearDimension()
|
|
if PAR.nId1 == -1 then return end
|
|
|
|
local dFinalLen = tonumber( PAR.Len )
|
|
if PAR.dU1 == PAR.nSubCrv1 then
|
|
local vtDir = EgtUV( PAR.nId1, PAR.nSubCrv1+0.1, GDB_RT.GLOB)
|
|
local dStartLen = dist(EgtUP( PAR.nId1, PAR.dU1, GDB_RT.GLOB), EgtUP( PAR.nId1, PAR.dU1 + 1, GDB_RT.GLOB))
|
|
vtDir = vtDir * ( dFinalLen - dStartLen) * (-1)
|
|
local NewStartPoint = EgtUP( PAR.nId1, PAR.dU1, GDB_RT.GLOB) + vtDir
|
|
if not (EgtGetType(PAR.nId1) == GDB_TY.CRV_COMPO) then
|
|
EgtModifyCurveStartPoint( PAR.nId1, NewStartPoint, GDB_RT.GLOB)
|
|
else
|
|
EgtModifyCurveCompoJoint( PAR.nId1, PAR.dU1, NewStartPoint, GDB_RT.GLOB)
|
|
end
|
|
else
|
|
local vtDir = EgtUV( PAR.nId1, PAR.nSubCrv1+0.1, GDB_RT.GLOB)
|
|
local dStartLen = dist(EgtUP( PAR.nId1, PAR.dU1, GDB_RT.GLOB), EgtUP( PAR.nId1, PAR.nSubCrv1, GDB_RT.GLOB))
|
|
vtDir = vtDir * ( dFinalLen - dStartLen)
|
|
local NewEndPoint = EgtUP( PAR.nId1, PAR.dU1, GDB_RT.GLOB) + vtDir
|
|
if not (EgtGetType(PAR.nId1) == GDB_TY.CRV_COMPO) then
|
|
EgtModifyCurveEndPoint( PAR.nId1, NewEndPoint, GDB_RT.GLOB)
|
|
else
|
|
EgtModifyCurveCompoJoint( PAR.nId1, PAR.dU1, NewEndPoint, GDB_RT.GLOB)
|
|
end
|
|
end
|
|
end
|
|
--
|
|
|
|
local function EraseAngularDimension()
|
|
local IdDimension = EgtGetInfo( PAR.nId1, 'AngularDim', 'i')
|
|
EgtErase( IdDimension)
|
|
end
|
|
--
|
|
|
|
function PAR.DrawAngularDimension()
|
|
EraseAngularDimension()
|
|
local vtDir = EgtSV( PAR.nId1, GDB_RT.GLOB)
|
|
local vtDir1 = Vector3d(1,0,0)
|
|
if nId2 then
|
|
vtDir1 = EgtSV( PAR.nId2, GDB_RT.GLOB)
|
|
end
|
|
IdDimension = EgtAngularDimension( EgtGetParent(PAR.nId1),EgtSP(PAR.nId1, GDB_RT.GLOB),EgtSP(PAR.nId1, GDB_RT.GLOB) + vtDir1,EgtSP(PAR.nId1, GDB_RT.GLOB) + vtDir, vtDir*50,'<>',GDB_RT.GLOB)
|
|
EgtSetInfo( nId, 'AngularDim', IdDimension)
|
|
EgtDraw()
|
|
end
|
|
--
|
|
|
|
function PAR.AngularDimension()
|
|
local vtDir = EgtUV( PAR.nId1, PAR.nSubCrv1+0.1, GDB_RT.GLOB)
|
|
if PAR.nId2 then
|
|
vtDir1 = EgtSV( PAR.nId2, GDB_RT.GLOB)
|
|
end
|
|
local dStartAng = GetRotation(vtDir, vtDir1, Z_AX())
|
|
local vsAng = PAR.Ang
|
|
local dFinalAng = tonumber( vsAng)
|
|
local ptAx = EgtUP(PAR.nId1, PAR.dU1, GDB_RT.GLOB)
|
|
EgtRotate({PAR.nId1},ptAx,Z_AX(), math.abs(dFinalAng-dStartAng),GDB_RT.GLOB)
|
|
end
|
|
|
|
function PAR.Reset()
|
|
ErasePoint( PAR.nId1)
|
|
PAR.nId1 = -1
|
|
PAR.Pt1 = Point3d(0,0,0)
|
|
PAR.dU1 = 0.0
|
|
ErasePoint( PAR.nId2)
|
|
PAR.nId2 = -1
|
|
PAR.Pt2 = Point3d(0,0,0)
|
|
PAR.dU2 = 0.0
|
|
PAR.nSubCrv1 = 0
|
|
PAR.nSubCrv2 = 0
|
|
end
|
|
--
|
|
|
|
local function SelectConstraint(sMsgComboBox)
|
|
local vsVal = EgtDialogBox( 'Select constraint',
|
|
{ 'Show', sMsgComboBox})
|
|
if not vsVal then return end
|
|
|
|
local Constraint = string.gsub( vsVal[1], '%s+', '')
|
|
if Constraint == 'Startpoint' then
|
|
TabConstraint.Stp = 'FIXED'
|
|
if nId2 then
|
|
local vsSelPt = EgtDialogBox( 'Type of joint?',
|
|
{ 'Show', 'CB:* Start-End, Start-Start, End-Start, End-End'})
|
|
local FinalPonint = EgtEP( nId2, GDB_RT.GLOB)
|
|
local StartPoint = EgtSP( nId, GDB_RT.GLOB)
|
|
if vsSelPt then
|
|
if vsSelPt[1] == 'Start-Start' then
|
|
FinalPonint = EgtSP( nId2, GDB_RT.GLOB)
|
|
elseif vsSelPt[1] == 'End-Start' then
|
|
FinalPonint = EgtSP( nId2, GDB_RT.GLOB)
|
|
StartPoint = EgtEP( nId, GDB_RT.GLOB)
|
|
elseif vsSelPt[1] == 'End-End' then
|
|
StartPoint = EgtEP( nId, GDB_RT.GLOB)
|
|
end
|
|
end
|
|
EgtSetInfo(nId2, StP, 'LINKED')
|
|
local vtMove = FinalPonint - StartPoint
|
|
EgtMove(GetLinkedLine(), vtMove, GDB_RT.GLOB)
|
|
-- EgtAddCurveCompoCurve
|
|
TabConstraint.Stp = 'LINKED'
|
|
end
|
|
|
|
elseif Constraint == 'Lenght' then
|
|
TabConstraint.Len = 'FIXED'
|
|
local dStartLen = EgtCurveLength( nId)
|
|
local vsLen = EgtDialogBox( 'Define constraint value',
|
|
{ 'Lenght', tostring(dStartLen)})
|
|
if vsLen then
|
|
local vtDir = EgtSV( nId, GDB_RT.GLOB)
|
|
local dFinalLen = tonumber( vsLen[1])
|
|
vtDir = vtDir * ( dFinalLen - dStartLen)
|
|
local NewEndPoint = EgtEP( nId, GDB_RT.GLOB) + vtDir
|
|
EgtModifyCurveEndPoint( nId, NewEndPoint, GDB_RT.GLOB)
|
|
end
|
|
|
|
elseif Constraint == 'Direction' then
|
|
TabConstraint.Dir = 'FIXED'
|
|
local vtDir = EgtSV( nId, GDB_RT.GLOB)
|
|
local vtDir1 = Vector3d(1,0,0)
|
|
if nId2 then
|
|
vtDir1 = EgtSV( nId2, GDB_RT.GLOB) * (-1)
|
|
end
|
|
local dStartAng = math.acos( vtDir*vtDir1) * 180 / math.pi
|
|
local vsAng = EgtDialogBox( 'Define constraint value',
|
|
{ 'Angle', tostring(dStartAng)})
|
|
if vsAng then
|
|
local dFinalAng = tonumber( vsAng[1])
|
|
EgtRotate({nId},EgtSP(nId, GDB_RT.GLOB),{0,0,1}, math.abs(dFinalAng-dStartAng),GDB_RT.GLOB)
|
|
vtDir = EgtSV( nId, GDB_RT.GLOB)
|
|
end
|
|
end
|
|
end
|
|
--
|