Files
webwindowconfigurator/WebWindowComplex/Models/ElementDimension.cs
T
2026-02-24 17:45:02 +01:00

283 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebWindowComplex.Json;
using static WebWindowComplex.Json.WindowConst;
namespace WebWindowComplex.Models
{
public class ElementDimension
{
#region Public Constructors
public ElementDimension(Area ParentArea, int nIndex, double dDimension)
{
m_ParentArea = ParentArea;
m_nIndex = nIndex;
m_dDimension = dDimension;
}
#endregion Public Constructors
#region Public Properties
public double dDimension
{
get
{
return m_dDimension;
}
set
{
if(dDimension != value)
{
double dimensioneOld = m_dDimension;
if (value > m_dMax)
m_dDimension = m_dMax;
else if (value < m_dMin)
m_dDimension = m_dMin;
else
m_dDimension = value;
if (m_ParentArea is Split split)
{
SplitElementDimension splitElem = (SplitElementDimension)this;
List<SplitDimension> elemList = new List<SplitDimension>();
Frame? frame = split.ParentWindow.AreaList.First();
double dimTot = 0;
if (split.ElemDimVertList.Contains(splitElem))
elemList = split.SplitVertList;
else if (split.ElemDimHorizList.Contains(splitElem))
elemList = split.SplitHorizList;
if(elemList.ElementAt(m_nIndex).MeasureType is MeasureTypes.ABSOLUTE ||
elemList.ElementAt(m_nIndex - 1).MeasureType is MeasureTypes.ABSOLUTE)
{
if (value > dimensioneOld)
{
dimTot = dimTot - (value - dimensioneOld);
}
else
{
dimTot = dimTot + (dimensioneOld - value);
}
double diff = (dimensioneOld - value)/2;
if(elemList.ElementAt(m_nIndex - 1).MeasureType is MeasureTypes.ABSOLUTE)
elemList.ElementAt(m_nIndex - 1).SetDimension(elemList.ElementAt(m_nIndex - 1).dDimension + diff);
if(elemList.ElementAt(m_nIndex).MeasureType is MeasureTypes.ABSOLUTE)
elemList.ElementAt(m_nIndex).SetDimension(elemList.ElementAt(m_nIndex).dDimension + diff);
}
if (split.SplitHorizList.Count > 0)
{
List<AreaDimension> dimList = new List<AreaDimension>();
foreach (var itemDim in split.SplitHorizList)
dimList.Add(new AreaDimension(itemDim.dDimension, itemDim.MeasureType, itemDim.Parent));
double height = ParentArea.CalculateWidthArea(ParentArea.ParentWindow.AreaList[0], ParentArea.ParentWindow.AreaList[0].AvailHeightArea());
for (int i = 0; i < split.AreaList.Count; i++)
{
if (i < split.SplitHorizList.Count)
{
SplitDimension currSplitDim = split.SplitHorizList[i];
double dim = currSplitDim.dDimension;
if (!(currSplitDim.MeasureType.Equals(MeasureTypes.ABSOLUTE)))
dim = currSplitDim.ConvertDimension(dimList, currSplitDim.MeasureType, MeasureTypes.ABSOLUTE, height, -1, 0);
split.AreaList.ElementAt(i).SearchAreaList(split.AreaList.ElementAt(i), dim, "Height");
}
}
}
if (split.SplitVertList.Count > 0)
{
List<AreaDimension> dimList = new List<AreaDimension>();
foreach (var itemDim in split.SplitVertList)
dimList.Add(new AreaDimension(itemDim.dDimension, itemDim.MeasureType, itemDim.Parent));
double width = ParentArea.CalculateWidthArea(ParentArea.ParentWindow.AreaList[0], ParentArea.ParentWindow.AreaList[0].AvailWidthArea());
for (int i = 0; i < split.AreaList.Count; i++)
{
if (i < split.SplitVertList.Count)
{
SplitDimension currSplitDim = split.SplitVertList[i];
double dim = currSplitDim.dDimension;
if (!(currSplitDim.MeasureType.Equals(MeasureTypes.ABSOLUTE)))
dim = currSplitDim.ConvertDimension(dimList, currSplitDim.MeasureType, MeasureTypes.ABSOLUTE, width, -1, 0);
split.AreaList.ElementAt(i).SearchAreaList(split.AreaList.ElementAt(i), dim, "Width");
}
}
}
}
else if(m_ParentArea is Sash sash)
{
if(m_nIndex == 2 || m_nIndex == 4)
{
if (sash.bIsDimensionLight)
{
int indSash = -1;
for(int i = 0; i < sash.SashList.Count; i++)
{
if (sash.SashList.ElementAt(i).ElementDimensionList.Contains(this))
{
indSash = i;
break;
}
}
if(sash.SashList.ElementAt(indSash).MeasureType is MeasureTypes.ABSOLUTE)
{
if (value > dimensioneOld)
{
double diff = (value - dimensioneOld);
sash.SashList.ElementAt(indSash).SetDimension(sash.SashList.ElementAt(indSash).dDimension - diff);
}
else
{
double diff = dimensioneOld - value;
sash.SashList.ElementAt(indSash).SetDimension(sash.SashList.ElementAt(indSash).dDimension + diff);
}
for (int i = 0; i < sash.AreaList.Count; i++)
sash.AreaList.ElementAt(i).SearchAreaList(sash.AreaList.ElementAt(i), sash.SashList.ElementAt(i).dDimension, "Width");
}
}
}
else
{
Frame? frame = sash.ParentWindow.AreaList.FirstOrDefault();
if(frame != null)
{
for (int i = 0; i < sash.AreaList.Count; i++)
sash.AreaList.ElementAt(i).SearchAreaList(sash.AreaList.ElementAt(i), sash.AreaList.ElementAt(i).CalculateHeightArea(frame, frame.AvailHeightArea()), "Height");
}
}
}
else if(m_ParentArea is Frame frame)
{
for (int i = 0; i < frame.AreaList.Count; i++)
{
frame.AreaList.ElementAt(i).SearchAreaList(frame, frame.AvailWidthArea(), "Width");
frame.AreaList.ElementAt(i).SearchAreaList(frame, frame.AvailHeightArea(), "Height");
}
}
}
}
}
public int nIndex
{
get
{
return m_nIndex;
}
}
public string sName
{
get
{
return m_sName;
}
set
{
if (m_sName != value)
{
m_sName = value;
}
}
}
public Area ParentArea
{
get
{
return m_ParentArea;
}
}
public double dOverlap
{
get
{
return m_dOverlap;
}
}
public double dMaxDim
{
get
{
return m_dMax;
}
}
public double dMinDim
{
get
{
return m_dMin;
}
}
#endregion Public Properties
#region Public Methods
public void SetDimension(double dValue)
{
m_dDimension = dValue;
}
public void SetIndex(int nIndex)
{
m_nIndex = nIndex;
}
public void SetMaxDimension(double dValue)
{
m_dMax = dValue;
}
public void SetMinDimension(double dValue)
{
m_dMin = dValue;
}
public void SetNameElement(string dValue)
{
m_sName = dValue;
}
public void SetOverlapElement(double dValue)
{
m_dOverlap = dValue;
}
public virtual ElementDimension Copy()
{
ElementDimension newElementDimension = new ElementDimension(ParentArea, nIndex, dDimension);
return newElementDimension;
}
#endregion Public Methods
#region Internal Methods
internal JsonElementDimension Serialize()
{
JsonElementDimension JsonElementDimension = new JsonElementDimension(m_nIndex, m_dDimension);
return JsonElementDimension;
}
#endregion Internal Methods
#region Private Fields
private Area m_ParentArea;
private double m_dDimension;
private double m_dOverlap;
private int m_nIndex;
private string m_sName = "";
private double m_dMin = 40;
private double m_dMax = 100;
#endregion Private Fields
}
}