Files
Carlo Baronchelli 741791a0e4 Copia locale Iniziale
2022-05-19 16:04:07 +02:00

495 lines
16 KiB
Lua

-- EgtDimension.lua by EgalTech s.r.l. 2019/032/31
-- Creazione di una quota
-- Tavola per definizione modulo (serve ma non usata)
local EgtDimension = {}
EgtOutLog( 'EgtDimension started', 1)
-- Intestazioni
require( 'EgtBase')
-- Frecce agli estremi della linea di quotatura
function Arrows(nParentId, ptP1, ptP2, dLenArr, iFrame, cColor, bRadius)
local Ang = atan2( (ptP2:getY() - ptP1:getY()), (ptP2:getX() - ptP1:getX()))
local iLine1
local iLine2
if not bRadius then
iLine1 = EgtLinePDL(nParentId, ptP1, Ang + 30, dLenArr, iFrame)
iLine2 = EgtLinePDL(nParentId, ptP1, Ang - 30, dLenArr, iFrame)
end
local iLine3 = EgtLinePDL(nParentId, ptP2, Ang + 150, dLenArr, iFrame)
local iLine4 = EgtLinePDL(nParentId, ptP2, Ang - 150, dLenArr, iFrame)
if cColor then
if not bRadius then
EgtSetColor( iLine1, cColor)
EgtSetColor( iLine2, cColor)
end
EgtSetColor( iLine3, cColor)
EgtSetColor( iLine4, cColor)
end
end
-- Quota verticale (bSide: false sx, true dx)
function CreateLinearDimensionOnY( nParentId, ptP1, ptP2, sText, iTextSize, dDistance, dLenArr, dDistText, bSide, sVar, iFrame, cColor)
if not iFrame then
iFrame = GDB_RT.LOC
end
local ptSx -- punto a sinistra
local ptDx -- punto a destra
if ptP1:getX() < ptP2:getX() - GEO.EPS_SMALL then
ptSx = Point3d(ptP1)
ptDx = Point3d(ptP2)
else
ptSx = Point3d(ptP2)
ptDx = Point3d(ptP1)
end
if not bSide then -- Quotatura a sinistra
if abs(ptSx:getY() - ptDx:getY()) < GEO.EPS_SMALL then -- Caso di quota nulla
local Uvx = Vector3d(-1, 0, 0)
local iLine = EgtLinePVL(nParentId, ptDx, Uvx, dDistance + ptDx:getX() - ptSx:getX(), iFrame)
local pText = Point3d(ptSx:getX() - dDistance - dDistText, ptSx:getY(),0)
local TextId = EgtTextAdv(nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.MR,iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
EgtSetColor( iLine, cColor)
EgtSetColor( TextId, cColor)
end
else -- Caso di quota non nulla
local ptSx1 = Point3d(ptSx:getX() - dDistance, ptSx:getY(), 0)
local ptDx1 = Point3d(ptSx:getX() - dDistance, ptDx:getY(), 0)
local iLine1 = EgtLine(nParentId, ptSx, ptSx1, iFrame)
local iLine2 = EgtLine(nParentId, ptDx, ptDx1, iFrame)
local ptSx2 = Point3d(ptSx:getX() - (dDistance - 0.5 * dLenArr), ptSx:getY(), 0)
local ptDx2 = Point3d(ptSx:getX() - (dDistance - 0.5 * dLenArr), ptDx:getY(), 0)
local iLine3 = EgtLine(nParentId, ptSx2, ptDx2, iFrame)
Arrows(nParentId, ptSx2, ptDx2, dLenArr, iFrame, cColor)
local pText = Point3d(ptSx1:getX() - dDistText, (ptSx1:getY() + ptDx1:getY())/2,0)
local TextId = EgtTextAdv(nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.MR)
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
EgtSetColor( iLine1, cColor)
EgtSetColor( iLine2, cColor)
EgtSetColor( iLine3, cColor)
EgtSetColor( TextId, cColor)
end
end
else -- Quotatura a destra
if abs(ptSx:getY() - ptDx:getY()) < GEO.EPS_SMALL then -- Caso di quota nulla
local Uvx = Vector3d(1, 0, 0)
local iLine = EgtLinePVL(nParentId, ptSx, Uvx, dDistance + ptDx:getX() - ptSx:getX(), iFrame)
local pText = Point3d(ptDx:getX() + dDistance + dDistText, ptSx:getY(),0)
local TextId = EgtTextAdv(nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.ML,iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
EgtSetColor( iLine, cColor)
EgtSetColor( TextId, cColor)
end
else -- Caso di quota non nulla
local ptSx1 = Point3d(ptDx:getX() + dDistance, ptSx:getY(), 0)
local ptDx1 = Point3d(ptDx:getX() + dDistance, ptDx:getY(), 0)
local iLine1 = EgtLine(nParentId, ptSx, ptSx1, iFrame)
local iLine2 = EgtLine(nParentId, ptDx, ptDx1, iFrame)
local ptSx2 = Point3d(ptDx:getX() + (dDistance - 0.5 * dLenArr), ptSx:getY(), 0)
local ptDx2 = Point3d(ptDx:getX() + (dDistance - 0.5 * dLenArr), ptDx:getY(), 0)
local iLine3 = EgtLine(nParentId, ptSx2, ptDx2, iFrame)
Arrows(nParentId, ptSx2, ptDx2, dLenArr, iFrame, cColor)
local pText = Point3d(ptDx1:getX() + dDistText, (ptSx1:getY() + ptDx1:getY())/2,0)
local TextId = EgtTextAdv(nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.ML,iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
EgtSetColor( iLine1, cColor)
EgtSetColor( iLine2, cColor)
EgtSetColor( iLine3, cColor)
EgtSetColor( TextId, cColor)
end
end
end
end
-- Quota orizzontale (bSide: false down, true up)
function CreateLinearDimensionOnX( nParentId, ptP1, ptP2, sText, iTextSize, dDistance, dLenArr, dDistText, bSide, sVar, iFrame, cColor, bRadius, bShiftLeft)
if not iFrame then
iFrame = GDB_RT.LOC
end
local ptDw -- punto in basso
local ptUp -- punto in alto
if ptP1:getY() < ptP2:getY() - GEO.EPS_SMALL then
ptDw = Point3d( ptP1)
ptUp = Point3d( ptP2)
else
ptDw = Point3d( ptP2)
ptUp = Point3d( ptP1)
end
-- Quotatura in basso
if not bSide then
-- Caso di quota nulla
if abs(ptDw:getX() - ptUp:getX()) < GEO.EPS_SMALL then
local UvY = Vector3d(0, -1, 0)
local iLine = EgtLinePVL(nParentId, ptUp, UvY, ptUp:getY() - ptDw:getY() + dDistance, iFrame)
local pText = Point3d(ptDw:getX(), ptDw:getY() - dDistance - dDistText,0)
local TextId = EgtTextAdv(nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.TC,iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if bShiftLeft then
EgtMove( TextId, Vector3d(-dLenArr/2, dLenArr + abs(ptDw:getX() - ptUp:getX()) + 20, 0))
end
if cColor then
EgtSetColor( iLine, cColor)
EgtSetColor( TextId, cColor)
end
-- Caso di quota non nulla
else
local ptDw1
local ptUp1
local ptDw2
local ptUp2
local iLine1
local iLine2
if not bRadius then
ptDw1 = Point3d(ptDw:getX(), ptDw:getY() - dDistance, 0)
ptUp1 = Point3d(ptUp:getX(), ptDw:getY() - dDistance, 0)
iLine1 = EgtLine(nParentId, ptDw, ptDw1, iFrame)
iLine2 = EgtLine(nParentId, ptUp, ptUp1, iFrame)
ptDw2 = Point3d(ptDw:getX(), ptDw:getY() - (dDistance - 0.5 * dLenArr), 0)
ptUp2 = Point3d(ptUp:getX(), ptDw:getY() - (dDistance - 0.5 * dLenArr), 0)
else
ptDw1 = Point3d(ptDw:getX(), ptDw:getY(), 0)
ptUp1 = Point3d(ptUp:getX(), ptDw:getY(), 0)
ptDw2 = Point3d(ptDw:getX(), ptDw:getY(), 0)
ptUp2 = Point3d(ptUp:getX(), ptDw:getY(), 0)
end
local iLine3 = EgtLine(nParentId, ptDw2, ptUp2, iFrame)
Arrows(nParentId, ptDw2, ptUp2, dLenArr, iFrame, cColor, bRadius)
local pText = Point3d((ptDw1:getX() + ptUp1:getX())/2, ptDw1:getY() - dDistText,0)
local TextId = EgtTextAdv(nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.TC,iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if bShiftLeft then
EgtMove( TextId, Vector3d(-dLenArr/2, dLenArr + abs(ptDw:getX() - ptUp:getX()) + 20, 0))
end
if cColor then
if not bRadius then
EgtSetColor( iLine1, cColor)
EgtSetColor( iLine2, cColor)
end
EgtSetColor( iLine3, cColor)
EgtSetColor( TextId, cColor)
end
end
-- Quotatura in alto
else
-- Caso di quota nulla
if abs( ptDw:getX() - ptUp:getX()) < GEO.EPS_SMALL then
local UvY = Vector3d(0, 1, 0)
local iLine = EgtLinePVL(nParentId, ptDw, UvY, ptUp:getY() - ptDw:getY() + dDistance, iFrame)
local pText = Point3d(ptUp:getX(), ptUp:getY() + dDistance + dDistText,0)
local TextId = EgtTextAdv(nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.BC,iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if bShiftLeft then
EgtMove( TextId, Vector3d(-dLenArr/2, dLenArr + abs(ptDw:getX() - ptUp:getX()) + 20, 0))
end
if cColor then
EgtSetColor( iLine, cColor)
EgtSetColor( TextId, cColor)
end
-- Caso di quota non nulla
else
local ptDw1
local ptUp1
local ptDw2
local ptUp2
local iLine1
local iLine2
if not bRadius then
ptDw1 = Point3d( ptDw:getX(), ptUp:getY() + dDistance, 0)
ptUp1 = Point3d( ptUp:getX(), ptUp:getY() + dDistance, 0)
iLine1 = EgtLine( nParentId, ptDw, ptDw1, iFrame)
iLine2 = EgtLine( nParentId, ptUp, ptUp1, iFrame)
ptDw2 = Point3d( ptDw:getX(), ptUp:getY() + (dDistance - 0.5 * dLenArr), 0)
ptUp2 = Point3d( ptUp:getX(), ptUp:getY() + (dDistance - 0.5 * dLenArr), 0)
else
ptDw1 = Point3d( ptDw:getX(), ptUp:getY(), 0)
ptUp1 = Point3d( ptUp:getX(), ptUp:getY(), 0)
ptDw2 = Point3d( ptDw:getX(), ptUp:getY(), 0)
ptUp2 = Point3d( ptUp:getX(), ptUp:getY(), 0)
end
local iLine3 = EgtLine( nParentId, ptDw2, ptUp2, iFrame)
Arrows( nParentId, ptDw2, ptUp2, dLenArr, iFrame, cColor, bRadius)
local pText = Point3d( ( ptDw1:getX() + ptUp1:getX()) / 2, ptUp1:getY() + dDistText, 0)
local TextId = EgtTextAdv( nParentId, pText, 0, sText,"", 400,"S", iTextSize, 1, 0, GDB_TI.BC,iFrame)
if bShiftLeft then
EgtMove( TextId, Vector3d( -dLenArr/2, dLenArr + abs( ptDw:getX() - ptUp:getX()) + 20, 0))
end
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
if not bRadius then
EgtSetColor( iLine1, cColor)
EgtSetColor( iLine2, cColor)
end
EgtSetColor( iLine3, cColor)
EgtSetColor( TextId, cColor)
end
end
end
end
-- Quota allineata (bSide: false sx, true dx)
function CreateLinearDimensionAligned( nParentId, ptP1, ptP2, sText, dTextSize, dDistance, dLenArr, dDistText, bSide, sVar, iFrame, cColor)
if not iFrame then
iFrame = GDB_RT.LOC
end
-- Se punti coincidenti, esco
if AreSamePointApprox(ptP1,ptP2) then
return false
end
-- Se quotatura orizzontale, uso questa
if abs(ptP1:getY() - ptP2:getY()) < GEO.EPS_SMALL then
-- adatto il lato
if ptP2:getX() > ptP1:getX() then
bSide = not bSide
end
CreateLinearDimensionOnX(nParentId, ptP1, ptP2, sText, dTextSize, dDistance, dLenArr, dDistText, bSide, sVar, iFrame, cColor)
return true
end
local Vv = ptP2 - ptP1
Vv:normalize()
local AngText = atan2( Vv:getY(), Vv:getX())
local bAngModif = false
if AngText > 90 then
AngText = AngText - 180
bAngModif = true
elseif AngText < - 90 then
AngText = AngText + 180
bAngModif = true
end
if bSide then
Vv:rotate(Z_AX(),-90)
if bAngModif then
PointType = GDB_TI.BC
else
PointType = GDB_TI.TC
end
else
Vv:rotate(Z_AX(),90)
if bAngModif then
PointType = GDB_TI.TC
else
PointType = GDB_TI.BC
end
end
local iLine1 = EgtLinePVL(nParentId,ptP1, Vv, dDistance, iFrame)
local iLine2 = EgtLinePVL(nParentId,ptP2, Vv, dDistance, iFrame)
local ptP1M = ptP1 + (dDistance - 0.5 * dLenArr) * Vv
local ptP2M = ptP2 + (dDistance - 0.5 * dLenArr) * Vv
local iLine3 = EgtLine(nParentId, ptP1M, ptP2M, iFrame)
Arrows(nParentId, ptP1M, ptP2M, dLenArr, iFrame, cColor)
local ptText = 0.5 * ( ptP1 + ptP2) + ( dDistance + dDistText) * Vv
local TextId = EgtTextAdv(nParentId, ptText, AngText , sText,"", 400,"S", dTextSize, 1, 0, PointType,iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
EgtSetColor( iLine1, cColor)
EgtSetColor( iLine2, cColor)
EgtSetColor( iLine3, cColor)
EgtSetColor( TextId, cColor)
end
end
-- Quota radiale (bSide: false sx, true dx)
function CreateRadialDimension( nParentId, ptC, ptP1, sText, dTextSize, dDistance, dLenArr, dDistText, bSide, sVar, iFrame, cColor)
if not iFrame then
iFrame = GDB_RT.LOC
end
-- Se punti coincidenti, esco
if AreSamePointApprox(ptC,ptP1) then
return false
end
-- Se quotatura orizzontale, uso questa
if abs( ptC:getY() - ptP1:getY()) < GEO.EPS_SMALL then
-- adatto il lato
if ptP1:getX() > ptC:getX() then
bSide = not bSide
end
CreateLinearDimensionOnX( nParentId, ptC, ptP1, sText, dTextSize, dDistance, dLenArr, dDistText, bSide, sVar, iFrame, cColor, true)
return true
end
local Vv = ptP1 - ptC
Vv:normalize()
local AngText = atan2( Vv:getY(), Vv:getX())
local bAngModif = false
if AngText > 90 then
AngText = AngText - 180
bAngModif = true
elseif AngText < - 90 then
AngText = AngText + 180
bAngModif = true
end
local ptText
if bSide == nil then
AngText = 0
Vv = - Vv
ptText = ptC + ( dDistText + 0.5 * dTextSize) * Vv
PointType = GDB_TI.MC
elseif bSide then
Vv:rotate( Z_AX(), -90)
ptText = 0.5 * ( ptC + ptP1) + ( dDistText) * Vv
PointType = EgtIf( bAngModif, GDB_TI.BC, GDB_TI.TC)
else
Vv:rotate( Z_AX(), 90)
ptText = 0.5 * ( ptC + ptP1) + ( dDistText) * Vv
PointType = EgtIf( bAngModif, GDB_TI.TC, GDB_TI.BC)
end
local iLine3 = EgtLine( nParentId, ptC, ptP1, iFrame)
Arrows( nParentId, ptC, ptP1, dLenArr, iFrame, cColor, true)
local TextId = EgtTextAdv( nParentId, ptText, AngText , sText,"", 400,"S", dTextSize, 1, 0, PointType, iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
EgtSetColor( iLine3, cColor)
EgtSetColor( TextId, cColor)
end
end
-- Quota angolare (bSide: false = text external, true dx = text internal)
function CreateAngleDimension( nParentId, ptC, dDir, sText, dTextSize, dAngVal, dAmpArc, dDistance, dLenArr, dDistText, bSide, sVar, iFrame, cColor)
if not iFrame then
iFrame = GDB_RT.LOC
end
-- Se distanza quota nulla, esco
if abs(dAmpArc) < GEO.EPS_SMALL or abs(dAngVal) < GEO.EPS_SMALL then
return false
end
-- disegno linee da quotare
local iLine1 = EgtLinePDL(nParentId, ptC, dDir, dAmpArc, iFrame)
local iLine2 = EgtLinePDL(nParentId, ptC, dDir+dAngVal, dAmpArc, iFrame)
-- prendo i punti finali delle due linee
local ptP1 = EgtEP(iLine1)
local ptP2 = EgtEP(iLine2)
-- allungo di nuovo le linee della distanza extra
EgtTrimExtendCurveByLen( iLine1, dDistance,ptP1)
EgtTrimExtendCurveByLen( iLine2, dDistance,ptP2)
-- arco
local iArc1 = EgtArcCPA( nParentId, ptC, ptP1, dAngVal, 0, iFrame)
local pPt3 = EgtMP(iArc1)
-- frecce
local iLine3
local ptP4
local nNeg = -1
if dAngVal > 0 then
nNeg = 1
end
-- faccio linee che parte da punto di freccia perpendicolare a linea di quota
iLine3 = EgtLinePDL(nParentId, ptP1, dDir+(90*nNeg), dAmpArc, iFrame)
ptP4 = EgtEP(iLine3)
EgtErase(iLine3)
-- prima freccia sulla prima linea
Arrows( nParentId, ptP4, ptP1, dLenArr, iFrame, cColor, true)
iLine3 = EgtLinePDL(nParentId, ptP2, dDir+dAngVal-(90*nNeg), dAmpArc, iFrame)
ptP4 = EgtEP(iLine3)
EgtErase(iLine3)
-- seconda freccia sulla seconda linea
Arrows( nParentId, ptP4, ptP2, dLenArr, iFrame, cColor, true)
local Vv = ptP1 - ptC
Vv:normalize()
local AngText = 0
local bAngModif = false
local ptText
if bSide == nil then
ptText = pPt3 + ( dDistText + 0.5 * dTextSize) * Vv
PointType = GDB_TI.MC
elseif bSide then
ptText = pPt3 + ( dDistText + 0.5 * dTextSize) * Vv
PointType = GDB_TI.MC
else
ptText = pPt3 - ( dDistText + 0.5 * dTextSize) * Vv
PointType = GDB_TI.MC
end
local TextId = EgtTextAdv( nParentId, ptText, AngText , sText,"", 400,"S", dTextSize, 1, 0, PointType, iFrame)
EgtSetInfo( TextId, 'Var', sVar)
if cColor then
EgtSetColor( iLine1, cColor)
EgtSetColor( iLine2, cColor)
EgtSetColor( iArc1, cColor)
EgtSetColor( TextId, cColor)
end
end
return EgtDimension