Example #1
0
 /// <summary>
 /// Init method called in the constructors
 /// </summary>
 private void Init()
 {
     worksheets   = new List <Worksheet>();
     styleManager = new StyleManager();
     styleManager.AddStyle(new Style.Style("default", 0, true));
     Style.Style borderStyle = new Style.Style("default_border_style", 1, true);
     borderStyle.CurrentBorder = Style.Style.BasicStyles.DottedFill_0_125.CurrentBorder;
     borderStyle.CurrentFill   = Style.Style.BasicStyles.DottedFill_0_125.CurrentFill;
     styleManager.AddStyle(borderStyle);
     workbookMetadata = new Metadata();
     shortener        = new Shortener();
 }
        // add new style
        private void BtAddNewStyle_OnClick(object sender, RoutedEventArgs e)
        {
            var selected = TvStyles.SelectedItem;

            if (selected == null)
            {
                return;
            }

            if (selected is EntityStyles entityStyles)
            {
                var newStyle = new SmartEntityStyle(entityStyles.EntityType, true)
                {
                    Name      = ModPlusAPI.Language.GetItem("h13"),
                    StyleType = StyleType.User
                };
                entityStyles.Styles.Add(newStyle);
                StyleManager.AddStyle(newStyle);
            }
            else if (selected is SmartEntityStyle style)
            {
                var newStyle = new SmartEntityStyle(style.EntityType, true)
                {
                    Name      = ModPlusAPI.Language.GetItem("h13"),
                    StyleType = StyleType.User
                };
                _styles.Single(es => es.Styles.Contains(style)).Styles.Add(newStyle);
                StyleManager.AddStyle(newStyle);
            }
        }
        private void BtCreateStyleFromEntity_OnClick(object sender, RoutedEventArgs e)
        {
            /* Созданный стиль нужно еще найти в TreeView и выбрать его, раскрыв дерево
             * для этого можно искать по гуиду, а сам поиск взять в плагине mpDwgBase
             */
            try
            {
                Hide();
                var promptEntityOptions =
                    new PromptEntityOptions($"\n{ModPlusAPI.Language.GetItem("msg3")}");
                promptEntityOptions.SetRejectMessage("\nWrong entity");
                promptEntityOptions.AllowNone = false;
                promptEntityOptions.AddAllowedClass(typeof(BlockReference), true);
                promptEntityOptions.AllowObjectOnLockedLayer = true;
                var selectionResult = AcadUtils.Document.Editor.GetEntity(promptEntityOptions);
                if (selectionResult.Status == PromptStatus.OK)
                {
                    var newStyleGuid = string.Empty;
                    using (var tr = new OpenCloseTransaction())
                    {
                        var obj = tr.GetObject(selectionResult.ObjectId, OpenMode.ForRead);
                        if (obj is BlockReference blockReference)
                        {
                            var entity   = EntityReaderService.Instance.GetFromEntity(blockReference);
                            var newStyle = new SmartEntityStyle(entity.GetType())
                            {
                                Name      = ModPlusAPI.Language.GetItem("h13"),
                                StyleType = StyleType.User,
                                Guid      = Guid.NewGuid().ToString()
                            };
                            newStyle.GetPropertiesFromEntity(entity, blockReference);
                            newStyleGuid = newStyle.Guid;
                            foreach (var entityStyles in _styles)
                            {
                                if (entityStyles.EntityType == entity.GetType())
                                {
                                    entityStyles.Styles.Add(newStyle);
                                    StyleManager.AddStyle(newStyle);
                                    break;
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(newStyleGuid))
                    {
                        SearchInTreeViewByGuid(newStyleGuid);
                    }
                }
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
            finally
            {
                Show();
            }
        }
Example #4
0
        /// <summary>
        /// Adds a style to the style manager
        /// </summary>
        /// <param name="style">Style to add</param>
        /// <returns>Returns the managed style of the style manager</returns>

        public Style AddStyle(Style style)
        {
            return(styleManager.AddStyle(style));
        }