Files
webwindowconfigurator/WebWindowComplex/Models/Frame.cs
T
Annamaria Sassi ada0fc2ce5 - Gestito salvataggio e chiusura componente con salvataggio jwd
- Correzioni valori nulli
- Aggiunta funzione per calcolare altezza sashGroup
2026-03-03 19:02:42 +01:00

764 lines
31 KiB
C#

using Egw.Window.Data;
using Newtonsoft.Json.Linq;
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 Frame : Area
{
#region Public Fields
// Lista soglie completa passata dal chiamante del componente
public static List<Threshold> m_AllThresholdList = new List<Threshold>();
#endregion Public Fields
#region Public Constructors
public Frame(Area? ParentArea, Window ParentWindow) : base(ParentArea, ParentWindow)
{
}
#endregion Public Constructors
#region Public Properties
//public FrameArcElement? FrameArcElem
//{
// get
// {
// return m_FrameArcElem;
// }
// set
// {
// m_FrameArcElem = value!;
// }
//}
public bool BottomRail
{
get
{
return m_bBottomRail;
}
set
{
m_bBottomRail = value;
}
}
public List<Threshold> ThresholdList
{
get
{
return m_ThresholdList;
}
set
{
m_ThresholdList = value;
}
}
public Threshold SelThreshold
{
get
{
return m_SelThreshold;
}
set
{
m_SelThreshold = value;
}
}
public int SelThresholdFromType
{
get
{
return m_SelThreshold.Type;
}
set
{
Threshold? newThreshold = m_ThresholdList.Where(x => x.Type.Equals(value)).FirstOrDefault();
if (newThreshold != null)
m_SelThreshold = newThreshold;
else
m_SelThreshold = new Threshold(3, "Bottom");
string profileName = "";
if (m_SelThreshold.Name.Equals("Threshold"))
profileName = "Frame_Sash_Threshold";
else
profileName = "Frame_Sash_Bottom";
ElementDimensionList.First().SetNameElement(profileName);
ElementDimensionList.First().SetMinDimension(Window.m_ParameterList.GetValueOrDefault(profileName + "_DimMin"));
ElementDimensionList.First().SetMaxDimension(Window.m_ParameterList.GetValueOrDefault(profileName + "_DimMax"));
ElementDimensionList.First().SetDimension(Window.m_ParameterList.GetValueOrDefault(profileName + "_DimStd"));
string overlapName = "Sash_Bottom_Overlap";
ElementDimensionList.First().SetOverlapElement(Window.m_ParameterList.GetValueOrDefault(overlapName));
if (AreaList.Count > 0)
{
SearchAreaList(this, AvailHeightArea(), "Height");
}
}
}
public int BottomRailQty
{
get
{
return m_nBottomRailQty;
}
set
{
if (value >= 0)
{
if(value > m_nBottomRailQty)
{
// Aggiungo un element in coda
BottomRailElemDimList.Add(new ElementDimension(this, BottomRailElemDimList.Count + 1, 78));
BottomRailElemDimList.Last().SetNameElement("Frame_Fill_Rail");
BottomRailElemDimList.Last().SetMinDimension(Window.m_ParameterList.GetValueOrDefault(BottomRailElemDimList.Last().sName + "_DimMin"));
BottomRailElemDimList.Last().SetMaxDimension(Window.m_ParameterList.GetValueOrDefault(BottomRailElemDimList.Last().sName + "_DimMax"));
BottomRailElemDimList.Last().SetDimension(Window.m_ParameterList.GetValueOrDefault(BottomRailElemDimList.Last().sName + "_DimStd"));
if (value > 1 && BottomRailElemDimList.Count - 2 >= 0)
{
BottomRailElemDimList.ElementAt(BottomRailElemDimList.Count - 2).SetNameElement("Frame_Rail");
BottomRailElemDimList.ElementAt(BottomRailElemDimList.Count - 2).SetMinDimension(Window.m_ParameterList.GetValueOrDefault(BottomRailElemDimList.ElementAt(BottomRailElemDimList.Count - 2).sName + "_DimMin"));
BottomRailElemDimList.ElementAt(BottomRailElemDimList.Count - 2).SetMaxDimension(Window.m_ParameterList.GetValueOrDefault(BottomRailElemDimList.ElementAt(BottomRailElemDimList.Count - 2).sName + "_DimMax"));
BottomRailElemDimList.ElementAt(BottomRailElemDimList.Count - 2).SetDimension(BottomRailElemDimList.ElementAt(BottomRailElemDimList.Count - 2).dDimension);
}
}
else if (value < m_nBottomRailQty)
{
// Elimino gli element
for(int i = BottomRailElemDimList.Count-1; i == value; i--)
BottomRailElemDimList.RemoveAt(i);
if (value >= 1)
{
BottomRailElemDimList.Last().SetNameElement("Frame_Fill_Rail");
BottomRailElemDimList.Last().SetMinDimension(Window.m_ParameterList.GetValueOrDefault(BottomRailElemDimList.Last().sName + "_DimMin"));
BottomRailElemDimList.Last().SetMaxDimension(Window.m_ParameterList.GetValueOrDefault(BottomRailElemDimList.Last().sName + "_DimMax"));
BottomRailElemDimList.Last().SetDimension(BottomRailElemDimList.Last().dDimension);
}
}
m_nBottomRailQty = value;
if (value > 0)
{
m_bBottomRail = true;
}
else
{
m_bBottomRail = false;
}
}
}
}
public List<ElementDimension> BottomRailElemDimList
{
get => m_BottomRailElemDimList;
set => m_BottomRailElemDimList = value;
}
public List<FrameDimension> DimensionList
{
get => m_DimensionList;
set => m_DimensionList = value;
}
public List<ElementDimension> ElementDimensionList
{
get => m_ElementDimensionList;
set => m_ElementDimensionList = value;
}
public List<Joint> JointList
{
get
{
return m_JointList;
}
set
{
m_JointList = value;
}
}
public int SelShapeIndex
{
get
{
return (int)m_Shape;
}
set
{
if (m_Shape != (Shapes)value)
{
Shapes oldShape = m_Shape;
m_Shape = (Shapes)value;
// salvo vecchie dimensioni
List<FrameDimension> oldDimensionList = new List<FrameDimension>(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.dDimension).First();
// aggiungo Dimensioni
switch (m_Shape)
{
case Shapes.RECTANGLE:
case Shapes.ARC_FULL:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", widthVal, true));
DimensionList.Add(new FrameDimension(this, 2, "Height", 1400, true));
SearchAreaList(this, AvailWidthArea(), "Width");
SearchAreaList(this, AvailHeightArea(), "Height");
break;
}
case Shapes.RIGHTCHAMFER:
{
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, AvailWidthArea(), "Width");
SearchAreaList(this, AvailHeightArea(), "Left Height");
break;
}
case Shapes.LEFTCHAMFER:
{
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, AvailWidthArea(), "Width");
SearchAreaList(this, AvailHeightArea(), "Right Height");
break;
}
case Shapes.DOUBLECHAMFER:
case Shapes.ARC:
{
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, AvailWidthArea(), "Width");
SearchAreaList(this, AvailHeightArea(), "Full Height");
break;
}
case Shapes.DOUBLEARC:
{
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, AvailWidthArea(), "Width");
SearchAreaList(this, AvailHeightArea(), "Full Height");
break;
}
case Shapes.THREECENTERARC:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 2000, true));
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, AvailWidthArea(), "Width");
SearchAreaList(this, AvailHeightArea(), "Full Height");
break;
}
case Shapes.TRIANGLE:
{
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, AvailWidthArea(), "Width");
SearchAreaList(this, AvailHeightArea(), "Height");
break;
}
case Shapes.CUSTOM:
{
DimensionList.Clear();
break;
}
}
// salvo tipo Joint
List<Joint> oldJointType = new List<Joint>(JointList);
// salvo la lista di sash
List<Sash> sashList = new List<Sash>();
SearchSash(sashList, this);
// aggiungo Joint
m_JointList.Clear();
switch (m_Shape)
{
case Shapes.RECTANGLE:
case Shapes.RIGHTCHAMFER:
case Shapes.LEFTCHAMFER:
case Shapes.DOUBLECHAMFER:
{
JointList.Add(new Joint(this, 1, oldJointType[0].SelJointType));
JointList.Add(new Joint(this, 2, oldJointType[1].SelJointType));
JointList.Add(new Joint(this, 3, oldJointType[2].SelJointType));
if (oldJointType.Count > 3)
JointList.Add(new Joint(this, 4, oldJointType[3].SelJointType));
else
JointList.Add(new Joint(this, 4, Joints.FULL_V));
break;
}
case Shapes.ARC:
case Shapes.ARC_FULL:
case Shapes.DOUBLEARC:
case Shapes.THREECENTERARC:
{
JointList.Add(new Joint(this, 1, oldJointType[0].SelJointType));
JointList.Add(new Joint(this, 2, oldJointType[1].SelJointType));
JointList.Add(new Joint(this, 3, Joints.ANGLED));
JointList.Add(new Joint(this, 4, Joints.ANGLED));
break;
}
case Shapes.TRIANGLE:
{
JointList.Add(new Joint(this, 1, oldJointType[0].SelJointType));
JointList.Add(new Joint(this, 2, oldJointType[1].SelJointType));
JointList.Add(new Joint(this, 3, Joints.ANGLED));
foreach (var s in sashList)
{
foreach (var sashDim in s.SashList)
{
sashDim.JointList.RemoveAt(sashDim.JointList.Count - 1);
sashDim.JointList.Last().SelJointType = Joints.ANGLED;
}
}
break;
}
case Shapes.CUSTOM:
{
JointList.Clear();
break;
}
}
if (oldShape is Shapes.TRIANGLE)
{
foreach (var s in sashList)
{
foreach (var sashDim in s.SashList)
{
if (sashDim.JointList.Count == 3)
sashDim.JointList.Add(new Joint(s, 4, Joints.FULL_V));
}
}
}
m_ElementDimensionList.Clear();
//switch (SelShape)
//{
// case Shapes.RECTANGLE:
// case Shapes.RIGHTCHAMFER:
// case Shapes.LEFTCHAMFER:
// case Shapes.DOUBLECHAMFER:
// case Shapes.TRIANGLE:
// {
// FrameArcElem = null;
// foreach (var s in sashList)
// s.SashArcElem = null;
// break;
// }
//}
}
}
}
protected List<Sash> SearchSash(List<Sash> sashList, Area node)
{
if (node != null)
{
if (node.AreaType.Equals(AreaTypes.SASH))
{
sashList.Add((Sash)node);
//Sash s = (Sash)node;
//s.SashArcElem = null;
}
foreach (var item in node.AreaList)
{
SearchSash(sashList, item);
}
}
return sashList;
}
public Shapes Shape
{
get
{
return m_Shape;
}
}
public List<IdNameStruct> ShapeList
{
get
{
return m_ShapeList;
}
}
#endregion Public Properties
#region Public Methods
public void RefreshThresholdList()
{
m_ThresholdList.Clear();
m_ThresholdList = m_AllThresholdList;
}
public double AvailHeightArea()
{
double dim = 0;
switch (SelShapeIndex)
{
case (int)Shapes.RECTANGLE:
case (int)Shapes.TRIANGLE:
case (int)Shapes.ARC_FULL:
{
dim = DimensionList.Where(x => x.sName == "Height").First().dDimension;
break;
}
case (int)Shapes.RIGHTCHAMFER:
{
dim = DimensionList.Where(x => x.sName == "Left Height").First().dDimension;
break;
}
case (int)Shapes.LEFTCHAMFER:
{
dim = DimensionList.Where(x => x.sName == "Right Height").First().dDimension;
break;
}
default:
{
dim = DimensionList.Where(x => x.sName == "Full Height").First().dDimension;
break;
}
}
double overlap = 0;
if (AreaList.First() is Sash)
overlap = ElementDimensionList.First().dOverlap +
ElementDimensionList.ElementAt(ElementDimensionList.Count() - 2).dOverlap;
if(BottomRailQty > 0)
{
foreach (var bottomRail in BottomRailElemDimList)
dim = dim - bottomRail.dDimension;
}
return dim - ElementDimensionList.First().dDimension -
ElementDimensionList.ElementAt(ElementDimensionList.Count() - 2).dDimension +
overlap;
}
public override Frame Copy(Area ParentArea)
{
return new Frame(null, ParentWindow);
}
/// <summary>
/// Metodo per calcolare l'area disponibile
/// </summary>
/// <returns></returns>
public double AvailWidthArea()
{
if (DimensionList.Count > 0 && DimensionList.FirstOrDefault(x => x.sName.Equals("Width")) != null)
{
double dim = DimensionList.FirstOrDefault(x => x.sName.Equals("Width"))!.dDimension;
double overlap = 0;
if(AreaList.First() is Sash)
overlap = ElementDimensionList.ElementAt(1).dOverlap +
ElementDimensionList.Last().dOverlap;
//if (AreaList.First() is Split split)
//{
// if(split.SplitHorizList.Count > 0)
// overlap = ElementDimensionList.ElementAt(1).dOverlap +
// ElementDimensionList.Last().dOverlap;
//}
return dim - ElementDimensionList.ElementAt(1).dDimension -
ElementDimensionList.Last().dDimension +
overlap;
}
return -1;
}
#endregion Public Methods
#region Internal Methods
//internal void SetFrameArcElem(FrameArcElement arcElement)
//{
// m_FrameArcElem = arcElement;
//}
internal static Area CreateFrame(Window Window)
{
Frame newFrame = new Frame(null, Window);
newFrame.SetAreaType(AreaTypes.FRAME);
newFrame.SetSelShape(Shapes.RECTANGLE);
newFrame.SetBottomRail(false);
newFrame.SetBottomRailQty(0);
newFrame.RefreshThresholdList();
if (m_AllThresholdList != null && m_AllThresholdList.Any())
{
newFrame.SetSelThresholdFromName(m_AllThresholdList.FirstOrDefault()?.Name ?? "");
}
//newFrame.FrameArcElem = null;
return newFrame;
}
internal override JsonArea Serialize(bool hideHw)
{
Area.nCounterGroup = 0;
if (nCounterGroup < GroupId)
Area.nCounterGroup = GroupId;
JsonFrame JsonFrame = new JsonFrame(m_Shape, m_SelThreshold.Name, m_bBottomRail, m_nBottomRailQty, GroupId);
foreach (var BottomRailDim in BottomRailElemDimList)
JsonFrame.BottomRailElemDimList.Add(BottomRailDim.Serialize());
//if (FrameArcElem != null)
// JsonFrame.ArcElement = FrameArcElem.Serialize();
//else
// JsonFrame.ArcElement = null;
foreach (var Dimension in DimensionList)
JsonFrame.DimensionList.Add(Dimension.Serialize());
foreach (var ElementDimension in ElementDimensionList)
JsonFrame.ElementDimensionList.Add(ElementDimension.Serialize());
foreach (var Joint in JointList)
JsonFrame.JointList.Add(Joint.Serialize());
foreach (var Area in AreaList)
JsonFrame.AreaList.Add(Area.Serialize(hideHw));
return JsonFrame;
}
internal void SetBottomRail(bool bBottomRail)
{
m_bBottomRail = bBottomRail;
}
internal void SetBottomRailQty(int nBottomRailQty)
{
m_nBottomRailQty = nBottomRailQty;
}
internal void SetSelShape(Shapes Value)
{
DimensionList.Clear();
// aggiungo Dimension
switch (Value)
{
case Shapes.RECTANGLE:
case Shapes.ARC_FULL:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 1500, true));
DimensionList.Add(new FrameDimension(this, 2, "Height", 1800, true));
break;
}
case Shapes.RIGHTCHAMFER:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 1500, true));
DimensionList.Add(new FrameDimension(this, 2, "Left Height", 1800, true));
DimensionList.Add(new FrameDimension(this, 3, "Right Height", 1500, true));
break;
}
case Shapes.LEFTCHAMFER:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 1500, true));
DimensionList.Add(new FrameDimension(this, 2, "Left Height", 1500, true));
DimensionList.Add(new FrameDimension(this, 3, "Right Height", 1800, true));
break;
}
case Shapes.DOUBLECHAMFER:
case Shapes.ARC:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 1500, true));
DimensionList.Add(new FrameDimension(this, 2, "Height", 1500, true));
DimensionList.Add(new FrameDimension(this, 3, "Full Height", 1800, true));
break;
}
case Shapes.DOUBLEARC:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 1500, true));
DimensionList.Add(new FrameDimension(this, 2, "Height", 1500, true));
DimensionList.Add(new FrameDimension(this, 3, "Full Height", 2400, true));
break;
}
case Shapes.THREECENTERARC:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 800, true));
DimensionList.Add(new FrameDimension(this, 2, "Height", 2100, true));
DimensionList.Add(new FrameDimension(this, 3, "Full Height", 2400, true));
DimensionList.Add(new FrameDimension(this, 4, "Radius", 100, true));
break;
}
case Shapes.TRIANGLE:
{
DimensionList.Add(new FrameDimension(this, 1, "Width", 2000, true));
DimensionList.Add(new FrameDimension(this, 2, "Height", 1500, true));
DimensionList.Add(new FrameDimension(this, 3, "Height projection", 0, true));
break;
}
case Shapes.CUSTOM:
{
DimensionList.Clear();
break;
}
}
// aggiungo Joint
//int nJointQty = 4;
switch (Value)
{
case Shapes.RECTANGLE:
case Shapes.RIGHTCHAMFER:
case Shapes.LEFTCHAMFER:
case Shapes.DOUBLECHAMFER:
case Shapes.ARC:
case Shapes.DOUBLEARC:
{
JointList.Add(new Joint(this, 1, Joints.FULL_H));
JointList.Add(new Joint(this, 2, Joints.FULL_H));
JointList.Add(new Joint(this, 3, Joints.FULL_H));
JointList.Add(new Joint(this, 4, Joints.FULL_H));
break;
}
case Shapes.ARC_FULL:
case Shapes.THREECENTERARC:
{
JointList.Add(new Joint(this, 1, Joints.FULL_H));
JointList.Add(new Joint(this, 2, Joints.FULL_H));
JointList.Add(new Joint(this, 3, Joints.ANGLED));
JointList.Add(new Joint(this, 4, Joints.ANGLED));
break;
}
case Shapes.TRIANGLE:
{
JointList.Add(new Joint(this, 1, Joints.FULL_H));
JointList.Add(new Joint(this, 2, Joints.FULL_H));
JointList.Add(new Joint(this, 3, Joints.ANGLED));
break;
}
case Shapes.CUSTOM:
{
JointList.Clear();
break;
}
}
ElementDimensionList.Clear();
// aggiungo Element Dimension
switch (Value)
{
case Shapes.RECTANGLE:
case Shapes.ARC_FULL:
case Shapes.RIGHTCHAMFER:
case Shapes.LEFTCHAMFER:
case Shapes.ARC:
{
for(int i = 0; i < 4; i++)
ElementDimensionList.Add(new ElementDimension(this, i + 1, 78));
break;
}
case Shapes.DOUBLECHAMFER:
case Shapes.DOUBLEARC:
{
for (int i = 0; i < 5; i++)
ElementDimensionList.Add(new ElementDimension(this, i + 1, 78));
break;
}
case Shapes.THREECENTERARC:
{
for (int i = 0; i < 6; i++)
ElementDimensionList.Add(new ElementDimension(this, i + 1, 78));
break;
}
case Shapes.TRIANGLE:
{
for (int i = 0; i < 3; i++)
ElementDimensionList.Add(new ElementDimension(this, i + 1, 78));
break;
}
case Shapes.CUSTOM:
{
ElementDimensionList.Clear();
break;
}
}
m_Shape = Value;
}
internal void SetSelThresholdFromName(string? value)
{
// verifica ci sia un valore...
if (!string.IsNullOrEmpty(value) && m_ThresholdList != null && m_ThresholdList.Count > 0)
{
m_SelThreshold = m_ThresholdList.Where(x => x.Name.Equals(value)).First();
}
else
{
m_SelThreshold = m_ThresholdList!.FirstOrDefault() ?? new Threshold(3, "Bottom");
}
}
#endregion Internal Methods
#region Private Fields
//private FrameArcElement m_FrameArcElem = new FrameArcElement();
private bool m_bBottomRail;
private Threshold m_SelThreshold = new Threshold(1, "");
private List<Threshold> m_ThresholdList = new List<Threshold>();
private List<FrameDimension> m_DimensionList = new List<FrameDimension>();
private List<ElementDimension> m_ElementDimensionList = new List<ElementDimension>();
private List<ElementDimension> m_BottomRailElemDimList = new List<ElementDimension>();
private List<Joint> m_JointList = new List<Joint>();
private int m_nBottomRailQty = 0;
private Shapes m_Shape;
private List<IdNameStruct> m_ShapeList = new List<IdNameStruct>
{
new IdNameStruct((int)Shapes.RECTANGLE, "Rectangle"),
new IdNameStruct((int)Shapes.RIGHTCHAMFER, "Right Chamfer"),
new IdNameStruct((int)Shapes.LEFTCHAMFER, "Left Chamfer"),
new IdNameStruct((int)Shapes.DOUBLECHAMFER, "Double Chamfer"),
new IdNameStruct((int)Shapes.ARC, "Arc"),
new IdNameStruct((int)Shapes.ARC_FULL, "Arc Full"),
new IdNameStruct((int)Shapes.DOUBLEARC, "Double Arc"),
new IdNameStruct((int)Shapes.THREECENTERARC, "Three Center Arc"),
new IdNameStruct((int)Shapes.TRIANGLE, "Triangle")
};
#endregion Private Fields
}
}