├── .gitignore ├── AddMaterials.sln ├── AddMaterials ├── AddMaterials.addin ├── AddMaterials.csproj ├── Command.cs ├── FillPatternBenchmarkCommand.cs ├── Properties │ ├── ._AssemblyInfo.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Resources │ └── delete.png ├── View │ ├── Commands │ │ └── RelayCommand.cs │ ├── Controls │ │ ├── FillPatternViewerControlWpf.xaml │ │ └── FillPatternViewerControlWpf.xaml.cs │ ├── Converters │ │ ├── BitmapSourceConverter.cs │ │ ├── BitmapToImageSourceConverter.cs │ │ ├── InversedStatusToErrorSignVisibilityConverter.cs │ │ ├── StatusToErrorMessageConverter.cs │ │ └── StatusToErrorSignVisibilityConverter.cs │ ├── FillPatternsView.xaml │ ├── FillPatternsView.xaml.cs │ ├── MaterialsView.xaml │ └── MaterialsView.xaml.cs └── ViewModel │ ├── Enum │ └── Status.cs │ ├── Events │ └── DialogCloseEventArgs.cs │ ├── FillPatternViewModel.cs │ ├── FillPatternsViewModel.cs │ ├── MaterialBrowserViewModel.cs │ ├── MaterialViewModel.cs │ └── ViewModelLocator.cs ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | -------------------------------------------------------------------------------- /AddMaterials.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddMaterials", "AddMaterials\AddMaterials.csproj", "{CC6FB9CE-8D9C-494C-BA77-29961459647B}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /AddMaterials/AddMaterials.addin: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | AddMaterials 5 | Some description for AddMaterials 6 | AddMaterials.dll 7 | AddMaterials.Command 8 | a9ec88c8-33a3-4a4d-bb91-e0cb54623b34 9 | TBC_ 10 | The Building Coder, http://thebuildingcoder.typepad.com 11 | 12 | 13 | AddMaterials Fill Pattern benchmark 14 | Some description for AddMaterials 15 | AddMaterials.dll 16 | AddMaterials.FillPatternBenchmarkCommand 17 | ff23fb73-8f11-4c93-b867-9a599a73dd53 18 | TBC_ 19 | The Building Coder, http://thebuildingcoder.typepad.com 20 | 21 | 22 | -------------------------------------------------------------------------------- /AddMaterials/AddMaterials.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | None 6 | 7 | 8 | 9 | 10 | Debug 11 | AnyCPU 12 | 13 | 14 | 15 | 16 | {CC6FB9CE-8D9C-494C-BA77-29961459647B} 17 | Library 18 | Properties 19 | AddMaterials 20 | v4.7 21 | 512 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | Program 32 | $(ProgramW6432)\Autodesk\Revit 2014\Revit.exe 33 | false 34 | 35 | 36 | pdbonly 37 | true 38 | bin\Release\ 39 | TRACE 40 | prompt 41 | 4 42 | Program 43 | $(ProgramW6432)\Autodesk\Revit 2014\Revit.exe 44 | false 45 | 46 | 47 | 48 | 49 | ..\..\..\lib\revit\2020\SDK\Samples\FireRating\VB.NET\Microsoft.Office.Interop.Excel.dll 50 | True 51 | 52 | 53 | 54 | 55 | ..\..\..\..\Program Files\Autodesk\Revit 2020\RevitAPI.dll 56 | False 57 | 58 | 59 | ..\..\..\..\Program Files\Autodesk\Revit 2020\RevitAPIUI.dll 60 | False 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | True 79 | True 80 | Resources.resx 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | FillPatternViewerControlWpf.xaml 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | FillPatternsView.xaml 100 | 101 | 102 | MaterialsView.xaml 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | PublicResXFileCodeGenerator 112 | Resources.Designer.cs 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | Designer 121 | MSBuild:Compile 122 | 123 | 124 | Designer 125 | MSBuild:Compile 126 | 127 | 128 | Designer 129 | MSBuild:Compile 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | copy "$(ProjectDir)AddMaterials.addin" "$(AppData)\Autodesk\REVIT\Addins\2016" 139 | copy "$(ProjectDir)bin\debug\AddMaterials.dll" "$(AppData)\Autodesk\REVIT\Addins\2016" 140 | 141 | -------------------------------------------------------------------------------- /AddMaterials/Command.cs: -------------------------------------------------------------------------------- 1 | #region Namespaces 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using AddMaterials.View; 6 | using AddMaterials.ViewModel; 7 | using AddMaterials.ViewModel.Enum; 8 | using Autodesk.Revit.ApplicationServices; 9 | using Autodesk.Revit.Attributes; 10 | using Autodesk.Revit.DB; 11 | using Autodesk.Revit.UI; 12 | using Excel = Microsoft.Office.Interop.Excel; 13 | #endregion 14 | 15 | namespace AddMaterials 16 | { 17 | [Transaction( TransactionMode.Manual )] 18 | public class Command : IExternalCommand 19 | { 20 | private const string _not_available = "N/A"; 21 | 22 | //const string _input_file_name = "C:/RevitAPI/MaterialList.xlsx"; 23 | //private const string _input_file_name = "C:/tmp/MaterialList.xlsx"; 24 | //const string _input_file_name = "Z:/a/doc/revit/blog/zip/MaterialList.xlsx"; 25 | 26 | const string _input_file_name = "Z:/a/doc/revit/tbc/zip/MaterialList.xlsx"; 27 | 28 | private static string PluralSuffix( int i ) 29 | { 30 | return 1 == i ? "" : "s"; 31 | } 32 | 33 | public Result Execute( 34 | ExternalCommandData commandData, 35 | ref string message, 36 | ElementSet elements ) 37 | { 38 | UIApplication uiapp = commandData.Application; 39 | UIDocument uidoc = uiapp.ActiveUIDocument; 40 | Document doc = uidoc.Document; 41 | 42 | // Create dictionary of existing 43 | // materials keyed by their name. 44 | 45 | Dictionary materials 46 | = new FilteredElementCollector( doc ) 47 | .OfClass( typeof( Material ) ) 48 | .Cast() 49 | .ToDictionary( 50 | e => e.Name ); 51 | 52 | // Ditto for fill patterns. 53 | 54 | Dictionary fillPatterns 55 | = new FilteredElementCollector( doc ) 56 | .OfClass( typeof( FillPatternElement ) ) 57 | .Cast() 58 | .ToDictionary( 59 | e => e.Name ); 60 | 61 | try 62 | { 63 | var materialsToImport = ReadMaterialsFromXlsx( materials, fillPatterns ).ToList(); 64 | var browser = new MaterialBrowserViewModel { Materials = materialsToImport }; 65 | var window = new MaterialsView { DataContext = browser }; 66 | var res = window.ShowDialog(); 67 | if( !res.HasValue || !res.Value ) 68 | return Result.Cancelled; 69 | 70 | var materialsToAdd = browser.Materials.Where( x => x.AddToProject ).ToList(); 71 | if( !materialsToAdd.Any() ) 72 | return Result.Cancelled; 73 | 74 | using( var tx = new Transaction( doc ) ) 75 | { 76 | tx.Start( "Add Materials" ); 77 | foreach( var materialViewModel in materialsToAdd ) 78 | { 79 | var materialCSI = materials[materialViewModel.BaseMaterialClass]; 80 | var myMaterial = materialCSI.Duplicate( materialViewModel.Name ); 81 | myMaterial.Color = materialViewModel.Color; 82 | myMaterial.Transparency = (int) materialViewModel.Transparency; 83 | if( materialViewModel.SurfacePattern != null ) 84 | { 85 | myMaterial.SurfaceForegroundPatternId 86 | = fillPatterns[materialViewModel.SurfacePattern.Name].Id; 87 | } 88 | if( materialViewModel.CutPattern != null ) 89 | { 90 | myMaterial.CutForegroundPatternId 91 | = fillPatterns[materialViewModel.CutPattern.Name].Id; 92 | } 93 | } 94 | tx.Commit(); 95 | } 96 | 97 | string msg = string.Format( 98 | "{0} row{1} successfully parsed and " 99 | + "{2} material{3} added:", 100 | materialsToImport.Count, 101 | PluralSuffix( materialsToImport.Count ), 102 | materialsToAdd.Count, 103 | PluralSuffix( materialsToAdd.Count ) ); 104 | 105 | TaskDialog dlg = new TaskDialog( 106 | "Revit AddMaterials" ); 107 | 108 | dlg.MainInstruction = msg; 109 | 110 | dlg.MainContent = string.Join( ", ", 111 | materialsToAdd.Select( x => x.Name ) ) + "."; 112 | 113 | dlg.Show(); 114 | } 115 | catch( Exception ex ) 116 | { 117 | message 118 | = "Revit AddMaterials Exception:\n" + ex; 119 | 120 | return Result.Failed; 121 | } 122 | return Result.Succeeded; 123 | } 124 | 125 | private IEnumerable ReadMaterialsFromXlsx( 126 | Dictionary materials, 127 | Dictionary fillPatterns ) 129 | { 130 | Excel.Application excel 131 | = new Excel.Application(); 132 | 133 | excel.Visible = false; 134 | 135 | Excel.Workbook workbook = excel.Workbooks.Open( 136 | _input_file_name, 0, true, 5, "", "", true, 137 | Excel.XlPlatform.xlWindows, "\t", false, 138 | false, 0, true, 1, 0 ); 139 | 140 | Excel.Worksheet worksheet = (Excel.Worksheet) 141 | workbook.Worksheets.get_Item( 1 ); 142 | 143 | Excel.Range range = worksheet.UsedRange; 144 | 145 | int iRow = 5; 146 | 147 | while( null != range.Cells[iRow, 1].Value2 ) 148 | { 149 | string matName = (string) range.Cells[iRow, 1].Value2; 150 | matName += " " + (string) range.Cells[iRow, 2].Value2; 151 | matName += " " + (string) range.Cells[iRow, 3].Value2; 152 | if( !string.IsNullOrEmpty( matName ) ) 153 | { 154 | double red = (double) range.Cells[iRow, 4].Value2; 155 | double green = (double) range.Cells[iRow, 5].Value2; 156 | double blue = (double) range.Cells[iRow, 6].Value2; 157 | double transparency = (double) range.Cells[iRow, 8].Value2; 158 | string surPatternName = (string) range.Cells[iRow, 9].Value2; 159 | string cutPatternName = (string) range.Cells[iRow, 10].Value2; 160 | string csi = (string) range.Cells[iRow, 11].Value2; 161 | 162 | FillPatternElement fillPatternElement; 163 | FillPattern surfacePattern = null, cutPattern = null; 164 | if( fillPatterns.TryGetValue( surPatternName, out fillPatternElement ) ) 165 | surfacePattern = fillPatternElement.GetFillPattern(); 166 | 167 | if( fillPatterns.TryGetValue( cutPatternName, out fillPatternElement ) ) 168 | cutPattern = fillPatternElement.GetFillPattern(); 169 | 170 | var status = Status.Normal; 171 | if( !materials.ContainsKey( csi ) ) 172 | status = Status.BaseMaterialClassNotFound; 173 | if( materials.ContainsKey( matName ) ) 174 | status = Status.ProjectAlreadyContainsMaterialWithTheSameName; 175 | 176 | yield return new MaterialViewModel 177 | { 178 | Name = matName, 179 | BaseMaterialClass = csi, 180 | Color = new Color( 181 | Byte.Parse( red.ToString() ), 182 | Byte.Parse( green.ToString() ), 183 | Byte.Parse( blue.ToString() ) ), 184 | Transparency = transparency, 185 | SurfacePattern = surfacePattern, 186 | CutPattern = cutPattern, 187 | Status = status, 188 | AddToProject = status == Status.Normal 189 | }; 190 | } 191 | ++iRow; 192 | } 193 | workbook.Close( true, null, null ); 194 | excel.Quit(); 195 | } 196 | } 197 | } 198 | 199 | // Z:\a\rvt\add_material_csi_03.rvt 200 | // Z:\a\rvt\fill_pattern_viewer.rvt 201 | 202 | -------------------------------------------------------------------------------- /AddMaterials/FillPatternBenchmarkCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Input; 3 | using AddMaterials.View; 4 | using AddMaterials.ViewModel; 5 | using Autodesk.Revit.Attributes; 6 | using Autodesk.Revit.DB; 7 | using Autodesk.Revit.UI; 8 | 9 | namespace AddMaterials 10 | { 11 | [Transaction( TransactionMode.ReadOnly )] 12 | public class FillPatternBenchmarkCommand 13 | : IExternalCommand 14 | { 15 | public Result Execute( 16 | ExternalCommandData commandData, 17 | ref string message, 18 | ElementSet elements ) 19 | { 20 | var doc = commandData.Application 21 | .ActiveUIDocument.Document; 22 | 23 | var fillPatternElements 24 | = new FilteredElementCollector( doc ) 25 | .OfClass( typeof( FillPatternElement ) ) 26 | .OfType() 27 | .OrderBy( fp => fp.Name ) 28 | .ToList(); 29 | 30 | var fillPatterns 31 | = fillPatternElements.Select( 32 | fpe => fpe.GetFillPattern() ); 33 | 34 | FillPatternsViewModel fillPatternsViewModel 35 | = new FillPatternsViewModel( fillPatterns 36 | .Select( x => new FillPatternViewModel( 37 | x ) ) ); 38 | 39 | FillPatternsView fillPatternsView 40 | = new FillPatternsView() 41 | { 42 | DataContext = fillPatternsViewModel 43 | }; 44 | 45 | fillPatternsView.ShowDialog(); 46 | 47 | return Result.Succeeded; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /AddMaterials/Properties/._AssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeremytammik/AddMaterials/43533712f759a3cf150d8f895dc2237c3d87be75/AddMaterials/Properties/._AssemblyInfo.cs -------------------------------------------------------------------------------- /AddMaterials/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle( "Revit AddMaterials Add-In" )] 9 | [assembly: AssemblyDescription( "Add materials from Excel spreadsheet to Revit project" )] 10 | [assembly: AssemblyConfiguration( "" )] 11 | [assembly: AssemblyCompany( "Autodesk Inc." )] 12 | [assembly: AssemblyProduct( "Revit AddMaterials Add-In" )] 13 | [assembly: AssemblyCopyright( "Copyright 2014 © Jeremy Tammik Autodesk Inc." )] 14 | [assembly: AssemblyTrademark( "" )] 15 | [assembly: AssemblyCulture( "" )] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible( false )] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid( "321044f7-b0b2-4b1c-af18-e71a19252be0" )] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | // 2014-03-20 2014.0.0.0 migrated from Revit 2011 to Revit 2014 36 | // 2014-03-29 2014.0.0.1 error message and reporting enhancements 37 | // 2014-04-02 2014.0.0.2 usability enhancements by Alexander Ignatovich 38 | // 2014-04-20 2015.0.0.2 migrated to Revit 2015 39 | // 2014-04-20 2015.0.0.3 integrated fill pattern viewer benchmark 40 | // 2015-11-04 2015.0.0.4 updated FillPatternViewerControlWpf.xaml.cs, merged pull request #1 by @kfpopeye 41 | // 2015-11-04 2015.0.0.5 updated FillPatternViewerControlWpf.xaml.cs, merged pull request #3 by @kfpopeye 42 | // 2015-11-04 2016.0.0.0 tested and migrated to Revit 2016 43 | // 2019-06-07 2016.0.0.1 integrated pull request #4 by @ridespirals -- handle 0 or negative DashPatterns 44 | // 2019-06-12 2020.0.0.0 flat migration to Revit 2020 45 | // 2019-06-12 2020.0.0.1 implemented suggestion by Александр Пекшев: Replace FillPattern = "{Binding CutPattern}" with FillPattern = "{Binding CutPattern, IsAsync=True}" and drawing thumbnails can get even faster 46 | // 47 | [assembly: AssemblyVersion( "2020.0.0.1" )] 48 | [assembly: AssemblyFileVersion( "2020.0.0.1" )] 49 | -------------------------------------------------------------------------------- /AddMaterials/Properties/Resources.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 AddMaterials.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | public static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AddMaterials.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | public static System.Drawing.Bitmap Error { 67 | get { 68 | object obj = ResourceManager.GetObject("Error", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /AddMaterials/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | -------------------------------------------------------------------------------- /AddMaterials/Resources/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeremytammik/AddMaterials/43533712f759a3cf150d8f895dc2237c3d87be75/AddMaterials/Resources/delete.png -------------------------------------------------------------------------------- /AddMaterials/View/Commands/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Windows.Input; 4 | 5 | 6 | namespace AddMaterials.View.Commands 7 | { 8 | public class RelayCommand : ICommand 9 | { 10 | private readonly Action execute; 11 | private readonly Predicate canExecute; 12 | 13 | /// 14 | /// Creates a new command that can always execute. 15 | /// 16 | /// The execution logic. 17 | public RelayCommand(Action execute) 18 | : this(execute, null) 19 | { 20 | } 21 | 22 | /// 23 | /// Creates a new command. 24 | /// 25 | /// The execution logic. 26 | /// The execution status logic. 27 | public RelayCommand(Action execute, Predicate canExecute) 28 | { 29 | if (execute == null) 30 | throw new ArgumentNullException("execute"); 31 | 32 | this.execute = execute; 33 | this.canExecute = canExecute; 34 | } 35 | 36 | [DebuggerStepThrough] 37 | public bool CanExecute(object parameter) 38 | { 39 | return canExecute == null || canExecute(parameter); 40 | } 41 | 42 | public event EventHandler CanExecuteChanged 43 | { 44 | add { CommandManager.RequerySuggested += value; } 45 | remove { CommandManager.RequerySuggested -= value; } 46 | } 47 | 48 | public void Execute(object parameter) 49 | { 50 | execute(parameter); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /AddMaterials/View/Controls/FillPatternViewerControlWpf.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 15 | 16 | 17 | 19 | 20 | 21 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /AddMaterials/View/Controls/FillPatternViewerControlWpf.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Diagnostics; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Windows; 7 | using Autodesk.Revit.DB; 8 | using Image = System.Drawing.Image; 9 | using Matrix = System.Drawing.Drawing2D.Matrix; 10 | using Rectangle = System.Drawing.Rectangle; 11 | 12 | namespace AddMaterials.View.Controls 13 | { 14 | /// 15 | /// Interaction logic for FillPatternViewerControlWpf.xaml 16 | /// 17 | public partial class FillPatternViewerControlWpf 18 | : INotifyPropertyChanged 19 | { 20 | private const float Scale = 50; 21 | private const float LENGTH = 100; 22 | private Bitmap fillPatternImg; 23 | 24 | #region FillPattern DependencyProperty 25 | public static readonly 26 | DependencyProperty FillPatternProperty 27 | = DependencyProperty.RegisterAttached( 28 | "FillPattern", 29 | typeof( FillPattern ), 30 | typeof( FillPatternViewerControlWpf ), 31 | new UIPropertyMetadata( null, 32 | OnFillPatternChanged ) ); 33 | 34 | private static void OnFillPatternChanged( 35 | DependencyObject d, 36 | DependencyPropertyChangedEventArgs e ) 37 | { 38 | var FillPatternViewerControlWpfControl 39 | = d as FillPatternViewerControlWpf; 40 | 41 | if( FillPatternViewerControlWpfControl == null ) return; 42 | 43 | FillPatternViewerControlWpfControl.OnPropertyChanged( 44 | "FillPattern" ); 45 | 46 | FillPatternViewerControlWpfControl.CreateFillPatternImage(); 47 | } 48 | 49 | public FillPattern FillPattern 50 | { 51 | get 52 | { 53 | return (FillPattern) GetValue( 54 | FillPatternProperty ); 55 | } 56 | set 57 | { 58 | SetValue( FillPatternProperty, value ); 59 | } 60 | } 61 | 62 | public FillPattern GetFillPattern( 63 | DependencyObject obj ) 64 | { 65 | return (FillPattern) obj.GetValue( 66 | FillPatternProperty ); 67 | } 68 | 69 | public void SetFillPattern( 70 | DependencyObject obj, 71 | FillPattern value ) 72 | { 73 | obj.SetValue( FillPatternProperty, value ); 74 | } 75 | #endregion 76 | 77 | public void Regenerate() 78 | { 79 | CreateFillPatternImage(); 80 | } 81 | 82 | public FillPatternViewerControlWpf() 83 | { 84 | InitializeComponent(); 85 | } 86 | 87 | public event PropertyChangedEventHandler 88 | PropertyChanged; 89 | 90 | //[NotifyPropertyChangedInvocator] 91 | protected virtual void OnPropertyChanged( 92 | string propertyName ) 93 | { 94 | var handler = PropertyChanged; 95 | if( handler != null ) 96 | { 97 | handler( this, 98 | new PropertyChangedEventArgs( 99 | propertyName ) ); 100 | } 101 | } 102 | 103 | public Image FillPatternImage 104 | { 105 | get 106 | { 107 | if( fillPatternImg == null ) 108 | CreateFillPatternImage(); 109 | return fillPatternImg; 110 | } 111 | } 112 | 113 | private void CreateFillPatternImage() 114 | { 115 | var width 116 | = ( ActualWidth == 0 ? Width : ActualWidth ) == 0 117 | ? 100 118 | : ( ActualWidth == 0 ? Width : ActualWidth ); 119 | 120 | if( double.IsNaN( width ) ) 121 | width = 100; 122 | 123 | var height 124 | = ( ActualHeight == 0 ? Height : ActualHeight ) == 0 125 | ? 30 126 | : ( ActualHeight == 0 ? Height : ActualHeight ); 127 | 128 | if( double.IsNaN( height ) ) 129 | height = 30; 130 | 131 | fillPatternImg = new Bitmap( 132 | (int) width, (int) height ); 133 | 134 | using( var g = Graphics.FromImage( 135 | fillPatternImg ) ) 136 | { 137 | var rect = new Rectangle( 138 | 0, 0, (int) width, (int) height ); 139 | g.FillRectangle( Brushes.White, rect ); 140 | DrawFillPattern( g ); 141 | } 142 | 143 | OnPropertyChanged( "FillPatternImage" ); 144 | } 145 | 146 | private void DrawFillPattern( Graphics g ) 147 | { 148 | Stopwatch sw = Stopwatch.StartNew(); 149 | float matrixScale; 150 | var fillPattern = FillPattern; 151 | if( fillPattern == null ) 152 | return; 153 | 154 | if( fillPattern.Target == FillPatternTarget.Model ) 155 | matrixScale = Scale; 156 | else 157 | matrixScale = Scale * 10; 158 | 159 | try 160 | { 161 | var width 162 | = ( ActualWidth == 0 ? Width : ActualWidth ) == 0 163 | ? 100 164 | : ( ActualWidth == 0 ? Width : ActualWidth ); 165 | 166 | if( double.IsNaN( width ) ) 167 | width = 100; 168 | 169 | var height 170 | = ( ActualHeight == 0 ? Height : ActualHeight ) == 0 171 | ? 30 172 | : ( ActualHeight == 0 ? Height : ActualHeight ); 173 | 174 | if( double.IsNaN( height ) ) 175 | height = 30; 176 | 177 | var viewRect = new Rectangle( 178 | 0, 0, (int) width, (int) height ); 179 | 180 | var centerX = ( viewRect.Left 181 | + viewRect.Left + viewRect.Width ) / 2; 182 | 183 | var centerY = ( viewRect.Top 184 | + viewRect.Top + viewRect.Height ) / 2; 185 | 186 | g.TranslateTransform( centerX, centerY ); 187 | 188 | var rectF = new Rectangle( -1, -1, 2, 2 ); 189 | g.FillRectangle( Brushes.Blue, rectF ); //draw a small rectangle in the center of the image 190 | 191 | g.ResetTransform(); 192 | 193 | var fillGrids = fillPattern.GetFillGrids(); 194 | 195 | Debug.Print( new string( '-', 100 ) ); 196 | Debug.Print( "FilPattern name: {0}", fillPattern.Name ); 197 | if( fillPattern.Target == FillPatternTarget.Model ) 198 | Debug.Print( "FillPattern type: Model" ); 199 | else 200 | Debug.Print( "FillPattern type: Drafting" ); 201 | Debug.Print( "Matrix scale: {0}", matrixScale ); 202 | Debug.Print( "Grids count: {0}", fillGrids.Count ); 203 | Debug.Print( "Len\\Area: {0}", fillPattern.LengthPerArea ); 204 | Debug.Print( "Lines\\Len: {0}", fillPattern.LinesPerLength ); 205 | Debug.Print( "Strokes\\Area: {0}", fillPattern.StrokesPerArea ); 206 | 207 | foreach( var fillGrid in fillGrids ) 208 | { 209 | var degreeAngle = (float) RadianToGradus( fillGrid.Angle ); 210 | Debug.Print( new string( '-', 50 ) ); 211 | Debug.Print( "Origin: U:{0} V:{1}", 212 | fillGrid.Origin.U, fillGrid.Origin.V ); 213 | Debug.Print( "Offset: {0}", fillGrid.Offset ); 214 | Debug.Print( "Angle: {0}", degreeAngle ); 215 | Debug.Print( "Shift: {0}", fillGrid.Shift ); 216 | 217 | var pen = new Pen( System.Drawing.Color.Black ) 218 | { 219 | Width = 1f / matrixScale 220 | }; 221 | 222 | float dashLength = 1; 223 | var segments = fillGrid.GetSegments(); 224 | 225 | if( segments.Count > 0 ) 226 | { 227 | pen.DashPattern = segments 228 | .Select(s => Math.Max(float.Epsilon, Convert.ToSingle(s)) ) 229 | .ToArray(); 230 | 231 | Debug.Print( "\tSegments:" ); 232 | foreach( var segment in segments ) 233 | { 234 | Debug.Print( "\t\t{0}", segment ); 235 | } 236 | dashLength = pen.DashPattern.Sum(); 237 | } 238 | g.ResetTransform(); 239 | var rotateMatrix = new Matrix(); 240 | rotateMatrix.Rotate( degreeAngle ); 241 | var matrix = new Matrix( 242 | 1, 0, 0, -1, centerX, centerY ); //-1 reflects about x-axis 243 | matrix.Scale( matrixScale, matrixScale ); 244 | matrix.Translate( (float) fillGrid.Origin.U, 245 | (float) fillGrid.Origin.V ); 246 | var backMatrix = matrix.Clone(); 247 | backMatrix.Multiply( rotateMatrix ); 248 | matrix.Multiply( rotateMatrix ); 249 | 250 | var offset = ( -10 ) * dashLength; 251 | matrix.Translate( offset, 0 ); 252 | backMatrix.Translate( offset, 0 ); 253 | Debug.Print( "Offset: {0}", offset ); 254 | 255 | 256 | bool moving_forward = true; 257 | bool moving_back = true; 258 | int safety = 500; 259 | double alternator = 0; 260 | while( moving_forward || moving_back ) // draw segments shifting and offsetting each time 261 | { 262 | Debug.Write( "*" ); 263 | var rectF1 = new RectangleF( 264 | -2 / matrixScale, -2 / matrixScale, 265 | 4 / matrixScale, 4 / matrixScale ); 266 | 267 | if( moving_forward && LineIntersectsRect( 268 | matrix, viewRect ) ) 269 | { 270 | g.Transform = matrix; 271 | g.DrawLine( pen, new PointF( 0, 0 ), 272 | new PointF( LENGTH, 0 ) ); 273 | } 274 | else 275 | { 276 | moving_forward = false; 277 | Debug.Print( "\n----> Matrix does not intersect view" ); 278 | } 279 | 280 | if( moving_back && LineIntersectsRect( 281 | backMatrix, viewRect ) ) 282 | { 283 | g.Transform = backMatrix; 284 | g.DrawLine( pen, new PointF( 0, 0 ), 285 | new PointF( LENGTH, 0 ) ); 286 | } 287 | else 288 | { 289 | moving_back = false; 290 | Debug.Print( "\n----> Back matrix does not intersect view" ); 291 | } 292 | 293 | if( safety == 0 ) 294 | { 295 | Debug.Print( "\n--------> Safety limit exceeded" ); 296 | break; 297 | } 298 | else 299 | --safety; 300 | 301 | matrix.Translate( (float) fillGrid.Shift, 302 | (float) fillGrid.Offset ); 303 | backMatrix.Translate( -(float) fillGrid.Shift, 304 | -(float) fillGrid.Offset ); 305 | 306 | alternator += fillGrid.Shift; 307 | if( Math.Abs( alternator ) > Math.Abs( offset ) ) 308 | { 309 | Debug.Print( "\n----> Alternating" ); 310 | matrix.Translate( offset, 0 ); 311 | backMatrix.Translate( offset, 0 ); 312 | alternator = 0d; 313 | } 314 | } 315 | } 316 | sw.Stop(); 317 | g.ResetTransform(); 318 | 319 | #if DEBUG 320 | g.DrawString( string.Format( 321 | "{0} ms", sw.ElapsedMilliseconds ), 322 | System.Drawing.SystemFonts.DefaultFont, 323 | Brushes.Red, 0, 0 ); 324 | #endif 325 | 326 | Debug.Print( new string( '-', 50 ) ); 327 | 328 | Pen p = new Pen( System.Drawing.Color.Black ); 329 | p.Width = 1f / matrixScale; 330 | Debug.Print( "Finished" ); 331 | } 332 | catch( Exception ex ) 333 | { 334 | Debug.Print( ex.ToString() ); 335 | } 336 | } 337 | 338 | public bool LineIntersectsRect( Matrix rayMatrix, Rectangle r ) 339 | { 340 | Matrix m = rayMatrix.Clone(); 341 | m.Translate( 200, 0 ); 342 | return LineIntersectsRect( 343 | new System.Drawing.Point( (int) rayMatrix.OffsetX, 344 | (int) rayMatrix.OffsetY ), 345 | new System.Drawing.Point( (int) m.OffsetX, 346 | (int) m.OffsetY ), 347 | r ); 348 | } 349 | 350 | public bool LineIntersectsRect( 351 | System.Drawing.Point p1, 352 | System.Drawing.Point p2, 353 | Rectangle r ) 354 | { 355 | return LineIntersectsLine( p1, p2, new System.Drawing.Point( r.X, r.Y ), new System.Drawing.Point( r.X + r.Width, r.Y ) ) 356 | || LineIntersectsLine( p1, p2, new System.Drawing.Point( r.X + r.Width, r.Y ), new System.Drawing.Point( r.X + r.Width, r.Y + r.Height ) ) 357 | || LineIntersectsLine( p1, p2, new System.Drawing.Point( r.X + r.Width, r.Y + r.Height ), new System.Drawing.Point( r.X, r.Y + r.Height ) ) 358 | || LineIntersectsLine( p1, p2, new System.Drawing.Point( r.X, r.Y + r.Height ), new System.Drawing.Point( r.X, r.Y ) ) 359 | || ( r.Contains( p1 ) && r.Contains( p2 ) ); 360 | } 361 | 362 | private bool LineIntersectsLine( 363 | System.Drawing.Point l1p1, 364 | System.Drawing.Point l1p2, 365 | System.Drawing.Point l2p1, 366 | System.Drawing.Point l2p2 ) 367 | { 368 | try 369 | { 370 | Int64 d = ( l1p2.X - l1p1.X ) * ( l2p2.Y - l2p1.Y ) - ( l1p2.Y - l1p1.Y ) * ( l2p2.X - l2p1.X ); 371 | if( d == 0 ) return false; 372 | 373 | Int64 q = ( l1p1.Y - l2p1.Y ) * ( l2p2.X - l2p1.X ) - ( l1p1.X - l2p1.X ) * ( l2p2.Y - l2p1.Y ); 374 | Int64 r = q / d; 375 | 376 | Int64 q1 = (Int64) ( l1p1.Y - l2p1.Y ) * (Int64) ( l1p2.X - l1p1.X ); 377 | Int64 q2 = (Int64) ( l1p1.X - l2p1.X ) * (Int64) ( l1p2.Y - l1p1.Y ); 378 | 379 | q = q1 - q2; 380 | Int64 s = q / d; 381 | 382 | if( r < 0 || r > 1 || s < 0 || s > 1 ) 383 | return false; 384 | 385 | return true; 386 | } 387 | catch( OverflowException err ) 388 | { 389 | Debug.Print( "----------------------------------" ); 390 | Debug.Print( err.Message ); 391 | Debug.Print( l1p1.ToString() ); 392 | Debug.Print( l1p2.ToString() ); 393 | Debug.Print( l2p1.ToString() ); 394 | Debug.Print( l2p2.ToString() ); 395 | return false; 396 | } 397 | } 398 | 399 | private double GetDistance( PointF point1, PointF point2 ) 400 | { 401 | // Pythagorean theorem c^2 = a^2 + b^2 402 | // thus c = square root(a^2 + b^2) 403 | 404 | double a = (double) ( point2.X - point1.X ); 405 | double b = (double) ( point2.Y - point1.Y ); 406 | 407 | return Math.Sqrt( a * a + b * b ); 408 | } 409 | 410 | private double RadianToGradus( double radian ) 411 | { 412 | return radian * 180 / Math.PI; 413 | } 414 | } 415 | } 416 | -------------------------------------------------------------------------------- /AddMaterials/View/Converters/BitmapSourceConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Windows; 4 | using System.Windows.Interop; 5 | using System.Windows.Media.Imaging; 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class BitmapSourceConverter 9 | { 10 | [System.Runtime.InteropServices.DllImport("gdi32.dll")] 11 | private static extern bool DeleteObject(IntPtr hObject); 12 | 13 | public static BitmapSource ConvertFromImage(Bitmap image) 14 | { 15 | lock (image) 16 | { 17 | IntPtr hBitmap = image.GetHbitmap(); 18 | try 19 | { 20 | var bs = Imaging.CreateBitmapSourceFromHBitmap( 21 | hBitmap, 22 | IntPtr.Zero, 23 | Int32Rect.Empty, 24 | BitmapSizeOptions.FromEmptyOptions()); 25 | 26 | return bs; 27 | } 28 | finally 29 | { 30 | // ReSharper disable UnusedVariable 31 | var res = DeleteObject(hBitmap); 32 | // ReSharper restore UnusedVariable 33 | } 34 | } 35 | } 36 | 37 | public static BitmapSource ConvertFromIcon(Icon icon) 38 | { 39 | 40 | try 41 | { 42 | var bs = Imaging 43 | .CreateBitmapSourceFromHIcon(icon.Handle, 44 | new Int32Rect(0, 0, icon.Width, icon.Height), 45 | BitmapSizeOptions.FromWidthAndHeight(icon.Width, 46 | icon.Height)); 47 | return bs; 48 | } 49 | finally 50 | { 51 | DeleteObject(icon.Handle); 52 | icon.Dispose(); 53 | // ReSharper disable RedundantAssignment 54 | icon = null; 55 | // ReSharper restore RedundantAssignment 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /AddMaterials/View/Converters/BitmapToImageSourceConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Globalization; 4 | using System.Windows.Data; 5 | 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class BitmapToImageSourceConverter : IValueConverter 9 | { 10 | private static readonly Lazy InstanceObj = 11 | new Lazy(() => new BitmapToImageSourceConverter()); 12 | 13 | public static BitmapToImageSourceConverter Instance 14 | { 15 | get { return InstanceObj.Value; } 16 | } 17 | 18 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | var bmp = value as Bitmap; 21 | if (bmp == null) 22 | { 23 | var defaultBmp = parameter as Bitmap; 24 | if (defaultBmp != null) 25 | return BitmapSourceConverter.ConvertFromImage(defaultBmp); 26 | } 27 | 28 | return bmp == null ? null : BitmapSourceConverter.ConvertFromImage(bmp); 29 | } 30 | 31 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 32 | { 33 | throw new NotSupportedException(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /AddMaterials/View/Converters/InversedStatusToErrorSignVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class InversedStatusToErrorSignVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | var converter = new StatusToErrorSignVisibilityConverter(); 13 | var converted = (Visibility)converter.Convert(value, targetType, parameter, culture); 14 | return converted == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible; 15 | } 16 | 17 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 18 | { 19 | throw new NotSupportedException(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /AddMaterials/View/Converters/StatusToErrorMessageConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using AddMaterials.ViewModel.Enum; 5 | 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class StatusToErrorMessageConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (!(value is Status)) 13 | return string.Empty; 14 | var status = (Status) value; 15 | switch (status) 16 | { 17 | case Status.ProjectAlreadyContainsMaterialWithTheSameName: 18 | return "Project already contains material with the same name"; 19 | case Status.BaseMaterialClassNotFound: 20 | return "Base material class not found in the project"; 21 | default: 22 | return string.Empty; 23 | } 24 | } 25 | 26 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 27 | { 28 | throw new NotSupportedException(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /AddMaterials/View/Converters/StatusToErrorSignVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | using AddMaterials.ViewModel.Enum; 6 | 7 | namespace AddMaterials.View.Converters 8 | { 9 | public class StatusToErrorSignVisibilityConverter : IValueConverter 10 | { 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | if (!(value is Status)) 14 | return Visibility.Collapsed; 15 | var status = (Status) value; 16 | 17 | return status != Status.Normal ? Visibility.Visible : Visibility.Collapsed; 18 | } 19 | 20 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 21 | { 22 | throw new NotSupportedException(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /AddMaterials/View/FillPatternsView.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 32 | 34 | 35 | 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /AddMaterials/View/FillPatternsView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Data; 8 | using System.Windows.Documents; 9 | using System.Windows.Input; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Imaging; 12 | using System.Windows.Navigation; 13 | using System.Windows.Shapes; 14 | 15 | namespace AddMaterials.View 16 | { 17 | /// 18 | /// Interaction logic for FillPatternsView.xaml 19 | /// 20 | public partial class FillPatternsView 21 | { 22 | public FillPatternsView() 23 | { 24 | InitializeComponent(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AddMaterials/View/MaterialsView.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 63 | 64 | 67 | 68 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 81 | 82 | 83 | 85 | 86 | 89 | 90 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 103 | 104 | 106 | 107 | 108 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 121 |