private ColorSchemeInfo ReadColorSchemeInfo(string filePath, out bool isReadable) { ColorSchemeInfo colorSchemeInfo = new ColorSchemeInfo(); isReadable = false; try { if (File.Exists(filePath)) { XmlSerializer serializer = new XmlSerializer(typeof(ColorSchemeInfo)); FileStream fs = new FileStream(filePath, FileMode.Open); XmlReader reader = XmlReader.Create(fs); if (serializer.CanDeserialize(reader)) { colorSchemeInfo = (ColorSchemeInfo)serializer.Deserialize(reader); isReadable = true; } reader.Close(); fs.Close(); } } catch (Exception ex) { MessageBox.Show("Failed to read markup.\n" + ex.Message, "ReadMarkup", MessageBoxButton.OK, MessageBoxImage.Warning); isReadable = false; return(null); } return(colorSchemeInfo); }
public StatusWindow(ColorSchemeInfo colorSchemeInfo, string sheetId) { schemeInfo = colorSchemeInfo; colorSheetId = sheetId; GetColorDefinitionList(out actionDefinitions, out responsibleDefinitions); InitializeComponent(); dataGridAction.ItemsSource = null; dataGridAction.ItemsSource = actionDefinitions; dataGridResponsibility.ItemsSource = null; dataGridResponsibility.ItemsSource = responsibleDefinitions; }
private void buttonSettings_Click(object sender, RoutedEventArgs e) { try { StatusWindow statusWindow = new StatusWindow(schemeInfo, bcfColorSchemeId); if (statusWindow.ShowDialog() == true) { schemeInfo = statusWindow.SchemeInfo; actionDefinitons = statusWindow.ActionDefinitions; responsibilityDefinitions = statusWindow.ResponsibleDefinitions; statusWindow.Close(); comboBoxAction.ItemsSource = null; comboBoxResponsible.ItemsSource = null; comboBoxAction.ItemsSource = actionDefinitons; comboBoxResponsible.ItemsSource = responsibilityDefinitions; freezeHandler = true; if (null != selElementProperties) { for (int i = 0; i < comboBoxAction.Items.Count; i++) { ColorDefinition definition = (ColorDefinition)comboBoxAction.Items[i]; if (definition.ParameterValue == selElementProperties.Action) { comboBoxAction.SelectedIndex = i; } } for (int i = 0; i < comboBoxResponsible.Items.Count; i++) { ColorDefinition definition = (ColorDefinition)comboBoxResponsible.Items[i]; if (definition.ParameterValue == selElementProperties.ResponsibleParty) { comboBoxResponsible.SelectedIndex = i; } } } freezeHandler = false; } } catch (Exception ex) { MessageBox.Show("Failed to set color schemes.\n" + ex.Message, "Color Settings", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void buttonImport_Click(object sender, RoutedEventArgs e) { ProjectWindow projectWindow = new ProjectWindow(); if (projectWindow.ShowDialog() == true) { string labelText = "Importing Color Schemes..."; UpdateLableDelegate updateLabelDelegate = new UpdateLableDelegate(statusLable.SetValue); Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, labelText }); string projectId = projectWindow.ProjectId; File colorSheet = FileManager.FindSubItemByFolderId("Color Schemes", projectId); ColorSchemeInfo colorInfo = BCFParser.ReadColorSchemes(colorSheet.Id, true); List <ColorDefinition> actionColors = new List <ColorDefinition>(); List <ColorDefinition> responsibilityColors = new List <ColorDefinition>(); foreach (ColorScheme colorScheme in colorInfo.ColorSchemes) { switch (colorScheme.SchemeName) { case "BCF Action": actionColors = colorScheme.ColorDefinitions; break; case "BCF Responsibility": responsibilityColors = colorScheme.ColorDefinitions; break; } } actionDefinitions = actionColors.OrderBy(o => o.ParameterValue).ToList(); responsibleDefinitions = responsibilityColors.OrderBy(o => o.ParameterValue).ToList(); dataGridAction.ItemsSource = null; dataGridAction.ItemsSource = actionDefinitions; dataGridResponsibility.ItemsSource = null; dataGridResponsibility.ItemsSource = responsibleDefinitions; bool writeColor = BCFParser.WriteColorSheet(colorInfo, colorSheetId); labelText = "Ready"; Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, labelText }); } }
public WalkerWindow(ExternalEvent exEvent, WalkerHandler handler) { m_event = exEvent; m_handler = handler; m_handler.WalkerWindow = this; InitializeComponent(); expanderBCF.Header = "Show BCF Info"; //expanderRowDefinition.Height = new GridLength(40); this.MinHeight = 535; this.Height = 535; this.Title = "smartBCF v." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); labelStep.Content = ""; filterOnImage = ImageUtil.LoadBitmapImage("filter.png", 24); filterOffImage = ImageUtil.LoadBitmapImage("filter_empty.png", 24); buttonFilterImage.Source = filterOffImage; bcfFileDictionary = m_handler.BCFFileDictionary; bcfDictionary = m_handler.BCFDictionary; categoryInfoList = m_handler.CategoryInfoList; schemeInfo = m_handler.SchemeInfo; bcfProjectId = m_handler.BCFProjectId; bcfColorSchemeId = m_handler.BCFColorSchemeId; googleFolders = m_handler.GoogleFolders; if (bcfDictionary.Count > 0) { currentIndex = 0; DisplayLinkedBCF(); DisplayColorscheme(schemeInfo); } else { //MessageBox.Show("Elements cannot be found in the active Revit document.\n", "Elements Not Found", MessageBoxButton.OK, MessageBoxImage.Information); } }
public bool WriteColorSchemeInfo(string filePath, ColorSchemeInfo colorSchemeInfo) { bool result = false; try { if (File.Exists(filePath)) { File.Delete(filePath); } XmlSerializer serializer = new XmlSerializer(typeof(ColorSchemeInfo)); StreamWriter writer = new StreamWriter(filePath); serializer.Serialize(writer, colorSchemeInfo); writer.Close(); result = true; } catch (Exception ex) { MessageBox.Show(filePath + "\nFailed to write color scheme info.\n" + ex.Message, "Write Color Scheme Info", MessageBoxButton.OK, MessageBoxImage.Warning); result = false; } return(result); }
private ColorSchemeInfo GetColorSchemeInfo(List <ColorDefinition> actionList, List <ColorDefinition> responsibleList) { ColorSchemeInfo colorSchemeInfo = schemeInfo; try { for (int i = 0; i < colorSchemeInfo.ColorSchemes.Count; i++) { if (colorSchemeInfo.ColorSchemes[i].SchemeName == "BCF Action") { colorSchemeInfo.ColorSchemes[i].ColorDefinitions = actionList; } else if (colorSchemeInfo.ColorSchemes[i].SchemeName == "BCF Responsibility") { colorSchemeInfo.ColorSchemes[i].ColorDefinitions = responsibleList; } } } catch (Exception ex) { MessageBox.Show("Failed to consolidate into color scheme info fromm color definition lists.\n" + ex.Message, "Get Color Scheme Info", MessageBoxButton.OK, MessageBoxImage.Warning); } return(colorSchemeInfo); }
public void Execute(UIApplication app) { try { m_doc = app.ActiveUIDocument.Document; switch (Request.Take()) { case RequestId.None: return; case RequestId.ReadLinkedFileInfo: break; case RequestId.UpdateLinkedFileInfo: bool updated = DataStorageUtil.UpdateLinkedBCFFileInfo(m_doc, bcfFileDictionary); Dictionary <string, Dictionary <string, IssueEntry> > dictionary = new Dictionary <string, Dictionary <string, IssueEntry> >(); int numCat = categoryNames.Count; AbortFlag.SetAbortFlag(false); progressWindow = new ProgressWindow("Loading BCF issues and images..."); progressWindow.Show(); foreach (string markupId in bcfFileDictionary.Keys) { LinkedBcfFileInfo bcfInfo = bcfFileDictionary[markupId]; if (bcfDictionary.ContainsKey(markupId)) { dictionary.Add(markupId, bcfDictionary[markupId]); } else { Dictionary <string, IssueEntry> issueDictionary = GetBCFIssueInfo(m_doc, bcfInfo); if (issueDictionary.Count > 0) { dictionary.Add(markupId, issueDictionary); } } } if (progressWindow.IsActive) { progressWindow.Close(); } bcfDictionary = dictionary; if (numCat != categoryNames.Count) { System.IO.MemoryStream stream = BCFParser.CreateCategoryStream(categoryNames); if (null != stream) { Google.Apis.Drive.v2.Data.File file = FileManager.UpdateSpreadsheet(stream, categorySheetId, bcfProjectId); } List <BuiltInCategory> bltCategories = catDictionary.Values.ToList(); bool parameterCreated = ParameterUtil.CreateBCFParameters(m_app, bltCategories); foreach (string catName in categoryNames) { var catFound = from category in categoryInfoList where category.CategoryName == catName select category; if (catFound.Count() == 0) { CategoryInfo catInfo = new CategoryInfo(catName, true); categoryInfoList.Add(catInfo); } } } if (null != walkerWindow) { walkerWindow.BCFFileDictionary = bcfFileDictionary; walkerWindow.BCFDictionary = bcfDictionary; walkerWindow.CategoryInfoList = categoryInfoList; walkerWindow.CurrentIndex = 0; walkerWindow.DisplayLinkedBCF(); } bool updatedId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId); schemeInfo = FileManager.ReadColorSchemes(bcfColorSchemeId, categorySheetId, false); if (null != walkerWindow) { walkerWindow.SchemeInfo = schemeInfo; walkerWindow.DisplayColorscheme(schemeInfo); } break; case RequestId.ReadProjectId: bcfProjectId = ParameterUtil.GetBCFProjectId(app); break; case RequestId.UpdateProjectId: bool updatedProjectId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId); break; case RequestId.ReadBCFParameterInfo: break; case RequestId.UpdateBCFParameterInfo: bool updatedParameters = ParameterUtil.UpdateBCFParameters(m_doc, currentElement, selectedIssue, selectedComment); break; case RequestId.UpdateAction: bool actionUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Action, currentElement.Action); break; case RequestId.UpdateResponsibility: bool responsibilityUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Responsibility, currentElement.ResponsibleParty); break; case RequestId.CreateIssue: break; case RequestId.UpdateViews: IsolateElement(isIsolateOn, m_doc); CreateSectionBox(isSectionBoxOn, m_doc); HighlightElement(isHighlightOn, m_doc); break; case RequestId.UpdateParameterByComment: UpdateParameters(m_doc); break; } } catch (Exception ex) { MessageBox.Show("Failed to execute an external event.\n" + ex.Message, "Execute Event", MessageBoxButton.OK, MessageBoxImage.Warning); } return; }
public WalkerHandler(UIApplication uiapp) { try { m_app = uiapp; m_doc = uiapp.ActiveUIDocument.Document; View3D view3d = m_doc.ActiveView as View3D; if (null != view3d) { activeView = view3d; } else { FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <View3D> view3ds = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList(); var viewfound = from view in view3ds where view.IsTemplate == false && view.IsPerspective == false && view.ViewName == "{3D}" select view; if (viewfound.Count() > 0) { activeView = viewfound.First(); using (Transaction trans = new Transaction(m_doc, "Open 3D View")) { try { trans.Start(); uiapp.ActiveUIDocument.ActiveView = activeView; trans.Commit(); } catch { trans.RollBack(); } } } } bcfProjectId = ParameterUtil.GetBCFProjectId(m_app); if (!string.IsNullOrEmpty(bcfProjectId)) { googleFolders = FileManager.FindGoogleFolders(bcfProjectId); if (null != googleFolders.ColorSheet) { bcfColorSchemeId = googleFolders.ColorSheet.Id; } if (null != googleFolders.CategorySheet) { categorySheetId = googleFolders.CategorySheet.Id; } if (!string.IsNullOrEmpty(bcfColorSchemeId) && !string.IsNullOrEmpty(categorySheetId)) { schemeInfo = FileManager.ReadColorSchemes(bcfColorSchemeId, categorySheetId, false); } bcfFileDictionary = DataStorageUtil.ReadLinkedBCFFileInfo(m_doc, bcfProjectId); bcfDictionary = GetBCFDictionary(m_doc); List <BuiltInCategory> bltCategories = catDictionary.Values.ToList(); bool parameterCreated = ParameterUtil.CreateBCFParameters(m_app, bltCategories); foreach (string catName in categoryNames) { CategoryInfo catInfo = new CategoryInfo(catName, true); categoryInfoList.Add(catInfo); } } else { MessageBox.Show("Please enter a BCF Project Id in Project Information.", "Empty BCF Project Id", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to initialize External Event handler.\n" + ex.Message, "External Event Handler", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public void DisplayColorscheme(ColorSchemeInfo info) { try { if (info.ColorSchemes.Count > 0) { comboBoxAction.ItemsSource = null; comboBoxResponsible.ItemsSource = null; actionDefinitons = new List <ColorDefinition>(); responsibilityDefinitions = new List <ColorDefinition>(); foreach (ColorScheme scheme in info.ColorSchemes) { if (scheme.SchemeName == "BCF Action") { foreach (ColorDefinition definition in scheme.ColorDefinitions) { actionDefinitons.Add(definition); } } else if (scheme.SchemeName == "BCF Responsibility") { foreach (ColorDefinition definition in scheme.ColorDefinitions) { responsibilityDefinitions.Add(definition); } } } actionDefinitons = actionDefinitons.OrderBy(o => o.ParameterValue).ToList(); responsibilityDefinitions = responsibilityDefinitions.OrderBy(o => o.ParameterValue).ToList(); comboBoxAction.ItemsSource = actionDefinitons; comboBoxResponsible.ItemsSource = responsibilityDefinitions; freezeHandler = true; if (null != selElementProperties) { for (int i = 0; i < comboBoxAction.Items.Count; i++) { ColorDefinition definition = (ColorDefinition)comboBoxAction.Items[i]; if (definition.ParameterValue == selElementProperties.Action) { comboBoxAction.SelectedIndex = i; break; } } for (int i = 0; i < comboBoxResponsible.Items.Count; i++) { ColorDefinition definition = (ColorDefinition)comboBoxResponsible.Items[i]; if (definition.ParameterValue == selElementProperties.ResponsibleParty) { comboBoxResponsible.SelectedIndex = i; break; } } } freezeHandler = false; } } catch (Exception ex) { MessageBox.Show("Failed to display color scheme info.\n" + ex.Message, "Display Color Scheme Info", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public SchemeWindow(ColorSchemeInfo schemeInfo) { colorSchemeInfo = schemeInfo; InitializeComponent(); DisplaySchemes(); }
private void buttonOK_Click(object sender, RoutedEventArgs e) { schemeInfo = GetColorSchemeInfo(actionDefinitions, responsibleDefinitions); this.DialogResult = true; }