using Egw.Window.Data; using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using NLog; using System.Collections.Generic; using System.Threading.Tasks; using WebWindowComplex.Compo; using WebWindowComplex.DTO; using WebWindowComplex.Json; using WebWindowComplex.Models; using static WebWindowComplex.Json.WindowConst; using static WebWindowComplex.LayoutConst; namespace WebWindowComplex { public partial class TableComp : IDisposable { #region Public Enums public enum DataReq { /// /// Nessuna richiesta /// None = 0, /// /// Richiesta hardware opzioni /// ReqHwOpt, /// /// Richiesta svg /// ReqSvg, /// /// Richiesta shape sash group /// ReqShape, /// /// Richiesta element /// ReqElement } #endregion Public Enums #region Public Properties /// /// Classe override css x SVG (x rescale) /// [Parameter] public string CssSvg { get; set; } = "responsive-svg"; /// /// Preselezione valori /// [Parameter] public SelectPayload? SelectionData { get; set; } = null; /// /// Richiesta azione al parent /// [Parameter] public EventCallback EC_ActionReq { get; set; } /// /// Richiesta update da JWD (SVG, calcoli vari...) /// [Parameter] public EventCallback> EC_DoUpdate { get; set; } /// /// Richiesta chiusura JWD (+ refresh) /// se torna true --> richiesta salvataggio /// se torna false --> richiesta revert /// [Parameter] public EventCallback EC_OnClose { get; set; } /// /// Sollevo evento errore validazione con una lista di errori rilevati /// [Parameter] public EventCallback> EC_ValidError { get; set; } /// /// Elenco anagrafiche di base /// [Parameter] public BaseListPayload ListPayload { get; set; } = null!; /// /// Dati live controllo (JWD, SVG, ...) /// [Parameter] public LivePayload LiveData { get; set; } = null!; /// /// Livello di accesso (utente base) /// [Parameter] public bool baseUser { get; set; } = false!; #endregion Public Properties #region Public Methods public void Dispose() { if (m_CurrWindow != null) { m_CurrWindow = null; } } #endregion Public Methods #region Protected Fields protected List currLoading = new List(); /// /// Dati live precedenti x comparazione /// protected LivePayload? prevLiveData = null; #endregion Protected Fields #region Protected Properties protected List FillList { get => m_FillList; } protected Frame FrameWindow { get => m_Frame!; set => m_Frame = value; } protected List ItemTableList { get => m_ItemTableList; } /// /// Componente SVG da mostrare /// protected MarkupString outSvg { get { // aggiunta gestione classe svg per posizionamento con costraints var newSvg = LiveData.SvgPreview.Replace(" SashList { get => m_SashList; } protected List SplittedList { get => m_SplittedList; } protected List SplitList { get => m_SplitList; } protected string SelColorMaterial { get; set; } = ""; protected string SelFamilyHardware { get; set; } = ""; protected string SelGlass { get; set; } = ""; protected string SelMaterial { get; set; } = ""!; protected string SelProfile { get; set; } = ""; #endregion Protected Properties #region Protected Methods /// /// Metodo per riempire la lista ItemTable in modo da poter rappresentarla come tabella /// /// Area da classificare /// numero di riga /// numero di colonna /// numero di riga massimo /// numero di colonna massimo protected void CreateElementTable(Area node, int row, int col, int maxRow, int maxCol) { if (node != null) { switch (node.AreaType) { case AreaTypes.FRAME: { if (node.AreaList.Count >= 1) ItemTableList.Add(new ItemTable(AreaTypes.FRAME, "FR", row, col, -1, node.AreaList.Count)); else ItemTableList.Add(new ItemTable(AreaTypes.FRAME, "FR", row, col, -1, 0)); row++; col++; maxRow++; maxCol++; break; } case AreaTypes.SASH: { string nWIndow; // Se ha fratelli if ((node.ParentArea.ParentArea != null && node.ParentArea.ParentArea.AreaList.Count > 1) || (node.ParentArea != null && node.ParentArea.AreaList.Count > 1)) { for (int i = 0; i < SashList.Count; i++) { if (SashList[i].Equals(node)) { nWIndow = SashList.Count == 1 ? "" : $"{i + 1}"; // Se il nodo ha figli, salvo il numero nell'oggetto if (node.AreaList.Count >= 1) ItemTableList.Add(new ItemTable(AreaTypes.SASH, "SG" + nWIndow, maxRow, col, i, node.AreaList.Count)); else ItemTableList.Add(new ItemTable(AreaTypes.SASH, "SG" + nWIndow, maxRow, col, i, 0)); } } maxCol++; } else { // Se il nodo ha figli, salvo il numero nell'oggetto if (node.AreaList.Count >= 1) ItemTableList.Add(new ItemTable(AreaTypes.SASH, "SG", row, col, 0, node.AreaList.Count)); else ItemTableList.Add(new ItemTable(AreaTypes.SASH, "SG", row, col, 0, 0)); maxCol++; } row++; col++; maxRow++; break; } case AreaTypes.FILL: { if ((node.ParentArea.AreaList.Count > 1 && node.ParentArea.AreaList.First().Equals(node)) || (node.ParentArea.ParentArea != null && node.ParentArea.ParentArea.AreaList.Count > 1 && node.ParentArea.ParentArea.AreaList.First().AreaList.First().Equals(node))) maxCol++; string nFill; for (int i = 0; i < FillList.Count; i++) { if (FillList[i].Equals(node)) { nFill = FillList.Count == 1 ? "" : $"{i + 1}"; if(node.AreaList.Count == 0) ItemTableList.Add(new ItemTable(AreaTypes.FILL, "FL" + nFill, maxRow, col, i, 0)); else ItemTableList.Add(new ItemTable(AreaTypes.FILL, "FL" + nFill, maxRow, col, i, node.AreaList.Count)); break; } } row++; col++; maxRow++; break; } case AreaTypes.SPLIT: { // Se il nodo ha fratelli o cugini if (node.ParentArea.AreaList.Count > 1 || (node.ParentArea.ParentArea != null && node.ParentArea.ParentArea.AreaList.Count > 1)) { if (node.ParentArea.AreaList.First().Equals(node) || node.ParentArea.ParentArea.AreaList.First().Equals(node)) maxCol++; for (int i = 0; i < SplitList.Count; i++) { if (SplitList[i].Equals(node)) { string nSplit = SplitList.Count == 1 ? "" : $"{i + 1}"; if (node.AreaList.Count >= 1) ItemTableList.Add(new ItemTable(AreaTypes.SPLIT, "SP" + nSplit, maxRow, col, i, node.AreaList.Count)); else ItemTableList.Add(new ItemTable(AreaTypes.SPLIT, "SP" + nSplit, maxRow, col, i, 0)); } } } else { for (int i = 0; i < SplitList.Count; i++) { if (SplitList[i].Equals(node)) { string nSplit = SplitList.Count == 1 ? "" : $"{i + 1}"; if (node.AreaList.Count >= 1) ItemTableList.Add(new ItemTable(AreaTypes.SPLIT, "SP" + nSplit, row, col, i, node.AreaList.Count)); else ItemTableList.Add(new ItemTable(AreaTypes.SPLIT, "SP" + nSplit, row, col, i, 0)); maxCol++; } } } row++; col++; maxRow++; break; } case AreaTypes.SPLITTED: { break; } } foreach (var item in node.AreaList) { if (maxRow < m_maxRow) CreateElementTable(item, row, col, m_maxRow, maxCol); else CreateElementTable(item, row, col, maxRow, maxCol); } } if (maxCol > m_maxCol) { m_maxCol = maxCol; } if (maxRow > m_maxRow) { m_maxRow = maxRow; } } /// /// Metodo per riempire le liste Sash, Split, Splitted e Fill /// /// Area da classificare /// Parametro per sapere se si è dentro un'anta protected void CreateWindowsList(Area node, bool IntoSash) { if (node != null) { if (node.ParentArea is Sash || IntoSash == true) IntoSash = true; switch (node.AreaType) { case AreaTypes.FRAME: { FrameWindow = (Frame)node; break; } case AreaTypes.SASH: { m_SashList.Add((Sash)node); break; } case AreaTypes.FILL: { m_FillList.Add((Fill)node); break; } case AreaTypes.SPLIT: { m_SplitList.Add((Split)node); break; } case AreaTypes.SPLITTED: { if (node.ParentArea is Split && !IntoSash && node.AreaList.First() is Fill) { m_SplittedList.Add((Splitted)node); } break; } } foreach (var item in node.AreaList) { CreateWindowsList(item, IntoSash); } } } /// /// Calcola CSS warning /// /// /// protected string cssValid(string fKey) { return listWarnings.ContainsKey(fKey) ? "border border-danger" : ""; } /// /// Richiesta chiusura SENZA salvataggio (= restore prev) /// /// protected Task DoClose() { editLock = false; Log.Info("Richietsa Chiusura"); //return EC_OnClose.InvokeAsync(false); if (m_CurrWindow != null) { #if DEBUG var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(), Formatting.Indented); #else var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize()); #endif //manca salvataggio JWD DataSave dataSave = new DataSave() { currJwd = CurrJwd, open = false, }; return EC_OnClose.InvokeAsync(dataSave); } return null; } /// /// Richiesta update anteprima SVG /// /// Forza richiesta anche con JWD invariato /// Nasconde hw (def. false) poiché senza è piu rapido /// protected async Task DoPreviewSvg(bool doForce = false, bool hideHw = false) { if (m_CurrWindow != null) { #if DEBUG var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(false), Formatting.Indented); var CalcJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(hideHw), Formatting.Indented); #else var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(false)); var CalcJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(hideHw)); #endif // verifico variazione JWD if (!prevJwd.Equals(CurrJwd) || doForce || prevReq != (int)DataReq.ReqSvg) { Log.Info("Richietsa svg"); prevJwd = CurrJwd; prevReq = (int)DataReq.ReqSvg; Dictionary Args = new Dictionary(); Args.Add("Mode", $"{(int)Enums.QuestionModes.PREVIEW}"); Args.Add("SerializedData", CalcJwd); await EC_DoUpdate.InvokeAsync(Args); } } } /// /// Richiesta calcolo Options HW /// /// Lista degli ID numerici dei gruppi da valutare /// protected async Task DoReqOptHardware(List groupIdList, bool isFirst = false) { if (m_CurrWindow != null) { loadListAdd("LoadHwOpt"); #if DEBUG var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(), Formatting.Indented); #else var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize()); #endif // verifico variazione JWD if (!prevJwd.Equals(CurrJwd) || isFirst || prevReq != (int)DataReq.ReqHwOpt) { Log.Info("Richietsa Hardware option"); prevJwd = CurrJwd; prevReq = (int)DataReq.ReqHwOpt; Dictionary Args = new Dictionary(); Args.Add("Mode", $"{(int)Enums.QuestionModes.HARDWARE}"); Args.Add("SubMode", $"{(int)Enums.QuestionHwSubModes.HARDWAREOPTIONS}"); Args.Add("SerializedData", CurrJwd); string listGroupId = JsonConvert.SerializeObject(groupIdList); Args.Add("GroupId", listGroupId); await EC_DoUpdate.InvokeAsync(Args); } } } /// /// Richiesta Shape compatibile da JWD /// /// Lista degli ID numerici dei gruppi da valutare /// protected async Task DoReqShape(List groupIdList) { if (m_CurrWindow != null) { #if DEBUG var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(), Formatting.Indented); #else var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize()); #endif // verifico variazione JWD if (!prevJwd.Equals(CurrJwd) || prevReq != (int)DataReq.ReqShape) //if (!prevLiveData.CurrJwd.Equals(CurrJwd)) { Log.Info("Richietsa shape"); prevJwd = CurrJwd; prevReq = (int)DataReq.ReqShape; Dictionary Args = new Dictionary(); Args.Add("Mode", $"{(int)Enums.QuestionModes.HARDWARE}"); Args.Add("SubMode", $"{(int)Enums.QuestionHwSubModes.SASHSHAPE}"); Args.Add("SerializedData", CurrJwd); string listGroupId = JsonConvert.SerializeObject(groupIdList); Args.Add("GroupId", listGroupId); await EC_DoUpdate.InvokeAsync(Args); } } } /// /// Richiesta Profili Element da JWD /// /// protected async Task DoReqElement(List groupIdList) { if (m_CurrWindow != null) { #if DEBUG var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(), Formatting.Indented); #else var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize()); #endif // verifico variazione JWD if (!prevJwd.Equals(CurrJwd) || prevReq != (int)DataReq.ReqElement) { Log.Info("Richietsa Profili Elementi"); prevJwd = CurrJwd; prevReq = (int)DataReq.ReqElement; Dictionary Args = new Dictionary(); Args.Add("Mode", $"{(int)Enums.QuestionModes.HARDWARE}"); Args.Add("SubMode", $"{(int)Enums.QuestionHwSubModes.PROFILEDATAFROMAREA}"); Args.Add("SerializedData", CurrJwd); string listGroupId = JsonConvert.SerializeObject(groupIdList); Args.Add("GroupId", listGroupId); await EC_DoUpdate.InvokeAsync(Args); } } } /// /// Metodo di reset /// protected Task DoReset() { Log.Info("Richietsa reset"); return Task.CompletedTask; // Da fare } /// /// Richiesta chiusura con salvataggio /// /// protected Task DoSave() { editLock = false; Log.Info("Richietsa Salvataggio"); //return EC_OnClose.InvokeAsync(false); if (m_CurrWindow != null) { #if DEBUG var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(), Formatting.Indented); #else var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize()); #endif //manca salvataggio JWD DataSave dataSave = new DataSave() { currJwd = CurrJwd, open = true, }; return EC_OnClose.InvokeAsync(dataSave); } return null; } protected override void OnAfterRender(bool firstRender) { isRendered = true; } /// /// Primo init componente /// protected override void OnInitialized() { // reset editLock... editLock = false; listErrPre = new Dictionary(); listErrLink = new Dictionary(); listWarnings = new Dictionary(); } /// /// Gestione update post ricezione parametri da controllo chiamante /// protected override async Task OnParametersSetAsync() { isLoading = true; // SOLO SE sono presenti... if (ListPayload.IsPopulated() && LiveData.IsValid()) { bool updRequested = false; listErrPre = new Dictionary(); listErrLink = new Dictionary(); listWarnings = new Dictionary(); // controllo elenchi BasePayload siano validi... if (ListPayload.IsValid()) { // SOLO SE modificato live data... if (prevLiveData == null || !prevLiveData.Equals(LiveData)) { bool needDeser = prevLiveData == null || !prevLiveData.JwdEqual(LiveData); updRequested = true; prevLiveData = new LivePayload() { CurrJwd = LiveData.CurrJwd, DictOptionsXml = LiveData.DictOptionsXml, DictShape = LiveData.DictShape, SvgPreview = LiveData.SvgPreview, ProfElementList = LiveData.ProfElementList }; // Aggiornati parametri di ingresso selezionati UpdateSelParameter(); // provo a deserializzare SE necessario if (needDeser) { JsonWindow WindowFromJson = new JsonWindow("", "", "", ""); try { WindowFromJson = JsonConvert.DeserializeObject(LiveData.CurrJwd, new PolymorphicJsonConverter()) ?? new JsonWindow("", "", "", ""); UpdateInputList(WindowFromJson); setCurrWindow(WindowFromJson); //SOLO SE non sono in edit... if (!editLock) { currStep = CompileStep.Tree; } } // altrimenti errore! catch (Exception ex) { listErrLink.Add("Window", $"Deserializing Error:{Environment.NewLine}{ex}"); Log.Error($"Errore nel deserializzare jwd: {ex.Message}"); // uso un oggetto "basico" per non fermarmi await BuildFrameDefault(); } } else { // usando m_currWindow (preesistente) impostare i parametri... UpdateDict(); } } if (m_CurrWindow != null && m_CurrWindow.AreaList != null && m_CurrWindow.AreaList.Count > 0) { checkWarnings(); if (SashList.Count > 0) { currAntaIndex = 0; } if (updRequested) { // se mancasse dizionario forme chiamo quello if (LiveData.DictShape.Count == 0 && listErrLink.Count == 0) { if (firstDisplay && isRendered) { firstDisplay = false; // preview SVG senza HW await DoPreviewSvg(true, true); if(LiveData.ProfElementList.Count == 0) await UpdateElement(FrameWindow); } List reqList = SashList.Select(x => x.GroupId).ToList(); if (reqList.Count > 0) { await DoReqShape(reqList); } } else { // chiedo SVG if (prevReq != (int)DataReq.ReqSvg || !prevLiveData.JwdEqual(LiveData.CurrJwd)) { if (prevReq != (int)DataReq.ReqHwOpt) await DoPreviewSvg(true); else if (LiveData.DictOptionsXml.Count > 0) await DoPreviewSvg(true); } } } } else { await BuildFrameDefault(); } } else { checkErrorPre(); } isLoading = false; } } private Task BuildFrameDefault() { // Costruisco window e setto i parametri Window window = new Window(); window.sProfilePath = "Profilo78"; window.sMaterial = "Pino"; window.sGlass = "Vetro BE 2S 4T/16/4T"; window.sColorMaterial = "Wood"; // Costruisco frame e setto i parametri Frame frame = new Frame(null, window); frame.SetGroupId(1); frame.SetAreaType(AreaTypes.FRAME); frame.SetSelShape(Shapes.RECTANGLE); frame.SetSelThresholdFromName("Bottom"); frame.SetBottomRail(false); frame.SetBottomRailQty(0); window.AreaList.Add(frame); List DimensionList = new List { new FrameDimension(frame, 1, "Width", 800, false), new FrameDimension(frame, 1, "Height", 1200, true) }; List JointList = new List { new Joint(frame, 1, Joints.FULL_H), new Joint(frame, 2, Joints.FULL_H), new Joint(frame, 3, Joints.FULL_H), new Joint(frame, 4, Joints.FULL_H) }; frame.JointList = JointList; frame.DimensionList = DimensionList; // Costruisco fill e setto i parametri Fill fill = new Fill(frame, window); fill.AreaType = AreaTypes.FILL; fill.SelFillType = FillTypes.GLASS; fill.GroupId = 2; frame.AreaList.Add(fill); JsonWindow jsonWindow = window.Serialize(); string jwd = JsonConvert.SerializeObject(jsonWindow); JsonWindow WindowFromJson = JsonConvert.DeserializeObject(jwd, new PolymorphicJsonConverter()) ?? new JsonWindow("", "", "", ""); setCurrWindow(WindowFromJson); return DoPreviewSvg(true); } /// /// Metodo per controllare che non ci siano duplicati di GroupId /// /// /// protected bool CheckGroupId(Window window) { List groupIdList = new List(); SearchInWindow(window.AreaList.First(), groupIdList); var duplicati = groupIdList.GroupBy(x => x) .Where(g => g.Count() > 1) .Select(g => g.Key) .ToList(); if (duplicati.Count > 0) return false; else return true; } /// /// Metodo per costruire oggetti della Window /// /// protected void setCurrWindow(JsonWindow WindowFromJson) { if (m_CurrWindow != null) { m_CurrWindow = null; } m_CurrWindow = WindowFromJson.Deserialize(); groupIdOK = CheckGroupId(m_CurrWindow); if (m_CurrWindow.AreaList != null && m_CurrWindow.AreaList.Count > 0 && groupIdOK) { FrameWindow = m_CurrWindow.AreaList[0]; if (m_PreviousWindow != null) { for (int i = 0; i < 2; i++) m_CurrWindow.AreaList.First().DimensionList[i].dDimension = m_PreviousWindow.AreaList.First().DimensionList[i].dDimension; if (m_CurrWindow.AreaList.First().Shape == Shapes.TRIANGLE) { for (int i = 0; i < 2; i++) m_CurrWindow.AreaList.First().JointList[i].SetSelJointType(m_PreviousWindow.AreaList.First().JointList[i].SelJointType); } else { for (int i = 0; i < 4; i++) m_CurrWindow.AreaList.First().JointList[i].SetSelJointType(m_PreviousWindow.AreaList.First().JointList[i].SelJointType); } } if (m_CurrWindow != null) { // Aggiornamento liste sash, split, splitted, fill e itemTable UpdateLists(); } if (SashList.Count > 0) currAntaIndex = 0; // Aggiorno window con dati shape e hw option UpdateDict(); } } /// /// Aggiornamento dei dati con informazioni ricevute dai dizionari /// protected void UpdateDict() { // se ho i dizionari delle forme le aggiungo if (LiveData.DictShape.Count > 0) { // Inserisco le forme ricevuto nei sash group foreach (var item in LiveData.DictShape) { //Sash sashFromGroupId = SashList.First(x => x.GroupId == item.Key); var sashFromGroupId = SashList.FirstOrDefault(x => x.GroupId == item.Key); if (sashFromGroupId != null) { sashFromGroupId.SashShape = item.Value; sashFromGroupId.UpdateShape(item.Value); } } if (prevReq == (int)DataReq.ReqShape) { if (reqHwOpt > 0) { List reqList = SashList.Select(x => x.GroupId).ToList(); if (reqList.Count > 0) { _ = DoReqOptHardware(reqList); } } } } // se ho le opzioni hw le aggiungo if (LiveData.DictOptionsXml.Count > 0) { loadListRem("LoadHwOpt"); foreach (var item in SashList) { if (LiveData.DictOptionsXml.ContainsKey(item.GroupId)) { item.SetHardwareOption(LiveData.DictOptionsXml[item.GroupId]); } } } if (LiveData.ProfElementList.Count > 0) { //List OrderedListProf = LiveData.ProfElementList.OrderBy(x => x.GroupId).ToList(); // Inserisco i profili ricevuti nei rispettivi Element foreach (var item in LiveData.ProfElementList) { UpdateProfileElement(item.Profiles, item.GroupId, item.EntId); } } } /// /// Metodo che resetta le liste (sash, split, splitted, fill e itemTable) e le crea nuovamente /// protected void UpdateLists() { m_maxCol = 0; m_maxRow = 0; m_FillList = new List(); m_SashList = new List(); m_SplitList = new List(); m_SplittedList = new List(); m_ItemTableList = new List(); CreateWindowsList((m_CurrWindow!).AreaList.First(), false); CreateElementTable(m_CurrWindow.AreaList.First(), 1, 1, 1, 1); foreach (var item in ItemTableList) { if (item.NumChild > 4) { if (!RowCollapsed.ContainsKey(item.Row)) { RowCollapsed.Add(item.Row, false); Child.Add(item.Row, item.NumChild); } } else if(RowCollapsed.ContainsKey(item.Row)) { RowCollapsed.Remove(item.Row); } } } /// /// Metodo per settare i parmateri di ingresso selezionati /// protected void UpdateInputList(JsonWindow WindowFromJson) { string profile = WindowFromJson.ProfilePath; Window.m_ParameterList = ListPayload.ProfileList?.FirstOrDefault(x => x.ProfileName.Equals(profile))?.ParameterDict ?? new(); Frame.m_AllThresholdList = ListPayload.ProfileList?.FirstOrDefault(x => x.ProfileName.Equals(profile))?.ThresholdList ?? new(); Sash.m_HardwareCompleteList = ListPayload.Hardware; Sash.s_FamilyHardwareList = ListPayload.FamilyHardware; } /// /// Metodo per settare i parmateri di ingresso selezionati /// protected void UpdateSelParameter() { if (SelectionData != null && SelectionData.IsValid()) { SelFamilyHardware = SelectionData.FamilyHardware ?? ""; SelColorMaterial = SelectionData.ColorMaterial ?? ""; SelMaterial = SelectionData.Material ?? ""; SelGlass = SelectionData.Glass ?? ""; SelProfile = SelectionData.Profile ?? ""; } } #endregion Protected Methods #region Private Fields private int currAntaIndex = 0; private int currFillIndex = -1; private int currSashIndex = -1; private int currSplitIndex = -1; private CompileStep currStep; private bool editLock = false; private bool firstDisplay = true; private bool groupIdOK = false; /// /// Booleana fase loading /// private bool isLoading = false; private bool isRendered = false; /// /// ELenco errori di coerenza/link dati (vanno risolti per disegnare/procedere) /// private Dictionary listErrLink = new Dictionary(); /// /// Elenco errori preliminari (mancano elementi di base di validazione modello dati)) /// private Dictionary listErrPre = new Dictionary(); /// /// Elenco warnings non bloccanti /// private Dictionary listWarnings = new Dictionary(); private Frame? m_Frame; private List m_ItemTableList = new List(); private int m_maxCol = 0; private int m_maxRow = 0; private List m_SashList = new List(); private List m_SplitList = new List(); private List m_FillList = new List(); private List m_SplittedList = new List(); private Dictionary RowCollapsed { get; set; } = new Dictionary(); private Dictionary Child { get; set; } = new Dictionary(); private static Logger Log = LogManager.GetCurrentClassLogger(); #endregion Private Fields #region Private Properties private Window? m_CurrWindow { get; set; } = null; private Window? m_PreviousWindow { get; set; } = null; /// /// Salvataggio JWD precedente x evitare loop su update (aggiornato dopo chiamate redis) /// private string prevJwd { get; set; } = ""; /// /// Salvataggio tipo di domanda precedente /// private int prevReq { get; set; } = 0; private int reqHwOpt { get; set; } = 0; #endregion Private Properties #region Private Methods /// /// Metodo per andare allo step successivo /// /// step successivo private void AdvStep(CompileStep newStep) { currStep = newStep; currSashIndex = -1; currFillIndex = -1; currSplitIndex = -1; } /// /// Verifica errori prelimionari per mostrare dove sia il problema /// private void checkErrorPre() { // verifico 1:1 le liste e indico cosa manca if (ListPayload.Hardware == null || ListPayload.Hardware.Count == 0) { listErrPre.Add("Hardware", "Missing Hardware List!"); Log.Warn("Missing Hardware List"); } else { if (ListPayload.FamilyHardware == null || ListPayload.FamilyHardware.Count == 0) { listErrPre.Add("FamilyHardware", "Missing Family HW List!"); Log.Warn(" Missing Family HW List"); } } if (ListPayload.Glass == null || ListPayload.Glass.Count == 0) { listErrPre.Add("Glass", "Missing Glass List!"); Log.Warn(" Missing Glass List"); } if (ListPayload.Material == null || ListPayload.Material.Count == 0) { listErrPre.Add("Material", "Missing Material List!"); Log.Warn(" Missing Material List"); } if (ListPayload.ColorMaterial == null || ListPayload.ColorMaterial.Count == 0) { listErrPre.Add("ColorMaterial", "Missing ColorMaterial List!"); Log.Warn("Missing ColorMaterial List"); } if (ListPayload.ProfileList == null || ListPayload.ProfileList.Count == 0) { listErrPre.Add("Profile", "Missing Profile data!"); Log.Warn("Missing Profile data"); } } /// /// Verifica warning minori (es coerenza colori...) /// private void checkWarnings() { // verifico 1:1 le liste e i valori siano coerenti... if (ListPayload.ColorMaterial != null && ListPayload.ColorMaterial.Count > 0) { if (m_CurrWindow != null) { if (ListPayload.ColorMaterial == null || !ListPayload.ColorMaterial.Contains(m_CurrWindow.sColorMaterial)) { listWarnings.Add("ColorMaterial", $"Missing Color: {m_CurrWindow.sColorMaterial}"); } if (ListPayload.Glass == null || !ListPayload.Glass.Contains(m_CurrWindow.sGlass)) { listWarnings.Add("Glass", $"Missing Glass: {m_CurrWindow.sGlass}"); } if (ListPayload.Material == null || !ListPayload.Material.Contains(m_CurrWindow.sMaterial)) { listWarnings.Add("Material", $"Missing Material: {m_CurrWindow.sMaterial}"); } if (ListPayload.ProfileList == null || !ListPayload.ProfileList.Any(x => x.ProfileName.Contains(m_CurrWindow.sProfilePath))) { listWarnings.Add("Profile", $"Missing Profile: {m_CurrWindow.sProfilePath}"); } if (!groupIdOK) { listWarnings.Add("GroupId", "JWD not correct!"); } } } } /// /// Helper aggiunta elemento a lista caricamento /// /// private void loadListAdd(string loadCode) { if (!currLoading.Contains(loadCode)) { currLoading.Add(loadCode); } } /// /// Helper rimozione elemento a lista caricamento /// /// private void loadListRem(string loadCode) { if (currLoading.Contains(loadCode)) { currLoading.Remove(loadCode); } } /// /// Metodo per cambiare step /// /// step successivo private void NextStep(CompileStep newStep, int Index = 1) { editLock = true; currStep = newStep; switch (newStep) { case CompileStep.Sash: { currSashIndex = Index; currFillIndex = -1; currSplitIndex = -1; break; } case CompileStep.Fill: { currFillIndex = Index; currSashIndex = -1; currSplitIndex = -1; break; } case CompileStep.Split: { currSplitIndex = Index; currSashIndex = -1; currFillIndex = -1; break; } } } /// /// Metodo per cambiare step /// /// private void NextStepArgs(DataNextStep Args) { CompileStep newStep = Args.currCompileStep; int Index = Args.index; NextStep(newStep, Index); } /// /// Metodo per aggiornare il valore collassato degli elementi della gerarchia /// /// private void CollapsedRowTree(Dictionary Args) { foreach(var item in Args) { RowCollapsed[item.Key] = Args[item.Key] ? true : false; if (m_ItemTableList.FirstOrDefault(x => x.Row == item.Key) != null) { Child[item.Key] = m_ItemTableList.FirstOrDefault(x => x.Row == item.Key)!.NumChild; } } } /// /// Richiesta reset dizionario Shape con action /// /// private Task ReqResetDict(DataUpdateRes args) { return EC_ActionReq.InvokeAsync(args.req); } /// /// Ritorno step Tree /// /// private void ReturnTree(bool args) { AdvStep(CompileStep.Tree); } ///// ///// Metodo per cercare un area precisa ///// ///// Area che si sta analizzando ///// Id Area che si sta cercando ///// Area che si sta cercando ///// //private Area SearchArea(Area currentArea, int idSearch, Area itemSearch) //{ // if (currentArea.GroupId == idSearch && currentArea.AreaType.Equals(itemSearch.AreaType)) // { // return currentArea; // } // foreach (Area child in currentArea.AreaList) // { // Area found = SearchArea(child, idSearch, itemSearch); // if (found != null) // { // return found; // } // } // return null; //} /// /// Metodo per cercare un area precisa partendo da GroupId /// /// Area che si sta analizzando /// Id Area che si sta cercando /// private Area? SearchAreaFromGroupId(Area currentArea, int idSearch) { if (currentArea.GroupId == idSearch) { return currentArea; } foreach (Area child in currentArea.AreaList) { Area? found = SearchAreaFromGroupId(child, idSearch); if (found != null) { return found; } } return null; } /// /// Metodo per aggiornare i nomi dei profili degli elementi /// /// Lista dei profili /// Id Area che si sta cercando /// Id dell'anta o dello split (se -1 non usare) /// private void UpdateProfileElement(List profileNameList, int GroupIdSearch, int EntityIdSearch) { // Cerco area corrispondente al GroupId Area? found = SearchAreaFromGroupId(FrameWindow, GroupIdSearch); List elemList = new List(); if (found != null) { switch (found.AreaType) { case AreaTypes.FRAME: { Frame frame = (Frame)found; for (int index = frame.ElementDimensionList.Count; index < profileNameList.Count; index++) { double valStd = Window.m_ParameterList.GetValueOrDefault(profileNameList.ElementAt(index) + "_DimStd"); frame.ElementDimensionList.Add(new ElementDimension(frame, index + 1, valStd)); } for (int i = 0; i < frame.ElementDimensionList.Count; i++) { frame.ElementDimensionList.ElementAt(i).SetNameElement(profileNameList.ElementAt(i)); } for (int index = profileNameList.Count; index < frame.ElementDimensionList.Count; index++) frame.ElementDimensionList.RemoveAt(index); elemList = frame.ElementDimensionList; foreach (var item in elemList) { string overlapName = string.Join("_", item.sName.Split('_').Skip(1)); item.SetOverlapElement(Window.m_ParameterList.GetValueOrDefault(overlapName + "_Overlap")); } foreach (var elem in frame.BottomRailElemDimList) { elem.SetOverlapElement(Window.m_ParameterList.GetValueOrDefault("Frame_BottomRail_Overlap")); } break; } case AreaTypes.SASH: { Sash sash = (Sash)found; SashDimension anta = sash.SashList.ElementAt(EntityIdSearch - 1); for (int index = anta.ElementDimensionList.Count; index < profileNameList.Count; index++) { double valStd = Window.m_ParameterList.GetValueOrDefault(profileNameList.ElementAt(index) + "_DimStd"); anta.ElementDimensionList.Add(new ElementDimension(sash, index + 1, valStd)); } int numElemDelete = anta.ElementDimensionList.Count - profileNameList.Count; for (int i = 0; i < numElemDelete; i++) { anta.ElementDimensionList.RemoveAt(anta.ElementDimensionList.Count - 1); } for (int index = profileNameList.Count; index < anta.ElementDimensionList.Count; index++) anta.ElementDimensionList.RemoveAt(index); for (int i = 0; i < anta.ElementDimensionList.Count; i++) { anta.ElementDimensionList.ElementAt(i).SetNameElement(profileNameList.ElementAt(i)); } SetOverlapSash(sash, anta, EntityIdSearch - 1, elemList); break; } case AreaTypes.SPLIT: { Split split = (Split)found; List SpElemList = split.searchElemFromSubArea(EntityIdSearch); for (int i = 0; i < SpElemList.Count; i++) { SpElemList.ElementAt(i).SetNameElement(profileNameList.ElementAt(i)); SpElemList.ElementAt(i).SetMinDimension(Window.m_ParameterList.GetValueOrDefault(SpElemList.ElementAt(i).sName + "_DimMin")); SpElemList.ElementAt(i).SetMaxDimension(Window.m_ParameterList.GetValueOrDefault(SpElemList.ElementAt(i).sName + "_DimMax")); if (SpElemList.ElementAt(i).dDimension > SpElemList.ElementAt(i).dMaxDim) { SpElemList.ElementAt(i).SetDimension(SpElemList.ElementAt(i).dMaxDim); Frame frame = split.ParentWindow.AreaList.First(); if (frame != null) { frame.SearchAreaList(frame, frame.AvailWidthArea(), "Width"); frame.SearchAreaList(frame, frame.AvailHeightArea(), "Height"); } } else if (SpElemList.ElementAt(i).dDimension < SpElemList.ElementAt(i).dMinDim) { SpElemList.ElementAt(i).SetDimension(SpElemList.ElementAt(i).dMinDim); Frame frame = split.ParentWindow.AreaList.First(); if (frame != null) { frame.SearchAreaList(frame, frame.AvailWidthArea(), "Width"); frame.SearchAreaList(frame, frame.AvailHeightArea(), "Height"); } } string overlapName = string.Join("_", SpElemList.ElementAt(i).sName.Split('_').Skip(1)); SpElemList.ElementAt(i).SetOverlapElement(Window.m_ParameterList.GetValueOrDefault(overlapName + "_Overlap")); } break; } } foreach (var item in elemList) { item.SetMinDimension(Window.m_ParameterList.GetValueOrDefault(item.sName + "_DimMin")); item.SetMaxDimension(Window.m_ParameterList.GetValueOrDefault(item.sName + "_DimMax")); if (item.dDimension > item.dMaxDim) item.SetDimension(item.dMaxDim); else if (item.dMaxDim < item.dMinDim) item.SetDimension(item.dMinDim); } } } private void SetOverlapSash(Sash sash, SashDimension anta, int indexAnta, List elemList) { string overlapNameBottom = ""; string overlapNameTop = ""; string overlapNameSx = ""; string overlapNameDx = ""; elemList = anta.ElementDimensionList; List elemOld = elemList; foreach(var elem in sash.BottomRailElemDimList) { elem.SetOverlapElement(Window.m_ParameterList.GetValueOrDefault("Sash_BottomRail_Overlap")); } if (sash.ParentArea is Frame || (sash.ParentArea.ParentArea is Split split && split.nSplitQtyHoriz == 0)) { Frame frame = sash.ParentWindow.AreaList.First(); if(frame.SelThreshold.Name.Contains("Threshold")) overlapNameBottom = "Sash_Threshold"; else overlapNameBottom = "Sash_Bottom"; overlapNameTop = "Sash_Top"; if(sash.ParentArea is Frame) { if(sash.SashList.Count == 1) { overlapNameDx = "Sash_Top"; overlapNameSx = "Sash_Top"; } else { if(indexAnta == 0) { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = "Sash_Top"; } else if (indexAnta == sash.SashList.Count - 1) { overlapNameDx = "Sash_Top"; overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } else { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } } } else { Split s = (Split)sash.ParentArea.ParentArea; int indexAreaSplit = s.AreaList.IndexOf(sash.ParentArea); int indexSplit = indexAreaSplit == 0 ? 0 : indexAreaSplit - 1; if (indexAreaSplit == 0) { if (sash.SashList.Count == 1) { if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameDx = "Mixed_Split_Top"; else overlapNameDx = "Sash_Vertical"; overlapNameSx = "Sash_Top"; } else { if(indexAnta == 0) { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = "Sash_Top"; } else if (indexAnta == sash.SashList.Count - 1) { if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameDx = "Mixed_Split_Top"; else overlapNameDx = "Sash_Vertical"; overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } else { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } } } else if (indexAreaSplit == s.AreaList.Count() - 1) { if (sash.SashList.Count == 1) { if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameSx = "Mixed_Split_Top"; else overlapNameSx = "Sash_Vertical"; overlapNameDx = "Sash_Top"; } else { if (indexAnta == 0) { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameSx = "Mixed_Split_Top"; else overlapNameSx = "Sash_Vertical"; } else if (indexAnta == sash.SashList.Count - 1) { overlapNameDx = "Sash_Top"; overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } else { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } } } else { if (sash.SashList.Count == 1) { if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameDx = "Mixed_Split_Top"; else overlapNameDx = "Sash_Vertical_Top"; if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameSx = "Mixed_Split_Top"; else overlapNameSx = "Sash_Vertical"; } else { if (indexAnta == 0) { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameSx = "Mixed_Split_Top"; else overlapNameSx = "Sash_Vertical"; } else if (indexAnta == sash.SashList.Count - 1) { if (s.ElemDimVertList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameDx = "Mixed_Split_Top"; else overlapNameDx = "Sash_Vertical"; overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } else { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } } } } } else if (sash.ParentArea.ParentArea is Split s && s.nSplitQtyHoriz > 0) { int indexAreaSplit = s.AreaList.IndexOf(sash.ParentArea); int indexSplit = indexAreaSplit == 0 ? 0 : indexAreaSplit - 1; if (indexAreaSplit == 0) { overlapNameBottom = "Sash_Bottom"; overlapNameTop = "Mixed_Split_Top"; } else if (indexAreaSplit == s.AreaList.Count() - 1) { if (s.ElemDimHorizList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameBottom = "Mixed_Split_Bottom"; else overlapNameBottom = "Sash_Horizontal_Bottom"; overlapNameTop = "Sash_Top"; } else { if (s.ElemDimHorizList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameBottom = "Mixed_Split_Bottom"; else overlapNameBottom = "Sash_Horizontal_Bottom"; if (s.ElemDimHorizList.ElementAt(indexSplit).sName.Contains("Mixed")) overlapNameTop = "Mixed_Split_Top"; else overlapNameTop = "Sash_Horizontal_Top"; } if (sash.SashList.Count == 1) { overlapNameDx = "Sash_Top"; overlapNameSx = "Sash_Top"; } else { if (indexAnta == 0) { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = "Sash_Top"; } else if (indexAnta == sash.SashList.Count - 1) { overlapNameDx = "Sash_Top"; overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } else { overlapNameDx = string.Join("_", elemList.ElementAt(1).sName.Split('_').Skip(1)); overlapNameSx = string.Join("_", elemList.Last().sName.Split('_').Skip(1)); } } } elemList.First().SetOverlapElement(Window.m_ParameterList.GetValueOrDefault(overlapNameBottom + "_Overlap")); elemList.ElementAt(1).SetOverlapElement(Window.m_ParameterList.GetValueOrDefault(overlapNameDx + "_Overlap")); for (int elem = 2; elem <= elemList.Count - 2; elem++) elemList.ElementAt(elem).SetOverlapElement(Window.m_ParameterList.GetValueOrDefault(overlapNameTop + "_Overlap")); elemList.Last().SetOverlapElement(Window.m_ParameterList.GetValueOrDefault(overlapNameSx + "_Overlap")); //bool recalcDim = false; //for(int i = 0; i < elemList.Count; i++) //{ // if (!elemList.ElementAt(i).Equals(elemOld.ElementAt(i))) // recalcDim = true; //} //if (recalcDim) //{ // Frame frame = sash.ParentWindow.AreaList.First(); // if (frame != null) // { // frame.SearchAreaList(frame, frame.AvailWidthArea(), "Width"); // frame.SearchAreaList(frame, frame.AvailHeightArea(), "Height"); // } //} } /// /// Metodo per aggiornare valori della sezione General /// /// private void UpdatePreviewGeneral(DataUpdateGeneral args) { string Color = args.Color; string Glass = args.Glass; string Material = args.Material; string Profile = args.Profile; if (m_CurrWindow != null) { if (!string.IsNullOrEmpty(Color)) m_CurrWindow.sColorMaterial = Color; else if (!string.IsNullOrEmpty(Glass)) m_CurrWindow.sGlass = Glass; else if (!string.IsNullOrEmpty(Material)) m_CurrWindow.sMaterial = Material; else if (!string.IsNullOrEmpty(Profile)) m_CurrWindow.sProfilePath = Profile; _ = DoPreviewSvg(); } } /// /// Calcola il css del tab selezionato /// /// Step /// private string tabNavCss(CompileStep testStep, int Index = -1) { if (testStep == CompileStep.Sash) { if ((currSashIndex == 0 && Index == 0) || (currSashIndex == 1 && Index == 1)) return "nav-link active fw-bold"; else return "nav-link text-dark"; } else if (testStep == CompileStep.Fill) { if ((currFillIndex == 0 && Index == 0) || (currFillIndex == 1 && Index == 1)) return "nav-link active fw-bold"; else return "nav-link text-dark"; } else if (testStep == CompileStep.Split) { if ((currSplitIndex == 0 && Index == 0) || (currSplitIndex == 1 && Index == 1)) return "nav-link active fw-bold"; else return "nav-link text-dark"; } return (testStep == currStep) ? "nav-link active fw-bold" : "nav-link text-dark"; } /// /// Metodo per cambiare tutti i Fill e richiedere aggiornamento SVG /// /// tipo di fill richiesto /// protected Task ChangeAllFill(FillTypes reqFillType) { updateAllFill(FrameWindow, reqFillType); return DoPreviewSvg(); } /// /// Metodo per aggiornare tutti i Fill al nuovo tipo /// /// area corrente /// tipo a cui aggiornare private void updateAllFill(Area area, FillTypes type) { if (area.AreaType.Equals(AreaTypes.FILL)) { Fill fill = (Fill)area; fill.SetSelFillType(type); return; } foreach (Area child in area.AreaList) { updateAllFill(child, type); } } /// /// Aggiornamento Fill /// /// Fill da aggiornare /// private async Task UpdatePreviewFill(Fill newFill) { if (newFill != null) { // cerco il record var currRec = (Fill?)SearchAreaFromGroupId(FrameWindow, newFill.GroupId); // lo aggiorno if(currRec != null) { currRec = newFill; await DoPreviewSvg(); } } } /// /// Aggiornamento Frame /// /// nuovo frame /// private async Task UpdatePreviewFrame(DataUpdateFrame args) { Frame newFrame = args.currFrame; bool forceSvgNoHw = args.svgNoHw; if (args.groupIdDelete != -1) RowCollapsed.Remove(args.groupIdDelete); if (newFrame != null) { // cerco il record var currRec = m_CurrWindow?.AreaList.FirstOrDefault(x => x.GroupId == newFrame.GroupId); // lo aggiorno currRec = newFrame; if (forceSvgNoHw) await DoPreviewSvg(true, true); else await DoPreviewSvg(); } } /// /// Aggiornamento opzioni dato nuovo frame /// /// nuovo frame /// private async Task UpdateHwOptionsFrame(Frame newFrame) { if (newFrame != null) { // cerco il record var currRec = m_CurrWindow?.AreaList.FirstOrDefault(x => x.GroupId == newFrame.GroupId); // lo aggiorno currRec = newFrame; // resetto hw lst await EC_ActionReq.InvokeAsync(DataAction.ResetHwOpt); reqHwOpt++; if (prevReq == (int)DataReq.ReqShape) { // richiesta calcolo opzioni hardware per la singola sash group List reqList = SashList.Select(x => x.GroupId).ToList(); // chiamo con gruppo della nuova sash await DoReqOptHardware(reqList); } } } /// /// Aggiornamento Element a causa di un cambiamento nella sash /// /// /// private async Task UpdateElementSash(Sash newSash) { if (newSash != null) { Sash currRec = (Sash)SearchAreaFromGroupId(FrameWindow, newSash.GroupId)!; currRec = newSash; await UpdateElement(FrameWindow); } } /// /// Aggiornamento Element a causa di un cambiamento nello split /// /// /// private async Task UpdateElementSplit(Split newSplit) { if (newSplit != null) { Split currRec = (Split)SearchAreaFromGroupId(FrameWindow, newSplit.GroupId)!; currRec = newSplit; await UpdateElement(FrameWindow); } } /// /// Aggiornamento Element a casua di un cambiamento nel frame /// /// nuovo frame /// private async Task UpdateElementFrame(Frame newFrame) { if (newFrame != null) { // cerco il record var currRec = m_CurrWindow?.AreaList.FirstOrDefault(x => x.GroupId == newFrame.GroupId); // lo aggiorno currRec = newFrame; // richiedo update element del frame await UpdateElement(FrameWindow); } } /// /// Aggiornamento Element /// /// nuovo frame /// private async Task UpdateElement(Frame newFrame) { if (newFrame != null) { // richiedo update element del frame List reqList = new List(); reqList.Add(FrameWindow.GroupId); // Aggiorno le liste sash, split m_FillList = new List(); m_SashList = new List(); m_SplitList = new List(); m_SplittedList = new List(); CreateWindowsList((m_CurrWindow!).AreaList.First(), false); ReqListGroupId(FrameWindow, reqList); //// richiedo update element della sash (se presenti) //if (SashList.Count > 0) //{ // foreach (var item in SashList) // { // reqList.Add(item.GroupId); // } //} //// richiedo update element degli split (se presenti) //if (SplitList.Count > 0) //{ // foreach (var item in SplitList) // { // reqList.Add(item.GroupId); // } //} await DoReqElement(reqList); } } private void ReqListGroupId(Area node, List groupId) { if (node.AreaList == null) return; if(node is Sash || node is Split) groupId.Add(node.GroupId); foreach (var child in node.AreaList) ReqListGroupId(child, groupId); } /// /// Aggiornamento opzioni data nuova sash group /// /// nuovo frame /// private async Task UpdateHwOptionsSash(Sash newSash) { if (newSash != null) { // cerco il record var currRec = SearchAreaFromGroupId(FrameWindow, newSash.GroupId); // lo aggiorno currRec = newSash; // resetto hw lst await EC_ActionReq.InvokeAsync(DataAction.ResetHwOpt); // richiesta calcolo opzioni hardware per la singola sash group List reqList = SashList.Select(x => x.GroupId).ToList(); // chiamo con gruppo della nuova sash await DoReqOptHardware(reqList); //} } } /// /// Richiesta opzioni hardware per la prima volta /// /// nuovo frame /// private async Task ReqFirstOptionHw(Sash newSash) { if (newSash != null) { // cerco il record var currRec = SearchAreaFromGroupId(FrameWindow, newSash.GroupId); // lo aggiorno currRec = newSash; // resetto hw lst await EC_ActionReq.InvokeAsync(DataAction.ResetHwOpt); // richiesta calcolo opzioni hardware per la singola sash group List reqList = SashList.Select(x => x.GroupId).ToList(); // chiamo con gruppo della nuova sash await DoReqOptHardware(reqList); } } /// /// Aggiornamento Frame /// /// nuovo frame /// private async Task UpdatePreviewSplit(DataUpdateSplit args) { Split newSplit = args.currSplit; bool forceSvgNoHw = args.svgNoHw; bool noSvg = args.noSvg; if (newSplit != null) { // cerco il record var currRec = SearchAreaFromGroupId(FrameWindow, newSplit.GroupId); // lo aggiorno currRec = newSplit; if (!noSvg) { if (forceSvgNoHw) await DoPreviewSvg(true, true); else await DoPreviewSvg(); } } } /// /// Metodo per aggiornare Splitted /// /// Splitted da aggiornare /// private async Task UpdatePreviewSplitted(Splitted currSplitted) { if (currSplitted != null) { var item = SearchAreaFromGroupId(FrameWindow, currSplitted.GroupId); item = currSplitted; // ricalcolo liste UpdateLists(); // richiedo update shape List reqList = SashList.Select(x => x.GroupId).ToList(); await DoPreviewSvg(); await UpdateElement(FrameWindow); await DoReqShape(reqList); } } /// /// Aggiornamento opzioni dato update sash /// /// nuova sash /// private async Task UpdatePreviewSashGroup(DataUpdateSash args) { Sash newSash = args.currSash; bool svgNoHw = args.svgNoHw; bool noSvg = args.noSvg; if (svgNoHw) { Sash? item = (Sash?)SearchAreaFromGroupId(FrameWindow, newSash.GroupId); if (newSash != null && item != null) { item = newSash; await DoPreviewSvg(true, true); } } else { Sash? item = (Sash?)SearchAreaFromGroupId(FrameWindow, newSash.GroupId); if (newSash != null && item != null) { item = newSash; if (!noSvg) await DoPreviewSvg(); } } } /// /// Calcola bottone per tutti i Fill /// /// private string buttonFillCss(FillTypes reqFillTypes) { foreach (var fill in FillList) { if (!fill.FillType.Equals(reqFillTypes)) return "btn btn-outline-secondary btn-sm"; } return "btn btn-secondary btn-sm"; } /// /// Metodo per ottenere lista groupId /// /// Area da aggiungere alla lista groupId /// Lista group id protected void SearchInWindow(Area node, List groupIdList) { if (node != null) { groupIdList.Add(node.GroupId); foreach (var item in node.AreaList) { SearchInWindow(item, groupIdList); } } } #endregion Private Methods } public class DataSave { public string currJwd { get; set; } public bool open { get; set; } = false; } }