Files
Dario Sassi cc55202ec5 DataDoors 2.7c1 :
- primo commit con versione corrente.
2025-03-18 17:02:20 +01:00

914 lines
39 KiB
Lua

--
-- EEEEEEEEEE GGGGGG wwww wwww
-- EEEEEEEEEE GGGGGGGGGG wwww wwww
-- EEEE GGGG GGGG wwww wwww wwww
-- EEEE GGGG wwww wwww wwww
-- EEEEEEE GGGG GGGGGGG wwww wwwwww wwww
-- EEEEEEE GGGG GGGGGGG wwww wwwwww wwww
-- EEEE GGGG GGGG wwww wwwwwwww wwww
-- EEEE GGGG GGGG wwww wwww wwww wwww
-- EEEEEEEEEE GGGGGGGGGG wwwwwwww wwwwwwww
-- EEEEEEEEEE GGGGGG wwwwwww wwwwwww
--
-- fc_rectangle.lua by EgalWare s.r.l. 2019.05.07
-- Autore: Filippo Monchi
-- fc_rectangle dati i valori 'Thickness' e 'face' e con nome attributo
-- 2019.05.07 V1.000 FM Write Component
-- 2019.09.24 V1.001 FM Manage side distance parameters (top, bottom, lock, hinge) from ddf
-- 2019.09.25 V1.002 FM Fix some error on calculate lines and rectangle position when diameter tool used
-- 2019.10.18 V2.000 FM Manage use Materials
-- 2019.10.18 V2.000 FM Manage to draw not premptive lines between premptive lines only if premptive lines are 2 and their start and stop
-- distances are defined and without or zero step value
-- 2022.07.27 V2.001 FM Modification to use compiled code
-- 2023.05.15 V2.002 FM fix errors (x/0) when exists only 1 horizontal line and/or only 1 vertical line and both distances ( from reference and opposite sides) are difined
-- Tavola per definizione modulo (serve ma non usata)
local fc_rectangle = {}
-- Intestazioni
require( 'EgtBase')
EgtEnableDebug( false)
-- per messaggi
-- EgtAddToPackagePath( EgtGetSourceDir() .. '?.lua')
EgtAddToPackagePath( DGD.BASEDIR .. '?.lua')
-- Valori limite
local DimMin = 4. -- valore minimo lato
local function GetMachToolErrorMessage( nErrorId, sGeomName, dIdMach, dOriDiamTool, nIdLogErr, sMchngName)
local EgtDoorsMsg = require( 'EgtDoorsMsg')
local sMessage = ''
if dOriDiamTool then
if nErrorId == -1 then -- lavorazione non presente in tabella
sMessage = string.format(EgtDoorsMsg[466], nIdLogErr, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool))
elseif nErrorId == -2 then -- errore nel settare la lavorazione, lavorazione non presente in libreria
sMessage = string.format(EgtDoorsMsg[467], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool))
elseif nErrorId == -3 then -- errore nell'acquisire parametri lavorazione
sMessage = string.format(EgtDoorsMsg[468], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool))
elseif nErrorId == -4 then -- errore nell'acquisire parametri lavorazione
sMessage = string.format(EgtDoorsMsg[469], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool))
elseif nErrorId == -5 then -- diametro utensile non trovato
sMessage = string.format(EgtDoorsMsg[470], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool))
elseif nErrorId == -6 then -- nome geometria non presente in tabella
sMessage = string.format(EgtDoorsMsg[471], nIdLogErr, sGeomName, EgtToUiUnits( dOriDiamTool))
elseif nErrorId == -7 then -- altezza massima utensile non trovata
sMessage = string.format(EgtDoorsMsg[472], nIdLogErr, sMchngName, dIdMach, sGeomName, EgtToUiUnits( dOriDiamTool))
elseif nErrorId == -8 then -- tabella non presente nelle note
sMessage = string.format(EgtDoorsMsg[509], nIdLogErr)
end
elseif nErrorId == -1 then -- lavorazione non presente in tabella
sMessage = string.format(EgtDoorsMsg[504], nIdLogErr, dIdMach, sGeomName)
elseif nErrorId == -2 then -- errore nel settare la lavorazione
sMessage = string.format(EgtDoorsMsg[505], nIdLogErr, sMchngName, dIdMach, sGeomName)
elseif nErrorId == -3 then -- errore nell'acquisire parametri lavorazione
sMessage = string.format(EgtDoorsMsg[506], nIdLogErr, sMchngName, dIdMach, sGeomName)
elseif nErrorId == -4 then -- errore nell'acquisire parametri lavorazione
sMessage = string.format(EgtDoorsMsg[507], nIdLogErr, sMchngName, dIdMach, sGeomName)
elseif nErrorId == -5 then -- diametro utensile non trovato
sMessage = string.format(EgtDoorsMsg[508], nIdLogErr, sMchngName, dIdMach, sGeomName)
elseif nErrorId == -6 then -- nome geometria non presente in tabella
sMessage = string.format(EgtDoorsMsg[503], nIdLogErr, sGeomName)
elseif nErrorId == -7 then -- altezza massima utensile non trovata
sMessage = string.format(EgtDoorsMsg[473], nIdLogErr, sMchngName, dIdMach, sGeomName)
elseif nErrorId == -8 then -- tabella non presente nelle note
sMessage = string.format(EgtDoorsMsg[509], nIdLogErr)
end
return sMessage
end
local function DrawAddLineDrawCircle( pInitial, pFinal, nGroup, idTable, bPrev, nGroupCirc,
nRad, bDrawFirst, bDrawLast, cColor1, cColor2, sMVar)
local nLine = EgtLine(nGroup, pInitial, pFinal, GDB_RT.LOC)
local nNumLine
if idTable then
table.insert( idTable, nLine)
-- se devo inserire una variazione nell'entità
if sMVar then
nNumLine = #idTable
end
end
if bPrev then
if bDrawFirst then
local nCircle1 = EgtCircle( nGroupCirc, pInitial, nRad , GDB_RT.LOC)
EgtSetColor(nCircle1, cColor1)
end
if bDrawLast then
local nCircle2 = EgtCircle( nGroupCirc, pFinal, nRad , GDB_RT.LOC)
EgtSetColor(nCircle2, cColor2)
end
end
return nLine, nNumLine, sMVar
end
local function DrawAddCircleDrawCircle( pCenter, dRadius, dAngIni, dAngCen, nGroup, idTable, bPrev, nGroupCirc,
nRad, bDrawFirst, bDrawLast, cColor1, cColor2, sMVar)
local nCircle = EgtArc( nGroup, pCenter, dRadius, dAngIni, dAngCen, 0, GDB_RT.LOC)
local nNumCircle
if idTable then
table.insert( idTable, nCircle)
-- se devo inserire una variazione nell'entità
if sMVar then
nNumCircle = #idTable
end
end
if bPrev then
if bDrawFirst then
local nCircle1 = EgtCircle( nGroupCirc, EgtSP( nCircle), nRad , GDB_RT.LOC)
EgtSetColor( nCircle1, cColor1)
end
if bDrawLast then
local nCircle2 = EgtCircle( nGroupCirc, EgtEP( nCircle), nRad , GDB_RT.LOC)
EgtSetColor( nCircle2, cColor2)
end
end
return nCircle, nNumCircle, sMVar
end
local function DrawRectangleWithFillet ( Lg, L, H, dThickD, rf)
local tHint = {}
local hint
local pIni, pEnd, pCen
-- Costruzione della geometria principale
pIni = Point3d(((L/2)-rf),(H/2),dThickD)
pCen = Point3d(((L/2)-rf),((H/2)-rf),dThickD)
pEnd = Point3d((L/2),((H/2)-rf),dThickD)
DrawAddCircleDrawCircle( pCen, rf, 90,-90, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
pIni = pEnd
if abs(rf - (H/2)) > GEO.EPS_SMALL then -- se c'è spazio per una linea tra i due raccordi
pEnd = Point3d((L/2),-(H/2)+rf,dThickD)
DrawAddLineDrawCircle( pIni, pEnd, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
pIni = pEnd
end
pCen = Point3d(((L/2)-rf),(-(H/2)+rf),dThickD)
pEnd = Point3d(((L/2)-rf),-(H/2),dThickD)
DrawAddCircleDrawCircle( pCen, rf, 0,-90, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
pIni = pEnd
if abs(rf - (L/2)) > GEO.EPS_SMALL then -- se c'è stazio per una linea tra i due raccordi
pEnd = Point3d(-((L/2)-rf),-(H/2),dThickD)
DrawAddLineDrawCircle( pIni, pEnd, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
pIni = pEnd
end
pCen = Point3d(-((L/2)-rf),(-(H/2)+rf),dThickD)
pEnd = Point3d(-(L/2),(-(H/2)+rf),dThickD)
DrawAddCircleDrawCircle( pCen, rf, -90,-90, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
pIni = pEnd
if abs(rf - (H/2)) > GEO.EPS_SMALL then -- se c'è stazio per una linea tra i due raccordi
pEnd = Point3d(-(L/2),((H/2)-rf),dThickD)
DrawAddLineDrawCircle( pIni, pEnd, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
pIni = pEnd
end
pCen = Point3d(-((L/2)-rf),((H/2)-rf),dThickD)
pEnd = Point3d(-((L/2)-rf),(H/2),dThickD)
DrawAddCircleDrawCircle( pCen, rf, 180,-90, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
pIni = pEnd
if abs(rf - (L/2)) > GEO.EPS_SMALL then -- se c'è spazio per una linea tra i due raccordi
pEnd = Point3d(((L/2)-rf),(H/2),dThickD)
DrawAddLineDrawCircle( pIni, pEnd, Lg, tHint, bPreview, Dm, 0, false, false, RED(), RED())
end
-- trasformo in geometria composita i/il percorsi/o di contorno
-- primo percorso
if ( #tHint > 0) then
hint = EgtCurveCompo( Lg, tHint, true)
if hint then
EgtInvertCurve( hint)
end
end
return hint
end
local function MakeRectWithFillet( Lg, P1, P2, Rf, Ang)
local hint_3 = EgtRectangle2P( Lg, P1, P2, GDB_RT.LOC)
if hint_3 then
local nNewId, nNumEnt = EgtExplodeCurveCompo( hint_3)
if nNewId and nNumEnt and nNumEnt > 0 then
local pStartIni
-- se devo inserire i raccordi
if Rf > 0 then
local tIdFil = {}
local nLine
for p = 1, (nNumEnt-1) do
nLine = EgtCurveFillet( Lg, ( nNewId + p - 1), EgtEP( nNewId + p - 1), ( nNewId + p), EgtSP( nNewId + p), Rf, true)
table.insert( tIdFil, nLine)
end
nLine = EgtCurveFillet( Lg, ( nNewId + nNumEnt - 1), EgtEP( nNewId + nNumEnt - 1), nNewId, EgtSP(nNewId), Rf, true)
table.insert( tIdFil, nLine)
-- creo curvecompo
pStartIni = EgtMP( nNewId)
hint_3 = EgtCurveCompo( Lg, { nNewId, tIdFil[1], (nNewId+1), tIdFil[2], (nNewId+2), tIdFil[3], (nNewId+3), tIdFil[4]}, true)
else
-- creo curvecompo
pStartIni = EgtMP( nNewId)
hint_3 = EgtCurveCompo( Lg, { nNewId, (nNewId+1), (nNewId+2), (nNewId+3)}, true)
end
if hint_3 then
EgtChangeClosedCurveStartPoint( hint_3, pStartIni, GDB_RT.LOC) -- cambio punto di inizio
if Ang ~= 0 then
EgtRotate( hint_3, EgtGP( hint_3), Z_AX(), Ang, GDB_RT.LOC) -- ruoto
end
end
end
end
return hint_3
end
-- Funzione di sistemazione parametri
function fc_rectangle.AdjustParams( tMhPar)
-- Assegno parametri da dati utensili in macchina
local MB = require( 'MachiningBase')
local EgtDoorsMsg = require( 'EgtDoorsMsg')
local nTempT3
local dNumMessage
local dNumLog = 0
local sMessToOut = ''
local dMaxMat3
local sMchngName3
local sLGR
local nLGRi = 1
-- setto le variabili dimensioni porta
tMhPar.W = DGD.dW
tMhPar.L = DGD.dH
tMhPar.type = 2 -- 1: lines, 2: rectangle
-- variabile supporto calcolo offset
tMhPar.esfr = 0
-- nome geometria e diametri utensili delle associate lavorazioni
if tMhPar.LGR then
sLGR = tMhPar.LGR
if DGD.MachEn > 0 and tMhPar.d3 then nTempT3, dMaxMat3, sMchngName3 = MB.GetToolDataFromAttrib( sLGR, nLGRi) end
end
-- se devo disegnare le geometrie di lavorazione
if DGD.MachEn > 0 then
-- gestisco il risultato della lettura utensili
if DGD.bProoduce and tMhPar.d3 and nTempT3 <= 0 then
dNumLog = -2795
sMessToOut = sMessToOut .. '\n'.. GetMachToolErrorMessage( nTempT3, sLGR, nLGRi, tMhPar.d3, dNumLog, sMchngName3)
elseif nTempT3 then
tMhPar.d3 = nTempT3
end
end
-- se il diametro non è stato definito (dal controllo lavorazione)
if not tMhPar.d3 then tMhPar.d3 = 0 end
-- assegnamento valore a variabili di appoggio
if not tMhPar.ctr then -- se non devo considerare l'utensile
tMhPar.esfr = 0
else -- considero l'utensile
tMhPar.esfr = tMhPar.d3/2
end
if not tMhPar.rf then
tMhPar.rf = 0
else
tMhPar.rf = abs(tMhPar.rf)
end
if tMhPar.rf > 0 then -- se c'è raccordo disattivo gli sbordi
tMhPar.pre = nil
end
---------------------------------------
-- setto parametri da ddf
---------------------------------------
-- profondità
if DGD.DEPTH then
if tMhPar.Dhr then
tMhPar.Dhr = EgtIf( DGD.DEPTH >= DGD.dT, 0, DGD.DEPTH)
end
end
if DGD.DFT and DGD.DFT > 0 then -- se ho distanza top
tMhPar.tdr = DGD.DFT
end
if DGD.DFB and DGD.DFB > 0 then -- se ho distanza bottom
tMhPar.bdr = DGD.DFB
end
if DGD.DFL and DGD.DFL > 0 then -- se ho distanza lock
tMhPar.ldr = DGD.DFL
end
if DGD.DFH and DGD.DFH > 0 then -- se ho distanza hinge
tMhPar.hdr = DGD.DFH
end
if not tMhPar.clr then -- se non è definita la lunghezza di arresto
tMhPar.clr = -tMhPar.d3*0.75
else
tMhPar.clr = abs(tMhPar.clr)
end
if not tMhPar.cir then -- se non è definita la lunghezza di arresto alle intersezioni
tMhPar.cir = 0
else
tMhPar.cir = abs(tMhPar.cir)
end
-- se devo disegnare le geometrie di lavorazione
if DGD.MachEn > 0 then
-- se la profondità delle linee verticali è maggiore della capacita utensile limito la profondità ed emetto un warning
if tMhPar.Dhr and dMaxMat3 and tMhPar.Dhr > dMaxMat3 then
dNumLog = -2794
dNumMessage = 549
sMessToOut = sMessToOut .. '\n'.. string.format(EgtDoorsMsg[dNumMessage], dNumLog, tMhPar.Nome, EgtToUiUnits(tMhPar.Dhr), EgtToUiUnits(dMaxMat3))
tMhPar.Dhr = dMaxMat3 - 0.02 -- tolgo 0.02 per permettere la lavorazione
end
end
if dNumLog ~= 0 then
return tMhPar, dNumLog, sMessToOut
end
return tMhPar, 0, ''
end
-- Funzione di disegno
function fc_rectangle.Draw( tFDecorPar, bPreview, bRunByCompo, nDrawMach)
-- Assegno le variabili per rettangolo
local Dhr = tFDecorPar.Dhr
local rty = tFDecorPar.rty
local ofr = tFDecorPar.ofr
local rer = tFDecorPar.rer
local tdr = tFDecorPar.tdr
local bdr = tFDecorPar.bdr
local ldr = tFDecorPar.ldr
local hdr = tFDecorPar.hdr
local rw = tFDecorPar.rw
local rl = tFDecorPar.rl
local rf = tFDecorPar.rf
local clr = tFDecorPar.clr
local cir = tFDecorPar.cir
local esfr = tFDecorPar.esfr
local d3 = tFDecorPar.d3
-- Assegno variabili comuni
local pre = tFDecorPar.pre
local dtype = tFDecorPar.type
local L = tFDecorPar.L
local W = tFDecorPar.W
-- Assegno i nomi geometrie
local LGR = tFDecorPar.LGR
local DM = 'DUMMY'
-- variabili per messaggi e settaggi vari
local sCompoName = tFDecorPar.Nome
local nCompoNpar = tFDecorPar.Npar
local sCompoPath = tFDecorPar.Path
-- eventuale messaggio errore rilevato nell'adjust
local nCodAdj = tFDecorPar.nCod
local sCodAdj = tFDecorPar.sCod
-- variabili per messaggi di errore
local sNamePar1 = 'rl'
local sNamePar2 = 'rw'
local sNamePar5 = 'Dhr'
local sNamePar6 = 'rf'
local sNamePar9 = 'ldr'
local sNamePar10 = 'tdr'
local sNamePar11 = 'ofr'
local sNamePar12 = 'hdr'
local sNamePar13 = 'bdr'
-- RunByComponentInterface
local RC = true
-- Messaggi codice errori
local EM = ' '
local EC = 0
local ErrorBase = 2700
-- variabili che abilitano la creazione della geometria
local bMakeFaceGeom3 = true
if not bRunByCompo then -- controllo se lanciato da componente
RC = false
end
-- 0 solo geom esterna, 1 solo geom mach, 2 entrambe
if not nDrawMach then -- se non definita la setto per non creare geometria di lavorazione
nDrawMach = 0
end
local nForceMakeFace = nDrawMach
if not Dhr or Dhr < GEO.EPS_SMALL or ( rty and rty == 1 and ( rl < GEO.EPS_SMALL or rw < GEO.EPS_SMALL)) then -- se rettangolo con spessore o dimensioni a 0
bMakeFaceGeom3 = false
end
-- if nForceMakeFace == 0 then -- se solo geometria disabilito il raggio fresa
-- esfr = 0
-- end
if ldr then ldr = abs(ldr) end
if hdr then hdr = abs(hdr) end
if tdr then tdr = abs(tdr) end
if bdr then bdr = abs(bdr) end
local EgtDoorsMsg = require( 'EgtDoorsMsg')
if not bPreview and EC ~= 0 then
return (ErrorBase+EC), EM
end
-- Se Preview cancello tutto
if bPreview then
EgtNewFile()
EgtSetDefaultMaterial( BLACK())
end
-- Pezzo e Layer
local Pz
if bPreview then
Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- nuovo pezzo
else
if not RC then
Pz = EgtGetCurrPart() -- pezzo corrente
end
if not Pz then
Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- nuovo pezzo
end
end
-- Layer
local Dm
local Lg
local GId
local hint
local nRev
local pIni, pEnd
local dStartValX, dStopValX
local dStartValY, dStopValY
local dValXv1Ini, dValXv1End, dValYv1Ini, dValYv1End -- prima linea verticale
local dValXv2Ini, dValXv2End, dValYv2Ini, dValYv2End -- seconda linea verticale
local dValXh1Ini, dValXh1End, dValYh1Ini, dValYh1End -- prima linea orizzontale
local dValXh2Ini, dValXh2End, dValYh2Ini, dValYh2End -- seconda linea orizzontale
local dStart
Lg = EgtGroup(Pz,GDB_RT.LOC) -- layer della figura principale
EgtSetName(Lg,sCompoName)
if nDrawMach > 0 then -- se abilitata geometria lavorazione
Dm = EgtGroup( Pz, GDB_RT.LOC) -- layer disegni cerchi rappresentante il diametro utensile
EgtSetName(Dm,DM)
end
if nForceMakeFace ~= 1 then -- se abilitata geometria esterna
if bMakeFaceGeom3 then -- se posso fare rettangolo
if not rty or rty == 0 then -- se rettangolo con offset
-- messaggio di errore
if 2*(abs(ofr)+esfr) >= W or 2*(abs(ofr)+esfr) >= L then -- se offset troppo grande
EC = 26
EM = string.format( EgtDoorsMsg[649], sNamePar11, EgtToUiUnits(ofr), EgtToUiUnits(esfr), EgtToUiUnits(min(((W/2)-esfr),((L/2)-esfr))-0.01), sCompoPath)
return (ErrorBase+EC), EM
end
-- al valore dell'offset viene aggiunta al raggio utensile
-- il rettangolo può risultare quindi inferiore
GId = EgtRectangle2P( Lg, Point3d( -(W/2)+(abs(ofr)+esfr), -(L/2)+(abs(ofr)+esfr), 0), Point3d( (W/2)-(abs(ofr)+esfr), (L/2)-(abs(ofr)+esfr), 0), GDB_RT.GLOB)
if GId then
-- cambio il punto di inizio in centro al lato inferiore
EgtChangeClosedCurveStartPoint( GId, Point3d( 0, -(L/2)+(abs(ofr)+esfr), 0), GDB_RT.GLOB)
EgtMove( GId, Point3d(W/2,L/2,0) - ORIG())
EgtModifyCurveThickness( GId, -Dhr) -- di default è sul lato keyway
EgtSetName( GId, LGR)
end
else -- rettangolo con geometria
if rty and rty == 2 then -- se rettangolo ricavato dalle distanze ricalcolo le dimensioni e il raccordo perché sono le distanze dai bordi a essere preservate
rw = W - ldr - hdr - (esfr*4)
rl = L - tdr - bdr - (esfr*4)
-- forzo la geometria a un valore che poi viene calcolato comunque dalle distanze dai bordi.
-- con valore 0 si ottiene la centratura del rettangolo risultante con la porta
-- con valori 1, 2, 4 e 5 si rispettano le distanze dai bordi
-- con valori 3 e 6 si ottiene la centratura in X del rettangolo risultante, le distanze top e bottom rispettano i relativi parametri.
-- con valori 7 e 8 si ottiene la centratura in Y del rettangolo risultante, le distanze lock e hinge rispettano i relativi parametri.
rer = 1
-- se le dimensioni risultano negative do errore
if rw+(esfr*2) <= 0 then
EC = 27
EM = string.format( EgtDoorsMsg[626], sNamePar9..'+'..sNamePar12, EgtToUiUnits(ldr+hdr), EgtToUiUnits(W-(esfr*2)-0.01), sCompoPath)
return (ErrorBase+EC), EM
elseif rl+(esfr*2) <= 0 then
EC = 28
EM = string.format( EgtDoorsMsg[626], sNamePar10..'+'..sNamePar13, EgtToUiUnits(tdr+bdr), EgtToUiUnits(L-(esfr*2)-0.01), sCompoPath)
return (ErrorBase+EC), EM
end
-- se ho il raccordo
if rf then
rf = rf - (esfr*2)
end
end
-- se le dimensioni del raccordo sono eccessive le riconduco a valori accettabili
if rl and rw and rf then
if 2*rf > min(rl,rw) then
rf = min(rl,rw)/2
end
end
if rf > 0 or not pre or pre == 0 then -- rettangolo con raccordo o non ho prelazione
local dCompareRadius = rf
if rty and rty == 2 then -- se rettangolo ricavato dalle distanze
dCompareRadius = dCompareRadius + esfr
end
if dCompareRadius > 0 then -- rettangolo con raccordo
-- alle dimensioni del rettangolo viene aggiunto il diametro utensile
-- il rettangolo può risultare quindi maggiorato
GId = DrawRectangleWithFillet ( Lg, rw+(2*esfr), rl+(2*esfr), 0, rf+esfr)
else -- senza raccordo
-- alle dimensioni del rettangolo viene aggiunto il diametro utensile
-- il rettangolo puo' risultare quindi maggiorato
GId = EgtRectangle2P( Lg, Point3d( -(rw/2)-esfr, -(rl/2)-esfr, 0), Point3d( (rw/2)+esfr, (rl/2)+esfr, 0), GDB_RT.GLOB)
end
if GId then
-- cambio il punto di inizio in centro al lato inferiore
EgtChangeClosedCurveStartPoint( GId, Point3d( 0, -(rl/2)-esfr, 0), GDB_RT.GLOB)
if not rer or rer == 0 then -- se in centro
EgtMove( GId, Point3d(W/2,L/2,0) - ORIG())
elseif rer == 1 then -- se riferito top-lock
if rty and rty == 2 then -- se rettangolo ricavato dalle distanze
EgtMove( GId, Point3d(((rw+(2*esfr))/2)+(ldr+esfr),L-((rl+(2*esfr))/2)-(tdr+esfr),0) - ORIG())
else
EgtMove( GId, Point3d(((rw+(2*esfr))/2)+(ldr-esfr),L-((rl+(2*esfr))/2)-(tdr-esfr),0) - ORIG())
end
elseif rer == 2 then -- se riferito top-hinge
EgtMove( GId, Point3d(W-((rw+(2*esfr))/2)-(hdr-esfr),L-((rl+(2*esfr))/2)-(tdr-esfr),0) - ORIG())
elseif rer == 3 then -- se riferito top-center
EgtMove( GId, Point3d(W/2,L-((rl+(2*esfr))/2)-(tdr-esfr),0) - ORIG())
elseif rer == 4 then -- se riferito bottom-lock
EgtMove( GId, Point3d(((rw+(2*esfr))/2)+(ldr-esfr),((rl+(2*esfr))/2)+(bdr-esfr),0) - ORIG())
elseif rer == 5 then -- se riferito bottom-hinge
EgtMove( GId, Point3d(W-((rw+(2*esfr))/2)-(hdr-esfr),((rl+(2*esfr))/2)+(bdr-esfr),0) - ORIG())
elseif rer == 6 then -- se riferito bottom-center
EgtMove( GId, Point3d(W/2,((rl+(2*esfr))/2)+(bdr-esfr),0) - ORIG())
elseif rer == 7 then -- se riferito center-lock
EgtMove( GId, Point3d(((rw+(2*esfr))/2)+(ldr-esfr),L/2,0) - ORIG())
elseif rer == 8 then -- se riferito center-hinge
EgtMove( GId, Point3d(W-((rw+(2*esfr))/2)-(hdr-esfr),L/2,0) - ORIG())
end
EgtModifyCurveThickness( GId, -Dhr) -- di default è sul lato keyway
EgtSetName( GId, LGR)
end
else -- ho prelazione
if pre == 1 then -- se prelazione su linee verticali
-- prima linea verticale
if not rer or rer == 0 or rer == 3 or rer == 6 then -- se in centro in X
dValXv1Ini = (W-rw)/2 - esfr
elseif rer == 1 or rer == 4 or rer == 7 then -- se riferito a lock
if rty and rty == 2 then -- se rettangolo ricavato dalle distanze
dValXv1Ini = ldr + esfr
else
dValXv1Ini = ldr - esfr
end
else -- tutti gli altri casi (riferito a hinge)
dValXv1Ini = W - hdr + esfr
end
dValXv1End = dValXv1Ini
dValYv1Ini = L - clr -- posizione in alto
dValYv1End = clr
-- disegno linea
pIni = Point3d( dValXv1Ini, dValYv1Ini, 0)
pEnd = Point3d( dValXv1End, dValYv1End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
-- seconda linea verticale
if rer and ( rer == 2 or rer == 5 or rer == 8) then -- se riferito a hinge
dValXv2Ini = dValXv1Ini - rw - 2*esfr
else -- tutti gli altri casi (riferito a lock)
dValXv2Ini = dValXv1Ini + rw + 2*esfr
end
dValXv2End = dValXv2Ini
dValYv2Ini = L - clr -- posizione in alto
dValYv2End = clr
-- disegno linea
pIni = Point3d( dValXv2Ini, dValYv2Ini, 0)
pEnd = Point3d( dValXv2End, dValYv2End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
-- prima linea orizzontale
if not rer or rer == 0 or rer == 7 or rer == 8 then -- se in centro
dValYh1Ini = (L+rl)/2 + esfr
elseif rer >= 1 and rer <= 3 then -- se riferito top
if rty and rty == 2 then -- se rettangolo ricavato dalle distanze
dValYh1Ini = L - tdr - esfr
else
dValYh1Ini = L - tdr + esfr
end
else -- tutti gli altri casi (bottom)
dValYh1Ini = bdr - esfr
end
dValYh1End = dValYh1Ini
if rer and ( rer == 2 or rer == 5 or rer == 8) then -- se riferito a hinge
dValXh1Ini = dValXv1Ini - cir
dValXh1End = dValXv2Ini + cir
else -- negli altri casi (riferito a lock)
dValXh1Ini = dValXv1Ini + cir
dValXh1End = dValXv2Ini - cir
end
-- disegno linea
pIni = Point3d( dValXh1Ini, dValYh1Ini, 0)
pEnd = Point3d( dValXh1End, dValYh1End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
-- seconda linea orizzontale
if rer and ( rer >= 4 and rer <= 6) then -- se riferito a bottom
dValYh2Ini = dValYh1Ini + rl + 2*esfr
else -- in tutti gli altri casi (top)
dValYh2Ini = dValYh1Ini - rl - 2*esfr
end
dValYh2End = dValYh2Ini
if rer and ( rer == 2 or rer == 5 or rer == 8) then
dValXh2Ini = dValXv1Ini - cir
dValXh2End = dValXv2Ini + cir
else -- negli altri casi
dValXh2Ini = dValXv1Ini + cir
dValXh2End = dValXv2Ini - cir
end
-- disegno linea
pIni = Point3d( dValXh2Ini, dValYh2Ini, 0)
pEnd = Point3d( dValXh2End, dValYh2End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
else -- ho prelazione su linee orizzontali
-- prima linea orizzontale
if not rer or rer == 0 or rer == 7 or rer == 8 then -- se in centro
dValYh1Ini = (L+rl)/2 + esfr
elseif rer >= 1 and rer <= 3 then -- se riferito top
if rty and rty == 2 then -- se rettangolo ricavato dalle distanze
dValYh1Ini = L - tdr - esfr
else
dValYh1Ini = L - tdr + esfr
end
else -- tutti gli altri casi (bottom)
dValYh1Ini = bdr - esfr
end
dValYh1End = dValYh1Ini
dValXh1Ini = clr -- posizione a sinistra
dValXh1End = W - clr
-- disegno linea
pIni = Point3d( dValXh1Ini, dValYh1Ini, 0)
pEnd = Point3d( dValXh1End, dValYh1End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
-- seconda linea orizzontale
if rer and ( rer >= 4 and rer <= 6) then -- se riferito a bottom
dValYh2Ini = dValYh1Ini + rl + 2*esfr
else -- in tutti gli altri casi
dValYh2Ini = dValYh1Ini - rl - 2*esfr
end
dValYh2End = dValYh2Ini
dValXh2Ini = clr -- posizione a sinistra
dValXh2End = W - clr
-- disegno linea
pIni = Point3d( dValXh2Ini, dValYh2Ini, 0)
pEnd = Point3d( dValXh2End, dValYh2End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
-- prima linea verticale
if not rer or rer == 0 or rer == 3 or rer == 6 then -- se in centro
dValXv1Ini = (W-rw)/2 - esfr
elseif rer == 1 or rer == 4 or rer == 7 then -- se riferito a lock
if rty and rty == 2 then -- se rettangolo ricavato dalle distanze
dValXv1Ini = ldr + esfr
else
dValXv1Ini = ldr - esfr
end
else -- tutti gli altri casi (riferito a hinge)
dValXv1Ini = W - hdr + esfr
end
dValXv1End = dValXv1Ini
if rer and ( rer >= 4 and rer <= 6) then -- se riferito a bottom
dValYv1Ini = dValYh1Ini + cir
dValYv1End = dValYh2Ini - cir
else -- tutti gli altri casi (top)
dValYv1Ini = dValYh1Ini - cir
dValYv1End = dValYh2Ini + cir
end
-- disegno linea
pIni = Point3d( dValXv1Ini, dValYv1Ini, 0)
pEnd = Point3d( dValXv1End, dValYv1End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
-- seconda linea verticale
if rer and ( rer == 2 or rer == 5 or rer == 8) then -- se in centro
dValXv2Ini = dValXv1Ini - rw - 2*esfr
else -- tutti gli altri casi
dValXv2Ini = dValXv1Ini + rw + 2*esfr
end
dValXv2End = dValXv2Ini
if rer and ( rer >= 4 and rer <= 6) then -- se riferito a bottom
dValYv2Ini = dValYh1Ini + cir
dValYv2End = dValYh2Ini - cir
else -- tutti gli altri casi (top)
dValYv2Ini = dValYh1Ini - cir
dValYv2End = dValYh2Ini + cir
end
-- disegno linea
pIni = Point3d( dValXv2Ini, dValYv2Ini, 0)
pEnd = Point3d( dValXv2End, dValYv2End, 0)
hint = DrawAddLineDrawCircle( pIni, pEnd, Lg, nil, bPreview, Dm, (d3/2), true, true, RED(), RED())
if hint then
EgtModifyCurveThickness( hint, -Dhr) -- di default è sul lato keyway
EgtSetName( hint, LGR)
end
end
end
-- messaggi di errore (dopo aver fatto il disegno)
if rty and rty == 1 then -- se rettangolo con dimensioni definite
if not rer or rer == 0 then -- se in centro
if rw + (2*esfr) >= W then -- se larghezza rettangolo è più grande della larghezza porta
EC = 29
EM = string.format( EgtDoorsMsg[626], sNamePar2, EgtToUiUnits(rw), EgtToUiUnits(W-(2*esfr)-0.001), sCompoPath)
return (ErrorBase+EC), EM
elseif rl + (2*esfr) >= L then -- se altezza rettangolo è più grande dell'altezza porta
EC = 30
EM = string.format( EgtDoorsMsg[626], sNamePar1, EgtToUiUnits(rl), EgtToUiUnits(L-(2*esfr)-0.001), sCompoPath)
return (ErrorBase+EC), EM
end
else
if rw + (2*esfr) >= W then -- se larghezza rettangolo è più grande della larghezza porta
EC = 31
EM = string.format( EgtDoorsMsg[626], sNamePar2, EgtToUiUnits(rw), EgtToUiUnits(W-(2*esfr)-0.001), sCompoPath)
return (ErrorBase+EC), EM
elseif rl + (2*esfr) >= L then -- se altezza rettangolo è più grande dell'altezza porta
EC = 32
EM = string.format( EgtDoorsMsg[626], sNamePar1, EgtToUiUnits(rl), EgtToUiUnits(L-(2*esfr)-0.001), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and ( rer == 2 or rer == 5 or rer == 8) and ( hdr+esfr+rw >= W) then -- se riferito a hinge e sborda in X
EC = 33
EM = string.format( EgtDoorsMsg[650], sNamePar12, EgtToUiUnits(hdr), sNamePar2, EgtToUiUnits(rw), EgtToUiUnits(esfr), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and ( rer == 2 or rer == 5 or rer == 8) and ( hdr-esfr <= 0) then -- se riferito a hinge e sborda in X
EC = 34
EM = string.format( EgtDoorsMsg[665], sNamePar12, EgtToUiUnits(hdr), EgtToUiUnits(esfr), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and (rer == 1 or rer == 4 or rer == 7) and (ldr+esfr+rw >= W) then -- se riferito a lock e sborda in X
EC = 35
EM = string.format( EgtDoorsMsg[650], sNamePar9, EgtToUiUnits(ldr), sNamePar2, EgtToUiUnits(rw), EgtToUiUnits(esfr), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and (rer == 1 or rer == 4 or rer == 7) and (ldr-esfr <= 0) then -- se riferito a lock e sborda in X
EC = 36
EM = string.format( EgtDoorsMsg[665], sNamePar9, EgtToUiUnits(ldr), EgtToUiUnits(esfr), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and ( rer >= 4 and rer <= 6) and (bdr+esfr+rl >= L) then -- se riferito a bottom e sborda in Y
EC = 37
EM = string.format( EgtDoorsMsg[651], sNamePar13, EgtToUiUnits(bdr), sNamePar1, EgtToUiUnits(rl), EgtToUiUnits(esfr*2), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and ( rer >= 4 and rer <= 6) and (bdr-esfr <= 0) then -- se riferito a bottom e sborda in Y
EC = 38
EM = string.format( EgtDoorsMsg[666], sNamePar13, EgtToUiUnits(bdr), EgtToUiUnits(esfr), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and ( rer >= 1 and rer <= 3) and (tdr+esfr+rl >= L) then -- se riferito a top e rettangolo sborda in Y
EC = 39
EM = string.format( EgtDoorsMsg[651], sNamePar10, EgtToUiUnits(tdr), sNamePar1, EgtToUiUnits(rl), EgtToUiUnits(esfr*2), sCompoPath)
return (ErrorBase+EC), EM
elseif rer and ( rer >= 1 and rer <= 3) and (tdr-esfr <= 0) then -- se riferito a top e rettangolo sborda in Y
EC = 40
EM = string.format( EgtDoorsMsg[666], sNamePar10, EgtToUiUnits(tdr), EgtToUiUnits(esfr), sCompoPath)
return (ErrorBase+EC), EM
end
end
end
end
end
end
-- cambio colore alla geometria
if bPreview then
if EC == 0 then
EgtSetColor( Lg or GDB_ID.NULL, AQUA())
else
EgtSetColor( Lg or GDB_ID.NULL, ORANGE())
end
end
-- Se non Preview
-- (NOTA : se ci sono errori il componente non viene eseguito dal programma di gestione dei componenti)
if not bPreview then
if bRunByCompo then
-- scrivo i parametri nelle info del pezzo
WriteCompoDataToPart(Pz,sCompoName,nCompoNpar)
end
-- scrivo note nel layer della cerniera
EgtSetInfo(Lg,'Type' ,'fc_rectangle')
EgtSetInfo(Lg,'L' ,L)
EgtSetInfo(Lg,'W' ,W)
EgtSetInfo(Lg,'Dhr' ,Dhr)
EgtSetInfo(Lg,'rty' ,rty)
EgtSetInfo(Lg,'ofr' ,ofr)
EgtSetInfo(Lg,'rer' ,rer)
EgtSetInfo(Lg,'tdr' ,tdr)
EgtSetInfo(Lg,'bdr' ,bdr)
EgtSetInfo(Lg,'ldr' ,ldr)
EgtSetInfo(Lg,'hdr' ,hdr)
EgtSetInfo(Lg,'rw' ,rw)
EgtSetInfo(Lg,'rl' ,rl)
EgtSetInfo(Lg,'rf' ,rf)
EgtSetInfo(Lg,'clr' ,clr)
EgtSetInfo(Lg,'cir' ,cir)
EgtSetInfo(Lg,'esfr' ,esfr)
EgtSetInfo(Lg,'pre' ,pre)
EgtSetInfo(Lg,'dtype' ,dtype)
EgtSetInfo(Lg,'LGR' ,LGR)
EgtSetInfo(Lg,'Path' ,sCompoPath)
-- cancello le parti ausiliarie se disegnate
if Dm then
EgtErase(Dm)
end
end
if EC == 0 and nCodAdj and nCodAdj < 0 then
EC = nCodAdj
EM = sCodAdj
end
return EC, EM, Lg
end
return fc_rectangle