Files
webwindowconfigurator/WebWindowComplex/Models/FrameDimension.cs
T
2025-12-02 18:19:57 +01:00

276 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebWindowComplex.Json;
using static WebWindowComplex.Json.WindowConst;
namespace WebWindowComplex.Models
{
public class FrameDimension
{
#region Public Constructors
public FrameDimension(Frame ParentFrame, int nIndex, string sName, double dValue, bool bIsLen)
{
m_ParentFrame = ParentFrame;
m_nIndex = nIndex;
m_sName = sName;
m_dValue = dValue;
m_bIsLen = bIsLen;
}
#endregion Public Constructors
#region Public Properties
public double dValue
{
get
{
return m_dValue;
}
set
{
if(m_dValue != value)
{
if (ParentFrame.SelShapeIndex == (int)Shapes.RECTANGLE ||
ParentFrame.SelShapeIndex == (int)Shapes.RIGHTCHAMFER ||
ParentFrame.SelShapeIndex == (int)Shapes.LEFTCHAMFER ||
ParentFrame.SelShapeIndex == (int)Shapes.DOUBLECHAMFER)
{
if (value > MaxDim)
{
m_dValue = MaxDim;
}
else if (value < MinDim && !m_sName.Equals("Radius"))
{
m_dValue = MinDim;
}
else
m_dValue = 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;
if (sName.Equals("Height") && value > 0.5 * width && value < MaxDim)
{
m_dValue = value;
}
else if (sName.Equals("Width") && height > 0.5 * value && value > MinDim)
{
m_dValue = 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;
if (sName.Equals("Full Height") && (value - height) < 0.5 * width && value < MaxDim)
{
m_dValue = value;
}
else if (sName.Equals("Height") && (fullHeight - value) < 0.5 * width && value < MaxDim)
{
m_dValue = value;
}
else if (sName.Equals("Width") && (fullHeight - height) < 0.5 * value && value < MaxDim)
{
m_dValue = 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;
if (sName.Equals("Full Height") && (value - height) < 0.5 * width && value < MaxDim)
{
m_dValue = value;
}
else if (sName.Equals("Height") && (fullHeight - value) < 0.5 * width && value < MaxDim)
{
m_dValue = value;
}
else if (sName.Equals("Width") && (fullHeight - height) < 0.5 * value)
{
m_dValue = value;
}
else if (sName.Equals("Radius") && value < 0.5 * width)
{
m_dValue = 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;
if (sName.Equals("Full Height") && (value - height) > 0.5 * width && value < MaxDim)
{
m_dValue = value;
}
else if (sName.Equals("Height") && (fullHeight - value) > 0.5 * width && value < MaxDim)
{
m_dValue = value;
}
else if (sName.Equals("Width") && (fullHeight - height) > 0.5 * value && value > MinDim)
{
m_dValue = value;
}
}
}
if (ParentFrame.AreaList.Count > 0)
SearchAreaList(ParentFrame);
}
}
}
public int nIndex
{
get
{
return m_nIndex;
}
}
public Frame ParentFrame
{
get
{
return m_ParentFrame;
}
}
public string sName
{
get
{
return m_sName;
}
}
#endregion Public Properties
#region Internal Methods
/// <summary>
/// Cerca nell'albero gli oggetti Sash e Split per associare la larghezza
/// </summary>
/// <param name="node"></param>
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();
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(area is Split)
{
Split split = (Split)area;
List<SplitDimension> 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);
}
}
}
}
}
internal void SetDimension(double dValue)
{
m_dValue = dValue;
}
internal JsonFrameDimension Serialize()
{
JsonFrameDimension JsonFrameDimension = new JsonFrameDimension(m_nIndex, m_sName, m_dValue);
return JsonFrameDimension;
}
#endregion Internal Methods
#region Protected Fields
protected Frame m_ParentFrame;
#endregion Protected Fields
#region Private Fields
private bool m_bIsLen = false;
private double m_dValue;
private int m_nIndex;
private string m_sName;
// valore massimo della dimensione del frame
private int MaxDim = 4000;
// valore minimo della dimensione del frame
private int MinDim = 600;
#endregion Private Fields
}
}