203 lines
7.9 KiB
C#
203 lines
7.9 KiB
C#
using System.Windows;
|
|
using Autodesk.Windows;
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|
|
|
|
|
using ShrlAlgoToolkit.RevitAddins.Properties;
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.Entry;
|
|
|
|
public class DrawingViewApp
|
|
{
|
|
private static readonly string TabName = Settings.Default.TabName;
|
|
|
|
public DrawingViewApp(UIControlledApplication application)
|
|
{
|
|
CreateAnnotationsTools(application);
|
|
RegisterDockPaneAndEvent(application);
|
|
}
|
|
|
|
private readonly ActionEventHandler zoomElementHandler = new();
|
|
private void CreateAnnotationsTools(UIControlledApplication application)
|
|
{
|
|
var ribbonPanel = application.CreateRibbonPanel(TabName, "视图与出图");
|
|
|
|
var autoAlignTags = UIAssist.NewPushButtonData<DrawSheet.AlignTagsCmd>(
|
|
"对齐标记",
|
|
Resources.align_tags_32px,
|
|
Resources.align_tags_16px
|
|
).SetAvailability<EnableInViewPlan>();
|
|
var arrangeTags = UIAssist.NewPushButtonData<DrawSheet.ArrangeTagsCmd>(
|
|
"整理标记",
|
|
Resources.arrange_tags_32px,
|
|
Resources.arrange_tags_16px
|
|
).SetAvailability<EnableInViewPlan>();
|
|
|
|
var dim2Line = UIAssist.NewPushButtonData<DrawSheet.DimensionBy2LineCmd>(
|
|
"双线标注",
|
|
Resources.two_lines_32px,
|
|
Resources.two_lines_16px,
|
|
"选择要标注的两条平行的几何模型边缘线进行标注。"
|
|
);
|
|
var adaptiveMEPTag = UIAssist.NewPushButtonData<DrawSheet.AdaptiveMEPTagCmd>(
|
|
"自适应标记",
|
|
Resources.adaptive_MEP_tag_32px,
|
|
Resources.adaptive_MEP_tag_16px,
|
|
"删除距离过密的标记及管上标记方向调整"
|
|
);
|
|
|
|
var visibilityControl = UIAssist.NewPushButtonData<DrawSheet.VisibilityControlCmd>(
|
|
"可见性",
|
|
Resources.visibility_control_32px,
|
|
Resources.visibility_control_16px,
|
|
"可见性控制"
|
|
).SetAvailability<OnProjectDocument>();
|
|
var sectionBox = UIAssist.NewPushButtonData<DrawSheet.SectionBoxControllerCmd>(
|
|
"剖面框",
|
|
Resources.sectionBox_32px,
|
|
Resources.sectionBox_16px
|
|
);
|
|
var filter = UIAssist.NewPushButtonData<DrawSheet.CivilViewFilterCmd>(
|
|
"过滤器",
|
|
Resources.filter_32px,
|
|
Resources.filter_16px,
|
|
"创建当前视图的结构模型区分的过滤"
|
|
);
|
|
|
|
var panelSchedule = UIAssist.NewPushButtonData<DrawSheet.PanelScheduleCmd>(
|
|
"铺砖明细表",
|
|
Resources.schedule_32px,
|
|
Resources.schedule_16px
|
|
);
|
|
var exportSchedulesPbd = UIAssist.NewPushButtonData<DrawSheet.ExportSchedulesCmd>(
|
|
"导出明细表",
|
|
Resources.export_excel_32px,
|
|
Resources.export_excel_16px,
|
|
"导出明细表为Excel文件"
|
|
);
|
|
var systemDisplay = UIAssist.NewPushButtonData<DrawSheet.SystemDisplayCmd>(
|
|
"系统显示",
|
|
Resources.system_display_32px,
|
|
Resources.system_display_16px
|
|
);
|
|
var viewManager = UIAssist.NewPushButtonData<DrawSheet.ViewManagerCmd>(
|
|
"视图管理",
|
|
Resources.view_manager_32px,
|
|
Resources.view_manager_16px
|
|
);
|
|
var quickViewSection = UIAssist.NewPushButtonData<DrawSheet.QuickViewSectionCmd>(
|
|
"快速剖面",
|
|
Resources.view_section_32px,
|
|
Resources.view_section_16px
|
|
);
|
|
var elementsControlCmd = UIAssist.NewPushButtonData<DrawSheet.ElementsControlCmd>(
|
|
"元素控制",
|
|
Resources.open_pane_32px,
|
|
Resources.open_pane_32px,
|
|
"元素菜单控制"
|
|
);
|
|
|
|
ribbonPanel.AddSplitButton("标记工具", dim2Line, autoAlignTags, arrangeTags, adaptiveMEPTag);
|
|
ribbonPanel.AddStackedItems(visibilityControl, sectionBox, filter);
|
|
//ribbonPanel.AddSplitButton(splitBtn1, dim2Line, autoAlignTags, arrangeTags);
|
|
|
|
ribbonPanel.AddItem(elementsControlCmd);
|
|
ribbonPanel.AddStackedItems(systemDisplay, viewManager, quickViewSection);
|
|
|
|
var tab = ComponentManager.Ribbon.Tabs.First(t => t.Name == TabName);
|
|
CreateToggleButton(tab, "视图与出图");
|
|
//面板下拉展开
|
|
ribbonPanel.AddSlideOut();
|
|
ribbonPanel.AddStackedItems(panelSchedule, exportSchedulesPbd);
|
|
|
|
//SplitButtonData splitBtn3 = new(nameof(splitBtn3), "显示设置");
|
|
//ribbonPanel.AddPushButton<SystemDisplayCmd>("系统显示", Resources.system_display_32px, "系统显示");
|
|
//ribbonPanel.AddPushButton<ViewManagerCmd>("视图管理", Resources.view_manager_32px, "视图管理");
|
|
}
|
|
|
|
private void CreateToggleButton(RibbonTab rt, string panelName)
|
|
{
|
|
try
|
|
{
|
|
var panel = rt.Panels.FirstOrDefault(p => p.Source.Name == panelName);
|
|
var tog = UIAssist.NewAwToggleButton(
|
|
"最大化",
|
|
Resources.zoom_32px,
|
|
"根据视图的图元是否可见,在切换视图时,对当前选中的图元进行快速缩放定位");
|
|
//var tog = new Autodesk.Windows.RibbonToggleButton()
|
|
//{
|
|
// LargeImage = Resources.zoom_32px.ToBitmapSource(),
|
|
// Size = RibbonItemSize.Large,
|
|
// Name = "ZoomElement",
|
|
// Text = "最大化",
|
|
// ShowText = true,
|
|
// ToolTip = "根据视图的图元是否可见,在切换视图时,对当前选中的图元进行快速缩放定位",
|
|
// IsCheckable = true,
|
|
// Orientation = System.Windows.Controls.Orientation.Vertical,
|
|
//};
|
|
tog.CheckStateChanged += (_, _) =>
|
|
{
|
|
zoomElementHandler.Raise(
|
|
uiapp =>
|
|
{
|
|
if (tog.CheckState == true)
|
|
{
|
|
uiapp.ViewActivated -= UiApp_ViewActivated;
|
|
uiapp.ViewActivated += UiApp_ViewActivated;
|
|
}
|
|
else
|
|
{
|
|
uiapp.ViewActivated -= UiApp_ViewActivated;
|
|
}
|
|
});
|
|
};
|
|
//Autodesk.Windows.RibbonItemControl
|
|
panel.Source.Items.Add(tog);
|
|
tog.IsChecked = true;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
MessageBox.Show(exception.Message, "添加TogButton错误");
|
|
}
|
|
}
|
|
private static void RegisterDockPaneAndEvent(UIControlledApplication application)
|
|
{
|
|
DrawSheet.ElementsControlDock pane = new();
|
|
application.RegisterDockablePane(Variables.PaneId, "元素控制菜单", pane);
|
|
}
|
|
private static void UiApp_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (sender is not UIApplication uiApp)
|
|
{
|
|
return;
|
|
}
|
|
var uidoc = uiApp.ActiveUIDocument;
|
|
var elemIdsSelected = uidoc.Selection.GetElementIds();
|
|
if (uidoc.Selection.GetElementIds().Count != 1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var elem = uidoc.Document.GetElement(elemIdsSelected.FirstOrDefault());
|
|
e.CurrentActiveView.ZoomElement(uidoc, elem.Id);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
//if (elem.IsVisible(e.CurrentActiveView))
|
|
//{
|
|
// var box = elem.get_BoundingBox(UiDocument.ActiveGraphicalView);
|
|
// const int extend = 5;
|
|
// var uiView = UiDocument.GetOpenUIViews().FirstOrDefault(v => v.ViewId == UiDocument.ActiveGraphicalView.Id);
|
|
// uiView?.ZoomAndCenterRectangle(
|
|
// box.Min + (extend * box.Min.Normalize()),
|
|
// box.Max - (extend * box.Min.Normalize())
|
|
// );
|
|
//}
|
|
}
|
|
}
|