Exemple #1
0
 private void OnClosed(object sender, EventArgs e)
 {
     UserConfigFile.SetValue(
         LevelMark.GetDescriptor().Name, ChkAlignArrowPoints.Name, ChkAlignArrowPoints.IsChecked.ToString(), true);
     UserConfigFile.SetValue(
         LevelMark.GetDescriptor().Name, ChkAlignBasePoints.Name, ChkAlignBasePoints.IsChecked.ToString(), true);
 }
        /// <inheritdoc/>
        public void CreateAnalog(SmartEntity sourceEntity, bool copyLayer)
        {
#if !DEBUG
            Statistic.SendCommandStarting(
                LevelMark.GetDescriptor().Name, ModPlusConnector.Instance.AvailProductExternalVersion);
#endif
            try
            {
                Overrule.Overruling = false;

                /* Регистрация ЕСКД приложения должна запускаться при запуске
                 * функции, т.к. регистрация происходит в текущем документе
                 * При инициализации плагина регистрации нет!
                 */
                ExtendedDataUtils.AddRegAppTableRecord(LevelMark.GetDescriptor());
                var levelMark = new LevelMark();

                var blockReference = MainFunction.CreateBlock(levelMark);

                levelMark.SetPropertiesFromSmartEntity(sourceEntity, copyLayer);

                InsertLevelMarkWithJig(levelMark, blockReference);
            }
            catch (System.Exception exception)
            {
                ExceptionBox.Show(exception);
            }
            finally
            {
                Overrule.Overruling = true;
            }
        }
        private static void CreateLevelMark()
        {
#if !DEBUG
            Statistic.SendCommandStarting(
                LevelMark.GetDescriptor().Name, ModPlusConnector.Instance.AvailProductExternalVersion);
#endif
            try
            {
                Overrule.Overruling = false;

                /* Регистрация ЕСКД приложения должна запускаться при запуске
                 * функции, т.к. регистрация происходит в текущем документе
                 * При инициализации плагина регистрации нет!
                 */
                ExtendedDataUtils.AddRegAppTableRecord(LevelMark.GetDescriptor());
                var style     = StyleManager.GetCurrentStyle(typeof(LevelMark));
                var levelMark = new LevelMark();

                var blockReference = MainFunction.CreateBlock(levelMark);
                levelMark.ApplyStyle(style, true);

                InsertLevelMarkWithJig(levelMark, blockReference);
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
            finally
            {
                Overrule.Overruling = true;
            }
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LevelMarkAlignSetup"/> class.
 /// </summary>
 public LevelMarkAlignSetup()
 {
     InitializeComponent();
     Title   = ModPlusAPI.Language.GetItem("h110");
     Closed += OnClosed;
     ChkAlignArrowPoints.IsChecked =
         !bool.TryParse(
             UserConfigFile.GetValue(LevelMark.GetDescriptor().Name, ChkAlignArrowPoints.Name), out var b) || b;
     ChkAlignBasePoints.IsChecked =
         !bool.TryParse(
             UserConfigFile.GetValue(LevelMark.GetDescriptor().Name, ChkAlignBasePoints.Name), out b) || b;
 }
        public void AlignLevelMarks()
        {
#if !DEBUG
            Statistic.SendCommandStarting("mpLevelMarkAlign", ModPlusConnector.Instance.AvailProductExternalVersion);
#endif
            try
            {
                var win = new LevelMarkAlignSetup();
                if (win.ShowDialog() != true)
                {
                    return;
                }

                var alignArrowPoints =
                    win.ChkAlignArrowPoints.IsChecked.HasValue && win.ChkAlignArrowPoints.IsChecked.Value;
                var alignBasePoints =
                    win.ChkAlignBasePoints.IsChecked.HasValue && win.ChkAlignBasePoints.IsChecked.Value;

                var pso = new PromptSelectionOptions
                {
                    // Выберите отметки уровня:
                    MessageForAdding = $"\n{Language.GetItem("msg14")}",

                    // Убрать объекты из выбора:
                    MessageForRemoval  = $"\n{Language.GetItem("msg16")}",
                    AllowSubSelections = false,
                    AllowDuplicates    = true,
                    RejectObjectsFromNonCurrentSpace = true,
                    RejectObjectsOnLockedLayers      = true
                };

                var availTypedValues = new TypedValue[1];
                availTypedValues.SetValue(
                    new TypedValue((int)DxfCode.ExtendedDataRegAppName, LevelMark.GetDescriptor().Name), 0);

                var filter = new SelectionFilter(availTypedValues);

                var selectionResult = AcadUtils.Editor.GetSelection(pso, filter);
                if (selectionResult.Status != PromptStatus.OK || selectionResult.Value.Count == 0)
                {
                    return;
                }

                var processMarksIds = selectionResult.Value.GetObjectIds();

                pso = new PromptSelectionOptions
                {
                    // Выберите эталонную отметку уровня:
                    MessageForAdding = $"\n{Language.GetItem("msg15")}",

                    // Убрать объекты из выбора:
                    MessageForRemoval  = $"\n{Language.GetItem("msg16")}",
                    AllowSubSelections = false,
                    AllowDuplicates    = true,
                    RejectObjectsFromNonCurrentSpace = true,
                    RejectObjectsOnLockedLayers      = true,
                    SingleOnly = true
                };

                selectionResult = AcadUtils.Editor.GetSelection(pso, filter);
                if (selectionResult.Status != PromptStatus.OK || selectionResult.Value.Count == 0)
                {
                    return;
                }

                var referenceMarkId = selectionResult.Value.GetObjectIds().First();

                using (AcadUtils.Document.LockDocument(DocumentLockMode.ProtectedAutoWrite, null, null, true))
                {
                    using (var tr = AcadUtils.Document.TransactionManager.StartOpenCloseTransaction())
                    {
                        var referenceMarkBlock = tr.GetObject(referenceMarkId, OpenMode.ForWrite);
                        var referenceMark      = EntityReaderService.Instance.GetFromEntity <LevelMark>(referenceMarkBlock);
                        if (referenceMark == null)
                        {
                            return;
                        }

                        foreach (var processMarkId in processMarksIds)
                        {
                            if (processMarkId == referenceMarkId)
                            {
                                continue;
                            }
                            var processMarkBlock = tr.GetObject(processMarkId, OpenMode.ForWrite);
                            var processMark      = EntityReaderService.Instance.GetFromEntity <LevelMark>(processMarkBlock);
                            if (processMark == null)
                            {
                                continue;
                            }

                            if (alignBasePoints)
                            {
                                ((BlockReference)processMarkBlock).Position = referenceMark.InsertionPoint;
                                processMark.InsertionPoint = referenceMark.InsertionPoint;
                            }

                            if (alignArrowPoints)
                            {
                                processMark.SetArrowPoint(new Point3d(
                                                              referenceMark.EndPoint.X,
                                                              processMark.EndPoint.Y,
                                                              processMark.EndPoint.Z));
                            }

                            processMark.UpdateEntities();
                            processMark.BlockRecord.UpdateAnonymousBlocks();

                            processMarkBlock.XData = processMark.GetDataForXData();
                        }

                        tr.Commit();
                    }

                    AcadUtils.Document.TransactionManager.QueueForGraphicsFlush();
                    AcadUtils.Document.TransactionManager.FlushGraphics();
                }
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
        }