76 Commits

Author SHA1 Message Date
Daniele Bariletti fd2a262cb2 - aggiunta parametro per la creazione di splitbottom che converge su un foro circolare. 2025-03-13 11:53:24 +01:00
Daniele Bariletti 60a031c91d - aggiunti nuovi parametri per la creazione di diversi tipi di fondo splittato.
- correzioni varie.
2025-03-07 16:20:43 +01:00
Daniele Bariletti e9fbae9561 - aggiornato elenco parametri per permettere la creazione di due tipi diversi di fori nei fondi di lavandino
- aggiunta la possibilità di scrivere più info in un pezzo in creazione.
2025-03-06 14:56:26 +01:00
Daniele Bariletti ebe2f0dd22 - aggiunta funzione per pulire l'outloop di un part creato come edge. 2025-02-27 14:30:00 +01:00
Daniele Bariletti 89b6b80260 - aggiunta controlli per la gestione degli edge di un part. 2025-02-27 12:18:31 +01:00
Daniele Bariletti f8af3d612c - corretta la funzione per la creazione di un fondo di lavandino come pezzo unico. 2025-02-26 11:54:15 +01:00
Nicola Pievani ea1e4778bf Merge branch 'Cabinet_Top_Chicken' of https://gitlab.steamware.net/egalware-cadcam/lua/StoneSolidGen into Cabinet_Top_Chicken 2025-02-24 10:11:43 +01:00
Nicola Pievani fc30fd5fa1 Gestione figure parametriche 2025-02-24 09:27:03 +01:00
Daniele Bariletti 62041468d8 Merge branch 'Cabinet_Top_Chicken' of https://gitlab.steamware.net/egalware-cadcam/lua/stonesolidgen into Cabinet_Top_Chicken 2025-02-21 12:17:08 +01:00
Daniele Bariletti 205253d1cc - gestite le info da scrivere su un part creato da template. 2025-02-21 12:17:04 +01:00
Nicola Pievani d6bf10959d Merge branch 'Cabinet_Top_Chicken' of https://gitlab.steamware.net/egalware-cadcam/lua/StoneSolidGen into Cabinet_Top_Chicken 2025-02-20 17:12:10 +01:00
Nicola Pievani 0f437d89e7 Prima versione (Bozza) gestione parametrico 2d 2025-02-20 17:11:19 +01:00
Daniele Bariletti 6a0a872b0b - ultimata la gestione delle giunzioni tra paretine. 2025-02-20 16:47:43 +01:00
Daniele Bariletti 45aedbbbc7 - corretta gestione degli offset per le paretine. 2025-02-19 15:46:23 +01:00
Daniele Bariletti 64b9a002be - piccola correzione. 2025-02-17 17:39:33 +01:00
Daniele Bariletti 2a1f155e98 - piccola correzione. 2025-02-17 17:38:43 +01:00
Daniele Bariletti 883c5a2dbd - corretta la gestione della creazione delle paretine in base al tipo di giunzione. 2025-02-17 17:38:24 +01:00
Daniele Bariletti e6ed9a2ec6 - aggiunta gestione della modifica delle paretine
- aggiunta la funzione per il clear della tabella globale
- resa pubblica la funzione per riempire la tabella dalle info di un part
- aggiunta la possibilità di scrivere un'info addizionale nelle paretine.
2025-02-14 16:56:52 +01:00
Daniele Bariletti 1d8bfba501 - irrobustita l'informazione "Paired" da OperationOnSolid. 2025-02-11 17:30:18 +01:00
Daniele Bariletti b5282c2330 - correzione al set dei side ang
- correzione al recupero del PairAng dei vicni
- correzione alla verifica dei vicini dello stesso tipo
- completata la funzione clear part
- resa ricorsiva la creazione dei pezzi in CreateSplitBottom.
2025-02-11 16:09:50 +01:00
Daniele Bariletti e407e75d29 - gestito il caso di selezione randomico dei part per la creazione di uno split bottom. 2025-02-07 17:29:20 +01:00
Daniele Bariletti 2e01ccac6e - sostituita la funzione tostring con EgtNumToString
- calcolo dell'atltezza dei pezzi dello splitBottom.
2025-02-07 14:43:20 +01:00
Daniele Bariletti 1dd33644d8 Merge branch 'Cabinet_Top_Chicken' of https://gitlab.steamware.net/egalware-cadcam/lua/stonesolidgen into Cabinet_Top_Chicken 2025-02-06 17:51:59 +01:00
Daniele Bariletti 73abd6aa1c - correzioni e aggiunte per lo splitBottom. 2025-02-06 17:51:54 +01:00
Demetrio Cassarino c94d4fb8d8 -tolto debug 2025-02-06 17:14:18 +01:00
Daniele Bariletti 56ce2b317d - cambiata la convenzione per le info di pairing. 2025-02-05 10:48:26 +01:00
Daniele Bariletti 1d60218943 Merge branch 'Cabinet_Top_Chicken' of https://gitlab.steamware.net/egalware-cadcam/lua/stonesolidgen into Cabinet_Top_Chicken 2025-02-05 09:25:13 +01:00
Daniele Bariletti 889e97e5c9 - cambiata la notazione per le info di accoppiamento.
- aggiunta la funzione per gestione UUID
- corretta la funzione delle info di machining
- piccole correzioni.
2025-02-05 09:25:08 +01:00
Nicola Pievani bafecedb38 Merge branch 'Cabinet_Top_Chicken' of https://gitlab.steamware.net/egalware-cadcam/lua/StoneSolidGen into Cabinet_Top_Chicken 2025-02-04 11:31:32 +01:00
Daniele Bariletti d352d8c93e - aggiunta la funzione per la creazione del fondello splittato. 2025-01-31 17:29:29 +01:00
Daniele Bariletti 04c3bad9c6 - piccola correzione. 2025-01-30 18:16:38 +01:00
Daniele Bariletti cb1f1ab08b - rinominate le variabili per i layer
- utilizzati solo nomi per salvare le info
- aggiunta la possibilità di avere fino a due paretine sullo stesso lato
- possibilità fare paretine sui loop interni
- correzione nella gestione degli offset
- possiiblità di avere più loop interni.
2025-01-30 15:06:34 +01:00
Daniele Bariletti cd61014fc2 - piccola correzione. 2025-01-28 12:11:02 +01:00
Daniele Bariletti b0f2fc2260 - correzioni. 2025-01-28 12:10:39 +01:00
Daniele Bariletti 8e0141d8c0 - piccola correzione. 2025-01-23 15:08:29 +01:00
Daniele Bariletti a5972bf40a - aggiunstamenti e generalizzazzioni. 2025-01-23 14:34:59 +01:00
Daniele Bariletti 8a3c3eca30 - generalizzate le chiamate alle funzioni e resa possibile la chiamata muta(previo riempimento delle variabili corrispondenti nella tabella globale TOOL). 2025-01-21 17:28:40 +01:00
Daniele Bariletti 369754cdd6 - generalizzazzione delle funzioni e del loro uso: spostate funzioni ed elementi da TopChicken a Template Tool
- aggiunte funzioni a TemplateTool per facilitare l'aggiunta di input.
- corretta in OperationOnSolid la funzione per il salvataggio definitivo degli eventi temporanei.
2025-01-20 09:29:32 +01:00
Daniele Bariletti cb472f4071 - aggiustamenti per l'aggiornamento delle funzioni di TemplateTool. 2025-01-16 14:56:33 +01:00
Daniele Bariletti e92c3ee546 - aggiunte le variabili per la chiamata "muta" delle funzioni CreateParetina, CreateAdjustedPart. 2025-01-16 14:56:00 +01:00
Daniele Bariletti a96680c081 - aggiunta la variabile DoNTimes
- aggiunta la funzione AddAllTempEvents
- migliorata gestione della variabile bRedoPossible
- corretta gestione dei valori della variabili di salvataggio nella funzione ApplyTransf
- corretta gestione dell'Undo
- corretta gestione dell'undo di un unpair svolto attivamente
- migliorata gestione dell'accoppiamento automatico.
2025-01-16 12:54:10 +01:00
Daniele Bariletti 0816e66510 - piccola modifica
- aggiunta della terna.
2025-01-13 14:21:23 +01:00
Daniele Bariletti 950f9bf303 miglioramento dell'autopair. 2025-01-03 16:39:16 +01:00
Daniele Bariletti a4fea15aee - gestione degli offset una tantum dei riferimenti, durante la creazione dei solidi
- gestione dimensione foro nel fondello split.
2024-12-20 17:54:02 +01:00
Daniele Bariletti 28922eff89 - disattivata l'impostazione per l'esecuzione nel CAM5 per il CreateSolid
- gestione dell'import di piani cucina con un loop interno
- gestione della creazione di un fondello con un pezzo unico o con un pezzo per lato
- correzioni al calcolo del draft angle, creazione del pezzo a partire da misure e angoli e calcolo delle misure del pezzo tenendo conto dei vicini.
2024-12-20 10:00:02 +01:00
Daniele Bariletti 6e6aa093cf aggiunto git ignore. 2024-12-18 10:01:09 +01:00
Daniele Bariletti f38f5df4bf aggiunto il fondo del lavello. 2024-12-17 17:12:17 +01:00
Daniele Bariletti d605c189ef aggiunta file con funzioni di base. 2024-12-17 10:48:42 +01:00
Daniele Bariletti f948be4c49 - aggiunta per corretta importazione in parcheggio
- pulizia codice
- creazione funzione per aggiunta fori nei pezzi.
2024-12-17 10:47:59 +01:00
Daniele Bariletti fe2cc47c51 - ridefinizione parametri in input
- spostamento delle funzioni di base nel file TemplateTool e richiamo a queste
- unificazione e semplificazione del codice del template.
2024-12-17 08:50:26 +01:00
Daniele Bariletti 098efa7a66 corretti i bug noti. 2024-12-13 15:18:19 +01:00
Daniele Bariletti 6b2b5eed0f compattamento del codice (con bug) 2024-12-13 12:09:39 +01:00
Daniele Bariletti cd5c951697 correzione delle funzioni per la creazione automatica dei pezzi 2024-12-12 11:58:46 +01:00
Daniele Bariletti 5b7678e5d3 aggiunta delle funzioni per il calcolo automatico delle dimensioni dei pezzi per il template piano cucina 2024-12-12 11:57:35 +01:00
Daniele Bariletti 5ce9e807f2 seprazione del template cabinet dal template piano cucina. 2024-12-04 16:45:33 +01:00
Nicola Pievani 3f5527ec0a Versione Alz and Front 2024-12-04 11:48:01 +01:00
Nicola Pievani c6af34c0e8 Alzatine frontalini (gestire dimensione alzatine) 2024-12-02 19:10:14 +01:00
Nicola Pievani 04929d823f Import di OutLoop come piano cucina 2024-12-02 15:49:26 +01:00
Nicola Pievani 8706506d20 Prima versione Generica per impoartazione Loop 2024-12-02 12:32:27 +01:00
Nicola Pievani 56370249a4 Merge commit 'b307f76f639b25579817f8901a256d38e751eb68' into develop 2024-12-02 12:11:07 +01:00
Daniele Bariletti b307f76f63 - impostato il check per la rigenerazione della scena solo se i dati sono cambiati
- aggiunti controlli
- accoprato il codice in funzioni
- aggiunti commenti.
2024-12-02 10:41:28 +01:00
Daniele Bariletti 8195c4f39a aggiunta del template per la creazione di un cabinet. 2024-12-02 10:39:03 +01:00
Daniele Bariletti b1d113b63f - corretto bug nella creazione del solido di un pezzo con un foro.
- aggiunta lettura thickness dalle info del part.
2024-12-02 09:42:41 +01:00
Daniele Bariletti 0007832e9b - correzioni varie all'accoppiamento. 2024-11-26 12:21:57 +01:00
Daniele Bariletti f595d03482 - cambiata la variabile globale da CMD a SLD
- attivata la funzionalità da CAM e disattivata per l'uso da OFFICE.
2024-11-26 12:21:27 +01:00
Daniele Bariletti a466488114 OpertaionOnSolid :
- gestione output errori.
- evento importazione.
- accoppiamento automatico di default middle-middle.
| CreateSolid:
- estensione a più feature.
- gestione delle info per gli offset dei riferimenti.
2024-11-20 17:27:22 +01:00
Daniele Bariletti 6de80f9598 aggiunta gestione delle pocket 2024-11-12 17:12:30 +01:00
Daniele Bariletti 6370198a0c - aggiunta la funzione per l'accoppiamento automatico
- piccole correzioni e migliorie.
2024-11-12 17:10:22 +01:00
Daniele Bariletti 10f293b549 - correzioni alla conversione da .NET a LUA
- aggiunte alla gestione della storia
- aggiunte alla gestione della terna
- correzioni varie.
2024-10-22 16:20:12 +02:00
Daniele Bariletti 622cafcfc8 correzioni e aggiunta di funzioni. 2024-10-17 18:11:30 +02:00
Daniele Bariletti de312b7804 aggiunto il file per la gestione delle operazioni sui solidi tutta in lua. 2024-10-14 10:40:06 +02:00
Daniele Bariletti fb92ae324c aggiunta gestione dei loop interni con archi con sideAng ( manca gestione Heel in questi casi) 2024-10-02 10:19:11 +02:00
Daniele Bariletti 12890da212 aggiunta gestione degli archi nei loop interni 2024-09-27 14:43:11 +02:00
Daniele Bariletti 2bb2ac39b8 Modifiche apportate al 20/09/24 2024-09-27 14:41:37 +02:00
Daniele Bariletti 2769f3a604 modiofiche apportate al 17/01/24 2024-09-27 14:40:39 +02:00
Daniele Bariletti 5dacc59e95 creazione solidi importata da OMAGCut e adattata per OMAGOffice. 2024-09-27 14:36:57 +02:00
10 changed files with 5198 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
# /
/revision.h
/*.aps
/*.ncb
/*.suo
/*.user
/*.sdf
/*.opensdf
/Debug32
/Release32
/Trial32
/Debug64
/Release64
/ipch
/.vscode
+738
View File
@@ -0,0 +1,738 @@
-- 2024/11/22
-- Template per la creazione di un cabinet
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
EgtAddToPackagePath(EgtGetSourceDir() .. 'LuaLibs\\?.lua')
require( 'EgtCompo')
-- Parametri : dichiarazione e valori standard
-- N.B.: le dimensioni sono comprese di spessori
local CMP = {}
CMP.N1 = 'Altezza' -- altezza
CMP.T1 = 3 -- 0=null, 1=bool, 2=int, 3=len, 4=num, 5=string
CMP.V1 = 400
CMP.N2 = 'Larghezza' -- larghezza
CMP.T2 = 3
CMP.V2 = 600
CMP.N3 = 'Profondità' -- profondità
CMP.T3 = 3
CMP.V3 = 300
CMP.N4 = 'Spessore Top' -- spessore top
CMP.T4 = 3
CMP.V4 = 20
CMP.N5 = 'Spessore Bottom' -- spessore bottom
CMP.T5 = 3
CMP.V5 = 20
CMP.N6 = 'Spessore Left' -- spessore left
CMP.T6 = 3
CMP.V6 = 8
CMP.N7 = 'Spessore Right' -- spessore right
CMP.T7 = 3
CMP.V7 = 6
CMP.N8 = 'Spessore Back' -- spessore back
CMP.T8 = 3
CMP.V8 = 7
CMP.ResetView = false
CMP.DrawSolid = true
CMP.Npar = 8
CMP.Nome = 'Cabinet'
_G.CMP = CMP
CMP.ERR = 0
CMP.MSG = ''
-- Aggiorno con ultimi valori salvati (se presenti)
CMP.DATA = EgtGetSourceDir() .. CMP.Nome ..'.dat'
LoadCompoData()
-- Percorso direttorio Vein3D
local sPath = ""
sPath = EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile())
EgtOutLog(''..sPath)
-- Carico i dati letti da file .dat
local tbOrigVal={}
local function OrigData()
tbOrigVal.v1 = CMP.V1
tbOrigVal.v2 = CMP.V2
tbOrigVal.v3 = CMP.V3
tbOrigVal.v4 = CMP.V4
tbOrigVal.v5 = CMP.V5
tbOrigVal.v6 = CMP.V6
tbOrigVal.v7 = CMP.V7
tbOrigVal.v8 = CMP.V8
end
---
local tbName = {'Bottom', 'Left', 'Right', 'Top', 'Back'}
local sUNICode = os.date( '%y%m%d%H%M%S', os.time()).."_"
-------------------------------------------------------------------------------------------------------------------------
-- FUNZIONI BASE PER GENERARE I COMPO SOLID INIZIO
-------------------------------------------------------------------------------------------------------------------------
local function SaveMEPlease()
EgtSaveFile('c:\\EgtData\\OmagOFFICE\\Vein3D\\FOO.nge')
end
-- CREAZIONE dei Layer di un singolo Part
-- I nomi dei layer sono: OutLoop, Region, Ref, Labels, Aux
local function CreatePartLayer(PartName)
-- Pezzo e Layer
local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- pezzo
EgtSetName( Pz, sUNICode..PartName)
local LOut = EgtGroup(Pz,GDB_RT.LOC) -- layer della figura principale
EgtSetName(LOut,'OutLoop')
local LReg = EgtGroup(Pz,GDB_RT.LOC) -- layer regione
EgtSetName(LReg,'Region')
local LRef = EgtGroup(Pz,GDB_RT.LOC) -- layer riferimenti
EgtSetName(LRef,'Ref')
EgtSetStatus( LRef, GDB_ST.OFF)
local LLabel= EgtGroup(Pz,GDB_RT.LOC) -- layer etichette
EgtSetName(LLabel,'Labels')
local LAux= EgtGroup(Pz,GDB_RT.LOC) -- layer etichette
EgtSetName(LAux,'Aux')
EgtOutLog(' Creo Part: '..sUNICode..PartName)
SaveMEPlease()
return Pz
end
--
-- RESTITUISCE una tabella con gli Id dei layer costruiti nella funzione CreatePartLayer part,
-- Se il nome del Part non esiste restituice nil
local function FindLayers( IdPart)
if not EgtIsPart( IdPart) then
CMP.ERR = 1
CMP.MSG = CMP.MSG.." In FindLayers 'IdPart' non è un Part"
return nil
end
local tbLayer = {}
tbLayer['OutLoop'] = EgtGetFirstNameInGroup(IdPart, 'OutLoop')
tbLayer['Region'] = EgtGetFirstNameInGroup(IdPart, 'Region')
tbLayer['Ref'] = EgtGetFirstNameInGroup(IdPart, 'Ref')
tbLayer['Labels'] = EgtGetFirstNameInGroup(IdPart, 'Labels')
tbLayer['Aux'] = EgtGetFirstNameInGroup(IdPart, 'Aux')
return tbLayer
end
--
-- ASSEGNO Info per conoscere le direzioni dei lati
local function SetMachiningInfo(Layer, bInLoop)
-- if not bInLoop then return end
if EgtIsLayer( Layer) then
local LayerName = EgtGetName( Layer)
-- verifico che sia di tipo In o Out, altrimenti ricerco nel Part il layer
if not LayerName == 'OutLoop' or not LayerName == 'InLoop' then
Layer = EgtGetFirstInGroup( Layer)
CMP.ERR = 2
CMP.MSG = CMP.MSG.." In SetMachiningInfo il Layer non è di tipo 'OutLoop' o 'InLoop'."
end
else
CMP.ERR = 3
CMP.MSG = CMP.MSG.." In SetMachiningInfo il Layer non è di tipo 'OutLoop' o 'InLoop'."
end
local nId = EgtGetFirstInGroup(Layer)
local nPrevId = EgtGetLastInGroup(Layer)
local nNextId = EgtGetNext(nId)
local nFirstId = nId
local nEdges = EgtGetGroupObjs(Layer)
if nEdges == 1 then
EgtSetInfo(nId, 'PrevAng', 0)
EgtSetInfo(nId, 'NextAng', 0)
return
end
for i = 1, nEdges do
-- recupero i dati
local vtCurrS = EgtSV(nId, GDB_RT.GLOB)
local vtPrevE = EgtEV(nPrevId, GDB_RT.GLOB)
local vtCurrE = EgtEV(nId, GDB_RT.GLOB)
local vtNextS = EgtSV(nNextId, GDB_RT.GLOB)
local vtAx = Z_AX()
if bInLoop then vtAx=-vtAx end
local NextAng = GetRotation( vtCurrE, vtNextS, vtAx)
local PrevAng = GetRotation( vtPrevE, vtCurrS, vtAx)
-- scrivo le info
EgtSetInfo(nId, 'PrevAng', PrevAng)
EgtSetInfo(nId, 'NextAng', NextAng)
-- aggiorno gli id
nPrevId = nId
nId = nNextId
nNextId = EgtGetNext(nNextId)
if nNextId == nil then
nNextId = nFirstId
end
end
end
--
-- DEVO RICEVERE SOLO UN CONTORNO!! Da semplificare
-- Dato un contorno ricavo i lati nel Layer di appartenenza del contorno
-- altrimenti se Part ricavo i lati nel loop specificato (Default=OutLoop o InLoop)
local function ExplodeAndNameEdges( IdLoop, bInLoop)
local sNameLayer = ''
if bInLoop then
sNameLayer = 'InLoop'
else
sNameLayer = 'OutLoop'
end
if not IdLoop or IdLoop == -1 then end
-- Se l'Id è un Part
if EgtIsPart( IdLoop) then
local tbLayer = FindLayers( IdLoop)
if tbLayer then IdLoop = EgtGetFirstInGroup( tbLayer[sNameLayer]) end
end
-- Se l'Id è un Layer
if EgtIsLayer( IdLoop) then
local LayerName = EgtGetName( IdLoop)
-- verifico che sia di tipo In o Out, altrimenti ricerco nel Part il layer
if LayerName == sNameLayer then
IdLoop = EgtGetFirstInGroup( IdLoop)
else
local tbLayer = FindLayers( EgtGetParent(IdLoop))
if tbLayer then IdLoop = EgtGetFirstInGroup( tbLayer[sNameLayer]) end
end
end
local nLay = EgtGetParent(IdLoop)
local nEdge, nTotEdges = EgtExplodeCurveCompo(IdLoop)
local nCount = 1
local tbIdLoop = {}
while nEdge do
local tbName = EgtNumToString(nCount)
EgtSetName( nEdge, "A"..tbName)
nCount = nCount + 1
table.insert( tbIdLoop, nEdge)
nEdge = EgtGetNext(nEdge)
end
-- Ricavo info direzioni
SetMachiningInfo(nLay,bInLoop)
return tbIdLoop
end
--
-- CREAZIONE LAyer per le dimensioni
local function CreateLayerDimension()
local Pz = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC) -- layer dimensioni e etichette
EgtSetName( Pz, 'Dimensions')
end
--
-- Per disporre i pezzi in piano non sovrappposti (in assemblaggio non serve)
local HorizontalOffset = 0
-- CREAZIONE di un solido, o della sua buca
local function CreatePart_0(IdPart, sName, ptDiagStart, ptDiagEnd, dTh, dOffset, bInLoop)
-- recupero il layer del contorno
local sNameLayer = ''
if bInLoop then
sNameLayer = 'InLoop'
if not ptDiagStart then
ptDiagStart = {1,1,0}
CMP.ERR = 4
CMP.MSG = CMP.MSG.." Manca la definizione del punto iniziale per l'InLoop, di default (1,1,0)."
end
else
sNameLayer = 'OutLoop'
ptDiagStart = ORIG()
end
-- Recupero gli Id dei Layer (che sono vuoti)
local tbLayer = FindLayers( IdPart)
-- Nel Layer OutLoop o InLoop definisco il contorno RETTANGOLO
EgtOutLog(sNameLayer..' '..tostring(tbLayer[sNameLayer]))
local IdLoop = EgtRectangle2P(tbLayer[sNameLayer],ptDiagStart,ptDiagEnd,GDB_RT.GLOB)
-- Nel Layer Region definisco la regione piana
local IdReg = EgtSurfFlatRegion(tbLayer['Region'],IdLoop)
-- Se InLoop allora faccio la sottrazione con la regione OutRegion
if sNameLayer == 'InLoop' then
local IdOutRegion = EgtGetPrev(IdReg)
if not EgtSurfFrSubtract( IdOutRegion,IdReg) then
CMP.ERR = 5
CMP.MSG = CMP.MSG.." Sottrazione tra superficie 'OutLoop' "..tostring(IdOutRegion).." e 'InLoop' "..tostring(IdReg).." non riuscita."
end
--EgtErase(IdReg) --debug
end
if bInLoop then EgtInvertCurve(IdLoop) end
-- Ricavo i lati da lavorare
ExplodeAndNameEdges( IdLoop)
-- Se sono InLoop non devo settare
if bInLoop then return end
-- definisco spessore pezzo
EgtSetInfo(IdPart, 'Th', dTh)
-- INFO NECESSARIA
EgtSetInfo(IdPart, 'Paired',tostring(IdPart))
-- inserisco le etichette del pezzo
local ptTop = Point3d(ptDiagEnd)/2
local ptBottom = Point3d( ptTop:getX(), -ptTop:getY(), dTh)
EgtTextAdv(tbLayer['Labels'], ptTop,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC)
if CMP.DrawSolid then
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.BOTTOM))
EgtTextAdv(tbLayer['Labels'], ptBottom,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC, GDB_RT.GRID)
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.TOP))
end
-- dispongo il pezzo in piano
local vtMove = Vector3d({dOffset,0,0})
--EgtMove(IdPart,vtMove, GDB_RT.GLOB)
HorizontalOffset = HorizontalOffset + Point3d(ptDiagEnd):getX()
end
--
-- Creazione del part assegnato un contorno esploso:
-- tbLayer : tabella dei layer (FindLayers dato il Part)
-- sName : nome da assegnare in grafica
-- tbIdEntCrv: tabella delle entità che costituiscono il contorno (da ExplodeAndNameEdges)
-- dTh : spessore pezzo
-- dOffset : per messa in piano dei pezzi (0 se non si usa)
-- bInLoop : tipo di contorno
local function CreatePart(tbLayer, sName, tbIdEntCrv, dTh, dOffset, bInLoop)
-- recupero il layer del contorno
local IdCurrLayer = EgtGetParent( tbIdEntCrv[1])
-- recupero l'Id del part
local IdPart = EgtGetParent( IdCurrLayer)
-- costruisco il contorno chiuso
local IdLoop = EgtCurveCompoByChain( IdCurrLayer, tbIdEntCrv, EgtSP(tbIdEntCrv[1],GDB_RT.GLOB), false, GDB_RT.GLOB)
-- Nel Layer Region definisco la regione piana
local IdReg = EgtSurfFlatRegion(tbLayer['Region'],IdLoop)
-- Se InLoop allora faccio la sottrazione con la regione OutRegion
if bInLoop then
local IdOutRegion = EgtGetPrev(IdReg)
if not EgtSurfFrSubtract( IdOutRegion,IdReg) then
CMP.ERR = 5
CMP.MSG = CMP.MSG.." Sottrazione tra superficie 'OutLoop' "..tostring(IdOutRegion).." e 'InLoop' "..tostring(IdReg).." non riuscita."
end
EgtErase(IdReg)
end
-- if bInLoop then EgtInvertCurve(IdLoop) end
-- elimino il contorno chiuso
EgtErase(IdLoop)
-- Se sono InLoop non devo settare
if bInLoop then return end
-- definisco spessore pezzo
EgtSetInfo(IdPart, 'Th', dTh)
-- INFO NECESSARIA
EgtSetInfo(IdPart, 'Paired',tostring(IdPart))
-- inserisco le etichette del pezzo nel centro della superofocie
local ptTop = EgtCP( IdReg, GDB_RT.GLOB)
local ptBottom = Point3d( ptTop:getX(), -ptTop:getY(), dTh)
EgtTextAdv(tbLayer['Labels'], ptTop,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC)
if CMP.DrawSolid then
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.BOTTOM))
EgtTextAdv(tbLayer['Labels'], ptBottom,0,sName, '', 10, '', 15,1.5,0,GDB_TI.MC, GDB_RT.GRID)
EgtSetGridFrame(Frame3d(ORIG(),GDB_FR.TOP))
end
-- dispongo il pezzo in piano
local vtMove = Vector3d({dOffset,0,0})
--EgtMove(IdPart,vtMove, GDB_RT.GLOB)
HorizontalOffset = HorizontalOffset + ptTop:getX()*2
end
--
-- Sposto l'etichetta del nome del Part nel Solido associato
local function RelocateLabels()
local nPartId = EgtGetFirstPart()
while nPartId do
local nChild = EgtGetInfo(nPartId, 'Child','i')
if nChild then
local nLaySource = EgtGetFirstNameInGroup(nPartId, 'Labels')
if nLaySource then EgtRelocateGlob( nLaySource, nChild) end
end
nPartId = EgtGetNext(nPartId)
end
end
--
-- Crea una copia dello spigolo e lo salva nel layer Ref
-- Nome del part (da tbName[1]),
-- Nome del Layer (OutLoop o InLoop),
-- Nome dello spigolo,
-- Nome della copia riferimento
-- Info per spostamento Ref in funzione di una variabile
local function CreateReference( sNamePart, sNameLayer,sNameEdge, sNameRef, dVar, sDir)
local IdPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart)
local tbLayer = FindLayers( IdPart)
--accoppiamento di left su bottom
local IdEnt = EgtGetFirstNameInGroup(tbLayer[sNameLayer], sNameEdge)
if not IdEnt then
CMP.ERR=6
CMP.MSG= CMP.MSG..' Non esiste il lato '..sNameEdge..' nel layer '..sNameLayer..' del part '..sNamePart
return
end
-- creo la copia dello spigolo come riferimento
local IdRef = EgtCopy( IdEnt, tbLayer['Ref'])
EgtSetName( IdRef, sNameRef)
if dVar and sDir then
EgtSetInfo(IdRef, 'Var', dVar)
EgtSetInfo(IdRef, 'Dir', sDir)
end
return IdRef
end
--
-- Crea una copia dello del punto dello spigolo e lo salva nel layer Ref
-- Nome del part (da tbName[1]),
-- Nome del Layer (OutLoop o InLoop),
-- Nome dello spigolo,
-- Nome della copia punto
-- Tipo di punto: 0/nil START, 1 END, 2 MID
local function CreatePointReference( sNamePart, sNameLayer,sNameEdge, sNameRef, nTypePt)
local IdPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart)
local tbLayer = FindLayers( IdPart)
--accoppiamento di left su bottom
local IdEnt = EgtGetFirstNameInGroup(tbLayer[sNameLayer], sNameEdge)
if not IdEnt then
CMP.ERR=6
CMP.MSG= CMP.MSG..' Non esiste il lato '..sNameEdge..' nel layer '..sNameLayer..' del part '..sNamePart
return
end
local pt = EgtSP(IdEnt, GDB_RT.GLOB)
if nTypePt == 1 then
pt = EgtEP(IdEnt, GDB_RT.GLOB)
elseif nTypePt == 2 then
pt = EgtMP(IdEnt, GDB_RT.GLOB)
end
local IdPtRef = EgtPoint( tbLayer['Ref'], pt, GDB_RT.GLOB)
EgtSetName(IdPtRef, sNameRef)
return IdPtRef
end
--
-- Accoppia lato a riferimento
-- Nome del pezzo da accoppiare
-- Nome del riferimento da usare
-- Nome del pezzo destinatario dell'accoppiamento
-- Nome del riferimento da usare come destinatario dell'accoppiamento
-- Concordanza del verso dei due spigoli
-- Angolo relativo tra i due pezzi: porta la normale della regione del pezzo corrente a coincidere
-- con la normale della regione del pezzo destinatario; il segno è riferito al verso del riferimento del part destinatario
-- Modalità di accoppiamento tra gli spigoli (0: start-start, 1:start-end, 2: end-start, 3: end-end, 4: mid-mid)
local function SetPairInfo( sMyNamePart, sNameMyRef, sToNamePart, sNameToRef, nPairSpin, dPairAng, nPairMode)
local nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sMyNamePart)
EgtSetInfo(nPart, "PairMyRef", sNameMyRef)
EgtSetInfo(nPart, "PairToRef", sUNICode..sToNamePart.."_"..sNameToRef)
EgtSetInfo(nPart, "PairSpin", nPairSpin)
EgtSetInfo(nPart, "PairAng", dPairAng)
if nPairMode then EgtSetInfo(nPart, "PairMode", nPairMode) end
end
-- Disegna la quota lineare
-- Nome del part in cui trovare il primo punto di riferimento
-- Nome del punto riferimento nel part indicato sopra
-- Nome del part in cui trovare il secondo punto di riferimento
-- Nome del punto riferimento nel part indicato sopra
-- Nome/valore stringa da scrivere nella dimensione
-- Frame del piano su cui disegnare la quotatura
-- Offset etichetta rispetto al punto medio
local function DrawLinearDimension( sNamePart1, sNameRef1, sNamePart2, sNameRef2, sNameDimension, GridFrame, ptOffset)
EgtSetGridFrame(GridFrame)
local nDimLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, 'Dimensions')
local nBottomLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart1)
local nRefBottom = EgtGetFirstNameInGroup(nBottomLay, 'Ref')
local nRef = EgtGetFirstNameInGroup(nRefBottom, sNameRef1)
local pt1 = EgtSP( nRef, GDB_RT.GRID)
local nTopLay = EgtGetFirstNameInGroup(GDB_ID.ROOT, sUNICode..sNamePart2)
local nRefTop = EgtGetFirstNameInGroup(nTopLay, 'Ref')
nRef = EgtGetFirstNameInGroup(nRefTop, sNameRef2)
local pt2 = EgtSP( nRef, GDB_RT.GRID)
local ptMid = (pt1 + pt2) / 2 + ptOffset
local nDim = EgtAlignedDimension( nDimLay, pt1, pt2, ptMid, sNameDimension, GDB_RT.GRID)
EgtSetColor( nDim, EgtStdColor( 'YELLOW'))
EgtRelocate(nDim, GDB_RT.GRID)
EgtSetName(nDim, sNameDimension)
end
--
-------------------------------------------------------------------------------------------------------------------------
-- FUNZIONI BASE PER GENERARE I COMPO SOLID FINE
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-- COSTRUZIONE RIFERIMENTI INIZIO
-------------------------------------------------------------------------------------------------------------------------
local function SetReference()
-- Esempio Riferimento:
-- CreateReference( tbName[2], 'OutLoop', 'A2', 'R1', CMP.SL, '0,0,-x')
-- SetPairInfo( tbName[2], 'R1', tbName[1], 'R1', -1, 90, 1)
-- Esempio Punto per dimension:
-- CreatePointReference( tbName[1], 'OutLoop', 'A1', 'R4', 0, CMP.SB, '0,0,-x')
SaveMEPlease()
end
--
local function AddDimensions()
local GridFr = Frame3d(ORIG(),GDB_FR.FRONT)
--Esempio:
-- DrawLinearDimension( tbName[1], 'R4', tbName[4], 'R2', 'SUA ALTEZZA',GridFr, Point3d(-50,0,0))
EgtSetGridFrame(GLOB_FRM())
end
--
-------------------------------------------------------------------------------------------------------------------------
-- COSTRUZIONE RIFERIMENTI FINE
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-- CREAZIONE/IMPORTAZIONE Loop INIZIO
-------------------------------------------------------------------------------------------------------------------------
-- Importa un contorno chiuso da file nge
function ImportOutLoop( tbLayer, sNameFileNGE)
local OutLayer = tbLayer['OutLoop']
if not EgtInsertFile( sNameFileNGE) then
EgtOutLog(' IMPORTAZIONE FALLITA: '..sNameFileNGE)
end
-- recupero ultimo Part
local LastPart = EgtGetLastPart()
local FstLayerInLstPart = EgtGetFirstGroupInGroup( LastPart)
local IdLoop = EgtGetFirstInGroup( FstLayerInLstPart)
if not EgtRelocateGlob( IdLoop, OutLayer) then
EgtOutLog(' RELOCATE AFLLITA MISERAMENTE: '..tostring(IdLoop)..';'..tostring(OutLayer))
end
EgtErase(LastPart)
local tbIdLoop = ExplodeAndNameEdges( IdLoop)
EgtSetInfo(tbIdLoop[1],'AF',1)
EgtSetInfo(tbIdLoop[2],'AF',2)
EgtSetInfo(tbIdLoop[3],'AF',2)
EgtSetInfo(tbIdLoop[4],'AF',2)
EgtSetInfo(tbIdLoop[5],'AF',2)
EgtSetInfo(tbIdLoop[6],'AF',2)
EgtSetInfo(tbIdLoop[7],'AF',1)
SaveMEPlease()
-- definizione SideAng
-- EgtSetInfo( tbIdLoop[1], 'OrigSideAng', 45)
return tbIdLoop
end
--
-- Crea un contorno chiuso rettangolare come OutLoop (con diagonale da origine a ptEND)
function CreateWaterfall( tbLayer, sNameLayer, ptEND, PrevAng, NextAng, bIsPrevWaterfall, bIsNextWaterfall)
local OffseAng = 3
local NAng = NextAng/2 + OffseAng
local PAng = PrevAng/2 + OffseAng
if not bIsNextWaterfall then
if NAng >= 0 then
NAng = -90 + NextAng
else
NAng = -90 - NextAng
end
end
if not bIsPrevWaterfall then
if PAng >= 0 then
PAng = -90 + PrevAng
else
PAng = -90 - PrevAng
end
end
local IdLoop = EgtRectangle2P(tbLayer[sNameLayer],{0,0,0}, ptEND,GDB_RT.GLOB)
local tbIdLoop = ExplodeAndNameEdges( IdLoop)
-- definizione SideAng
-- bla bla bla---------------------------------------------------------------------------------------------------
EgtSetInfo( tbIdLoop[2], 'OrigSideAng', -NAng)
EgtSetInfo( tbIdLoop[2], 'SideAng', -NAng)
EgtSetInfo( tbIdLoop[4], 'OrigSideAng', -PAng)
EgtSetInfo( tbIdLoop[4], 'SideAng', -PAng)
-- bla bla bla---------------------------------------------------------------------------------------------------
return tbIdLoop
end
--
-- Crea un contorno chiuso rettangolare come OutLoop (con diagonale da origine a ptEND)
function CreateSplashtop( tbLayer, sNameLayer, ptEND, PrevAng, NextAng, bIsPrevSplashtop, bIsNextSplashtop, Th)
local OffseAng = 3
local NAng = NextAng/2 + OffseAng
local PAng = PrevAng/2 + OffseAng
if not bIsNextWaterfall then
if NAng >= 0 then
NAng = 90 - NextAng
else
NAng = 90 + NextAng
end
end
if not bIsPrevWaterfall then
if PAng >= 0 then
PAng = 90 - PrevAng
else
PAng = 90 + PrevAng
end
end
EgtOutLog(PAng)
EgtOutLog(NAng)
-- allarghiamo il pezzo
ptEND[1] = ptEND[1] + Th*(sin(NAng) + sin(PAng))
--ptEND[1] = ptEND[1] + Th*(sin(NAng) + sin(PAng)) - Th/cos(NAng)
local IdLoop = EgtRectangle2P(tbLayer[sNameLayer],{0,0,0}, ptEND,GDB_RT.GLOB)
local tbIdLoop = ExplodeAndNameEdges( IdLoop)
-- definizione SideAng
-- bla bla bla---------------------------------------------------------------------------------------------------
EgtSetInfo( tbIdLoop[2], 'OrigSideAng', -NAng)
EgtSetInfo( tbIdLoop[2], 'SideAng', -NAng)
EgtSetInfo( tbIdLoop[4], 'OrigSideAng', -PAng)
EgtSetInfo( tbIdLoop[4], 'SideAng', -PAng)
-- bla bla bla---------------------------------------------------------------------------------------------------
return tbIdLoop, PAng, NAng, Th*sin(PAng)
end
--
-------------------------------------------------------------------------------------------------------------------------
-- CREAZIONE/IMPORTAZIONE Loop FINE
-------------------------------------------------------------------------------------------------------------------------
local function GetInfoSplahtopOrWaterfall()
local tbSplWf = {}
-- ...
return tbSplWf
end
-------------------------------------------------------------------------------------------------------------------------
-- METODI AUSILIARI LOCALI INIZIO
-------------------------------------------------------------------------------------------------------------------------
-- Restituisce l'angolo precedente e successivo dell'aentità passata
local function GetPrevNextAng(IdEnt)
local PrevAng = EgtGetInfo(IdEnt,'PrevAng','d') or 0
local NextAng = EgtGetInfo(IdEnt,'NextAng','d') or 0
return PrevAng, NextAng
end
--
-- Verifica se esiste un Waterfall successivo a quallo corrente (i-esimo) della lista passata
local function IsNextWaterfall(tbIdLoop, i)
i = i+1
if i > #tbIdLoop then i = 1 end
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
if nVal == 2 then
return true
end
return false
end
--
-- Verifica se esiste un Waterfall precedente a quallo corrente (i-esimo) della lista passata
local function IsPrevWaterfall(tbIdLoop, i)
i = i-1
if i < 1 then i = #tbIdLoop end
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
if nVal == 2 then
return true
end
return false
end
--
-- Verifica se esiste un Splashtop successivo a quallo corrente (i-esimo) della lista passata
local function IsNextSplashtop(tbIdLoop, i)
i = i+1
if i > #tbIdLoop then i = 1 end
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
if nVal == 1 then
return true
end
return false
end
--
-- Verifica se esiste un Splashtop precedente a quallo corrente (i-esimo) della lista passata
local function IsPrevSplashtop(tbIdLoop, i)
i = i-1
if i < 1 then i = #tbIdLoop end
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
if nVal == 1 then
return true
end
return false
end
-------------------------------------------------------------------------------------------------------------------------
-- METODI AUSILIARI LOCALI FINE
-------------------------------------------------------------------------------------------------------------------------
-- Confronto i dati del fiel .dat con quelli letti da programma
local function IsDataChanged()
local bOk = false
if not tbOrigVal.v1 then return true end
if math.abs(CMP.V1 - tbOrigVal.v1) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V2 - tbOrigVal.v2) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V3 - tbOrigVal.v3) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V4 - tbOrigVal.v4) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V5 - tbOrigVal.v5) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V6 - tbOrigVal.v6) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V7 - tbOrigVal.v7) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V8 - tbOrigVal.v8) > 0.5 then bOk = bOk or true end
return bOk
end
function CMP_Draw(bPreview)
local bRedraw = IsDataChanged()
if bRedraw or not CMP.DrawSolid then
-- pulisco il file e leggo i dati
EgtNewFile()
HorizontalOffset = 0
CMP.A = CMP.V1 -- altezza
CMP.L = CMP.V2 -- lunghezza
CMP.P = CMP.V3 -- profondità
CMP.ST = CMP.V4 -- spessore top
CMP.SB = CMP.V5 -- spessore bottom
CMP.SL = CMP.V6 -- spessore left
CMP.SR = CMP.V7 -- spessore right
CMP.SBA = CMP.V8 -- spessore back
-- PIANO POLLO
local Pz_Top = CreatePartLayer( 'TopChicken')
-- Creo il contorno esterno
local tbIdLoop = ImportOutLoop( FindLayers( Pz_Top), sPath ..'\\'.. 'TopChicken.nge')
-- Creo il pezzo dato il contorno
CreatePart( FindLayers( Pz_Top), 'TopChicken', tbIdLoop, CMP.ST, 0)
for i=1, #tbIdLoop do
local nVal = EgtGetInfo(tbIdLoop[i], 'AF', 'i') or 0
if nVal == 2 then
-- WATERFALL
local dH = 100
local sNamePz = 'A'.. tostring(i)..'Waterfall'
local Pz_A = CreatePartLayer(sNamePz)
local dLen = EgtCurveLength(tbIdLoop[i])
local PAng, NAng = GetPrevNextAng(tbIdLoop[i])
local tbIdLoopWF = CreateWaterfall( FindLayers(Pz_A), 'OutLoop', {dLen, dH,0}, PAng, NAng, IsPrevWaterfall(tbIdLoop, i), IsNextWaterfall(tbIdLoop, i))
CreatePart( FindLayers(Pz_A), sNamePz, tbIdLoopWF, CMP.ST, 0)
CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(i), 'R'..tostring(i), CMP.ST, '0,0,-x')
CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, '0,0,0')
SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(i), -1, -90, 1)
elseif nVal == 1 then
-- SPLASHTOP
local dH = 200
local sNamePz = 'A'.. tostring(i)..'Splahtop'
local Pz_A = CreatePartLayer(sNamePz)
local dLen = EgtCurveLength(tbIdLoop[i])
local PAng, NAng = GetPrevNextAng(tbIdLoop[i])
local tbIdLoopWF, PAng, dLenOffset = CreateSplashtop( FindLayers(Pz_A), 'OutLoop', {dLen, dH,0}, PAng, NAng, IsPrevSplashtop(tbIdLoop, i), IsNextSplashtop(tbIdLoop, i), CMP.ST)
CreatePart( FindLayers(Pz_A), sNamePz, tbIdLoopWF, CMP.ST, 0)
CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(i), 'R'..tostring(i), CMP.ST, '0,0,0')
CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, tostring(dLenOffset)..',0,-x')
--CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, '0,0,-x')
SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(i), -1, 90, 2)
end
end
CreateLayerDimension()
SetReference()
if CMP.DrawSolid then
loadfile(sPath ..'\\'.. "CreateSOLID_FromPartsInPark.lua")({AutoRun=true})
RelocateLabels()
loadfile(sPath ..'\\'.. "OperationOnSolid.lua")({AutoRun=true, nVeinCtx=EgtGetContext()})
AddDimensions()
end
-- Se non ci sono errori salvo i dati
if CMP.ERR == 0 then
-- scrivo i parametri nelle info del pezzo !! DA FARE !!
-- WriteCompoDataToPart( Pz, CMP.Nome, CMP.Npar)
-- salvo i parametri come nuovo default
SaveCompoData(CMP.Npar)
OrigData()
end
SaveMEPlease()
end
end
--CMP_Draw()
_G.CMP_Draw = CMP_Draw
+980
View File
@@ -0,0 +1,980 @@
-- 2023/05/__
-- |ultima modifica:|
-- |aggiunta gestione di più loop interni|
--ERR == -1 valore di default
--ERR == 1 SLD.CurrId non è valido ( == -1)
--ERR == 0 eseguito senza problemi
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
-- Dati raccolti direttamente dal programma
local SLD = {}
--input
SLD.THICK = 40
SLD.CurrId = -1
-- output
SLD.CurrPartSolid = -1
SLD.CurrSrfTmId = -1
SLD.ERR = -1
----- mi preparo a ricevere argomenti
local arg = ...
local bAutoRun = false
if arg then
bAutoRun = arg.AutoRun
end
_G.SLD = SLD
local ColorSTD = 'AQUA'
local ColocERR = 'ORANGE'
-- Id del primo Part del progetto
local IdP_FirstPart = -1
-- Id del layer "OutLoop"
local IdL_OutLoop = -1
-- Id del layer "InLoop"
local IdL_InLoop = -1
-- Id del layer "OnPath"
local IdL_OnPath = -1
-- Id del layer "Pocket"
local IdL_Pocket = -1
-- Id del layer "FiloTop"
local IdL_FiloTop = -1
-- Id del Part "SOLID"
local IdP_SOLID = -1
-- Id dei layer apprtenenti a "SOLID"
local IdL_Temp = -1
local IdL_Solid = -1
local IdL_Bound = -1
local IdL_Faces = -1
--[[
tabella contenente: IdSurf → superificie di taglio,
ptS → punto in basso a sinistra dalla superificie
vtS → direzioned del lato basso della superficie
Ang → inclinazione rispetto alla verticale
Hill → tallone
NAng → direzione agolo orizzontale lato successivo
]]--
local tbId_RectSurf = {}
-- tabella contenente i lati del layer OutLoop: IdS → lato del contorno
local tbId_OutLoop = {}
-- tabella contenente le tabelle dei layer degli InLoop: IdI → lato del contorno
local tbId_InLoop = {}
-- tabella contenente le tabelle delle curve composte del layer OnPath: IdI →
local tbId_OnPath = {}
-- tabella contenente le tabelle dei lati del layer Pocket: IdI →
local tbId_Pocket = {}
-- tabella contenente la tabella delle curve composte del layer FiloTop: IdI →
local tbId_FiloTop = {}
-- Id del solido generato
local IdEnt_Part = -1
-- Id del solido da sottrarre
local IdEnt_SubPart = -1
-- Id della facce come Flat Region
local tbId_Faces = {}
-- Spessore grezzo (Ddefault)
local RTh = 30
local bAlwaysOnTop = true
--local nIdTrimOut = -1
--local nIdTrimIn = -1
local tbTrimTot = {}
-- Estensioni delle regioni di taglio per SideAngle
--NB: lo spessore dei pezzi è limitato a 100(o meno, se ci sono dei sideAng), quindi per spessori importanti bisognerebbe modificare il valore di questa dimensione
local DefaultDim = 100
-- valore di tolleranza minimo per estrarre i contorni da una regione
local TollY = 1
local m_bArc = false
----------------------------------------------------------------------------
-- **Preparo ambiente** Part+Layer
----------------------------------------------------------------------------
-- Reimposto a vuoto il valore delle tabelle, resetto gli Id
local function ResetAllTabAndVar()
tbId_RectSurf = {}
-- tabella contenente i lati del layer OutLoop: IdS → lato del contorno
tbId_OutLoop = {}
-- tabella contenente i lati del layer InLoop: IdI → lato del contorno
tbId_InLoop = {}
-- tabella delle superfici laterali ( facce adiacenti già mergiate in un'unica superficie), la prima è quella out, le successive sono quelle in
tbId_SurfLat = {}
-- tabella contenente le curve composte del layer OnPath: IdI →
tbId_OnPath = {}
-- tabella contenente i lati del layer Pocket: IdI →
tbId_Pocket = {}
-- tabella contenente le curve composte del layer FiloTop: IdI →
tbId_FiloTop = {}
-- Id del solido generato
IdEnt_Part = -1
-- Id del solido da sottrarre
IdEnt_SubPart = -1
-- -- Id della superficie interna del solido
-- nIdTrimIn = -1
-- -- Id dalla superficie esterna del solido
-- nIdTrimOut = -1
-- tabella delle superfici per costruire il solido
tbTrimTot = {}
-- tabella delle superfici laterali
tbId_SurfLat = {}
-- Id della facce come Flat Region
tbId_Faces = {}
m_bArc = false
end
-- Elimino il layer solid del Part selezionato
local function ClearCurrIdSOLID()
IdP_SOLID = EgtGetFirstPart()
while IdP_SOLID do
local IdP_SOLID_Next = EgtGetNext( IdP_SOLID)
local nIdParent = EgtGetInfo(IdP_SOLID, "Parent", 'i')
if EgtGetName( IdP_SOLID) == "SOLID" and nIdParent ~= nil and IdFP == nIdParent then
EgtErase( IdP_SOLID)
break
end
IdP_SOLID = IdP_SOLID_Next
end
end
--
--[[
Creazione di un nuovo Part: IdP_SOLID → part "SOLID"
IdL_Temp → Layer di destinazione delle superfici di taglio
IdL_Solid → Layer di destinazione del solido
IdL_Bound → Layer di destinazione delle linee di contorno del solido
]]--
local function CreatePartSOLID()
ResetAllTabAndVar()
IdP_SOLID = EgtGroup(GDB_ID.ROOT,GDB_RT.LOC)
EgtSetName( IdP_SOLID, "SOLID")
EgtSetInfo(IdP_SOLID, "Parent", IdFP)
EgtSetInfo(IdFP, "Child", IdP_SOLID)
EgtSetInfo( IdP_SOLID, "Th", RTh)
IdL_Temp = EgtGroup(IdP_SOLID,GDB_RT.LOC)
EgtSetName( IdL_Temp, "Temp")
IdL_Solid = EgtGroup(IdP_SOLID,GDB_RT.LOC)
EgtSetName( IdL_Solid, "Surface")
IdL_Bound = EgtGroup(IdP_SOLID,GDB_RT.LOC)
EgtSetName( IdL_Bound, "Boundary")
IdL_Faces = EgtGroup(IdP_SOLID,GDB_RT.LOC)
EgtSetName( IdL_Faces, "Faces")
end
--
----------------------------------------------------------------------------
-- **Recupero info dei pezzi** SideAng:Ang, Heel; FiloTop:Depth
----------------------------------------------------------------------------
-- restituisce le info sui lati inclinati
local function GetAngHill( nInd)
if nInd then
local A = EgtGetInfo( nInd, 'OrigSideAng', 'd')
local H = EgtGetInfo( nInd, 'Heel', 'd')
if A and H then
return A, H
elseif A and not H then
return A, 0
end
end
return 0,0
end
--
-- restituisce l'affondamento del profilo FiloTop
local function GetDepth( nInd)
if nInd then
local D = EgtGetInfo( nInd, 'Depth', 'd')
if D then
return D
end
end
return 0
end
--
-- restituisce l'affondamento del profilo FiloTop
local function GetDepthOnPath( nInd)
if nInd then
D = EgtGetInfo( nInd, 'Depth', 'd')
if not D then
D = EgtGetInfo( nInd, 'Th', 'd')
end
if D then
return D
end
end
return 5
end
--
-- restituisce il valore dell'angolo successivo (se <0 angolo concavo)
local function GetnNextAng( nInd)
local A = EgtGetInfo( nInd, 'NextAng', 'd')
if not A then
SLD.ERR = 2
SLD.MSG = 'Non è presente NAng, probabilmente non ci sono le info di machining sugli edge'
end
return A
end
--
-- restituisce il valore dell'angolo precedente (se <0 angolo concavo)
local function GetnPrevAng( nInd)
local A = EgtGetInfo( nInd, 'PrevAng', 'd')
return A
end
--
----------------------------------------------------------------------------
-- **Carico tabelle** IdL_OutLoop, IdL_InLoop, tbId_OnPath, tbId_Pocket, tbId_FiloTop
----------------------------------------------------------------------------
-- riceve la tablella e il nome del Layer, riempie la tabella e restituisce l'ID del layer
local function GetIdFromLay( myTab, sLay)
RTh = SLD.THICK
--IdFP = EgtGetFirstPart()
local IdLay = EgtGetFirstNameInGroup( IdFP, sLay)
local tbIdLayTemp = {}
-- salvo l'id solo del primo layer con nome sLay
local IdFirstLay = IdLay
-- questo while su IdLay serve se ho più gruppi con questo nome
while IdLay do
local IdS = EgtGetFirstInGroup( IdLay)
while IdS do
if EgtGetType( IdS) == GDB_TY.CRV_LINE or EgtGetType( IdS) == GDB_TY.CRV_ARC or EgtGetType( IdS) == GDB_TY.CRV_COMPO then
if sLay == 'OutLoop' then
table.insert( myTab, IdS)
elseif sLay == 'InLoop' or sLay == 'Pocket' or sLay == 'FiloTop' or sLay == 'OnPath' then
table.insert( tbIdLayTemp, IdS)
end
end
IdS = EgtGetNext( IdS)
end
if sLay == 'InLoop' or sLay == 'Pocket' or sLay == 'FiloTop' or sLay == 'OnPath' then
table.insert( myTab, tbIdLayTemp)
tbIdLayTemp = {}
end
IdLay = EgtGetNextName( IdLay, sLay)
end
return IdFirstLay
end
--
----------------------------------------------------------------------------
-- **Solido di riferimento** IdEnt_Part
----------------------------------------------------------------------------
-- dato il contorno del pezzo
local function CreateSolid()
local nLoopOut, nCountOut = EgtExtractSurfTmLoops( tbId_SurfLat[1], IdL_Bound)
local tbLoop1 ={nLoopOut}
local tbLoop2 ={nLoopOut + 1}
--local ptSBottom = EgtSP( nLoopOut + 1)
local nLoopIn = -1
local nCountIn = 0
if #tbId_SurfLat > 1 then
for k = 2, #tbId_SurfLat, 1 do
nLoopIn, nCountIn = EgtExtractSurfTmLoops( tbId_SurfLat[k], IdL_Bound)
for p=0, nCountIn - 1, 1 do
if math.abs(EgtSP( nLoopIn + p):getZ() - EgtSP( nLoopOut):getZ()) < 0.01 then
table.insert(tbLoop1, nLoopIn + p)
else --math.abs(EgtSP( nLoopIn + p):getZ() - EgtSP( nLoopOut + 1):getZ()) < EPS_SMALL then
table.insert(tbLoop2, nLoopIn + p)
end
end
end
end
-- creo le SurfTm delle facce sopra e sotto
local nIdSurf1 = EgtSurfTmByRegion( IdL_Solid, tbLoop1)
local nIdSurf2 = EgtSurfTmByRegion( IdL_Solid, tbLoop2)
for i = 1, #tbLoop1, 1 do
EgtErase( tbLoop1[i])
end
for i = 1, #tbLoop2, 1 do
EgtErase( tbLoop2[i])
end
EgtInvertSurf( {nIdSurf1, nIdSurf2})
tbTrimTot = {nIdSurf1, nIdSurf2}
for k = 1, #tbId_SurfLat, 1 do
table.insert( tbTrimTot, tbId_SurfLat[k])
end
local nIdTrimTot = EgtSurfTmByTriangles( IdL_Solid, tbTrimTot, false)
EgtSetColor( nIdTrimTot, ColorSTD)
EgtErase( tbTrimTot)
tbTrimTot = {nIdTrimTot}
IdEnt_Part = nIdTrimTot
SLD.CurrPartSolid = IdP_SOLID
SLD.CurrSrfTmId = nIdTrimTot
--scrivo l'info dello spessore nel part
EgtSetInfo(IdFP, "Th", EgtNumToString(SLD.THICK))
end
--
----------------------------------------------------------------------------
-- **Pocket**
----------------------------------------------------------------------------
local function PocketSolid()
-- se sono presenti dei ribassi provvedo a disegnarli
if #tbId_Pocket > 0 then
for i = 1, #tbId_Pocket do
local IdCompo_Pocket, nCrv = EgtCurveCompoByChain( IdL_Solid, tbId_Pocket[i], EgtSP( tbId_Pocket[i][1]), false)
local IdEnt_Pocket = EgtSurfTmByRegionExtrusion( IdL_Solid, {IdCompo_Pocket}, Z_AX()*(2* RTh))
EgtSurfTmSubtract( IdEnt_Part, IdEnt_Pocket)
EgtErase( {IdEnt_Pocket})
EgtErase( {IdCompo_Pocket})
local a = 0
end
end
end
----------------------------------------------------------------------------
-- **OnPath**
----------------------------------------------------------------------------
local function Engraves( nId)
-- se non restituisce nulla allora utlizzo direttamente la copia
local vtExtr
local vtO
nNbr = 1
vtO = EgtSV( nId)
vtExtr = Vector3d( vtO[3]/vtO[1], 0, 1)
vtExtr:normalize()
local D = 10
EgtMove( {nId}, vtExtr*(D))
if D > 0 or not vt then
local nEntCopy_1 = EgtCopy( nId, IdL_Temp)
local nEntCopy_2 = EgtCopy( nId, IdL_Temp)
EgtMove( {nEntCopy_2}, vtExtr*(- D))
local nLine_1 = EgtLine( IdL_Temp, EgtSP( nEntCopy_1, GDB_ID.ROOT ), EgtSP( nEntCopy_2, GDB_ID.ROOT ))
local nLine_2 = EgtLine( IdL_Temp, EgtEP( nEntCopy_1, GDB_ID.ROOT ), EgtEP( nEntCopy_2, GDB_ID.ROOT ))
local nCompo = EgtCurveCompoByChain( IdL_Solid, {nEntCopy_1,nLine_1,nEntCopy_2,nLine_2}, EgtSP( nLine_1), false)
vtExtr:rotate( vtO, 90)
local IdSubSolid = EgtSurfTmByRegionExtrusion( IdL_Solid, {nCompo}, vtExtr*(2))
EgtSurfTmSubtract( IdEnt_Part, IdSubSolid)
EgtErase( {nEntCopy_1,nLine_1,nEntCopy_2,nLine_2, nCompo, IdSubSolid, nId})
end
end
--
-- genero i tagli singoli
local function OnPathSolid()
for i=1, #tbId_OnPath, 1 do
for j=1, #tbId_OnPath[i], 1 do
local nInd = tbId_OnPath[i][j]
local D = GetDepthOnPath( nInd)
if D > RTh then
SLD.ERR = 1
EgtSetColor( {IdEnt_Part}, ColocERR)
end
-- creo una copia nel Layer "Temp"
local nEntCopy = EgtCopy( nInd, IdL_Temp)
local nId, nNbr = EgtExplodeCurveCompo( nEntCopy)
-- definisco il vettore di spostamento verticale del solido da sottrarre
local vtV = Z_AX()
if nId ~= nil then
for j=0 , nNbr-1, 1 do
local nTempId = nId + j
local vt = EgtSV( nTempId)
vt:rotate(vtV, 90)
if D > 0 or not vt then
local nEntCopy_1 = EgtCopy( nTempId, IdL_Temp)
local nEntCopy_2 = EgtCopy( nTempId, IdL_Temp)
EgtMove( {nEntCopy_2}, vtV*(- D))
local nLine_1 = EgtLine( IdL_Temp, EgtSP( nEntCopy_1, GDB_ID.ROOT ), EgtSP( nEntCopy_2, GDB_ID.ROOT ))
local nLine_2 = EgtLine( IdL_Temp, EgtEP( nEntCopy_1, GDB_ID.ROOT ), EgtEP( nEntCopy_2, GDB_ID.ROOT ))
local nCompo = EgtCurveCompoByChain( IdL_Solid, {nEntCopy_1,nLine_1,nEntCopy_2,nLine_2}, EgtSP( nLine_1), false)
local IdSubSolid = EgtSurfTmByRegionExtrusion( IdL_Solid, {nCompo}, vt*(2))
EgtSurfTmSubtract( IdEnt_Part, IdSubSolid)
EgtErase( {nEntCopy_1,nLine_1,nEntCopy_2,nLine_2, nCompo, IdSubSolid, nTempId})
end
end
else
Engraves( nEntCopy)
end
end
end
end
--
----------------------------------------------------------------------------
-- **Filo Top**
----------------------------------------------------------------------------
-- sottraggo al solido il contorno FiloTop
local function FiloTopSolid()
local nLay = EgtGetFirstNameInGroup( IdFP, "FiloTop")
for i = 1, #tbId_FiloTop do
local D = GetDepth( nLay)
if D < 0.1 then
return
end
local IdEnt_SurfFiloTop = EgtSurfTmByRegionExtrusion( IdL_Solid, tbId_FiloTop[i], Z_AX()*(- D -1))
EgtMove( {IdEnt_SurfFiloTop}, Z_AX()*1)
EgtSurfTmSubtract( IdEnt_Part, IdEnt_SurfFiloTop)
EgtErase( {IdEnt_SurfFiloTop})
nLay = EgtGetNextName( nLay, "FiloTop")
end
end
--
----------------------------------------------------------------------------
-- HillPlane D
----------------------------------------------------------------------------
local function PlaneShift( nId, Hill)
if bAlwaysOnTop then
Hill = Hill * (-1)
end
local vtTrasl = Z_AX() * Hill
EgtMove( nId, vtTrasl)
end
--
----------------------------------------------------------------------------
-- HillPlane C
----------------------------------------------------------------------------
local function PlaneNoShift( nId)
PlaneShift( nId, 0)
end
--
----------------------------------------------------------------------------
-- HillPlane A
----------------------------------------------------------------------------
local function HillPlaneAng( nId, ptS, vtS, Ang, Hill)
local nIdHill = EgtCopy( nId, IdL_Solid)
EgtRotate( nIdHill, ptS, vtS, Ang, GDB_ID.ROOT)
local dTrasl
if bAlwaysOnTop then
if Ang > 0 then
dTrasl = ( RTh - Hill) * math.tan( Ang * math.pi / 180)
else
dTrasl = 0
end
else
if Ang > 0 then
dTrasl = 0
else
dTrasl = ( RTh - Hill) * math.tan( -Ang * math.pi / 180)
end
end
local vtTrasl = ( vtS ^ Z_AX()) * dTrasl
EgtMove( nIdHill, vtTrasl)
if bAlwaysOnTop then
if Ang < 0 then
PlaneShift( nId, Hill)
end
else
if Ang > 0 then
PlaneShift( nId, Hill)
end
end
local pt_a, vn_a = EgtSurfTmFacetCenter( nId, 0)
local pt_h, vn_h = EgtSurfTmFacetCenter( nIdHill, 0)
EgtCutSurfTmPlane( nIdHill, pt_a, vn_a, false)
EgtCutSurfTmPlane( nId, pt_h, vn_h, false)
PlaneNoShift( nId)
return nIdHill, vtTrasl
end
--
------------------------------------------------------------------------------
---- HillPlane B
------------------------------------------------------------------------------
--local function HillPlaneNegAng( nId, ptS, vtS, Ang, Hill)
-- local nIdHill, vtTrasl = HillPlanePosAng( nId, ptS, vtS, Ang, Hill, true)
-- return nIdHill, vtTrasl
--end
----
----------------------------------------------------------------------------
-- **Side Ang**
----------------------------------------------------------------------------
local function SideAngSolid( tbLoop, bInLoop)
local tbIdR = {}
local IdS
local Ang = 0
local Hill = 0
local NAng = 0
m_bArc = false
local tbArc = {}
local tbLimited = {}
for i=1, #tbLoop, 1 do
IdS = tbLoop[i]
-- recupero i dati SideAng per ogni lato
Ang, Hill = GetAngHill( IdS)
NAng = GetnNextAng( IdS)
if math.abs(NAng) <= 2 then NAng = 0 end
-- verifico che il lato presenti un angolo inclinato
if EgtGetType( IdS) == GDB_TY.CRV_ARC then
m_bArc = true
table.insert(tbArc, true)
local ptStart = EgtSP(IdS, GDB_ID.ROOT)
local vtStart = EgtSV( IdS, GDB_ID.ROOT)
local vtEnd = EgtEV( IdS, GDB_ID.ROOT)
if Ang == 0 then
local vtExtr = Z_AX() * RTh
if bAlwaysOnTop then
vtExtr = vtExtr * (-1)
end
local nSurfId = EgtSurfTmByExtrusion(IdL_Solid, IdS, vtExtr)
if bAlwaysOnTop then
EgtInvertSurf( nSurfId)
end
local tbInfoRot = { nSurfId, ptStart, vtStart, Ang, Hill, NAng, vtEnd}
table.insert(tbIdR,tbInfoRot)
table.insert(tbLimited, false)
else
-- costruisco la superficie laterale generata dall'arco con una swept lungo l'arco stesso
-- la sezione di cui effetturare lo sweep viene creata trovando il punto di partenza del secondo arco che delimita questa superficie
local dLatMove = RTh * math.tan( math.abs(Ang) * pi / 180)
local vtLatMove = (Z_AX() ^ vtStart)
local vtVertMove = Z_AX() * RTh
if not bInLoop then vtLatMove = vtLatMove * (-1) end
-- devo controllare se il side ang e lo spessore della lastra sono abbastanza da far collassare l'arco in un punto ed eventualmente andare oltre
-- verifico quindi se devo limitare la superficie della sezione di cono
local dRad = EgtArcRadius( IdS)
local bLimited = false
local dArcAng = EgtArcAngCenter( IdS)
local bCheckLimit = (dArcAng > 0 and Ang < 0 ) or ( dArcAng < 0 and Ang > 0)
if bCheckLimit then
if dRad < math.abs(dLatMove) + 0.01 then
vtLatMove = vtLatMove * dRad
vtVertMove = Z_AX() * dRad / math.tan( math.abs(Ang) * pi / 180)
bLimited = true
end
else
vtLatMove = vtLatMove * dLatMove
end
table.insert(tbLimited, bLimited)
if (Ang > 0 and bAlwaysOnTop) or ( Ang < 0 and not bAlwaysOnTop) then
vtLatMove = vtLatMove * ( -1)
end
if bAlwaysOnTop then
vtVertMove = vtVertMove * (-1)
end
local ptSecondArcStart = ptStart + ( vtVertMove + vtLatMove)
local nIdLine = EgtLine(IdL_Temp,ptStart,ptSecondArcStart,GDB_ID.ROOT)
local nPointId = EgtPoint( IdL_Temp, ptSecondArcStart)
local nSurfId = 0
if not bLimited then
nSurfId = EgtSurfTmSwept(IdL_Solid,nIdLine,IdS,Z_AX(),false,0.01,GDB_ID.ROOT)
EgtInvertSurf( nSurfId)
else
local vtAx = Z_AX()
if not bAlwaysOnTop then
vtAx = vtAx * (-1)
end
nSurfId = EgtSurfTmRuled( IdL_Solid, nPointId, IdS)
EgtInvertSurf( nSurfId)
-- nSurfId = EgtSurfTmCone(IdL_Solid,ptSecondArcStart, vtAx, dRad, RTh)
end
EgtErase( nIdLine)
EgtErase( nPointId)
local tbInfoRot = { nSurfId, ptStart, vtStart, Ang, Hill, NAng, vtEnd}
table.insert(tbIdR,tbInfoRot)
end
elseif EgtGetType( IdS) ~= GDB_TY.CRV_COMPO then
table.insert(tbArc, false)
local ptS = EgtSP( IdS, GDB_ID.ROOT)
local vtS = EgtSV( IdS, GDB_ID.ROOT)
local vtE = EgtEV( IdS, GDB_ID.ROOT)
local IdRect = EgtCurveGetFatCurve( IdS, IdL_Temp, DefaultDim, true)
local IdSurf = EgtSurfTmByRegion( IdL_Solid, IdRect)
EgtErase( IdRect)
local tbInfoRot = { IdSurf, ptS, vtS, Ang, Hill, NAng, vtE}
table.insert( tbIdR, tbInfoRot)
table.insert(tbLimited, false)
end
end
-- posiziono i piani calcolati in precedenza e creo i piani di Hill
for i=1, #tbIdR, 1 do
local dTempAng = 90
if not tbArc[i] then
EgtRotate( tbIdR[i][1], tbIdR[i][2], tbIdR[i][3], -tbIdR[i][4] + dTempAng, GDB_ID.ROOT)
end
-- se ho l'hill lo creo e lo aggiungo alle caratteristiche della faccia
if tbIdR[i][4] ~= 0 and tbIdR[i][5] > 0 then
if not tbArc[i] then
local nIdHill
nIdHill, tbIdR[i][8] = HillPlaneAng( tbIdR[i][1], tbIdR[i][2], tbIdR[i][3], tbIdR[i][4], tbIdR[i][5])
-- aggiungo l'hill come elemento separato della faccia di taglio
tbIdR[i][9] = { nIdHill, tbIdR[i][2] + tbIdR[i][8], tbIdR[i][3], tbIdR[i][4], tbIdR[i][5], tbIdR[i][6], tbIdR[i][8]}
else
--- hill da gestire per il caso del lato che è un arco
end
else
tbIdR[i][8] = Vector3d({0,0,0})
end
end
-- **NANG** corrego la dimenione dei piani in funzione dell'angolo che descrivono con il pezzo successivo
for i=1, #tbIdR, 1 do
local Ind_Curr = i
local Ind_Nex = i + 1
if i == #tbIdR then
Ind_Nex = 1
end
-- se ho solo una faccia laterale termino ( è un foro descritto da un unico loop circolare)
if Ind_Curr == Ind_Nex then break end
local pt_n, vn_n = EgtSurfTmFacetCenter( tbIdR[Ind_Nex][1], 0)
local pt_c, vn_c = EgtSurfTmFacetCenter( tbIdR[Ind_Curr][1], 0)
if tbArc[Ind_Nex] then
pt_n = tbIdR[Ind_Nex][2] -- prendo startPoint
vn_n = tbIdR[Ind_Nex][3] -- prendo vtStart
if math.abs( tbIdR[Ind_Curr][6]) > 90 then
vn_n = vn_n * (-1)
elseif math.abs( tbIdR[Ind_Curr][6]) > 90 then
vn_n = EgtEV( tbLoop[Ind_Curr], GDB_ID.ROOT) -- prendo l'end del segmento precedente all'arco
end
end
if tbArc[Ind_Curr] then
pt_c = EgtEP( tbLoop[Ind_Curr], GDB_ID.ROOT) -- prendo endPoint
vn_c = tbIdR[Ind_Curr][7] -- prendo vtEnd
if math.abs( tbIdR[Ind_Curr][6]) < 90 then
vn_c = vn_c * (-1)
elseif math.abs( tbIdR[Ind_Curr][6]) > 90 then
vn_c = tbIdR[Ind_Nex][3] -- prendo lo start del segmento successivo all'arco
end
end
if (not tbArc[Ind_Nex]) and (not tbArc[Ind_Curr]) then
if ( tbIdR[Ind_Curr][6] < 0) then
vn_n = vn_n * (-1)
vn_c = vn_c * (-1)
end
end
-- devo tagliare le superfici di taglio con le superfici di taglio
-- gli archi li taglio usando i suoi vettori a inizio e fine curva
if tbArc[Ind_Curr] then
EgtCutSurfTmPlane( tbIdR[Ind_Curr][1], tbIdR[Ind_Curr][2], - tbIdR[Ind_Curr][3], false)
EgtCutSurfTmPlane( tbIdR[Ind_Curr][1], EgtEP(tbLoop[Ind_Curr], GDB_ID.ROOT), tbIdR[Ind_Curr][7], false)
else
EgtCutSurfTmPlane( tbIdR[Ind_Curr][1], pt_n, vn_n, false)
end
if not tbArc[Ind_Nex] then
EgtCutSurfTmPlane( tbIdR[Ind_Nex][1], pt_c, vn_c, false)
end
-- nel caso in cui la superficie generata dall'arco è limitata devo tagliare tra loro anche le superfici precedente e successiva all'arco--------------------------------------------------
if tbLimited[Ind_Curr] then
local Ind_Pre = Ind_Curr > 1 and (Ind_Curr - 1) or #tbLoop
local pt_p, vn_p = EgtSurfTmFacetCenter( tbIdR[Ind_Pre][1], 0)
pt_n, vn_n = EgtSurfTmFacetCenter( tbIdR[Ind_Nex][1], 0)
-- calcolo l'angolo tra le due facce
local dArcAng = EgtArcAngCenter( tbLoop[Ind_Curr])
local dAngSkip = tbIdR[Ind_Pre][6] + tbIdR[Ind_Nex][6] + dArcAng
if dAngSkip < 0 then
vn_p = vn_p * (-1)
vn_n = vn_n * (-1)
end
EgtCutSurfTmPlane( tbIdR[Ind_Pre][1], pt_n, vn_n, false)
EgtCutSurfTmPlane( tbIdR[Ind_Nex][1], pt_p, vn_p, false)
end
--taglio i piani dei talloni con i piani dei talloni ( se non ho un altro tallone allora taglio con la sup di taglio)
local pt_nH, vn_nH
local pt_cH, vn_cH
if tbIdR[Ind_Curr][5] > 0 then
pt_cH, vn_cH = EgtSurfTmFacetCenter( tbIdR[Ind_Curr][9][1], 0)
if ( tbIdR[Ind_Curr][6] < 0) then
vn_cH = vn_cH * (-1)
end
end
if tbIdR[Ind_Nex][5] > 0 then
pt_nH, vn_nH = EgtSurfTmFacetCenter( tbIdR[Ind_Nex][9][1], 0)
if ( tbIdR[Ind_Curr][6] < 0) then
vn_nH = vn_nH * (-1)
end
if tbIdR[Ind_Curr][5] > 0 then
EgtCutSurfTmPlane( tbIdR[Ind_Curr][9][1], tbIdR[Ind_Nex][9][2], vn_nH, false)
EgtCutSurfTmPlane( tbIdR[Ind_Nex][9][1], tbIdR[Ind_Curr][9][2], vn_cH, false)
-- se l'angolo con il prossimo lato è positivo, entrambi hanno un hill e gli Ang sono discordi, allora devo anche tagliare gli hill con i piani di taglio e viceversa
--if tbIdR[Ind_Curr][6] > 0 and tbIdR[Ind_Curr][4] * tbIdR[Ind_Nex][4] < 0 then
if tbIdR[Ind_Curr][6] > 0 then -- ho tolto la condizione che gli angoli debbano essere discordi!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
EgtCutSurfTmPlane( tbIdR[Ind_Nex][9][1], pt_c, vn_c, false)
EgtCutSurfTmPlane( tbIdR[Ind_Curr][9][1], pt_n, vn_n, false)
EgtCutSurfTmPlane( tbIdR[Ind_Curr][1], tbIdR[Ind_Nex][9][2], vn_nH, false)
EgtCutSurfTmPlane( tbIdR[Ind_Nex][1], tbIdR[Ind_Curr][9][2], vn_cH, false)
end
else
EgtCutSurfTmPlane( tbIdR[Ind_Nex][9][1], pt_c, vn_c, false)
EgtCutSurfTmPlane( tbIdR[Ind_Curr][1], tbIdR[Ind_Nex][9][2], vn_nH, false)
end
else
if tbIdR[Ind_Curr][5] > 0 then
EgtCutSurfTmPlane( tbIdR[Ind_Curr][9][1], pt_n, vn_n, false)
EgtCutSurfTmPlane( tbIdR[Ind_Nex][1], tbIdR[Ind_Curr][9][2], vn_cH, false)
end
end
end
-- unisco tutte le superfici laterali
local tbIdTrim = {}
for i=1, #tbIdR, 1 do
if tbIdR[i][1] > -1 then
table.insert( tbIdTrim, tbIdR[i][1])
if tbIdR[i][5] > 0 then
table.insert( tbIdTrim, tbIdR[i][9][1])
end
end
end
if #tbIdR > 0 then
local nIdTrim = EgtSurfTmByTriangles( IdL_Solid, tbIdTrim, true)
table.insert( tbId_SurfLat, nIdTrim)
-- le trimmo con la superficie superiore e con quella inferiore
local ptOrig_t
local ptOrig_b
if bAlwaysOnTop then
ptOrig_t = tbIdR[1][2]
ptOrig_b = ptOrig_t + Point3d({0,0,-RTh})
else
ptOrig_b = tbIdR[1][2]
ptOrig_t = ptOrig_b + Point3d({0,0,RTh})
end
EgtCutSurfTmPlane( nIdTrim, ptOrig_b, {0,0,-1}, false, GDB_RT.GLOB)
EgtCutSurfTmPlane( nIdTrim, ptOrig_t, {0,0,1}, false, GDB_RT.GLOB)
end
end
--
function SLD.CorrectReference(IdPart)
if not IdPart then IdPart = SLD.CurrId end
local sName = EgtGetName( IdPart)
if sName ~= "SOLID" then
local nLayRef = EgtGetFirstNameInGroup( IdPart, "Ref")
local nRef = EgtGetFirstInGroup(nLayRef)
while nRef do
-- controllo se l'offset ai riferimenti è già stato eseguito
local bDone = EgtGetInfo(nRef, 'OffsetDone')
if not bDone then
local var = EgtGetInfo(nRef, "Var")
if var == "Th" then
var = RTh
else
var = EgtGetInfo(nRef, "Var", "i")
end
local dir = EgtGetInfo(nRef, "Dir")
if dir then
local tbDir = EgtSplitString(dir,",")
local vtDir = {}
for _,sDir in pairs(tbDir) do
sDir = sDir:gsub("x", EgtNumToString(var))
table.insert(vtDir, EgtEvalNumExpr(sDir))
end
vtDir = Vector3d(vtDir)
EgtMove(nRef,vtDir, GDB_RT.LOC)
end
-- setto l'info che certifica che l'offset è stato eseguito
EgtSetInfo(nRef, 'OffsetDone', true)
end
nRef = EgtGetNext(nRef)
end
end
end
local function GetThickness()
local val = EgtGetInfo( IdFP,"Th","d")
if val then
SLD.THICK = val
end
end
----------------------------------------------------------------------------
-- **Wire Frame**
----------------------------------------------------------------------------
local function ExplodSurf( nId)
local IdFac, Nbr = EgtExplodeSurf(nId)
local i = 0
while IdFac and Nbr > 1 and i < Nbr do
ExplodSurf( IdFac)
IdFac = IdFac + 1
i = i+1
end
return IdFac, Nbr
end
--
-- estraggo il contorno delle superfici del solido
local function ExtractBoundaryAndFaces()
local nSurfCopy = EgtCopy( tbTrimTot[1], IdL_Temp)
local IdFac, Nbr = ExplodSurf( nSurfCopy)
local IdS = EgtGetFirstInGroup( IdL_Temp)
local nCount = 0
while IdS ~= nil do
------------------------ gestione archi
-- local tabMergSurf = {}
-- local _, dX, dY = EgtSurfTmFacetMinAreaRectangle( IdS, 0)
-- if dY~=nil and dY > TollY then
-- local TempIdSmall = EgtExtractSurfTmFacetLoops( IdS, 0, IdL_Bound)
-- else
-- table.insert( tabMergSurf, IdS)
-- end
-- EgtSurfTmByTriangles( IdL_Temp, tabMergSurf)
-- EgtErase( tabMergSurf)
-- IdS = EgtGetNext( IdS)
------------------------ gestione archi
----------- gestione archi che non vengono esplosi----------------
nCount = nCount + 1
local bExplode = false
----------- gestione archi che non vengono esplosi----------------
---
local nLoop, nLoopCount = EgtExtractSurfTmFacetLoops( IdS, 0, IdL_Bound)
local ColorApply = 'BLACK'
local tbLoopFlatRegion = {}
for l=nLoop, nLoop + (nLoopCount-1), 1 do
-- coloro il loop e lo aggiungo alla tabella per ricreare la flat region
EgtSetColor( l, ColorApply)
table.insert(tbLoopFlatRegion, l)
end
-- ricreo la faccia laterale come flat region e la metto con trasparenza massima
local nIdFace = EgtSurfFlatRegion( IdL_Faces, tbLoopFlatRegion)
EgtSetAlpha(nIdFace,1)
table.insert( tbId_Faces, nIdFace)
for l=nLoop, nLoop + (nLoopCount-1), 1 do
-- esplodo i loop
EgtExplodeCurveCompo( l)
end
local nIdCurr = IdS
IdS = EgtGetNext( IdS)
-- cancello la superficie
EgtErase( nIdCurr)
end
-- cancello le linee doppie sugli edge
local IdL = EgtGetFirstInGroup(IdL_Bound)
while IdL ~= nil do
local ptStart = EgtSP( IdL)
local ptEnd = EgtEP( IdL)
IdL_b = EgtGetFirstInGroup(IdL_Bound)
while IdL_b ~= nil do
local ptStart_b = EgtSP( IdL_b)
local ptEnd_b = EgtEP( IdL_b)
if IdL_b ~= IdL and
(AreSamePointApprox(ptStart, ptStart_b) and AreSamePointApprox(ptEnd, ptEnd_b)) or
(AreSamePointApprox(ptStart, ptEnd_b) and AreSamePointApprox(ptEnd, ptStart_b)) then
local IdL_bNext = IdL_b
EgtErase( IdL_b)
IdL_b = EgtGetNext( IdL_bNext)
else
IdL_b = EgtGetNext( IdL_b)
end
end
IdL = EgtGetNext( IdL)
end
end
--
----------------------------------------------------------------------------
-- |ESEGUO FUNZIONI|
----------------------------------------------------------------------------
-- funzione che si occupa di creare il solido finale
local function Draw(bPreview)
CreatePartSOLID()
-- SOLID
IdL_OutLoop = GetIdFromLay( tbId_OutLoop, 'OutLoop')
IdL_InLoop = GetIdFromLay( tbId_InLoop, 'InLoop')
IdL_OnPath = GetIdFromLay( tbId_OnPath, 'OnPath')
IdL_Pocket = GetIdFromLay( tbId_Pocket, 'Pocket')
IdL_FiloTop = GetIdFromLay( tbId_FiloTop, 'FiloTop')
-- SIDEANG
SideAngSolid( tbId_OutLoop, false)
for i = 1, #tbId_InLoop, 1 do
SideAngSolid( tbId_InLoop[i], true)
end
CreateSolid()
---- POCKET
PocketSolid()
---- FILO TOP
FiloTopSolid()
-- -- ONPATH
OnPathSolid()
-- WIREFRAME
---- Correzione dei riferimenti
SLD.CorrectReference(IdFP)
ExtractBoundaryAndFaces()
end
--
--per uso nell' |omagOFFICE| ( bAutoRun deve essere settato a false)
function SLD.Main()
IdFP = SLD.CurrId
ClearCurrIdSOLID()
if IdFP == -1 then
SLD.ERR = 1
return
end
RTh = SLD.THICK
if RTh == 0 then
return
end
GetThickness()
Draw( true)
EgtSetStatus( IdFP, GDB_ST.OFF)
--EgtDraw()
SLD.ERR = 0
end
--per uso nell' |omagOFFICE|
--per uso nel |CAM5| (bAutoRun da settare a true)
--bAutoRun = true
if bAutoRun then
ClearCurrIdSOLID()
RTh = SLD.THICK
IdFP = EgtGetFirstPart()
local sName = ""
--IdFP = 204
while IdFP ~= nil and sName ~= "SOLID" do
-- procedo a costruire il solido solo se sono in un part con un OutLoop
local nLay = EgtGetFirstNameInGroup(IdFP, "OutLoop")
if nLay then
GetThickness()
Draw( true)
EgtSetStatus( IdFP, GDB_ST.OFF)
end
IdFP = EgtGetNextPart(IdFP)
sName = EgtGetName(IdFP)
--break
end
--EgtSaveFile('c:\\EgtData\\OmagOFFICE\\Temp\\buche_sottili_SOLID.nge')
--EgtDraw()
--SLD.ERR = 0
end
-----per uso nel |CAM5|
--_G.SLD_Main = SLD_Main
+956
View File
@@ -0,0 +1,956 @@
--24/10/09 ASSEMBLER : File per gestire le operazioni su Part nel VeinMatch3D
-- creato da D.B.
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
-- mi preparo a ricevere argomenti
local arg =...
-- variabile globale
-- setto i valori standard nella tabella di comunicazione col programma
local ASS = {}
-- const da settare al caricamento del file
ASS.nMaxStory = 100 -- lunghezza massima della storia
ASS.bActiveHist = false -- flag che indica se attivare il salvataggio delle operazioni ( per poter usare undo e redo)
-- input
ASS.nPartId = GDB_ID.NULL -- part da accoppiare
ASS.nIdFirstLine = GDB_ID.NULL -- edge del part con cui eseguire l'accoppiamento
ASS.nIdSecondLine = GDB_ID.NULL -- edge di destinazione dell'accoppiamento
ASS.nIdAxs = GDB_ID.NULL -- asse con cui eseguire la rotazione( è una CRV_LINE)
ASS.dAng = 0 -- angolo per la rotazione
ASS.vtAx = V_NULL() -- asse di rotazione
ASS.ptAx = ORIG() -- punto per l'asse di rotazione
ASS.vtMove = V_NULL() -- vettore di traslazione
ASS.vtFirstNorm = V_NULL() -- normale della superficie del part da accoppiare
ASS.vtSecondNorm = V_NULL() -- normale di destinazione dell'accoppiamento
ASS.nVeinCtx = GDB_ID.NULL -- indice del contesto del VeinMatch3D
ASS.nOption = 0 -- intero che indica l'opzione di pairing scelta
ASS.nGroup = 0 -- intero che indica il numero del gruppo da aggiornare per il part nPartToPair
ASS.nPartToPair = GDB_ID.NULL -- id del part di cui si vogliono aggiornare le info di pairing
ASS.sPairList = "" -- lista di accoppiamento
ASS.bSaveHist = true -- flag che indica se salvare nella storia l'operazione eseguita
ASS.bSaveTemp = false -- flag che indica se salvare nella storia temporanea l'operazione eseguita
ASS.nTempToSave = GDB_ID.NULL -- posizione nel vettore temporaneo della trasformazione da salvare
ASS.nTypeTrf = GDB_ID.NULL -- tipo della trasformazione da aggiungere alla storia ( 0: traslazione; 1: rotazione; 2: accoppiamento/disaccoppiamento; 3: import)
ASS.nDoNTimes = 1 -- numero di volte per cui ripetere una certa operazione (per undo e redo)
-- output
ASS.ERR = 0 -- -1 : valori non settati o sbagliati, -2 : operazione impossibile(es: fuori dall'array), -3 : manca qualcosa nel database (info, pezzi, layer..)
ASS.nTransf = 0 -- numero di operazioni eseguite / numero di operazione nella tabella della storia, aggiornato dopo un Undo o un Redo
ASS.sFunc = "" -- funzione in cui è stato eseguito il return a seguito di un errore
ASS.bRedoPossible = false
-- variabili locali
local vPaired = {}
local ptPair = ORIG()
local GroupCounter = 1 -- ogni volta che viene usato va incrementato di 1
local nTernaId = GDB_ID.NULL
local ptOrigId = ORIG()
-- gestione della storia
-- tbEvent = { Id, vtDir, ptAx, dAngOrId, bWPaired, lPair} -- solo move e rotate possono essere effettuati su pezzi singoli, anche se accoppiati
-- se vtDir ~= da V_NULL allora ho una rotazione o traslazione ( distinte da dAngOrId ~= 0)
-- se vtDir == V_NULL e dAngOrId ~= 0 allora ho un accoppiamento o undo di un accoppiamento
-- se dAngOrId == 0 e #lPair ~= 0 allora ho un disaccoppiamento o accoppiamento di un singolo part da/a un accoppiato
-- se dAngOrId == 0 e #lPair == 0 allora ho un import
local Time = 0
local tbStory = {}
-- gestione della storia temporanea
local TempTime = 0
local tbTempStory = {}
-- leggo gli argomenti passati dalla chiamata del file
local bAutoRun = false
if arg then
ASS.nVeinCtx = arg.nVeinCtx
bAutoRun = arg.AutoRun
end
-- rendo la variabile globale
_G.ASS = ASS
function ResetASS()
-- input
ASS.nPartId = GDB_ID.NULL
ASS.nIdFirstLine = GDB_ID.NULL
ASS.nIdSecondLine = GDB_ID.NULL
ASS.nIdAxs = GDB_ID.NULL
ASS.dAng = 0
ASS.vtAx = V_NULL()
ASS.ptAx = ORIG()
ASS.vtMove = V_NULL()
ASS.vtFirstNorm = V_NULL()
ASS.vtSecondNorm = V_NULL()
ASS.nVeinCtx = GDB_ID.NULL
ASS.nOption = 0
ASS.nGroup = 0
ASS.nPartToPair = GDB_ID.NULL
ASS.sPairList = ""
ASS.nTempToSave = GDB_ID.NULL
ASS.nTypeTrf = GDB_ID.NULL
-- output
ASS.ERR = GDB_ID.NULL
ASS.nTransf = 0
end
local function FromStringToINTVECTOR( sIntVectorString)
local vInt = {}
local vsInt = EgtSplitString(sIntVectorString,",")
for sInt in vsInt do
table.insert( vInt, EgtEvalNumExpr(sInt))
end
return vInt
end
local function AddEvent( tbEvent)
if not tbEvent.Id then do return end end
-- se ho già raggiunto il massimo della storia salvabile allora elimino il primo elemento
if Time == ASS.nMaxStory then table.remove(tbStory,1) end
-- se ero avevo già fatto degli undo allora devo cancellare la storia che sto per sovrascrivere
if Time < #tbStory then
local nLastEvent = #tbStory
for nItTime = Time, nLastEvent, 1 do
table.remove(tbStory, Time + 1)
end
ASS.bRedoPossible = false
end
if Time < ASS.nMaxStory then Time = Time + 1 end
table.insert( tbStory, tbEvent)
return true
end
local function AddTempEvent( tbEvent)
-- se ho già raggiunto il massimo della storia salvabile allora elimino il primo elemento
if TempTime == ASS.nMaxStory then table.remove(tbTempStory,1) end
-- se ero avevo già fatto degli undo allora devo cancellare la storia che sto per sovrascrivere
if TempTime < #tbTempStory then
local nLastEvent = #tbTempStory
for nItTime = TempTime, nLastEvent, 1 do
table.remove(tbTempStory, TempTime + 1)
end
end
if TempTime < ASS.nMaxStory then TempTime = TempTime + 1 end
table.insert( tbTempStory, tbEvent)
end
function ASS.AddEvent()
ASS.sFunc = "ASS.AddEvent"
local tbEvent = {}
local a = tbEvent.nId
if ASS.nTypeTrf == 0 then -- traslazione
if ASS.nPartId == GDB_ID.NULL or AreSameVectorApprox(ASS.vtMove, V_NULL()) then
ASS.ERR = -1
return false
end
tbEvent = {Id = ASS.nPartId, vtDir = ASS.vtMove, ptAx = ORIG(), dAngOrId = 0, bWPaired = true, lPair = {}}
elseif ASS.nTypeTrf == 1 then -- rotazione
if ASS.nPartId == GDB_ID.NULL or AreSameVectorApprox(ASS.vtAx, V_NULL()) or ASS.dAng == nil then
ASS.ERR = -1
return false
end
tbEvent = {Id = ASS.nPartId, vtDir = ASS.vtAx, ptAx = ASS.ptAx, dAngOrId = ASS.dAng, bWPaired = true, lPair = {}}
elseif ASS.nTypeTrf == 2 then -- accoppiamento
if ASS.nPartId == GDB_ID.NULL or ASS.nPartToPair == GDB_ID.NULL then
ASS.ERR = -1
return false
end
tbEvent = {Id = ASS.nPartId, vtDir = V_NULL(), ptAx = ORIG(), dAngOrId = ASS.nPartToPair, bWPaired = true, lPair = FromStringToINTVECTOR(ASS.sPairList)}
elseif ASS.nTypeTrf == 3 then -- importazione oggetto
if ASS.nPartId == GDB_ID.NULL then
ASS.ERR = -1
return false
end
tbEvent = {Id = ASS.nPartId, vtDir = V_NULL(), ptAx = ORIG(), dAngOrId = 0, bWPaired = true, lPair = {}}
else
do return false end
end
local bOk = false
if AddEvent( tbEvent) then bOk = true end
ASS.nTransf = Time
return bOk
end
-- aggiunta di un singolo evento dalla storia temporanea(indice indicato da ASS.nTempToSave) a quella generale
function ASS.AddEventFromTemp()
ASS.sFunc = "AddEventFromTemp"
if abs(ASS.nTempToSave) > #tbTempStory then
ASS.ERR = -2
return false
end
-- nTempToSave indica l'indice dell'elemento del vettore temporaneo da salvare
-- con un valore negativo si intende contando a partire dal fondo del vettore
if ASS.nTempToSave < 0 then ASS.nTempToSave = #tbTempStory + 1 + ASS.nTempToSave end
AddEvent( tbTempStory[ASS.nTempToSave])
return true
end
-- aggiunta degli ultimi n eventi temporanei(ASS.nTempToSave) alla storia generale
function ASS.AddLastestEventsFromTemp()
ASS.sFunc = "AddTempEvents"
if abs(ASS.nTempToSave) > #tbTempStory then
ASS.ERR = -2
return false
end
-- nTempToSave indica quanti degli ultimi elementi della storia temporanea salvare nella storia
for i = ASS.nTempToSave, 0, -1 do
AddEvent( tbTempStory[#tbTempStory-i])
end
return true
end
function ASS.ResetStory()
tbStory = {}
Time = 0
return true
end
function ASS.ResetTempStory()
tbTempStory = {}
TempTime = 0
return true
end
local function ApplyTransf( tbEvent, bForward, bSave, bTemp)
-- tbEvent = { nId, vtDir, ptAx, dAngOrId, bWPaired, lPair}
if tbEvent == nil or bForward == nil or bSave == nil or bTemp == nil or
tbEvent.Id == GDB_ID.NULL or tbEvent.Id == nil or tbEvent.vtDir == nil or
tbEvent.ptAx == nil or tbEvent.dAngOrId == nil then
ASS.ERR = -1
return false
end
-- salvo le impostazioni di lavoro per la storia da ripristinare alla fine di questa funzione
local bSaveHistBefore = ASS.bSaveHist
ASS.bSaveHist = bSave
local bSaveTempBefore = bSaveTempBefore
ASS.bSaveTemp = bTemp
local bOk = true
-- se ho una traslazione o una rotazione applico la trasformazione a tutto l'accoppiato
if not AreSameVectorExact(V_NULL(), tbEvent.vtDir) then
local vtDir = Vector3d(tbEvent.vtDir)
-- se è un undo allora inverto il vettore
if not bForward then vtDir = vtDir * (-1) end
if tbEvent.dAngOrId == 0 then
ASS.nTypeTrf = 0 -- setto il tipo di trasformazione che sto facendo (in caso serva al chiamante)
ASS.nPartId = tbEvent.Id
ASS.vtMove = vtDir
if tbEvent.bWPaired then
ASS.Move()
else
ASS.MoveSingle()
end
elseif not AreSameVectorExact(V_NULL(), vtDir) then
ASS.nTypeTrf = 1 -- setto il tipo di trasformazione che sto facendo (in caso serva al chiamante)
ASS.nPartId = tbEvent.Id
ASS.vtAx = vtDir
ASS.ptAx = tbEvent.ptAx
ASS.dAng = tbEvent.dAngOrId
if tbEvent.bWPaired then
ASS.Rotate()
else
ASS.RotateSingle()
end
end
elseif tbEvent.dAngOrId == 0 then
ASS.nTypeTrf = 3 -- setto il tipo di trasformazione che sto facendo (in caso serva al chiamante)
-- se non sono definiti né l'asse né l'angolo/id di accoppiamento allora è un import
if not bForward then
-- se sto facendo un undo allora elimino il part e il SOLID importati
local nChild = EgtGetInfo(tbEvent.Id, "Child", "i")
EgtErase(nChild)
EgtErase(tbEvent.Id)
else
-- se sto facendo un redo, non faccio nulla
end
elseif #tbEvent.lPair > 0 and dAngOrId < 0 then
-- sto effettuando un disaccoppiamento (di un part da tutto l'assemblato)
ASS.nTypeTrf = 2
ASS.nPartId = tbEvent.Id
if bForward then
ASS.Unpair()
else
ASS.nPartToPair = tbEvent.lPair[0]
ASS.UpdatePairInfo()
end
else
-- sto applicando un accoppiamento o l'undo di un accoppiamento
if bForward then
ASS.nTypeTrf = 2 -- setto il tipo di trasformazione che sto facendo (in caso serva al chiamante)
-- sto applicando un accoppiamento
-- aggiorno le info dei due part e di tutti i loro associati
ASS.nPartId = tbEvent.Id
ASS.nPartToPair = tbEvent.dAngOrId
if not ASS.UpdatePairInfo() then bOk = false goto END end
else
ASS.nTypeTrf = 2 -- setto il tipo di trasformazione che sto facendo (in caso serva al chiamante)
-- sto applicando un disaccoppiamento (come undo di un accoppiamento)
if #tbEvent.lPair == 1 then
ASS.nPartId = tbEvent.dAngOrId
if not ASS.Unpair() then
ASS.ERR = -2
bOk = false
goto END
end
else
-- alla lista dei paired del part selezionato per essere accoppiato tolgo tutti i part che ho aggiunto( part destinatario e suoi eventuali accoppiati)
for n, nIdToUnpair in pairs(tbEvent.lPair) do
-- rimuovo anche le info
ASS.nPartId = tbEvent.Id
ASS.nPartToPair = nIdToUnpair
if not ASS.RemovePairInfo() then
bOk = false
goto END
end
end
local sPairedNew1 = EgtGetInfo( tbEvent.Id, "Paired", "s")
local lPairNew1 = EgtGetInfo(tbEvent.Id, "Paired", "vi")
if lPairNew1 == nil or sPairedNew1 == nil then
ASS.ERR = -3
bOk = false
goto END
end
-- copio la nuova lista dei paired in tutti gli altri paired
for n, nIdPaired in pairs(lPairNew1) do
ASS.nPartId = nIdPaired
ASS.sPairList = sPairedNew1
ASS.nGroup = -1
ASS.UpdatePairInfoSingle()
end
-- se il part corrente era già accoppiato con altri pezzi allora lascio a quell'accoppiato il numero del gruppo che sto spezzando
-- e darò un nuovo numero al destinatario e al suo accoppiato
local bCurrWasSingle = false
if #lPairNew1 == 1 then
bCurrWasSingle = true
ASS.sPairList = sPairedNew1
ASS.nGroup = 0
ASS.UpdatePairInfoSingle()
end
-- alla lista del part destinatario dell'accoppiamento tolgo tutti i part che gli ho aggiunto
for n, nIdPaired in pairs(lPairNew1) do
ASS.nPartId = tbEvent.dAngOrId
ASS.nPartToPair = nIdPaired
if not ASS.RemovePairInfo() then
bOk = false
goto END
end
end
-- assegno un nuovo numero di gruppo al gruppo che ho creato
local sPairedNew2 = EgtGetInfo( tbEvent.dAngOrId, "Paired", "s")
local lPairNew2 = EgtGetInfo( tbEvent.dAngOrId, "Paired", "vi")
local nGroupCode = -1
-- se il curr era single allora mantengo il numero di gruppo per l'assemblato del destinatario
if not bCurrWasSingle then
-- il curr non era single, quindi a lui resta il numero di gruppo
if #lPairNew2 > 1 then
-- anche il destinatario non era single, quindi serve un nuovo numero di gruppo
nGroupCode = GroupCounter
GroupCounter = GroupCounter + 1
else
-- il destinatario era single, quindi rimetto semplicemente a 0 il numero di gruppo
nGroupCode = 0
end
end
-- aggiorno la lista dei part che erano già paired con il part selezionato
for n, nIdPaired in pairs(lPairNew2) do
ASS.nPartId = nIdPaired
ASS.sPairList = sPairedNew2
ASS.nGroup = nGroupCode
ASS.UpdatePairInfoSingle()
end
end
end
end
::END::
-- ripristino i valori iniziali delle impostazioni di salvataggio
ASS.bSaveHist = bSaveHistBefore
ASS.bSaveTemp = bSaveTempBefore
return bOk
end
function ASS.Undo()
ASS.sFunc = "ASS.Undo"
if Time == 0 then do return false end end
if Time > #tbStory then Time = #tbStory end
ApplyTransf(tbStory[Time], false, false, false)
Time = Time - 1
ASS.nTransf = Time
ASS.bRedoPossible = true
return true
end
function ASS.Redo()
ASS.sFunc = "ASS.Redo"
if Time >= #tbStory then ASS.bRedoPossible = false return false end
if Time == ASS.nMaxStory then ASS.bRedoPossible = false return false end
ApplyTransf(tbStory[Time + 1], true, false, false)
Time = Time + 1
ASS.nTransf = Time
if Time >= #tbStory then ASS.bRedoPossible = false end
if Time == ASS.nMaxStory then ASS.bRedoPossible = false end
return true
end
function ASS.UndoTemp()
ASS.sFunc = "ASS.UndoTemp"
if TempTime == 0 then do return end end
if TempTime > ASS.nMaxStory then TempTime = ASS.nMaxStory end
ApplyTransf(tbTempStory[TempTime], false, false, false)
TempTime = TempTime - 1
end
function ASS.RedoTemp()
ASS.sFunc = "ASS.RedoTemp"
if TempTime >= #tbTempStory then do return end end
if TempTime == ASS.nMaxStory then do return end end
ApplyTransf(tbTempStory[TempTime + 1], true, false, false)
TempTime = TempTime + 1
end
local function RetrieveSurfNorm( nPartId)
-- recupero la normale della faccia principale del Part a partire dall'id del Part
local nLayR = EgtGetFirstNameInGroup( nPartId, "Region")
local nId = EgtGetFirstInGroup(nLayR)
local nSurfId = GDB_ID.NULL
while nId do
if EgtGetType( nId) == GDB_TY.SRF_FRGN then
nSurfId = nId
break
end
nId = EgtGetNext(nId)
end
local vtNorm = EgtSurfFrNormVersor(nSurfId, GDB_RT.GLOB)
return vtNorm
end
local function RetrieveParent( nId)
-- recupero il parent dell'oggetto nId
-- se è un oggetto all'interno contenuto in un Part che si chiama SOLID allora recupero il Part
nId = EgtGetParent(EgtGetParent(nId))
local sName = ""
sName = EgtGetName(nId, "s")
if sName == "SOLID" then
nId = EgtGetInfo(nId, "Parent","i")
end
return nId
end
local function RetrievePart( nId)
local sName = EgtGetName(nId)
local nParent = nId
if sName == "SOLID" then
nParent = EgtGetInfo(nId, "Parent","i")
end
return nParent
end
local function RetrievePaired()
vPaired = EgtGetInfo( RetrievePart(ASS.nPartId), "Paired", "vi")
if vPaired == nil then ASS.ERR = -3 return false end
return true
end
local function RetrieveLocAxis()
-- recupero l'id della terna, se esiste
nTernaId = GDB_ID.NULL
nTernaId = EgtGetInfo( ASS.nPartId, "Terna", "i")
if not nTernaId then
return false
else
return true
end
end
local function RetrieveLocOrig()
-- recupero l'origine della terna
if nTernaId == GDB_ID.NULL then do return end end
local LayOrig = EgtGetFirstNameInGroup(nTernaId, "ORIG")
ptOrigId = EgtGetFirstNameInGroup(LayOrig, "ORIG")
end
function ASS.Move()
ASS.sFunc = "ASS.Move"
if AreSameVectorApprox(ASS.vtMove, V_NULL()) then return true end
if ASS.nPartId == nil or ASS.nPartId == GDB_ID.NULL or ASS.vtMove == nil then ASS.ERR = -1 return false end
-- recupero la lista degli accoppiati
if not RetrievePaired() then return false end
if RetrieveLocAxis() then
EgtMove(nTernaId, ASS.vtMove, GDB_RT.GLOB)
end
-- muovo il pezzo e tutti i suoi accoppiati
for n, nId in pairs(vPaired) do
EgtMove( nId, ASS.vtMove, GDB_RT.GLOB)
local nChild = EgtGetInfo( nId, "Child", "i")
EgtMove( nChild, ASS.vtMove, GDB_RT.GLOB)
end
-- se richiesto salvo la storia
if ASS.bActiveHist then
local tbEv = {Id = ASS.nPartId, vtDir = ASS.vtMove, ptAx = ORIG(), dAngOrId = 0, bWPaired = true, lPair = {}}
if ASS.bSaveHist then AddEvent( tbEv) end
if ASS.bSaveTemp then AddTempEvent( tbEv) end
end
return true
end
function ASS.MoveSingle()
ASS.sFunc = "ASS.MoveSingle"
if AreSameVectorApprox(ASS.vtMove, V_NULL()) then return true end
if ASS.nPartId == nil or ASS.nPartId == GDB_ID.NULL or ASS.vtMove == nil then ASS.ERR = -1 return false end
-- muovo il pezzo MA NON i suoi accoppiati
EgtMove( ASS.nPartId, ASS.vtMove, GDB_RT.GLOB)
local nChild = EgtGetInfo( ASS.nPartId, "Child", "i")
EgtMove( nChild, ASS.vtMove, GDB_RT.GLOB)
if RetrieveLocAxis() then
EgtMove(nTernaId, ASS.vtMove, GDB_RT.GLOB)
end
-- se richiesto salvo la storia
if ASS.bActiveHist then
local tbEv = {Id = ASS.nPartId, vtDir = ASS.vtMove, ptAx = ORIG(), dAngOrId = 0, bWPaired = false, lPair = {}}
if ASS.bSaveHist then AddEvent( tbEv) end
if ASS.bSaveTemp then AddTempEvent( tbEv) end
end
return true
end
function ASS.Rotate()
ASS.sFunc = "ASS.Rotate"
if ASS.dAng == 0 then return true end
if ASS.nPartId == nil or ASS.nPartId == GDB_ID.NULL or ASS.ptAx == nil or
AreSameVectorApprox( ASS.vtAx, V_NULL()) then ASS.ERR = -1 return false end
-- recupero la lista degli accoppiati
if not RetrievePaired() then return false end
if RetrieveLocAxis() then
RetrieveLocOrig()
-- muovo la terna
local ptBefore = EgtSP(ptOrigId, GDB_RT.GLOB)
local ptAfterId = EgtCopyGlob(ptOrigId, nTernaId)
EgtRotate( ptAfterId, ASS.ptAx, ASS.vtAx, ASS.dAng, GDB_RT.GLOB, GDB_RT.GLOB)
local vtMove = Point3d(EgtSP( ptAfterId, GDB_RT.GLOB)) - Point3d(ptBefore)
EgtMove( nTernaId, vtMove, GDB_RT.GLOB)
EgtErase(ptAfterId)
end
-- ruoto il pezzo e tutti i suoi accoppiati
for n, nId in pairs(vPaired) do
EgtRotate( nId, ASS.ptAx, ASS.vtAx, ASS.dAng, GDB_RT.GLOB)
local nChild = EgtGetInfo( nId, "Child","i")
EgtRotate( nChild, ASS.ptAx, ASS.vtAx, ASS.dAng, GDB_RT.GLOB)
end
-- se richiesto salvo la storia
if ASS.bActiveHist then
local tbEv = {Id = ASS.nPartId, vtDir = ASS.vtAx, ptAx = ASS.ptAx, dAngOrId = ASS.dAng, bWPaired = true, lPair = {}}
if ASS.bSaveHist then AddEvent( tbEv) end
if ASS.bSaveTemp then AddTempEvent( tbEv) end
end
return true
end
function ASS.RotateSingle()
ASS.sFunc = "ASS.RotateSingle"
if ASS.dAng == 0 then return true end
if RetrieveLocAxis() then
RetrieveLocOrig()
-- muovo la terna
local ptBefore = EgtSP(ptOrigId, GDB_RT.GLOB)
local ptAfterId = EgtCopy(ptOrigId, nTernaId)
EgtRotate( ptAfterId, ASS.ptAx, ASS.vtAx, ASS.dAng, GDB_RT.GLOB)
local vtMove = Point3d(EgtSP( ptAfterId, GDB_RT.GLOB)) - Point3d(ptBefore)
EgtMove( nTernaId, vtMove, GDB_RT.GLOB)
EgtErase(ptAfterId)
end
-- ruoto il pezzo MA NON i suoi accoppiati
EgtRotate( ASS.nPartId, ASS.ptAx, ASS.vtAx, ASS.dAng, GDB_RT.GLOB)
local nChild = EgtGetInfo( ASS.nPartId, "Child","i")
EgtRotate( nChild, ASS.ptAx, ASS.vtAx, ASS.dAng, GDB_RT.GLOB)
-- se richiesto salvo la storia
if ASS.bActiveHist then
local tbEv = {Id = ASS.nPartId, vtDir = ASS.vtMove, ptAx = ASS.ptAx, dAngOrId = ASS.dAng, bWPaired = false, lPair = {}}
if ASS.bSaveHist then AddEvent( tbEv) end
if ASS.bSaveTemp then AddTempEvent( tbEv) end
end
return true
end
function ASS.FlipParallel()
ASS.sFunc = "ASS.FlipParallel"
local vtNorm = V_NULL()
-- recupero la normale della superficie originale
vtNorm = RetrieveSurfNorm( RetrievePart(ASS.nPartId))
if vtNorm == nil or AreSameVectorApprox(vtNorm, V_NULL()) then ASS.ERR = -3 return false end
ASS.ptAx = ptPair
ASS.vtAx = vtNorm
ASS.dAng = 180
if not ASS.Rotate() or not ASS.EdgePair() then return false end
return true
end
function ASS.FlipPerpendicular()
ASS.sFunc = "ASS.FlipPerpendicular"
-- recupero la normale della faccia principale del part del secondo part
local vtNorm = V_NULL()
vtNorm = RetrieveSurfNorm( RetrieveParent(ASS.nIdSecondLine))
if vtNorm == nil or AreSameVectorApprox(vtNorm, V_NULL()) then ASS.ERR = -3 return false end
local vtStartDir = EgtSV(ASS.nIdSecondLine, GDB_RT.GLOB)
local vtAx = vtNorm ^ vtStartDir
if vtAx == nil or AreSameVectorApprox(vtAx, V_NULL()) then ASS.ERR = -2 return false end
-- recupero il punto usato per l'accoppiamento
if ptPair == nil then ASS.ERR = -2 return false end
ASS.ptAx = ptPair
ASS.vtAx = vtAx
ASS.dAng = 180
if not ASS.Rotate() or not ASS.EdgePair() then return false end
return true
end
function ASS.FacePair()
ASS.sFunc = "ASS.FacePair"
-- setto e controllo
EgtSetContext(ASS.nVeinCtx)
if ASS.nPartId == GDB_ID.NULL then ASS.ERR = -1 return false end
if ASS.nIdSecondLine == GDB_ID.NULL then ASS.ERR = -1 return false end
-- recupero gli id dei Part
local nIdToPair = RetrieveParent(ASS.nIdSecondLine)
ASS.nPartId = RetrievePart(ASS.nPartId)
local ptAx = EgtSP(ASS.nIdSecondLine, GDB_RT.GLOB)
local vtAx = Vector3d(EgtSV(ASS.nIdSecondLine, GDB_RT.GLOB))
local vtNorm1 = Vector3d(ASS.vtFirstNorm):isZero() and Vector3d(RetrieveSurfNorm(ASS.nPartId)) or Vector3d(ASS.vtFirstNorm)
local vtNorm2 = Vector3d(ASS.vtSecondNorm):isZero() and Vector3d(RetrieveSurfNorm( nIdToPair)) or Vector3d(ASS.vtSecondNorm)
local dAng = GetAngle( vtNorm1, vtNorm2)
local vtCopy = Vector3d(vtNorm1)
vtCopy:rotate(vtAx, 180 - dAng)
vtCopy = vtCopy * (GDB_ID.NULL)
ASS.ptAx = ptAx
ASS.vtAx = vtAx
if AreSameVectorApprox(vtNorm2, vtCopy) then
ASS.dAng = 180 - dAng
if not ASS.Rotate() then return false end
else
ASS.dAng = -(180 - dAng)
if not ASS.Rotate() then return false end
end
return true
end
function ASS.EdgePair()
ASS.sFunc = "ASS.EdgePair"
-- setto e faccio i controlli
-- resetto il conto di operazioni fatto
ASS.nTransf = 1
EgtSetContext(ASS.nVeinCtx)
if ASS.nPartId == GDB_ID.NULL then ASS.ERR = -1 return false end
if ASS.nIdFirstLine == GDB_ID.NULL then ASS.ERR = -1 return false end
if ASS.nIdSecondLine == GDB_ID.NULL then ASS.ERR = -1 return false end
-- controllo che i due part non siano già accoppiati
-- recupero l'id del secondo part
local nIdToPair = RetrieveParent(ASS.nIdSecondLine)
if nIdToPair == GDB_ID.NULL then ASS.ERR = -1 return false end
ASS.nPartId = RetrievePart(ASS.nPartId)
if ASS.nPartId == GDB_ID.NULL then ASS.ERR = -1 return false end
-- verifico che i due part non siano già accoppiati
local nGroup1 = 0
local nGroup2 = 0
nGroup1 = EgtGetInfo( ASS.nPartId, "GroupCode","i") or 0
nGroup2 = EgtGetInfo( nIdToPair, "GroupCode","i") or 0
if nGroup1 == nGroup2 and nGroup1 ~= 0 then return true end
-- se i due part non erano già associati allora procedo con l'accoppiamento
-- first line
local ptStartF, ptEndF, ptMidF, vtDirF
ptStartF = EgtSP(ASS.nIdFirstLine, GDB_RT.GLOB)
ptEndF = EgtEP(ASS.nIdFirstLine, GDB_RT.GLOB)
ptMidF = EgtMP(ASS.nIdFirstLine, GDB_RT.GLOB)
vtDirF = EgtSV(ASS.nIdFirstLine, GDB_RT.GLOB)
-- second line
local ptStartS, ptEndS, ptMidS, vtDirS
ptStartS = EgtSP(ASS.nIdSecondLine, GDB_RT.GLOB)
ptEndS = EgtEP(ASS.nIdSecondLine, GDB_RT.GLOB)
ptMidS = EgtMP(ASS.nIdSecondLine, GDB_RT.GLOB)
vtDirS = EgtSV(ASS.nIdSecondLine, GDB_RT.GLOB)
local ptIni, ptFin
if ASS.nOption == 0 then
-- Start-Start
ptIni = ptStartF
ptFin = ptStartS
elseif ASS.nOption == 1 then
-- Start-End
ptIni = ptStartF
ptFin = ptEndS
elseif ASS.nOption == 2 then
-- End-Start
ptIni = ptEndF
ptFin = ptStartS
elseif ASS.nOption == 3 then
-- End-End
ptIni = ptEndF
ptFin = ptEndS
elseif ASS.nOption == 4 then
-- Mid-Mid
ptIni = ptMidF
ptFin = ptMidS
end
ptPair = ptFin
-- calcolo il vettore movimento e sposto solid e part
ASS.vtMove = ptFin - ptIni
local dAng = GetAngle(vtDirF, vtDirS)
if not ASS.Move() then return false end
local dTol = 0.001
if dAng < dTol or abs(dAng - 180) < dTol or abs(dAng - 360) < dTol then
--EgtDraw()
return true
end
ASS.nTransf = 2
-- ruoto il solid che sto spostando
local vtAx = Vector3d( vtDirF ^ vtDirS)
ASS.dAng = dAng
ASS.ptAx = ptFin
ASS.vtAx = vtAx
if not ASS.Rotate() then return false end
--EgtDraw()
return true
end
function ASS.Unpair()
ASS.sFunc = "ASS.Unpair"
if ASS.nPartId == nil or ASS.nPartId == GDB_ID.NULL then ASS.ERR = -1 return false end
local lPairList = EgtGetInfo( ASS.nPartId, "Paired", "vi")
-- rimuovo le info dal PartCurr e da tutti i suoi Pair
ASS.nPartToPair = ASS.nPartId
if not ASS.RemovePairInfo() then return false end
local nPartCurr = ASS.nPartId
if not RetrievePaired() then return false end
local sPaired = EgtGetInfo(ASS.nPartId, "Paired")
if sPaired == nil then ASS.ERR = -3 return false end
for n, nId in pairs(vPaired) do
ASS.nPartId = nId
ASS.sPairList = sPaired
ASS.nGroup = #vPaired > 1 and GDB_ID.NULL or 0
if not ASS.UpdatePairInfoSingle() then return false end
end
-- resetto le info di pairing del part corrente
ASS.nPartId = nPartCurr
ASS.sPairList = EgtNumToString(nPartCurr)
ASS.nGroup = 0
if not ASS.UpdatePairInfoSingle() then return false end
-- se richiesto salvo la storia
local nPartToPair = lPairList[1] ~= ASS.nPartId and -lPairList[1] or -lPairList[2]
if ASS.bActiveHist then
local tbEv = {Id = ASS.nPartId, vtDir = V_NULL(), ptAx = ORIG() , dAngOrId = nPartToPair, bWPaired = false, lPair = lPairList}
if ASS.bSaveHist then AddEvent( tbEv) end
if ASS.bSaveTemp then AddTempEvent( tbEv) end
end
return true
end
function ASS.RemovePairInfo() --nId As Integer, nIdToUnpair As Integer
-- al part nId tolgo l'accoppiamento con nIdToUnpair
ASS.sFunc = "ASS.RemovePairInfo"
--aggiorno le info
local sPair = EgtGetInfo(ASS.nPartId, "Paired", sPair)
local vsPaired = EgtSplitString(sPair, ",")
local sIdToUnpair = EgtNumToString(ASS.nPartToPair)
if sIdToUnpair == nil or sIdToUnpair == "" or vsPaired == nil or sPair == nil then ASS.ERR = -3 return false end
-- ricostruisco l'informazione paired senza l'Id che ho disaccoppiato
local sNewPaired = ""
for s, sIdPaired in pairs(vsPaired) do
if sIdPaired ~= sIdToUnpair then
if sNewPaired ~= "" then
sNewPaired = sNewPaired .. "," .. sIdPaired
else
sNewPaired = sIdPaired
end
end
end
-- aggiorno le info
local nGroup = #vsPaired > 2 and GDB_ID.NULL or 0
ASS.sPairList = sNewPaired
ASS.nGroup = nGroup
if not ASS.UpdatePairInfoSingle() then return false end
return true
end
function ASS.UpdatePairInfoSingle()
ASS.sFunc = "ASS.UpdatePairInfoSingle"
if ASS.sPairList == nil or ASS.sPairList == "" or ASS.nGroup == nil then ASS.ERR = -1 return false end
EgtSetInfo(ASS.nPartId, "Paired", ASS.sPairList)
if ASS.nGroup ~= GDB_ID.NULL then
EgtSetInfo(ASS.nPartId, "GroupCode", ASS.nGroup)
end
return true
end
function ASS.UpdatePairInfo()
ASS.sFunc = "ASS.UpdatePairInfo"
local nId1 = RetrievePart(ASS.nPartId)
if nId1 == nil or nId1 == GDB_ID.NULL then ASS.ERR = -1 return false end
ASS.nPartId = nId1
-- il secondo id lo recupero dal parent del secondo edge, se presente, altrimenti da nPartToPair
local nId2 = GDB_ID.NULL
if ASS.nIdSecondLine ~= GDB_ID.NULL then
nId2 = RetrieveParent(ASS.nIdSecondLine)
else
nId2 = RetrievePart(ASS.nPartToPair)
end
if nId1 == nil or nId1 == GDB_ID.NULL then ASS.ERR = -1 return false end
ASS.nPartToPair = nId2
-- salvo la lista degli attuali accoppiati del part destinatario dell'accoppiamento
local lPairList = EgtGetInfo( ASS.nPartToPair,"Paired", "vi")
if lPairList == nil then ASS.ERR = -3 return false end
-- verifico se uno o entrambi dei due part sono già in un gruppo
local sPaired1 = ""
sPaired1 = EgtGetInfo(nId1, "Paired")
if sPaired1 == nil then ASS.ERR = -3 return false end
local sPaired2 = ""
sPaired2 = EgtGetInfo(nId2, "Paired")
if sPaired2 == nil then ASS.ERR = -3 return false end
local nGroup = 0
-- se nessuno dei due era in un gruppo creo un nuovo gruppo con questi due part
if sPaired1 == EgtNumToString(nId1) and sPaired2 == EgtNumToString(nId2) then
sPaired1 = sPaired1 .. "," .. sPaired2
nGroup = EgtGetInfo(nId1, "GroupCode","i")
-- se solo il secondo era in un gruppo, al secondo copio gli id del gruppo
elseif sPaired1 == EgtNumToString(nId1) and sPaired2 ~= EgtNumToString(nId2) then
sPaired2 = sPaired2 .. "," .. EgtNumToString(nId1)
sPaired1 = sPaired2
nGroup = EgtGetInfo(nId2, "GroupCode","i")
-- se solo il primo era in un gruppo, al secondo copio gli id del gruppo
elseif sPaired1 ~= EgtNumToString(nId1) and sPaired2 == EgtNumToString(nId2) then
sPaired1 = sPaired1 .. "," .. EgtNumToString(nId2)
nGroup = EgtGetInfo(nId1, "GroupCode","i")
-- se entrambi erano in un gruppo faccio il merge
elseif sPaired1 ~= EgtNumToString(nId1) and sPaired2 ~= EgtNumToString(nId2) then
sPaired1 = sPaired1 .. "," .. sPaired2
local nGroup1 = EgtGetInfo(nId1, "GroupCode","i")
local nGroup2 = EgtGetInfo(nId2, "GroupCode","i")
nGroup = nGroup1 < nGroup2 and nGroup1 or nGroup2
end
if nGroup == 0 or nGroup == nil then
nGroup = GroupCounter
GroupCounter = GroupCounter + 1
end
-- scorro tutti i part associati e aggiorno le loro info
local vPaired_s = EgtSplitString(sPaired1) -- qua devo fare uno split sulle virgole
ASS.sPairList = sPaired1
ASS.nGroup = nGroup
local nPartCurr = ASS.nPartId
for n, sId in pairs(vPaired_s) do
local nId = EgtEvalNumExpr(sId)
ASS.nPartId = nId
if not ASS.UpdatePairInfoSingle() then return false end
end
if ASS.bActiveHist then
ASS.nPartId = nPartCurr
local tbEv = {Id = ASS.nPartId, vtDir = V_NULL(), ptAx = ORIG(), dAngOrId = ASS.nPartToPair, bWPaired = true, lPair = lPairList}
if ASS.bSaveHist then AddEvent( tbEv) end
if ASS.bSaveTemp then AddTempEvent( tbEv) end
end
return true
end
local function PairPartFollowingInfo(nPart, tbTrasfTot)
local sLineToPair = EgtGetInfo(nPart, "PairToRef")
local sMyLineToPairName = EgtGetInfo( nPart, "PairMyRef")
if sLineToPair then
-- recupero l'id del lato da accoppiare
local sLayName = "Ref"
local nLayRef = EgtGetFirstNameInGroup(nPart, sLayName)
local nMyLineToPair = EgtGetFirstNameInGroup(nLayRef, sMyLineToPairName)
if nMyLineToPair == nil or nMyLineToPair == GDB_ID.NULL then ASS.ERR = -3 return false end
-- spezzo l'informazione per risalire al lato di destinazione dell'accoppiamento
local vToInfo = EgtSplitString(sLineToPair, ",")
local sLineToPairName = vToInfo[2]
local sPartName = vToInfo[1]
local nPartToPair = EgtGetFirstNameInGroup(GDB_ID.ROOT, sPartName)
local nLay = EgtGetFirstNameInGroup(nPartToPair, sLayName)
local nLineToPair = EgtGetFirstNameInGroup(nLay, sLineToPairName)
if nLineToPair == nil or nLineToPair == GDB_ID.NULL then ASS.ERR = -3 return false end
local nSpin = EgtGetInfo(nPart, "PairSpin", "i")
ASS.nPartId = nPart
ASS.nIdFirstLine = nMyLineToPair
ASS.nIdSecondLine = nLineToPair
-- controllo se è settata la modalità di accoppiamento sennò lascio il default middle-middle
local nOption = EgtGetInfo(nPart, "PairMode", "i")
ASS.nOption = nOption and nOption or 4
if not ASS.EdgePair() then return false end
tbTrasfTot[1] = tbTrasfTot[1] + ASS.nTransf
-- verifico che lo spin sia rispettato
local vtEdge1 = EgtSV( ASS.nIdFirstLine, GDB_RT.GLOB)
local vtEdge2 = EgtSV( ASS.nIdSecondLine, GDB_RT.GLOB)
if AreSameVectorApprox( vtEdge1, vtEdge2) and nSpin == -1 then
if not ASS.FlipParallel() then return false end
end
-- recupero l'angolo che deve esserci tra le due facce dei part alla fine dell'accoppiamento
local nAngGoal = EgtGetInfo(nPart, "PairAng", "d")
-- calcolo l'angolo attuale tra le due normali e quindi la rotazione che devo applicare per differenza
local vtSurf1 = RetrieveSurfNorm(nPart)
local vtSurf2 = RetrieveSurfNorm(RetrieveParent(ASS.nIdSecondLine))
if vtSurf1 == nil or AreSameVectorApprox( vtSurf1, V_NULL()) or vtSurf2 == nil or AreSameVectorApprox( vtSurf2, V_NULL()) then ASS.ERR = -3 return false end
ASS.vtAx = EgtSV(ASS.nIdSecondLine, GDB_RT.GLOB)
if ASS.vtAx == nil or AreSameVectorApprox(ASS.vtAx, V_NULL()) then ASS.ERR = -1 return false end
local dAngCurr = GetRotation(vtSurf1, vtSurf2, ASS.vtAx)
ASS.dAng = dAngCurr - nAngGoal
ASS.ptAx = EgtSP(ASS.nIdSecondLine, GDB_RT.GLOB)
if not ASS.Rotate() then return false end
tbTrasfTot[1] = tbTrasfTot[1] + 1
-- aggiorno le info di accoppiamento
ASS.nPartToPair = nPartToPair
if not ASS.UpdatePairInfo() then return false end
tbTrasfTot[1] = tbTrasfTot[1] + 1
end
return true
end
function ASS.PairSingle()
if ASS.nPartId ~= GDB_ID.NULL then
local tbTrasfTot = {0}
PairPartFollowingInfo(ASS.nPartId, tbTrasfTot)
ASS.nTransf = tbTrasfTot[1]
end
end
function ASS.PairAll()
ASS.sFunc = "ASS.PairAll"
local tbTrasfTot = {0} -- tabella per il conteggio delle operazioni svolte (uso la tabella per passare per riferimento il numero di operazioni alla
-- funzione PairPartFollowingInfo)
EgtSetContext(ASS.nVeinCtx)
local nPart = EgtGetFirstPart()
if nPart == nil or nPart == GDB_ID.NULL then ASS.ERR = -3 return false end
while nPart do
EgtOutLog(tostring(nPart))
-- controllo se il pezzo è già stato accoppiato con la sua destinazione
local tbPaired = EgtGetInfo(nPart, "Paired","vi")
if not tbPaired then EgtSetInfo(nPart, "Paired", EgtNumToString(nPart)) end
local bAlreadyPaired = false
if not tbPaired then goto NEXT end
for _, nPaired in pairs(tbPaired) do
if nPaired == nPartToPair then bAlreadyPaired = true end
if bAlreadyPaired then goto NEXT end
end
PairPartFollowingInfo(nPart, tbTrasfTot)
::NEXT::
nPart = EgtGetNext(nPart)
end
ASS.nTransf = tbTrasfTot[1]
return true
end
------ per funzionare con il require
--return ASS
------ per funzionare con il require
------ per funzionare nel CAM5
-- ASS.nVeinCtx = 1
-- ASS.PairAll()
-- EgtDraw()
------ per funzionare nel CAM5
---
if bAutoRun then
ASS.PairAll()
end
+235
View File
@@ -0,0 +1,235 @@
-- 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
--
+1776
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
###ESEMPIO COMANDO ROBOCOPY###
#path cartella di origine
$sourceFolder = "C:\Users\YYY"
#nomi dei file da copiare
$file1 = "nome1.txt"
$file2 = "nome2.txt"
$file3 = "nome3.txt"
#path delle cartelle di destinazione
$destFolder1 = "C:\Users\XXX1"
$destFolder2 = "C:\Users\XXX2"
$destFolder3 = "C:\Users\XXX3"
#copio primo file
robocopy $sourceFolder $destFolder1 $file1
#copio secondo file
robocopy $sourceFolder $destFolder2 $file2
#copio terzo file
robocopy $sourceFolder $destFolder3 $file3
+476
View File
@@ -0,0 +1,476 @@
-- 2024/11/22
-- Template per la creazione di un cabinet
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
EgtAddToPackagePath(EgtGetSourceDir() .. 'LuaLibs\\?.lua')
require( 'EgtCompo')
-- Parametri : dichiarazione e valori standard
-- N.B.: le dimensioni sono comprese di spessori
local CMP = {}
CMP.N1 = 'Altezza alzatina' -- altezza
CMP.T1 = 3 -- 0=null, 1=bool, 2=int, 3=len, 4=num, 5=string
CMP.V1 = 40
CMP.N2 = 'Altezza frontalino' -- larghezza
CMP.T2 = 3
CMP.V2 = 60
CMP.N3 = 'Profondità lavello' -- profondità
CMP.T3 = 3
CMP.V3 = 300
CMP.N4 = 'Spessore Top' -- spessore top
CMP.T4 = 3
CMP.V4 = 20
CMP.N5 = 'Spessore Bottom' -- spessore bottom
CMP.T5 = 3
CMP.V5 = 10
CMP.N6 = 'Spessore Alzatine' -- spessore left
CMP.T6 = 3
CMP.V6 = 30
CMP.N7 = 'Spessore Frontalini' -- spessore right
CMP.T7 = 3
CMP.V7 = 5
CMP.N8 = 'Dimensione Foro' -- diametro del foro
CMP.T8 = 3
CMP.V8 = 5
CMP.N9 = 'Pendenza del fondo' -- angolo di pendenza del fondo
CMP.T9 = 3
CMP.V9 = 0.15
CMP.ResetView = false
CMP.DrawSolid = true
CMP.IsCabinet = true
CMP.Npar = 9
CMP.Nome = 'TopChicken'
_G.CMP = CMP
CMP.ERR = 0
CMP.MSG = ''
-- Aggiorno con ultimi valori salvati (se presenti)
CMP.DATA = EgtGetSourceDir() .. CMP.Nome ..'.dat'
LoadCompoData()
-- Percorso direttorio Vein3D
local sPath = ""
sPath = EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile())
EgtOutLog(''..sPath)
-- definzione delle variabile per le classi di paretine
local dAngAlzatina = 90
local dAngFrontalino = -90
-- Carico i dati letti da file .dat
local tbOrigVal={}
local function OrigData()
tbOrigVal.v1 = CMP.V1
tbOrigVal.v2 = CMP.V2
tbOrigVal.v3 = CMP.V3
tbOrigVal.v4 = CMP.V4
tbOrigVal.v5 = CMP.V5
tbOrigVal.v6 = CMP.V6
tbOrigVal.v7 = CMP.V7
tbOrigVal.v8 = CMP.V8
tbOrigVal.v9 = CMP.V9
end
---
-- Per disporre i pezzi in piano non sovrappposti (in assemblaggio non serve)
local HorizontalOffset = 0
-------------------------------------------------------------------------------------------------------------------------
-- COSTRUZIONE RIFERIMENTI INIZIO
-------------------------------------------------------------------------------------------------------------------------
local function SetReference()
-- Esempio Riferimento:
-- CreateReference( tbName[2], 'OutLoop', 'A2', 'R1', CMP.SL, '0,0,-x')
-- SetPairInfo( tbName[2], 'R1', tbName[1], 'R1', -1, 90, 1)
-- Esempio Punto per dimension:
-- CreatePointReference( tbName[1], 'OutLoop', 'A1', 'R4', 0, CMP.SB, '0,0,-x')
--SaveMePlease()
end
--
local function AddDimensions()
-- local GridFr = Frame3d(ORIG(),GDB_FR.FRONT)
-- --Esempio:
-- -- DrawLinearDimension( tbName[1], 'R4', tbName[4], 'R2', 'SUA ALTEZZA',GridFr, Point3d(-50,0,0))
-- EgtSetGridFrame(GLOB_FRM())
end
--
-------------------------------------------------------------------------------------------------------------------------
-- COSTRUZIONE RIFERIMENTI FINE
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-- CREAZIONE/IMPORTAZIONE Loop INIZIO
-------------------------------------------------------------------------------------------------------------------------
-- Importa un contorno chiuso da file nge
function ImportLoop( PartId, tbLayer, sNameFileNGE)
local OutLayer = tbLayer['OutLoop']
if not EgtInsertFile( sNameFileNGE) then
EgtOutLog(' IMPORTAZIONE FALLITA: '..sNameFileNGE)
end
-- recupero ultimo Part
local LastPart = EgtGetLastPart()
local FstLayerInLstPart = EgtGetFirstGroupInGroup( LastPart)
local IdLoop = EgtGetFirstInGroup( FstLayerInLstPart)
if not EgtRelocateGlob( IdLoop, OutLayer) then
EgtOutLog(' RELOCATE FALLITA MISERAMENTE: '..tostring(IdLoop)..';'..tostring(OutLayer))
end
local tbIdAllLoops = {}
local tbIdLoop = TOOL.ExplodeAndNameEdges( IdLoop)
table.insert(tbIdAllLoops, tbIdLoop)
EgtSetInfo(tbIdLoop[1],'AF',1)
EgtSetInfo(tbIdLoop[2],'AF',2)
EgtSetInfo(tbIdLoop[3],'AF',2)
EgtSetInfo(tbIdLoop[4],'AF',2)
EgtSetInfo(tbIdLoop[5],'AF',2)
EgtSetInfo(tbIdLoop[6],'AF',2)
EgtSetInfo(tbIdLoop[7],'AF',1)
-- controllo la presenza di eventuali inloop ( che mi aspetto essere CCW)
local IdInLoop = EgtGetFirstInGroup(FstLayerInLstPart)
if IdInLoop then
EgtInvertCurve(IdInLoop)
local InLoopLay = EgtGroup(PartId)
EgtSetName(InLoopLay, 'InLoop')
EgtRelocateGlob( IdInLoop, InLoopLay)
local tbIdInLoop = TOOL.ExplodeAndNameEdges( IdInLoop, true)
table.insert(tbIdAllLoops, tbIdInLoop)
EgtSetInfo(tbIdInLoop[1],'AF',2)
EgtSetInfo(tbIdInLoop[2],'AF',2)
EgtSetInfo(tbIdInLoop[3],'AF',2)
EgtSetInfo(tbIdInLoop[4],'AF',2)
end
-- cancello il part dell'importazione
EgtErase(LastPart)
return tbIdAllLoops
end
--
-- sNamePartDest deve essere il pezzo al cui lato A1 si attacca il lato A4 del pezzo Bottom
local function CreateBottomPart( tbIdLoop, nParent)
-- creo il fondo del lavello
local tbPart = {}
tbPart.sName = sUNICode..'Bottom'
local Pz_Bottom = TOOL.CreatePartLayer(tbPart.sName)
tbPart.nId = Pz_Bottom
tbPart.nParent = nParent
tbPart.dTh = CMP.SB
tbPart.sDestRefOff = '0,0,-x'
tbPart.sRefOff = '0,0,0'
tbPart.dPairAng = 90
local tbLayerBottom = TOOL.FindLayers(Pz_Bottom)
local bInvert = true
local bInLoop = false
local tbOutLoop = TOOL.AddLoopToLayer(tbLayerBottom['OutLoop'], tbIdLoop, CMP.SWater, bInvert, bInLoop) -- il loop viene aggiunto ma nella posizione da inloop del piano cucina, non come nuovo pezzo messo nell'origine
TOOL.CreatePart(tbLayerBottom,tbPart.sName,tbOutLoop,tbPart.dTh,bInLoop)
-- creo il foro
local ptCenter = EgtGP( EgtGetFirstInGroup(tbLayerBottom['Region']), GDB_RT.GLOB)
TOOL.CreateCircularHole( Pz_Bottom, ptCenter, CMP.DiamBore)
-- creo i riferimenti e salvo i parametri del part
local nIdRefDest = TOOL.CreateReference( nParent, 'OutLoop', 'A1', tbPart.dTh, tbPart.sDestRefOff)
local nIdMyRef = TOOL.CreateReference( tbPart.nId, 'OutLoop', 'A4', 0, tbPart.sRefOff)
TOOL.SetPairInfo( tbPart, nIdMyRef, sNamePartDest, nIdRefDest, -1)
end
local function CreateSplitBottomPart( tbIdLoop, tbParent, dOffset)
-- creo il fondo diviso in un numero di pezzi pari ai lati del loop passato
local nLay = EgtGetParent(tbIdLoop[1])
local nAuxLay = EgtGroup( nLay)
EgtSetName(nAuxLay, 'OutLoop')
local nLoop = EgtCurveCompoByChain(nAuxLay, tbIdLoop, EgtSP(tbIdLoop[1], GDB_RT.GLOB), false)
EgtOffsetCurve(nLoop, -dOffset, GDB_OT.EXTEND)
local ptCenter = EgtGP(nLoop, GDB_RT.GLOB)
local tbLoopOff = TOOL.ExplodeAndNameEdges( nLoop, false)
local nPrev = 0
local nFirst = 0
local tbSplitBottom = {}
-- creo i part con tutte le info
for i = 1, #tbLoopOff do
local tbPart = {}
local Pz_Bottom = TOOL.CreatePartLayer('BottomA'..tostring(i), sUNICode)
if i == 1 then nFirst = Pz_Bottom end
tbPart.sName = EgtGetName(Pz_Bottom)
tbPart.nId = Pz_Bottom
tbPart.nEdge = i
tbPart.nEdgeId = tbLoopOff[i]
tbPart.dTh = CMP.SB
EgtSetInfo(Pz_Bottom, 'dTh', CMP.SB)
tbPart.sDestRefOff = '0,0,-x'
tbPart.sRefOff = '0,0,0'
tbPart.dPairAng = 90 - CMP.dSlopeAng
EgtSetInfo(Pz_Bottom, 'PairAng', tbPart.dPairAng)
tbPart.nJunctionType = 3
tbPart.bOnLoop = true
tbPart.dH = (EgtPointCurveDist( ptCenter, tbPart.nEdgeId, GDB_RT.GLOB) - CMP.DiamBore) / cos(CMP.dSlopeAng)
tbPart.nPrev = nPrev
if i > 1 then tbSplitBottom[nPrev].nNext = Pz_Bottom end
tbSplitBottom[Pz_Bottom] = tbPart
nPrev = Pz_Bottom
end
tbSplitBottom[nPrev].nNext = nFirst
tbSplitBottom[nFirst].nPrev = nPrev
-- scorro i part e costruisco effettivamente i pezzi in funzione del precedente e del successivo
local c = 1
for nPart, tbPart in pairs(tbSplitBottom) do
local tbLayerBottom = TOOL.FindLayers(nPart)
local bInLoop = false
TOOL.CreateParetina( tbPart.nEdgeId, tbPart, 90)
-- tbPart.dLen = 300 + CMP.SWater * 2
-- tbPart.dAngBL = 46
-- tbPart.dAngBR = 46
local tbPartLoop = TOOL.CreateAdjustedPart( tbLayerBottom['OutLoop'],tbPart.dLen, tbPart.dH, tbPart.dAngBL, tbPart.dAngBR)
TOOL.CreatePart(tbLayerBottom,tbPart)
-- tbPart.dSideAngL = 8
-- tbPart.dSideAngR = 8
if tbPart.dSideAngL then TOOL.SetSideAng(tbLayerBottom['OutLoop'], 'A2', tbPart.dSideAngL) end
if tbPart.dSideAngR then TOOL.SetSideAng(tbLayerBottom['OutLoop'], 'A4', tbPart.dSideAngR) end
-- creo i riferimenti e salvo i parametri del part
local nPartDestId = tbParent[c]
c = c + 1
local nIdToRef = TOOL.CreateReference( nPartDestId, 'OutLoop', 'A1', 'R1', tbPart.dTh, tbPart.sDestRefOff)
local nMyRef = TOOL.CreateReference( tbPart.nId, 'OutLoop', 'A1', 'R1', 0, tbPart.sRefOff)
TOOL.SetPairInfo( tbPart, nMyRef, sNamePartDest, nIdToRef, -1)
end
EgtErase(nAuxLay)
return tbSplitBottom
end
-- Confronto i dati del file.dat con quelli letti da programma
local function IsDataChanged()
local bOk = false
if not tbOrigVal.v1 then return true end
if math.abs(CMP.V1 - tbOrigVal.v1) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V2 - tbOrigVal.v2) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V3 - tbOrigVal.v3) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V4 - tbOrigVal.v4) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V5 - tbOrigVal.v5) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V6 - tbOrigVal.v6) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V7 - tbOrigVal.v7) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V8 - tbOrigVal.v8) > 0.5 then bOk = bOk or true end
if math.abs(CMP.V9 - tbOrigVal.v9) > 0.005 then bOk = bOk or true end
return bOk
end
-- EgtAddToPackagePath(sPath..'TemplateTool.lua')
-- require('TemplateTool')
local TOOL = dofile(sPath..'TemplateTool.lua')
local sUNICode = TOOL.sUNICode
function CMP_Draw(bPreview)
local bRedraw = IsDataChanged()
if bRedraw or not CMP.DrawSolid then
-- pulisco il file e leggo i dati
EgtNewFile()
HorizontalOffset = 0
CMP.HSplash = CMP.V1 -- altezza alzatina
CMP.HWater = CMP.V2 -- altezza frotalino
CMP.DSink = CMP.V3 -- profondità lavello
CMP.ST = CMP.V4 -- spessore top
CMP.SB = CMP.V5 -- spessore bottom
CMP.SSplash = CMP.V6 -- spessore alzatine
CMP.SWater = CMP.V7 -- spessore frontalini
CMP.DiamBore = CMP.V8 -- spessore back
CMP.dSlopeAng = CMP.V9 -- angolo di pendenza
-- PIANO POLLO
local Pz_Top = TOOL.CreatePartLayer( 'TopChicken')
-- Creo il contorno esterno (id degli edge esterni)
local tbLoopsTC = ImportLoop( Pz_Top, TOOL.FindLayers( Pz_Top), sPath .. 'TopChicken.nge')
local tbIdLoopTC = tbLoopsTC[1]
local tbIdInLoopTC = tbLoopsTC[2]
-- Creo il pezzo dato il contorno
local dTh_TC = CMP.ST
local tbTCLayer = TOOL.FindLayers( Pz_Top)
local tbTCInfo = {sName = "TopChicken", dTh = dTh_TC, }
TOOL.CreatePart( tbTCLayer['OutLoop'], tbTCInfo)
if tbTCLayer['InLoop'] then
TOOL.AddInLoopToPart( tbTCLayer['InLoop'])
end
--INIZIO CREAZIONE PARETINE dell'OutLoop
-- tabella che contiene le tabelle con le info dei vari part
local tbPartsInfo = {}
local dThCurr = 20
local dHCurr = 100
local nPrev = 0
local nFirst = 0
for i=1, #tbIdLoopTC do
local tbInfo = {}
tbInfo.nParent = Pz_Top
tbInfo.nEdge = i -- posizione dell'edge nel loop, 1 based
tbInfo.nEdgeId = tbIdLoopTC[i]
tbInfo.nPrev = nPrev
local sNamePz = 'PartA'.. tostring(i)
tbInfo.sName = sUNICode..sNamePz
local Pz_A = TOOL.CreatePartLayer(sNamePz)
if nPrev ~= 0 then tbPartsInfo[nPrev].nNext = Pz_A end
if i == 1 then nFirst = Pz_A end
tbInfo.nId = Pz_A
local nType = EgtGetInfo(tbInfo.nEdgeId, 'AF', 'i') or 0
local dPairAng = 0
if nType == 1 then
dPairAng = dAngAlzatina
tbInfo.dTh = CMP.SSplash
tbInfo.dH = CMP.HSplash
elseif nType == 2 then
dPairAng = dAngFrontalino
tbInfo.dTh = CMP.SWater
tbInfo.dH = CMP.HWater
end
tbInfo.nType = nType
tbInfo.dPairAng = dPairAng
nPrev = Pz_A
tbPartsInfo[tbInfo.nId] = tbInfo
end
tbPartsInfo[nFirst].nPrev = nPrev
tbPartsInfo[nPrev].nNext = nFirst
-- aggiungo le paretine dell'InLoop
nPrev = 0
nFirst = 0
for i=1, #tbIdInLoopTC do
local tbInfo = {}
tbInfo.nParent = Pz_Top
tbInfo.nEdge = i -- posizione dell'edge nel loop, 1 based
tbInfo.nEdgeId = tbIdInLoopTC[i]
tbInfo.nPrev = nPrev
local sNamePz = 'InPartA'.. tostring(i)
tbInfo.sName = sUNICode..sNamePz
local Pz_A = TOOL.CreatePartLayer(sNamePz)
if nPrev ~= 0 then tbPartsInfo[nPrev].nNext = Pz_A end
if i == 1 then nFirst = Pz_A end
tbInfo.nId = Pz_A
local nType = EgtGetInfo(tbInfo.nEdgeId, 'AF', 'i') or 0
local dPairAng = 0
if nType == 1 then
dPairAng = dAngAlzatina
elseif nType == 2 then
dPairAng = dAngFrontalino
end
tbInfo.nType = nType
tbInfo.dPairAng = dPairAng
tbInfo.dTh = CMP.SWater
tbInfo.dH = CMP.DSink
nPrev = Pz_A
tbInfo.bInLoop = true
tbPartsInfo[tbInfo.nId] = tbInfo
end
tbPartsInfo[nFirst].nPrev = nPrev
tbPartsInfo[nPrev].nNext = nFirst
--local bOnLoop = false -- bool che indica se la faccia buona del part sta sull'edge del piano cucina o no
--local nJunctionType = 1 -- tipo di giunzione: 1 trim start, 2 trim end, 3 giunzione angolata
for nPart, tbInfo in pairs( tbPartsInfo) do
-- scrivo nel part le info di prev e next e del part proprietario del loop
EgtSetInfo(tbInfo.nId, "Next", tbInfo.nNext)
EgtSetInfo(tbInfo.nId, "Prev", tbInfo.nPrev)
EgtSetInfo(tbInfo.nId, "Base", Pz_Top)
-- procedo a raccogliere tutte le altre info che mi servono per creare il pezzo
local nType = tbInfo.nType
if nType == 1 then
----- caratteristiche alzatina
tbInfo.dSideAngT = tbInfo.dPairAng - 90 -- side ang del lato top
tbInfo.dYOffset = tbInfo.dTh * tan(tbInfo.dSideAngT)
--nJunctionType = 2 -- trim end
--nJunctionType = 1 -- trim start
tbInfo.nJunctionType = 1 -- angle junction
tbInfo.bOnLoop = false
----- caratteristiche alzatina
elseif nType == 2 then
----- caratteristiche frontalino
tbInfo.dSideAngT = tbInfo.dPairAng + 90 -- side ang del lato top
tbInfo.dYOffset = tbInfo.dTh * tan(tbInfo.dSideAngT)
tbInfo.nJunctionType = 3 -- angle junction
tbInfo.bOnLoop = true
----- caratteristiche forntalino
end
-- if not tbInfo.bInLoop then
-- TOOL.CreateParetina( tbInfo.nEdgeId, tbIdLoopTC, tbInfo)
-- else
-- TOOL.CreateParetina( tbInfo.nEdgeId, tbIdInLoopTC, tbInfo)
-- end
TOOL.CreateParetina( tbInfo.nEdgeId, tbInfo)
-- setto l'offset dei riferimenti
if nType == 1 then
-- SPLASHTOP
tbInfo.sDestRefOff = '0,0,0'
tbInfo.sRefOff = tostring(tbInfo.dXOffset)..','..tostring(tbInfo.dYOffset)..',-x'
elseif nType == 2 then
-- WATERFALL
tbInfo.sDestRefOff = '0,0,-x'
tbInfo.sRefOff = '0,'..tostring(tbInfo.dYOffset)..',0'
end
end
-- creo tutte le paretine
for nPart, tbPart in pairs( tbPartsInfo) do
EgtOutLog(tostring(nPart))
local nEdge = tbPart.nEdge
local tbLayer = TOOL.FindLayers(nPart)
local tbIdLoop = TOOL.CreateAdjustedPart( tbLayer['OutLoop'],tbPart.dLen, tbPart.dH, tbPart.dAngBL, tbPart.dAngBR)
TOOL.CreatePart(tbLayer['OutLoop'],tbPart)
if not tbPart.bInLoop then
local nIdRefDest = TOOL.CreateReference( tbPart.nParent, 'OutLoop', 'A'..tostring(nEdge), dTh_TC, tbPart.sDestRefOff)
local nIdMyRef = TOOL.CreateReference( tbPart.nId, 'OutLoop', 'A3', tbPart.dTh, tbPart.sRefOff)
TOOL.SetPairInfo( tbPart, nIdMyRef, 'TopChicken', nIdRefDest, -1)
else
local nIdRefDest = TOOL.CreateReference( tbPart.nParent, 'InLoop', 'A'..tostring(nEdge), dTh_TC, tbPart.sDestRefOff)
local nIdMyRef = TOOL.CreateReference( tbPart.nId, 'OutLoop', 'A3', tbPart.dTh, tbPart.sRefOff)
TOOL.SetPairInfo( tbPart, nIdMyRef, 'TopChicken', nIdRefDest, -1)
end
if tbPart.dSideAngL then TOOL.SetSideAng(tbLayer['OutLoop'], 'A2', tbPart.dSideAngL) end
if tbPart.dSideAngR then TOOL.SetSideAng(tbLayer['OutLoop'], 'A4', tbPart.dSideAngR) end
if tbPart.dSideAngT then TOOL.SetSideAng(tbLayer['OutLoop'], 'A3', tbPart.dSideAngT) end
end
-- -- creo il fondo
-- devo ricavare "id del InPartA4" dalle info del TC
--CreateBottomPart( tbIdInLoopTC, -- id del 'InPartA4')
CreateSplitBottomPart( tbIdInLoopTC, Pz_Top, CMP.SWater)
TOOL.CreateDimensionLayer()
--SetReference()
--TOOL.SaveMePlease()
if CMP.DrawSolid then
loadfile(sPath ..'\\'.. "CreateSOLID_FromPartsInPark.lua")({AutoRun=true})
TOOL.RelocateLabels()
loadfile(sPath ..'\\'.. "OperationOnSolid.lua")({AutoRun=true, nVeinCtx=EgtGetContext()})
AddDimensions()
end
-- Se non ci sono errori salvo i dati
if CMP.ERR == 0 then
-- scrivo i parametri nelle info del pezzo !! DA FARE !!
-- WriteCompoDataToPart( Pz, CMP.Nome, CMP.Npar)
-- salvo i parametri come nuovo default
SaveCompoData(CMP.Npar)
OrigData()
end
--EgtSaveFile("D:\\Temp\\marmo\\Vein3D\\piano_assemblato.nge")
end
end
--CMP_Draw()
_G.CMP_Draw = CMP_Draw
BIN
View File
Binary file not shown.