Files
webwindowconfigurator/WebWindowComplex/Models/ElementDimension.cs
T
Annamaria Sassi 80a8d44172 - Iniziato ad aggiungere inglesine come split
- Corretto warnings
2026-02-17 16:14:04 +01:00

218 lines
6.9 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)
{
if (m_ParentArea is Split)
{
if (value > m_dMax)
value = m_dMax;
else if (value < m_dMin)
value = m_dMin;
Split s = (Split)m_ParentArea;
SplitElementDimension splitElem = (SplitElementDimension)this;
List<SplitDimension> elemList = new List<SplitDimension>();
Frame? frame = s.ParentWindow.AreaList.First();
double dimTot = 0;
if (s.ElemDimVertList.Contains(splitElem))
elemList = s.SplitVertList;
else if (s.ElemDimHorizList.Contains(splitElem))
elemList = s.SplitHorizList;
if(elemList.ElementAt(m_nIndex).MeasureType is MeasureTypes.ABSOLUTE ||
elemList.ElementAt(m_nIndex - 1).MeasureType is MeasureTypes.ABSOLUTE)
{
if (value > m_dDimension)
{
dimTot = dimTot - (value - m_dDimension);
}
else
{
dimTot = dimTot + (m_dDimension - value);
}
double diff = (m_dDimension - 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);
}
}
else if(m_ParentArea is Sash && (m_nIndex == 2 || m_nIndex == 4))
{
if (value > m_dMax)
value = m_dMax;
else if (value < m_dMin)
value = m_dMin;
Sash s = (Sash)m_ParentArea;
if (s.bIsDimensionLight)
{
int indSash = -1;
for(int i = 0; i < s.SashList.Count; i++)
{
if (s.SashList.ElementAt(i).ElementDimensionList.Contains(this))
{
indSash = i;
break;
}
}
if(s.SashList.ElementAt(indSash).MeasureType is MeasureTypes.ABSOLUTE)
{
if (value > m_dDimension)
{
double diff = (value - m_dDimension);
s.SashList.ElementAt(indSash).SetDimension(s.SashList.ElementAt(indSash).dDimension - diff);
}
else
{
double diff = m_dDimension - value;
s.SashList.ElementAt(indSash).SetDimension(s.SashList.ElementAt(indSash).dDimension + diff);
}
}
}
}
if (value > m_dMax)
m_dDimension = m_dMax;
else if (value < m_dMin)
m_dDimension = m_dMin;
else
m_dDimension = value;
}
}
}
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;
}
}
#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
}
}