Client/Desktop/KMBIM3.0/KMBIM3.0_소스/Cmd/HeatingCoil/FormCoil.cs

504 lines
18 KiB
C#

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using KDCS.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KMBIM
{
public partial class FormCoil : System.Windows.Forms.Form
{
public Document doc;
private int _ListIndex;
public int ListIndex
{
get { return _ListIndex; }
set { _ListIndex = ListCoil.SelectedIndex; }
}
//코일 간격
private double _CoilDist;
public double CoilDist
{
get { return _CoilDist; }
set { _CoilDist = value; }
}
//벽면에서의 거리
private double _CoilDistFromWall;
public double CoilDistFromWall
{
get { return _CoilDistFromWall; }
set { _CoilDistFromWall = value; }
}
//코일의 외기길이 제한
private double _CoilOutAirLenLimit;
public double CoilOutAirLenLimit
{
get { return _CoilOutAirLenLimit; }
set { _CoilOutAirLenLimit = value; }
}
//코일의 간격띄우기
private double _CoilOffset;
public double CoilOffset
{
get { return _CoilOffset; }
set { _CoilOffset = value; }
}
//코일 유형 리스트
private List<string> _CoilTypeLst;
public List<string> CoilTypeLst
{
get { return _CoilTypeLst; }
set { _CoilTypeLst = value; }
}
//코일 유형
private PipeType _CoilType;
public PipeType CoilType
{
get { return _CoilType; }
set { _CoilType = value; }
}
//코일 시스템 유형 리스트
private List<string> _CoilSysTypeLst;
public List<string> CoilSysTypeLst
{
get { return _CoilSysTypeLst; }
set { _CoilSysTypeLst = value; }
}
//코일 시스템 유형
private PipingSystemType _CoilSysType;
public PipingSystemType CoilSysType
{
get { return _CoilSysType; }
set { _CoilSysType = value; }
}
//코일 관경
private double _CoilDiameter;
public double CoilDiameter
{
get { return _CoilDiameter; }
set { _CoilDiameter = value; }
}
public FormCoil()
{
InitializeComponent();
}
private void FormCoil_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
ListCoil.SelectedIndex = 0;
ListIndex = 0;
//코일 간격
if(Reg.getReg("CoilDist") == "")
{
CoilDist = System.Math.Round(CoilDist, 3);
txt_CoilDist.Text = CoilDist.ToString();
Reg.setReg("CoilDist", CoilDist.ToString());
}
else
{
string Str_CoilDist = Reg.getReg("CoilDist");
txt_CoilDist.Text = Str_CoilDist;
}
//txt_CoilDist.Text = "200";
//벽에서의 거리
if (Reg.getReg("CoilDistFromWall") == "")
{
CoilDistFromWall = System.Math.Round(CoilDistFromWall, 3);
txt_CoilDistFromWall.Text = CoilDistFromWall.ToString();
Reg.setReg("CoilDistFromWall", CoilDistFromWall.ToString());
}
else
{
string Str_CoilDistFromWall = Reg.getReg("CoilDistFromWall");
txt_CoilDistFromWall.Text = Str_CoilDistFromWall;
}
//txt_CoilDistFromWall.Text = "80";
////벽에서의 최소거리
//MinCoilDistFromWall = System.Math.Round(MinCoilDistFromWall, 3);
//txt_MinCoilDistFromWall.Text = MinCoilDistFromWall.ToString();
////txt_MinCoilDistFromWall.Text = "80";
//
////코일의 총 길이 제한
//CoilTotalLenLimit = System.Math.Round(CoilTotalLenLimit, 3);
//txt_CoilTotalLenLimit.Text = CoilTotalLenLimit.ToString();
//txt_CoilTotalLenLimit.Text = "100.0";
//코일의 외기 길이 제한
if (Reg.getReg("CoilOutAirLenLimit") == "")
{
CoilOutAirLenLimit = System.Math.Round(CoilOutAirLenLimit, 3);
txt_CoilOutAirLenLimit.Text = CoilOutAirLenLimit.ToString();
Reg.setReg("CoilOutAirLenLimit", CoilOutAirLenLimit.ToString());
}
else
{
string Str_CoilOutAirLenLimit = Reg.getReg("CoilOutAirLenLimit");
txt_CoilOutAirLenLimit.Text = Str_CoilOutAirLenLimit;
}
//txt_CoilOutAirLenLimit.Text = "8.0";
//코일 간격띄우기
if (Reg.getReg("CoilOffset") == "")
{
CoilOffset = System.Math.Round(CoilOffset, 3);
txt_CoilOffset.Text = CoilOffset.ToString();
Reg.setReg("CoilOffset", CoilOffset.ToString());
}
else
{
string Str_CoilOffset = Reg.getReg("CoilOffset");
txt_CoilOffset.Text = Str_CoilOffset;
}
////코일 관경
//CoilDiameter = System.Math.Round(CoilDiameter, 3);
//코일 유형
foreach (string str in CoilTypeLst)
{
combo_CoilType.Items.Add(str);
}
//코일유형 없으면 기본값 지정 X
if (combo_CoilType.Items.Count != 0)
{
if(Reg.getReg("combo_CoilType_Idx") == "")
{
combo_CoilType.SelectedIndex = 0;
Reg.setReg("combo_CoilType_Idx", "0");
}
else
{
string Str_combo_CoilType = Reg.getReg("combo_CoilType_Idx");
//만약 저장된 레지스트리 인덱스값이 없으면 디폴트값으로
if (combo_CoilType.Items.Count - 1 >= Convert.ToInt32(Str_combo_CoilType))
{
combo_CoilType.SelectedIndex = Convert.ToInt32(Str_combo_CoilType);
}
else
{
combo_CoilType.SelectedIndex = 0;
Reg.setReg("combo_CoilType_Idx", "0");
}
}
}
//코일 시스템 유형
foreach (string str in CoilSysTypeLst)
{
combo_SystemType.Items.Add(str);
}
//코일 시스템유형 없으면 기본값 지정 X
if (combo_SystemType.Items.Count != 0)
{
if (Reg.getReg("combo_SystemType_Idx") == "")
{
combo_SystemType.SelectedIndex = 0;
Reg.setReg("combo_SystemType_Idx", "0");
}
else
{
string Str_combo_SystemType = Reg.getReg("combo_SystemType_Idx");
//만약 저장된 레지스트리 인덱스값이 없으면 디폴트값으로
if (combo_SystemType.Items.Count - 1 >= Convert.ToInt32(Str_combo_SystemType))
{
combo_SystemType.SelectedIndex = Convert.ToInt32(Str_combo_SystemType);
}
else
{
combo_SystemType.SelectedIndex = 0;
Reg.setReg("combo_SystemType_Idx", "0");
}
}
}
}
//코일 간격
private void txt_CoilDist_TextChanged(object sender, EventArgs e)
{
if (txt_CoilDist.Text == "")
return;
else
{
CoilDist = double.Parse(txt_CoilDist.Text);
Reg.setReg("CoilDist", CoilDist.ToString());
}
}
//벽에서의 거리
private void txt_CoilDistFromWall_TextChanged(object sender, EventArgs e)
{
if (txt_CoilDistFromWall.Text == "")
return;
else
{
CoilDistFromWall = double.Parse(txt_CoilDistFromWall.Text);
Reg.setReg("CoilDistFromWall", CoilDistFromWall.ToString());
}
}
//코일의 외기 길이 제한
private void txt_CoilOutAirLenLimit_TextChanged(object sender, EventArgs e)
{
if (txt_CoilOutAirLenLimit.Text == "")
return;
else
{
CoilOutAirLenLimit = double.Parse(txt_CoilOutAirLenLimit.Text);
Reg.setReg("CoilOutAirLenLimit", CoilOutAirLenLimit.ToString());
}
}
//간격 띄우기 추가 2020-11-13 서주현
private void txt_CoilOffset_TextChanged(object sender, EventArgs e)
{
if (txt_CoilOffset.Text == "") return;
if (txt_CoilOffset.Text != "-")
{
CoilOffset = double.Parse(txt_CoilOffset.Text);
Reg.setReg("CoilOffset", CoilOffset.ToString());
}
}
private void pictureCoil1_Click(object sender, EventArgs e)
{
pictureCoil1.Image = KMBIM.Revit.Tools.Properties.Resources.Coil01r;
pictureCoil2.Image = KMBIM.Revit.Tools.Properties.Resources.Coil02;
pictureCoil3.Image = KMBIM.Revit.Tools.Properties.Resources.Coil03;
ListCoil.SelectedIndex = 0;
ListIndex = ListCoil.SelectedIndex;
}
private void pictureCoil2_Click(object sender, EventArgs e)
{
pictureCoil1.Image = KMBIM.Revit.Tools.Properties.Resources.Coil01;
pictureCoil2.Image = KMBIM.Revit.Tools.Properties.Resources.Coil02r;
pictureCoil3.Image = KMBIM.Revit.Tools.Properties.Resources.Coil03;
ListCoil.SelectedIndex = 1;
ListIndex = ListCoil.SelectedIndex;
}
private void pictureCoil3_Click(object sender, EventArgs e)
{
pictureCoil1.Image = KMBIM.Revit.Tools.Properties.Resources.Coil01;
pictureCoil2.Image = KMBIM.Revit.Tools.Properties.Resources.Coil02;
pictureCoil3.Image = KMBIM.Revit.Tools.Properties.Resources.Coil03r;
ListCoil.SelectedIndex = 2;
ListIndex = ListCoil.SelectedIndex;
}
private void ListCoil_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListCoil.SelectedIndex == 0)
{
pictureCoil1.Image = KMBIM.Revit.Tools.Properties.Resources.Coil01r;
pictureCoil2.Image = KMBIM.Revit.Tools.Properties.Resources.Coil02;
pictureCoil3.Image = KMBIM.Revit.Tools.Properties.Resources.Coil03;
}
else if (ListCoil.SelectedIndex == 1)
{
pictureCoil1.Image = KMBIM.Revit.Tools.Properties.Resources.Coil01;
pictureCoil2.Image = KMBIM.Revit.Tools.Properties.Resources.Coil02r;
pictureCoil3.Image = KMBIM.Revit.Tools.Properties.Resources.Coil03;
}
else if (ListCoil.SelectedIndex == 2)
{
pictureCoil1.Image = KMBIM.Revit.Tools.Properties.Resources.Coil01;
pictureCoil2.Image = KMBIM.Revit.Tools.Properties.Resources.Coil02;
pictureCoil3.Image = KMBIM.Revit.Tools.Properties.Resources.Coil03r;
}
}
//코일 유형 변경시
private void combo_CoilType_SelectedIndexChanged(object sender, EventArgs e)
{
//파이프 세그먼트 관경 가져오기
List<double> segLst = GetPipeSegmentSizes(doc, combo_CoilType.SelectedItem.ToString());
//코일 유형 변경시 관경도 리셋해야 함.
combo_CoilDia.Items.Clear();
foreach (double seg in segLst)
{
combo_CoilDia.Items.Add(Math.Round(seg, 2));
}
//코일 관경이 없으면 기본값 지정 X
if (combo_CoilDia.Items.Count != 0)
combo_CoilDia.SelectedIndex = 0;
Reg.setReg("combo_CoilType_Idx", combo_CoilType.SelectedIndex.ToString());
}
//파이프 시스템 유형 변경
private void combo_SystemType_SelectedIndexChanged(object sender, EventArgs e)
{
ICollection<Element> pipeSysTypes = new FilteredElementCollector(doc).OfClass(typeof(PipingSystemType)).ToElements();
foreach (Element elem in pipeSysTypes)
{
if (elem is PipingSystemType)
{
PipingSystemType pipeSysType = elem as PipingSystemType;
//파이프 유형이름이 다르면 loop
if (pipeSysType.Name != combo_SystemType.SelectedItem.ToString()) continue;
//작도에 쓰일 pipetype Element
CoilSysType = pipeSysType;
if(CoilSysType!=null)
break;
}
}
Reg.setReg("combo_SystemType_Idx", combo_SystemType.SelectedIndex.ToString());
}
//코일 관경 변경시
private void combo_CoilDia_SelectedIndexChanged(object sender, EventArgs e)
{
string str_coilDia = combo_CoilDia.SelectedItem.ToString();
CoilDiameter = Convert.ToDouble(str_coilDia);
}
//파이프 세그먼트 관경들 구하기.
public List<double> GetPipeSegmentSizes(Document doc, string pipeTypeName)
{
List<double> m_pipeDiaList = new List<double>();
ICollection<Element> pipeTypes = new FilteredElementCollector(doc).OfClass(typeof(PipeType)).ToElements();
foreach (Element elem in pipeTypes)
{
if (elem is PipeType)
{
PipeType pipeType = elem as PipeType;
//파이프 유형이름이 다르면 loop
if (pipeType.Name != pipeTypeName) continue;
//작도에 쓰일 pipetype Element
CoilType = pipeType;
RoutingPreferenceManager rpm = pipeType.RoutingPreferenceManager;
int segmentCnt = rpm.GetNumberOfRules(RoutingPreferenceRuleGroupType.Segments);
for (int i = 0; i != segmentCnt; i++)
{
RoutingPreferenceRule segmentRule = rpm.GetRule(RoutingPreferenceRuleGroupType.Segments, i);
Segment segment = doc.GetElement(segmentRule.MEPPartId) as Segment;
foreach (MEPSize size in segment.GetSizes())
{
//m_pipeDiaList.Add(Unit.CovertFromAPI(DisplayUnitType.DUT_MILLIMETERS, size.NominalDiameter));
m_pipeDiaList.Add(Unit.FeetToMM(size.NominalDiameter));
}
}
m_pipeDiaList.Sort();
return m_pipeDiaList;
}
}
return null;
}
private void FormCoil_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
//this.Close();
this.DialogResult = DialogResult.Cancel;
}
else if (e.KeyCode == Keys.Enter)
{
this.DialogResult = DialogResult.OK;
}
}
private void txt_CoilDist_KeyPress(object sender, KeyPressEventArgs e)
{
int keyCode = (int)e.KeyChar;
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46)
e.Handled = true;
if (keyCode == 46)
{
if (string.IsNullOrEmpty(txt_CoilDist.Text) || txt_CoilDist.Text.Contains('.') == true)
e.Handled = true;
}
}
private void txt_CoilDistFromWall_KeyPress(object sender, KeyPressEventArgs e)
{
int keyCode = (int)e.KeyChar;
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46)
e.Handled = true;
if (keyCode == 46)
{
if (string.IsNullOrEmpty(txt_CoilDistFromWall.Text) || txt_CoilDistFromWall.Text.Contains('.') == true)
e.Handled = true;
}
}
private void txt_CoilOutAirLenLimit_KeyPress(object sender, KeyPressEventArgs e)
{
int keyCode = (int)e.KeyChar;
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46)
e.Handled = true;
if (keyCode == 46)
{
if (string.IsNullOrEmpty(txt_CoilOutAirLenLimit.Text) || txt_CoilOutAirLenLimit.Text.Contains('.') == true)
e.Handled = true;
}
}
private void txt_CoilOffset_KeyPress(object sender, KeyPressEventArgs e)
{
int keyCode = (int)e.KeyChar;
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46 && keyCode != 45)
e.Handled = true;
if (keyCode == 46)
{
if (string.IsNullOrEmpty(txt_CoilOffset.Text) || txt_CoilOffset.Text.Contains('.') == true)
e.Handled = true;
}
//else if(keyCode == 45)
//{
// if (string.IsNullOrEmpty(txt_CoilOffset.Text) || txt_CoilOffset.Text.Contains('-') == true)
// e.Handled = true;
//}
}
}
}