// generate column header tree from scratch void GenerateFullColumnHeader(Dictionary <RXClass, StringCollection> classPropertiesMap) { treeColumnHeader.Nodes.Clear(); // First, we generate a "General" header which contains common properties that are scheduled across different classes. Dictionary <string, List <RXClass> > propertyClassesMap = classPropertiesMap.GroupClassesByProperty(); if (propertyClassesMap.ContainsGeneralProperty()) { propertyClassesMap.FilterOutSingleProperties(); TreeNode headerNode = treeColumnHeader.Nodes.Add("General"); GenerateColumnHeaderByProperty(propertyClassesMap, headerNode.Nodes); } Dictionary <RXClass, StringCollection> newClassPropertiesMap = classPropertiesMap.DeepClone(); propertyClassesMap.FilterOutGeneralProperties(newClassPropertiesMap); foreach (RXClass objectType in newClassPropertiesMap.Keys) { if (newClassPropertiesMap[objectType].Count > 0) { TreeNode headerNode = treeColumnHeader.Nodes.Add(ScheduleSample.GetDisplayName(objectType)); GenerateColumnHeaderByObjectType(objectType, newClassPropertiesMap[objectType], headerNode.Nodes); } } treeColumnHeader.ExpandAll(); }
// another way to find the index of a property definition //private static int FindPropertyDefinitionIndex(PropertySetDefinition psd, string propertyName) //{ // PropertyDefinition propDef = new PropertyDefinition(); // propDef.Name = propertyName; // return psd.Definitions.IndexOf(propDef); //} private static ScheduleTableStyle CreateStyle(UiData uiData, PropertySetDefinition psd, Transaction trans) { Database db = ScheduleSample.GetDatabase(); ScheduleTableStyle style = new ScheduleTableStyle(); style.SetToStandard(db); style.SubSetDatabaseDefaults(db); // sets the object type to which the schedule table style applies StringCollection filter = new StringCollection(); foreach (RXClass rc in uiData.classPropertiesMap.Keys) { filter.Add(rc.Name); } style.AppliesToFilter = filter; CreateChildNodes(uiData.headerColumnDesignData, style.Tree, psd, style); //add it into database DictionaryScheduleTableStyle scheduleTableStyleDict = new DictionaryScheduleTableStyle(db); style.Title = uiData.scheduleTableStyleName; scheduleTableStyleDict.AddNewRecord(uiData.scheduleTableStyleName, style); trans.AddNewlyCreatedDBObject(style, true); return(style); }
bool SaveStyleNameToUiData() { if (textStyleName.Text.Length == 0) { MessageBox.Show("Please specify a name for the schedule table style."); return(false); } Database db = ScheduleSample.GetDatabase(); DictionaryScheduleTableStyle dict = new DictionaryScheduleTableStyle(db); DBTransactionManager tm = db.TransactionManager; using (Transaction trans = tm.StartTransaction()) { if (dict.Has(textStyleName.Text, trans)) { MessageBox.Show("The style name you specified already exists. Please specify a new one."); return(false); } } runtimeData.scheduleTableStyleName = textStyleName.Text; return(true); }
private static ScheduleTable CreateScheduleTable(UiData uiData, ObjectId propertySetDefinitionId, ObjectId styleId, Transaction trans) { Database db = ScheduleSample.GetDatabase(); BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; ScheduleTable scheduleTable = new ScheduleTable(); scheduleTable.SetToStandard(db); scheduleTable.SetDatabaseDefaults(db); scheduleTable.StyleId = styleId; scheduleTable.SetDefaultLayer(); btr.AppendEntity(scheduleTable); trans.AddNewlyCreatedDBObject(scheduleTable, true); ObjectIdCollection selectionSet = new ObjectIdCollection(); foreach (List <ObjectId> idSetByObjectType in uiData.classObjectIdsMap.Values) { foreach (ObjectId id in idSetByObjectType) { selectionSet.Add(id); } } scheduleTable.SetSelectionSet(selectionSet, new ObjectIdCollection()); scheduleTable.AutomaticUpdate = true; return(scheduleTable); }
private static List <ScheduleTableStyleHeaderNode> CreateChildNodes(List <ColumnHeaderNode> childNodes, ScheduleTableStyleHeaderTree tree, PropertySetDefinition psd, ScheduleTableStyle style) { Database db = ScheduleSample.GetDatabase(); List <ScheduleTableStyleHeaderNode> nodesCreated = new List <ScheduleTableStyleHeaderNode>(); foreach (ColumnHeaderNode childNode in childNodes) { if (childNode.IsColumn) { PropertyClassData data = childNode.ColumnData; ScheduleTableStyleColumn column = CreateColumn(data, psd, style); style.Columns.Add(column); nodesCreated.Add(column); } else if (childNode.IsHeader) { string headerName = childNode.NodeData as string; List <ScheduleTableStyleHeaderNode> myChildren = CreateChildNodes(childNode.Children, tree, psd, style); ScheduleTableStyleHeaderNode header = tree.InsertNode(headerName, tree.Root.Children.Count, tree.Root, myChildren.ToArray()); nodesCreated.Add(header); } else { throw new ArgumentException("Cannot resolve node type properly when creating schedule table style."); } } return(nodesCreated); }
private void listObjectType_Format(object sender, ListControlConvertEventArgs e) { KeyValuePair <RXClass, List <ObjectId> > pair = (KeyValuePair <RXClass, List <ObjectId> >)e.ListItem; RXClass objectType = pair.Key; e.Value = ScheduleSample.GetDisplayName(objectType) + "(" + pair.Value.Count.ToString() + ")"; }
/// <summary> /// Creates the whole property sets, schedule table style and schedule table in database. /// </summary> /// <param name="uiData">The data saved from the wizard.</param> /// <returns>Returns the object id of the property set definition, schedule table style and schedule table.</returns> public static ScheduleTableCreateResult CreateScheduleTable(UiData uiData) { ScheduleTableCreateResult result = new ScheduleTableCreateResult(); Database db = ScheduleSample.GetDatabase(); DBTransactionManager tm = db.TransactionManager; using (Transaction trans = tm.StartTransaction()) { try { PropertySetDefinition psd = CreatePropertySetDefinition(uiData, trans); result.PropertySetDefinitionId = psd.Id; if (result.PropertySetDefinitionId == ObjectId.Null) { throw (new System.Exception("Failed to create property set definition.")); } ScheduleTableStyle style = CreateStyle(uiData, psd, trans); result.StyleId = style.Id; if (result.StyleId == ObjectId.Null) { throw (new System.Exception("Failed to create property style.")); } AddPropertySetToObjects(uiData, result.PropertySetDefinitionId, trans); ScheduleTable table = CreateScheduleTable(uiData, result.PropertySetDefinitionId, result.StyleId, trans); result.ScheduleTableId = table.Id; if (result.ScheduleTableId == ObjectId.Null) { throw (new System.Exception("Failed to create Schedule Table.")); } Editor editor = ScheduleSample.GetEditor(); PromptPointResult editorResult = editor.GetPoint("Please pick a point to insert the schedule table:"); if (editorResult.Status == PromptStatus.OK) { table.Location = editorResult.Value; table.Scale = 10; trans.Commit(); } else { trans.Abort(); } } catch (System.Exception) { trans.Abort(); return(null); } finally { trans.Dispose(); } } return(result); }
private static ScheduleTableStyleColumn CreateColumn(PropertyClassData nodeData, PropertySetDefinition psd, ScheduleTableStyle style) { Database db = ScheduleSample.GetDatabase(); ScheduleTableStyleColumn column = new ScheduleTableStyleColumn(); column.SetToStandard(db); column.SubSetDatabaseDefaults(db); column.PropertySetDefinitionId = psd.Id; column.ColumnType = ScheduleTableStyleColumnType.Normal; column.Heading = nodeData.DisplayName; column.PropertyId = psd.Definitions.IndexOf(nodeData.PropertyName); return(column); }
private static PropertySetDefinition CreatePropertySetDefinition(UiData uiData, Transaction trans) { Database db = ScheduleSample.GetDatabase(); string psdName = uiData.propertySetDefinitionName; StringCollection appliesTo = new StringCollection(); foreach (RXClass rc in uiData.classPropertiesMap.Keys) { appliesTo.Add(rc.Name); } // create the property set definition PropertySetDefinition psd = new PropertySetDefinition(); psd.SetToStandard(db); psd.SubSetDatabaseDefaults(db); psd.AlternateName = psdName; psd.IsLocked = false; psd.IsVisible = true; psd.IsWriteable = true; psd.SetAppliesToFilter(appliesTo, false); Dictionary <string, List <RXClass> > propertyClassesMap = uiData.classPropertiesMap.GroupClassesByProperty(); foreach (string propertyName in propertyClassesMap.Keys) { PropertyDefinition propDef = new PropertyDefinition(); propDef.SetToStandard(db); propDef.SubSetDatabaseDefaults(db); propDef.Name = propertyName; propDef.Automatic = true; propDef.Description = propertyName; propDef.IsVisible = true; propDef.IsReadOnly = true; foreach (RXClass objectType in propertyClassesMap[propertyName]) { propDef.SetAutomaticData(objectType.Name, propertyName); } psd.Definitions.Add(propDef); } DictionaryPropertySetDefinitions propDefs = new DictionaryPropertySetDefinitions(db); propDefs.AddNewRecord(uiData.propertySetDefinitionName, psd); trans.AddNewlyCreatedDBObject(psd, true); return(psd); }
void GenerateReportOfPropertySet(StringBuilder sb, RXClass objectType, StringCollection propertyNames) { if (propertyNames.Count == 0) { return; } sb.AppendFormat("{0} - {1} properties:", ScheduleSample.GetDisplayName(objectType), propertyNames.Count); sb.AppendLine(); foreach (string name in propertyNames) { sb.AppendLine(name); } sb.AppendLine(); }
string GenerateReportOfSelectedObjects() { StringBuilder sb = new StringBuilder(); int objectCount = 0; foreach (List <ObjectId> objectIdList in runtimeData.classObjectIdsMap.Values) { objectCount += objectIdList.Count; } sb.AppendFormat("You are about to schedule {0} objects:", objectCount); sb.AppendLine(); foreach (RXClass objectType in runtimeData.classObjectIdsMap.Keys) { sb.AppendFormat("{0}[{1}] ", ScheduleSample.GetDisplayName(objectType), runtimeData.classObjectIdsMap[objectType].Count); } sb.AppendLine(); return(sb.ToString()); }
bool SavePropertySetDefinitionNameToUiData() { if (textPsdName.Text.Length == 0) { MessageBox.Show("Please specify a name for the property set definition."); return(false); } Database db = ScheduleSample.GetDatabase(); DictionaryPropertySetDefinitions dict = new DictionaryPropertySetDefinitions(db); DBTransactionManager tm = db.TransactionManager; using (Transaction trans = tm.StartTransaction()) { if (dict.Has(textPsdName.Text, trans)) { MessageBox.Show("The property set definition name you specified already exists. Please specify a new one."); return(false); } } runtimeData.propertySetDefinitionName = textPsdName.Text; return(true); }
// Fill the property tree with the property definition sets defined in the previous wizard sheet. void FillPropertyTree() { treeProperties.Nodes.Clear(); // Add a "General" node which contains common properties that are scheduled across different classes. Dictionary <string, List <RXClass> > propertyClassesMap = runtimeData.classPropertiesMap.GroupClassesByProperty(); if (propertyClassesMap.ContainsGeneralProperty()) { TreeNode headerNode = treeProperties.Nodes.Add("General"); StringCollection generalProperties = propertyClassesMap.GetGeneralPropertyNames(); foreach (string propName in generalProperties) { AddPropertyToNodeCollection(headerNode.Nodes, propertyClassesMap[propName], propName); } } // Now we add properties grouped by class Dictionary <RXClass, StringCollection> newClassPropertiesMap = runtimeData.classPropertiesMap.DeepClone(); propertyClassesMap.FilterOutGeneralProperties(newClassPropertiesMap); // we only need the properties that are not shared across classes at this stage foreach (RXClass objectType in newClassPropertiesMap.Keys) { if (newClassPropertiesMap[objectType].Count == 0) { continue; } TreeNode newNode = treeProperties.Nodes.Add(ScheduleSample.GetDisplayName(objectType)); StringCollection propertyNames = newClassPropertiesMap[objectType]; foreach (string propertyName in propertyNames) { AddPropertyToNodeCollection(newNode.Nodes, objectType, propertyName); } } treeProperties.ExpandAll(); }
string GenerateReportOfIneligibleObjects() { if (runtimeData.ineligibleClassObjectIdsMap.Keys.Count == 0) { return(null); } StringBuilder sb = new StringBuilder(); sb.AppendLine("Some objects you picked cannot be scheduled:"); foreach (RXClass objectType in runtimeData.ineligibleClassObjectIdsMap.Keys) { sb.AppendFormat("{0} object(s) of {1}.", runtimeData.ineligibleClassObjectIdsMap[objectType].Count, ScheduleSample.GetDisplayName(objectType)); sb.AppendLine(); } return(sb.ToString()); }
void FillSourceNameList() { // nothing selected if (listObjectType.SelectedIndex == -1) { return; } listProperties.Items.Clear(); KeyValuePair <RXClass, List <ObjectId> > pair = (KeyValuePair <RXClass, List <ObjectId> >)listObjectType.Items[listObjectType.SelectedIndex]; string[] sourceNames = PropertyDataServices.FindAutomaticSourceNames(pair.Key.Name, ScheduleSample.GetDatabase()); StringCollection selectedNames = null; if (runtimeData.classPropertiesMap.ContainsKey(pair.Key)) { selectedNames = runtimeData.classPropertiesMap[pair.Key]; } foreach (string name in sourceNames) { if (selectedNames == null) { listProperties.Items.Add(name); } else { listProperties.Items.Add(name, selectedNames.Contains(name)); } } }