コード例 #1
0
        // 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();
        }
コード例 #2
0
        // 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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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() + ")";
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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();
        }
コード例 #11
0
        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());
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        // 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();
        }
コード例 #14
0
        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());
        }
コード例 #15
0
        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));
                }
            }
        }