using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Reflection.Metadata; using WebWindowConfigurator.DTO; using WebWindowConfigurator.Json; using static WebWindowConfigurator.Json.WindowConst; namespace WebWindowConfigurator { public partial class WebWindowMaker : IDisposable { #region Public Properties [Parameter] public string CssSvg { get; set; } = "responsive-svg"; [Parameter] public EventCallback EC_OnClose { get; set; } [Parameter] public EventCallback EC_OnSelectedTemplate { get; set; } [Parameter] public EventCallback> EC_OnUpdate { get; set; } [Parameter] public Template IN_SelTemplate { get => m_SelTemplate; set { // Se non ho ancora selezionato template oppure se cambio template di selezione if (value != null && (m_SelTemplate == null || (m_SelTemplate != null && value.nIndex != m_SelTemplate.nIndex)) && !string.IsNullOrEmpty(value.JWD)) { m_SelTemplate = value; JsonWindow WindowFromJson = JsonConvert.DeserializeObject(m_SelTemplate.JWD, new PolymorphicJsonConverter()) ?? new JsonWindow(""); if (m_CurrWindow != null) { m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview; m_CurrWindow = null; } m_CurrWindow = WindowFromJson.Deserialize(); m_CurrWindow.OnPreview += M_CurrWindow_OnPreview; // recupero dimensioni Frame e Joint Frame della finestra precedente if(m_PreviousWindow != null) { for(int i = 0; i < 2; i++) m_CurrWindow.AreaList[0].DimensionList[i] = m_PreviousWindow.AreaList[0].DimensionList[i]; for (int i = 0; i < 4; i++) m_CurrWindow.AreaList[0].JointList[i] = m_PreviousWindow.AreaList[0].JointList[i]; } } if (m_CurrWindow != null) { m_FillList = new List(); m_SashList = new List(); m_SplitList = new List(); m_SplittedList = new List(); CreateWindowsList(m_CurrWindow.AreaList[0]); } } } [Parameter] public List IN_TemplateDTOList { get; set; } = null!; [Parameter] public string LiveSVG { get => m_SelSVG; set => m_SelSVG = value; } #endregion Public Properties #region Public Methods public void Dispose() { if (m_CurrWindow != null) { m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview; m_CurrWindow = null; } } #endregion Public Methods #region Protected Enums protected enum CompileStep { Template = 0, Frame = 1, Split, Sash, Fill, General } protected enum ColorWindow { Bianco = 0, Grigio = 1, Tortora, Blu, Verde, Nero } #endregion Protected Enums #region Protected Properties protected Frame FrameWindow { get => m_Frame; set => m_Frame = value; } protected string m_SelSVG { get; set; } = ""; /// /// Componente SVG da mostrare /// protected MarkupString outSvg { get { // aggiunta gestione classe svg per posizionamento con costraints var newSvg = LiveSVG.Replace(" SashList { get => m_SashList; } protected List SplitList { get => m_SplitList; } protected List FillList { get => m_FillList; } protected List SplittedList { get => m_SplittedList; } protected TemplateSelectDTO? SelTemplateDTO { get; set; } = null; #endregion Protected Properties #region Protected Methods /// /// Metodo per la scelta della maniglia univoca /// /// /// protected async Task changeHandle(SashDimension sashDim) { //if(m_SashList[0].AreaList.Count < 3) //{ foreach (SashDimension item in SashList[0].SashList) { if (item.Equals(sashDim)) { item.bHasHandle = true; } else { item.bHasHandle = false; } } //} await Task.Delay(1); } // Ancora da fare... protected async Task DoClose() { await EC_OnClose.InvokeAsync(true); } /// /// Anteprima SVG /// /// protected async Task DoPreviewSvg() { if (m_CurrWindow != null) { var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(), Formatting.Indented); Dictionary Args = new Dictionary(); Args.Add("Jwd", CurrJwd); Args.Add("Mode", 1.ToString()); await EC_OnUpdate.InvokeAsync(Args); } } /// /// Metodo di reset dei dati a quelli del template /// protected async Task DoReset() { JsonWindow WindowFromJson = JsonConvert.DeserializeObject(m_SelTemplate.JWD, new PolymorphicJsonConverter()) ?? new JsonWindow(""); if (m_CurrWindow != null) { m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview; m_CurrWindow = null; } m_CurrWindow = WindowFromJson.Deserialize(); m_CurrWindow.OnPreview += M_CurrWindow_OnPreview; m_FillList = new List(); m_SashList = new List(); m_SplitList = new List(); m_SplittedList = new List(); // popolo le liste Fill, Sash e Split CreateWindowsList(m_CurrWindow.AreaList[0]); currSash = -1; await DoPreviewSvg(); } // Ancora da fare.. protected async Task DoSave() { //manca salvataggio JWD await EC_OnClose.InvokeAsync(true); } /// /// Selezione del template /// /// template selezionato protected async void DoSelect(TemplateSelectDTO newSel) { SelTemplateDTO = newSel; //DoSelectAndPreview(CompileStep.Frame); await EC_OnSelectedTemplate.InvokeAsync(newSel); } /// /// Metodo per cambiare step e aggiornare preview svg /// /// step successivo protected async void NextStepAndPreview(CompileStep newStep, int Index = -1) { currStep = newStep; if (newStep == CompileStep.Sash) currSash = Index; else currSash = -1; await DoPreviewSvg(); } //protected void CreateWindowsList(Area node, bool IntoSash) //{ // if (node != null) // { // bool nodeIntoSash = false; // if (node.ParentArea is Sash || IntoSash == true) // nodeIntoSash = true; // switch (node.AreaType) // { // case AreaTypes.FRAME: // { // FrameWindow = (Frame)node; // if (node.AreaList[0] is Split) // SplitParentList.Add(new SplitParent(AreaTypes.FRAME, "Frame", nodeIntoSash, node.AreaList[0], null)); // else // SplitParentList.Add(new SplitParent(AreaTypes.FRAME, "Frame", nodeIntoSash, null, node)); // break; // } // case AreaTypes.SASH: // { // m_SashList.Add((Sash)node); // if (node.AreaList[0] is Fill) // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Sash", nodeIntoSash, null, node)); // else if (node.AreaList[0] is Split) // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Sash into split", nodeIntoSash, node.AreaList[0], node)); // break; // } // case AreaTypes.FILL: // { // m_FillList.Add((Fill)node); // break; // } // case AreaTypes.SPLIT: // { // m_SplitList.Add((Split)node); // break; // } // case AreaTypes.SPLITTED: // { // m_SplittedList.Add((Splitted)node); // if (node.AreaList[0] is Split) // { // if (node.ParentArea is Sash) // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Sash", nodeIntoSash, node.AreaList[0], node)); // else // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Split", nodeIntoSash, node.AreaList[0], node)); // } // else if (node.AreaList[0] is Sash) // { // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Split area with sash", nodeIntoSash, null, node)); // } // else // { // if (node.ParentArea is Sash) // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Sash", nodeIntoSash, null, node)); // else if (nodeIntoSash) // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Area split into sash", nodeIntoSash, null, node)); // else // SplitParentList.Add(new SplitParent(AreaTypes.SPLITTED, "Split", nodeIntoSash, null, node)); // } // break; // } // } // foreach (var item in node.AreaList) // { // CreateWindowsList(item, nodeIntoSash); // } // } //} protected void CreateWindowsList(Area node) { if (node != null) { 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: { m_SplittedList.Add((Splitted)node); break; } } foreach (var item in node.AreaList) { CreateWindowsList(item); } } } /// /// Metodo per settare tutti i Joints di Frame o Sash come ANGLED o FULL_H o FULL_V /// /// tipo di giunzione (ANGLED o FULL_H o FULL_V) /// oggetto a cui essere applicato (Frame o Sash) /// private async Task AllJointsFrame(int int_type, int int_place) { Joints type = Joints.ANGLED; if (int_type == 2) { type = Joints.FULL_H; } else if (int_type == 3) { type = Joints.FULL_V; } if(int_place == 0) { foreach (Joint joint in FrameWindow.JointList) { joint.SetSelJointType(type); } } else if(int_place == 1) { foreach (Joint joint in m_SashList[0].JointList) { joint.SetSelJointType(type); } } await DoPreviewSvg(); } /// /// Metodo per settare tutti i Joints di Frame o Sash come ANGLED o FULL_H o FULL_V /// /// tipo di giunzione (ANGLED o FULL_H o FULL_V) /// oggetto a cui essere applicato (Frame o Sash) /// private async Task AllFill(int int_type) { FillTypes type = FillTypes.GLASS; if (int_type == 2) { type = FillTypes.WOOD; } foreach (Fill currFill in m_FillList) { currFill.SetFillType(type); } await DoPreviewSvg(); } private async Task SwapTwoAree(Area currArea) { currArea.SwapAree(); await DoPreviewSvg(); } #endregion Protected Methods #region Private Fields private CompileStep currStep = CompileStep.Template; private ColorWindow currColorWin = ColorWindow.Bianco; private Frame m_Frame; private int currSash = -1; 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 enum positionJoints { BL=0, // Bottom Left BR=1, // Bottom Right TR, // Top Right TL // Top Left } #endregion Private Fields #region Private Properties private Window? m_CurrWindow { get; set; } = null; private Window? m_PreviousWindow { get; set; } = null; private Template m_SelTemplate { get; set; } = null!; #endregion Private Properties #region Private Methods /// /// Metodo per andare allo step successivo /// /// step successivo private void AdvStep(CompileStep newStep) { currStep = newStep; currSash = -1; } private void ChangeColorWindow(ColorWindow newColorWin) { currColorWin = newColorWin; } private void M_CurrWindow_OnPreview(object? sender, OnPreviewEventArgs e) { Dictionary Args = new Dictionary(); Args.Add("Jwd", e.sJwd); Args.Add("Mode", 1.ToString()); EC_OnUpdate.InvokeAsync(Args); } /// /// Calcola il css del tab selezionato /// /// /// 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"; } } return (testStep == currStep) ? "nav-link active fw-bold" : "nav-link text-secondary"; } private string buttonCss(ColorWindow testColor) { return testColor.Equals(currColorWin) ? "btn btn-outline-secondary active" : "btn btn-outline-secondary"; } /// /// Calcola larghezza colonna da mostrare /// /// private string mainCss() { return currStep == CompileStep.Template ? "col-12" : "col-6"; } #endregion Private Methods } }