using Egw.Window.Data; using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using System.Reflection.Metadata; using WebWindowComplex.Compo; using WebWindowComplex.DTO; using WebWindowComplex.Json; using WebWindowComplex.Models; using static WebWindowComplex.LayoutConst; using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex { public partial class TableComp : IDisposable { #region Public Enums public enum DataAction { /// /// Nessuna richiesta /// None = 0, /// /// Reset dizionario shape /// ResetDictShape } public enum DataReq { /// /// Nessuna richiesta /// None = 0, /// /// Richiesta hardware opzioni /// ReqHwOpt, /// /// Richiesta svg /// ReqSvg, /// /// Richiesta shape sash group /// ReqShape } #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? CurrSelection { 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!; #endregion Public Properties #region Public Methods public void Dispose() { if (m_CurrWindow != null) { m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview; m_CurrWindow.OnReqHwOption -= M_CurrWindow_OnHwOption; m_CurrWindow.OnReqShape -= M_CurrWindow_OnShape; m_CurrWindow = null; } } #endregion Public Methods #region Protected Fields /// /// 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 string SelColorMaterial { get; set; } = ""; protected string SelFamilyHardware { get; set; } = ""; protected string SelGlass { get; set; } = ""; protected string SelMaterial { get; set; } = ""!; protected string SelProfile { get; set; } = ""; protected List SplitList { get => m_SplitList; } #endregion Protected Properties #region Protected Methods /// /// Metodo per la scelta della maniglia univoca /// /// anta su cui si seleziona la maniglia /// protected void ChangeHandle(DataChangeHandle Args) { SashDimension sashDim = Args.currSashDimension; Sash currSash = Args.currItem; // Cerco la Sash che si sta considerando nella lista Sash var s = SashList.Where(x => x.GroupId == currSash.GroupId).FirstOrDefault(); if(s != null) { // Setto la presenza o meno della maniglia per ogni anta foreach (SashDimension item in s.SashList) { if (item.Equals(sashDim)) { item.bHasHandle = true; } else { if (item.bHasHandle) { switch (item.SelOpeningType) { case Openings.TILTTURN_LEFT: { item.SetOpeningType(Openings.TURNONLY_LEFT); break; } case Openings.TILTTURN_RIGHT: { item.SetOpeningType(Openings.TURNONLY_RIGHT); break; } default: { break; } } } item.bHasHandle = false; } } } // Per ogni anta della Sash setto HasHandle currSash.RefreshHardwareList(); currSash.SetFirstHardware(); _ = DoPreviewSvg(); } /// /// Metodo per la scelta dello split intero nella modalità griglia /// /// split su cui si sceglie /// protected async Task changeStartVert(DataChangeStartVert Args) { ChangeEventArgs e = Args.eventArg; Split currSplit = Args.currItem; // Cerco la Sash che si sta considerando nella lista Sash foreach (Split s in SplitList) { if (s.Equals(currSplit)) { s.SetSplitStartVert((bool)e.Value); } } await DoPreviewSvg(); } /// /// 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}"; ItemTableList.Add(new ItemTable(AreaTypes.FILL, "FL" + nFill, maxRow, col, i, 0)); 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 async Task DoClose() { editLock = false; await EC_OnClose.InvokeAsync(false); } /// /// 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) { 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 da JWD /// /// Lista degli ID numerici dei gruppi da valutare /// protected async Task DoReqOptHardware(List groupIdList, bool isFirst = false) { if (m_CurrWindow != null) { isLoadingHwOpt = true; #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) { 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)) { 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); } } } /// /// Metodo di reset /// protected async Task DoReset() { // Da fare } /// /// Richiesta chiusura con salvataggio /// /// protected async Task DoSave() { editLock = false; //manca salvataggio JWD await EC_OnClose.InvokeAsync(true); } 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 }; // 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("", "", "", ""); 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}"); } } else { // usando m_currWindow (preesistente) impostare i parametri... UpdateDict(); } } checkWarnings(); if (SashList.Count > 0) { currAnta = 0; } if (updRequested) { // se mancasse dizionario forme chiamo quello if (LiveData.DictShape.Count == 0) { if (firstDisplay && isRendered) { firstDisplay = false; // preview SVG senza HW await DoPreviewSvg(true, true); } List reqList = SashList.Select(x => x.GroupId).ToList(); if (reqList.Count > 0) { await DoReqShape(reqList); } } else { // chiedo SVG await DoPreviewSvg(true); } } } else { checkErrorPre(); } isLoading = false; } } /// /// Metodo per costruire oggetti della Window /// /// protected void setCurrWindow(JsonWindow WindowFromJson) { if (m_CurrWindow != null) { m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview; m_CurrWindow.OnReqHwOption -= M_CurrWindow_OnHwOption; m_CurrWindow.OnReqShape -= M_CurrWindow_OnShape; m_CurrWindow = null; } m_CurrWindow = WindowFromJson.Deserialize(); m_CurrWindow.OnPreview += M_CurrWindow_OnPreview; m_CurrWindow.OnReqHwOption += M_CurrWindow_OnHwOption; m_CurrWindow.OnReqShape += M_CurrWindow_OnShape; // Recupero dimensioni Frame e Joint del frame della finestra precedente if (m_PreviousWindow != null) { for (int i = 0; i < 2; i++) m_CurrWindow.AreaList.First().DimensionList[i] = m_PreviousWindow.AreaList.First().DimensionList[i]; for (int i = 0; i < 4; i++) m_CurrWindow.AreaList.First().JointList[i] = m_PreviousWindow.AreaList.First().JointList[i]; } if (m_CurrWindow != null) { // Aggiornamento liste sash, split, splitted, fill e itemTable UpdateLists(); } if (SashList.Count > 0) currAnta = 0; isLoadingHwOpt = false; // 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.Where(x => x.GroupId == item.Key).First(); sashFromGroupId.SashShape = item.Value; sashFromGroupId.UpdateShape(item.Value); } } // se ho le opzioni hw le aggiungo if (LiveData.DictOptionsXml.Count > 0) { foreach (var item in SashList) { if (LiveData.DictOptionsXml.ContainsKey(item.GroupId)) { item.SetHardwareOption(LiveData.DictOptionsXml[item.GroupId]); } } } } /// /// 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); } /// /// Metodo per settare i parmateri di ingresso selezionati /// protected void UpdateSelParameter() { Sash.m_HardwareCompleteList = ListPayload.Hardware; Sash.s_FamilyHardwareList = ListPayload.FamilyHardware; if (CurrSelection != null && CurrSelection.IsValid()) { SelFamilyHardware = CurrSelection.FamilyHardware ?? ""; SelColorMaterial = CurrSelection.ColorMaterial ?? ""; SelMaterial = CurrSelection.Material ?? ""; SelGlass = CurrSelection.Glass ?? ""; SelProfile = CurrSelection.Profile ?? ""; } } #endregion Protected Methods #region Private Fields private int currAnta = 0; private int currFill = -1; private int currSash = -1; private int currSplit = -1; private CompileStep currStep; private bool editLock = false; private bool firstDisplay = true; /// /// Booleana fase loading /// private bool isLoading = false; private bool isRendered = false; private bool isLoadingHwOpt = 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 List m_FillList = new List(); 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_SplittedList = new List(); #endregion Private Fields #region Private Properties private Window? m_CurrWindow { get; set; } = null; private Window? m_PreviousWindow { get; set; } = null; private string m_SelFamilyHardware { get; set; } = ""; /// /// 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; #endregion Private Properties #region Private Methods /// /// Metodo per aggiungere una Sash /// /// /// private void AddSashIntoSplit(DataAreaSplitted Args) { Splitted currSplitted = Args.splitted; currSplitted.AddFirstSash(); // ricalcolo liste UpdateLists(); // richiedo update shape List reqList = SashList.Select(x => x.GroupId).ToList(); _ = DoReqShape(reqList); //_ = DoReqOptHardware(reqList); } /// /// Metodo per aggiungere una sash di default al Frame /// /// private void AddSashToFrame(Frame f) { f.AddFirstSash(); // ricalcolo liste UpdateLists(); // richiedo update shape List reqList = SashList.Select(x => x.GroupId).ToList(); _ = DoReqShape(reqList); } /// /// Metodo per aggiungere uno split di default al Frame /// /// private void AddSplitToFrame(Frame f) { f.AddSplit(); } /// /// Metodo per andare allo step successivo /// /// step successivo private void AdvStep(CompileStep newStep) { currStep = newStep; currSash = -1; currFill = -1; currSplit = -1; } /// /// Prima chiamata alle opzioni hardware /// /// Group Id del sash group di cui si vuole Hw option /// private async Task CallFirstHwOpt(int groupId) { bool isFirst = true; List reqList = new List() { groupId }; await DoReqOptHardware(reqList, isFirst); } /// /// Metodo per settare tutti i Fill in contemporanea /// /// tipo di riempimento (GLASS o WOOD) /// private async Task ChangeAllFill(FillTypes type) { foreach (Fill currFill in FillList) { currFill.SetSelFillType(type); } await DoPreviewSvg(); } /// /// Metodo per settare tutti i Joints di Frame o Sash come ANGLED o FULL_H o FULL_V /// /// /// private async Task ChangeAllJoints(DataChangeJoints Args) { WindowConst.Joints type = Args.currJointType; Area area = Args.currArea; if (area is Frame) { foreach (Joint joint in FrameWindow.JointList) { joint.SetSelJointType(type); } } else { Sash a = (Sash)area; foreach (Joint joint in a.JointList) { joint.SetSelJointType(type); } } await DoPreviewSvg(); } /// /// Metodo per settare tutti i Fill in contemporanea /// /// tipo di riempimento (GLASS o WOOD) /// private async Task ChangeOneFill(FillTypes type) { Fill fillChange = FillList.ElementAt(currFill); fillChange.SetSelFillType(type); await DoPreviewSvg(); } /// /// 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!"); } else { if (ListPayload.FamilyHardware == null || ListPayload.FamilyHardware.Count == 0) { listErrPre.Add("FamilyHardware", "Missing Family HW List!"); } } if (ListPayload.Glass == null || ListPayload.Glass.Count == 0) { listErrPre.Add("Glass", "Missing Glass List!"); } if (ListPayload.Material == null || ListPayload.Material.Count == 0) { listErrPre.Add("Material", "Missing Material List!"); } if (ListPayload.ColorMaterial == null || ListPayload.ColorMaterial.Count == 0) { listErrPre.Add("ColorMaterial", "Missing ColorMaterial List!"); } if (ListPayload.Profile == null || ListPayload.Profile.Count == 0) { listErrPre.Add("Profile", "Missing Profile List!"); } } /// /// 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) { // verifico colore attuale sia consistente... if (m_CurrWindow != null) { if (!ListPayload.ColorMaterial.Contains(m_CurrWindow.sColorMaterial)) { listWarnings.Add("ColorMaterial", $"Missing Color: {m_CurrWindow.sColorMaterial}"); } if (!ListPayload.Glass.Contains(m_CurrWindow.sGlass)) { listWarnings.Add("Glass", $"Missing Glass: {m_CurrWindow.sGlass}"); } if (!ListPayload.Material.Contains(m_CurrWindow.sMaterial)) { listWarnings.Add("Material", $"Missing Material: {m_CurrWindow.sMaterial}"); } if (!ListPayload.Profile.Contains(m_CurrWindow.sProfilePath)) { listWarnings.Add("Profile", $"Missing Profile: {m_CurrWindow.sProfilePath}"); } } } } /// /// Metodo per copiare contenuto di un'anta in un'altra anta /// /// private async Task CopyContentSash(DataCopyContentSash Args) { Sash sashItem = Args.currItem; int IndexCopy = Args.indexCopy; int IndexModify = Args.indexModify; // Anta selezionata Area sashSplitted = sashItem.AreaList[IndexModify]; // Rimuovo riempimento da anta selezionata sashSplitted.AreaList.RemoveAt(0); // Creo la copia dell'anta scelta Area a = sashItem.AreaList[IndexCopy].AreaList.First().Copy(sashSplitted); // Aggiungo copia all'anta selezionata sashItem.AreaList[IndexModify].AreaList.Add(a); await DoPreviewSvg(); } /// /// Metodo per copiare una Sash intera /// /// /// private async Task CopySash(DataAreaSplit Args) { Splitted currSplitted = Args.splitted; int numSash = Args.index; //Rimuovo contenuto di Splitted e rimuovo area da conteggio gruppi currSplitted.AreaList.RemoveAll(i => i != null); //Area.DelCounterGroup(); // Copio sash Area a = SashList[numSash].Copy(currSplitted); a.SetParentArea(currSplitted); // Aggiungo copia a Splitted currSplitted.AreaList.Add(a); await DoPreviewSvg(); } private void M_CurrWindow_OnHwOption(object? sender, OnReqHwOptEventArgs e) { isLoadingHwOpt = true; Dictionary Args = new Dictionary(); Args.Add("Mode", $"{(int)Enums.QuestionModes.HARDWARE}"); Args.Add("SubMode", $"{(int)Enums.QuestionHwSubModes.HARDWAREOPTIONS}"); Args.Add("SerializedData", e.sJwd); string listGroupId = JsonConvert.SerializeObject(new List { e.nGroupId }); Args.Add("GroupId", listGroupId); _ = EC_DoUpdate.InvokeAsync(Args); } private void M_CurrWindow_OnPreview(object? sender, OnPreviewEventArgs e) { Dictionary Args = new Dictionary(); Args.Add("Mode", $"{(int)Enums.QuestionModes.PREVIEW}"); Args.Add("SerializedData", e.sJwd); _ = EC_DoUpdate.InvokeAsync(Args); } private void M_CurrWindow_OnShape(object? sender, OnReqShapeEventArgs e) { Dictionary Args = new Dictionary(); Args.Add("Mode", $"{(int)Enums.QuestionModes.HARDWARE}"); Args.Add("SubMode", $"{(int)Enums.QuestionHwSubModes.SASHSHAPE}"); Args.Add("SerializedData", e.sJwd); string listGroupId = JsonConvert.SerializeObject(new List { e.groupId }); Args.Add("GroupId", listGroupId); _ = EC_DoUpdate.InvokeAsync(Args); } /// /// Metodo per cambiare step /// /// step successivo private void NextStep(CompileStep newStep, int Index = 1) { editLock = true; currStep = newStep; switch (newStep) { case CompileStep.Sash: { currSash = Index; currFill = -1; currSplit = -1; break; } case CompileStep.Fill: { currFill = Index; currSash = -1; currSplit = -1; break; } case CompileStep.Split: { currSplit = Index; currSash = -1; currFill = -1; break; } } } /// /// Metodo per cambiare step /// /// private void NextStepArgs(DataNextStep Args) { CompileStep newStep = Args.currCompileStep; int Index = Args.index; NextStep(newStep, Index); } /// /// Metodo per eliminare Split o Sash /// /// Area corrente /// private void RemoveArea(Area currArea) { if (currArea is Split) ((Split)currArea).Remove(); else if (currArea is Sash) { ((Sash)currArea).Remove(); } currStep = CompileStep.Tree; } /// /// Richiesta reset dizionario Shape con action /// /// /// private void ReqResetDict(bool args) { _ = EC_ActionReq.InvokeAsync(DataAction.ResetDictShape); } /// /// Ritorno step Tree /// /// private void ReturnTree(bool args) { AdvStep(CompileStep.Tree); } /// /// Cerca e aggiorna la sash /// /// area corrente che si sta valutando /// id della sash che si sta cercando /// nuova sash /// private Area SearchSash(Area currentArea, int idSearch, Sash newSash) { if (currentArea.GroupId == idSearch && currentArea.AreaType.Equals(AreaTypes.SASH)) { currentArea = newSash; return currentArea; } foreach (Area child in currentArea.AreaList) { Area found = SearchSash(child, idSearch, newSash); if (found != null) { return found; } } return null; } /// /// Selezione del colore /// /// private void SelectColor(string newVal) { if (m_CurrWindow != null) { m_CurrWindow.sColorMaterial = newVal; } } /// /// Selezione del vetro /// /// private void SelectGlass(string newVal) { if (m_CurrWindow != null) { m_CurrWindow.sGlass = newVal; } } /// /// Selezione del materiale /// /// private void SelectMat(string newVal) { if (m_CurrWindow != null) { m_CurrWindow.sMaterial = newVal; } } /// /// Selezione del profilo /// /// private void SelectProfile(string newVal) { if (m_CurrWindow != null) { m_CurrWindow.sProfilePath = newVal; } } /// /// Metodo per scambiare due aree di uno split /// /// Area corrente /// private async Task SwapTwoAree(Area currArea) { currArea.SwapAree(); await DoPreviewSvg(true, true); if(currArea is Split) { List reqShape = new List(); if(currArea.AreaList[0].AreaList.Where(x => x.AreaType == AreaTypes.SASH).ToList().Count() > 0) reqShape.Add(currArea.AreaList[0].AreaList.Where(x => x.AreaType == AreaTypes.SASH).Select(x => x.GroupId).FirstOrDefault()); if (currArea.AreaList[1].AreaList.Where(x => x.AreaType == AreaTypes.SASH).ToList().Count() > 0) reqShape.Add(currArea.AreaList[1].AreaList.Where(x => x.AreaType == AreaTypes.SASH).Select(x => x.GroupId).FirstOrDefault()); await DoReqShape(reqShape); } } /// /// Calcola il css del tab selezionato /// /// Step /// private string tabNavCss(CompileStep testStep, int Index = -1) { if (testStep == CompileStep.Sash) { if ((currSash == 0 && Index == 0) || (currSash == 1 && Index == 1)) return "nav-link active fw-bold"; else return "nav-link text-secondary"; } else if (testStep == CompileStep.Fill) { if ((currFill == 0 && Index == 0) || (currFill == 1 && Index == 1)) return "nav-link active fw-bold"; else return "nav-link text-secondary"; } else if (testStep == CompileStep.Split) { if ((currSplit == 0 && Index == 0) || (currSplit == 1 && Index == 1)) return "nav-link active fw-bold"; else return "nav-link text-secondary"; } return (testStep == currStep) ? "nav-link active fw-bold" : "nav-link text-secondary"; } /// /// Aggiornamento Frame /// /// /// private async Task UpdateFrame(Frame newFrame) { FrameWindow = newFrame; await DoPreviewSvg(); } /// /// Aggiornamento opzioni dato update sash /// /// nuova sash /// private async Task UpdateHwOptions(Sash newSash) { // richiesta calcolo opzioni hardware per la singola sash group //string req = newSash.SelHardware.Id; List reqList = new List() { newSash.GroupId }; // chiamo con gruppo della nuova sash await DoReqOptHardware(reqList); } /// /// Aggiornamento Sash e Frame /// /// nuova sash /// private async Task UpdateSash(Sash newSash) { SearchSash(FrameWindow, newSash.GroupId, newSash); await DoPreviewSvg(); } /// /// Aggiornamento Shape x ogni Group di Sash della finestra /// /// /// private async Task UpdateShape(Frame newFrame) { FrameWindow = newFrame; if (SashList.Count > 0) { // ciclo x ogni group della mia frame List reqList = SashList.Select(x => x.GroupId).ToList(); await DoReqShape(reqList); } } #endregion Private Methods } }