From a8047f4ca82c06b83b507761d34f6f14be5a5bd2 Mon Sep 17 00:00:00 2001 From: Annamaria Sassi Date: Mon, 15 Dec 2025 18:17:36 +0100 Subject: [PATCH] - Corretto conversione tipi dimensioni - Corretto aggiornamento dimensioni a causa di una modifica (no gestione split grid) --- README.md | 6 +- WebWindowComplex/Compo/CardSashGroup.razor.cs | 4 +- .../Compo/EditFrameDimensions.razor.cs | 7 +- .../Compo/EditSplitDimensions.razor.cs | 13 +- WebWindowComplex/Models/Area.cs | 235 ++++++- WebWindowComplex/Models/AreaDimension.cs | 350 ++++++++++ WebWindowComplex/Models/Frame.cs | 17 +- WebWindowComplex/Models/FrameDimension.cs | 368 ++++++----- WebWindowComplex/Models/Sash.cs | 148 +---- WebWindowComplex/Models/SashDimension.cs | 602 +++++++++-------- WebWindowComplex/Models/Split.cs | 29 +- WebWindowComplex/Models/SplitDimension.cs | 625 ++++++++++-------- WebWindowComplex/TableComp.razor.cs | 2 +- WebWindowComplex/WebWindowComplex.csproj | 9 +- .../WebWindowConfigurator.csproj | 12 +- 15 files changed, 1559 insertions(+), 868 deletions(-) create mode 100644 WebWindowComplex/Models/AreaDimension.cs diff --git a/README.md b/README.md index abf39d1..6b6d784 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ La richiesta della forma del gruppo di ante viene trasmessa se si cambiano i seg - Forma del telaio; - Dimensioni del telaio; - Aggiunta di uno split nel frame se già presente un gruppo di ante; - - Se si effettua lo scambio delle aree di uno split e una delle aree contiene una sash + - Se si effettua lo scambio delle aree di uno split e una delle aree contiene una sash; - Eliminazione di uno split. La lista degli hardware viene aggiornata se si cambiano i seguenti parametri: @@ -120,7 +120,7 @@ Vengono richieste nei seguenti casi: - Click sul pulsante per visualizzarle; - Cambiamento nel numero di ante; - Cambiamento nella selezione dell'hardware; - - Cambiamento nella selezione della famiglia hardware; + - Cambiamento nella selezione della famiglia hardware. ### Riempimento (Fill) @@ -128,8 +128,6 @@ Descrive il tipo di riempimento: vetro o pannello. ## Roadmap -Mancano: - - [ ] Filtrare hardware utilizzando anche la posizione dell'anta battente. ## License For open source projects, say how it is licensed. diff --git a/WebWindowComplex/Compo/CardSashGroup.razor.cs b/WebWindowComplex/Compo/CardSashGroup.razor.cs index 9b2bade..34ef42b 100644 --- a/WebWindowComplex/Compo/CardSashGroup.razor.cs +++ b/WebWindowComplex/Compo/CardSashGroup.razor.cs @@ -214,9 +214,9 @@ namespace WebWindowComplex.Compo protected async Task SetMeasureType(MeasureTypes type) { isOpen = !isOpen; - foreach (var item in CurrSashGroup.SashList) + for(int i = 0; i < CurrSashGroup.SashList.Count; i++) { - item.SetSelMeasureType(type); + CurrSashGroup.SashList.ElementAt(i).SetSelMeasureType(type, i); } var args = new DataUpdateSash { diff --git a/WebWindowComplex/Compo/EditFrameDimensions.razor.cs b/WebWindowComplex/Compo/EditFrameDimensions.razor.cs index 75352ab..9007621 100644 --- a/WebWindowComplex/Compo/EditFrameDimensions.razor.cs +++ b/WebWindowComplex/Compo/EditFrameDimensions.razor.cs @@ -25,12 +25,13 @@ namespace WebWindowComplex.Compo /// private double CurrVal { - get => CurrRec.dValue; + get => CurrRec.dDimension; set { - if (CurrRec.dValue != value) + if (CurrRec.dDimension != value) { - CurrRec.dValue = value; + CurrRec.dDimension = value; + CurrRec.dDimension = value; _ = EC_Update.InvokeAsync(CurrRec); } } diff --git a/WebWindowComplex/Compo/EditSplitDimensions.razor.cs b/WebWindowComplex/Compo/EditSplitDimensions.razor.cs index e09ef1d..18114cd 100644 --- a/WebWindowComplex/Compo/EditSplitDimensions.razor.cs +++ b/WebWindowComplex/Compo/EditSplitDimensions.razor.cs @@ -76,10 +76,15 @@ namespace WebWindowComplex.Compo private string SplitDimCss() { - if (CurrRec.Parent.SelSplitShape.Equals(Json.WindowConst.SplitShapes.GRID)) - return ""; - else - return "col-md-12 col-lg-6"; + if(CurrRec.Parent is Split) + { + Split s = (Split)CurrRec.Parent; + if (s.SelSplitShape.Equals(Json.WindowConst.SplitShapes.GRID)) + return ""; + else + return "col-md-12 col-lg-6"; + } + return ""; } /// diff --git a/WebWindowComplex/Models/Area.cs b/WebWindowComplex/Models/Area.cs index 7ccbb24..bf2e0a6 100644 --- a/WebWindowComplex/Models/Area.cs +++ b/WebWindowComplex/Models/Area.cs @@ -1,4 +1,5 @@ -using WebWindowComplex.Json; +using System.ComponentModel.Design; +using WebWindowComplex.Json; using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex.Models @@ -69,7 +70,6 @@ namespace WebWindowComplex.Models set { m_nAreaId = value; - //m_ParentWindow.OnUpdatePreview(m_ParentWindow.sSerialized()); } } @@ -124,8 +124,6 @@ namespace WebWindowComplex.Models // Inserisco il riempimento precedente AreaList[0].AreaList.Add(ContentArea[0]); AreaList[0].AreaList[0].SetParentArea(AreaList[0]); - // Richiesta SVG con hardware di default - //ParentWindow.OnUpdatePreview(ParentWindow.sSerialized()); } public void AddSplit() @@ -182,6 +180,155 @@ namespace WebWindowComplex.Models AreaList[0] = AreaList[1]; AreaList[1] = tempArea; } + //SearchAreaList(this, "Width"); + } + + /// + /// Cerca nell'albero gli oggetti Sash e Split per associare la larghezza + /// + /// + public void SearchAreaList(Area node, double dim, string nameDim) + { + if (node != null) + { + if (node.AreaType.Equals(AreaTypes.SASH)) + UpdateDimSubArea((Sash)node, dim, nameDim); + else if (node.AreaType.Equals(AreaTypes.SPLIT)) + UpdateDimSubArea((Split)node, dim, nameDim); + for (int i = 0; i < node.AreaList.Count; i++) + { + if (node.AreaType.Equals(AreaTypes.SASH)) + { + Sash s = (Sash)node; + List dimList = new List(); + foreach (var item in s.SashList) + dimList.Add(new AreaDimension(item.dDimension, item.MeasureType)); + if(nameDim.Equals("Width")) + SearchAreaList(node.AreaList.ElementAt(i), s.SashList.ElementAt(i).CalculateAbsoluteValue(dimList, dim), nameDim); + else + SearchAreaList(node.AreaList.ElementAt(i), dim, nameDim); + } + else if (node.AreaType.Equals(AreaTypes.SPLIT)) + { + Split s = (Split)node; + List dimList = new List(); + if (s.SplitHorizList.Count > 0 && i < s.SplitHorizList.Count) + { + foreach (var item in s.SplitHorizList) + dimList.Add(new AreaDimension(item.dDimension, item.MeasureType)); + if(nameDim.Equals("Width")) + SearchAreaList(node.AreaList.ElementAt(i), dim, nameDim); + else + SearchAreaList(node.AreaList.ElementAt(i), s.SplitHorizList.ElementAt(i).CalculateAbsoluteValue(dimList, dim), nameDim); + } + if (s.SplitVertList.Count > 0 && i < s.SplitVertList.Count) + { + foreach (var item in s.SplitVertList) + dimList.Add(new AreaDimension(item.dDimension, item.MeasureType)); + if(nameDim.Equals("Width")) + SearchAreaList(node.AreaList.ElementAt(i), s.SplitVertList.ElementAt(i).CalculateAbsoluteValue(dimList, dim), nameDim); + else + SearchAreaList(node.AreaList.ElementAt(i), dim, nameDim); + } + } + else + SearchAreaList(node.AreaList.ElementAt(i), dim, nameDim); + } + } + } + + public void UpdateDimSubArea(Area area, double dim, string nameDim) + { + if (area is Sash && nameDim.Equals("Width")) + { + Sash sash = (Sash)area; + int countAbsolute = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Count(); + int countProportional = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).Count(); + int countPercentage = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).Count(); + List dimList = new List(); + Split temp = new Split(null, null); + if (sash.ParentArea.ParentArea is Split) + temp = (Split)sash.ParentArea.ParentArea; + if (sash.ParentArea is Frame || (sash.ParentArea.ParentArea is Split && temp.SplitHorizList.Count > 0)) + { + Frame f = null; + if(temp.SplitHorizList.Count > 0) + f = (Frame)sash.ParentArea.ParentArea.ParentArea; + else + f = (Frame)sash.ParentArea; + foreach (var i in f.DimensionList) + dimList.Add(new AreaDimension(i.dDimension, i.SelMeasureType)); + } + else + { + Split s = (Split)sash.ParentArea.ParentArea; + foreach (var i in s.SplitVertList) + dimList.Add(new AreaDimension(i.dDimension, i.SelMeasureType)); + } + if (countAbsolute == sash.SashList.Count) + { + double sum = sash.SashList.Sum(x => x.dDimension); + double res = dim - sum; + if (res > 0) + { + foreach (var sashDim in sash.SashList) + { + sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); + } + } + else + { + foreach (var sashDim in sash.SashList) + { + // Sommo perchè res è negativo + sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); + } + } + } + else if (countAbsolute < sash.SashList.Count) + { + if (countPercentage > 0 && countPercentage <= sash.SashList.Count && countProportional == 0) + { + double sumAbsolute = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Sum(x => x.dDimension); + var percentageList = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).ToList(); + foreach (var i in percentageList) + { + i.SetDimension(i.ConvertIn(dimList, (dim - sumAbsolute) / countPercentage, i.MeasureType, dim)); + } + } + } + } + else if (area is Split) + { + Split split = (Split)area; + List splitList = null; + if (nameDim.Equals("Width")) + splitList = split.SplitVertList; + else + splitList = split.SplitHorizList; + int countAbsolute = splitList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Count(); + if (countAbsolute != 0 && countAbsolute == splitList.Count) + { + double sum = splitList.Sum(x => x.dDimension); + double res = 0; + res = dim - sum; + if (res > 0) + { + foreach (var item in splitList) + { + item.SetDimension(item.dDimension + res / countAbsolute); + } + } + else + { + foreach (var item in splitList) + { + // Sommo perchè res è negativo + item.SetDimension(item.dDimension + res / countAbsolute); + } + } + } + } } #endregion Public Methods @@ -200,13 +347,81 @@ namespace WebWindowComplex.Models m_ParentArea = ParentArea; } + /// + /// Metodo per convertire da misura proporzionale a misura assoluta o percentuale + /// + /// + /// + internal double ConvertFromPropVal(Sash sashGroup, double sashDim, MeasureTypes newType, double widthTot) + { + double tot = widthTot; + List adList = new List(); + foreach (var it in sashGroup.SashList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + //Somma misura non proporzionali + double sumNotProp = sashGroup.SashList + .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL && !m.Equals(this)) + .Sum(m => m.CalculateAbsoluteValue(adList, tot)); + //Calcolo residuo + double res = tot - sumNotProp; + if (res < 0) res = 0; + //Misure proporzionali + var proportionalList = sashGroup.SashList + .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + .ToList(); + + double sumPesi = proportionalList.Sum(p => p.dDimension); + if (sumPesi == 0) sumPesi = 1; + if (newType.Equals(MeasureTypes.ABSOLUTE)) + { + return res / sumPesi * sashDim; + } + else + { + return (res / sumPesi * sashDim) / tot * 100; + } + } + + /// + /// Metodo per convertire da misura proporzionale a misura assoluta o percentuale + /// + /// + /// + internal double ConvertFromPropVal(List splitList, double splitDim, MeasureTypes newType, double widthTot) + { + double tot = widthTot; + List adList = new List(); + foreach (var it in splitList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + //Somma misura non proporzionali + double sumNotProp = splitList + .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL && !m.Equals(this)) + .Sum(m => m.CalculateAbsoluteValue(adList, tot)); + //Calcolo residuo + double res = tot - sumNotProp; + if (res < 0) res = 0; + //Misure proporzionali + var proportionalList = splitList + .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + .ToList(); + + double sumPesi = proportionalList.Sum(p => p.dDimension); + if (sumPesi == 0) + sumPesi = 1; + return res / sumPesi * splitDim; + } + /// /// Metodo per calcolare larghezza area /// /// area di partenza /// larghezza di partenza /// - internal double CalculateWidthArea(Area area, double width) + public double CalculateWidthArea(Area area, double width) { for (int i = 0; i < area.AreaList.Count; i++) { @@ -228,7 +443,7 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - //risultato = CalculateWidthSashGroup(item, split.SplitVertList.ElementAt(i).dDimension); + risultato = CalculateWidthArea(item, ConvertFromPropVal(split.SplitVertList, split.SplitVertList.ElementAt(i).dDimension, MeasureTypes.ABSOLUTE, width)); break; } case MeasureTypes.PERCENTAGE: @@ -257,7 +472,7 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - //risultato = CalculateWidthSashGroup(item, sash.SashList.ElementAt(i).dDimension); + risultato = CalculateWidthArea(item, ConvertFromPropVal(sash, sash.SashList.ElementAt(i).dDimension, MeasureTypes.ABSOLUTE, width)); break; } case MeasureTypes.PERCENTAGE: @@ -285,7 +500,7 @@ namespace WebWindowComplex.Models /// area di partenza /// altezza di partenza /// - internal double CalculateHeightArea(Area area, double height) + public double CalculateHeightArea(Area area, double height) { for (int i = 0; i < area.AreaList.Count; i++) { @@ -307,7 +522,7 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - //risultato = CalculateHeighthArea(item, split.SplitHorizList.ElementAt(i).dDimension); + risultato = CalculateHeightArea(item, ConvertFromPropVal(split.SplitHorizList, split.SplitHorizList.ElementAt(i).dDimension, MeasureTypes.ABSOLUTE, height) ); break; } case MeasureTypes.PERCENTAGE: @@ -336,7 +551,7 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - //risultato = CalculateHeighthArea(item, sash.SashList.ElementAt(i).dDimension); + risultato = CalculateHeightArea(item, ConvertFromPropVal(sash, sash.SashList.ElementAt(i).dDimension, MeasureTypes.ABSOLUTE, height)); break; } case MeasureTypes.PERCENTAGE: diff --git a/WebWindowComplex/Models/AreaDimension.cs b/WebWindowComplex/Models/AreaDimension.cs new file mode 100644 index 0000000..a7970cc --- /dev/null +++ b/WebWindowComplex/Models/AreaDimension.cs @@ -0,0 +1,350 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static WebWindowComplex.Json.WindowConst; + +namespace WebWindowComplex.Models +{ + public class AreaDimension + { + #region Public Constructors + + public AreaDimension(double dDimension, MeasureTypes MeasureType) + { + m_dDimension = dDimension; + m_SelMeasureType = MeasureType; + //m_Parent = Parent; + } + + #endregion Public Constructors + + #region Public Properties + + public virtual double dDimension + { + get + { + return m_dDimension; + } + set + { + m_dDimension = value; + } + } + + //public Area Parent + //{ + // get + // { + // return m_Parent; + // } + // set + // { + // m_Parent = value; + // } + //} + + public MeasureTypes MeasureType + { + get + { + return m_SelMeasureType; + } + } + + public List MeasureTypeList + { + get + { + return m_MeasureTypeList; + } + } + + public MeasureTypes SelMeasureType + { + get + { + return m_SelMeasureType; + } + set + { + m_SelMeasureType = value; + } + } + + public virtual int SelMeasureTypeIndex + { + get + { + return (int)m_SelMeasureType; + } + set + { + if (m_SelMeasureType != (MeasureTypes)value) + { + MeasureTypes newType = (MeasureTypes)value; + } + } + } + + #endregion Public Properties + + #region Private Fields + + protected double m_dDimension; + + protected List m_MeasureTypeList = new List + { + new IdNameStruct((int)MeasureTypes.ABSOLUTE, "Absolute"), + new IdNameStruct((int)MeasureTypes.PROPORTIONAL, "Proportional"), + new IdNameStruct((int)MeasureTypes.PERCENTAGE, "Percentage"), + }; + + protected MeasureTypes m_SelMeasureType; + + // reference + // protected Area m_Parent; + + #endregion Private Fields + + #region Public Methods + + public void SetDimension(double dValue) + { + m_dDimension = dValue; + } + + /// + /// Metodo per convertire la dimensione dal vecchio tipo al nuovo tipo + /// + /// Vecchio tipo + /// Nuovo tipo + /// + public double ConvertDimension(List itemList, MeasureTypes oldType, MeasureTypes newType, double widthTot, int indexSash) + { + switch (oldType) + { + case MeasureTypes.ABSOLUTE: + { + if (newType.Equals(MeasureTypes.PERCENTAGE)) + { + //return Double.Round((m_dDimension / m_Parent.Width) * 100, 1); + return (dDimension / widthTot) * 100; + } + else + { + return CalculatePropVal(itemList, indexSash, widthTot); + } + } + case MeasureTypes.PROPORTIONAL: + { + if (newType.Equals(MeasureTypes.ABSOLUTE)) + { + //return Double.Round(ConvertFromPropVal(newType), 2); + return ConvertFromPropVal(itemList, newType, widthTot); + } + else + { + //return Double.Round(ConvertFromPropVal(newType), 1); + return ConvertFromPropVal(itemList, newType, widthTot); + } + } + case MeasureTypes.PERCENTAGE: + { + if (newType.Equals(MeasureTypes.ABSOLUTE)) + { + //return Double.Round((m_dDimension * m_Parent.Width) / 100, 2); + return (dDimension * widthTot) / 100; + } + else + { + return CalculatePropVal(itemList, indexSash, widthTot); + } + } + } + return -1; + } + + #endregion Public Methods + + #region Internal Methods + + /// + /// Calcolo MCD + /// + /// + /// + /// + internal double CalculateMCD(double a, double b) + { + while (b >= 0.01) + { + double temp = b; + b = a % b; + a = temp; + } + //return Double.Round(a,2); + return a; + } + + /// + /// Metodo per ricalcolare i valori proporzionali a causa della modifica di uno + /// + /// + internal double CalculatePropVal(List itemList, int indexArea, double widthTot) + { + if (itemList.Where(m => m.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).ToList().Count == 0) + { + return 1; + } + List absoluteValue = new List(); + foreach (var item in itemList) + { + absoluteValue.Add(item.CalculateAbsoluteValue(itemList, widthTot)); + } + int numProportional = itemList.Where(x => x.SelMeasureType == MeasureTypes.PROPORTIONAL).Count(); + if(itemList.Count > 2 && numProportional == itemList.Count - 1) + { + int inedMin = absoluteValue.IndexOf(absoluteValue.Min()); + var mcd = CalculateMCD(absoluteValue.ElementAt(indexArea), absoluteValue.ElementAt(inedMin)); + itemList.ElementAt(inedMin).SetDimension(absoluteValue.ElementAt(inedMin) / mcd); + itemList.ElementAt(indexArea).SetDimension(absoluteValue.ElementAt(indexArea) / mcd); + } + else + { + for (int i = 0; i < itemList.Count; i++) + { + if (!itemList.ElementAt(i).Equals(this) && + itemList.ElementAt(i).MeasureType.Equals(MeasureTypes.PROPORTIONAL)) + { + if (absoluteValue.ElementAt(indexArea) <= absoluteValue.ElementAt(i)) + { + var mcd = CalculateMCD(absoluteValue.ElementAt(indexArea), absoluteValue.ElementAt(i)); + itemList.ElementAt(i).SetDimension(absoluteValue.ElementAt(i) / mcd); + itemList.ElementAt(indexArea).SetDimension(absoluteValue.ElementAt(indexArea) / mcd); + } + else + { + var mcd = CalculateMCD(absoluteValue.ElementAt(indexArea), absoluteValue.ElementAt(i)); + itemList.ElementAt(i).SetDimension(absoluteValue.ElementAt(i) / mcd); + itemList.ElementAt(indexArea).SetDimension(absoluteValue.ElementAt(indexArea) / mcd); + } + break; + } + } + } + return itemList.ElementAt(indexArea).dDimension; + } + + /// + /// Metodo per trasformare una dimensione in valore assoluto rispetto alla larghezza totale + /// + /// Larghezza totale + /// + internal double CalculateAbsoluteValue(List itemList, double widthTot) + { + switch (SelMeasureType) + { + case MeasureTypes.ABSOLUTE: + { + //return Double.Round(dDimension, 2); + return dDimension; + } + case MeasureTypes.PROPORTIONAL: + { + //return Double.Round(Proportional2AbsolutVal(), 2); + return ProportionalToAbsoluteVal(itemList, dDimension, widthTot); + } + case MeasureTypes.PERCENTAGE: + { + //return Double.Round((dDimension / 100) * widthTot, 1); + return (dDimension / 100) * widthTot; + } + } + return 0; + } + + /// + /// Metodo per convertire una dimensione da un valore assoluto al suo rispettivo tipo + /// + /// Valore assoluto + /// Tipo di misura della dimensione + /// Larghezza totale + /// + internal double ConvertIn(List itemList, double absoluteVal, MeasureTypes type, double widthTot) + { + switch (type) + { + case MeasureTypes.ABSOLUTE: + { + return absoluteVal; + } + case MeasureTypes.PROPORTIONAL: + { + return ProportionalToAbsoluteVal(itemList, absoluteVal, widthTot); + } + case MeasureTypes.PERCENTAGE: + { + return (absoluteVal / widthTot) * 100; + } + } + return -1; + } + + /// + /// Metodo per convertire da misura proporzionale a misura assoluta o percentuale + /// + /// + /// + internal double ConvertFromPropVal(List itemList, MeasureTypes newType, double widthTot) + { + double tot = widthTot; + //Somma misura non proporzionali + double sumNotProp = itemList.Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL && !m.Equals(this)) + .Sum(m => m.CalculateAbsoluteValue(itemList, tot)); + //Calcolo residuo + double res = tot - sumNotProp; + if (res < 0) res = 0; + //Misure proporzionali + var proportionalList = itemList.Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + .ToList(); + + double sumPesi = proportionalList.Sum(p => p.dDimension); + if (sumPesi == 0) sumPesi = 1; + if (newType.Equals(MeasureTypes.ABSOLUTE)) + { + return res / sumPesi * dDimension; + } + else + { + return (res / sumPesi * dDimension) / tot * 100; + } + } + + /// + /// Metodo per trasformare il valore proporzionale in assoluto + /// + /// + internal double ProportionalToAbsoluteVal(List itemList, double dimensionProp, double widthTot) + { + double tot = widthTot; + //Somma misura non proporzionali + double sumNotProp = itemList.Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL) + .Sum(m => m.CalculateAbsoluteValue(itemList, tot)); + //Calcolo residuo + double res = tot - sumNotProp; + if (res < 0) res = 0; + //Misure proporzionali + var proportionalList = itemList.Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + .ToList(); + double sumPesi = proportionalList.Sum(p => p.dDimension); + if (sumPesi == 0) sumPesi = 1; + return res / sumPesi * dimensionProp; + } + + + #endregion Public Method + } +} diff --git a/WebWindowComplex/Models/Frame.cs b/WebWindowComplex/Models/Frame.cs index 73e7393..d8e1fc2 100644 --- a/WebWindowComplex/Models/Frame.cs +++ b/WebWindowComplex/Models/Frame.cs @@ -100,7 +100,8 @@ namespace WebWindowComplex.Models List oldDimensionList = new List(DimensionList); // verifico parametri Dimension DimensionList.Clear(); - double widthVal = oldDimensionList.Where(x => x.sName.Equals("Width")).Select(x => x.dValue).First(); + //double widthVal = oldDimensionList.Where(x => x.sName.Equals("Width")).Select(x => x.dValue).First(); + double widthVal = oldDimensionList.Where(x => x.sName.Equals("Width")).Select(x => x.dDimension).First(); // aggiungo Dimensioni switch (SelShape) { @@ -109,6 +110,8 @@ namespace WebWindowComplex.Models { DimensionList.Add(new FrameDimension(this, 1, "Width", widthVal, true)); DimensionList.Add(new FrameDimension(this, 2, "Height", 1400, true)); + foreach (var dim in DimensionList) + SearchAreaList(this, dim.dDimension,dim.sName); break; } @@ -117,6 +120,8 @@ namespace WebWindowComplex.Models DimensionList.Add(new FrameDimension(this, 1, "Width", widthVal, true)); DimensionList.Add(new FrameDimension(this, 2, "Left Height", 1800, true)); DimensionList.Add(new FrameDimension(this, 3, "Right Height", 1500, true)); + SearchAreaList(this, widthVal, "Width"); + SearchAreaList(this, 1800, "Left Height"); break; } @@ -125,6 +130,8 @@ namespace WebWindowComplex.Models DimensionList.Add(new FrameDimension(this, 1, "Width", widthVal, true)); DimensionList.Add(new FrameDimension(this, 2, "Left Height", 1500, true)); DimensionList.Add(new FrameDimension(this, 3, "Right Height", 1800, true)); + SearchAreaList(this, widthVal, "Width"); + SearchAreaList(this, 1800, "Right Height"); break; } @@ -134,6 +141,8 @@ namespace WebWindowComplex.Models DimensionList.Add(new FrameDimension(this, 1, "Width", widthVal, true)); DimensionList.Add(new FrameDimension(this, 2, "Height", 1800 - (0.4 * widthVal), true)); DimensionList.Add(new FrameDimension(this, 3, "Full Height", 1800, true)); + SearchAreaList(this, widthVal, "Width"); + SearchAreaList(this, 1800, "Full Height"); break; } @@ -142,6 +151,8 @@ namespace WebWindowComplex.Models DimensionList.Add(new FrameDimension(this, 1, "Width", widthVal, true)); DimensionList.Add(new FrameDimension(this, 2, "Height", 2400 - (0.6 * widthVal), true)); DimensionList.Add(new FrameDimension(this, 3, "Full Height", 2400, true)); + SearchAreaList(this, widthVal, "Width"); + SearchAreaList(this, 2400, "Full Height"); break; } @@ -151,6 +162,8 @@ namespace WebWindowComplex.Models DimensionList.Add(new FrameDimension(this, 2, "Height", 2400 - (0.4 * widthVal), true)); DimensionList.Add(new FrameDimension(this, 3, "Full Height", 2400, true)); DimensionList.Add(new FrameDimension(this, 4, "Radius", 200, true)); + SearchAreaList(this, 2000, "Width"); + SearchAreaList(this, 2400, "Full Height"); break; } @@ -159,6 +172,8 @@ namespace WebWindowComplex.Models DimensionList.Add(new FrameDimension(this, 1, "Width", widthVal, true)); DimensionList.Add(new FrameDimension(this, 2, "Height", 1500, true)); DimensionList.Add(new FrameDimension(this, 3, "Height projection", 0, true)); + SearchAreaList(this, widthVal, "Width"); + SearchAreaList(this, 1500, "Height"); break; } diff --git a/WebWindowComplex/Models/FrameDimension.cs b/WebWindowComplex/Models/FrameDimension.cs index ef3c347..d969a12 100644 --- a/WebWindowComplex/Models/FrameDimension.cs +++ b/WebWindowComplex/Models/FrameDimension.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,16 +9,15 @@ using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex.Models { - public class FrameDimension + public class FrameDimension:AreaDimension { #region Public Constructors - public FrameDimension(Frame ParentFrame, int nIndex, string sName, double dValue, bool bIsLen) + public FrameDimension(Frame ParentFrame, int nIndex, string sName, double dDimension, bool bIsLen) : base(dDimension, MeasureTypes.ABSOLUTE) { m_ParentFrame = ParentFrame; m_nIndex = nIndex; m_sName = sName; - m_dValue = dValue; m_bIsLen = bIsLen; } @@ -25,15 +25,15 @@ namespace WebWindowComplex.Models #region Public Properties - public double dValue + public override double dDimension { get { - return m_dValue; + return m_dDimension; } set { - if(m_dValue != value) + if(dDimension != value) { if (ParentFrame.SelShapeIndex == (int)Shapes.RECTANGLE || ParentFrame.SelShapeIndex == (int)Shapes.RIGHTCHAMFER || @@ -43,91 +43,93 @@ namespace WebWindowComplex.Models { if (value > MaxDim) { - m_dValue = MaxDim; + m_dDimension = MaxDim; } else if (value < MinDim && !m_sName.Equals("Radius") && !m_sName.Equals("Height projection")) { - m_dValue = MinDim; + m_dDimension = MinDim; } else - m_dValue = value; + m_dDimension = value; } else { if (ParentFrame.SelShapeIndex == (int)Shapes.ARC_FULL) { - var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).dValue; - var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).dValue; + var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).m_dDimension; + var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension; if (sName.Equals("Height") && value > 0.5 * width && value < MaxDim) { - m_dValue = value; + m_dDimension = value; } else if (sName.Equals("Width") && height > 0.5 * value && value > MinDim) { - m_dValue = value; + m_dDimension = value; } } else if (ParentFrame.SelShapeIndex == (int)Shapes.ARC) { - var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).dValue; - var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).dValue; - var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).dValue; + var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).m_dDimension; + var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension; + var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).m_dDimension; if (sName.Equals("Full Height") && (value - height) < 0.5 * width && value < MaxDim) { - m_dValue = value; + dDimension = value; } else if (sName.Equals("Height") && (fullHeight - value) < 0.5 * width && value < MaxDim) { - m_dValue = value; + dDimension = value; } else if (sName.Equals("Width") && (fullHeight - height) < 0.5 * value && value < MaxDim) { - m_dValue = value; + dDimension = value; } } else if (ParentFrame.SelShapeIndex == (int)Shapes.THREECENTERARC) { - var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).dValue; - var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).dValue; - var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).dValue; + var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).m_dDimension; + var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension; + var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).m_dDimension; if (sName.Equals("Full Height") && (value - height) < 0.5 * width && value < MaxDim) { - m_dValue = value; + m_dDimension = value; } else if (sName.Equals("Height") && (fullHeight - value) < 0.5 * width && value < MaxDim) { - m_dValue = value; + m_dDimension = value; } else if (sName.Equals("Width") && (fullHeight - height) < 0.5 * value) { - m_dValue = value; + m_dDimension = value; } else if (sName.Equals("Radius") && value < 0.5 * width) { - m_dValue = value; + m_dDimension = value; } } else if (ParentFrame.SelShapeIndex == (int)Shapes.DOUBLEARC) { - var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).dValue; - var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).dValue; - var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).dValue; + var width = ParentFrame.DimensionList.First(x => x.sName.Equals("Width")).m_dDimension; + var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension; + var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).m_dDimension; if (sName.Equals("Full Height") && (value - height) > 0.5 * width && value < MaxDim) { - m_dValue = value; + m_dDimension = value; } else if (sName.Equals("Height") && (fullHeight - value) > 0.5 * width && value < MaxDim) { - m_dValue = value; + m_dDimension = value; } else if (sName.Equals("Width") && (fullHeight - height) > 0.5 * value && value > MinDim) { - m_dValue = value; + m_dDimension = value; } } } - if (ParentFrame.AreaList.Count > 0) - SearchAreaList(ParentFrame); + if (ParentFrame.AreaList.Count > 0 && sName.Equals("Width")) + ParentFrame.SearchAreaList(ParentFrame, dDimension, "Width"); + else + ParentFrame.SearchAreaList(ParentFrame, dDimension, "Height"); } } } @@ -160,107 +162,132 @@ namespace WebWindowComplex.Models #region Internal Methods - /// - /// Cerca nell'albero gli oggetti Sash e Split per associare la larghezza - /// - /// - protected void SearchAreaList(Area node) - { - if (node != null) - { - if (node.AreaType.Equals(AreaTypes.SASH)) - UpdateDimSubArea((Sash)node); - else if (node.AreaType.Equals(AreaTypes.SPLIT)) - UpdateDimSubArea((Split)node); - foreach (var item in node.AreaList) - { - SearchAreaList(item); - } - } - } + ///// + ///// Cerca nell'albero gli oggetti Sash e Split per associare la larghezza + ///// + ///// + //protected void SearchAreaList(Area node) + //{ + // if (node != null) + // { + // if (node.AreaType.Equals(AreaTypes.SASH)) + // UpdateDimSubArea((Sash)node); + // else if (node.AreaType.Equals(AreaTypes.SPLIT)) + // UpdateDimSubArea((Split)node); + // foreach (var item in node.AreaList) + // { + // SearchAreaList(item); + // } + // } + //} - protected void UpdateDimSubArea(Area area) - { - if(area is Sash && sName.Equals("Width")) - { - Sash sash = (Sash)area; - int countAbsolute = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Count(); - int countProportional = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).Count(); - int countPercentage = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).Count(); - if (countAbsolute == sash.SashList.Count) - { - double sum = sash.SashList.Sum(x => x.dDimension); - double res = dValue - sum; - if (res > 0) - { - foreach (var sashDim in sash.SashList) - { - sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); - } - } - else - { - foreach (var sashDim in sash.SashList) - { - // Sommo perchè res è negativo - sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); - } - } - } - else if (countAbsolute < sash.SashList.Count) - { - if (countPercentage > 0 && countPercentage <= sash.SashList.Count && countProportional == 0) - { - double widthTot = ParentFrame.CalculateWidthArea(ParentFrame, ParentFrame.DimensionList.First(x => x.m_sName.Equals("Width")).dValue); - double sumAbsolute = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Sum(x => x.dDimension); - var percentageList = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).ToList(); - foreach(var i in percentageList) - { - i.SetDimension(ConvertIn((widthTot - sumAbsolute) / countPercentage, i.MeasureType, widthTot, sash)); - } - } - } - } - else if(area is Split) - { - Split split = (Split)area; - List splitList = null; - if (sName.Equals("Width")) - splitList = split.SplitVertList; - else - splitList = split.SplitHorizList; - int countAbsolute = splitList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Count(); - if (countAbsolute != 0 && countAbsolute == splitList.Count) - { - double sum = splitList.Sum(x => x.dDimension); - double res = dValue - sum; - if (res > 0) - { - foreach (var sashDim in splitList) - { - sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); - } - } - else - { - foreach (var sashDim in splitList) - { - // Sommo perchè res è negativo - sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); - } - } - } - } - } + //protected void UpdateDimSubArea(Area area) + //{ + // if(area is Sash && sName.Equals("Width")) + // { + // Sash sash = (Sash)area; + // int countAbsolute = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Count(); + // int countProportional = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).Count(); + // int countPercentage = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).Count(); + // double widthTot = 0; + // if (sash.ParentArea is Frame) + // { + // widthTot = ParentFrame.CalculateWidthArea(ParentFrame, ParentFrame.DimensionList.First(x => x.m_sName.Equals("Width")).dValue); + // } + // else + // { + // Split s = (Split)sash.ParentArea.ParentArea; + // int index = s.AreaList.First().AreaList.IndexOf(sash); + // widthTot = s.CalculateWidthArea(s, s.SplitVertList.ElementAt(index).dDimension); + // } + // if (countAbsolute == sash.SashList.Count) + // { + // double sum = sash.SashList.Sum(x => x.dDimension); + // double res = widthTot - sum; + // if (res > 0) + // { + // foreach (var sashDim in sash.SashList) + // { + // sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); + // } + // } + // else + // { + // foreach (var sashDim in sash.SashList) + // { + // // Sommo perchè res è negativo + // sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); + // } + // } + // } + // else if (countAbsolute < sash.SashList.Count) + // { + // if (countPercentage > 0 && countPercentage <= sash.SashList.Count && countProportional == 0) + // { + // double sumAbsolute = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Sum(x => x.dDimension); + // var percentageList = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).ToList(); + // foreach(var i in percentageList) + // { + // i.SetDimension(ConvertIn((widthTot - sumAbsolute) / countPercentage, i.MeasureType, widthTot, sash)); + // } + // } + // } + // } + // else if(area is Split) + // { + // Split split = (Split)area; + // List splitList = null; + // if (sName.Equals("Width")) + // splitList = split.SplitVertList; + // else + // splitList = split.SplitHorizList; + // int countAbsolute = splitList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Count(); + // double widthTot = 0; + // if (split.ParentArea is Frame) + // { + // widthTot = ParentFrame.CalculateWidthArea(ParentFrame, ParentFrame.DimensionList.First(x => x.m_sName.Equals("Width")).dValue); + // } + // else + // { + // Sash s = (Sash)split.ParentArea.ParentArea; + // int index = -1; + // if (s.AreaList.First().AreaList.IndexOf(split) != -1) + // index = s.AreaList.First().AreaList.IndexOf(split); + // else + // index = s.AreaList.Last().AreaList.IndexOf(split); + // widthTot = s.CalculateWidthArea(s, s.SashList.ElementAt(index).dDimension); + // } + // if (countAbsolute != 0 && countAbsolute == splitList.Count) + // { + // double sum = splitList.Sum(x => x.dDimension); + // double res = widthTot - sum; + // if (res > 0) + // { + // foreach (var sashDim in splitList) + // { + // sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); + // } + // } + // else + // { + // foreach (var sashDim in splitList) + // { + // // Sommo perchè res è negativo + // sashDim.SetDimension(sashDim.dDimension + res / countAbsolute); + // } + // } + // } + // } + //} - internal void SetDimension(double dValue) - { - m_dValue = dValue; - } + //internal void SetDimension(double dValue) + //{ + // m_dDimension = dValue; + //} internal JsonFrameDimension Serialize() { - JsonFrameDimension JsonFrameDimension = new JsonFrameDimension(m_nIndex, m_sName, m_dValue); + JsonFrameDimension JsonFrameDimension = new JsonFrameDimension(m_nIndex, m_sName, m_dDimension); return JsonFrameDimension; } @@ -271,48 +298,53 @@ namespace WebWindowComplex.Models /// Tipo di misura della dimensione /// Larghezza totale /// - internal double ConvertIn(double absoluteVal, MeasureTypes type, double widthTot, Sash sash) - { - switch (type) - { - case MeasureTypes.ABSOLUTE: - { - return absoluteVal; - } - case MeasureTypes.PROPORTIONAL: - { - return ProportionalFromAbsoluteVal(absoluteVal, widthTot, sash); - } - case MeasureTypes.PERCENTAGE: - { - return (absoluteVal / widthTot) * 100; - } - } - return -1; - } + //internal double ConvertIn(double absoluteVal, MeasureTypes type, double widthTot, Sash sash) + //{ + // switch (type) + // { + // case MeasureTypes.ABSOLUTE: + // { + // return absoluteVal; + // } + // case MeasureTypes.PROPORTIONAL: + // { + // return ProportionalFromAbsoluteVal(absoluteVal, widthTot, sash); + // } + // case MeasureTypes.PERCENTAGE: + // { + // return (absoluteVal / widthTot) * 100; + // } + // } + // return -1; + //} /// /// Metodo per trasformare il valore proporzionale in assoluto /// /// - internal double ProportionalFromAbsoluteVal(double absoluteVal, double widthTot, Sash sash) - { - double tot = widthTot; - //Somma misura non proporzionali - double sumNotProp = sash.SashList - .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL) - .Sum(m => m.CalculateAbsoluteValue(tot)); - //Calcolo residuo - double res = tot - sumNotProp; - if (res < 0) res = 0; - //Misure proporzionali - var proportionalList = sash.SashList - .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) - .ToList(); - double sumPesi = proportionalList.Sum(p => p.dDimension); - if (sumPesi == 0) sumPesi = 1; - return res / sumPesi * absoluteVal; - } + //internal double ProportionalFromAbsoluteVal(double absoluteVal, double widthTot, Sash sash) + //{ + // double tot = widthTot; + // List adList = new List(); + // foreach (var it in sash.SashList) + // { + // adList.Add(new AreaDimension(it.m_dDimension, it.SelMeasureType)); + // } + // //Somma misura non proporzionali + // double sumNotProp = sash.SashList + // .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL) + // .Sum(m => m.CalculateAbsoluteValue(adList, tot)); + // //Calcolo residuo + // double res = tot - sumNotProp; + // if (res < 0) res = 0; + // //Misure proporzionali + // var proportionalList = sash.SashList + // .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + // .ToList(); + // double sumPesi = proportionalList.Sum(p => p.m_dDimension); + // if (sumPesi == 0) sumPesi = 1; + // return res / sumPesi * absoluteVal; + //} #endregion Internal Methods @@ -326,7 +358,7 @@ namespace WebWindowComplex.Models private bool m_bIsLen = false; - private double m_dValue; + //private double m_dDimension; private int m_nIndex; diff --git a/WebWindowComplex/Models/Sash.cs b/WebWindowComplex/Models/Sash.cs index 54163a8..dc9721b 100644 --- a/WebWindowComplex/Models/Sash.cs +++ b/WebWindowComplex/Models/Sash.cs @@ -34,17 +34,17 @@ namespace WebWindowComplex.Models #region Public Properties - public bool bIsMeasureGlass - { - get - { - return m_bIsMeasureGlass; - } - set - { - m_bIsMeasureGlass = value; - } - } + //public bool bIsMeasureGlass + //{ + // get + // { + // return m_bIsMeasureGlass; + // } + // set + // { + // m_bIsMeasureGlass = value; + // } + //} public bool bIsSashVertical { @@ -104,7 +104,7 @@ namespace WebWindowComplex.Models { if (value > 0 && value <= 3) { - double widthTot = CalculateWidthArea(ParentWindow.AreaList.First(), ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); + double widthTot = CalculateWidthArea(ParentWindow.AreaList.First(), ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); if (value > m_SashList.Count) { // recupero larghezza ultimo @@ -145,7 +145,16 @@ namespace WebWindowComplex.Models SashList.RemoveAt(SplitIndex); } if (!itemDelete.SelMeasureType.Equals(m_SashList[SashList.Count - 1].SelMeasureType)) - deleteDim = itemDelete.ConvertDimension(itemDelete.SelMeasureType, m_SashList[SashList.Count - 1].SelMeasureType, widthTot); + { + AreaDimension ad = new AreaDimension(itemDelete.dDimension, itemDelete.SelMeasureType); + List adList = new List(); + foreach (var it in SashList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + deleteDim = ad.ConvertDimension(adList, itemDelete.SelMeasureType, m_SashList[SashList.Count - 1].SelMeasureType, widthTot, m_SashList.IndexOf(itemDelete)); + } + //deleteDim = Convert.ConvertDimension(itemDelete, itemDelete.SelMeasureType, m_SashList[SashList.Count - 1].SelMeasureType, itemDelete.dDimension, widthTot); else deleteDim = itemDelete.dDimension; //dLastDimension += m_SashList[SashList.Count - 1].dDimension; @@ -227,6 +236,8 @@ namespace WebWindowComplex.Models } } } + for (int i = 0; i < AreaList.Count; i++) + AreaList.ElementAt(i).SearchAreaList(AreaList.ElementAt(i), SashList.ElementAt(i).dDimension, "Width"); } RefreshHardwareList(); ClearHardwareOptionList(); @@ -270,7 +281,6 @@ namespace WebWindowComplex.Models } set { - // Controllo che il valore inserito sia positivo if (value >= 0) { m_nSashBottomRailQty = value; @@ -384,7 +394,6 @@ namespace WebWindowComplex.Models { m_bIsSashVertical = false; } - //m_ParentWindow.OnUpdatePreview(m_ParentWindow.sSerialized()); } } @@ -444,6 +453,9 @@ namespace WebWindowComplex.Models Enums.OpeningTypes sOpeningType = ConvertOpeningType(); if (string.IsNullOrEmpty(m_SelFamilyHardware)) m_SelFamilyHardware = s_FamilyHardwareList.FirstOrDefault(); + int sashPosition = 1; + if (nSashQty > 2 && !(SashList.First().bHasHandle || SashList.Last().bHasHandle)) + sashPosition = 2; var iComp = StringComparison.InvariantCultureIgnoreCase; var rawList = m_HardwareCompleteList .Where(x => x.Id == "000000" || @@ -451,7 +463,8 @@ namespace WebWindowComplex.Models x.FamilyName.Equals(m_SelFamilyHardware, iComp) && x.SashQty == nSashQty && x.Shape.Equals(m_CurrShape, iComp) && - x.OpeningType == sOpeningType) + x.OpeningType == sOpeningType && + x.SashPosition == sashPosition) ) .ToList() ?? new List(); if(rawList.Count == 0 || rawList == null) @@ -475,31 +488,6 @@ namespace WebWindowComplex.Models //m_ParentWindow.OnUpdatePreview(m_ParentWindow.sSerialized()); } - ///// - ///// Richiesta calcolo shape corrente - ///// - //public void ReqRefreshShape() - //{ - // if (m_HardwareCompleteList != null && m_HardwareCompleteList.Count > 0) - // { - // m_HardwareList.Clear(); - // // reset shape corrente - // m_CurrShape = ""; - // // chiamata evento calcolo shape: gruppo da calcolare - // } - //} - - ///// - ///// Richiesta calcolo hardware option list - ///// - //public void ReqRefreshHwOption() - //{ - // HwOptionList.Clear(); - // m_ReqHwOption = true; - // // chiamata evento calcolo opzioni hardware - // //m_ParentWindow.OnReqHwOptionPreview(m_ParentWindow.sSerialized(), GroupId); - //} - public void SetSelFamilyHardware(string sFamilyHw) { m_SelFamilyHardware = sFamilyHw; @@ -559,84 +547,6 @@ namespace WebWindowComplex.Models #region Internal Methods - ///// - ///// Metodo per calcolare larghezza intera sash group - ///// - ///// area di partenza - ///// larghezza di partenza - ///// - //internal double CalculateWidthSashGroup(Area area, double width) - //{ - // for (int i = 0; i < area.AreaList.Count; i++) - // { - // double risultato = -1; - // if (area.Equals(this)) - // return width; - // Area item = area.AreaList[i]; - // if (area is Split) - // { - // Split split = (Split)area; - // if(split.SplitVertList.Count > 0) - // { - // switch (split.SplitVertList.ElementAt(i).SelMeasureType) - // { - // case MeasureTypes.ABSOLUTE: - // { - // risultato = CalculateWidthSashGroup(item, split.SplitVertList.ElementAt(i).dDimension); - // break; - // } - // case MeasureTypes.PROPORTIONAL: - // { - // //risultato = CalculateWidthSashGroup(item, split.SplitVertList.ElementAt(i).dDimension); - // break; - // } - // case MeasureTypes.PERCENTAGE: - // { - // risultato = CalculateWidthSashGroup(item, split.SplitVertList.ElementAt(i).dDimension * width / 100); - // break; - // } - // } - // } - // else - // { - // risultato = CalculateWidthSashGroup(item, width); - // } - // if (risultato != -1) - // return risultato; - // } - // else if (area is Sash) - // { - // Sash sash = (Sash)area; - // switch (sash.SashList.ElementAt(i).SelMeasureType) - // { - // case MeasureTypes.ABSOLUTE: - // { - // risultato = CalculateWidthSashGroup(item, sash.SashList.ElementAt(i).dDimension); - // break; - // } - // case MeasureTypes.PROPORTIONAL: - // { - // //risultato = CalculateWidthSashGroup(item, sash.SashList.ElementAt(i).dDimension); - // break; - // } - // case MeasureTypes.PERCENTAGE: - // { - // risultato = CalculateWidthSashGroup(item, sash.SashList.ElementAt(i).dDimension * width / 100); - // break; - // } - // } - // if (risultato != -1) - // return risultato; - // } - // else - // { - // risultato = CalculateWidthSashGroup(item, width); - // if (risultato != -1) - // return risultato; - // } - // } - // return width; - //} internal static Sash CreateSash(Area Area) { Sash newSash = new Sash(Area, Area.ParentWindow); diff --git a/WebWindowComplex/Models/SashDimension.cs b/WebWindowComplex/Models/SashDimension.cs index a24e41b..da3b283 100644 --- a/WebWindowComplex/Models/SashDimension.cs +++ b/WebWindowComplex/Models/SashDimension.cs @@ -5,15 +5,15 @@ using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex.Models { - public class SashDimension + public class SashDimension : AreaDimension { #region Public Constructors - public SashDimension(double dDimension, MeasureTypes MeasureType, Sash Parent, int nSashId) + public SashDimension(double dDimension, MeasureTypes MeasureType, Sash Parent, int nSashId):base(dDimension, MeasureType) { m_dDimension = dDimension; - m_Parent = Parent; m_nSashId = nSashId; + m_Parent = Parent; SetMeasureType(MeasureType); // assengno maniglia if (Parent.SashList.Count == 0 || !Parent.SashList.Any(x => x.bHasHandle)) @@ -106,6 +106,18 @@ namespace WebWindowComplex.Models } } + public Sash Parent + { + get + { + return m_Parent; + } + set + { + m_Parent = value; + } + } + public List JointList { get @@ -118,7 +130,7 @@ namespace WebWindowComplex.Models } } - public double dDimension + public override double dDimension { get { @@ -126,7 +138,8 @@ namespace WebWindowComplex.Models } set { - double widthTot = CalculateWidthSashGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); + //double widthTot = CalculateWidthSashGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); + double widthTot = CalculateWidthSashGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); double valMinAbsolute = 200; double valMaxAbsolute = widthTot - valMinAbsolute * (m_Parent.SashList.Count - 1); bool valueAccept = false; @@ -155,9 +168,17 @@ namespace WebWindowComplex.Models { List dimensions = m_Parent.SashList; List absoluteValList = new List(); + AreaDimension ad = new AreaDimension(m_dDimension, SelMeasureType); + List adList = new List(); + foreach (var it in m_Parent.SashList) + { + adList.Add(new AreaDimension(it.m_dDimension, it.SelMeasureType)); + } + int index = 0; foreach (var item in m_Parent.SashList) { - absoluteValList.Add(item.CalculateAbsoluteValue(widthTot)); + absoluteValList.Add(adList.ElementAt(index).CalculateAbsoluteValue(adList, widthTot)); + index++; } int nIndex = dimensions.IndexOf(this); int proportionalCount = dimensions.Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).ToList().Count; @@ -171,13 +192,13 @@ namespace WebWindowComplex.Models // Le dimensioni sono solo in percentuale else if (percentageCount == dimensions.Count) { - if (value < dDimension) + if (value < m_dDimension) { // L'anta modificata non è l'ultima if (nIndex < dimensions.Count - 1) - dimensions[nIndex + 1].SetDimension(dimensions[nIndex + 1].dDimension + (m_dDimension - value)); + dimensions[nIndex + 1].SetDimension(dimensions[nIndex + 1].m_dDimension + (m_dDimension - value)); else if (dimensions.Count > 1) - dimensions[nIndex - 1].SetDimension(dimensions[nIndex - 1].dDimension + (m_dDimension - value)); + dimensions[nIndex - 1].SetDimension(dimensions[nIndex - 1].m_dDimension + (m_dDimension - value)); else { m_dDimension = 100; @@ -191,7 +212,7 @@ namespace WebWindowComplex.Models if (nIndex < dimensions.Count - 1) { for (var nInd = 0; nInd <= nIndex - 1; nInd++) - dRes += dimensions[nInd].dDimension; + dRes += dimensions[nInd].m_dDimension; dRes = (100 - dRes) / (dimensions.Count - nIndex - 1); for (var Ind = nIndex + 1; Ind <= dimensions.Count - 1; Ind++) dimensions[Ind].SetDimension(dRes); @@ -202,7 +223,7 @@ namespace WebWindowComplex.Models if (dimensions.Count > 2) { for (var Ind = 0; Ind <= nIndex - 2; Ind++) - dRes += dimensions[Ind].dDimension; + dRes += dimensions[Ind].m_dDimension; } dRes = (100 - dRes); dimensions[nIndex - 1].SetDimension(dRes); @@ -228,9 +249,8 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - var pesi = value + dimensions - .Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL) && !x.Equals(this)) - .Sum(x => x.m_dDimension); + var pesi = value + dimensions.Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL) && !x.Equals(this)) + .Sum(x => x.m_dDimension); valueInAbsolute = widthTot / pesi * value; break; } @@ -240,7 +260,7 @@ namespace WebWindowComplex.Models break; } } - if (value < dDimension) + if (value < m_dDimension) { // L'anta modificata non è l'ultima if (nIndex < absoluteValList.Count - 1) @@ -275,11 +295,12 @@ namespace WebWindowComplex.Models for (int i = 0; i < absoluteValList.Count; i++) { var item = m_Parent.SashList.ElementAt(i); - item.SetDimension(ConvertIn(absoluteValList[i], (MeasureTypes)item.SelMeasureTypeIndex, widthTot)); + item.SetDimension(ad.ConvertIn(adList, absoluteValList[i], (MeasureTypes)item.SelMeasureTypeIndex, widthTot)); } } + foreach(var item in m_Parent.AreaList) + item.SearchAreaList(item, dDimension, "Width"); } - } } @@ -342,48 +363,55 @@ namespace WebWindowComplex.Models } } - public MeasureTypes MeasureType - { - get - { - return m_SelMeasureType; - } - } + //public MeasureTypes MeasureType + //{ + // get + // { + // return m_SelMeasureType; + // } + //} - public List MeasureTypeList - { - get - { - return m_MeasureTypeList; - } - } + //public List MeasureTypeList + //{ + // get + // { + // return m_MeasureTypeList; + // } + //} - public MeasureTypes SelMeasureType + //public MeasureTypes SelMeasureType + //{ + // get + // { + // return m_SelMeasureType; + // } + // set + // { + // m_SelMeasureType = value; + // } + //} + + public override int SelMeasureTypeIndex { get { - return m_SelMeasureType; + return (int)SelMeasureType; } set { - m_SelMeasureType = value; - } - } - - public int SelMeasureTypeIndex - { - get - { - return (int)m_SelMeasureType; - } - set - { - if(m_SelMeasureType != (MeasureTypes)value) + if(SelMeasureType != (MeasureTypes)value) { MeasureTypes newType = (MeasureTypes)value; - double widthTot = CalculateWidthSashGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); - m_dDimension = ConvertDimension(m_SelMeasureType, newType, widthTot); - m_SelMeasureType = (MeasureTypes)value; + double widthTot = CalculateWidthSashGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); + AreaDimension ad = new AreaDimension(m_dDimension, SelMeasureType); + List adList = new List(); + foreach (var it in m_Parent.SashList) + { + adList.Add(new AreaDimension(it.m_dDimension, it.SelMeasureType)); + } + m_dDimension = ad.ConvertDimension(adList, SelMeasureType, newType, widthTot, nSashId-1); + //m_dDimension = Convert.ConvertDimension(this, m_SelMeasureType, newType, m_dDimension, widthTot); + SelMeasureType = (MeasureTypes)value; } } } @@ -398,50 +426,50 @@ namespace WebWindowComplex.Models /// Vecchio tipo /// Nuovo tipo /// - public double ConvertDimension(MeasureTypes oldType, MeasureTypes newType, double widthTot) - { - switch (oldType) - { - case MeasureTypes.ABSOLUTE: - { - if (newType.Equals(MeasureTypes.PERCENTAGE)) - { - //return Double.Round((m_dDimension / m_Parent.Width) * 100, 1); - return (m_dDimension / widthTot) * 100; - } - else - { - return CalculatePropVal(widthTot); - } - } - case MeasureTypes.PROPORTIONAL: - { - if (newType.Equals(MeasureTypes.ABSOLUTE)) - { - //return Double.Round(ConvertFromPropVal(newType), 2); - return ConvertFromPropVal(newType, widthTot); - } - else - { - //return Double.Round(ConvertFromPropVal(newType), 1); - return ConvertFromPropVal(newType, widthTot); - } - } - case MeasureTypes.PERCENTAGE: - { - if (newType.Equals(MeasureTypes.ABSOLUTE)) - { - //return Double.Round((m_dDimension * m_Parent.Width) / 100, 2); - return (m_dDimension * widthTot) / 100; - } - else - { - return CalculatePropVal(widthTot); - } - } - } - return -1; - } + //public double ConvertDimension(MeasureTypes oldType, MeasureTypes newType, double widthTot) + //{ + // switch (oldType) + // { + // case MeasureTypes.ABSOLUTE: + // { + // if (newType.Equals(MeasureTypes.PERCENTAGE)) + // { + // //return Double.Round((m_dDimension / m_Parent.Width) * 100, 1); + // return (m_dDimension / widthTot) * 100; + // } + // else + // { + // return CalculatePropVal(widthTot); + // } + // } + // case MeasureTypes.PROPORTIONAL: + // { + // if (newType.Equals(MeasureTypes.ABSOLUTE)) + // { + // //return Double.Round(ConvertFromPropVal(newType), 2); + // return ConvertFromPropVal(newType, widthTot, dDimension); + // } + // else + // { + // //return Double.Round(ConvertFromPropVal(newType), 1); + // return ConvertFromPropVal(newType, widthTot, dDimension); + // } + // } + // case MeasureTypes.PERCENTAGE: + // { + // if (newType.Equals(MeasureTypes.ABSOLUTE)) + // { + // //return Double.Round((m_dDimension * m_Parent.Width) / 100, 2); + // return (m_dDimension * widthTot) / 100; + // } + // else + // { + // return CalculatePropVal(widthTot); + // } + // } + // } + // return -1; + //} /// /// Metodo per copiare l'intero oggetto @@ -449,7 +477,7 @@ namespace WebWindowComplex.Models /// public SashDimension Copy() { - SashDimension newSashDim = new SashDimension(dDimension, MeasureType, m_Parent, m_nSashId); + SashDimension newSashDim = new SashDimension(m_dDimension, MeasureType, m_Parent, m_nSashId); newSashDim.SetMeasureType(MeasureType); newSashDim.SetOpeningType(SelOpeningType); newSashDim.SetHasHandle(bHasHandle); @@ -493,7 +521,13 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - //risultato = CalculateWidthSashGroup(item, split.SplitVertList.ElementAt(i).dDimension); + AreaDimension ad = new AreaDimension(split.SplitVertList.ElementAt(i).dDimension, split.SplitVertList.ElementAt(i).SelMeasureType); + List adList = new List(); + foreach(var it in split.SplitVertList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + risultato = CalculateWidthSashGroup(item, ad.ConvertFromPropVal(adList, MeasureTypes.ABSOLUTE, width)); break; } case MeasureTypes.PERCENTAGE: @@ -522,7 +556,14 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - //risultato = CalculateWidthSashGroup(item, sash.SashList.ElementAt(i).dDimension); + //risultato = CalculateWidthSashGroup(item, ConvertFromPropVal(MeasureTypes.ABSOLUTE, width, sash.SashList.ElementAt(i).dDimension)); + AreaDimension ad = new AreaDimension(sash.SashList.ElementAt(i).dDimension, sash.SashList.ElementAt(i).SelMeasureType); + List adList = new List(); + foreach (var it in sash.SashList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + risultato = CalculateWidthSashGroup(item, ad.ConvertFromPropVal(adList, MeasureTypes.ABSOLUTE, width)); break; } case MeasureTypes.PERCENTAGE: @@ -544,185 +585,185 @@ namespace WebWindowComplex.Models return width; } - /// - /// Calcolo MCD - /// - /// - /// - /// - internal static double CalculateMCD(double a, double b) - { - while (b >= 0.01) - { - double temp = b; - b = a % b; - a = temp; - } - //return Double.Round(a,2); - return a; - } + ///// + ///// Calcolo MCD + ///// + ///// + ///// + ///// + //internal static double CalculateMCD(double a, double b) + //{ + // while (b >= 0.01) + // { + // double temp = b; + // b = a % b; + // a = temp; + // } + // //return Double.Round(a,2); + // return a; + //} - /// - /// Metodo per ricalcolare i valori proporzionali a causa della modifica di uno - /// - /// - internal double CalculatePropVal(double widthTot) - { - if (m_Parent.SashList.Where(m => m.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).ToList().Count == 0) - { - return 1; - } - List absoluteValue = new List(); - foreach (var item in m_Parent.SashList) - { - absoluteValue.Add(item.CalculateAbsoluteValue(widthTot)); - } - for (int i = 0; i < m_Parent.SashList.Count; i++) - { - if (!m_Parent.SashList.ElementAt(i).Equals(this) && - m_Parent.SashList.ElementAt(i).MeasureType.Equals(MeasureTypes.PROPORTIONAL)) - { - int nIndex = m_Parent.SashList.IndexOf(this); - if (absoluteValue.ElementAt(nIndex) <= absoluteValue.ElementAt(i)) - { - var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); - m_Parent.SashList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; - m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; - } - else - { - var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); - m_Parent.SashList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; - m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; - } - break; - } - } - return m_dDimension; - } + ///// + ///// Metodo per ricalcolare i valori proporzionali a causa della modifica di uno + ///// + ///// + //internal double CalculatePropVal(double widthTot) + //{ + // if (m_Parent.SashList.Where(m => m.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).ToList().Count == 0) + // { + // return 1; + // } + // List absoluteValue = new List(); + // foreach (var item in m_Parent.SashList) + // { + // absoluteValue.Add(item.CalculateAbsoluteValue(widthTot)); + // } + // for (int i = 0; i < m_Parent.SashList.Count; i++) + // { + // if (!m_Parent.SashList.ElementAt(i).Equals(this) && + // m_Parent.SashList.ElementAt(i).MeasureType.Equals(MeasureTypes.PROPORTIONAL)) + // { + // int nIndex = m_Parent.SashList.IndexOf(this); + // if (absoluteValue.ElementAt(nIndex) <= absoluteValue.ElementAt(i)) + // { + // var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); + // m_Parent.SashList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; + // m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; + // } + // else + // { + // var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); + // m_Parent.SashList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; + // m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; + // } + // break; + // } + // } + // return m_dDimension; + //} - /// - /// Metodo per trasformare una dimensione in valore assoluto rispetto alla larghezza totale - /// - /// Larghezza totale - /// - internal double CalculateAbsoluteValue(double widthTot) - { - switch (MeasureType) - { - case MeasureTypes.ABSOLUTE: - { - //return Double.Round(dDimension, 2); - return dDimension; - } - case MeasureTypes.PROPORTIONAL: - { - //return Double.Round(Proportional2AbsolutVal(), 2); - return ProportionalFromAbsoluteVal(widthTot); - } - case MeasureTypes.PERCENTAGE: - { - //return Double.Round((dDimension / 100) * widthTot, 1); - return (dDimension / 100) * widthTot; - } - } - return 0; - } + ///// + ///// Metodo per trasformare una dimensione in valore assoluto rispetto alla larghezza totale + ///// + ///// Larghezza totale + ///// + //internal double CalculateAbsoluteValue(double widthTot) + //{ + // switch (MeasureType) + // { + // case MeasureTypes.ABSOLUTE: + // { + // //return Double.Round(dDimension, 2); + // return dDimension; + // } + // case MeasureTypes.PROPORTIONAL: + // { + // //return Double.Round(Proportional2AbsolutVal(), 2); + // return ProportionalFromAbsoluteVal(widthTot); + // } + // case MeasureTypes.PERCENTAGE: + // { + // //return Double.Round((dDimension / 100) * widthTot, 1); + // return (dDimension / 100) * widthTot; + // } + // } + // return 0; + //} - /// - /// Metodo per convertire una dimensione da un valore assoluto al suo rispettivo tipo - /// - /// Valore assoluto - /// Tipo di misura della dimensione - /// Larghezza totale - /// - internal double ConvertIn(double absoluteVal, MeasureTypes type, double widthTot) - { - switch (type) - { - case MeasureTypes.ABSOLUTE: - { - return absoluteVal; - } - case MeasureTypes.PROPORTIONAL: - { - return ProportionalFromAbsoluteVal(widthTot); - } - case MeasureTypes.PERCENTAGE: - { - return (absoluteVal / widthTot) * 100; - } - } - return -1; - } + ///// + ///// Metodo per convertire una dimensione da un valore assoluto al suo rispettivo tipo + ///// + ///// Valore assoluto + ///// Tipo di misura della dimensione + ///// Larghezza totale + ///// + //internal double ConvertIn(double absoluteVal, MeasureTypes type, double widthTot) + //{ + // switch (type) + // { + // case MeasureTypes.ABSOLUTE: + // { + // return absoluteVal; + // } + // case MeasureTypes.PROPORTIONAL: + // { + // return ProportionalFromAbsoluteVal(widthTot); + // } + // case MeasureTypes.PERCENTAGE: + // { + // return (absoluteVal / widthTot) * 100; + // } + // } + // return -1; + //} - /// - /// Metodo per convertire da misura proporzionale a misura assoluta o percentuale - /// - /// - /// - internal double ConvertFromPropVal(MeasureTypes newType, double widthTot) - { - double tot = widthTot; - //Somma misura non proporzionali - double sumNotProp = m_Parent.SashList - .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL && !m.Equals(this)) - .Sum(m => m.CalculateAbsoluteValue(tot)); - //Calcolo residuo - double res = tot - sumNotProp; - if (res < 0) res = 0; - //Misure proporzionali - var proportionalList = m_Parent.SashList - .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) - .ToList(); + ///// + ///// Metodo per convertire da misura proporzionale a misura assoluta o percentuale + ///// + ///// + ///// + //internal double ConvertFromPropVal(MeasureTypes newType, double widthTot, double dim) + //{ + // double tot = widthTot; + // //Somma misura non proporzionali + // double sumNotProp = m_Parent.SashList + // .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL && !m.Equals(this)) + // .Sum(m => m.CalculateAbsoluteValue(tot)); + // //Calcolo residuo + // double res = tot - sumNotProp; + // if (res < 0) res = 0; + // //Misure proporzionali + // var proportionalList = m_Parent.SashList + // .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + // .ToList(); - double sumPesi = proportionalList.Sum(p => p.dDimension); - if (sumPesi == 0) sumPesi = 1; - if (newType.Equals(MeasureTypes.ABSOLUTE)) - { - return res / sumPesi * dDimension; - } - else - { - return (res / sumPesi * dDimension) / tot * 100; - } - } + // double sumPesi = proportionalList.Sum(p => p.dDimension); + // if (sumPesi == 0) sumPesi = 1; + // if (newType.Equals(MeasureTypes.ABSOLUTE)) + // { + // return res / sumPesi * dim; + // } + // else + // { + // return (res / sumPesi * dim) / tot * 100; + // } + //} - /// - /// Metodo per trasformare il valore proporzionale in assoluto - /// - /// - internal double ProportionalFromAbsoluteVal(double widthTot) - { - double tot = widthTot; - //Somma misura non proporzionali - double sumNotProp = m_Parent.SashList - .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL) - .Sum(m => m.CalculateAbsoluteValue(tot)); - //Calcolo residuo - double res = tot - sumNotProp; - if (res < 0) res = 0; - //Misure proporzionali - var proportionalList = m_Parent.SashList - .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) - .ToList(); - double sumPesi = proportionalList.Sum(p => p.dDimension); - if (sumPesi == 0) sumPesi = 1; - return res / sumPesi * dDimension; - } + ///// + ///// Metodo per trasformare il valore proporzionale in assoluto + ///// + ///// + //internal double ProportionalFromAbsoluteVal(double widthTot) + //{ + // double tot = widthTot; + // //Somma misura non proporzionali + // double sumNotProp = m_Parent.SashList + // .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL) + // .Sum(m => m.CalculateAbsoluteValue(tot)); + // //Calcolo residuo + // double res = tot - sumNotProp; + // if (res < 0) res = 0; + // //Misure proporzionali + // var proportionalList = m_Parent.SashList + // .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + // .ToList(); + // double sumPesi = proportionalList.Sum(p => p.dDimension); + // if (sumPesi == 0) sumPesi = 1; + // return res / sumPesi * dDimension; + //} internal JsonSashDimension Serialize() { - JsonSashDimension JsonSashDimension = new JsonSashDimension(OpeningType, MeasureType, m_bHasHandle, m_dDimension, m_nSashId); + JsonSashDimension JsonSashDimension = new JsonSashDimension(OpeningType, MeasureType, m_bHasHandle, dDimension, m_nSashId); foreach (var Joint in JointList) JsonSashDimension.JointList.Add(Joint.Serialize()); return JsonSashDimension; } - internal void SetDimension(double dValue) - { - m_dDimension = dValue; - } + //internal void SetDimension(double dValue) + //{ + // m_dDimension = dValue; + //} internal void SetHasHandle(bool value) { @@ -736,17 +777,28 @@ namespace WebWindowComplex.Models internal void SetMeasureType(MeasureTypes value) { - m_SelMeasureType = value; + SelMeasureType = value; } - internal void SetSelMeasureType(MeasureTypes value) + internal void SetSelMeasureType(MeasureTypes value, int indexSash) { - if (m_SelMeasureType != (MeasureTypes)value) + if (SelMeasureType != (MeasureTypes)value) { MeasureTypes newType = (MeasureTypes)value; - double widthTot = CalculateWidthSashGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); - m_dDimension = ConvertDimension(m_SelMeasureType, newType, widthTot); - m_SelMeasureType = (MeasureTypes)value; + double widthTot = CalculateWidthSashGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); + AreaDimension ad = new AreaDimension(dDimension, SelMeasureType); + List newDimensions = new List(); + foreach(var item in m_Parent.SashList) + { + newDimensions.Add(new AreaDimension(item.dDimension, item.SelMeasureType)); + } + m_dDimension = ad.ConvertDimension(newDimensions, SelMeasureType, newType, widthTot, indexSash); + if(newType is MeasureTypes.PROPORTIONAL) + { + for (int i = 0; i < newDimensions.Count; i++) + m_Parent.SashList.ElementAt(i).SetDimension(newDimensions.ElementAt(i).dDimension); + } + SelMeasureType = (MeasureTypes)value; } } @@ -756,7 +808,7 @@ namespace WebWindowComplex.Models private bool m_bHasHandle; - private double m_dDimension; + //private double m_dDimension; private int m_nSashId; @@ -789,12 +841,12 @@ namespace WebWindowComplex.Models //new IdNameStruct((int)Openings.LIFTSLIDE_RIGHT, "←┐") }; - private List m_MeasureTypeList = new List - { - new IdNameStruct((int)MeasureTypes.ABSOLUTE, "Absolute"), - new IdNameStruct((int)MeasureTypes.PROPORTIONAL, "Proportional"), - new IdNameStruct((int)MeasureTypes.PERCENTAGE, "Percentage"), - }; + //private List m_MeasureTypeList = new List + //{ + // new IdNameStruct((int)MeasureTypes.ABSOLUTE, "Absolute"), + // new IdNameStruct((int)MeasureTypes.PROPORTIONAL, "Proportional"), + // new IdNameStruct((int)MeasureTypes.PERCENTAGE, "Percentage"), + //}; // reference private Sash m_Parent; @@ -803,7 +855,7 @@ namespace WebWindowComplex.Models private Openings m_SelOpeningType; - private MeasureTypes m_SelMeasureType; + //private MeasureTypes m_SelMeasureType; #endregion Private Fields diff --git a/WebWindowComplex/Models/Split.cs b/WebWindowComplex/Models/Split.cs index 4169ecf..61eaf0e 100644 --- a/WebWindowComplex/Models/Split.cs +++ b/WebWindowComplex/Models/Split.cs @@ -127,7 +127,6 @@ namespace WebWindowComplex.Models ParentArea.AreaList.Remove(this); } } - //m_ParentWindow.OnUpdatePreview(m_ParentWindow.sSerialized()); } } } @@ -158,7 +157,7 @@ namespace WebWindowComplex.Models } else { - double widthTot = CalculateWidthArea(ParentWindow.AreaList.First(), ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); + double widthTot = CalculateWidthArea(ParentWindow.AreaList.First(), ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); // Ricalcolo dimensioni aggiungendo split if (value > m_SplitVertList.Count - 1) { @@ -224,6 +223,24 @@ namespace WebWindowComplex.Models ParentArea.AreaList.Remove(this); } } + if(SplitHorizList.Count > 0) + { + int i = 0; + foreach (var item in AreaList) + { + item.SearchAreaList(item, SplitHorizList.ElementAt(i).dDimension, "Width"); + i++; + } + } + if (SplitVertList.Count > 0) + { + int i = 0; + foreach (var item in AreaList) + { + item.SearchAreaList(item, SplitVertList.ElementAt(i).dDimension, "Height"); + i++; + } + } } } } @@ -469,19 +486,19 @@ namespace WebWindowComplex.Models case (int)Shapes.TRIANGLE: case (int)Shapes.ARC_FULL: { - return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Height").First().dValue; + return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Height").First().dDimension; } case (int)Shapes.RIGHTCHAMFER: { - return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Left Height").First().dValue; + return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Left Height").First().dDimension; } case (int)Shapes.LEFTCHAMFER: { - return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Right Height").First().dValue; + return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Right Height").First().dDimension; } default: { - return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Full Height").First().dValue; + return ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Full Height").First().dDimension; } } } diff --git a/WebWindowComplex/Models/SplitDimension.cs b/WebWindowComplex/Models/SplitDimension.cs index 391b8c8..cbea2e9 100644 --- a/WebWindowComplex/Models/SplitDimension.cs +++ b/WebWindowComplex/Models/SplitDimension.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,14 +9,13 @@ using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex.Models { - public class SplitDimension + public class SplitDimension:AreaDimension { #region Public Constructors - public SplitDimension(double dDimension, MeasureTypes MeasureType, bool bIsRelative, Split Parent, bool IsVertList) + public SplitDimension(double dDimension, MeasureTypes MeasureType, bool bIsRelative, Split Parent, bool IsVertList):base(dDimension, MeasureType) { m_dDimension = dDimension; - m_SelMeasureType = MeasureType; m_bIsRelative = bIsRelative; m_Parent = Parent; m_bIsVertListDim = IsVertList; @@ -41,7 +41,7 @@ namespace WebWindowComplex.Models } } - public double dDimension + public override double dDimension { get { @@ -54,12 +54,12 @@ namespace WebWindowComplex.Models if (bIsVertListDim) { dimensions = m_Parent.SplitVertList; - dimensionTot = CalculateWidthSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); + dimensionTot = CalculateWidthSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); } else { dimensions = m_Parent.SplitHorizList; - dimensionTot = CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), HeightTot()); + dimensionTot = CalculateHeightSplitGroup(m_Parent, HeightTot()); } double valMinAbsolute = 100; double valMaxAbsolute = dimensionTot - valMinAbsolute * (dimensions.Count - 1); @@ -88,9 +88,15 @@ namespace WebWindowComplex.Models if (valueAccept) { List absoluteValList = new List(); + AreaDimension ad = new AreaDimension(dDimension, SelMeasureType); + List adList = new List(); + foreach (var it in dimensions) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } foreach (var item in dimensions) { - absoluteValList.Add(item.CalculateAbsoluteValue(dimensionTot, dimensions)); + absoluteValList.Add(item.CalculateAbsoluteValue(adList, dimensionTot)); } int nIndex = dimensions.IndexOf(this); int proportionalCount = dimensions.Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).ToList().Count; @@ -207,11 +213,30 @@ namespace WebWindowComplex.Models for (int i = 0; i < absoluteValList.Count; i++) { var item = dimensions.ElementAt(i); - item.SetDimension(ConvertIn(absoluteValList[i], (MeasureTypes)item.SelMeasureTypeIndex, dimensionTot, dimensions)); + //item.SetDimension(ConvertIn(absoluteValList[i], (MeasureTypes)item.SelMeasureTypeIndex, dimensionTot, dimensions)); + item.SetDimension(ad.ConvertIn(adList, absoluteValList[i], (MeasureTypes)item.SelMeasureTypeIndex, dimensionTot)); + } + } + foreach (var item in m_Parent.AreaList) + { + if (m_Parent.SplitHorizList.Count > 0) + { + for (int i = 0; i < m_Parent.AreaList.Count(); i++) + { + item.SearchAreaList(item, m_Parent.SplitHorizList.ElementAt(i).dDimension, "Width"); + i++; + } + } + if (m_Parent.SplitVertList.Count > 0) + { + for (int i = 0; i < m_Parent.AreaList.Count(); i++) + { + item.SearchAreaList(item, m_Parent.SplitVertList.ElementAt(i).dDimension, "Height"); + i++; + } } } } - } } @@ -227,35 +252,35 @@ namespace WebWindowComplex.Models } } - public MeasureTypes MeasureType - { - get - { - return m_SelMeasureType; - } - } + //public MeasureTypes MeasureType + //{ + // get + // { + // return m_SelMeasureType; + // } + //} - public List MeasureTypeList - { - get - { - return m_MeasureTypeList; - } - } + //public List MeasureTypeList + //{ + // get + // { + // return m_MeasureTypeList; + // } + //} - public MeasureTypes SelMeasureType - { - get - { - return m_SelMeasureType; - } - set - { - m_SelMeasureType = value; - } - } + //public MeasureTypes SelMeasureType + //{ + // get + // { + // return m_SelMeasureType; + // } + // set + // { + // m_SelMeasureType = value; + // } + //} - public int SelMeasureTypeIndex + public override int SelMeasureTypeIndex { get { @@ -271,14 +296,20 @@ namespace WebWindowComplex.Models if (bIsVertListDim) { splitList = m_Parent.SplitVertList; - tot = CalculateWidthSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); + tot = CalculateWidthSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); } else { splitList = m_Parent.SplitHorizList; tot = CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), HeightTot()); } - m_dDimension = ConvertDimension(m_SelMeasureType, newType, tot, splitList); + AreaDimension ad = new AreaDimension(dDimension, SelMeasureType); + List adList = new List(); + foreach (var it in splitList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + m_dDimension = ad.ConvertDimension(adList, m_SelMeasureType, newType, tot, splitList.IndexOf(this)); m_SelMeasureType = (MeasureTypes)value; //m_Parent.ParentWindow.OnUpdatePreview(m_Parent.ParentWindow.sSerialized()); } @@ -289,56 +320,56 @@ namespace WebWindowComplex.Models #region Public Methods - /// - /// Metodo per convertire la dimensione dal vecchio tipo al nuovo tipo - /// - /// Vecchio tipo - /// Nuovo tipo - /// - public double ConvertDimension(MeasureTypes oldType, MeasureTypes newType, double widthTot, List splitList) - { - switch (oldType) - { - case MeasureTypes.ABSOLUTE: - { - if (newType.Equals(MeasureTypes.PERCENTAGE)) - { - //return Double.Round((m_dDimension / m_Parent.Width) * 100, 1); - return (m_dDimension / widthTot) * 100; - } - else - { - return CalculatePropVal(widthTot, splitList); - } - } - case MeasureTypes.PROPORTIONAL: - { - if (newType.Equals(MeasureTypes.ABSOLUTE)) - { - //return Double.Round(ConvertFromPropVal(newType), 2); - return ConvertFromPropVal(newType, widthTot, splitList); - } - else - { - //return Double.Round(ConvertFromPropVal(newType), 1); - return ConvertFromPropVal(newType, widthTot, splitList); - } - } - case MeasureTypes.PERCENTAGE: - { - if (newType.Equals(MeasureTypes.ABSOLUTE)) - { - //return Double.Round((m_dDimension * m_Parent.Width) / 100, 2); - return (m_dDimension * widthTot) / 100; - } - else - { - return CalculatePropVal(widthTot, splitList); - } - } - } - return -1; - } + ///// + ///// Metodo per convertire la dimensione dal vecchio tipo al nuovo tipo + ///// + ///// Vecchio tipo + ///// Nuovo tipo + ///// + //public double ConvertDimension(MeasureTypes oldType, MeasureTypes newType, double widthTot, List splitList) + //{ + // switch (oldType) + // { + // case MeasureTypes.ABSOLUTE: + // { + // if (newType.Equals(MeasureTypes.PERCENTAGE)) + // { + // //return Double.Round((m_dDimension / m_Parent.Width) * 100, 1); + // return (m_dDimension / widthTot) * 100; + // } + // else + // { + // return CalculatePropVal(widthTot, splitList); + // } + // } + // case MeasureTypes.PROPORTIONAL: + // { + // if (newType.Equals(MeasureTypes.ABSOLUTE)) + // { + // //return Double.Round(ConvertFromPropVal(newType), 2); + // return ConvertFromPropVal(newType, widthTot, splitList); + // } + // else + // { + // //return Double.Round(ConvertFromPropVal(newType), 1); + // return ConvertFromPropVal(newType, widthTot, splitList); + // } + // } + // case MeasureTypes.PERCENTAGE: + // { + // if (newType.Equals(MeasureTypes.ABSOLUTE)) + // { + // //return Double.Round((m_dDimension * m_Parent.Width) / 100, 2); + // return (m_dDimension * widthTot) / 100; + // } + // else + // { + // return CalculatePropVal(widthTot, splitList); + // } + // } + // } + // return -1; + //} public SplitDimension Copy() { @@ -358,11 +389,11 @@ namespace WebWindowComplex.Models /// internal double CalculateWidthSplitGroup(Area area, double width) { + if (area.Equals(m_Parent)) + return width; for (int i = 0; i < area.AreaList.Count; i++) { double risultato = -1; - if (area.Equals(m_Parent)) - return width; Area item = area.AreaList[i]; if (area is Split) { @@ -378,6 +409,13 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { + AreaDimension ad = new AreaDimension(split.SplitVertList.ElementAt(i).dDimension, split.SplitVertList.ElementAt(i).SelMeasureType); + List adList = new List(); + foreach (var it in split.SplitVertList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + risultato = CalculateWidthSplitGroup(item, ad.ConvertFromPropVal(adList, MeasureTypes.ABSOLUTE, width)); //risultato = CalculateWidthSplitGroup(item, split.SplitVertList.ElementAt(i).dDimension); break; } @@ -393,6 +431,8 @@ namespace WebWindowComplex.Models else { risultato = CalculateWidthSplitGroup(item, width); + if (risultato != -1) + return risultato; } } else if (area is Sash) @@ -407,6 +447,13 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { + AreaDimension ad = new AreaDimension(sash.SashList.ElementAt(i).dDimension, sash.SashList.ElementAt(i).SelMeasureType); + List adList = new List(); + foreach (var it in sash.SashList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + risultato = CalculateWidthSplitGroup(item, ad.ConvertFromPropVal(adList, MeasureTypes.ABSOLUTE, width)); //risultato = CalculateWidthSplitGroup(item, sash.SashList.ElementAt(i).dDimension); break; } @@ -426,7 +473,7 @@ namespace WebWindowComplex.Models return risultato; } } - return width; + return -1; } /// @@ -457,7 +504,13 @@ namespace WebWindowComplex.Models } case MeasureTypes.PROPORTIONAL: { - //risultato = CalculateHeightSplitGroup(item, split.SplitVertList.ElementAt(i).dDimension); + AreaDimension ad = new AreaDimension(split.SplitHorizList.ElementAt(i).dDimension, split.SplitHorizList.ElementAt(i).SelMeasureType); + List adList = new List(); + foreach (var it in split.SplitHorizList) + { + adList.Add(new AreaDimension(it.dDimension, it.SelMeasureType)); + } + risultato = CalculateHeightSplitGroup(item, ad.ConvertFromPropVal(adList, MeasureTypes.ABSOLUTE, height)); break; } case MeasureTypes.PERCENTAGE: @@ -472,6 +525,8 @@ namespace WebWindowComplex.Models else { risultato = CalculateHeightSplitGroup(item, height); + if (risultato != -1) + return risultato; } } else @@ -484,172 +539,172 @@ namespace WebWindowComplex.Models return height; } - /// - /// Calcolo MCD - /// - /// - /// - /// - internal static double CalculateMCD(double a, double b) - { - while (b >= 0.01) - { - double temp = b; - b = a % b; - a = temp; - } - //return Double.Round(a,2); - return a; - } + ///// + ///// Calcolo MCD + ///// + ///// + ///// + ///// + //internal static double CalculateMCD(double a, double b) + //{ + // while (b >= 0.01) + // { + // double temp = b; + // b = a % b; + // a = temp; + // } + // //return Double.Round(a,2); + // return a; + //} - /// - /// Metodo per ricalcolare i valori proporzionali a causa della modifica di uno - /// - /// - internal double CalculatePropVal(double widthTot, List splitList) - { - if (splitList.Where(m => m.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).ToList().Count == 0) - { - return 1; - } - List absoluteValue = new List(); - foreach (var item in splitList) - { - absoluteValue.Add(item.CalculateAbsoluteValue(widthTot, splitList)); - } - for (int i = 0; i < splitList.Count; i++) - { - if (!splitList.ElementAt(i).Equals(this) && - splitList.ElementAt(i).MeasureType.Equals(MeasureTypes.PROPORTIONAL)) - { - int nIndex = splitList.IndexOf(this); - if (absoluteValue.ElementAt(nIndex) <= absoluteValue.ElementAt(i)) - { - var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); - splitList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; - m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; - } - else - { - var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); - splitList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; - m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; - } - break; - } - } - return m_dDimension; - } + ///// + ///// Metodo per ricalcolare i valori proporzionali a causa della modifica di uno + ///// + ///// + //internal double CalculatePropVal(double widthTot, List splitList) + //{ + // if (splitList.Where(m => m.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).ToList().Count == 0) + // { + // return 1; + // } + // List absoluteValue = new List(); + // foreach (var item in splitList) + // { + // absoluteValue.Add(item.CalculateAbsoluteValue(widthTot, splitList)); + // } + // for (int i = 0; i < splitList.Count; i++) + // { + // if (!splitList.ElementAt(i).Equals(this) && + // splitList.ElementAt(i).MeasureType.Equals(MeasureTypes.PROPORTIONAL)) + // { + // int nIndex = splitList.IndexOf(this); + // if (absoluteValue.ElementAt(nIndex) <= absoluteValue.ElementAt(i)) + // { + // var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); + // splitList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; + // m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; + // } + // else + // { + // var mcd = CalculateMCD(absoluteValue.ElementAt(nIndex), absoluteValue.ElementAt(i)); + // splitList.ElementAt(i).m_dDimension = absoluteValue.ElementAt(i) / mcd; + // m_dDimension = absoluteValue.ElementAt(nIndex) / mcd; + // } + // break; + // } + // } + // return m_dDimension; + //} - /// - /// Metodo per trasformare una dimensione in valore assoluto rispetto alla larghezza totale - /// - /// Larghezza totale - /// - internal double CalculateAbsoluteValue(double widthTot, List splitList) - { - switch (MeasureType) - { - case MeasureTypes.ABSOLUTE: - { - //return Double.Round(dDimension, 2); - return dDimension; - } - case MeasureTypes.PROPORTIONAL: - { - //return Double.Round(Proportional2AbsolutVal(), 2); - return Proportional2AbsoluteVal(widthTot, splitList); - } - case MeasureTypes.PERCENTAGE: - { - //return Double.Round((dDimension / 100) * widthTot, 1); - return (dDimension / 100) * widthTot; - } - } - return 0; - } + ///// + ///// Metodo per trasformare una dimensione in valore assoluto rispetto alla larghezza totale + ///// + ///// Larghezza totale + ///// + //internal double CalculateAbsoluteValue(double widthTot, List splitList) + //{ + // switch (MeasureType) + // { + // case MeasureTypes.ABSOLUTE: + // { + // //return Double.Round(dDimension, 2); + // return dDimension; + // } + // case MeasureTypes.PROPORTIONAL: + // { + // //return Double.Round(Proportional2AbsolutVal(), 2); + // return Proportional2AbsoluteVal(widthTot, splitList); + // } + // case MeasureTypes.PERCENTAGE: + // { + // //return Double.Round((dDimension / 100) * widthTot, 1); + // return (dDimension / 100) * widthTot; + // } + // } + // return 0; + //} - /// - /// Metodo per convertire una dimensione da un valore assoluto al suo rispettivo tipo - /// - /// Valore assoluto - /// Tipo di misura della dimensione - /// Larghezza totale - /// - internal double ConvertIn(double absoluteVal, MeasureTypes type, double widthTot, List splitList) - { - switch (type) - { - case MeasureTypes.ABSOLUTE: - { - return absoluteVal; - } - case MeasureTypes.PROPORTIONAL: - { - return Proportional2AbsoluteVal(widthTot, splitList); - } - case MeasureTypes.PERCENTAGE: - { - return (absoluteVal / widthTot) * 100; - } - } - return -1; - } + ///// + ///// Metodo per convertire una dimensione da un valore assoluto al suo rispettivo tipo + ///// + ///// Valore assoluto + ///// Tipo di misura della dimensione + ///// Larghezza totale + ///// + //internal double ConvertIn(double absoluteVal, MeasureTypes type, double widthTot, List splitList) + //{ + // switch (type) + // { + // case MeasureTypes.ABSOLUTE: + // { + // return absoluteVal; + // } + // case MeasureTypes.PROPORTIONAL: + // { + // return Proportional2AbsoluteVal(widthTot, splitList); + // } + // case MeasureTypes.PERCENTAGE: + // { + // return (absoluteVal / widthTot) * 100; + // } + // } + // return -1; + //} - /// - /// Metodo per convertire da misura proporzionale a misura assoluta o percentuale - /// - /// - /// - internal double ConvertFromPropVal(MeasureTypes newType, double widthTot, List splitList) - { - double tot = widthTot; - //Somma misura non proporzionali - double sumNotProp = splitList - .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL && !m.Equals(this)) - .Sum(m => m.CalculateAbsoluteValue(tot, splitList)); - //Calcolo residuo - double res = tot - sumNotProp; - if (res < 0) res = 0; - //Misure proporzionali - var proportionalList = splitList - .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) - .ToList(); + ///// + ///// Metodo per convertire da misura proporzionale a misura assoluta o percentuale + ///// + ///// + ///// + //internal double ConvertFromPropVal(MeasureTypes newType, double widthTot, List splitList) + //{ + // double tot = widthTot; + // //Somma misura non proporzionali + // double sumNotProp = splitList + // .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL && !m.Equals(this)) + // .Sum(m => m.CalculateAbsoluteValue(tot, splitList)); + // //Calcolo residuo + // double res = tot - sumNotProp; + // if (res < 0) res = 0; + // //Misure proporzionali + // var proportionalList = splitList + // .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + // .ToList(); - double sumPesi = proportionalList.Sum(p => p.dDimension); - if (sumPesi == 0) sumPesi = 1; - if (newType.Equals(MeasureTypes.ABSOLUTE)) - { - return res / sumPesi * dDimension; - } - else - { - return (res / sumPesi * dDimension) / tot * 100; - } - } + // double sumPesi = proportionalList.Sum(p => p.dDimension); + // if (sumPesi == 0) sumPesi = 1; + // if (newType.Equals(MeasureTypes.ABSOLUTE)) + // { + // return res / sumPesi * dDimension; + // } + // else + // { + // return (res / sumPesi * dDimension) / tot * 100; + // } + //} - /// - /// Metodo per trasformare il valore proporzionale in assoluto - /// - /// - internal double Proportional2AbsoluteVal(double widthTot, List splitList) - { - double tot = widthTot; - //Somma misura non proporzionali - double sumNotProp = splitList - .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL) - .Sum(m => m.CalculateAbsoluteValue(tot, splitList)); - //Calcolo residuo - double res = tot - sumNotProp; - if (res < 0) res = 0; - //Misure proporzionali - var proportionalList = splitList - .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) - .ToList(); - double sumPesi = proportionalList.Sum(p => p.dDimension); - if (sumPesi == 0) sumPesi = 1; - return res / sumPesi * dDimension; - } + ///// + ///// Metodo per trasformare il valore proporzionale in assoluto + ///// + ///// + //internal double Proportional2AbsoluteVal(double widthTot, List splitList) + //{ + // double tot = widthTot; + // //Somma misura non proporzionali + // double sumNotProp = splitList + // .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL) + // .Sum(m => m.CalculateAbsoluteValue(tot, splitList)); + // //Calcolo residuo + // double res = tot - sumNotProp; + // if (res < 0) res = 0; + // //Misure proporzionali + // var proportionalList = splitList + // .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL) + // .ToList(); + // double sumPesi = proportionalList.Sum(p => p.dDimension); + // if (sumPesi == 0) sumPesi = 1; + // return res / sumPesi * dDimension; + //} internal JsonSplitDimension Serialize() { @@ -657,10 +712,10 @@ namespace WebWindowComplex.Models return JsonSplitDimension; } - internal void SetDimension(double dValue) - { - m_dDimension = dValue; - } + //internal void SetDimension(double dValue) + //{ + // m_dDimension = dValue; + //} internal void SetIsRelative(bool value) { @@ -685,16 +740,40 @@ namespace WebWindowComplex.Models double tot = 0; if (bIsVertListDim) { - tot = CalculateWidthSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dValue); - m_dDimension = ConvertDimension(m_SelMeasureType, newType, tot, m_Parent.SplitVertList); - } + tot = CalculateWidthSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Width").First().dDimension); + AreaDimension ad = new AreaDimension(dDimension, SelMeasureType); + List newDimensions = new List(); + foreach (var item in m_Parent.SplitVertList) + { + newDimensions.Add(new AreaDimension(item.dDimension, item.SelMeasureType)); + } + m_dDimension = ad.ConvertDimension(newDimensions, m_SelMeasureType, newType, tot, m_Parent.SplitVertList.IndexOf(this)); + if (newType is MeasureTypes.PROPORTIONAL) + { + for (int i = 0; i < m_Parent.SplitVertList.Count; i++) + { + m_Parent.SplitVertList.ElementAt(i).SetDimension(newDimensions.ElementAt(i).dDimension); + } + } } else { - tot = CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), HeightTot()); - m_dDimension = ConvertDimension(m_SelMeasureType, newType, tot, m_Parent.SplitHorizList); + tot = CalculateHeightSplitGroup(m_Parent, HeightTot()); + AreaDimension ad = new AreaDimension(dDimension, SelMeasureType); + List newDimensions = new List(); + foreach (var item in m_Parent.SplitHorizList) + { + newDimensions.Add(new AreaDimension(item.dDimension, item.SelMeasureType)); + } + m_dDimension = ad.ConvertDimension(newDimensions, m_SelMeasureType, newType, tot, m_Parent.SplitHorizList.IndexOf(this)); + if(newType is MeasureTypes.PROPORTIONAL) + { + for(int i = 0; i < m_Parent.SplitHorizList.Count; i++) + { + m_Parent.SplitHorizList.ElementAt(i).SetDimension(newDimensions.ElementAt(i).dDimension); + } + } } m_SelMeasureType = (MeasureTypes)value; - //m_Parent.ParentWindow.OnUpdatePreview(m_Parent.ParentWindow.sSerialized()); } } @@ -706,19 +785,19 @@ namespace WebWindowComplex.Models case (int)Shapes.TRIANGLE: case (int)Shapes.ARC_FULL: { - return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Height").First().dValue); + return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Height").First().dDimension); } case (int)Shapes.RIGHTCHAMFER: { - return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Left Height").First().dValue); + return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Left Height").First().dDimension); } case (int)Shapes.LEFTCHAMFER: { - return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Right Height").First().dValue); + return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Right Height").First().dDimension); } default: { - return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Full Height").First().dValue); + return CalculateHeightSplitGroup(m_Parent.ParentWindow.AreaList.FirstOrDefault(), m_Parent.ParentWindow.AreaList.FirstOrDefault().DimensionList.Where(x => x.sName == "Full Height").First().dDimension); } } } @@ -731,16 +810,16 @@ namespace WebWindowComplex.Models private bool m_bIsVertListDim = false; - private double m_dDimension; + //private double m_dDimension; - private List m_MeasureTypeList = new List - { - new IdNameStruct((int)MeasureTypes.ABSOLUTE, "Absolute"), - new IdNameStruct((int)MeasureTypes.PROPORTIONAL, "Proportional"), - new IdNameStruct((int)MeasureTypes.PERCENTAGE, "Percentage"), - }; + //private List m_MeasureTypeList = new List + //{ + // new IdNameStruct((int)MeasureTypes.ABSOLUTE, "Absolute"), + // new IdNameStruct((int)MeasureTypes.PROPORTIONAL, "Proportional"), + // new IdNameStruct((int)MeasureTypes.PERCENTAGE, "Percentage"), + //}; - private MeasureTypes m_SelMeasureType; + //private MeasureTypes m_SelMeasureType; // reference private Split m_Parent; diff --git a/WebWindowComplex/TableComp.razor.cs b/WebWindowComplex/TableComp.razor.cs index ad477d0..bb1e71e 100644 --- a/WebWindowComplex/TableComp.razor.cs +++ b/WebWindowComplex/TableComp.razor.cs @@ -663,7 +663,7 @@ namespace WebWindowComplex if (m_PreviousWindow != null) { for (int i = 0; i < 2; i++) - m_CurrWindow.AreaList.First().DimensionList[i].dValue = m_PreviousWindow.AreaList.First().DimensionList[i].dValue; + 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++) diff --git a/WebWindowComplex/WebWindowComplex.csproj b/WebWindowComplex/WebWindowComplex.csproj index e43a29f..6ceb52a 100644 --- a/WebWindowComplex/WebWindowComplex.csproj +++ b/WebWindowComplex/WebWindowComplex.csproj @@ -6,7 +6,7 @@ net8.0 enable enable - 2.7.12.916 + 2.7.12.1518 Annamaria Sassi Egalware Componente gestione Configurazioni avanzate Window per LUX @@ -353,6 +353,13 @@ + + + + + + + diff --git a/WebWindowConfigurator/WebWindowConfigurator.csproj b/WebWindowConfigurator/WebWindowConfigurator.csproj index 6796056..fb8c56c 100644 --- a/WebWindowConfigurator/WebWindowConfigurator.csproj +++ b/WebWindowConfigurator/WebWindowConfigurator.csproj @@ -6,7 +6,7 @@ net8.0 enable enable - 2.7.12.916 + 2.7.12.1518 Annamaria Sassi Egalware Componente gestione JWD per LUX @@ -429,6 +429,16 @@ + + + + + + + + + +