public ElevationByPickElements(UIApplication uiapp, ElevationCreatorSettings settings, Dictionary <int, LinkedInstanceProperties> linkedInstances, Dictionary <int, RoomElevationProperties> roomProperties)
 {
     m_app           = uiapp;
     uidoc           = m_app.ActiveUIDocument;
     m_doc           = uidoc.Document;
     toolSettings    = settings;
     linkedDocuments = linkedInstances;
     roomDictionary  = roomProperties;
 }
 public ElevationCreator(UIApplication uiapp, RoomElevationProperties rep, ElevationCreatorSettings settings, Dictionary <int, LinkedInstanceProperties> linkedInstances)
 {
     //create by room list
     m_app              = uiapp;
     m_doc              = uiapp.ActiveUIDocument.Document;
     roomProperties     = rep;
     m_room             = roomProperties.RoomObj;
     toolSettings       = settings;
     linkedDocuments    = linkedInstances;
     m_viewPlan         = toolSettings.ActiveViewPlan;
     m_viewFamilyTypeId = new ElementId(toolSettings.ViewFamilyId);
 }
        public static ElevationCreatorSettings  GetElevationCreatorSettings(Document doc)
        {
            ElevationCreatorSettings settings = new ElevationCreatorSettings();

            try
            {
                if (null == m_schema)
                {
                    m_schema = CreateSchema();
                }
                if (null != m_schema)
                {
                    IList <DataStorage> savedStorage = GetElevationCreatorSettings(doc, m_schema);
                    if (savedStorage.Count > 0)
                    {
                        DataStorage storage = savedStorage.First();
                        Entity      entity  = storage.GetEntity(m_schema);

                        settings.IsLinkedRoom         = entity.Get <bool>(m_schema.GetField(s_IsLinkedRoom));
                        settings.IsLInkedWall         = entity.Get <bool>(m_schema.GetField(s_IsLinkedWall));
                        settings.ViewFamilyId         = entity.Get <int>(m_schema.GetField(s_ViewFamilyId));
                        settings.ViewTemplateId       = entity.Get <int>(m_schema.GetField(s_ViewTemplateId));
                        settings.ScaleByTemplate      = entity.Get <bool>(m_schema.GetField(s_SacleByTemplate));
                        settings.CustomScale          = entity.Get <int>(m_schema.GetField(s_CustomRatio));
                        settings.SpaceAround          = entity.Get <int>(m_schema.GetField(s_SpaceAround));
                        settings.AIsSelected          = entity.Get <bool>(m_schema.GetField(s_AEnabled));
                        settings.BIsSelected          = entity.Get <bool>(m_schema.GetField(s_BEnabled));
                        settings.CIsSelected          = entity.Get <bool>(m_schema.GetField(s_CEnabled));
                        settings.DIsSelected          = entity.Get <bool>(m_schema.GetField(s_DEnabled));
                        settings.PrefixSelected       = entity.Get <bool>(m_schema.GetField(s_PrefixSelected));
                        settings.PrefixText           = entity.Get <string>(m_schema.GetField(s_PrefixText));
                        settings.IntermediateSelected = entity.Get <bool>(m_schema.GetField(s_IntermediateSelected));
                        settings.IntermediateText     = entity.Get <string>(m_schema.GetField(s_IntermediateText));
                        settings.ElevationSelected    = entity.Get <bool>(m_schema.GetField(s_ElevationSelected));
                        settings.ABCDSelected         = entity.Get <bool>(m_schema.GetField(s_ABCDSelected));
                        settings.SuffixSelected       = entity.Get <bool>(m_schema.GetField(s_SuffixSelected));
                        settings.SuffixText           = entity.Get <string>(m_schema.GetField(s_SuffixText));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get elevation creator settings from data storage.\n" + ex.Message, "Elevation Creator : GetElevationCreatorSettings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(settings);
        }
 public ElevationCreatorSettings(ElevationCreatorSettings settings)
 {
     isLinkedRoom         = settings.IsLinkedRoom;
     isLinkedWall         = settings.IsLInkedWall;
     viewFamilyId         = settings.ViewFamilyId;
     viewTemplateId       = settings.ViewTemplateId;
     scaleByTemplate      = settings.ScaleByTemplate;
     customScale          = settings.CustomScale;
     spaceAround          = settings.SpaceAround;
     a_isSelected         = settings.AIsSelected;
     b_isSelected         = settings.BIsSelected;
     c_isSelected         = settings.CIsSelected;
     d_isSelected         = settings.DIsSelected;
     prefixSelected       = settings.PrefixSelected;
     prefixText           = settings.PrefixText;
     intermediateSelected = settings.IntermediateSelected;
     elevationSelected    = settings.ElevationSelected;
     abcdSelected         = settings.ABCDSelected;
     suffixSelected       = settings.SuffixSelected;
     suffixText           = settings.SuffixText;
     activeViewPlan       = settings.ActiveViewPlan;
 }
        public static bool StoreElevationCreatorSettings(Document doc, ElevationCreatorSettings settings)
        {
            bool saved = false;

            try
            {
                if (null == m_schema)
                {
                    m_schema = CreateSchema();
                }

                if (null != m_schema)
                {
                    IList <DataStorage> savedStorage = GetElevationCreatorSettings(doc, m_schema);
                    if (savedStorage.Count > 0)
                    {
                        using (Transaction trans = new Transaction(doc))
                        {
                            trans.Start("Delete Data Storage");
                            try
                            {
                                DataStorage storageToDelete = savedStorage.First();
                                doc.Delete(storageToDelete.Id);
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                MessageBox.Show("Failed to delete data storage of elevation creator settings.\n" + ex.Message, "Elevation Creator : Update Data Storage", MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                        }
                    }

                    using (Transaction trans = new Transaction(doc))
                    {
                        trans.Start("Add New Storage");
                        try
                        {
                            DataStorage storage = DataStorage.Create(doc);
                            Entity      entity  = new Entity(schemaId);
                            entity.Set <bool>(s_IsLinkedRoom, settings.IsLinkedRoom);
                            entity.Set <bool>(s_IsLinkedWall, settings.IsLInkedWall);
                            entity.Set <int>(s_ViewFamilyId, settings.ViewFamilyId);
                            entity.Set <int>(s_ViewTemplateId, settings.ViewTemplateId);
                            entity.Set <bool>(s_SacleByTemplate, settings.ScaleByTemplate);
                            entity.Set <int>(s_CustomRatio, settings.CustomScale);
                            entity.Set <int>(s_SpaceAround, settings.SpaceAround);
                            entity.Set <bool>(s_AEnabled, settings.AIsSelected);
                            entity.Set <bool>(s_BEnabled, settings.BIsSelected);
                            entity.Set <bool>(s_CEnabled, settings.CIsSelected);
                            entity.Set <bool>(s_DEnabled, settings.DIsSelected);
                            entity.Set <bool>(s_PrefixSelected, settings.PrefixSelected);
                            entity.Set <string>(s_PrefixText, settings.PrefixText);
                            entity.Set <bool>(s_IntermediateSelected, settings.IntermediateSelected);
                            entity.Set <string>(s_IntermediateText, settings.IntermediateText);
                            entity.Set <bool>(s_ElevationSelected, settings.ElevationSelected);
                            entity.Set <bool>(s_ABCDSelected, settings.ABCDSelected);
                            entity.Set <bool>(s_SuffixSelected, settings.SuffixSelected);
                            entity.Set <string>(s_SuffixText, settings.SuffixText);

                            storage.SetEntity(entity);
                            trans.Commit();
                            saved = true;
                        }
                        catch (Exception ex)
                        {
                            trans.RollBack();
                            MessageBox.Show("Failed to add data storage of elevation creator settings.\n" + ex.Message, "Elevation Creator : Update Data Stroage", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save elevation creator settings in data storage.\n" + ex.Message, "Elevation Creator : StoreElevationCreatorSettings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(saved);
        }
        private void GetToolSettings()
        {
            try
            {
                toolSettings = ElevationCreatorSettingStorageUtil.GetElevationCreatorSettings(m_doc);
                radioBttnRoomLink.IsChecked = toolSettings.IsLinkedRoom;
                radioBttnWallLink.IsChecked = toolSettings.IsLInkedWall;

                for (int i = 0; i < comboBoxViewFamily.Items.Count; i++)
                {
                    ViewFamilyType vft = comboBoxViewFamily.Items[i] as ViewFamilyType;
                    if (vft.Id.IntegerValue == toolSettings.ViewFamilyId)
                    {
                        comboBoxViewFamily.SelectedIndex = i; break;
                    }
                }

                for (int i = 0; i < comboBoxViewTemplate.Items.Count; i++)
                {
                    ViewTemplateProperties vtp = comboBoxViewTemplate.Items[i] as ViewTemplateProperties;
                    if (vtp.TemplateId.IntegerValue == toolSettings.ViewTemplateId)
                    {
                        comboBoxViewTemplate.SelectedIndex = i; break;
                    }
                }

                radioBttnTemplate.IsChecked    = toolSettings.ScaleByTemplate;
                textBoxScale.Text              = toolSettings.CustomScale.ToString();
                textBoxSpace.Text              = toolSettings.SpaceAround.ToString();
                checkBoxA.IsChecked            = toolSettings.AIsSelected;
                checkBoxB.IsChecked            = toolSettings.BIsSelected;
                checkBoxC.IsChecked            = toolSettings.CIsSelected;
                checkBoxD.IsChecked            = toolSettings.DIsSelected;
                checkBoxPrefix.IsChecked       = toolSettings.PrefixSelected;
                textBoxPrefix.Text             = toolSettings.PrefixText;
                checkBoxIntermediate.IsChecked = toolSettings.IntermediateSelected;

                for (int i = 0; i < comboBoxIntermediate.Items.Count; i++)
                {
                    string itemText = comboBoxIntermediate.Items[i].ToString();
                    if (itemText == toolSettings.IntermediateText)
                    {
                        comboBoxIntermediate.SelectedIndex = i;
                    }
                }

                checkBoxElevation.IsChecked = toolSettings.ElevationSelected;
                checkBoxABCD.IsChecked      = toolSettings.ABCDSelected;
                checkBoxSuffix.IsChecked    = toolSettings.SuffixSelected;

                for (int i = 0; i < comboBoxSuffix.Items.Count; i++)
                {
                    string itemText = comboBoxSuffix.Items[i].ToString();
                    if (itemText == toolSettings.SuffixText)
                    {
                        comboBoxSuffix.SelectedIndex = i;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get Elevation Creator settings.\n" + ex.Message, "Elevation Creator: GetToolSettings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }