/// <inheritdoc />
        public override void OnGripStatusChanged(ObjectId entityId, Status newStatus)
        {
            try
            {
                // При начале перемещения запоминаем первоначальное положение ручки
                // Запоминаем начальные значения
                if (newStatus == Status.GripStart)
                {
                    _gripTmp = GripPoint;
                }

                // При удачном перемещении ручки записываем новые значения в расширенные данные
                // По этим данным я потом получаю экземпляр класса groundLine
                if (newStatus == Status.GripEnd)
                {
                    using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction())
                    {
                        var blkRef = tr.GetObject(IntellectualEntity.BlockId, OpenMode.ForWrite, true, true);
                        using (var resBuf = IntellectualEntity.GetDataForXData())
                        {
                            blkRef.XData = resBuf;
                        }

                        tr.Commit();
                    }

                    IntellectualEntity.Dispose();
                }

                // При отмене перемещения возвращаем временные значения
                if (newStatus == Status.GripAbort)
                {
                    if (_gripTmp != null)
                    {
                        if (GripIndex == 0)
                        {
                            IntellectualEntity.InsertionPoint = _gripTmp;
                        }
                        else if (GripIndex == ((ILinearEntity)IntellectualEntity).MiddlePoints.Count + 1)
                        {
                            IntellectualEntity.EndPoint = _gripTmp;
                        }
                        else
                        {
                            ((ILinearEntity)IntellectualEntity).MiddlePoints[GripIndex - 1] = _gripTmp;
                        }
                    }
                }

                base.OnGripStatusChanged(entityId, newStatus);
            }
            catch (Exception exception)
            {
                if (exception.ErrorStatus != ErrorStatus.NotAllowedForThisProxy)
                {
                    ExceptionBox.Show(exception);
                }
            }
        }
        /// <inheritdoc />
        public override ReturnValue OnHotGrip(ObjectId entityId, Context contextFlags)
        {
            using (IntellectualEntity)
            {
                Point3d?newInsertionPoint = null;

                var linearEntity = (ILinearEntity)IntellectualEntity;

                if (GripIndex == 0)
                {
                    IntellectualEntity.InsertionPoint = linearEntity.MiddlePoints[0];
                    newInsertionPoint = linearEntity.MiddlePoints[0];
                    linearEntity.MiddlePoints.RemoveAt(0);
                }
                else if (GripIndex == linearEntity.MiddlePoints.Count + 1)
                {
                    IntellectualEntity.EndPoint = linearEntity.MiddlePoints.Last();
                    linearEntity.MiddlePoints.RemoveAt(linearEntity.MiddlePoints.Count - 1);
                }
                else
                {
                    linearEntity.MiddlePoints.RemoveAt(GripIndex - 1);
                }

                IntellectualEntity.UpdateEntities();
                IntellectualEntity.BlockRecord.UpdateAnonymousBlocks();
                using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction())
                {
                    var blkRef = tr.GetObject(IntellectualEntity.BlockId, OpenMode.ForWrite, true, true);
                    if (newInsertionPoint.HasValue)
                    {
                        ((BlockReference)blkRef).Position = newInsertionPoint.Value;
                    }

                    using (var resBuf = IntellectualEntity.GetDataForXData())
                    {
                        blkRef.XData = resBuf;
                    }

                    tr.Commit();
                }
            }

            return(ReturnValue.GetNewGripPoints);
        }
Пример #3
0
        private void Property_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_isModifiedFromAutocad)
            {
                return;
            }

            Overrule.Overruling = false;
            var intellectualEntityProperty = (IntellectualEntityProperty)sender;

            try
            {
                using (AcadUtils.Document.LockDocument())
                {
                    using (var blockReference = _blkRefObjectId.Open(OpenMode.ForWrite, true, true) as BlockReference)
                    {
                        var entityType   = _intellectualEntity.GetType();
                        var propertyInfo = entityType.GetProperty(intellectualEntityProperty.Name);
                        if (propertyInfo != null)
                        {
                            if (intellectualEntityProperty.Name == "Style")
                            {
                                var style = StyleManager.GetStyleByName(entityType, intellectualEntityProperty.Value.ToString());
                                if (style != null)
                                {
                                    _intellectualEntity.ApplyStyle(style, false);
                                }
                            }
                            else if (intellectualEntityProperty.Name == "LayerName")
                            {
                                if (blockReference != null)
                                {
                                    blockReference.Layer = intellectualEntityProperty.Value.ToString();
                                }
                            }
                            else if (intellectualEntityProperty.Name == "LineType")
                            {
                                if (blockReference != null)
                                {
                                    blockReference.Linetype = intellectualEntityProperty.Value.ToString();
                                }
                            }
                            else
                            {
                                propertyInfo.SetValue(_intellectualEntity, intellectualEntityProperty.Value);
                            }

                            _intellectualEntity.UpdateEntities();
                            _intellectualEntity.GetBlockTableRecordWithoutTransaction(blockReference);
                            using (var resBuf = _intellectualEntity.GetDataForXData())
                            {
                                if (blockReference != null)
                                {
                                    blockReference.XData = resBuf;
                                }
                            }

                            if (blockReference != null)
                            {
                                blockReference.ResetBlock();
                            }
                        }
                    }
                }

                Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
            }
            catch (System.Exception exception)
            {
                if (exception.Message != "eOnLockedLayer")
                {
                    ExceptionBox.Show(exception);
                }
                else
                {
                    OnLockedLayerEventHandler?.Invoke(this, intellectualEntityProperty);
                }
            }

            Overrule.Overruling = true;
        }
Пример #4
0
        /// <inheritdoc />
        public override void OnGripStatusChanged(ObjectId entityId, Status newStatus)
        {
            if (newStatus == Status.GripStart)
            {
                AcadUtils.Editor.TurnForcedPickOn();
                AcadUtils.Editor.PointMonitor += AddNewVertex_EdOnPointMonitor;
            }

            if (newStatus == Status.GripEnd)
            {
                AcadUtils.Editor.TurnForcedPickOff();
                AcadUtils.Editor.PointMonitor -= AddNewVertex_EdOnPointMonitor;
                using (IntellectualEntity)
                {
                    Point3d?newInsertionPoint = null;

                    var linearEntity = (ILinearEntity)IntellectualEntity;

                    if (GripLeftPoint == IntellectualEntity.InsertionPoint)
                    {
                        linearEntity.MiddlePoints.Insert(0, NewPoint);
                    }
                    else if (GripLeftPoint == null)
                    {
                        linearEntity.MiddlePoints.Insert(0, IntellectualEntity.InsertionPoint);
                        IntellectualEntity.InsertionPoint = NewPoint;
                        newInsertionPoint = NewPoint;
                    }
                    else if (GripRightPoint == null)
                    {
                        linearEntity.MiddlePoints.Add(IntellectualEntity.EndPoint);
                        IntellectualEntity.EndPoint = NewPoint;
                    }
                    else
                    {
                        linearEntity.MiddlePoints.Insert(
                            linearEntity.MiddlePoints.IndexOf(GripLeftPoint.Value) + 1, NewPoint);
                    }

                    IntellectualEntity.UpdateEntities();
                    IntellectualEntity.BlockRecord.UpdateAnonymousBlocks();
                    using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction())
                    {
                        var blkRef = tr.GetObject(IntellectualEntity.BlockId, OpenMode.ForWrite, true, true);
                        if (newInsertionPoint.HasValue)
                        {
                            ((BlockReference)blkRef).Position = newInsertionPoint.Value;
                        }

                        using (var resBuf = IntellectualEntity.GetDataForXData())
                        {
                            blkRef.XData = resBuf;
                        }

                        tr.Commit();
                    }
                }
            }

            if (newStatus == Status.GripAbort)
            {
                AcadUtils.Editor.TurnForcedPickOff();
                AcadUtils.Editor.PointMonitor -= AddNewVertex_EdOnPointMonitor;
            }

            base.OnGripStatusChanged(entityId, newStatus);
        }