274 lines
8.7 KiB
C#
274 lines
8.7 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
using Autodesk.Revit.UI;
|
|
using KDCS.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace KMBIM
|
|
{
|
|
|
|
public partial class Form_UpperPipeRack : System.Windows.Forms.Form
|
|
{
|
|
public Autodesk.Revit.UI.ExternalCommandData revit;
|
|
public Level level;
|
|
public int m_Extend, m_Radidx = 0;
|
|
public string m_LvlAttach, m_LvlCurrent;
|
|
private double m_offset;
|
|
private Pipe m_MaxPipe = null, m_MinPipe = null;
|
|
|
|
public double Offset
|
|
{
|
|
get { return m_offset; }
|
|
set { m_offset = value; }
|
|
}
|
|
|
|
public Pipe MaxDiaPipe
|
|
{
|
|
get { return m_MaxPipe; }
|
|
set { m_MaxPipe = value; }
|
|
}
|
|
|
|
public Pipe MinOffPipe
|
|
{
|
|
get { return m_MinPipe; }
|
|
set { m_MinPipe = value; }
|
|
}
|
|
|
|
public Form_UpperPipeRack()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
|
|
private void Form_UpperPipeRack_Load(object sender, EventArgs e)
|
|
{
|
|
this.KeyPreview = true;
|
|
UIApplication uiapp = revit.Application;
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
Autodesk.Revit.DB.Document doc = uidoc.Document;
|
|
Level level = doc.ActiveView.GenLevel;
|
|
List<Level> levelList = null;
|
|
|
|
if (level != null)
|
|
{
|
|
txt_UpCurLevel.Text = level.Name;
|
|
m_LvlCurrent = level.Name;
|
|
}
|
|
else
|
|
{
|
|
txt_UpCurLevel.Text = "Unknown";
|
|
m_LvlCurrent = "Unknown";
|
|
}
|
|
|
|
//레벨 가져오기
|
|
levelList = getLevel();
|
|
LevelComparer levelComparer = new LevelComparer();
|
|
levelList.Sort(levelComparer);
|
|
//레벨 리스트 목록 콤보박스 추가
|
|
foreach (Level lvl in levelList)
|
|
{
|
|
combo_UpAttachLevel.Items.Add(lvl.Name);
|
|
}
|
|
|
|
//파이프 레벨
|
|
Level PipeLevel = null;
|
|
if (MinOffPipe != null)
|
|
PipeLevel = MinOffPipe.ReferenceLevel;
|
|
else
|
|
PipeLevel = MaxDiaPipe.ReferenceLevel;
|
|
|
|
//string aa = "";
|
|
//foreach (Level lvl in levelList)
|
|
//{
|
|
// //if(PipeLevel.Name == lvl.Name)
|
|
// aa += lvl.Name+"\n";
|
|
//}
|
|
//MessageBox.Show("" + aa);
|
|
|
|
////파이프 참조레벨 다음레벨
|
|
Level PipeUpLevel = null;
|
|
|
|
for(int i=0; i<levelList.Count; i++)
|
|
{
|
|
if(levelList[i].Name == PipeLevel.Name)
|
|
{
|
|
if (levelList.Count > i + 1)
|
|
{
|
|
PipeUpLevel = levelList[i + 1];
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
PipeUpLevel = levelList[i];
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (PipeUpLevel != null)
|
|
{
|
|
foreach (Level lvl in levelList)
|
|
{
|
|
if (PipeUpLevel.Name == lvl.Name)
|
|
{
|
|
int idx = combo_UpAttachLevel.FindString(lvl.Name);
|
|
if (idx != -1)
|
|
{
|
|
combo_UpAttachLevel.SelectedIndex = idx;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else//파이프 레벨이 없으면 콤보박스 첫번쨰로
|
|
{
|
|
combo_UpAttachLevel.SelectedIndex = 0;
|
|
}
|
|
|
|
////콤보박스 저장된 레벨 값 불러오기, 없으면 첫번쨰 레벨
|
|
//if (levelList.Count > 0)
|
|
//{
|
|
// if(Reg.getReg("UpPipeRack_Combo_SelLevel") == "")
|
|
// {
|
|
// Level lvl = levelList[0] as Level;
|
|
// Reg.setReg("UpPipeRack_Combo_SelLevel", lvl.Name);
|
|
// combo_UpAttachLevel.SelectedIndex = 0;
|
|
// }
|
|
// else
|
|
// {
|
|
// string str_SelectLevel = Reg.getReg("UpPipeRack_Combo_SelLevel");
|
|
// foreach(Element elem in levelList)
|
|
// {
|
|
// Level lvl = elem as Level;
|
|
// if (str_SelectLevel == lvl.Name)
|
|
// {
|
|
// int idx = combo_UpAttachLevel.FindString(lvl.Name);
|
|
// if (idx != -1)
|
|
// {
|
|
// combo_UpAttachLevel.SelectedIndex = idx;
|
|
// break;
|
|
// }
|
|
// }
|
|
// else
|
|
// combo_UpAttachLevel.SelectedIndex = 0;
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
|
|
//볼트 타입
|
|
if (Reg.getReg("Rack_Type") == "")
|
|
{
|
|
m_Radidx = 0;
|
|
Reg.setReg("Rack_Type", "" + m_Radidx);
|
|
}
|
|
else
|
|
{
|
|
string str_RadIdx = Reg.getReg("Rack_Type");
|
|
m_Radidx = int.Parse(str_RadIdx);
|
|
if (m_Radidx == 0)
|
|
rad_guideShoe.Checked = true;
|
|
else if (m_Radidx == 1)
|
|
rad_Ubolt.Checked = true;
|
|
else
|
|
radNon.Checked = true;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private void combo_UpAttachLevel_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
m_Extend = combo_UpAttachLevel.SelectedIndex;
|
|
m_LvlAttach = combo_UpAttachLevel.SelectedItem.ToString();
|
|
//Reg.setReg("UpPipeRack_Combo_SelLevel", m_LvlAttach);
|
|
}
|
|
|
|
|
|
private void combo_UpAttachLevel_DrawItem(object sender, DrawItemEventArgs e)
|
|
{
|
|
System.Windows.Forms.ComboBox cbx = sender as System.Windows.Forms.ComboBox;
|
|
if (cbx != null)
|
|
{
|
|
e.DrawBackground();
|
|
if (e.Index >= 0)
|
|
{
|
|
StringFormat sf = new StringFormat();
|
|
sf.LineAlignment = StringAlignment.Center;
|
|
sf.Alignment = StringAlignment.Far;
|
|
Brush brush = new SolidBrush(cbx.ForeColor);
|
|
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
|
|
brush = SystemBrushes.HighlightText;
|
|
e.Graphics.DrawString(cbx.Items[e.Index].ToString(), cbx.Font, brush, e.Bounds, sf);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Form_UpperPipeRack_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 rad_guideShoe_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
m_Radidx = 0;
|
|
Reg.setReg("Rack_Type", "" + m_Radidx);
|
|
}
|
|
|
|
private void rad_Ubolt_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
m_Radidx = 1;
|
|
Reg.setReg("Rack_Type", "" + m_Radidx);
|
|
}
|
|
private void radNon_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
m_Radidx = 2;
|
|
Reg.setReg("Rack_Type", "" + m_Radidx);
|
|
}
|
|
|
|
private List<Level> getLevel()
|
|
{
|
|
this.Hide();
|
|
UIApplication uiapp = revit.Application;
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
Autodesk.Revit.DB.Document doc = uidoc.Document;
|
|
|
|
Autodesk.Revit.DB.View view = doc.ActiveView;
|
|
ElementId levelId = null;
|
|
List<Level> ElemList = new List<Level>();
|
|
|
|
Autodesk.Revit.DB.Parameter level = view.LookupParameter("Associated Level");
|
|
|
|
FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
|
|
ICollection<Element> lvlCollection = lvlCollector.OfClass(typeof(Level)).ToElements();
|
|
|
|
foreach (Element l in lvlCollection)
|
|
{
|
|
Level lvl = l as Level;
|
|
ElemList.Add(lvl);
|
|
//MessageBox.Show("" + lvl.Name);
|
|
}
|
|
return ElemList;
|
|
}
|
|
}
|
|
}
|