Aggiunti tipi di misure (absolut, proportional, percentage) per sashDimension

This commit is contained in:
Annamaria Sassi
2025-11-10 15:22:04 +01:00
parent 1d3edf121c
commit 6b06ec861e
6 changed files with 280 additions and 83 deletions
+9 -11
View File
@@ -46,13 +46,13 @@ namespace WebWindowComplex.Models
}
}
public bool bIsPercentage
{
get
{
return m_bIsPercentage;
}
}
//public bool bIsPercentage
//{
// get
// {
// return m_bIsPercentage;
// }
//}
public bool bIsSashVertical
{
@@ -128,7 +128,7 @@ namespace WebWindowComplex.Models
// aggiungo area Sash di default
for (var SplitIndex = m_SashList.Count; SplitIndex <= value - 1; SplitIndex++)
{
SashList.Add(new SashDimension(dNewDimension, true, this, SplitIndex + 1));
SashList.Add(new SashDimension(dNewDimension, MeasureTypes.PERCENTAGE, this, SplitIndex + 1));
}
}
else if (value < m_SashList.Count)
@@ -804,7 +804,7 @@ namespace WebWindowComplex.Models
dNewDimension = dLastDimension / (Qty + 1 - nSashQty);
// aggiungo area Sash di default
for (var SplitIndex = m_SashList.Count; SplitIndex <= Qty - 1; SplitIndex++)
SashList.Add(new SashDimension(dNewDimension, true, this, SplitIndex + 1));
SashList.Add(new SashDimension(dNewDimension, MeasureTypes.PERCENTAGE, this, SplitIndex + 1));
}
else if (Qty < m_SashList.Count)
{
@@ -864,8 +864,6 @@ namespace WebWindowComplex.Models
private bool m_bIsMeasureGlass;
private bool m_bIsPercentage = true;
private bool m_bIsSashVertical;
private bool m_bSashBottomRail;
+227 -69
View File
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebWindowComplex.Json;
using WebWindowComplex.Json;
using static WebWindowComplex.Json.WindowConst;
namespace WebWindowComplex.Models
@@ -12,12 +7,12 @@ namespace WebWindowComplex.Models
{
#region Public Constructors
public SashDimension(double dDimension, bool bIsRelative, Sash Parent, int nSashId)
public SashDimension(double dDimension, MeasureTypes MeasureType, Sash Parent, int nSashId)
{
m_dDimension = dDimension;
m_bIsRelative = bIsRelative;
m_Parent = Parent;
m_nSashId = nSashId;
SetMeasureType(MeasureType);
// assengno maniglia
if (Parent.SashList.Count == 0 || !Parent.SashList.Any(x => x.bHasHandle))
m_bHasHandle = true;
@@ -110,14 +105,6 @@ namespace WebWindowComplex.Models
}
}
public bool bIsRelative
{
get
{
return m_bIsRelative;
}
}
public double dDimension
{
get
@@ -126,69 +113,150 @@ namespace WebWindowComplex.Models
}
set
{
// Controllo che il valore inserito sia compreso tra 0 e 100
if (value > 0 && value < 100)
double valMax = 0;
bool valueAccept = false;
switch (MeasureType)
{
// se sono in percentuale
if (m_bIsRelative)
{
// verifico se ci sono assoluti
List<SashDimension> RelativeDimList = m_Parent.SashList.Where(x => x.bIsRelative).ToList();
if (RelativeDimList.Count > 0)
case MeasureTypes.ABSOLUT:
{
if (m_Parent.bIsPercentage)
valMax = m_Parent.SashList.Sum(x => x.dDimension);
valueAccept = (value < valMax && value > 0) ? true: false;
break;
}
case MeasureTypes.PROPORTIONAL:
{
valMax = m_Parent.SashList.Sum(x => x.dDimension);
break;
}
case MeasureTypes.PERCENTAGE:
{
valMax = 100;
valueAccept = (value < valMax && value > 0) ? true : false;
break;
}
}
if (!MeasureType.Equals(MeasureTypes.PROPORTIONAL))
{
if (valueAccept)
{
// verifico se ci sono altri in percentuale
List<SashDimension> DimList = m_Parent.SashList.Where(x => x.MeasureType.Equals(MeasureType)).ToList();
if (DimList.Count > 0)
{
int nIndex = DimList.IndexOf(this);
// se diminuisce dimensione
if (value < m_dDimension)
{
int nIndex = RelativeDimList.IndexOf(this);
// se diminuisce dimensione
if (value < m_dDimension)
{
if (nIndex < RelativeDimList.Count - 1)
RelativeDimList[nIndex + 1].SetDimension(RelativeDimList[nIndex + 1].dDimension + (m_dDimension - value));
else if (RelativeDimList.Count > 1)
RelativeDimList[nIndex - 1].SetDimension(RelativeDimList[nIndex - 1].dDimension + (m_dDimension - value));
else
{
m_dDimension = 100;
return;
}
}
// se aumenta dimensione
if (nIndex < DimList.Count - 1)
DimList[nIndex + 1].SetDimension(DimList[nIndex + 1].dDimension + (m_dDimension - value));
else if (DimList.Count > 1)
DimList[nIndex - 1].SetDimension(DimList[nIndex - 1].dDimension + (m_dDimension - value));
else
{
double dRes = value;
// se non ultima anta
if (nIndex < RelativeDimList.Count - 1)
m_dDimension = valMax;
return;
}
}
// se aumenta dimensione
else
{
double dRes = value;
// se non ultima anta
if (nIndex < DimList.Count - 1)
{
for (var nInd = 0; nInd <= nIndex - 1; nInd++)
dRes += DimList[nInd].dDimension;
dRes = (100 - dRes) / (DimList.Count - nIndex - 1);
for (var Ind = nIndex + 1; Ind <= DimList.Count - 1; Ind++)
DimList[Ind].SetDimension(dRes);
}
// se ultima anta
else if (DimList.Count > 1)
{
if (DimList.Count > 2)
{
for (var nInd = 0; nInd <= nIndex - 1; nInd++)
dRes += RelativeDimList[nInd].dDimension;
dRes = (100 - dRes) / (RelativeDimList.Count - nIndex - 1);
for (var Ind = nIndex + 1; Ind <= RelativeDimList.Count - 1; Ind++)
RelativeDimList[Ind].SetDimension(dRes);
}
// se ultima anta
else if (RelativeDimList.Count > 1)
{
if (RelativeDimList.Count > 2)
{
for (var Ind = 0; Ind <= nIndex - 2; Ind++)
dRes += RelativeDimList[Ind].dDimension;
}
dRes = (100 - dRes);
RelativeDimList[nIndex - 1].SetDimension(dRes);
}
else
{
m_dDimension = 100;
return;
for (var Ind = 0; Ind <= nIndex - 2; Ind++)
dRes += DimList[Ind].dDimension;
}
dRes = (valMax - dRes);
DimList[nIndex - 1].SetDimension(dRes);
}
else
{
m_dDimension = valMax;
return;
}
}
}
m_dDimension = value;
m_Parent.ParentWindow.OnUpdatePreview(m_Parent.ParentWindow.sSerialized());
}
}
else
{
m_dDimension = value;
m_Parent.ParentWindow.OnUpdatePreview(m_Parent.ParentWindow.sSerialized());
}
//// se sono in percentuale
//if (m_MeasureType.Equals(MeasureTypes.PERCENTAGE))
//{
// // Controllo che il valore inserito sia compreso tra 0 e 100
// if (value > 0 && value < 100)
// {
// // verifico se ci sono altri in percentuale
// List<SashDimension> RelativeDimList = m_Parent.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).ToList();
// if (RelativeDimList.Count > 0)
// {
// int nIndex = RelativeDimList.IndexOf(this);
// // se diminuisce dimensione
// if (value < m_dDimension)
// {
// if (nIndex < RelativeDimList.Count - 1)
// RelativeDimList[nIndex + 1].SetDimension(RelativeDimList[nIndex + 1].dDimension + (m_dDimension - value));
// else if (RelativeDimList.Count > 1)
// RelativeDimList[nIndex - 1].SetDimension(RelativeDimList[nIndex - 1].dDimension + (m_dDimension - value));
// else
// {
// m_dDimension = 100;
// return;
// }
// }
// // se aumenta dimensione
// else
// {
// double dRes = value;
// // se non ultima anta
// if (nIndex < RelativeDimList.Count - 1)
// {
// for (var nInd = 0; nInd <= nIndex - 1; nInd++)
// dRes += RelativeDimList[nInd].dDimension;
// dRes = (100 - dRes) / (RelativeDimList.Count - nIndex - 1);
// for (var Ind = nIndex + 1; Ind <= RelativeDimList.Count - 1; Ind++)
// RelativeDimList[Ind].SetDimension(dRes);
// }
// // se ultima anta
// else if (RelativeDimList.Count > 1)
// {
// if (RelativeDimList.Count > 2)
// {
// for (var Ind = 0; Ind <= nIndex - 2; Ind++)
// dRes += RelativeDimList[Ind].dDimension;
// }
// dRes = (100 - dRes);
// RelativeDimList[nIndex - 1].SetDimension(dRes);
// }
// else
// {
// m_dDimension = 100;
// return;
// }
// }
// }
// }
// m_dDimension = value;
// m_Parent.ParentWindow.OnUpdatePreview(m_Parent.ParentWindow.sSerialized());
//}
}
}
@@ -204,7 +272,7 @@ namespace WebWindowComplex.Models
{
get
{
return (Openings)m_SelOpeningType;
return m_SelOpeningType;
}
}
@@ -255,13 +323,54 @@ namespace WebWindowComplex.Models
}
}
public MeasureTypes MeasureType
{
get
{
return m_SelMeasureType;
}
}
public List<IdNameStruct> MeasureTypeList
{
get
{
return m_MeasureTypeList;
}
}
public MeasureTypes SelMeasureType
{
get
{
return m_SelMeasureType;
}
set
{
m_SelMeasureType = value;
}
}
public int SelMeasureTypeIndex
{
get
{
return (int)m_SelMeasureType;
}
set
{
m_SelMeasureType = (MeasureTypes)value;
}
}
#endregion Public Properties
#region Public Methods
public SashDimension Copy()
{
SashDimension newSashDim = new SashDimension(dDimension, bIsRelative, m_Parent, m_nSashId);
SashDimension newSashDim = new SashDimension(dDimension, MeasureType, m_Parent, m_nSashId);
newSashDim.SetMeasureType(MeasureType);
newSashDim.SetOpeningType(SelOpeningType);
newSashDim.SetHasHandle(bHasHandle);
return newSashDim;
@@ -292,14 +401,17 @@ namespace WebWindowComplex.Models
m_SelOpeningType = value;
}
internal void SetMeasureType(MeasureTypes value)
{
m_SelMeasureType = value;
}
#endregion Internal Methods
#region Private Fields
private bool m_bHasHandle;
private bool m_bIsRelative = false;
private double m_dDimension;
private int m_nSashId;
@@ -333,11 +445,57 @@ namespace WebWindowComplex.Models
//new IdNameStruct((int)Openings.LIFTSLIDE_RIGHT, "←┐")
};
private List<IdNameStruct> m_MeasureTypeList = new List<IdNameStruct>
{
new IdNameStruct((int)MeasureTypes.ABSOLUT, "Absolut"),
new IdNameStruct((int)MeasureTypes.PROPORTIONAL, "Proportional"),
new IdNameStruct((int)MeasureTypes.PERCENTAGE, "Percentage"),
};
// reference
private Sash m_Parent;
private Openings m_SelOpeningType;
private MeasureTypes m_SelMeasureType;
#endregion Private Fields
#region Private Methods
/// <summary>
/// Recupero della larghezza del frame
/// </summary>
/// <returns></returns>
private double GetWidth()
{
double width = 0;
int indexSash = 0;
if (m_Parent.ParentArea != null && m_Parent.ParentArea.ParentArea != null && m_Parent.ParentArea.ParentArea is Split)
{
Split splitParent = (Split)m_Parent.ParentArea.ParentArea;
if(splitParent.SplitVertList.Count > 0)
{
for(int i = 0; i < splitParent.AreaList.Count; i++)
{
if (splitParent.AreaList[i].AreaList[0].Equals(this))
{
indexSash = i;
}
}
}
//int indexSash = splitParent.AreaList.Where(x => x.AreaList[0].Equals(this));
}
else
{
Frame a = m_Parent.ParentWindow.AreaList[0];
FrameDimension? fd = a.DimensionList.Where(x => x.sName == "Width").SingleOrDefault();
width = fd.dValue;
}
return width;
}
#endregion Private Methods
}
}