Exemple #1
0
 public virtual void Copy(SingleDot singleDot)
 {
     base.Copy(singleDot);
     this.P1         = singleDot.P1;
     this.GroupParam = CopyUtil.DeepCopy(singleDot.GroupParam);
     this.IsSelected = singleDot.IsSelected;
 }
Exemple #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            var pwrData = new DataCurveInfo
            {
                Data            = CopyUtil.DeepCopy(this.Model.PwrCtrlPara.PowerCurve),
                ShowAbs         = this.Model.PwrCtrlPara.ShowAbs,
                SpeedUnit       = UnitObserverFacade.Instance.SpeedUnitObserver.UnitType,
                Speed           = this.Model.CutSpeed,
                Freq            = this.Model.PulseFrequency,
                PowerPercentage = this.Model.PowerPercent
            };
            var freData = new DataCurveInfo
            {
                Data            = CopyUtil.DeepCopy(this.Model.PwrCtrlPara.FreqCurve),
                ShowAbs         = this.Model.PwrCtrlPara.ShowAbs,
                SpeedUnit       = UnitObserverFacade.Instance.SpeedUnitObserver.UnitType,
                Speed           = this.Model.CutSpeed,
                Freq            = this.Model.PulseFrequency,
                PowerPercentage = this.Model.PowerPercent
            };

            var frm = new FrmPowerEdit(pwrData, freData);

            if (frm.ShowDialog(this) == DialogResult.OK)
            {
                this.Model.PwrCtrlPara.PowerCurve.Points = CopyUtil.DeepCopy(frm.PwrData.Data.Points);
                this.Model.PwrCtrlPara.FreqCurve.Points  = CopyUtil.DeepCopy(frm.FreqData.Data.Points);
                this.InitializeCurve();
            }
        }
Exemple #3
0
 public void DoMicroConnect(List <IDrawObject> drawObjects, List <List <MicroConnectModel> > parms, bool isUpdate)
 {
     if (drawObjects == null || drawObjects.Count == 0)
     {
         return;
     }
     if (isUpdate)
     {
         var oldParams = CopyUtil.DeepCopy(drawObjects.Select(e => e.MicroConnParams).ToList());
         for (int i = 0; i < drawObjects.Count; i++)
         {
             drawObjects[i].MicroConnParams = CopyUtil.DeepCopy(parms[i]);
             drawObjects[i].Update();
         }
         if (this.undoRedoBuffer.CanCapture)
         {
             this.undoRedoBuffer.AddCommand(new EditCommandMicroConnect(drawObjects, oldParams));
         }
     }
     else
     {
         if (this.undoRedoBuffer.CanCapture)
         {
             this.undoRedoBuffer.AddCommand(new EditCommandMicroConnect(drawObjects, parms));
         }
     }
 }
        public override bool DoUndo(IModel dataModel)
        {
            var temp = CopyUtil.DeepCopy(this.curParams);

            this.curParams = CopyUtil.DeepCopy(this.oldParams);
            this.oldParams = temp;
            dataModel.DoCornerRing(this.drawObjects, this.curParams);
            return(true);
        }
Exemple #5
0
 public EditCommandSetLeadwire(List <IDrawObject> drawObjects, List <LineInOutParamsModel> leadwireModels, List <LineInOutParamsModel> leadwireModelOlds)
 {
     this.drawObjects = drawObjects;
     for (int i = 0; i < leadwireModels.Count; i++)
     {
         this.leadwireModels.Add(CopyUtil.DeepCopy(leadwireModels[i]));
     }
     this.leadwireModelOlds = leadwireModelOlds;
 }
Exemple #6
0
        public override bool DoRedo(IModel dataModel)
        {
            var temp = CopyUtil.DeepCopy(this.curParams);

            this.curParams = CopyUtil.DeepCopy(this.oldParams);
            this.oldParams = temp;
            dataModel.DoMicroConnect(this.drawObjects, this.curParams, true);
            return(true);
        }
 public FrmDeleteSmallFigure(DeleteSmallFigureModel deleteSmallFigure) : this()
 {
     this.Model = CopyUtil.DeepCopy(deleteSmallFigure);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new DeleteSmallFigureModel();
         }
         this.mvvmContext1.SetViewModel(typeof(DeleteSmallFigureModel), this.Model);
         this.InitializeBindings();
     }
 }
Exemple #8
0
 public FrmConnectKnife(ConnectKnifeModel connectKnife) : this()
 {
     this.Model = CopyUtil.DeepCopy(connectKnife);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new ConnectKnifeModel();
         }
         this.mvvmContext1.SetViewModel(typeof(ConnectKnifeModel), this.Model);
         this.InitializeBindings();
     }
 }
Exemple #9
0
 public FrmArrayAnnular(ArrayAnnularModel arrayAnnular) : this()
 {
     this.Model = CopyUtil.DeepCopy(arrayAnnular);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new ArrayAnnularModel();
         }
         this.mvvmContext1.SetViewModel(typeof(ArrayAnnularModel), this.Model);
         this.InitializeBindings();
     }
 }
Exemple #10
0
 public FrmMachineCount(MachineCountModel machineCount) : this()
 {
     this.Model = CopyUtil.DeepCopy(machineCount);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new MachineCountModel();
         }
         this.mvvmContext1.SetViewModel(typeof(MachineCountModel), this.Model);
         InitializeBindings();
     }
 }
Exemple #11
0
 public FrmAutoLayout(AutoLayoutModel autoLayout) : this()
 {
     this.Model = CopyUtil.DeepCopy(autoLayout);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new AutoLayoutModel();
         }
         this.mvvmContext1.SetViewModel(typeof(AutoLayoutModel), this.Model);
         this.InitializeBindings();
     }
 }
 public FrmCurveSmoothing(CurveSmoothingModel curveSmoothing) : this()
 {
     this.Model = CopyUtil.DeepCopy(curveSmoothing);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new CurveSmoothingModel();
         }
         this.mvvmContext1.SetViewModel(typeof(CurveSmoothingModel), this.Model);
         this.InitializeBindings();
     }
 }
Exemple #13
0
 public FrmMultiContourConnectCut(MultiContourConnectCutModel multiContourConnectCut) : this()
 {
     this.Model = CopyUtil.DeepCopy(multiContourConnectCut);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new MultiContourConnectCutModel();
         }
         this.mvvmContext1.SetViewModel(typeof(MultiContourConnectCutModel), this.Model);
         this.InitializeBindings();
     }
 }
 public FrmMergeConnectLine(MergeConnectLineModel mergeConnectLine) : this()
 {
     this.Model = CopyUtil.DeepCopy(mergeConnectLine);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new MergeConnectLineModel();
         }
         this.mvvmContext1.SetViewModel(typeof(MergeConnectLineModel), this.Model);
         this.InitializeBindings();
     }
 }
Exemple #15
0
 public FrmUserConfig(UserConfigModel userConfig) : this()
 {
     this.Model = CopyUtil.DeepCopy(userConfig);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new UserConfigModel();
         }
         this.mvvmContext1.SetViewModel(typeof(UserConfigModel), this.Model);
         InitializeBindings();
         InitializeBindings();
     }
 }
        public FigureUnit Take(string id)
        {
            FigureUnit figure = null;

            try
            {
                var temp = this.figureMap[id];
                figure = CopyUtil.DeepCopy <FigureUnit>(temp);
            }
            catch
            {
            }
            return(figure);
        }
Exemple #17
0
 public FrmLineFlyingCut(LineFlyingCutModel lineFlyingCut) : this()
 {
     this.Model = CopyUtil.DeepCopy(lineFlyingCut);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model != null)
         {
             this.mvvmContext1.SetViewModel(typeof(LineFlyingCutModel), this.Model);
         }
         else
         {
             this.Model = this.mvvmContext1.GetViewModel <LineFlyingCutModel>();
         }
         InitializeBindings();
     }
 }
Exemple #18
0
        public void DoInnerCut(List <IDrawObject> drawObjects)
        {
            if (drawObjects == null || drawObjects.Count == 0)
            {
                return;
            }
            var oldParams = CopyUtil.DeepCopy(drawObjects.Select(e => e.CompensationParam).ToList());

            for (int i = 0; i < drawObjects.Count; i++)
            {
                drawObjects[i].SetInnerCut();
            }
            if (this.undoRedoBuffer.CanCapture)
            {
                this.undoRedoBuffer.AddCommand(new EditCommandCompensation(drawObjects, oldParams));
            }
        }
Exemple #19
0
        private static List <IDrawObject> ConvertToMultiSegLine(Circle circle, List <BridgePoints> bridges)
        {
            List <IDrawObject> retObjects = new List <IDrawObject>();

            if (bridges.Count == 2)
            {
                bridges[0].Point2.Bulge = BulgeHelper.GetBulgeFromTwoPointsAndCenter(circle.Center, bridges[0].Point2.Point, bridges[1].Point1.Point, circle.IsClockwise);;
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = circle.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(circle.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        bridges[0].Point2, bridges[1].Point1
                    }
                });

                bridges[1].Point2.Bulge = BulgeHelper.GetBulgeFromTwoPointsAndCenter(circle.Center, bridges[1].Point2.Point, bridges[0].Point1.Point, circle.IsClockwise);;
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = circle.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(circle.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        bridges[1].Point2, bridges[0].Point1
                    }
                });
            }
            else if (bridges.Count == 1)
            {
                bridges[0].Point2.Bulge = BulgeHelper.GetBulgeFromTwoPointsAndCenter(circle.Center, bridges[0].Point2.Point, bridges[0].Point1.Point, circle.IsClockwise);;
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = circle.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(circle.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        bridges[0].Point2, bridges[0].Point1
                    }
                });
            }
            return(retObjects);
        }
Exemple #20
0
        public void DoCornerRing(List <IDrawObject> drawObjects, List <CornerRingModel> parms)
        {
            if (drawObjects == null || drawObjects.Count == 0)
            {
                return;
            }
            var oldParams = CopyUtil.DeepCopy(drawObjects.Select(e => e.CornerRingParam).ToList());

            for (int i = 0; i < drawObjects.Count; i++)
            {
                ((IDrawTranslation)drawObjects[i]).DoCornerRing(parms[i]);
            }
            if (this.undoRedoBuffer.CanCapture)
            {
                this.undoRedoBuffer.AddCommand(new EditCommandCornerRing(drawObjects, oldParams));
            }
        }
Exemple #21
0
 public FrmArrayRectangle(ArrayRectangleModel arrayLayout) : this()
 {
     this.Model = CopyUtil.DeepCopy(arrayLayout);
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new ArrayRectangleModel();
         }
         Model.RowCount             = 4; Model.ColumnCount = 4;
         Model.OffsetType           = ArrayOffsetTypes.Spacing;
         Model.OffsetRow            = 0.05; Model.OffsetColumn = 0.05;
         Model.ArrayRowDirection    = ArrayRowDirections.Bottom;
         Model.ArrayColumnDirection = ArrayColumnDirections.Right;
         this.mvvmContext1.SetViewModel(typeof(ArrayRectangleModel), this.Model);
         this.InitializeBindings();
     }
 }
Exemple #22
0
 public FrmBridging(BridgingModel bridging) : this()
 {
     this.Model = CopyUtil.DeepCopy(bridging);
     if (this.Model.MaxDistance == 0)
     {
         this.Model.MaxDistance = 100;
     }
     if (this.Model.Width == 0)
     {
         this.Model.Width = 10;
     }
     if (!this.mvvmContext1.IsDesignMode)
     {
         if (this.Model == null)
         {
             this.Model = new BridgingModel();
         }
         this.mvvmContext1.SetViewModel(typeof(BridgingModel), this.Model);
         this.InitializeBindings();
     }
 }
 public EditCommandCornerRing(List <IDrawObject> drawObjects, List <CornerRingModel> oldParams)
 {
     this.drawObjects = drawObjects;
     this.curParams   = CopyUtil.DeepCopy(drawObjects.Select(e => e.CornerRingParam).ToList());
     this.oldParams   = CopyUtil.DeepCopy(oldParams);
 }
        private void MouseDownSetStartMovePoint(MouseEventArgs e)
        {
            UnitPoint   mousePoint = this.ToUnit(this.mouseDownPoint);
            IDrawObject hitObject  = this.Model.GetHitObject(mousePoint);

            if (hitObject != null && leadLineDone && hitObject.IsCloseFigure)
            {
                LineInOutParamsModel leadInOutParamsModel = CopyUtil.DeepCopy(hitObject.LeadInOutParams);
                leadInOutParamsModel.LinePosition      = LinePositions.FigureTotalLength;
                leadInOutParamsModel.FigureTotalLength = this.CalPercentByPoint(hitObject, mousePoint);
                this.Model.DoSetLeadwire(new List <IDrawObject>()
                {
                    hitObject
                }, new List <LineInOutParamsModel>()
                {
                    leadInOutParamsModel
                });
                this.DoInvalidate(true);
            }
            else//绘制引入线
            {
                if (this.leadLine == null)
                {
                    this.leadLine     = new LeadLine(mousePoint);
                    this.leadLineDone = false;
                }
                else
                {
                    if (hitObject != null)
                    {
                        LineInOutParamsModel leadInOutParamsModel = CopyUtil.DeepCopy(hitObject.LeadInOutParams);
                        leadInOutParamsModel.LinePosition = LinePositions.FigureTotalLength;
                        leadInOutParamsModel.LineInType   = CommomModel.DrawModel.LeadLine.LeadLineType.Line;
                        if (hitObject.IsCloseFigure)
                        {
                            DrawObjectMouseDown result = this.leadLine.OnMouseDown(mousePoint);
                            this.leadLine.CalLeadLineParams(hitObject, leadInOutParamsModel);
                            this.Model.DoSetLeadwire(new List <IDrawObject>()
                            {
                                hitObject
                            }, new List <LineInOutParamsModel>()
                            {
                                leadInOutParamsModel
                            });
                        }
                        else if (HitUtil.PointInPoint(mousePoint, hitObject.FirstDrawPoint, GetThresholdWidth()))
                        {
                            DrawObjectMouseDown result = this.leadLine.OnMouseDown(hitObject.FirstDrawPoint);
                            this.leadLine.CalLeadLineParams(hitObject, leadInOutParamsModel);
                            this.Model.DoSetLeadwire(new List <IDrawObject>()
                            {
                                hitObject
                            }, new List <LineInOutParamsModel>()
                            {
                                leadInOutParamsModel
                            });
                        }
                        this.leadLine     = null;
                        this.leadLineDone = true;
                    }
                    else
                    {
                        this.leadLine = new LeadLine(mousePoint);
                    }
                    this.DoInvalidate(true);
                }
            }
        }
Exemple #25
0
        public bool TrySpilt(PointF point, out List <DataUnit> items)
        {
            int index = -1;

            items = new List <DataUnit>();
            if (this.Points.Count > 1)
            {
                for (int i = 0; i < this.Points.Count - 1; i++)
                {
                    var p1 = this.Points[i];
                    var p2 = this.Points[i + 1];

                    if (MathEx.IsInLine(point, p1, p2))
                    {
                        index = i;
                        break;
                    }

                    //if (MathEx.IsInLine(point, p1, p2))
                    //{
                    //    //double k1 = MathEx.GetSlope(p1, point);
                    //    //double k2 = MathEx.GetSlope(point, p2);
                    //    //if (Math.Abs(k1 - k2) < 0.001 || (double.IsInfinity(k1) && double.IsInfinity(k2)))
                    //    //{
                    //        index = i;
                    //        break;
                    //    //}
                    //}

                    //bool condition1 = point.X >= p1.X && point.X <= p2.X;
                    //bool condition2 = point.X <= p1.X && point.X >= p2.X;

                    //if (condition1 || condition2)
                    //{
                    //    double k1 = MathEx.GetSlope(p1, point);
                    //    double k2 = MathEx.GetSlope(point, p2);
                    //    if (Math.Abs(k1 - k2) < 0.001 || (double.IsInfinity(k1) && double.IsInfinity(k2)))
                    //    {
                    //        index = i;
                    //        break;
                    //    }
                    //}
                }
            }
            if (index != -1)
            {
                var tmp1 = this.Points.GetRange(0, index + 1);
                tmp1.Add(point);
                var tmp2 = this.Points.GetRange(index + 1, this.Points.Count - (index + 1));
                tmp2.Insert(0, point);

                var part1 = CopyUtil.DeepCopy(this);
                part1.Points = tmp1;
                part1.Length = MathEx.GetDistance(part1.Points);
                var part2 = CopyUtil.DeepCopy(this);
                part2.Points = tmp2;
                part2.Length = MathEx.GetDistance(part2.Points);

                items.Add(part1);
                items.Add(part2);
            }
            return(index != -1);
        }
Exemple #26
0
 private void chartControlCurve_OnCurveDataChanged(object sender, OnCurveChangedEventArgs e)
 {
     this.Curve.Data.Points = CopyUtil.DeepCopy(e.CurveData);
     this.InitializeCurve();
 }
Exemple #27
0
        private static List <IDrawObject> ConvertToMultiSegLine(MultiSegmentLineBase multiSegLine, List <BridgePoints> bridges)
        {
            List <IDrawObject>    retObjects   = new List <IDrawObject>();
            double                totalLength  = 0;
            List <MicroUnitPoint> microTemps   = MicroConnectHelper.InitMicroUnitPoint(multiSegLine.Points, multiSegLine.IsCloseFigure, out totalLength);
            List <MicroUnitPoint> microBridges = new List <MicroUnitPoint>();

            microTemps.ForEach(e => e.Point.IsBasePoint = true);

            #region 位置点计算长度
            foreach (BridgePoints point in bridges)
            {
                //第一个位置点
                MicroUnitPoint startPoint = microTemps[(int)point.Point1.Position];
                MicroUnitPoint endPoint   = microTemps[(int)point.Point1.Position + 1 > microTemps.Count - 1 ? 0 : (int)point.Point1.Position + 1];
                double         length     = 0;
                if (!double.IsNaN(startPoint.Point.Bulge))
                {
                    var    arcMini = DrawingOperationHelper.GetArcParametersFromBulge(startPoint.Point.Point, endPoint.Point.Point, (float)startPoint.Point.Bulge);
                    double bulge   = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arcMini.Center, startPoint.Point.Point, point.Point1.Point, arcMini.Clockwise);
                    var    arcNew  = DrawingOperationHelper.GetArcParametersFromBulge(startPoint.Point.Point, point.Point1.Point, (float)bulge);
                    length = DrawingOperationHelper.GetArcLength(arcNew.Radius, arcNew.SweepAngle);
                }
                else
                {
                    length = HitUtil.Distance(startPoint.Point.Point, point.Point1.Point);
                }
                microBridges.Add(new MicroUnitPoint()
                {
                    Point       = point.Point1,
                    OwerPos     = (int)point.Point1.Position,
                    StartLength = startPoint.StartLength + length,
                    Flags       = MicroConnectFlags.None
                });
                //第二个位置点
                startPoint = microTemps[(int)point.Point2.Position];
                endPoint   = microTemps[(int)point.Point2.Position + 1 > microTemps.Count - 1 ? 0 : (int)point.Point2.Position + 1];
                if (!double.IsNaN(startPoint.Point.Bulge))
                {
                    var    arcMini = DrawingOperationHelper.GetArcParametersFromBulge(startPoint.Point.Point, endPoint.Point.Point, (float)startPoint.Point.Bulge);
                    double bulge   = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arcMini.Center, startPoint.Point.Point, point.Point2.Point, arcMini.Clockwise);
                    var    arcNew  = DrawingOperationHelper.GetArcParametersFromBulge(startPoint.Point.Point, point.Point2.Point, (float)bulge);
                    length = DrawingOperationHelper.GetArcLength(arcMini.Radius, arcNew.SweepAngle);
                }
                else
                {
                    length = HitUtil.Distance(startPoint.Point.Point, point.Point2.Point);
                }
                microBridges.Add(new MicroUnitPoint()
                {
                    Point       = point.Point2,
                    OwerPos     = (int)point.Point2.Position,
                    StartLength = startPoint.StartLength + length,
                    Flags       = MicroConnectFlags.None
                });
            }
            #endregion

            #region 排序,相当于在合适的位置插入位置点
            microTemps.AddRange(microBridges);
            microTemps.Sort((x, y) => { if (x.StartLength > y.StartLength)
                                        {
                                            return(1);
                                        }
                                        return(-1); });
            #endregion

            #region 更新bulge
            for (int i = 0; i < microTemps.Count; i++)
            {
                int iNext = i + 1 >= microTemps.Count ? 0 : i + 1;
                if (!double.IsNaN(microTemps[i].Point.Bulge) &&
                    (!microTemps[i].Point.IsBasePoint || !microTemps[iNext].Point.IsBasePoint))
                {
                    int          mIndex = microTemps[i].Point.IsBasePoint ? microTemps[i].OwerPos : (int)microTemps[i].Point.Position;
                    int          mNext  = mIndex + 1 >= multiSegLine.Points.Count ? 0 : mIndex + 1;
                    ArcModelMini arc    = DrawingOperationHelper.GetArcParametersFromBulge(multiSegLine.Points[mIndex].Point, multiSegLine.Points[mNext].Point, (float)multiSegLine.Points[mIndex].Bulge);
                    microTemps[i].Point.Bulge = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arc.Center, microTemps[i].Point.Point, microTemps[iNext].Point.Point, arc.Clockwise);
                }
            }
            #endregion

            #region 更新断开的位置标志
            bridges.ForEach(e =>
            {
                int startIndex = microTemps.FindIndex(m => m.Point == e.Point1);
                int endIndex   = microTemps.FindIndex(m => m.Point == e.Point2);
                if (startIndex > endIndex)
                {
                    var points1 = microTemps.GetRange(startIndex, microTemps.Count - startIndex);
                    var points2 = microTemps.GetRange(0, endIndex);
                    points1.ForEach(p => p.Point.HasMicroConn = true);
                    points2.ForEach(p => p.Point.HasMicroConn = true);
                }
                else
                {
                    var points = microTemps.GetRange(startIndex, endIndex - startIndex);
                    points.ForEach(p => p.Point.HasMicroConn = true);
                }
            });
            #endregion

            #region 转换为多段线
            MultiSegmentLineBase lwPolyLine = null;
            for (int i = 0; i < microTemps.Count; i++)
            {
                if (microTemps[i].Point.HasMicroConn)
                {
                    if (lwPolyLine != null)
                    {
                        microTemps[i].Point.HasMicroConn = false;
                        lwPolyLine.Points.Add(microTemps[i].Point);
                        retObjects.Add(lwPolyLine);
                        lwPolyLine = null;
                    }
                }
                else
                {
                    if (lwPolyLine == null)
                    {
                        lwPolyLine = new MultiSegmentLineBase()
                        {
                            IsCloseFigure = false,
                            LayerId       = multiSegLine.LayerId,
                            GroupParam    = CopyUtil.DeepCopy(multiSegLine.GroupParam),
                            Points        = new List <UnitPointBulge>()
                        };
                    }
                    lwPolyLine.Points.Add(microTemps[i].Point);
                }
            }
            if (lwPolyLine != null)
            {
                if (multiSegLine.IsCloseFigure)
                {
                    (retObjects[0] as MultiSegmentLineBase).Points.InsertRange(0, lwPolyLine.Points);
                }
                else
                {
                    retObjects.Add(lwPolyLine);
                }
            }
            #endregion

            return(retObjects);
        }
Exemple #28
0
 public EditCommandMicroConnect(List <IDrawObject> drawObjects, List <List <MicroConnectModel> > oldParams)
 {
     this.drawObjects = drawObjects;
     this.curParams   = CopyUtil.DeepCopy(drawObjects.Select(e => e.MicroConnParams).ToList());
     this.oldParams   = CopyUtil.DeepCopy(oldParams);
 }
Exemple #29
0
        public static List <IDrawObject> GetBridgeObjects(List <IDrawObject> drawObjects, UnitPoint p1, UnitPoint p2, BridgingModel param, out bool isChanged)
        {
            isChanged = false;//桥接是否改变了图形
            List <BridgePoints> bridgePoints = new List <BridgePoints>();

            #region 计算桥接点在图形中的点的坐标
            drawObjects?.ForEach(drawObject =>
            {
                if ((drawObject.FigureType == FigureTypes.Circle))
                {
                    Circle circle = drawObject as Circle;
                    var bridges   = BridgeHelper.GetBridgeByCircle(circle, p1, p2, param);
                    bridgePoints.AddRange(bridges);
                }
                else if (drawObject.FigureType == FigureTypes.Arc)
                {
                    ArcBase arc = drawObject as ArcBase;
                    var bridges = BridgeHelper.GetBridgeByArc(arc, p1, p2, param);
                    bridgePoints.AddRange(bridges);
                }
                else if (drawObject.FigureType == FigureTypes.LwPolyline)
                {
                    MultiSegmentLineBase multiSegLine = drawObject as MultiSegmentLineBase;
                    var bridges = BridgeHelper.GetBridgeByMultiSegLine(multiSegLine, p1, p2, param);
                    bridgePoints.AddRange(bridges);
                }
            });
            #endregion

            #region 根据桥接点坐标,按直线的起点距离排序,如果奇数个将移除最后一个,保证偶数个可以连接
            bridgePoints.Sort((x, y) => { if (x.Distance > y.Distance)
                                          {
                                              return(1);
                                          }
                                          return(-1); });
            if (bridgePoints.Count % 2 == 1)
            {
                bridgePoints.RemoveAt(bridgePoints.Count - 1);
            }
            #endregion

            #region 移除间距大于最大条件的点
            List <BridgePoints> removes = new List <BridgePoints>();
            for (int i = 0; i < bridgePoints.Count - 1; i += 2)
            {
                var bridge1 = bridgePoints[i];
                var bridge2 = bridgePoints[i + 1];
                if (Math.Abs(bridge1.Distance - bridge2.Distance) > param.MaxDistance)
                {
                    removes.Add(bridge1);
                    removes.Add(bridge2);
                }
            }
            removes.ForEach(e => bridgePoints.Remove(e));
            #endregion

            if (bridgePoints.Count > 0)
            {
                List <IDrawObject> temps    = new List <IDrawObject>(); //计算后的图形
                List <IDrawObject> oldDraws = new List <IDrawObject>(); //不用计算的原图

                #region 根据桥接点的位置把原图形拆为多段线
                foreach (IDrawObject drawObject in drawObjects)
                {
                    var points = bridgePoints.FindAll(b => b.Owner == drawObject);
                    if (points.Count > 0)
                    {
                        List <IDrawObject> draws = null;
                        if (drawObject.FigureType == FigureTypes.Circle)
                        {
                            draws = BridgeHelper.ConvertToMultiSegLine(drawObject as Circle, points);
                        }
                        else if (drawObject.FigureType == FigureTypes.Arc)
                        {
                            draws = BridgeHelper.ConvertToMultiSegLine(drawObject as ArcBase, points);
                        }
                        else if (drawObject.FigureType == FigureTypes.LwPolyline)
                        {
                            draws = BridgeHelper.ConvertToMultiSegLine(drawObject as MultiSegmentLineBase, points);
                        }
                        if (draws != null)
                        {
                            draws.RemoveAll(p => (p as MultiSegmentLineBase).Points.Count < 2);
                            temps.AddRange(draws);
                        }
                    }
                    else
                    {
                        oldDraws.Add(drawObject);
                    }
                }
                #endregion

                #region 连接最新的桥接图形
                for (int i = 0; i < bridgePoints.Count - 1; i += 2)
                {
                    var                  bridge1    = bridgePoints[i];
                    var                  bridge2    = bridgePoints[i + 1];
                    bool                 clockwise1 = HitUtil.IsClockwiseByCross(p1, p2, bridge1.Point1.Point);
                    bool                 clockwise2 = HitUtil.IsClockwiseByCross(p1, p2, bridge2.Point1.Point);
                    UnitPointBulge       point11    = !clockwise1 ? bridge1.Point1 : bridge1.Point2;
                    UnitPointBulge       point12    = clockwise1 ? bridge1.Point1 : bridge1.Point2;
                    UnitPointBulge       point21    = !clockwise2 ? bridge2.Point1 : bridge2.Point2;
                    UnitPointBulge       point22    = clockwise2 ? bridge2.Point1 : bridge2.Point2;
                    MultiSegmentLineBase draw11     = temps.Find(d => (d as MultiSegmentLineBase).Points.Contains(point11)) as MultiSegmentLineBase;
                    MultiSegmentLineBase draw12     = temps.Find(d => (d as MultiSegmentLineBase).Points.Contains(point12)) as MultiSegmentLineBase;
                    MultiSegmentLineBase draw21     = temps.Find(d => (d as MultiSegmentLineBase).Points.Contains(point21)) as MultiSegmentLineBase;
                    MultiSegmentLineBase draw22     = temps.Find(d => (d as MultiSegmentLineBase).Points.Contains(point22)) as MultiSegmentLineBase;
                    if (draw11 == null)
                    {
                        draw11 = new MultiSegmentLineBase()
                        {
                            LayerId = (bridge1.Owner as DrawObjectBase).LayerId, GroupParam = CopyUtil.DeepCopy(bridge1.Owner.GroupParam), Points = new List <UnitPointBulge>()
                        };
                    }
                    if (draw12 == null)
                    {
                        draw12 = new MultiSegmentLineBase()
                        {
                            LayerId = (bridge1.Owner as DrawObjectBase).LayerId, GroupParam = CopyUtil.DeepCopy(bridge1.Owner.GroupParam), Points = new List <UnitPointBulge>()
                        };
                    }
                    if (draw21 == null)
                    {
                        draw21 = new MultiSegmentLineBase()
                        {
                            LayerId = (bridge2.Owner as DrawObjectBase).LayerId, GroupParam = CopyUtil.DeepCopy(bridge2.Owner.GroupParam), Points = new List <UnitPointBulge>()
                        };
                    }
                    if (draw22 == null)
                    {
                        draw22 = new MultiSegmentLineBase()
                        {
                            LayerId = (bridge2.Owner as DrawObjectBase).LayerId, GroupParam = CopyUtil.DeepCopy(bridge2.Owner.GroupParam), Points = new List <UnitPointBulge>()
                        };
                    }
                    #region 组合多段线
                    if (draw11 == draw12 && draw21 == draw22)
                    {
                        if (draw11.Points.Count > 0 && draw11.Points[0] == point11)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw21.Points.Count > 0 && draw21.Points[0] != point21)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw11.Points.Count > 0)
                        {
                            draw11.Points[draw11.Points.Count - 1].Bulge = double.NaN;
                        }
                        if (draw21.Points.Count > 0)
                        {
                            draw21.Points[draw21.Points.Count - 1].Bulge = double.NaN;
                        }
                        draw11.Points.AddRange(draw21.Points);
                        draw11.IsCloseFigure = true;
                        temps.Remove(draw21);
                    }
                    else if (draw11 == draw12 && draw21 != draw22)
                    {
                        if (draw21.Points.Count > 0 && draw21.Points[0] == point21)
                        {
                            draw21.ReverseDirection();
                        }
                        if (draw22.Points.Count > 0 && draw22.Points[0] != point22)
                        {
                            draw22.ReverseDirection();
                        }
                        if (draw11.Points.Count > 0 && draw11.Points[0] != point11)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw21.Points.Count > 0)
                        {
                            draw21.Points[draw21.Points.Count - 1].Bulge = double.NaN;
                        }
                        if (draw11.Points.Count > 0)
                        {
                            draw11.Points[draw11.Points.Count - 1].Bulge = double.NaN;
                        }
                        draw21.Points.AddRange(draw11.Points);
                        draw21.Points.AddRange(draw22.Points);
                        temps.Remove(draw11);
                        temps.Remove(draw22);
                    }
                    else if (draw11 != draw12 && draw21 == draw22)
                    {
                        if (draw11.Points.Count > 0 && draw11.Points[0] == point11)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw21.Points.Count > 0 && draw21.Points[0] != point21)
                        {
                            draw21.ReverseDirection();
                        }
                        if (draw12.Points.Count > 0 && draw12.Points[0] != point12)
                        {
                            draw12.ReverseDirection();
                        }
                        if (draw11.Points.Count > 0)
                        {
                            draw11.Points[draw11.Points.Count - 1].Bulge = double.NaN;
                        }
                        if (draw21.Points.Count > 0)
                        {
                            draw21.Points[draw21.Points.Count - 1].Bulge = double.NaN;
                        }
                        draw11.Points.AddRange(draw21.Points);
                        draw11.Points.AddRange(draw12.Points);
                        temps.Remove(draw21);
                        temps.Remove(draw12);
                    }
                    else if (draw11 == draw21 && draw12 == draw22)
                    {
                        if (draw11.Points.Count > 0 && draw11.Points[0] != point11)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw12.Points.Count > 0 && draw12.Points[0] != point12)
                        {
                            draw12.ReverseDirection();
                        }
                        if (draw11.Points.Count > 0)
                        {
                            draw11.Points[draw11.Points.Count - 1].Bulge = double.NaN;
                        }
                        if (draw12.Points.Count > 0)
                        {
                            draw12.Points[draw12.Points.Count - 1].Bulge = double.NaN;
                        }
                        draw11.IsCloseFigure = true;
                        draw12.IsCloseFigure = true;
                    }
                    else if (draw11 == draw21 && draw12 != draw22)
                    {
                        if (draw11.Points.Count > 0 && draw11.Points[0] != point11)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw12.Points.Count > 0 && draw12.Points[0] == point12)
                        {
                            draw12.ReverseDirection();
                        }
                        if (draw22.Points.Count > 0 && draw22.Points[0] != point22)
                        {
                            draw22.ReverseDirection();
                        }
                        if (draw11.Points.Count > 0)
                        {
                            draw11.Points[draw11.Points.Count - 1].Bulge = double.NaN;
                        }
                        if (draw12.Points.Count > 0)
                        {
                            draw12.Points[draw12.Points.Count - 1].Bulge = double.NaN;
                        }
                        draw11.IsCloseFigure = true;
                        draw12.Points.AddRange(draw22.Points);
                        temps.Remove(draw22);
                    }
                    else if (draw11 != draw21 && draw12 == draw22)
                    {
                        if (draw12.Points.Count > 0 && draw12.Points[0] != point12)
                        {
                            draw12.ReverseDirection();
                        }
                        if (draw11.Points.Count > 0 && draw11.Points[0] == point11)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw21.Points.Count > 0 && draw21.Points[0] != point21)
                        {
                            draw21.ReverseDirection();
                        }
                        if (draw12.Points.Count > 0)
                        {
                            draw12.Points[draw12.Points.Count - 1].Bulge = double.NaN;
                        }
                        if (draw11.Points.Count > 0)
                        {
                            draw11.Points[draw11.Points.Count - 1].Bulge = double.NaN;
                        }
                        draw12.IsCloseFigure = true;
                        draw11.Points.AddRange(draw21.Points);
                        temps.Remove(draw21);
                    }
                    else
                    {
                        if (draw11.Points.Count > 0 && draw11.Points[0] == point11)
                        {
                            draw11.ReverseDirection();
                        }
                        if (draw21.Points.Count > 0 && draw21.Points[0] != point21)
                        {
                            draw21.ReverseDirection();
                        }
                        if (draw12.Points.Count > 0 && draw12.Points[0] == point12)
                        {
                            draw12.ReverseDirection();
                        }
                        if (draw22.Points.Count > 0 && draw22.Points[0] != point22)
                        {
                            draw22.ReverseDirection();
                        }
                        if (draw11.Points.Count > 0)
                        {
                            draw11.Points[draw11.Points.Count - 1].Bulge = double.NaN;
                        }
                        if (draw12.Points.Count > 0)
                        {
                            draw12.Points[draw12.Points.Count - 1].Bulge = double.NaN;
                        }
                        draw11.Points.AddRange(draw21.Points);
                        draw12.Points.AddRange(draw22.Points);
                        temps.Remove(draw21);
                        temps.Remove(draw22);
                    }
                    #endregion
                }
                #endregion

                isChanged = true;
                temps.ForEach(d => d.Update());
                temps.AddRange(oldDraws);
                return(temps);
            }
            return(drawObjects);
        }
Exemple #30
0
        private static List <IDrawObject> ConvertToMultiSegLine(ArcBase arc, List <BridgePoints> bridges)
        {
            List <IDrawObject> retObjects = new List <IDrawObject>();

            if (bridges.Count == 2)
            {
                double angle1 = HitUtil.LineAngleR(arc.Center, bridges[0].Point1.Point, 0);
                double angle2 = HitUtil.LineAngleR(arc.Center, bridges[1].Point1.Point, 0);
                angle1 = HitUtil.CalAngleSweep(arc.StartAngle, HitUtil.RadiansToDegrees(angle1), arc.IsClockwise);
                angle2 = HitUtil.CalAngleSweep(arc.StartAngle, HitUtil.RadiansToDegrees(angle2), arc.IsClockwise);
                if (angle1 > angle2)
                {
                    bridges.Reverse();
                }

                double bulge1 = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arc.Center, arc.startPoint, bridges[0].Point1.Point, arc.IsClockwise);
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = arc.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(arc.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        new UnitPointBulge(arc.startPoint, bulge1), bridges[0].Point1
                    }
                });

                bridges[0].Point2.Bulge = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arc.Center, bridges[0].Point2.Point, bridges[1].Point1.Point, arc.IsClockwise);;
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = arc.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(arc.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        bridges[0].Point2, bridges[1].Point1
                    }
                });

                bridges[1].Point2.Bulge = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arc.Center, bridges[1].Point2.Point, arc.endPoint, arc.IsClockwise);;
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = arc.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(arc.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        bridges[1].Point2, new UnitPointBulge(arc.endPoint, bridges[1].Point2.Bulge)
                    }
                });
            }
            else if (bridges.Count == 1)
            {
                double bulge1 = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arc.Center, arc.startPoint, bridges[0].Point1.Point, arc.IsClockwise);
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = arc.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(arc.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        new UnitPointBulge(arc.startPoint, bulge1), bridges[0].Point1
                    }
                });

                bridges[0].Point2.Bulge = BulgeHelper.GetBulgeFromTwoPointsAndCenter(arc.Center, bridges[0].Point2.Point, arc.endPoint, arc.IsClockwise);;
                retObjects.Add(new MultiSegmentLineBase()
                {
                    IsCloseFigure = false,
                    LayerId       = arc.LayerId,
                    GroupParam    = CopyUtil.DeepCopy(arc.GroupParam),
                    Points        = new List <UnitPointBulge>()
                    {
                        bridges[0].Point2, new UnitPointBulge(arc.endPoint, bridges[0].Point2.Bulge)
                    }
                });
            }
            return(retObjects);
        }