338 lines
12 KiB
C#
338 lines
12 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Mechanical;
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
using Autodesk.Revit.UI;
|
|
using KDCS.Utils;
|
|
using KMBIM.Revit.Tools.LogicClass;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace KMBIM.Revit.Tools.Cmd.Insulation
|
|
{
|
|
public partial class InsulationSettings : System.Windows.Forms.Form
|
|
{
|
|
List<PipeType> pipeCollection = null;
|
|
List<DuctType> ductCollection = null;
|
|
List<PipeInsulationType> PipeinsulationCollection = null;
|
|
List<DuctInsulationType> DuctinsulationCollection = null;
|
|
|
|
|
|
public TblDataStorage PipeData = null;
|
|
TblInsulationType PipeinsulList = new TblInsulationType();
|
|
TblInsulationType DuctinsulList = new TblInsulationType();
|
|
public bool bKeepInsulation = false;
|
|
public bool bApplyPipe = false;
|
|
public bool bApplyDuct = false;
|
|
string category = string.Empty;
|
|
private Document m_doc = null;
|
|
UIDocument m_uidoc = null;
|
|
public InsulationSettings(Document doc, UIDocument uidoc,
|
|
List<PipeType> pipeCollection,
|
|
List<DuctType> ductCollection,
|
|
List<PipeInsulationType> PipeinsulationCollection,
|
|
List<DuctInsulationType> DuctinsulationCollection,
|
|
TblDataStorage PipeData,
|
|
ref TblInsulationType PipeinsulList,
|
|
ref TblInsulationType DuctinsulList)
|
|
{
|
|
InitializeComponent();
|
|
m_doc = doc;
|
|
m_uidoc = uidoc;
|
|
this.pipeCollection = pipeCollection;
|
|
this.ductCollection = ductCollection;
|
|
this.PipeinsulationCollection = PipeinsulationCollection;
|
|
this.DuctinsulationCollection = DuctinsulationCollection;
|
|
this.PipeData = PipeData;
|
|
this.PipeinsulList = PipeinsulList;
|
|
this.DuctinsulList = DuctinsulList;
|
|
|
|
|
|
}
|
|
|
|
private void InsulationSettings_Load(object sender, EventArgs e)
|
|
{
|
|
this.KeyPreview = true;
|
|
|
|
category = Reg.getReg("kdcsInsulationDefaultType");
|
|
if (category.CompareTo("") == 0) { Reg.setReg("kdcsInsulationDefaultType", "기본"); category = "기본"; }
|
|
|
|
PipeinsulationTypeBindingSource.DataSource = PipeinsulList.GetTable();
|
|
DuctinsulationTypeBindingSource.DataSource = DuctinsulList.GetTable();
|
|
PipedataStorageBindingSource.DataSource = PipeData.GetTable(category, true);
|
|
DuctdataStorageBindingSource.DataSource = PipeData.GetTable(category, false);
|
|
cbCategory.Items.Clear();
|
|
foreach (var row in PipeData.GetTable())
|
|
{
|
|
cbCategory.Items.Add(row.Key);
|
|
}
|
|
cbCategory.SelectedIndex = cbCategory.FindString(category);
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
bKeepInsulation = this.ckKeepInsulation.Checked;
|
|
bApplyDuct = this.ckDuct.Checked;
|
|
bApplyPipe = this.ckPipe.Checked;
|
|
string category = cbCategory.Text;
|
|
if (category.CompareTo("") == 0) return;
|
|
|
|
Reg.setReg("kdcsInsulationDefaultType", category);
|
|
this.Close();
|
|
}
|
|
|
|
|
|
private void btnCategory_Click(object sender, EventArgs e)
|
|
{
|
|
string category = cbCategory.Text;
|
|
if (category.CompareTo("") == 0) return;
|
|
|
|
|
|
string strPipeinsul = PipeinsulationCollection.First().Name;
|
|
string strDucteinsul = DuctinsulationCollection.First().Name;
|
|
|
|
PipeData.AddCategory(category);
|
|
|
|
foreach (var row in pipeCollection)
|
|
{
|
|
PipeData.Add(category, true, row.Name, strPipeinsul, 25.0);
|
|
}
|
|
|
|
foreach (var row in ductCollection)
|
|
{
|
|
PipeData.Add(category, false, row.Name, strDucteinsul, 25.0);
|
|
}
|
|
cbCategory.Items.Clear();
|
|
foreach (var row in PipeData.GetTable())
|
|
{
|
|
cbCategory.Items.Add(row.Key);
|
|
}
|
|
cbCategory.SelectedIndex = cbCategory.FindString(category);
|
|
|
|
RefreshList();
|
|
}
|
|
|
|
private void cbCategory_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
RefreshList();
|
|
|
|
}
|
|
private void RefreshList()
|
|
{
|
|
string category = cbCategory.Text;
|
|
if (category.CompareTo("") == 0) return;
|
|
PipedataStorageBindingSource.DataSource = null;
|
|
DuctdataStorageBindingSource.DataSource = null;
|
|
PipedataStorageBindingSource.DataSource = PipeData.GetTable(category, true);
|
|
DuctdataStorageBindingSource.DataSource = PipeData.GetTable(category, false);
|
|
}
|
|
|
|
private void btn_Export_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
save();
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|
saveFileDialog.FileName = m_uidoc.Document.Title + "_settings" + ".kins"; //초기 파일명을 지정할 때 사용한다.
|
|
saveFileDialog.Filter = "kins|*.kins";
|
|
saveFileDialog.Title = "Save an kins File";
|
|
if(saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
if (saveFileDialog.FileName != "")
|
|
{
|
|
string location = Util.GetKMBIMLibraryFolder("\\Libraries\\Insulation");
|
|
string jsonPath = Path.Combine(location, "settings.kins");
|
|
|
|
System.IO.File.Copy(jsonPath, saveFileDialog.FileName, true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private void btn_Import_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
openFileDialog.Filter = "kins|*.kins";
|
|
openFileDialog.Title = "Save an kins File";
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
if (openFileDialog.FileName != "")
|
|
{
|
|
string location = Util.GetKMBIMLibraryFolder("\\Libraries\\Insulation");
|
|
string jsonPath = Path.Combine(location, "settings.kins");
|
|
|
|
System.IO.File.Copy(jsonPath, openFileDialog.FileName, true);
|
|
}
|
|
}
|
|
|
|
|
|
if (openFileDialog.FileName != "")
|
|
{
|
|
string location = Util.GetKMBIMLibraryFolder("\\Libraries\\Insulation");
|
|
string jsonPath = Path.Combine(location, "settings.kins");
|
|
|
|
System.IO.File.Copy(openFileDialog.FileName, jsonPath, true);
|
|
open();
|
|
|
|
cbCategory.Items.Clear();
|
|
foreach (var row in PipeData.GetTable())
|
|
{
|
|
cbCategory.Items.Add(row.Key);
|
|
}
|
|
category = PipeData.GetTable().First().Key;
|
|
cbCategory.SelectedIndex = cbCategory.FindString(category);
|
|
RefreshList();
|
|
|
|
}
|
|
|
|
}
|
|
public void open()
|
|
{
|
|
string location = Util.GetKMBIMLibraryFolder("\\Libraries\\Insulation");
|
|
string jsonPath = Path.Combine(location, "settings.kins");
|
|
//DirectoryInfo 생성
|
|
DirectoryInfo di = new DirectoryInfo(location);
|
|
//DirectoryInfo.Exists로 폴더 존재유무 확인
|
|
if (!di.Exists) { di.Create(); }
|
|
|
|
|
|
|
|
if (File.Exists(jsonPath))
|
|
{
|
|
using (StreamReader r = new StreamReader(jsonPath))
|
|
{
|
|
|
|
using (JsonTextReader reader1 = new JsonTextReader(r))
|
|
{
|
|
JValue o2 = (JValue)JToken.ReadFrom(reader1);
|
|
string strJson = o2.ToString();
|
|
PipeData.LoadJson(strJson);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void btnCategoryDel_Click(object sender, EventArgs e)
|
|
{
|
|
string category = cbCategory.Text;
|
|
if (category.CompareTo("") == 0) return;
|
|
PipeData.Remove(category);
|
|
|
|
cbCategory.Items.Clear();
|
|
foreach (var row in PipeData.GetTable())
|
|
{
|
|
cbCategory.Items.Add(row.Key);
|
|
}
|
|
category = PipeData.GetTable().First().Key;
|
|
cbCategory.SelectedIndex = cbCategory.FindString(category);
|
|
RefreshList();
|
|
|
|
|
|
}
|
|
|
|
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
|
|
{
|
|
for(int i=0; i< dataGridView1.Rows.Count; i++)
|
|
{
|
|
DataStorage row = dataGridView1.Rows[i].DataBoundItem as DataStorage;
|
|
if(row.bisNew)
|
|
{
|
|
for(int j = 0; j < dataGridView1.ColumnCount; j++)
|
|
{
|
|
dataGridView1.Rows[i].Cells[j].Style.BackColor = System.Drawing.Color.SkyBlue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void save()
|
|
{
|
|
|
|
string location = Util.GetKMBIMLibraryFolder("\\Libraries\\Insulation");
|
|
string jsonPath = Path.Combine(location, "settings.kins");
|
|
|
|
//DirectoryInfo 생성
|
|
DirectoryInfo di = new DirectoryInfo(location);
|
|
//DirectoryInfo.Exists로 폴더 존재유무 확인
|
|
if (!di.Exists) { di.Create(); }
|
|
|
|
|
|
using (StreamWriter file = File.CreateText(jsonPath))
|
|
{
|
|
string strJson = PipeData.toJson();
|
|
|
|
JsonSerializer serializer = new JsonSerializer();
|
|
//serialize object directly into file stream
|
|
serializer.Serialize(file, strJson);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if(e.ColumnIndex == 1)
|
|
{
|
|
DataStorage row = dataGridView1.Rows[e.RowIndex].DataBoundItem as DataStorage;
|
|
BoreSettings dlg = new BoreSettings(row.BoreList);
|
|
if(dlg.ShowDialog() == DialogResult.OK){
|
|
row.BoreList = dlg.BoreList;
|
|
}
|
|
}
|
|
//dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]
|
|
|
|
}
|
|
|
|
private void textBox_Thickness_TextChanged(object sender, EventArgs e)
|
|
{
|
|
double dblthick = 0;
|
|
double.TryParse(textBox_Thickness.Text, out dblthick);
|
|
|
|
|
|
foreach (DataGridViewCell cell in dataGridView2.SelectedCells)
|
|
{
|
|
var row = dataGridView2.Rows[cell.RowIndex].DataBoundItem as DataStorage;
|
|
row.dblLaggingThickness = dblthick;
|
|
dataGridView2.Rows[cell.RowIndex].Cells[2].Value = dblthick;
|
|
dataGridView2.Refresh();
|
|
}
|
|
}
|
|
|
|
private void InsulationSettings_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Escape)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
}
|
|
else if (e.KeyCode == Keys.Enter)
|
|
{
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
|
|
private void textBox_Thickness_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(textBox_Thickness.Text) || textBox_Thickness.Text.Contains('.') == true)
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|