├── .gitignore ├── App.cs ├── Archilizer_Warchart.addin ├── Command.cs ├── Helpers └── BitmapIcons.cs ├── LICENSE ├── PackageContents.xml ├── Properties ├── Settings.Designer.cs └── Settings.settings ├── README.md ├── Resources ├── Theme.xaml ├── archilizer_default.png ├── archilizer_warchart.png ├── icon_Warchart.png ├── store icon │ └── Warchart.png └── warchart.png ├── Utility ├── Request.cs ├── RequestHandler.cs ├── Utils.cs └── WCModelComparer.cs ├── WarningChart.csproj ├── WarningChart.csproj.SdkResolver.1981936763.proj ├── WarningChart.csproj.user ├── WarningChart.sln ├── WarningChartWPF ├── CustomLegend.xaml ├── CustomLegend.xaml.cs ├── CustomTooltip.cs ├── MyResourceDictionary.xaml ├── WarChartView.xaml ├── WarChartView.xaml.cs ├── WarningChartModel.cs ├── WarningChartPoint.cs ├── WarningChartPresenter.cs ├── WarningChartSettings.xaml ├── WarningChartSettings.xaml.cs ├── WarningChartView.xaml └── WarningChartView.xaml.cs ├── app.config └── archilizer.ico /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /App.cs: -------------------------------------------------------------------------------- 1 | #region Namespaces 2 | using System; 3 | using System.Collections.Generic; 4 | using Autodesk.Revit.ApplicationServices; 5 | using Autodesk.Revit.Attributes; 6 | using Autodesk.Revit.DB; 7 | using Autodesk.Revit.UI; 8 | using System.Reflection; 9 | using System.Windows.Media.Imaging; 10 | using WC.WarningChartWPF; 11 | using System.Diagnostics; 12 | using System.Windows.Forms; 13 | using Autodesk.Revit.UI.Events; 14 | using System.Collections; 15 | using WC.Helpers; 16 | #endregion 17 | 18 | namespace WC 19 | { 20 | 21 | class App : IExternalApplication 22 | { 23 | private static UIControlledApplication MyApplication { get; set; } 24 | private static Assembly assembly; 25 | 26 | private static object TheInternalDoingPart(UIControlledApplication CApp, string TabName, string PanelName) 27 | { 28 | IList ERPs = null; 29 | 30 | ERPs = CApp.GetRibbonPanels(TabName); 31 | 32 | Autodesk.Revit.UI.RibbonPanel NewOrExtgRevitPanel = null; 33 | 34 | foreach (Autodesk.Revit.UI.RibbonPanel Pan in ERPs) 35 | { 36 | if (Pan.Name == PanelName) 37 | { 38 | NewOrExtgRevitPanel = Pan; 39 | goto FoundSoJumpPastNew; 40 | } 41 | } 42 | 43 | Autodesk.Revit.UI.RibbonPanel NewRevitPanel = null; 44 | 45 | NewRevitPanel = CApp.CreateRibbonPanel(TabName, PanelName); 46 | 47 | NewOrExtgRevitPanel = NewRevitPanel; 48 | FoundSoJumpPastNew: 49 | 50 | return NewOrExtgRevitPanel; 51 | } 52 | // Windows Revit handle 53 | static WindowHandle _hWndRevit = null; 54 | // Class instance 55 | internal static App thisApp = null; 56 | // Presenter instance 57 | private WarningChartPresenter _presenter; 58 | // Keeps track of the number of Warnings in the current Document 59 | private int _currentCount; 60 | // Current Document 61 | private Document _document; 62 | // Hardcoded helpfile path 63 | static string helpFile = "file:///C:/ProgramData/Autodesk/ApplicationPlugins/Archilizer_Warchart.bundle/Content/Help/Warchart%20_%20Revit%20_%20Autodesk%20App%20Store.html"; 64 | private bool _disabled; 65 | 66 | static void AddRibbonPanel(UIControlledApplication application) 67 | { 68 | // Create a custom ribbon panel 69 | var tabName = "Archilizer"; 70 | var panelName = "Miscellaneous"; 71 | try 72 | { 73 | application.CreateRibbonTab(tabName); 74 | } 75 | catch (Exception) 76 | { 77 | 78 | } 79 | 80 | var ribbonPanel = (RibbonPanel)TheInternalDoingPart(application, tabName, panelName); 81 | 82 | // Get dll assembly path 83 | var thisAssemblyPath = Assembly.GetExecutingAssembly().Location; 84 | assembly = Assembly.GetExecutingAssembly(); 85 | var assemblyVersion = assembly.GetName().Version; 86 | 87 | var ch = new ContextualHelp(ContextualHelpType.Url, @helpFile); 88 | 89 | CreatePushButton(ribbonPanel, String.Format("Warning" + Environment.NewLine + "Chart"), thisAssemblyPath, "WC.CommandWarningChart", 90 | String.Format("Displays a Pie Chart representing Project Warnings.{0}{0}v{1}", Environment.NewLine, assemblyVersion), "WC.Resources.icon_Warchart.png", ch); 91 | } 92 | 93 | private static void CreatePushButton(RibbonPanel ribbonPanel, string name, string path, string command, string tooltip, string icon, ContextualHelp ch) 94 | { 95 | BitmapIcons bitmapIcons = new BitmapIcons(assembly, icon, MyApplication); 96 | 97 | PushButtonData pbData = new PushButtonData( 98 | name, 99 | name, 100 | path, 101 | command); 102 | 103 | PushButton pb = ribbonPanel.AddItem(pbData) as PushButton; 104 | 105 | pb.ToolTip = tooltip; 106 | var largeImage = bitmapIcons.LargeBitmap(); 107 | var smallImage = bitmapIcons.SmallBitmap(); 108 | pb.LargeImage = largeImage; 109 | pb.Image = smallImage; 110 | pb.SetContextualHelp(ch); 111 | } 112 | 113 | public Result OnStartup(UIControlledApplication a) 114 | { 115 | ControlledApplication c_app = a.ControlledApplication; 116 | MyApplication = a; 117 | 118 | // Make sure you have to update the plugin 119 | string version = a.ControlledApplication.VersionNumber; 120 | 121 | AddRibbonPanel(a); 122 | 123 | _presenter = null; // no dialog needed yet; ThermalAsset command will bring it 124 | thisApp = this; // static access to this application instance 125 | c_app.DocumentChanged // Document Changed event - whenever it changes, check for your stuff (in this app check if warnings number has changed) 126 | += new EventHandler( 127 | c_app_DocumentChanged); 128 | 129 | a.ViewActivated += new EventHandler(OnViewActivated); 130 | 131 | 132 | return Result.Succeeded; 133 | } 134 | public Result OnShutdown(UIControlledApplication a) 135 | { 136 | ControlledApplication c_app = a.ControlledApplication; 137 | 138 | c_app.DocumentChanged 139 | -= new EventHandler( 140 | c_app_DocumentChanged); 141 | 142 | a.ViewActivated -= new EventHandler(OnViewActivated); 143 | 144 | if (_presenter != null) 145 | { 146 | _presenter.Close(); 147 | } 148 | 149 | return Result.Succeeded; 150 | } 151 | /// 152 | /// On Document Switched 153 | /// 154 | /// 155 | /// 156 | private void OnViewActivated(object sender, ViewActivatedEventArgs e) 157 | { 158 | Document doc = e.CurrentActiveView.Document; 159 | 160 | // If the document is a Family Document, disable the UI 161 | if(doc.IsFamilyDocument) 162 | { 163 | if(!_disabled && _presenter != null) 164 | { 165 | _presenter.Disable(); 166 | _disabled = true; 167 | } 168 | return; 169 | } 170 | else 171 | { 172 | if(_disabled) 173 | { 174 | _presenter.Enable(); 175 | _disabled = false; 176 | } 177 | } 178 | 179 | if (_document != null && _document.Title != doc.Title) 180 | { 181 | _document = doc; 182 | _currentCount = doc.GetWarnings().Count; 183 | _presenter._Application = new UIApplication(doc.Application); 184 | _presenter.DocumentSwitched(); 185 | } 186 | } 187 | /// 188 | /// On document change, update Family Parameters 189 | /// 190 | /// 191 | /// 192 | private void c_app_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e) 193 | { 194 | if (_presenter != null) 195 | { 196 | if (e.GetDocument().GetWarnings().Count != _currentCount) 197 | { 198 | _currentCount = e.GetDocument().GetWarnings().Count; 199 | _presenter.DocumentChanged(); 200 | } 201 | } 202 | } 203 | /// 204 | /// De-facto the command is here. 205 | /// 206 | /// 207 | public void ShowForm(UIApplication uiapp) 208 | { 209 | // get the isntance of Revit Thread 210 | // to pass it to the Windows Form later 211 | if (null == _hWndRevit) 212 | { 213 | Process process 214 | = Process.GetCurrentProcess(); 215 | 216 | IntPtr h = process.MainWindowHandle; 217 | _hWndRevit = new WindowHandle(h); 218 | } 219 | 220 | if (_presenter == null || _presenter.IsClosed) 221 | { 222 | //new handler 223 | RequestHandler handler = new RequestHandler(); 224 | //new event 225 | ExternalEvent exEvent = ExternalEvent.Create(handler); 226 | // set current document 227 | _document = uiapp.ActiveUIDocument.Document; 228 | 229 | // Set the initial number of warnings so we don't detect document change on the first event 230 | _currentCount = uiapp.ActiveUIDocument.Document.GetWarnings().Count; 231 | 232 | _presenter = new WarningChartPresenter(uiapp, exEvent, handler); 233 | 234 | try 235 | { 236 | //pass parent (Revit) thread here 237 | _presenter.Show(_hWndRevit); 238 | } 239 | catch(Exception ex) 240 | { 241 | Autodesk.Revit.UI.TaskDialog.Show("Error", ex.Message); 242 | _presenter.Dispose(); 243 | _presenter = null; 244 | } 245 | } 246 | } 247 | } 248 | /// 249 | /// Retrieve Revit Windows thread in order to pass it to the form as it's owner 250 | /// 251 | public class WindowHandle : IWin32Window 252 | { 253 | IntPtr _hwnd; 254 | 255 | public WindowHandle(IntPtr h) 256 | { 257 | Debug.Assert(IntPtr.Zero != h, 258 | "expected non-null window handle"); 259 | 260 | _hwnd = h; 261 | } 262 | 263 | public IntPtr Handle 264 | { 265 | get 266 | { 267 | return _hwnd; 268 | } 269 | } 270 | } 271 | 272 | } 273 | -------------------------------------------------------------------------------- /Archilizer_Warchart.addin: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Archilizer_Warchart 5 | Warning Chart - creates a pie chart which dynamically updates and displays project Warnings. 6 | Archilizer_Warchart.dll 7 | WC.App 8 | a4e78d1d-7a56-479d-9664-15d56d7e5a73 9 | archilizer.com 10 | Deyan Nenov, Archilizer 11 | 12 | 13 | -------------------------------------------------------------------------------- /Command.cs: -------------------------------------------------------------------------------- 1 | #region Namespaces 2 | using System; 3 | using Autodesk.Revit.Attributes; 4 | using Autodesk.Revit.DB; 5 | using Autodesk.Revit.UI; 6 | #endregion 7 | 8 | namespace WC 9 | { 10 | [Transaction(TransactionMode.Manual)] 11 | public class CommandWarningChart : IExternalCommand 12 | { 13 | public static string global_message; 14 | 15 | public Result Execute( 16 | ExternalCommandData commandData, 17 | ref string message, 18 | ElementSet elements) 19 | { 20 | try 21 | { 22 | App.thisApp.ShowForm(commandData.Application); 23 | return Result.Succeeded; 24 | } 25 | catch (Exception ex) 26 | { 27 | message += global_message; 28 | message = ex.Message; 29 | return Result.Failed; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Helpers/BitmapIcons.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.UI; 2 | using System; 3 | using System.Diagnostics; 4 | using System.Drawing; 5 | using System.Reflection; 6 | using System.Windows.Forms; 7 | using System.Windows.Media.Imaging; 8 | 9 | namespace WC.Helpers 10 | { 11 | public class BitmapIcons 12 | { 13 | public enum IconSize 14 | { 15 | ICON_SMALL = 16, 16 | ICON_MEDIUM = 24, 17 | ICON_LARGE = 32 18 | } 19 | 20 | public const int DEFAULT_DPI = 96; 21 | 22 | /// 23 | /// The Window Handle of the host process 24 | /// 25 | private static IntPtr _hWndRevit; 26 | /// 27 | /// Revit Verson 28 | /// 29 | public int Version { get; set; } 30 | /// 31 | /// The Revit Application 32 | /// 33 | public UIControlledApplication Application { get; set; } 34 | /// 35 | /// The image location in the Resource folder of the Assembly 36 | /// 37 | public string IconFilePath { get; set; } 38 | /// 39 | /// This Assembly, used to get the bitmap stream 40 | /// 41 | private Assembly loadedAssembly { get; set; } 42 | 43 | /// 44 | /// Public constructor 45 | /// 46 | /// This assembly, used to retrieve the resource images 47 | /// The image path it the resource folder. Remember, it needs to be Embedded Resource 48 | /// The Revit Application 49 | public BitmapIcons(Assembly loadedAssembly, string imageFile, UIControlledApplication app) 50 | { 51 | this.IconFilePath = imageFile; 52 | this.Application = app; 53 | this.Version = Int32.Parse(app.ControlledApplication.VersionNumber); 54 | this.loadedAssembly = loadedAssembly; 55 | if (this.Version < 2019) 56 | { 57 | GetHandle18(); 58 | } 59 | else 60 | { 61 | GetHandle19(); 62 | } 63 | } 64 | /// 65 | /// Warns if the image is too large 66 | /// 67 | private void CheckIconSize() 68 | { 69 | var image = Image.FromFile(IconFilePath); 70 | var imageSize = Math.Max(image.Width, image.Height); 71 | if (imageSize > 96) 72 | { 73 | string warning = "Icon file is too large"; 74 | } 75 | } 76 | /// 77 | /// Get Windows handle of the host process 78 | /// 79 | private void GetHandle18() 80 | { 81 | if (null == _hWndRevit) 82 | { 83 | Process process 84 | = Process.GetCurrentProcess(); 85 | 86 | IntPtr h = process.MainWindowHandle; 87 | _hWndRevit = new WindowHandle(h).Handle; 88 | } 89 | } 90 | private void GetHandle19() 91 | { 92 | if (null == _hWndRevit) 93 | { 94 | _hWndRevit = Application.MainWindowHandle; 95 | } 96 | } 97 | /// 98 | /// Resample image and creates bitmap or the given size. 99 | /// Produces crispiest icons of all times 100 | /// Icons are assumed to be square 101 | /// Courtesey to pyRevit 102 | /// 103 | /// IconSize (int): icon size (width and height) 104 | /// Imaging.BitmapSource: object containing image data at given size 105 | private BitmapSource CreateBitmap(IconSize size) 106 | { 107 | using (var stream = loadedAssembly.GetManifestResourceStream(IconFilePath)) 108 | { 109 | var bitmapImage = new Bitmap(stream); 110 | var adjustedIconSize = (int)size * 2; 111 | var adjustedDPI = DEFAULT_DPI * 2; 112 | var screenScaling = ProcessScreenScalefactor(); 113 | 114 | stream.Seek(0, System.IO.SeekOrigin.Begin); 115 | BitmapImage baseImage = new BitmapImage(); 116 | baseImage.BeginInit(); 117 | baseImage.StreamSource = stream; 118 | //baseImage.StreamSource = fileStream; 119 | baseImage.DecodePixelHeight = Convert.ToInt32(adjustedIconSize * screenScaling); 120 | baseImage.EndInit(); 121 | stream.Seek(0, System.IO.SeekOrigin.Begin); 122 | 123 | var imageSize = baseImage.PixelWidth; 124 | var imageFormat = baseImage.Format; 125 | var imageBytePerPixel = baseImage.Format.BitsPerPixel / 8; 126 | var palette = baseImage.Palette; 127 | 128 | var stride = imageSize * imageBytePerPixel; 129 | var arraySize = stride * imageSize; 130 | var imageData = Array.CreateInstance(typeof(Byte), arraySize); 131 | baseImage.CopyPixels(imageData, stride, 0); 132 | 133 | var bitmapSource = BitmapSource.Create( 134 | Convert.ToInt32(adjustedIconSize * screenScaling), 135 | Convert.ToInt32(adjustedIconSize * screenScaling), 136 | adjustedDPI * screenScaling, 137 | adjustedDPI * screenScaling, 138 | imageFormat, 139 | palette, 140 | imageData, 141 | stride); 142 | 143 | return bitmapSource; 144 | } 145 | } 146 | /// 147 | /// Takes into account the user screen settings in order to create a proper scale ratio for the image icon 148 | /// 149 | /// Scale Factor (double): the scale factor to be multiplied by. 150 | private double ProcessScreenScalefactor() 151 | { 152 | Screen screen = Screen.FromHandle(_hWndRevit); 153 | if(screen != null) 154 | { 155 | var actualWidth = System.Windows.SystemParameters.PrimaryScreenWidth; 156 | var scaledWidth = Screen.PrimaryScreen.WorkingArea.Width; 157 | return Math.Abs(scaledWidth / actualWidth); 158 | } 159 | return 1.0; 160 | } 161 | 162 | public BitmapSource SmallBitmap() 163 | { 164 | return this.CreateBitmap(IconSize.ICON_SMALL); 165 | } 166 | public BitmapSource MediumBitmap() 167 | { 168 | return this.CreateBitmap(IconSize.ICON_MEDIUM); 169 | } 170 | public BitmapSource LargeBitmap() 171 | { 172 | return this.CreateBitmap(IconSize.ICON_LARGE); 173 | } 174 | } 175 | } 176 | 177 | /// 178 | /// Retrieve Revit Windows thread in order to pass it to the form as it's owner 179 | /// 180 | public class WindowHandle : IWin32Window 181 | { 182 | IntPtr _hwnd; 183 | 184 | public WindowHandle(IntPtr h) 185 | { 186 | Debug.Assert(IntPtr.Zero != h, 187 | "expected non-null window handle"); 188 | 189 | _hwnd = h; 190 | } 191 | 192 | public IntPtr Handle 193 | { 194 | get 195 | { 196 | return _hwnd; 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Deyan Nenov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PackageContents.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WC.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.13.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.UserScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("0,0,0,0")] 29 | public global::System.Windows.Rect WindowPosition { 30 | get { 31 | return ((global::System.Windows.Rect)(this["WindowPosition"])); 32 | } 33 | set { 34 | this["WindowPosition"] = value; 35 | } 36 | } 37 | 38 | [global::System.Configuration.UserScopedSettingAttribute()] 39 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 40 | [global::System.Configuration.DefaultSettingValueAttribute("2000")] 41 | public int WarningNumber { 42 | get { 43 | return ((int)(this["WarningNumber"])); 44 | } 45 | set { 46 | this["WarningNumber"] = value; 47 | } 48 | } 49 | 50 | [global::System.Configuration.UserScopedSettingAttribute()] 51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 52 | [global::System.Configuration.DefaultSettingValueAttribute("1")] 53 | public int IsCheckedState { 54 | get { 55 | return ((int)(this["IsCheckedState"])); 56 | } 57 | set { 58 | this["IsCheckedState"] = value; 59 | } 60 | } 61 | 62 | [global::System.Configuration.UserScopedSettingAttribute()] 63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 64 | [global::System.Configuration.DefaultSettingValueAttribute("200")] 65 | public double LegendWidth { 66 | get { 67 | return ((double)(this["LegendWidth"])); 68 | } 69 | set { 70 | this["LegendWidth"] = value; 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 0,0,0,0 7 | 8 | 9 | 2000 10 | 11 | 12 | 1 13 | 14 | 15 | 200 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Warchart 2 | ============ 3 | 4 | ![Screenshot](http://www.archilizer.com/wp-content/uploads/2018/07/Archilizer_Warchart_200.png) 5 | 6 | 7 | Warchart stands for Warnings (Pie) Chart. Warchart is a visual interactive tool that helps you navigate, isolate and ultimately eliminate Autodesk® Revit® Warnings. The real-time update of the chart will follow your progress and give you immediate feedback. 8 | 9 | ## Official Download Link: 10 | 11 | You can download the current version of Warchart for Revit. 12 | 13 | https://apps.autodesk.com/RVT/en/Detail/Index?id=5069841371205448504&appLang=en&os=Win64 14 | 15 | ## Website 16 | 17 | For more information visit Archilizer website: 18 | 19 | http://www.archilizer.com/release/warchart/ 20 | 21 | A few examples: 22 | 23 | 24 | 25 | 26 | License 27 | ============ 28 | 29 | Copyright (c) 2018-present, Deyan Nenov, Archilizer 30 | 31 | MIT, see [LICENSE.md](https://github.com/2adicted/WarningChart/blob/master/LICENSE) for details. 32 | -------------------------------------------------------------------------------- /Resources/Theme.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 72 | 147 | -------------------------------------------------------------------------------- /Resources/archilizer_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnenov/WarningChart/ca284ccec5090ac41d6b99a3b7c4e97397a4adea/Resources/archilizer_default.png -------------------------------------------------------------------------------- /Resources/archilizer_warchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnenov/WarningChart/ca284ccec5090ac41d6b99a3b7c4e97397a4adea/Resources/archilizer_warchart.png -------------------------------------------------------------------------------- /Resources/icon_Warchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnenov/WarningChart/ca284ccec5090ac41d6b99a3b7c4e97397a4adea/Resources/icon_Warchart.png -------------------------------------------------------------------------------- /Resources/store icon/Warchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnenov/WarningChart/ca284ccec5090ac41d6b99a3b7c4e97397a4adea/Resources/store icon/Warchart.png -------------------------------------------------------------------------------- /Resources/warchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnenov/WarningChart/ca284ccec5090ac41d6b99a3b7c4e97397a4adea/Resources/warchart.png -------------------------------------------------------------------------------- /Utility/Request.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | // 3 | // (C) Copyright 2003-2014 by Autodesk, Inc. 4 | // 5 | // Permission to use, copy, modify, and distribute this software in 6 | // object code form for any purpose and without fee is hereby granted, 7 | // provided that the above copyright notice appears in all copies and 8 | // that both that copyright notice and the limited warranty and 9 | // restricted rights notice below appear in all supporting 10 | // documentation. 11 | // 12 | // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 13 | // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 14 | // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. 15 | // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 16 | // UNINTERRUPTED OR ERROR FREE. 17 | // 18 | // Use, duplication, or disclosure by the U.S. Government is subject to 19 | // restrictions set forth in FAR 52.227-19 (Commercial Computer 20 | // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 21 | // (Rights in Technical Data and Computer Software), as applicable. 22 | // 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Threading; 26 | 27 | namespace WC 28 | { 29 | /// 30 | /// A list of requests the dialog has available 31 | /// 32 | /// 33 | public enum RequestId : int 34 | { 35 | /// 36 | /// None 37 | /// 38 | None = 0, 39 | /// 40 | /// "Select Warnings" request 41 | /// 42 | SelectWarnings = 1, 43 | } 44 | 45 | /// 46 | /// A class around a variable holding the current request. 47 | /// 48 | /// 49 | /// Access to it is made thread-safe, even though we don't necessarily 50 | /// need it if we always disable the dialog between individual requests. 51 | /// 52 | /// 53 | public class Request 54 | { 55 | // Storing the value as a plain Int makes using the interlocking mechanism simpler 56 | private int m_request = (int)RequestId.None; 57 | // try tp tramsport information 58 | private List> ids; 59 | /// 60 | /// Take - The Idling handler calls this to obtain the latest request. 61 | /// 62 | /// 63 | /// This is not a getter! It takes the request and replaces it 64 | /// with 'None' to indicate that the request has been "passed on". 65 | /// 66 | /// 67 | public RequestId Take() 68 | { 69 | return (RequestId)Interlocked.Exchange(ref m_request, (int)RequestId.None); 70 | } 71 | /// 72 | /// Make - The Dialog calls this when the user presses a command button there. 73 | /// 74 | /// 75 | /// It replaces any older request previously made. 76 | /// 77 | /// 78 | public void Make(RequestId request) 79 | { 80 | Interlocked.Exchange(ref m_request, (int)request); 81 | } 82 | // try to trasport the message 83 | internal void SelectWarnings(List> ids) 84 | { 85 | this.ids = ids; 86 | } 87 | // try to transport the message 88 | internal List> GetIDs() 89 | { 90 | return this.ids; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Utility/RequestHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Autodesk.Revit.DB; 7 | using Autodesk.Revit.UI; 8 | 9 | namespace WC 10 | { 11 | /// 12 | /// A class with methods to execute requests made by the dialog user. 13 | /// 14 | /// 15 | public class RequestHandler : IExternalEventHandler 16 | { 17 | // delegate that will expect a family parameter to act upon 18 | private delegate void FamilyOperation(FamilyManager fm, FamilyParameter fp); 19 | // The value of the latest request made by the modeless form 20 | private Request m_request = new Request(); 21 | 22 | /// 23 | /// A public property to access the current request value 24 | /// 25 | public Request Request 26 | { 27 | get { return m_request; } 28 | } 29 | 30 | /// 31 | /// A method to identify this External Event Handler 32 | /// 33 | public String GetName() 34 | { 35 | return "Warning Chart"; 36 | } 37 | 38 | public void Execute(UIApplication uiapp) 39 | { 40 | try 41 | { 42 | switch (Request.Take()) 43 | { 44 | case RequestId.None: 45 | { 46 | return; 47 | } 48 | case RequestId.SelectWarnings: 49 | { 50 | ExecuteMakeSelection(uiapp, "Select Warnings", Request.GetIDs()); 51 | break; 52 | } 53 | default: 54 | { 55 | break; 56 | } 57 | } 58 | } 59 | finally 60 | { 61 | //App.thisApp.WakeFormUp(); 62 | } 63 | 64 | return; 65 | } 66 | /// 67 | /// Executes on restore all values 68 | /// 69 | /// 70 | /// 71 | /// 72 | private void ExecuteMakeSelection(UIApplication uiapp, String text, List> ids) 73 | { 74 | UIDocument uidoc = uiapp.ActiveUIDocument; 75 | Document doc = uidoc.Document; 76 | 77 | if (doc.IsFamilyDocument) 78 | { 79 | CommandWarningChart.global_message = 80 | "Please run this command in a normal document."; 81 | TaskDialog.Show("Message", CommandWarningChart.global_message); 82 | } 83 | 84 | if ((uidoc != null)) 85 | { 86 | List idsToSelect = new List(); 87 | 88 | foreach (var warning in ids) 89 | { 90 | foreach(var id in warning) 91 | { 92 | idsToSelect.Add(id); 93 | } 94 | } 95 | 96 | try 97 | { 98 | using (Transaction trans = new Transaction(uidoc.Document)) 99 | { 100 | if (trans.Start(text) == TransactionStatus.Started) 101 | { 102 | uidoc.Selection.SetElementIds(idsToSelect); 103 | doc.Regenerate(); 104 | trans.Commit(); 105 | uidoc.RefreshActiveView(); 106 | } 107 | } 108 | } 109 | catch (Exception) { } 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Utility/Utils.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Threading.Tasks; 8 | using WC.WarningChartWPF; 9 | 10 | namespace WC 11 | { 12 | public static class Utils 13 | { 14 | internal static Tuple, List, List> FindChange(List previousWarningModels, List warningModels) 15 | { 16 | if(previousWarningModels == null) 17 | { 18 | return null; 19 | } 20 | else 21 | { 22 | // new warnings 23 | var newWarning = warningModels.Where(x => !previousWarningModels.Any(y => y.Name == x.Name)).ToList(); 24 | 25 | // no longer exist warnings 26 | var deletedWarnings = previousWarningModels.Where(x => !warningModels.Any(y => y.Name == x.Name)).ToList(); 27 | 28 | // changed warnings (few warnings have been added or removed) 29 | var changedWarnings = warningModels.Where(x => !previousWarningModels.Any(y => y.ID == x.ID)).Except(newWarning).ToList(); 30 | 31 | return (Tuple.Create(newWarning, deletedWarnings, changedWarnings)); 32 | } 33 | } 34 | 35 | /// 36 | /// truncate string and add '..' at the end 37 | /// 38 | /// 39 | /// 40 | public static string Truncate(string source, int length) 41 | { 42 | if (source.Length > length) 43 | { 44 | source = source.Substring(0, length); 45 | return source + ".."; 46 | } 47 | else 48 | { 49 | return source; 50 | } 51 | } 52 | /// 53 | /// Check if a string contains unallowed characters 54 | /// 55 | /// 56 | /// 57 | internal static bool UnallowedChacarcters(string text) 58 | { 59 | var regexItem = new Regex("^[a-zA-Z0-9 _!-]+$"); 60 | bool result = regexItem.IsMatch(text); 61 | return(result ? true : false); 62 | } 63 | /// 64 | /// Check if it's a Family Document 65 | /// 66 | /// 67 | /// 68 | internal static Autodesk.Revit.DB.Document checkDoc(Autodesk.Revit.DB.Document document) 69 | { 70 | if (document.IsFamilyDocument) 71 | { 72 | return document; 73 | } 74 | else 75 | { 76 | return null; 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Utility/WCModelComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using WC.WarningChartWPF; 3 | 4 | namespace WC 5 | { 6 | internal class WCModelComparer : IEqualityComparer 7 | { 8 | public int GetHashCode(WarningChartModel co) 9 | { 10 | if (co == null) 11 | { 12 | return 0; 13 | } 14 | return co.Number.GetHashCode(); 15 | } 16 | 17 | public bool Equals(WarningChartModel x1, WarningChartModel x2) 18 | { 19 | if (object.ReferenceEquals(x1, x2)) 20 | { 21 | return true; 22 | } 23 | if (object.ReferenceEquals(x1, null) || 24 | object.ReferenceEquals(x2, null)) 25 | { 26 | return false; 27 | } 28 | return x1.Number == x2.Number; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /WarningChart.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net8.0-windows7.0 4 | Library 5 | WC 6 | Archilizer_Warchart 7 | false 8 | true 9 | true 10 | true 11 | 12 | 13 | bin\Debug\Archilizer_Warchart.bundle\ 14 | Program 15 | $(ProgramW6432)\Autodesk\Revit 2025\Revit.exe 16 | x64 17 | 18 | 19 | Program 20 | $(ProgramW6432)\Autodesk\Revit 2025\Revit.exe 21 | 22 | 23 | archilizer.ico 24 | 25 | 26 | NU1701 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | ..\..\..\..\..\Program Files\Autodesk\Revit 2026\RevitAPI.dll 182 | False 183 | 184 | 185 | ..\..\..\..\..\Program Files\Autodesk\Revit 2026\RevitAPIUI.dll 186 | False 187 | 188 | 189 | 190 | 191 | True 192 | True 193 | Settings.settings 194 | 195 | 196 | 197 | 198 | SettingsSingleFileGenerator 199 | Settings.Designer.cs 200 | 201 | 202 | 203 | 204 | copy "$(MSBuildProjectDirectory)\Archilizer_Warchart.addin" "C:\ProgramData\Autodesk\ApplicationPlugins\Archilizer_Warchart_2025.bundle\Content\windows" 205 | copy "$(MSBuildProjectDirectory)\PackageContents.xml" "C:\ProgramData\Autodesk\ApplicationPlugins\Archilizer_Warchart_2025.bundle" 206 | copy "$(MSBuildProjectDirectory)\bin\Debug\Archilizer_Warchart.bundle\net8.0-windows7.0\*.*" "C:\ProgramData\Autodesk\ApplicationPlugins\Archilizer_Warchart_2025.bundle\Content\windows" 207 | 208 | 209 | if not exist "C:\ProgramData\Autodesk\ApplicationPlugins\Archilizer_Warchart_2025.bundle\Content\windows" mkdir "C:\ProgramData\Autodesk\ApplicationPlugins\Archilizer_Warchart_2025.bundle\Content\windows" 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | -------------------------------------------------------------------------------- /WarningChart.csproj.SdkResolver.1981936763.proj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | C:\Program Files\dotnet\dotnet.exe 5 | 9.0.2 6 | 7 | -------------------------------------------------------------------------------- /WarningChart.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | C:\Program Files\Autodesk\Revit 2025\Revit.exe 5 | 6 | 7 | ProjectFiles 8 | 9 | 10 | 11 | Code 12 | 13 | 14 | Code 15 | 16 | 17 | -------------------------------------------------------------------------------- /WarningChart.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2035 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarningChart", "WarningChart.csproj", "{A049B200-9AD0-4D05-BE24-0D3173B7715E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {A049B200-9AD0-4D05-BE24-0D3173B7715E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {A049B200-9AD0-4D05-BE24-0D3173B7715E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {A049B200-9AD0-4D05-BE24-0D3173B7715E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {A049B200-9AD0-4D05-BE24-0D3173B7715E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {25573238-C59B-4BD7-894F-1D1751159BCB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WarningChartWPF/CustomLegend.xaml: -------------------------------------------------------------------------------- 1 |  15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 38 | 39 | 40 | 41 | 46 | 47 | 52 | 53 | 54 | 55 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /WarningChartWPF/CustomLegend.xaml.cs: -------------------------------------------------------------------------------- 1 | using LiveChartsCore; 2 | using LiveChartsCore.Kernel.Sketches; 3 | using LiveChartsCore.SkiaSharpView.Painting; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Collections.ObjectModel; 7 | using System.Globalization; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows; 12 | using System.Windows.Controls; 13 | using System.Windows.Data; 14 | using System.Windows.Documents; 15 | using System.Windows.Input; 16 | using System.Windows.Media; 17 | using System.Windows.Media.Imaging; 18 | using System.Windows.Navigation; 19 | using System.Windows.Shapes; 20 | 21 | namespace WC.WarningChartWPF 22 | { 23 | public class PaintToBrushConverter : IValueConverter 24 | { 25 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 26 | { 27 | if (value is SolidColorPaint paint) 28 | { 29 | var c = paint.Color; 30 | return new SolidColorBrush(Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue)); 31 | } 32 | 33 | return Brushes.Transparent; 34 | } 35 | 36 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => 37 | throw new NotImplementedException(); 38 | } 39 | 40 | public class SeriesToNumberConverter : IValueConverter 41 | { 42 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 43 | { 44 | if (value is ISeries series && 45 | series.Values is IEnumerable points) 46 | { 47 | return points.FirstOrDefault()?.Number ?? 0; 48 | } 49 | return 0; 50 | } 51 | 52 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => 53 | throw new NotImplementedException(); 54 | } 55 | 56 | /// 57 | /// Interaction logic for CustomLegend.xaml 58 | /// 59 | public partial class CustomLegend : UserControl 60 | { 61 | public event EventHandler LegendItemSelected; 62 | 63 | public CustomLegend() 64 | { 65 | InitializeComponent(); 66 | } 67 | 68 | public void Show(IEnumerable series) 69 | { 70 | DataContext = new { Series = series.ToList() }; 71 | } 72 | 73 | public void Hide() 74 | { 75 | DataContext = null; 76 | } 77 | 78 | private void LegendItem_Click(object sender, RoutedEventArgs e) 79 | { 80 | if (sender is Button button && button.DataContext is ISeries series) 81 | { 82 | var name = series.Name; 83 | LegendItemSelected?.Invoke(this, name); 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /WarningChartWPF/CustomTooltip.cs: -------------------------------------------------------------------------------- 1 | using LiveChartsCore.Drawing; 2 | using LiveChartsCore.Kernel.Sketches; 3 | using LiveChartsCore.Kernel; 4 | using LiveChartsCore.Measure; 5 | using LiveChartsCore.SkiaSharpView.Drawing.Geometries; 6 | using LiveChartsCore.SkiaSharpView.Drawing; 7 | using LiveChartsCore.SkiaSharpView.Painting; 8 | using LiveChartsCore.VisualElements; 9 | using LiveChartsCore; 10 | using SkiaSharp; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | using System.Text; 15 | using System.Threading.Tasks; 16 | using LiveChartsCore.SkiaSharpView.VisualElements; 17 | using System.Windows.Controls; 18 | 19 | namespace WC.WarningChartWPF 20 | { 21 | 22 | public class CustomTooltip : IChartTooltip 23 | { 24 | private StackPanel? _stackPanel; 25 | private static readonly int s_zIndex = 10100; 26 | private readonly SolidColorPaint _backgroundPaint = new(new SKColor(250, 250, 250)) { ZIndex = s_zIndex }; 27 | private readonly SolidColorPaint _fontPaint = new(new SKColor(40, 40, 40)) { ZIndex = s_zIndex + 1 }; 28 | 29 | public void Show(IEnumerable foundPoints, Chart chart) 30 | { 31 | if (_stackPanel is null) 32 | { 33 | _stackPanel = new StackPanel 34 | { 35 | Padding = new Padding(12), 36 | Orientation = ContainerOrientation.Vertical, 37 | HorizontalAlignment = Align.Start, 38 | VerticalAlignment = Align.Middle, 39 | BackgroundPaint = _backgroundPaint, 40 | }; 41 | 42 | _stackPanel 43 | .Animate( 44 | new Animation(EasingFunctions.BounceOut, TimeSpan.FromSeconds(1)), 45 | nameof(_stackPanel.X), 46 | nameof(_stackPanel.Y)); 47 | } 48 | 49 | // clear the previous elements. 50 | foreach (var child in _stackPanel.Children.ToArray()) 51 | { 52 | _ = _stackPanel.Children.Remove(child); 53 | chart.RemoveVisual(child); 54 | } 55 | 56 | foreach (var point in foundPoints) 57 | { 58 | var sketch = ((IChartSeries)point.Context.Series).GetMiniaturesSketch(); 59 | var relativePanel = sketch.AsDrawnControl(s_zIndex); 60 | var name = (point.Context.DataSource as WarningChartPoint)?.Name; 61 | 62 | var label = new LabelVisual 63 | { 64 | Text = point.Coordinate.PrimaryValue.ToString(), 65 | Paint = _fontPaint, 66 | TextSize = 15, 67 | Padding = new Padding(20, 0, 0, 0), 68 | ClippingMode = ClipMode.None, // required on tooltips 69 | VerticalAlignment = Align.Start, 70 | HorizontalAlignment = Align.Start 71 | }; 72 | 73 | var sp = new StackPanel 74 | { 75 | Padding = new Padding(8, 2), 76 | VerticalAlignment = Align.Middle, 77 | HorizontalAlignment = Align.Middle, 78 | Children = 79 | { 80 | relativePanel, 81 | label 82 | } 83 | }; 84 | 85 | var tb = new LabelVisual 86 | { 87 | Text = name, 88 | Paint = _fontPaint, 89 | TextSize = 13, 90 | Padding = new Padding(8, 10, 20, 0), 91 | ClippingMode = ClipMode.None, // required on tooltips 92 | VerticalAlignment = Align.Start, 93 | HorizontalAlignment = Align.Start, 94 | MaxWidth = 240, 95 | }; 96 | 97 | _stackPanel?.Children.Add(sp); 98 | _stackPanel?.Children.Add(tb); 99 | } 100 | 101 | var size = _stackPanel.Measure(chart); 102 | 103 | var location = foundPoints.GetTooltipLocation(size, chart); 104 | 105 | _stackPanel.X = location.X; 106 | _stackPanel.Y = location.Y; 107 | 108 | chart.AddVisual(_stackPanel); 109 | } 110 | 111 | public void Hide(Chart chart) 112 | { 113 | if (chart is null || _stackPanel is null) return; 114 | chart.RemoveVisual(_stackPanel); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /WarningChartWPF/MyResourceDictionary.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 40 | 136 | 137 | -------------------------------------------------------------------------------- /WarningChartWPF/WarChartView.xaml: -------------------------------------------------------------------------------- 1 |  27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 45 | 46 | 47 | 48 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 67 | 68 | 69 | 70 | 71 | 83 | 84 | 85 | 94 | 95 | 96 | 103 | 104 | 105 | 106 | 114 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 142 | 143 | 155 | 161 | 162 | 163 | 164 | 165 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /WarningChartWPF/WarChartView.xaml.cs: -------------------------------------------------------------------------------- 1 | using LiveChartsCore; 2 | using LiveChartsCore.Drawing; 3 | using LiveChartsCore.Kernel; 4 | using LiveChartsCore.Kernel.Sketches; 5 | using LiveChartsCore.SkiaSharpView; 6 | using LiveChartsCore.SkiaSharpView.Drawing; 7 | using LiveChartsCore.SkiaSharpView.Painting; 8 | using LiveChartsCore.SkiaSharpView.SKCharts; 9 | using LiveChartsCore.SkiaSharpView.WPF; 10 | using SkiaSharp; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Collections.ObjectModel; 14 | using System.ComponentModel; 15 | using System.Globalization; 16 | using System.Linq; 17 | using System.Runtime.Versioning; 18 | using System.Text; 19 | using System.Threading.Tasks; 20 | using System.Windows; 21 | using System.Windows.Controls; 22 | using System.Windows.Data; 23 | using System.Windows.Documents; 24 | using System.Windows.Input; 25 | using System.Windows.Media; 26 | using System.Windows.Media.Imaging; 27 | using System.Windows.Shapes; 28 | 29 | namespace WC.WarningChartWPF 30 | { 31 | 32 | /// 33 | /// Int to Color Converter 34 | /// 35 | public class IntToColorConverter : IValueConverter 36 | { 37 | private static GradientStopCollection grsc = new GradientStopCollection() 38 | { 39 | new GradientStop((Color)ColorConverter.ConvertFromString("#00EDF2F4"), 0), // mellow yellow 40 | new GradientStop((Color)ColorConverter.ConvertFromString("#EDF2F4"), 0.1), // mellow yellow 41 | new GradientStop((Color)ColorConverter.ConvertFromString("#FFCB21"), 0.5), // anti-flash white 42 | new GradientStop((Color)ColorConverter.ConvertFromString("#B21A00"), 0.9), //mordant red 19 43 | new GradientStop((Color)ColorConverter.ConvertFromString("#9E031E"), 1), //heidelberg red 44 | }; 45 | 46 | private static Color GetColorByOffset(GradientStopCollection collection, double offset) 47 | { 48 | GradientStop[] stops = collection.OrderBy(x => x.Offset).ToArray(); 49 | if (offset <= 0) return stops[0].Color; 50 | if (offset >= 1) return stops[stops.Length - 1].Color; 51 | GradientStop left = stops[0], right = null; 52 | foreach (GradientStop stop in stops) 53 | { 54 | if (stop.Offset >= offset) 55 | { 56 | right = stop; 57 | break; 58 | } 59 | left = stop; 60 | } 61 | offset = Math.Round((offset - left.Offset) / (right.Offset - left.Offset), 2); 62 | 63 | byte a = (byte)((right.Color.A - left.Color.A) * offset + left.Color.A); 64 | byte r = (byte)((right.Color.R - left.Color.R) * offset + left.Color.R); 65 | byte g = (byte)((right.Color.G - left.Color.G) * offset + left.Color.G); 66 | byte b = (byte)((right.Color.B - left.Color.B) * offset + left.Color.B); 67 | 68 | return Color.FromArgb(a, r, g, b); 69 | } 70 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 71 | { 72 | int val = System.Convert.ToInt32(value); 73 | 74 | var color = GetColorByOffset(grsc, Remap(val, 0, Properties.Settings.Default.WarningNumber, 0, 1)); 75 | 76 | return new SolidColorBrush(color); 77 | } 78 | public static float Remap(float value, float from1, float to1, float from2, float to2) 79 | { 80 | return (value - from1) / (to1 - from1) * (to2 - from2) + from2; 81 | } 82 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 83 | { 84 | throw new NotImplementedException(); 85 | } 86 | } 87 | 88 | /// 89 | /// Interaction logic for WarChartView.xaml 90 | /// 91 | [SupportedOSPlatform("windows7.0")] 92 | public partial class WarChartView : Window, INotifyPropertyChanged, IDisposable 93 | { 94 | public event Action SeriesSelectedEvent; 95 | public bool? IsCheckedState { get; private set; } 96 | public bool DocumentChanged { get; internal set; } 97 | public bool DocumentSwitched { get; internal set; } 98 | 99 | private List _warningModels; 100 | private List _previousWarningModels; 101 | private const int pushAmount = 12; 102 | 103 | private Tuple, List, List> _changes; 104 | 105 | public ObservableCollection Series { get; set; } 106 | 107 | private int _warningNumber; 108 | public int WarningNumber 109 | { 110 | get 111 | { 112 | return _warningNumber; 113 | } 114 | set 115 | { 116 | if (_warningNumber != value) 117 | { 118 | _warningNumber = value; 119 | OnPropertyChanged(nameof(WarningNumber)); 120 | } 121 | } 122 | } 123 | 124 | public List warningModels 125 | { 126 | get 127 | { 128 | return _warningModels; 129 | } 130 | set 131 | { 132 | _previousWarningModels = _warningModels; 133 | _warningModels = value; 134 | _changes = Utils.FindChange(_previousWarningModels, _warningModels); 135 | 136 | LoadSeries(); 137 | 138 | pieChart.DataPointerDown += PieChartOnDataPointerDown; 139 | 140 | 141 | // Hook up legend click handler 142 | legend.LegendItemSelected += (s, seriesName) => 143 | { 144 | SeriesSelectedEvent?.Invoke(seriesName); 145 | 146 | // Reset pushouts 147 | foreach (var series in Series) 148 | { 149 | if (series is PieSeries pie) 150 | pie.Pushout = 0; 151 | } 152 | 153 | // Apply pushout to selected 154 | var selectedSeries = Series.FirstOrDefault(x => x.Name == seriesName) as PieSeries; 155 | if (selectedSeries != null) 156 | { 157 | selectedSeries.Pushout = pushAmount; 158 | } 159 | }; 160 | } 161 | } 162 | 163 | private void PieChartOnDataPointerDown(IChartView chart, IEnumerable points) 164 | { 165 | var point = points.FirstOrDefault(); 166 | if (point == null) return; 167 | 168 | if (point.Context.DataSource is WarningChartPoint data) 169 | { 170 | // Do something with your data 171 | string name = data.Name; 172 | SeriesSelectedEvent?.Invoke(name); 173 | } 174 | 175 | // Reset pushouts 176 | foreach (var series in Series) 177 | { 178 | if (series is PieSeries pie) 179 | pie.Pushout = 0; 180 | } 181 | 182 | // Apply pushout to selected 183 | if (point.Context.Series is PieSeries selectedPie) 184 | { 185 | selectedPie.Pushout = pushAmount; 186 | } 187 | } 188 | 189 | public bool? intToBool(int i) 190 | { 191 | switch (i) 192 | { 193 | case 0: return null; 194 | case 1: return true; 195 | default: 196 | return false; 197 | } 198 | } 199 | 200 | public int boolToInt(bool? b) 201 | { 202 | switch (b) 203 | { 204 | case true: return 1; 205 | case false: return -1; 206 | default: 207 | return 0; 208 | } 209 | } 210 | 211 | /// 212 | /// Color library 213 | /// 214 | public static readonly SKColor[] CustomColors = new[] 215 | { 216 | SKColor.Parse("#FFCB21"), 217 | SKColor.Parse("#8D99AE"), 218 | SKColor.Parse("#EDF2F4"), 219 | SKColor.Parse("#EF233C"), 220 | SKColor.Parse("#9E031E"), 221 | SKColor.Parse("#FFDECA"), 222 | SKColor.Parse("#9891BA"), 223 | SKColor.Parse("#EFE2FF"), 224 | SKColor.Parse("#F93E18"), 225 | SKColor.Parse("#B21A00"), 226 | }; 227 | 228 | public WarChartView() 229 | { 230 | var initial = new WarningChartModel() { Name = "Initial", Number = 1, IDs = null }; 231 | var initialList = new List() { initial }; 232 | 233 | Series = GroupsByNumberOfWarnings(initialList); 234 | 235 | InitializeComponent(); 236 | 237 | this.Loaded += new RoutedEventHandler(MyWindow_Loaded); 238 | IsCheckedState = intToBool(Properties.Settings.Default.IsCheckedState); 239 | 240 | UpdateInterfaceLayout(); 241 | 242 | DataContext = this; 243 | } 244 | 245 | public void LoadSeries() 246 | { 247 | if (!DocumentChanged && !DocumentSwitched) 248 | { 249 | if (warningModels == null) return; 250 | 251 | // Only at the start 252 | Series = GroupsByNumberOfWarnings(warningModels); 253 | } 254 | else if (DocumentSwitched) 255 | { 256 | // When a different document is active 257 | DocumentSwitched = false; 258 | // Reset the popouts 259 | foreach (var series in Series) 260 | { 261 | if (series is PieSeries pie) 262 | { 263 | pie.Pushout = 0; // Reset push-out 264 | } 265 | } 266 | Series = GroupsByNumberOfWarnings(warningModels); 267 | } 268 | else if (DocumentChanged) 269 | { 270 | // When some of the warnings have changed 271 | DocumentChanged = false; 272 | // Reset the popouts 273 | foreach (var series in Series) 274 | { 275 | if (series is PieSeries pie) 276 | { 277 | pie.Pushout = 0; // Reset push-out 278 | } 279 | } 280 | // Item1 - New 281 | // Item2 - Deleted 282 | // Item3 - Changed 283 | if (_changes == null) return; 284 | if (_changes.Item1.Count > 0) 285 | { 286 | foreach (var item in GroupsByNumberOfWarnings(_changes.Item1)) 287 | { 288 | Series.Add(item); 289 | } 290 | } 291 | if (_changes.Item2.Count > 0) 292 | { 293 | foreach (var deleted in _changes.Item2) 294 | { 295 | var name = deleted.Name; 296 | var deletedSeries = Series.Cast>().First(x => x.Tag?.Equals(name) == true); //use Series Tag to identify ...? 297 | 298 | Series.Remove(deletedSeries); 299 | } 300 | } 301 | if (_changes.Item3.Count > 0) 302 | { 303 | foreach (var changed in _changes.Item3) 304 | { 305 | var name = changed.Name; 306 | var changedSeries = Series.Cast>().First(x => x.Tag?.Equals(name) == true); //use Series Tag to identify ...? 307 | 308 | if (changedSeries is PieSeries pie) 309 | { 310 | var color = pie.Fill; 311 | // do something with color 312 | Series.Remove(changedSeries); 313 | Series.Add(ChagnedSeries(changed, color)); 314 | } 315 | 316 | } 317 | } 318 | } 319 | 320 | OnPropertyChanged("Series"); 321 | } 322 | 323 | private static ObservableCollection GroupsByNumberOfWarnings(List content) 324 | { 325 | var series = new ObservableCollection(); 326 | if (!content.Any()) return series; 327 | 328 | var total = content.Sum(x => x.Number); 329 | var max = content.OrderByDescending(x => x.Number).First().Name; 330 | 331 | return new ObservableCollection( 332 | content 333 | .OrderByDescending(x => x.Number) 334 | .Select((x, i) => new PieSeries 335 | { 336 | Values = new[] { new WarningChartPoint { Number = x.Number, Title = x.Title, Name = x.Name } }, 337 | Name = x.Name, 338 | Mapping = (model, index) => new Coordinate(index, model.Number), 339 | Pushout = x.Name == max ? pushAmount : 0, 340 | Stroke = null, 341 | DataLabelsSize = 12, 342 | DataLabelsPaint = new SolidColorPaint(SKColors.Black), 343 | DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Middle, 344 | Fill = new SolidColorPaint(CustomColors[i % CustomColors.Length]), 345 | DataLabelsFormatter = point => 346 | { 347 | var value = point.Coordinate.PrimaryValue; 348 | var percent = value / total; 349 | return percent > 0.05 350 | ? string.Format("{0} {1} ({2:P})", value, Environment.NewLine, percent) 351 | : string.Empty; 352 | } 353 | }).ToArray() 354 | ); 355 | } 356 | 357 | private static PieSeries ChagnedSeries(WarningChartModel content, IPaint color) 358 | { 359 | return new PieSeries 360 | { 361 | Values = new[] 362 | { 363 | new WarningChartPoint 364 | { 365 | Number = content.Number, 366 | Title = content.Title, 367 | Name = content.Name 368 | } 369 | }, 370 | Mapping = (model, index) => new Coordinate(index, model.Number), 371 | Pushout = pushAmount, 372 | Tag = content.Name, 373 | Fill = color, 374 | Name = content.Title 375 | }; 376 | } 377 | 378 | // Drag window by clicking on any control 379 | private void Window_MouseDown(object sender, MouseButtonEventArgs e) 380 | { 381 | if (e.ChangedButton == MouseButton.Left) 382 | this.DragMove(); 383 | } 384 | 385 | private void SettingsButton_Click(object sender, RoutedEventArgs e) 386 | { 387 | WarningChartSettings settings = new WarningChartSettings(); 388 | if (settings.ShowDialog() == true) 389 | { 390 | //stupid update 391 | var holder = WarningNumber; 392 | WarningNumber = 0; 393 | WarningNumber = holder; 394 | } 395 | } 396 | 397 | // If there are no warnings in the current project 398 | // Collapse the Chart (and Legend) 399 | // And display a 'No Warning' sign ;) 400 | public bool NoProjectWarnings { get; private set; } 401 | 402 | internal void NoWarnings() 403 | { 404 | if (!NoProjectWarnings) 405 | { 406 | NoProjectWarnings = true; 407 | pieChart.Visibility = Visibility.Collapsed; 408 | legend.Visibility = Visibility.Collapsed; 409 | lblNoWarnings.Visibility = Visibility.Visible; 410 | btnToggle.IsEnabled = false; 411 | } 412 | } 413 | 414 | internal void YesWarnings() 415 | { 416 | if (NoProjectWarnings) 417 | { 418 | NoProjectWarnings = false; 419 | lblNoWarnings.Visibility = Visibility.Collapsed; 420 | btnToggle.IsEnabled = true; 421 | ResumeInterfaceLayout(); 422 | } 423 | } 424 | 425 | 426 | private void CloseButton_Click(object sender, RoutedEventArgs e) 427 | { 428 | SavePosition(); 429 | Close(); 430 | } 431 | 432 | private void CollapseButton_Click(object sender, RoutedEventArgs e) 433 | { 434 | Properties.Settings.Default.IsCheckedState = boolToInt(IsCheckedState); 435 | UpdateInterfaceLayout(); 436 | } 437 | 438 | #region Update Layout 439 | private void UpdateInterfaceLayout() 440 | { 441 | // cycle through the three states 442 | if (IsCheckedState == true) 443 | { 444 | // 1: show everything 445 | IsCheckedState = null; 446 | pieChart.Visibility = Visibility.Visible; 447 | legend.Visibility = Visibility.Visible; 448 | 449 | splitterColumn.Width = new GridLength(5); 450 | legendColumn.Width = GridLength.Auto; 451 | } 452 | else if (IsCheckedState == null) 453 | { 454 | // 2: hide legend 455 | IsCheckedState = false; 456 | pieChart.Visibility = Visibility.Visible; 457 | legend.Visibility = Visibility.Collapsed; 458 | 459 | splitterColumn.Width = new GridLength(0); 460 | legendColumn.Width = new GridLength(0); 461 | } 462 | else if (IsCheckedState == false) 463 | { 464 | // 3: hide chart 465 | IsCheckedState = true; 466 | pieChart.Visibility = Visibility.Collapsed; 467 | legend.Visibility = Visibility.Collapsed; 468 | 469 | splitterColumn.Width = new GridLength(0); 470 | legendColumn.Width = new GridLength(0); 471 | } 472 | } 473 | 474 | private void ResumeInterfaceLayout() 475 | { 476 | // cycle through the three states 477 | if (IsCheckedState == true) 478 | { 479 | // 1: show everything 480 | pieChart.Visibility = Visibility.Visible; 481 | legend.Visibility = Visibility.Visible; 482 | 483 | splitterColumn.Width = new GridLength(5); 484 | legendColumn.Width = GridLength.Auto; 485 | } 486 | else if (IsCheckedState == null) 487 | { 488 | // 2: hide legend 489 | pieChart.Visibility = Visibility.Visible; 490 | legend.Visibility = Visibility.Collapsed; 491 | 492 | splitterColumn.Width = new GridLength(0); 493 | legendColumn.Width = new GridLength(0); 494 | } 495 | else if (IsCheckedState == false) 496 | { 497 | // 3: hide chart 498 | pieChart.Visibility = Visibility.Visible; 499 | legend.Visibility = Visibility.Collapsed; 500 | 501 | splitterColumn.Width = new GridLength(0); 502 | legendColumn.Width = new GridLength(0); 503 | } 504 | } 505 | #endregion 506 | 507 | #region Location 508 | // On loaded, move the UI to the up-right corner 509 | // or load the previous position and size 510 | private void MyWindow_Loaded(object sender, RoutedEventArgs e) 511 | { 512 | this.WindowStartupLocation = WindowStartupLocation.Manual; 513 | double screenHeight = SystemParameters.FullPrimaryScreenHeight; 514 | double screenWidth = SystemParameters.FullPrimaryScreenWidth; 515 | this.Top = 160; 516 | this.Left = screenWidth - this.Width - 80; 517 | try 518 | { 519 | Rect bounds = Properties.Settings.Default.WindowPosition; 520 | if (bounds.Top != 0) 521 | { 522 | this.Top = bounds.Top; 523 | 524 | } 525 | if (bounds.Left != 0) 526 | { 527 | this.Left = bounds.Left; 528 | } 529 | // Restore the size only for a manually sized window. 530 | if (bounds.Width != 0 && bounds.Height != 0) 531 | { 532 | this.SizeToContent = SizeToContent.Manual; 533 | this.Width = bounds.Width; 534 | this.Height = bounds.Height; 535 | } 536 | 537 | // Set legend grid column width 538 | if (Properties.Settings.Default.LegendWidth != 0) 539 | { 540 | legendColumn.Width = new GridLength(Properties.Settings.Default.LegendWidth); 541 | } 542 | else 543 | { 544 | legendColumn.Width = new GridLength(200); 545 | } 546 | } 547 | catch 548 | { 549 | MessageBox.Show("No settings stored."); 550 | } 551 | } 552 | // Save the location of the UI (per user) 553 | private void SavePosition() 554 | { 555 | Properties.Settings.Default.WindowPosition = this.RestoreBounds; 556 | Properties.Settings.Default.LegendWidth = legendColumn.Width.Value; 557 | Properties.Settings.Default.Save(); 558 | } 559 | #endregion 560 | 561 | #region INotifyPropertyChanged implementation 562 | 563 | public event PropertyChangedEventHandler PropertyChanged; 564 | 565 | protected virtual void OnPropertyChanged(string propertyName) 566 | { 567 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 568 | } 569 | #endregion 570 | 571 | #region Dispose 572 | public void Dispose() 573 | { 574 | pieChart.DataPointerDown -= PieChartOnDataPointerDown; 575 | } 576 | #endregion 577 | } 578 | } 579 | 580 | -------------------------------------------------------------------------------- /WarningChartWPF/WarningChartModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Windows.Media; 5 | 6 | namespace WC.WarningChartWPF 7 | { 8 | class SingleRandom : Random 9 | { 10 | static SingleRandom _Instance; 11 | public static SingleRandom Instance 12 | { 13 | get 14 | { 15 | if (_Instance == null) _Instance = new SingleRandom(); 16 | return _Instance; 17 | } 18 | } 19 | 20 | private SingleRandom() { } 21 | } 22 | public static class BrushSwatch 23 | { 24 | static List brb = new List() 25 | { 26 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F2E273")), 27 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F2BC73")), 28 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CAF188")), 29 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#55F1AF")), 30 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#30F1BB")), 31 | 32 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#64F2B6")), 33 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#55F3C7")), 34 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#DDF6B3")), 35 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F6ECA5")), 36 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F6D4A5")), 37 | 38 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F2BC73")), 39 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F2E273")), 40 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CAF188")), 41 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#5BDCA6")), 42 | new SolidColorBrush((Color)ColorConverter.ConvertFromString("#C6FBEC")), 43 | }; 44 | 45 | public static Brush Get() 46 | { 47 | SingleRandom r = SingleRandom.Instance; 48 | 49 | return brb[r.Next(brb.Count)]; 50 | } 51 | } 52 | 53 | public class WarningChartModel : INotifyPropertyChanged 54 | { 55 | private string name; 56 | private string title; 57 | private int number; 58 | private List> ids; 59 | private Brush color; 60 | private string id; 61 | 62 | // The ID of the WarningModel 63 | public string ID 64 | { 65 | get 66 | { 67 | return id; 68 | } 69 | set 70 | { 71 | if (id != value) 72 | { 73 | id = value; 74 | RaisePropertyChanged("ID"); 75 | } 76 | } 77 | } 78 | //Name of the Warning 79 | public string Name 80 | { 81 | get 82 | { 83 | return name; 84 | } 85 | set 86 | { 87 | if(name != value) 88 | { 89 | name = value; 90 | Title = Utils.Truncate(value, 24); 91 | //Color = BrushSwatch.Get(); 92 | RaisePropertyChanged("Name"); 93 | } 94 | } 95 | } 96 | //Number of that Warning in the current Project 97 | public int Number 98 | { 99 | get 100 | { 101 | return number; 102 | } 103 | set 104 | { 105 | if(number != value) 106 | { 107 | number = value; 108 | RaisePropertyChanged("Number"); 109 | } 110 | } 111 | } 112 | //IDs associated with this Warning 113 | public List> IDs 114 | { 115 | get 116 | { 117 | return ids; 118 | } 119 | set 120 | { 121 | if(ids != value) 122 | { 123 | ids = value; 124 | RaisePropertyChanged("IDs"); 125 | } 126 | } 127 | } 128 | //The title is the trimmed version of the name (for legend use) 129 | public string Title 130 | { 131 | get 132 | { 133 | return title; 134 | } 135 | set 136 | { 137 | title = value; 138 | RaisePropertyChanged("Title"); 139 | } 140 | } 141 | //Create a color based on swatches 142 | public Brush Color 143 | { 144 | get 145 | { 146 | return color; 147 | } 148 | set 149 | { 150 | color = value; 151 | RaisePropertyChanged("Color"); 152 | } 153 | } 154 | 155 | public event PropertyChangedEventHandler PropertyChanged; 156 | 157 | private void RaisePropertyChanged(string property) 158 | { 159 | if (PropertyChanged != null) 160 | { 161 | PropertyChanged(this, new PropertyChangedEventArgs(property)); 162 | } 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /WarningChartWPF/WarningChartPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace WC.WarningChartWPF 8 | { 9 | public class WarningChartPoint 10 | { 11 | static WarningChartPoint() 12 | { 13 | //In this case we are plotting our own point to have 14 | //more control over the current plot 15 | //configuring a custom type is quite simple 16 | 17 | //first we define a mapper 18 | //var mapper = Mappers.Pie() 19 | // .Value(x => x.Number);//use the value property in the plot 20 | 21 | ////then we save the mapper globally, there are many ways 22 | ////so configure a series, for more info see: 23 | ////https://lvcharts.net/App/examples/v1/wpf/Types%20and%20Configuration 24 | //Charting.For(mapper); 25 | } 26 | 27 | /// 28 | /// Gets or sets the value to plot 29 | /// 30 | /// 31 | /// The value. 32 | /// 33 | public double Value 34 | { 35 | get { return Number; } 36 | } 37 | 38 | /// 39 | /// Gets or sets the content, all the values that represent this point 40 | /// 41 | /// 42 | /// The content. 43 | /// 44 | public int Number { get; set; } 45 | 46 | /// 47 | /// Gets or sets the title. 48 | /// 49 | /// 50 | /// The title. 51 | /// 52 | public string Title { get; set; } 53 | 54 | /// 55 | /// Gets or sets the full name of the warning 56 | /// 57 | public string Name { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WarningChartWPF/WarningChartPresenter.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using Autodesk.Revit.UI; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Input; 10 | using Autodesk.Revit.ApplicationServices; 11 | using System.Runtime.Versioning; 12 | using System.Runtime.InteropServices; 13 | 14 | namespace WC.WarningChartWPF 15 | { 16 | [SupportedOSPlatform("windows7.0")] 17 | public class WarningChartPresenter : IDisposable 18 | { 19 | private UIApplication uiapp; 20 | private Document doc; 21 | private List warnings; 22 | private List warningModels; 23 | private ExternalEvent exEvent; 24 | private RequestHandler handler; 25 | public WarChartView form; 26 | internal bool IsClosed; 27 | 28 | public UIApplication _Application 29 | { 30 | get 31 | { 32 | return uiapp; 33 | } 34 | set 35 | { 36 | if (uiapp != value) 37 | { 38 | uiapp = value; 39 | _Document = uiapp.ActiveUIDocument.Document; 40 | } 41 | } 42 | } 43 | 44 | public Document _Document 45 | { 46 | get 47 | { 48 | return doc; 49 | } 50 | set 51 | { 52 | if (doc != value) 53 | { 54 | doc = value; 55 | } 56 | } 57 | } 58 | 59 | public WarningChartPresenter(UIApplication uiapp, ExternalEvent exEvent, RequestHandler handler) 60 | { 61 | this._Application = uiapp; 62 | this.exEvent = exEvent; 63 | this.handler = handler; 64 | this.LoadData(); 65 | } 66 | 67 | private void LoadData() 68 | { 69 | //Get the list of Warnings in the Project 70 | this.warnings = new List(doc.GetWarnings()); 71 | 72 | //WOW!! Get the list of WarningModels 73 | this.warningModels = warnings.GroupBy(x => x.GetDescriptionText()) 74 | //.Where(g => g.Count() > 1) 75 | .Select(x => new WarningChartModel { Name = x.Key, Number = x.Count(), ID = x.Key + x.Count().ToString(), IDs = x.Select(y => y.GetFailingElements()).ToList() }).ToList(); 76 | } 77 | 78 | internal void DocumentChanged() 79 | { 80 | // Fetch the new warnings 81 | LoadData(); 82 | // Update the Form 83 | form.DocumentChanged = true; 84 | if (this.warningModels.Count == 0) 85 | { 86 | form.NoWarnings(); 87 | } 88 | else 89 | { 90 | form.YesWarnings(); 91 | form.warningModels = this.warningModels; 92 | } 93 | form.WarningNumber = this.warnings.Count; 94 | } 95 | 96 | internal void DocumentSwitched() 97 | { 98 | // Fetch the new warnings 99 | LoadData(); 100 | // Update the Form 101 | form.DocumentSwitched = true; 102 | if (this.warningModels.Count == 0) 103 | { 104 | form.NoWarnings(); 105 | } 106 | else 107 | { 108 | form.YesWarnings(); 109 | form.warningModels = this.warningModels; 110 | } 111 | form.WarningNumber = this.warnings.Count; 112 | } 113 | 114 | internal void Close() 115 | { 116 | form.Close(); 117 | 118 | IsClosed = true; 119 | } 120 | 121 | [SupportedOSPlatform("windows7.0")] 122 | internal void Show(WindowHandle hWndRevit) 123 | { 124 | form = new WarChartView(); 125 | System.Windows.Interop.WindowInteropHelper x = new System.Windows.Interop.WindowInteropHelper(form); 126 | x.Owner = hWndRevit.Handle; 127 | form.DocumentChanged = false; 128 | if (this.warningModels.Count == 0) 129 | { 130 | form.NoWarnings(); 131 | } 132 | else 133 | { 134 | form.YesWarnings(); 135 | form.warningModels = this.warningModels; 136 | form.WarningNumber = this.warnings.Count; 137 | } 138 | form.WarningNumber = this.warnings.Count; 139 | form.Closed += FormClosed; 140 | form.SeriesSelectedEvent += SeriesSelected; 141 | form.Show(); 142 | } 143 | 144 | // Notify that the System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.' Line number '72' and line pform is closed 145 | private void FormClosed(object sender, EventArgs e) 146 | { 147 | form.Dispose(); 148 | this.Dispose(); 149 | } 150 | 151 | private void SeriesSelected(string name) 152 | { 153 | try 154 | { 155 | MakeRequest(RequestId.SelectWarnings, warningModels.First(x => x.Name.Equals(name)).IDs); 156 | } 157 | catch (Exception ex) 158 | { 159 | // 160 | } 161 | } 162 | private void MakeRequest(RequestId request, List> ids) 163 | { 164 | //MessageBox.Show("You are in the Control.Request event."); 165 | handler.Request.SelectWarnings(ids); 166 | handler.Request.Make(request); 167 | exEvent.Raise(); 168 | } 169 | 170 | public void Dispose() 171 | { 172 | // Revit handler stuff 173 | exEvent.Dispose(); 174 | exEvent = null; 175 | handler = null; 176 | // This form is closed 177 | IsClosed = true; 178 | // Remove registered events 179 | form.Closed -= FormClosed; 180 | form.SeriesSelectedEvent -= SeriesSelected; 181 | } 182 | 183 | internal void Disable() 184 | { 185 | form.IsEnabled = false; 186 | form.Visibility = System.Windows.Visibility.Hidden; 187 | } 188 | 189 | internal void Enable() 190 | { 191 | form.IsEnabled = true; 192 | form.Visibility = System.Windows.Visibility.Visible; 193 | } 194 | 195 | 196 | [DllImport("user32.dll")] 197 | private static extern bool SetProcessDPIAware(); 198 | } 199 | 200 | public class DelegateCommand : ICommand 201 | { 202 | private readonly Action _action; 203 | 204 | public DelegateCommand(Action action) 205 | { 206 | _action = action; 207 | } 208 | 209 | public void Execute(object parameter) 210 | { 211 | _action(); 212 | } 213 | 214 | public bool CanExecute(object parameter) 215 | { 216 | return true; 217 | } 218 | 219 | #pragma warning disable 67 220 | public event EventHandler CanExecuteChanged { add { } remove { } } 221 | #pragma warning restore 67 222 | } 223 | 224 | public abstract class ObservableObject : INotifyPropertyChanged 225 | { 226 | public event PropertyChangedEventHandler PropertyChanged; 227 | 228 | protected void RaisePropertyChangedEvent(string propertyName) 229 | { 230 | var handler = PropertyChanged; 231 | if (handler != null) 232 | handler(this, new PropertyChangedEventArgs(propertyName)); 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /WarningChartWPF/WarningChartSettings.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Answer 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /WarningChartWPF/WarningChartSettings.xaml.cs: -------------------------------------------------------------------------------- 1 | using MaterialDesignColors; 2 | using MaterialDesignThemes.Wpf; 3 | using System; 4 | using System.Text.RegularExpressions; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Media; 8 | 9 | namespace WC.WarningChartWPF 10 | { 11 | /// 12 | /// Interaction logic for WarningChartSettings.xaml 13 | /// 14 | public partial class WarningChartSettings : Window 15 | { 16 | public WarningChartSettings() 17 | { 18 | InitializeComponent(); 19 | 20 | txtAnswer.Text = Properties.Settings.Default.WarningNumber.ToString(); 21 | } 22 | 23 | private void btnDialogOk_Click(object sender, RoutedEventArgs e) 24 | { 25 | string result = txtAnswer.Text; 26 | if(result.Equals("") || !IsTextAllowed(result)) 27 | { 28 | this.DialogResult = false; 29 | } 30 | else 31 | { 32 | Properties.Settings.Default.WarningNumber = Int32.Parse(txtAnswer.Text); 33 | this.DialogResult = true; 34 | } 35 | } 36 | 37 | private void Window_ContentRendered(object sender, EventArgs e) 38 | { 39 | txtAnswer.SelectAll(); 40 | txtAnswer.Focus(); 41 | } 42 | // Check if the input text matches the Regex 43 | private void txtAnswer_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) 44 | { 45 | TextBox box = sender as TextBox; 46 | if(box.SelectionLength > 0) 47 | { 48 | e.Handled = !IsTextAllowed(e.Text); 49 | }else 50 | { 51 | e.Handled = !IsTextAllowed(((TextBox)sender).Text + e.Text); 52 | } 53 | } 54 | // Checks the input against the Regex (only positive integers) 55 | private static bool IsTextAllowed(string text) 56 | { 57 | int result = 0; 58 | if (Int32.TryParse(text, out result)) 59 | { 60 | // Your conditions 61 | if (result > 0 && result < 100000) 62 | { 63 | return true; 64 | } 65 | } 66 | return false; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /WarningChartWPF/WarningChartView.xaml: -------------------------------------------------------------------------------- 1 |  21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 71 | 72 | 75 | 76 | 79 | 80 | 85 | 86 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /WarningChartWPF/WarningChartView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Windows; 6 | using System.Windows.Input; 7 | using System.Windows.Media; 8 | using LiveChartsCore; 9 | using LiveChartsCore.SkiaSharpView; 10 | using LiveChartsCore.SkiaSharpView.WPF; 11 | using SkiaSharp; 12 | using System.Collections.ObjectModel; 13 | using System.Windows.Data; 14 | using System.Globalization; 15 | using System.Windows.Controls; 16 | using MaterialDesignThemes.Wpf; 17 | using MaterialDesignColors; 18 | using LiveChartsCore.SkiaSharpView.Painting; 19 | 20 | namespace WC.WarningChartWPF 21 | { 22 | /// 23 | /// Interaction logic for WarningChartView.xaml 24 | /// 25 | public partial class WarningChartView : Window, INotifyPropertyChanged 26 | { 27 | /// 28 | /// Color library 29 | /// 30 | public static readonly SKColor[] CustomColors = new[] 31 | { 32 | SKColor.Parse("#FFCB21"), 33 | SKColor.Parse("#8D99AE"), 34 | SKColor.Parse("#EDF2F4"), 35 | SKColor.Parse("#EF233C"), 36 | SKColor.Parse("#9E031E"), 37 | SKColor.Parse("#FFDECA"), 38 | SKColor.Parse("#9891BA"), 39 | SKColor.Parse("#EFE2FF"), 40 | SKColor.Parse("#F93E18"), 41 | SKColor.Parse("#B21A00"), 42 | }; 43 | 44 | private List _warningModels; 45 | private List _previousWarningModels; 46 | private const int pushAmount = 12; 47 | private int _warningNumber; 48 | public event Action SeriesSelectedEvent; 49 | public bool DocumentChanged { get; internal set; } 50 | public bool DocumentSwitched { get; internal set; } 51 | public int WarningNumber 52 | { 53 | get 54 | { 55 | return _warningNumber; 56 | } 57 | set 58 | { 59 | if(_warningNumber != value) 60 | { 61 | _warningNumber = value; 62 | OnPropertyChanged("WarningNumber"); 63 | } 64 | } 65 | } 66 | public bool? IsCheckedState { get; private set; } 67 | 68 | //public static Func labelPoint = chartPoint => 69 | //chartPoint.Participation > 0.05 ? 70 | //string.Format("{0} {1} ({2:P})", chartPoint.Y, Environment.NewLine, chartPoint.Participation) 71 | //: ""; 72 | 73 | // The series that will be updated (Warnings) 74 | private ISeries[] _series; 75 | 76 | public ISeries[] Series 77 | { 78 | get => _series; 79 | set 80 | { 81 | _series = value; 82 | OnPropertyChanged(nameof(Series)); 83 | } 84 | } 85 | 86 | private Tuple, List, List> _changes; 87 | private ObservableCollection _test; 88 | public ObservableCollection Test 89 | { 90 | get { return _test; } 91 | set 92 | { 93 | if (value != _test) 94 | { 95 | _test = value; 96 | OnPropertyChanged("Name2"); 97 | } 98 | } 99 | } 100 | 101 | public WarningChartView() 102 | { 103 | var initial = new WarningChartModel() { Name = "Initial", Number = 1, IDs = null }; 104 | var initialList = new List() { initial }; 105 | //Series = GroupsByNumberOfWarnings(initialList); 106 | 107 | Test = new ObservableCollection(new string[] { "element1", "element2", "element3" }); 108 | 109 | //InitializeMaterialDesign(); 110 | InitializeComponent(); 111 | 112 | 113 | // Places the UI where it needs to go 114 | this.Loaded += new RoutedEventHandler(MyWindow_Loaded); 115 | //this.MyCustomLegend.StatusUpdated += new EventHandler(MyEventHandlerFunction_StatusUpdated); 116 | 117 | //IsCheckedState = intToBool(Properties.Settings.Default.IsCheckedState); 118 | 119 | //UpdateInterfaceLayout(); 120 | 121 | DataContext = this; 122 | } 123 | /*** 124 | private void InitializeMaterialDesign() 125 | { 126 | // Create dummy objects to force the MaterialDesign assemblies to be loaded 127 | // from this assembly, which causes the MaterialDesign assemblies to be searched 128 | // relative to this assembly's path. Otherwise, the MaterialDesign assemblies 129 | // are searched relative to Eclipse's path, so they're not found. 130 | var card = new Card(); 131 | var hue = new Hue("Dummy", Colors.Black, Colors.White); 132 | } 133 | public bool? intToBool(int i) 134 | { 135 | switch (i) 136 | { 137 | case 0: return null; 138 | case 1: return true; 139 | default: 140 | return false; 141 | } 142 | } 143 | 144 | public int boolToInt(bool? b) 145 | { 146 | switch (b) 147 | { 148 | case true: return 1; 149 | case false: return -1; 150 | default: 151 | return 0; 152 | } 153 | } 154 | 155 | private void MyEventHandlerFunction_StatusUpdated(object sender, EventArgs e) 156 | { 157 | ListBoxItem item = (e as RoutedEventArgs).Source as ListBoxItem; 158 | SeriesSelectedEvent((string)item.ToolTip); 159 | } 160 | 161 | private void LoadSeries() 162 | { 163 | if(!DocumentChanged && !DocumentSwitched) 164 | { 165 | // Only at the start 166 | Series = GroupsByNumberOfWarnings(warningModels); 167 | } 168 | else if(DocumentSwitched) 169 | { 170 | // When a different document is active 171 | DocumentSwitched = false; 172 | // Reset the popouts 173 | foreach (PieSeries series in Series) series.PushOut = 0; 174 | Series = GroupsByNumberOfWarnings(warningModels); 175 | } 176 | else if(DocumentChanged) 177 | { 178 | // When some of the warnings have changed 179 | DocumentChanged = false; 180 | // Reset the popouts 181 | foreach (PieSeries series in Series) series.PushOut = 0; 182 | // Item1 - New 183 | // Item2 - Deleted 184 | // Item3 - Changed 185 | if (_changes == null) return; 186 | if(_changes.Item1.Count > 0) 187 | { 188 | Series.AddRange(GroupsByNumberOfWarnings(_changes.Item1)); 189 | } 190 | if (_changes.Item2.Count > 0) 191 | { 192 | foreach (var deleted in _changes.Item2) 193 | { 194 | var name = deleted.Name; 195 | var deletedSeries = Series.Cast().First(x => x.Tag.Equals(name)); //use Series Tag to identify ...? 196 | 197 | Series.Remove(deletedSeries); 198 | } 199 | } 200 | if(_changes.Item3.Count > 0) 201 | { 202 | foreach (var changed in _changes.Item3) 203 | { 204 | var name = changed.Name; 205 | var changedSeries = Series.Cast().First(x => x.Tag.Equals(name)); //use Series Tag to identify ...? 206 | 207 | var color = ((PieSeries)changedSeries).Fill; 208 | 209 | Series.Remove(changedSeries); 210 | Series.Add(ChagnedSeries(changed, color)); 211 | } 212 | } 213 | } 214 | 215 | OnPropertyChanged("Series"); 216 | } 217 | 218 | private static PieSeries ChagnedSeries(WarningChartModel content, Brush color) 219 | { 220 | var series = new PieSeries 221 | { 222 | Values = new ChartValues 223 | { 224 | new WarningChartPoint {Number = content.Number, Title = content.Title, Name = content.Name } 225 | }, 226 | LabelPoint = labelPoint, 227 | PushOut = pushAmount, 228 | Tag = content.Name, 229 | Fill = color, 230 | Title = content.Title 231 | }; 232 | return series; 233 | } 234 | 235 | private static ISeries[] GroupsByNumberOfWarnings(List content) 236 | { 237 | var max = content.OrderByDescending(x => x.Number).First().Name; 238 | 239 | return content.Select(x => new PieSeries 240 | { 241 | Values = new[] { new WarningChartPoint { Number = x.Number, Title = x.Title, Name = x.Name } }, 242 | Name = x.Title, 243 | //Mapping = (wp, chartPoint) => 244 | //{ 245 | // chartPoint.PrimaryValue = wp.Number; 246 | // chartPoint.Label = wp.Title; 247 | //}, 248 | Pushout = x.Name == max ? 12 : 0, 249 | DataLabelsSize = 12, 250 | DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.ChartCenter, 251 | Fill = new SolidColorPaint(new SKColor(255, 203, 33)), 252 | //TooltipLabelFormatter = point => $"{point.Label}: {point.PrimaryValue}" 253 | }).ToArray(); 254 | } 255 | 256 | 257 | public List warningModels 258 | { 259 | get 260 | { 261 | return _warningModels; 262 | } 263 | set 264 | { 265 | _previousWarningModels = _warningModels; 266 | _warningModels = value; 267 | _changes = Utils.FindChange(_previousWarningModels, _warningModels); 268 | 269 | LoadSeries(); 270 | } 271 | } 272 | 273 | public bool NoProjectWarnings { get; private set; } 274 | 275 | // If there are no warnings in the current project 276 | // Collapse the Chart (and Legend) 277 | // And display a 'No Warning' sign ;) 278 | internal void NoWarnings() 279 | { 280 | if(!NoProjectWarnings) 281 | { 282 | NoProjectWarnings = true; 283 | pieChart.Visibility = Visibility.Collapsed; 284 | Legend.Visibility = Visibility.Collapsed; 285 | lblNoWarnings.Visibility = Visibility.Visible; 286 | btnToggle.IsEnabled = false; 287 | } 288 | } 289 | internal void YesWarnings() 290 | { 291 | if (NoProjectWarnings) 292 | { 293 | NoProjectWarnings = false; 294 | lblNoWarnings.Visibility = Visibility.Collapsed; 295 | btnToggle.IsEnabled = true; 296 | ResumeInterfaceLayout(); 297 | } 298 | } 299 | 300 | #region Button Events 301 | // When user clicks on one of the pies 302 | public void Chart_OnDataClick(object sender, ChartPoint chartpoint) 303 | { 304 | var chart = (LiveCharts.Wpf.PieChart)chartpoint.ChartView; 305 | 306 | //clear selected slice. 307 | foreach (PieSeries series in chart.Series) 308 | series.PushOut = 0; 309 | 310 | var selectedSeries = (PieSeries)chartpoint.SeriesView; 311 | selectedSeries.PushOut = pushAmount; 312 | SeriesSelectedEvent((string)((PieSeries)selectedSeries).Tag); 313 | } 314 | // When user clicks on the custom legend 315 | private void MyCustomLegend_LegendItemSelected(object sender, RoutedEventArgs e) 316 | { 317 | var test = (e as SelectedLegendRoutedEventArgs).SelectedItem; 318 | SeriesSelectedEvent(test); 319 | } 320 | // Drag window by clicking on any control 321 | private void Window_MouseDown(object sender, MouseButtonEventArgs e) 322 | { 323 | if (e.ChangedButton == MouseButton.Left) 324 | this.DragMove(); 325 | } 326 | // Close 327 | private void CloseButton_Click(object sender, RoutedEventArgs e) 328 | { 329 | SavePosition(); 330 | Close(); 331 | } 332 | // Collapse 333 | private void CollapseButton_Click(object sender, RoutedEventArgs e) 334 | { 335 | Properties.Settings.Default.IsCheckedState = boolToInt(IsCheckedState); 336 | UpdateInterfaceLayout(); 337 | } 338 | private void SettingsButton_Click(object sender, RoutedEventArgs e) 339 | { 340 | WarningChartSettings settings = new WarningChartSettings(); 341 | if (settings.ShowDialog() == true) 342 | { 343 | //stupid update 344 | var holder = WarningNumber; 345 | WarningNumber = 0; 346 | WarningNumber = holder; 347 | } 348 | } 349 | #endregion 350 | 351 | #region Update Layout 352 | private void UpdateInterfaceLayout() 353 | { 354 | // cycle through the three states 355 | if (IsCheckedState == true) 356 | { 357 | // 1: show everything 358 | IsCheckedState = null; 359 | pieChart.Visibility = Visibility.Visible; 360 | Legend.Visibility = Visibility.Visible; 361 | } 362 | else if (IsCheckedState == null) 363 | { 364 | // 2: hide legend 365 | IsCheckedState = false; 366 | pieChart.Visibility = Visibility.Visible; 367 | Legend.Visibility = Visibility.Collapsed; 368 | } 369 | else if (IsCheckedState == false) 370 | { 371 | // 3: hide chart 372 | IsCheckedState = true; 373 | pieChart.Visibility = Visibility.Collapsed; 374 | Legend.Visibility = Visibility.Collapsed; 375 | } 376 | } 377 | private void ResumeInterfaceLayout() 378 | { 379 | // cycle through the three states 380 | if (IsCheckedState == true) 381 | { 382 | // 1: show everything 383 | pieChart.Visibility = Visibility.Visible; 384 | Legend.Visibility = Visibility.Visible; 385 | } 386 | else if (IsCheckedState == null) 387 | { 388 | // 2: hide legend 389 | pieChart.Visibility = Visibility.Visible; 390 | Legend.Visibility = Visibility.Collapsed; 391 | } 392 | else if (IsCheckedState == false) 393 | { 394 | // 3: hide chart 395 | pieChart.Visibility = Visibility.Collapsed; 396 | Legend.Visibility = Visibility.Collapsed; 397 | } 398 | } 399 | #endregion 400 | 401 | ***/ 402 | 403 | #region Location 404 | // On loaded, move the UI to the up-right corner 405 | // or load the previous position and size 406 | private void MyWindow_Loaded(object sender, RoutedEventArgs e) 407 | { 408 | this.WindowStartupLocation = WindowStartupLocation.Manual; 409 | double screenHeight = SystemParameters.FullPrimaryScreenHeight; 410 | double screenWidth = SystemParameters.FullPrimaryScreenWidth; 411 | this.Top = 160; 412 | this.Left = screenWidth - this.Width - 80; 413 | try 414 | { 415 | Rect bounds = Properties.Settings.Default.WindowPosition; 416 | if (bounds.Top != 0) 417 | { 418 | this.Top = bounds.Top; 419 | 420 | } 421 | if (bounds.Left != 0) 422 | { 423 | this.Left = bounds.Left; 424 | } 425 | // Restore the size only for a manually sized window. 426 | if (bounds.Width != 0 && bounds.Height != 0) 427 | { 428 | this.SizeToContent = SizeToContent.Manual; 429 | this.Width = bounds.Width; 430 | this.Height = bounds.Height; 431 | } 432 | } 433 | catch 434 | { 435 | MessageBox.Show("No settings stored."); 436 | } 437 | } 438 | // Save the location of the UI (per user) 439 | private void SavePosition() 440 | { 441 | Properties.Settings.Default.WindowPosition = this.RestoreBounds; 442 | Properties.Settings.Default.Save(); 443 | } 444 | #endregion 445 | 446 | #region INotifyPropertyChanged implementation 447 | 448 | public event PropertyChangedEventHandler PropertyChanged; 449 | 450 | protected virtual void OnPropertyChanged(string propertyName) 451 | { 452 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 453 | } 454 | #endregion 455 | 456 | private void Window_MouseDown(object sender, MouseButtonEventArgs e) 457 | { 458 | 459 | } 460 | } 461 | 462 | } 463 | -------------------------------------------------------------------------------- /app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 |
7 | 8 | 9 | 10 | 11 | 12 | 2000 13 | 14 | 15 | 1 16 | 17 | 18 | 200 19 | 20 | 21 | 22 | 23 | 0,0,0,0 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /archilizer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnenov/WarningChart/ca284ccec5090ac41d6b99a3b7c4e97397a4adea/archilizer.ico --------------------------------------------------------------------------------