// 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();
        }
Esempio n. 2
0
        public void ShowSample()
        {
            ObjectIdCollection ids = PickObjectSet("Please pick the objects to be scheduled:");

            if (ids.Count == 0)
            {
                return;
            }

            Dictionary <RXClass, List <ObjectId> > classDictionary           = new Dictionary <RXClass, List <ObjectId> >();
            Dictionary <RXClass, List <ObjectId> > ineligibleClassDictionary = new Dictionary <RXClass, List <ObjectId> >();
            StringCollection eligibleClassNames = new StringCollection();

            eligibleClassNames.AddRange(PropertyDataServices.FindEligibleClassNames());
            foreach (ObjectId id in ids)
            {
                if (!eligibleClassNames.Contains(id.ObjectClass.Name))
                {
                    if (!ineligibleClassDictionary.ContainsKey(id.ObjectClass))
                    {
                        ineligibleClassDictionary[id.ObjectClass] = new List <ObjectId>();
                    }

                    ineligibleClassDictionary[id.ObjectClass].Add(id);
                }
                else
                {
                    if (!classDictionary.ContainsKey(id.ObjectClass))
                    {
                        classDictionary[id.ObjectClass] = new List <ObjectId>();
                    }

                    classDictionary[id.ObjectClass].Add(id);
                }
            }

            if (classDictionary.Keys.Count == 0)
            {
                GetEditor().WriteMessage("No eligible object is selected. Schedule table sample will now quit.");
                return;
            }

            UiData runtimeData = new UiData();

            runtimeData.classObjectIdsMap           = classDictionary;
            runtimeData.ineligibleClassObjectIdsMap = ineligibleClassDictionary;
            WizardSheetPropertySetDefinition sheetPsd = new WizardSheetPropertySetDefinition();
            WizardSheetScheduleTableStyle    sheetSts = new WizardSheetScheduleTableStyle();
            WizardSheetSummary sheetSummary           = new WizardSheetSummary();
            WizardManager      wizard = new WizardManager();

            wizard.AddSheet(sheetPsd);
            wizard.AddSheet(sheetSts);
            wizard.AddSheet(sheetSummary);
            wizard.RuntimeData = runtimeData;
            if (wizard.ShowWizard() == System.Windows.Forms.DialogResult.OK)
            {
                ScheduleTableCreateResult result = ScheduleTableCreateEx.CreateScheduleTable(runtimeData);
            }
        }
 public static bool ContainsGeneralProperty(this Dictionary <string, List <RXClass> > propertyClassesMap)
 {
     foreach (string propertyName in propertyClassesMap.Keys)
     {
         if (propertyClassesMap[propertyName].Count > 1)
         {
             return(true);
         }
     }
     return(false);
 }
        public static StringCollection GetGeneralPropertyNames(this Dictionary <string, List <RXClass> > propertyClassesMap)
        {
            StringCollection propNames = new StringCollection();

            foreach (string propName in propertyClassesMap.Keys)
            {
                if (propertyClassesMap[propName].Count > 1)
                {
                    propNames.Add(propName);
                }
            }
            return(propNames);
        }
        public static Dictionary <RXClass, StringCollection> DeepClone(this Dictionary <RXClass, StringCollection> classPropertiesMap)
        {
            Dictionary <RXClass, StringCollection> newMap = new Dictionary <RXClass, StringCollection>();

            foreach (RXClass objectType in classPropertiesMap.Keys)
            {
                StringCollection propsCopy = new StringCollection();
                string[]         rawProps  = new string[classPropertiesMap[objectType].Count];
                classPropertiesMap[objectType].CopyTo(rawProps, 0);
                propsCopy.AddRange(rawProps);
                newMap[objectType] = propsCopy;
            }
            return(newMap);
        }
Esempio n. 6
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);
        }
        public static void FilterOutGeneralProperties(this Dictionary <string, List <RXClass> > propertyClassesMap, Dictionary <RXClass, StringCollection> classPropertiesMap)
        {
            StringCollection generalPropertyNames = propertyClassesMap.GetGeneralPropertyNames();

            foreach (RXClass objectType in classPropertiesMap.Keys)
            {
                for (int i = classPropertiesMap[objectType].Count - 1; i >= 0; --i)
                {
                    string prop = classPropertiesMap[objectType][i];
                    if (generalPropertyNames.Contains(prop))
                    {
                        classPropertiesMap[objectType].RemoveAt(i);
                    }
                }
            }
        }
        public static Dictionary <string, List <RXClass> > GroupClassesByProperty(this Dictionary <RXClass, StringCollection> classPropertiesMap)
        {
            Dictionary <string, List <RXClass> > propertyClassesMap = new Dictionary <string, List <RXClass> >();

            foreach (RXClass objectType in classPropertiesMap.Keys)
            {
                foreach (string propertyName in classPropertiesMap[objectType])
                {
                    if (!propertyClassesMap.ContainsKey(propertyName))
                    {
                        propertyClassesMap[propertyName] = new List <RXClass>();
                    }
                    propertyClassesMap[propertyName].Add(objectType);
                }
            }
            return(propertyClassesMap);
        }
        public static void FilterOutSingleProperties(this Dictionary <string, List <RXClass> > propertyClassesMap)
        {
            StringCollection generalPropertyNames = propertyClassesMap.GetGeneralPropertyNames();
            StringCollection singlePropertyNames  = new StringCollection();

            foreach (string prop in propertyClassesMap.Keys)
            {
                if (!generalPropertyNames.Contains(prop))
                {
                    singlePropertyNames.Add(prop);
                }
            }
            foreach (string prop in singlePropertyNames)
            {
                propertyClassesMap.Remove(prop);
            }
        }
        void GenerateColumnHeaderByObjectType(RXClass objectType, StringCollection propertyNames, TreeNodeCollection nodes)
        {
            // First we categorize the properties.
            Dictionary <string, StringCollection> categorizedProperties = new Dictionary <string, StringCollection>();

            foreach (string propertyName in propertyNames)
            {
                string catName = GetCategoryName(propertyName);
                if (!categorizedProperties.ContainsKey(catName))
                {
                    categorizedProperties[catName] = new StringCollection();
                }
                categorizedProperties[catName].Add(propertyName);
            }
            // sort category names alphabetically
            List <string> sortedCatNames = new List <string>();

            foreach (string catName in categorizedProperties.Keys)
            {
                sortedCatNames.Add(catName);
            }
            sortedCatNames.Sort();
            // create category headers
            foreach (string catName in sortedCatNames)
            {
                TreeNode headerNode = nodes.Add(catName);
                // create columns
                List <string> sortedPropNames = new List <string>();
                string[]      propNames       = new string[categorizedProperties[catName].Count];
                categorizedProperties[catName].CopyTo(propNames, 0);
                sortedPropNames.AddRange(propNames);
                sortedPropNames.Sort();
                foreach (string propName in sortedPropNames)
                {
                    AddPropertyToNodeCollection(headerNode.Nodes, objectType, propName);
                }
            }
        }
        // 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();
        }