8949762c34
- Modifica tipi dimensione split - Modificati valori CalcUid e windowUid a valori random
371 lines
16 KiB
C#
371 lines
16 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 FrameDimension:AreaDimension
|
|
{
|
|
#region Public Constructors
|
|
|
|
public FrameDimension(Frame ParentFrame, int nIndex, string sName, double dDimension, bool bIsLen) : base(dDimension, MeasureTypes.ABSOLUTE)
|
|
{
|
|
m_ParentFrame = ParentFrame;
|
|
m_nIndex = nIndex;
|
|
m_sName = sName;
|
|
m_bIsLen = bIsLen;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public override double dDimension
|
|
{
|
|
get
|
|
{
|
|
return m_dDimension;
|
|
}
|
|
set
|
|
{
|
|
if(dDimension != value)
|
|
{
|
|
if (ParentFrame.SelShapeIndex == (int)Shapes.RECTANGLE ||
|
|
ParentFrame.SelShapeIndex == (int)Shapes.RIGHTCHAMFER ||
|
|
ParentFrame.SelShapeIndex == (int)Shapes.LEFTCHAMFER ||
|
|
ParentFrame.SelShapeIndex == (int)Shapes.DOUBLECHAMFER ||
|
|
ParentFrame.SelShapeIndex == (int)Shapes.TRIANGLE)
|
|
{
|
|
if (value > MaxDim)
|
|
{
|
|
m_dDimension = MaxDim;
|
|
}
|
|
else if (value < MinDim && !m_sName.Equals("Radius") && !m_sName.Equals("Height projection"))
|
|
{
|
|
m_dDimension = MinDim;
|
|
}
|
|
else
|
|
m_dDimension = value;
|
|
}
|
|
else
|
|
{
|
|
var widthArea = (ParentFrame.DimensionList.First(x => x.sName.Equals("Width"))).m_dDimension;
|
|
if (ParentFrame.SelShapeIndex == (int)Shapes.ARC_FULL)
|
|
{
|
|
var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension;
|
|
if (sName.Equals("Height") && value > 0.5 * widthArea && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Width") && height > 0.5 * value && value > MinDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
}
|
|
else if (ParentFrame.SelShapeIndex == (int)Shapes.ARC)
|
|
{
|
|
var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension;
|
|
var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).m_dDimension;
|
|
if (sName.Equals("Full Height") && (value - height) < 0.5 * widthArea && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Height") && (fullHeight - value) < 0.5 * widthArea && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Width") && (fullHeight - height) < 0.5 * value && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
}
|
|
else if (ParentFrame.SelShapeIndex == (int)Shapes.THREECENTERARC)
|
|
{
|
|
var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension;
|
|
var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).m_dDimension;
|
|
if (sName.Equals("Full Height") && (value - height) < 0.5 * widthArea && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Height") && (fullHeight - value) < 0.5 * widthArea && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Width") && (fullHeight - height) < 0.5 * value)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Radius") && value < 0.5 * widthArea)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
}
|
|
else if (ParentFrame.SelShapeIndex == (int)Shapes.DOUBLEARC)
|
|
{
|
|
var height = ParentFrame.DimensionList.First(x => x.sName.Equals("Height")).m_dDimension;
|
|
var fullHeight = ParentFrame.DimensionList.First(x => x.sName.Equals("Full Height")).m_dDimension;
|
|
if (sName.Equals("Full Height") && (value - height) > 0.5 * widthArea && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Height") && (fullHeight - value) > 0.5 * widthArea && value < MaxDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
else if (sName.Equals("Width") && (fullHeight - height) > 0.5 * value && value > MinDim)
|
|
{
|
|
m_dDimension = value;
|
|
}
|
|
}
|
|
}
|
|
if (ParentFrame.AreaList.Count > 0 && sName.Equals("Width"))
|
|
ParentFrame.SearchAreaList(ParentFrame, dDimension, "Width");
|
|
else
|
|
ParentFrame.SearchAreaList(ParentFrame, dDimension, "Height");
|
|
}
|
|
}
|
|
}
|
|
|
|
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();
|
|
// int countProportional = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PROPORTIONAL)).Count();
|
|
// int countPercentage = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).Count();
|
|
// double widthTot = 0;
|
|
// if (sash.ParentArea is Frame)
|
|
// {
|
|
// widthTot = ParentFrame.CalculateWidthArea(ParentFrame, ParentFrame.DimensionList.First(x => x.m_sName.Equals("Width")).dValue);
|
|
// }
|
|
// else
|
|
// {
|
|
// Split s = (Split)sash.ParentArea.ParentArea;
|
|
// int index = s.AreaList.First().AreaList.IndexOf(sash);
|
|
// widthTot = s.CalculateWidthArea(s, s.SplitVertList.ElementAt(index).dDimension);
|
|
// }
|
|
// if (countAbsolute == sash.SashList.Count)
|
|
// {
|
|
// double sum = sash.SashList.Sum(x => x.dDimension);
|
|
// double res = widthTot - 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 (countAbsolute < sash.SashList.Count)
|
|
// {
|
|
// if (countPercentage > 0 && countPercentage <= sash.SashList.Count && countProportional == 0)
|
|
// {
|
|
// double sumAbsolute = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.ABSOLUTE)).Sum(x => x.dDimension);
|
|
// var percentageList = sash.SashList.Where(x => x.MeasureType.Equals(MeasureTypes.PERCENTAGE)).ToList();
|
|
// foreach(var i in percentageList)
|
|
// {
|
|
// i.SetDimension(ConvertIn((widthTot - sumAbsolute) / countPercentage, i.MeasureType, widthTot, sash));
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// 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();
|
|
// double widthTot = 0;
|
|
// if (split.ParentArea is Frame)
|
|
// {
|
|
// widthTot = ParentFrame.CalculateWidthArea(ParentFrame, ParentFrame.DimensionList.First(x => x.m_sName.Equals("Width")).dValue);
|
|
// }
|
|
// else
|
|
// {
|
|
// Sash s = (Sash)split.ParentArea.ParentArea;
|
|
// int index = -1;
|
|
// if (s.AreaList.First().AreaList.IndexOf(split) != -1)
|
|
// index = s.AreaList.First().AreaList.IndexOf(split);
|
|
// else
|
|
// index = s.AreaList.Last().AreaList.IndexOf(split);
|
|
// widthTot = s.CalculateWidthArea(s, s.SashList.ElementAt(index).dDimension);
|
|
// }
|
|
// if (countAbsolute != 0 && countAbsolute == splitList.Count)
|
|
// {
|
|
// double sum = splitList.Sum(x => x.dDimension);
|
|
// double res = widthTot - 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_dDimension = dValue;
|
|
//}
|
|
|
|
internal JsonFrameDimension Serialize()
|
|
{
|
|
JsonFrameDimension JsonFrameDimension = new JsonFrameDimension(m_nIndex, m_sName, m_dDimension);
|
|
return JsonFrameDimension;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo per convertire una dimensione da un valore assoluto al suo rispettivo tipo
|
|
/// </summary>
|
|
/// <param name="absoluteVal"> Valore assoluto </param>
|
|
/// <param name="type"> Tipo di misura della dimensione </param>
|
|
/// <param name="widthTot"> Larghezza totale </param>
|
|
/// <returns></returns>
|
|
//internal double ConvertIn(double absoluteVal, MeasureTypes type, double widthTot, Sash sash)
|
|
//{
|
|
// switch (type)
|
|
// {
|
|
// case MeasureTypes.ABSOLUTE:
|
|
// {
|
|
// return absoluteVal;
|
|
// }
|
|
// case MeasureTypes.PROPORTIONAL:
|
|
// {
|
|
// return ProportionalFromAbsoluteVal(absoluteVal, widthTot, sash);
|
|
// }
|
|
// case MeasureTypes.PERCENTAGE:
|
|
// {
|
|
// return (absoluteVal / widthTot) * 100;
|
|
// }
|
|
// }
|
|
// return -1;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Metodo per trasformare il valore proporzionale in assoluto
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//internal double ProportionalFromAbsoluteVal(double absoluteVal, double widthTot, Sash sash)
|
|
//{
|
|
// double tot = widthTot;
|
|
// List<AreaDimension> adList = new List<AreaDimension>();
|
|
// foreach (var it in sash.SashList)
|
|
// {
|
|
// adList.Add(new AreaDimension(it.m_dDimension, it.SelMeasureType));
|
|
// }
|
|
// //Somma misura non proporzionali
|
|
// double sumNotProp = sash.SashList
|
|
// .Where(m => m.MeasureType != MeasureTypes.PROPORTIONAL)
|
|
// .Sum(m => m.CalculateAbsoluteValue(adList, tot));
|
|
// //Calcolo residuo
|
|
// double res = tot - sumNotProp;
|
|
// if (res < 0) res = 0;
|
|
// //Misure proporzionali
|
|
// var proportionalList = sash.SashList
|
|
// .Where(m => m.SelMeasureType == MeasureTypes.PROPORTIONAL)
|
|
// .ToList();
|
|
// double sumPesi = proportionalList.Sum(p => p.m_dDimension);
|
|
// if (sumPesi == 0) sumPesi = 1;
|
|
// return res / sumPesi * absoluteVal;
|
|
//}
|
|
|
|
#endregion Internal Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected Frame m_ParentFrame;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Fields
|
|
|
|
private bool m_bIsLen = false;
|
|
|
|
//private double m_dDimension;
|
|
|
|
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
|
|
}
|
|
} |