using Egw.Window.Data; 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 hardware completa passata dal chiamante del componente public static Dictionary> m_AllThresholdList = new Dictionary>(); #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 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 { m_SelThreshold = m_ThresholdList.Where(x=>x.Type.Equals(value)).First(); } } public int BottomRailQty { get { return m_nBottomRailQty; } set { if (m_nBottomRailQty >= 0) { m_nBottomRailQty = value; if (m_nBottomRailQty > 0) { m_bBottomRail = true; } else { m_bBottomRail = false; } } } } public List DimensionList { get => m_DimensionList; set => m_DimensionList = value; } public List JointList { get { return m_JointList; } set { m_JointList = value; } } public int SelShapeIndex { get { return (int)m_Shape; } set { Shapes SelShape = (Shapes)value; if (m_Shape != SelShape) { // salvo vecchie dimensioni 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.dDimension).First(); // aggiungo Dimensioni switch (SelShape) { 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)); foreach (var dim in DimensionList) SearchAreaList(this, dim.dDimension,dim.sName); 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, widthVal, "Width"); SearchAreaList(this, 1800, "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, widthVal, "Width"); SearchAreaList(this, 1800, "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, widthVal, "Width"); SearchAreaList(this, 1800, "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, widthVal, "Width"); SearchAreaList(this, 2400, "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, 2000, "Width"); SearchAreaList(this, 2400, "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, widthVal, "Width"); SearchAreaList(this, 1500, "Height"); break; } case Shapes.CUSTOM: { DimensionList.Clear(); break; } } // salvo tipo Joint List oldJointType = new List(JointList); // salvo la lista di sash List sashList = new List(); SearchSash(sashList, this); // aggiungo Joint m_JointList.Clear(); switch (SelShape) { 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(JointList.Count > 3) { 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)); } } } //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; // } //} m_Shape = SelShape; } } } protected List SearchSash(List 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 ShapeList { get { return m_ShapeList; } } #endregion Public Properties #region Public Methods public void RefreshThresholdList() { m_ThresholdList.Clear(); m_ThresholdList = m_AllThresholdList.GetValueOrDefault(ParentWindow.sProfilePath); } public override Frame Copy(Area ParentArea) { return null; } #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(); newFrame.SetSelThresholdFromName(m_AllThresholdList.GetValueOrDefault(Window.sProfilePath).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); //if (FrameArcElem != null) // JsonFrame.ArcElement = FrameArcElem.Serialize(); //else // JsonFrame.ArcElement = null; foreach (var Dimension in DimensionList) JsonFrame.DimensionList.Add(Dimension.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; } } m_Shape = Value; } internal void SetSelThresholdFromName(string value) { m_SelThreshold = m_ThresholdList.Where(x=>x.Name.Equals(value)).First(); } #endregion Internal Methods #region Private Fields //private FrameArcElement m_FrameArcElem = new FrameArcElement(); private bool m_bBottomRail; private Threshold m_SelThreshold; private List m_ThresholdList = new List(); private List m_DimensionList = new List(); private List m_JointList = new List(); private int m_nBottomRailQty = 0; private Shapes m_Shape; private List m_ShapeList = new List { 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 } }