using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Collections; using System.Text.RegularExpressions; using KDCS.Utils; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.DB; namespace KMBIM { public struct PipeStr { public string kdn; public double bor; public string io; }; ///////////yong 냉온수 공급 및 환수 헤더 public struct HeValue { public string he; public string we; public string val; }; ///////////yong 플랜지 크기별 각각 size public struct HdValue { public string HDDIA; //헤더지름 public string BLTSIZE; //볼트 사이즈 public string BLTBORE; //구멍크기 public string BLTNO; //구멍개수 public string FLGID; //플랜지 내경 public string BLTCENDST; //볼트 중심간 거리 public string FLGOD; //플랜지 외경 }; public partial class Form_Supply : System.Windows.Forms.Form { public List m_ArrValue = new List(); public List m_ArrHdValue = new List(); public double[] dlst; // 관경의 목록을 저장 public int listboxcnt = -1; public double mainHeaderDia; public List m_ArrDia = new List(); string m_strpath = string.Empty; public int m_nMode = -1; public double m_HeadHgt = 0, m_ValHgt = 0; public string m_BFpath = null, m_Drainpath = null, m_Safepath = null, m_PGpath = null, m_TGpath = null; public List HeaderSysTypeLst = new List(); public List SelectedSysTypeNameLst = new List(); public PipingSystemType HeaderSysType = null; public Document doc; //메인 헤더 높이 public double HeadHeight { get { return m_HeadHgt; } set { m_HeadHgt = value; } } //나비형 밸브 경로 public string BFvalvePath { get { return m_BFpath; } set { m_BFpath = value; } } //배수 밸브 경로 public string DrainvalvePath { get { return m_Drainpath; } set { m_Drainpath = value; } } //안전 밸브 경로 public string SafevalvePath { get { return m_Safepath; } set { m_Safepath = value; } } //압력계 경로 public string PGaugePath { get { return m_BFpath; } set { m_BFpath = value; } } //온도계 경로 public string TGaugePath { get { return m_PGpath; } set { m_PGpath = value; } } public Form_Supply() { InitializeComponent(); //string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location; // //m_strpath = Tmp.Replace("\\KMBIM2019.dll", ""); m_strpath = Util.GetKMBIMLibraryFolder("Libraries\\Header"); } private void init() { string s, sql; m_ArrValue.Clear(); m_ArrHdValue.Clear(); if (m_nMode == 4) { GetDia("STEAM.csv"); } else { GetDia("HEAD.csv"); } for (int i = 0; i < m_ArrDia.Count; i++) { s = m_ArrDia[i]; s = s.Replace("D", ""); cmb_pipedia.Items.Add(s); } s = m_ArrDia[0]; s = s.Replace("D", ""); cmb_pipedia.Text = s; //////// //헤더 지름별 사양...입력 부분.... GetHDValue("HDDIA.csv"); // m_hd = m_HdFirst;//"200"; //if (m_hd = _T("")) m_hd = _T("200"); /* buttonDisable(); UpdateData(FALSE); m_PipeDia.SetCurSel(0);*/ } private void GetDia(string filename) { try { long id; FileStream fs = null; string csFileName, csRecord; string strPath; bool res = false; //m_strpath = m_strpath.Replace("\\KMBIM2019.dll", ""); csFileName = Util.GetKMBIMLibraryFolder("Libraries\\Header\\") + filename; FileInfo _finfo = new FileInfo(csFileName); bool sw = _finfo.Exists; if (sw == false) { // 파일 존재 유무 조사 string strMsg; strMsg = System.String.Format("파일{0}을 찾을 수 없습니다.", csFileName); MessageBox.Show(strMsg); return; } fs = new FileStream(csFileName, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default); if (fs == null) { string strMsg; strMsg = System.String.Format("파일({0})을 열 수 없습니다.", csFileName); MessageBox.Show(strMsg); return; } int ic = 0; HeValue val; double zero, one; zero = 0.0f; ArrayList csaFieldNames = new ArrayList(); int iInside = 0, iPipeName = 0; while (sr.Peek() > -1) { //ArxUtils::SeparateString(csRecord, csaFields, _T(",\t\n")); string str = sr.ReadLine(); string[] arr = Regex.Split(str, ",\t"); if (arr.Length <= 0) break; // 이 문 없으면 죽는다. if (ic == 0) { // 필드레코드 ic++; for (int j = 0; j < arr.Length; j++) { csaFieldNames.Add(arr[j]); } continue; } ic++; m_ArrDia.Add(arr[0]); for (int j = 1; j < arr.Length; j++) { val.val = arr[j].ToString(); one = Convert.ToDouble(val.val); if ((val.val != string.Empty) && ((one > 0.0f))) { val.he = csaFieldNames[j].ToString(); val.we = arr[0].ToString(); val.he = val.he.Replace("D", ""); val.we = val.we.Replace("D", ""); m_ArrValue.Add(val); } } }//end-while fs.Close(); } catch (FieldAccessException ex) { //pEx->ReportError(); } } private void GetHDValue(string lpszCSV) { // Clear the contents of the Array m_ArrDia.Clear(); list_Sup.Items.Clear(); try { long id; FileStream fs = null; string csFileName, csRecord; string strPath; bool res = false; //m_strpath = m_strpath.Replace("\\KMBIM2019.dll", ""); // MessageBox.Show(m_strpath); csFileName = Util.GetKMBIMLibraryFolder("Libraries\\Header\\") + lpszCSV; FileInfo _finfo = new FileInfo(csFileName); bool sw = _finfo.Exists; if (sw == false) { // 파일 존재 유무 조사 string strMsg; strMsg = System.String.Format("파일{0}을 찾을 수 없습니다.", csFileName); MessageBox.Show(strMsg); return; } fs = new FileStream(csFileName, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default); if (fs == null) { string strMsg; strMsg = System.String.Format("파일({0})을 열 수 없습니다.", csFileName); MessageBox.Show(strMsg); return; } int ic = 0; HdValue val; double zero, one; zero = 0.0f; ArrayList csaFieldNames = new ArrayList(); int iInside = 0, iPipeName = 0; while (sr.Peek() > -1) { //ArxUtils::SeparateString(csRecord, csaFields, _T(",\t\n")); string str = sr.ReadLine(); string[] arr = Regex.Split(str, ",\t"); if (arr.Length <= 0) break; // 이 문 없으면 죽는다. if (ic == 0) { // 필드레코드 ic++; for (int j = 0; j < arr.Length; j++) { csaFieldNames.Add(arr[j]); } continue; } ic++; string sHDDIA, sBLTSIZE, sBLTBORE, sBLTNO, sFLGID, sBLTCENDST, sFLGOD; sHDDIA = arr[0]; sBLTSIZE = arr[1]; sBLTBORE = arr[2]; sBLTNO = arr[3]; sFLGID = arr[4]; sBLTCENDST = arr[5]; sFLGOD = arr[6]; if ((sHDDIA != string.Empty) && (sBLTSIZE != string.Empty) && (sBLTBORE != string.Empty) && (sBLTNO != string.Empty) && (sFLGID != string.Empty) && (sBLTCENDST != string.Empty) && (sFLGOD != string.Empty)) { //int n=sHDDIA.get.GetLength(); cmb_headdia.Items.Add(sHDDIA); val.HDDIA = sHDDIA; val.FLGOD = sFLGOD; val.FLGID = sFLGID; sBLTSIZE = sBLTSIZE.Replace("M", ""); val.BLTSIZE = sBLTSIZE; val.BLTNO = sBLTNO; val.BLTCENDST = sBLTCENDST; val.BLTBORE = sBLTBORE; m_ArrHdValue.Add(val); } }//end-while cmb_headdia.SelectedIndex = 0; fs.Close(); } catch (FieldAccessException ex) { } } private void Form_Supply_Load(object sender, EventArgs e) { this.KeyPreview = true; init(); string versionNumber = doc.Application.VersionNumber.ToString(); //stxt_headhgt.Text = "1000"; //패밀리 기본값. //string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location; string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Header"); Tmp = Tmp.Replace("\\KMBIM2019.dll", ""); m_BFpath = Tmp + "\\family\\"+versionNumber+"\\KS_Butterfly Valve -Lever.rfa"; m_Drainpath = Tmp + "\\family\\"+versionNumber+"\\PV_Ball Valve - 8-100mm -Threaded.rfa"; m_Safepath = Tmp + "\\family\\" + versionNumber + "\\YSF-3(25-50).rfa"; m_PGpath = Tmp + "\\family\\"+versionNumber+"\\KS_Pressure Gauge.rfa"; m_TGpath = Tmp + "\\family\\"+versionNumber+"\\KS_Temperature Gauge.rfa"; txt_path1.Text = Path.GetFileName(m_BFpath); txt_path2.Text = Path.GetFileName(m_Drainpath); txt_path3.Text = Path.GetFileName(m_Safepath); txt_path4.Text = Path.GetFileName(m_PGpath); txt_path5.Text = Path.GetFileName(m_TGpath); //메인 헤더 높이 if (Reg.getReg("supply_headHgt") == "") { m_HeadHgt = Math.Round(m_HeadHgt, 3); txt_headhgt.Text = m_HeadHgt.ToString(); Reg.setReg("supply_headHgt", m_HeadHgt.ToString()); } else { string str_headHgt = Reg.getReg("supply_headHgt"); txt_headhgt.Text = str_headHgt; } //조작밸브 높이 if (Reg.getReg("supply_valveHgt") == "") { m_ValHgt = Math.Round(m_ValHgt, 3); txt_valveHgt.Text = m_ValHgt.ToString(); Reg.setReg("supply_valveHgt", m_ValHgt.ToString()); } else { string str_ValHgt = Reg.getReg("supply_valveHgt"); txt_valveHgt.Text = str_ValHgt; } //코일 시스템 유형 foreach (string str in HeaderSysTypeLst) { combo_SupSysType.Items.Add(str); } //코일 시스템유형 없으면 기본값 지정 X if(combo_SupSysType.Items.Count != 0) { if(Reg.getReg("combo_SupSysType_Idx") == "") { combo_SupSysType.SelectedIndex = 0; Reg.setReg("combo_SupSysType_Idx", "0"); } else { string Str_combo_SupSysType = Reg.getReg("combo_SupSysType_Idx"); //만약 저장된 레지스트리 인덱스값이 없으면 디폴트값으로 if (combo_SupSysType.Items.Count - 1 >= Convert.ToInt32(Str_combo_SupSysType)) { combo_SupSysType.SelectedIndex = Convert.ToInt32(Str_combo_SupSysType); } else { combo_SupSysType.SelectedIndex = 0; Reg.setReg("combo_SupSysType_Idx", "0"); } } } } private void btn_add_Click(object sender, EventArgs e) { if (cmb_pipedia.Text != "") list_Sup.Items.Add(cmb_pipedia.Text); SelectedSysTypeNameLst.Add(HeaderSysType); } private void btn_itemedit_Click(object sender, EventArgs e) { int index = list_Sup.SelectedIndex; list_Sup.Items[index] = cmb_pipedia.Text; } private void btn_itemadd_Click(object sender, EventArgs e) { if (cmb_pipedia.Text != "") list_Sup.Items.Add(cmb_pipedia.Text); SelectedSysTypeNameLst.Add(HeaderSysType); } private void btn_itemdel_Click(object sender, EventArgs e) { int index = list_Sup.SelectedIndex; list_Sup.Items.RemoveAt(index); SelectedSysTypeNameLst.RemoveAt(index); } private void button5_Click(object sender, EventArgs e) { int count = list_Sup.Items.Count; listboxcnt = count; dlst = new double[count]; if (count > 0) { for (int i = 0; i < count; i++) { object Tmp = list_Sup.Items[i]; dlst[i] = Convert.ToDouble(Tmp.ToString()); } } mainHeaderDia = Convert.ToDouble(cmb_headdia.Text); } private void Form_Supply_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_headhgt_TextChanged(object sender, EventArgs e) { if (txt_headhgt.Text == "") return; if (txt_headhgt.Text != "-") { m_HeadHgt = double.Parse(txt_headhgt.Text); Reg.setReg("supply_headHgt", txt_headhgt.Text); } } //조작밸브 높이 private void txt_valveHgt_TextChanged(object sender, EventArgs e) { if (txt_valveHgt.Text == "") return; if (txt_valveHgt.Text != "-") { m_ValHgt = double.Parse(txt_valveHgt.Text); Reg.setReg("supply_valveHgt", txt_valveHgt.Text); } } private void txt_headhgt_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_headhgt.Text) || txt_headhgt.Text.Contains('.') == true) e.Handled = true; } } //나비형 밸브 대화상자 버튼 private void btn_path1_Click(object sender, EventArgs e) { string versionNumber = doc.Application.VersionNumber.ToString(); m_BFpath = GetFamilyPath(); if (m_BFpath != null) txt_path1.Text = Path.GetFileName(m_BFpath); else { //string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location; //Tmp = Tmp.Replace("\\KMBIM2019.dll", ""); string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Header"); m_BFpath = Tmp + "\\family\\"+versionNumber+"\\KS_Butterfly Valve -Lever.rfa"; txt_path1.Text = Path.GetFileName(m_BFpath); } } //배수 밸브 대화상자 버튼 private void btn_path2_Click(object sender, EventArgs e) { string versionNumber = doc.Application.VersionNumber.ToString(); m_Drainpath = GetFamilyPath(); if (m_Drainpath != null) txt_path2.Text = Path.GetFileName(m_Drainpath); else { //string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location; //Tmp = Tmp.Replace("\\KMBIM2019.dll", ""); string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Header"); m_Drainpath = Tmp + "\\family\\"+versionNumber+"\\PV_Ball Valve - 8-100mm -Threaded.rfa"; txt_path2.Text = Path.GetFileName(m_Drainpath); } } //시스템 유형 변경 시 private void combo_SupSysType_SelectedIndexChanged(object sender, EventArgs e) { ICollection 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_SupSysType.SelectedItem.ToString()) continue; //작도에 쓰일 pipetype Element HeaderSysType = pipeSysType; if (HeaderSysType != null) break; } } Reg.setReg("combo_SupSysType_Idx", combo_SupSysType.SelectedIndex.ToString()); } //안전 밸브 대화상자 버튼 private void btn_path3_Click(object sender, EventArgs e) { string versionNumber = doc.Application.VersionNumber.ToString(); m_Safepath = GetFamilyPath(); if (m_Safepath != null) txt_path3.Text = Path.GetFileName(m_Safepath); else { //string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location; //Tmp = Tmp.Replace("\\KMBIM2019.dll", ""); string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Header"); m_Safepath = Tmp + "\\family\\"+versionNumber+"\\YSF-3(25-50).rfa"; txt_path3.Text = Path.GetFileName(m_Safepath); } } //압력계 대화상자 버튼 private void btn_path4_Click(object sender, EventArgs e) { string versionNumber = doc.Application.VersionNumber.ToString(); m_PGpath = GetFamilyPath(); if (m_PGpath != null) txt_path4.Text = Path.GetFileName(m_PGpath); else { //string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location; //Tmp = Tmp.Replace("\\KMBIM2019.dll", ""); string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Header"); m_PGpath = Tmp + "\\family\\"+versionNumber+"\\KS_Pressure Gauge.rfa"; txt_path4.Text = Path.GetFileName(m_PGpath); } } //온도계 대화상자 버튼 private void btn_path5_Click(object sender, EventArgs e) { string versionNumber = doc.Application.VersionNumber.ToString(); m_TGpath = GetFamilyPath(); if (m_TGpath != null) txt_path5.Text = Path.GetFileName(m_TGpath); else { //string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location; //Tmp = Tmp.Replace("\\KMBIM2019.dll", ""); string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Header"); m_TGpath = Tmp + "\\family\\"+versionNumber+"\\KS_Temperature Gauge.rfa"; txt_path5.Text = Path.GetFileName(m_TGpath); } } public string GetFamilyPath() { string versionNumber = doc.Application.VersionNumber.ToString(); string path = null; OpenFileDialog FileDlg = new OpenFileDialog(); FileDlg.InitialDirectory = "C:\\ProgramData\\DCS.CO.KR\\KMBIM\\Libraries\\Header\\family\\"+versionNumber+"\\"; FileDlg.Filter = "rfa Files(*.rfa)|*.rfa|All Files(*.*)|*.*"; FileDlg.FilterIndex = 2; FileDlg.RestoreDirectory = true; if (FileDlg.ShowDialog() == DialogResult.OK) { if (FileDlg.FileName != null) { //확장자가 rfa가 아닐 경우 if (Path.GetExtension(FileDlg.FileName) != ".rfa") { MessageBox.Show("rfa 파일이 아닙니다."); } else { path = FileDlg.FileName; } } } return path; } } }