|
| 1 | +using Autodesk.AutoCAD.DatabaseServices; |
| 2 | +using Autodesk.AutoCAD.Runtime; |
| 3 | +using Autodesk.AutoCAD.Windows; |
| 4 | +using Autodesk.Windows; |
| 5 | +using ricaun.AutoCAD.UI.Busy; |
| 6 | +using ricaun.AutoCAD.UI.Tasks; |
| 7 | +using ricaun.AutoCAD.UI.Windows; |
| 8 | +using System; |
| 9 | +using System.Diagnostics; |
| 10 | +using System.Threading.Tasks; |
| 11 | + |
| 12 | +[assembly: ExtensionApplication(typeof(ricaun.AutoCAD.UI.Example.App))] |
| 13 | + |
| 14 | +namespace ricaun.AutoCAD.UI.Example |
| 15 | +{ |
| 16 | + public class App : ExtensionApplication |
| 17 | + { |
| 18 | + private const string PanelName = "Example"; |
| 19 | + private const string TabName = "ricaun"; |
| 20 | + |
| 21 | + public override void OnStartup(RibbonControl ribbonControl) |
| 22 | + { |
| 23 | + var ribbonPanel = ribbonControl.CreateOrSelectPanel(PanelName, TabName); |
| 24 | + |
| 25 | + ribbonPanel.RowLargeStackedItems( |
| 26 | + ribbonPanel.CreateButton("Theme") |
| 27 | + .SetShowText(false) |
| 28 | + .SetCommand(Commands.ThemeChange) |
| 29 | + .SetLargeImage("https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/2.0.0/Box-Grey-Light.tiff"), |
| 30 | + ribbonPanel.CreateButton("Theme") |
| 31 | + .SetShowText(false) |
| 32 | + .SetCommand(Commands.ThemeChange) |
| 33 | + .SetLargeImage("https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/2.0.0/Box-Red-Light.tiff"), |
| 34 | + ribbonPanel.CreateButton("Theme") |
| 35 | + .SetCommand(Commands.ThemeChange) |
| 36 | + .SetLargeImage("https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/2.0.0/Box-Green-Light.ico"), |
| 37 | + ribbonPanel.CreateButton("Theme") |
| 38 | + .SetCommand(Commands.ThemeChange) |
| 39 | + .SetLargeImage("https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/2.0.0/Box-Blue-32-Light.png") |
| 40 | + ); |
| 41 | + |
| 42 | + ribbonPanel.AddSeparator(); |
| 43 | + |
| 44 | + ribbonPanel.CreateButton("Circle\rCreate") |
| 45 | + .SetCommand(Commands.CircleCreate) |
| 46 | + .SetDescription("Create a circle with a random radius in the model space.") |
| 47 | + .SetToolTip("This button use the command 'CircleCreate'.") |
| 48 | + .SetLargeImage("Resources/Cube-Grey-Light.tiff"); |
| 49 | + |
| 50 | + ribbonPanel.CreateButton("Show\rMessage") |
| 51 | + .SetCommand((item) => { Windows.MessageBox.ShowMessage(item.Text, "This is a custom message."); }) |
| 52 | + .SetLargeImage("Resources/Cube-Grey-Light.tiff"); |
| 53 | + |
| 54 | + ribbonPanel.CreateButton("Show\rBalloon") |
| 55 | + .SetCommand((item) => { Windows.InfoCenter.ShowBalloon(item.Text, "This is a custom message."); }) |
| 56 | + .SetLargeImage("Resources/Cube-Grey-Light.tiff"); |
| 57 | + |
| 58 | + ribbonButtonBusy = ribbonPanel.CreateButton("None") |
| 59 | + .SetLargeImage("Resources/Cube-Grey-Light.tiff"); |
| 60 | + |
| 61 | + ribbonPanel.CreateButton("Task") |
| 62 | + .SetCommand((item) => |
| 63 | + { |
| 64 | + if (autoCADTask is null) return; |
| 65 | + item.IsEnabled = false; |
| 66 | + Task.Run(async () => |
| 67 | + { |
| 68 | + try |
| 69 | + { |
| 70 | + for (int i = 0; i < 10; i++) |
| 71 | + { |
| 72 | + await autoCADTask.Run(Commands.CircleCreate); |
| 73 | + await Task.Delay(100); |
| 74 | + } |
| 75 | + } |
| 76 | + finally |
| 77 | + { |
| 78 | + await autoCADTask.Run(() => |
| 79 | + { |
| 80 | + item.IsEnabled = true; |
| 81 | + }); |
| 82 | + } |
| 83 | + }); |
| 84 | + }) |
| 85 | + .SetLargeImage("Resources/Cube-Grey-Light.tiff"); |
| 86 | + |
| 87 | + ribbonPanel.CreateButton("Show\rPalette") |
| 88 | + .SetCommand(() => { paletteSet?.ToggleVisible(); }) |
| 89 | + .SetLargeImage("Resources/Cube-Grey-Light.tiff"); |
| 90 | + |
| 91 | + ribbonControl.ActiveTab = ribbonPanel.Tab; |
| 92 | + } |
| 93 | + public override void OnShutdown(RibbonControl ribbonControl) |
| 94 | + { |
| 95 | + ribbonControl.RemovePanel(PanelName, TabName); |
| 96 | + } |
| 97 | + |
| 98 | + private RibbonButton ribbonButtonBusy; |
| 99 | + private PaletteSet paletteSet; |
| 100 | + private AutoCADBusyService busyService; |
| 101 | + private AutoCADTaskService taskService; |
| 102 | + public IAutoCADTask autoCADTask => taskService; |
| 103 | + public override void Initialize() |
| 104 | + { |
| 105 | + base.Initialize(); |
| 106 | + busyService = new AutoCADBusyService(); |
| 107 | + busyService.Initialize(); |
| 108 | + busyService.PropertyChanged += (sender, e) => |
| 109 | + { |
| 110 | + ribbonButtonBusy?.SetText(busyService.IsAutoCADBusy ? "Busy" : "Idle"); |
| 111 | + var color = busyService.IsAutoCADBusy ? "Red" : "Green"; |
| 112 | + ribbonButtonBusy?.SetLargeImage($"Resources/Cube-{color}-Light.tiff"); |
| 113 | + }; |
| 114 | + taskService = new AutoCADTaskService(); |
| 115 | + taskService.Initialize(); |
| 116 | + |
| 117 | + var visual = new System.Windows.Controls.Grid() |
| 118 | + { |
| 119 | + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.LightGray), |
| 120 | + }; |
| 121 | + paletteSet = PaletteSetUtils.Create("Example Palette Set", new Guid("360B945E-1EFF-4212-9C00-3E841A9F1B28"), visual); |
| 122 | + } |
| 123 | + |
| 124 | + public override void Terminate() |
| 125 | + { |
| 126 | + base.Terminate(); |
| 127 | + busyService?.Dispose(); |
| 128 | + taskService?.Dispose(); |
| 129 | + } |
| 130 | + } |
| 131 | +} |
0 commit comments