Ejemplo n.º 1
0
        public void ConvertToPolyline()
        {
            List <IFigure> newPolyLinePoints = new List <IFigure>();
            List <IFigure> verticesToDelete  = new List <IFigure>();

            using (Drawing.ActionManager.CreateTransaction())
            {
                foreach (var vertex in this.Dependencies)
                {
                    IPoint    vertexPoint    = vertex as IPoint;
                    FreePoint newVertexPoint = Factory.CreateFreePoint(this.Drawing, vertexPoint.Coordinates);
                    Actions.Add(Drawing, newVertexPoint);
                    verticesToDelete.Add(vertexPoint);
                    newPolyLinePoints.Add(newVertexPoint);
                }

                // add last point
                newPolyLinePoints.Add(newPolyLinePoints[0]);
                Polyline newPolyline = Factory.CreatePolyline(this.Drawing, newPolyLinePoints);
                Actions.Add(Drawing, newPolyline);
                // delete main shape
                Actions.Remove(this);
                foreach (var vertexToDelete in verticesToDelete)
                {
                    Actions.Remove(vertexToDelete);
                }
            }
        }
Ejemplo n.º 2
0
        void JoinSegments(FreePoint point)
        {
            var dependents = point.Dependents.OfType <Segment>().ToArray();

            if (dependents.Length != 2)
            {
                return;
            }
            var line1 = dependents[0];
            var line2 = dependents[1];

            var otherPoint1 = line1.Dependencies.Without(point).FirstOrDefault();
            var otherPoint2 = line2.Dependencies.Without(point).FirstOrDefault();

            if (otherPoint1 == null || otherPoint2 == null)
            {
                return;
            }

            var segment = Factory.CreateSegment(Drawing, new[] { otherPoint1, otherPoint2 });

            using (Drawing.ActionManager.CreateTransaction())
            {
                RemovePointFromPolygons(point);
                Actions.Remove(line2);
                Actions.ReplaceWithNew(line1, segment);
                Actions.Remove(point);
            }
        }
Ejemplo n.º 3
0
        void ProcessPoint(IniFile.Section section)
        {
            var type         = section.ReadInt("Type");
            var parentFigure = section["ParentFigure"];

            if (!parentFigure.IsEmpty())
            {
                EnsureSectionProcessed("Figure" + parentFigure);
                return;
            }

            if (type == 8)
            {
                FindAndProcessArcWithPoint(section.GetTitleNumber("Point"));
                return;
            }

            if (type == 9)
            {
                FindAndProcessMidPoint(section.GetTitleNumber("Point"));
                return;
            }

            var       x     = section.ReadDouble("X");
            var       y     = section.ReadDouble("Y");
            FreePoint point = Factory.CreateFreePoint(drawing, new Point(x, y));

            point.Name = section["Name"];
            SetPointStyle(section, point);
            Actions.Add(drawing, point);
            int pointIndex = section.GetTitleNumber("Point");

            points[pointIndex] = point;
        }
Ejemplo n.º 4
0
        private static bool TearOff(ParallelLine parallelLine)
        {
            if (parallelLine == null)
            {
                return(false);
            }

            Drawing       drawing     = parallelLine.Drawing;
            PointPair     coordinates = parallelLine.Coordinates;
            FreePoint     point1      = Factory.CreateFreePoint(drawing, coordinates.P1);
            FreePoint     point2      = Factory.CreateFreePoint(drawing, coordinates.P2);
            LineTwoPoints line        = Factory.CreateLineTwoPoints(drawing, new[] { point1, point2 });

            using (drawing.ActionManager.CreateTransaction())
            {
                Actions.Add(drawing, point1);
                Actions.Add(drawing, point2);
                Actions.Add(drawing, line);
                Actions.ReplaceWithExisting(parallelLine, line);
                Actions.Remove(parallelLine);
            }

            drawing.RaiseDisplayProperties(line);

            return(true);
        }
Ejemplo n.º 5
0
            public void AddPoint()
            {
                var xresult = parent.Drawing.CompileExpression(X);
                var yresult = parent.Drawing.CompileExpression(Y);

                if (xresult.IsSuccess && yresult.IsSuccess)
                {
                    double x = double.Parse(X, CultureInfo.CurrentUICulture);
                    double y = double.Parse(Y, CultureInfo.CurrentUICulture);

                    FreePoint first = (FreePoint)this.parent.FoundDependencies.FirstOrDefault(f => f is FreePoint);
                    if (first == null || !(first.X == x && first.Y == y))
                    {
                        this.parent.AddDependency(new Point(x, y));
                    }
                    else
                    {
                        if (this.parent.TempPoint != null)
                        {
                            this.parent.FoundDependencies.Remove(this.parent.TempPoint);
                        }
                        this.parent.AddFiguresAndRestart();
                    }
                }
            }
Ejemplo n.º 6
0
        protected virtual FreePoint CreatePointAtCurrentPosition(System.Windows.Input.MouseButtonEventArgs e)
        {
            FreePoint p = Factory.CreateFreePoint();

            Drawing.Figures.Add(p);
            p.MoveTo(Coordinates(e));
            return(p);
        }
Ejemplo n.º 7
0
        private FreePoint compareFreePoints(RootFigureList figureList, FreePoint aPoint)
        {
            foreach (IFigure aFigure in figureList)
                if (aFigure is FreePoint && Math.Abs((aFigure as FreePoint).X - aPoint.X)<_delta && Math.Abs((aFigure as FreePoint).Y - aPoint.Y)<_delta)
                    return aFigure as FreePoint;

            return null;
        }
Ejemplo n.º 8
0
 private void Finish(System.Windows.Input.MouseButtonEventArgs e)
 {
     if (TempPoint != null)
     {
         TempPoint.Shape.Fill = new SolidColorBrush(Colors.LightYellow);
         TempPoint            = null;
     }
     Reset();
 }
Ejemplo n.º 9
0
        public static FreePoint CreateFreePoint(Drawing drawing, Point coordinates)
        {
            FreePoint result = new FreePoint()
            {
                Drawing = drawing
            };

            result.MoveTo(coordinates);
            return(result);
        }
Ejemplo n.º 10
0
 void RemovePointFromPolygons(FreePoint point)
 {
     foreach (var polygon in point.Dependents.OfType <PolygonBase>().ToList())
     {
         if (polygon.Dependencies.Count > 3)
         {
             RemovePointFromPolygon(point, polygon);
         }
     }
 }
Ejemplo n.º 11
0
        private FreePoint compareFreePoints(RootFigureList figureList, FreePoint aPoint)
        {
            foreach (IFigure aFigure in figureList)
            {
                if (aFigure is FreePoint && Math.Abs((aFigure as FreePoint).X - aPoint.X) < _delta && Math.Abs((aFigure as FreePoint).Y - aPoint.Y) < _delta)
                {
                    return(aFigure as FreePoint);
                }
            }

            return(null);
        }
Ejemplo n.º 12
0
        private static List <FreePoint> getPoints(List <IFigure> aPath, FreePoint sPoint)
        {
            var       aPoints = new List <FreePoint>();
            var       aFig    = sPoint.Dependents.Where <IFigure>((aaFig) => { return(aPath.Contains(aaFig)); }).First <IFigure>(); //aPath[0];
            FreePoint aPoint  = sPoint;                                                                                             //aFig.Dependencies[0].Dependents.Count > 2 ? aFig.Dependencies[0] as FreePoint : aFig.Dependencies[1] as FreePoint;

            while (aFig != null)
            {
                aPoints.Add(aPoint);
                aFig = getNextFigure(aFig, ref aPoint);
            }
            return(aPoints);
        }
Ejemplo n.º 13
0
 private static FreePoint getNextVertex(IFigure aFig, FreePoint aPoint)
 {
     if (aFig is CircleArcBase)
     {
         return(Math.Round(((aFig.Dependencies[1] as FreePoint).Coordinates - aPoint.Coordinates).Length, 2) == 0 ? aFig.Dependencies[2] as FreePoint : aFig.Dependencies[1] as FreePoint);
     }
     else
     {
         return(Math.Round(((aFig.Dependencies[0] as FreePoint).Coordinates - aPoint.Coordinates).Length, 2) == 0 ? aFig.Dependencies[1] as FreePoint : aFig.Dependencies[0] as FreePoint);
     }
     //var aDependents = aFig.Dependencies.Without<IFigure>(aPoint); //.Where<IFigure>((aaFig)=>{return aaFig.Dependents.Without<IFigure>(aaFig.Center).Count<IFigure>()>0;});
     //return aDependents.Count<IFigure>() == 0 ? null : aDependents.First<IFigure>() as FreePoint;
 }
Ejemplo n.º 14
0
 private static IFigure getNextFigure(IFigure aFig, ref FreePoint aPoint)
 {
     if (aFig.Dependencies.Count < 2)
     {
         return(null);
     }
     else
     if (aFig.Dependencies[0] == aPoint)
     {
         aPoint = aFig.Dependencies[1] as FreePoint;
     }
     else
     {
         aPoint = aFig.Dependencies[0] as FreePoint;
     }
     return(aPoint.Dependents.Count != 2 ? null : aPoint.Dependents[0] == aFig ? aPoint.Dependents[1] : aPoint.Dependents[0]);
 }
Ejemplo n.º 15
0
 private static bool isCenter(FreePoint aPoint)
 {
     if (aPoint.Dependents.Count == 1)
     {
         var aDependencies = aPoint.Dependents[0].Dependencies.Without <IFigure>(aPoint).ToList <IFigure>();
         if (aDependencies.Count == 2)
         {
             return(Math.Round((aPoint.Coordinates - (aDependencies[0] as FreePoint).Coordinates).Length, 2) == Math.Round((aPoint.Coordinates - (aDependencies[1] as FreePoint).Coordinates).Length, 2));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
 private static double getAngle(IFigure aFig, FreePoint aEndPoint)
 {
     if (aFig is CircleArcBase)
     {
         var aAngle  = aEndPoint.Coordinates.AngleTo((aFig as CircleArcBase).Center);
         var aAngle2 = getNextVertex(aFig, aEndPoint).Coordinates.AngleTo((aFig as CircleArcBase).Center);
         if (aAngle2 < aAngle)
         {
             return(aEndPoint.Coordinates.AngleTo((aFig as CircleArcBase).Center) + Math.PI / 2);
         }
         else
         {
             return(aEndPoint.Coordinates.AngleTo((aFig as CircleArcBase).Center) - Math.PI / 2);
         }
     }
     else
     {
         return(aEndPoint.Coordinates.AngleTo(getNextVertex(aFig, aEndPoint).Coordinates));
     }
 }
Ejemplo n.º 17
0
        void JoinPolyLineSegments(FreePoint point)
        {
            var dependents = point.Dependents.OfType<Polyline>().ToArray();

            foreach (object obj in dependents)
            {
                if (obj is Polyline)
                {
                    Polyline polyline = (Polyline)obj;

                    if (polyline.Dependencies.Count <= 3)
                    {
                        return;
                    }

                    List<IFigure> NewPolyLinePoints = new List<IFigure>();

                    // Eliminate deleted point
                    for (int i = 0; i < polyline.Dependencies.Count; i++)
                    {
                        IPoint p1 = polyline.Dependencies[i] as IPoint;

                        if (p1.Coordinates.X != point.Coordinates.X
                            && p1.Coordinates.Y != point.Coordinates.Y)
                        {
                            NewPolyLinePoints.Add(p1);
                        }
                    }

                    // create new polyline
                    var newPolyLine = Factory.CreatePolyline(Drawing, NewPolyLinePoints);
                    using (Drawing.ActionManager.CreateTransaction())
                    {
                        Actions.Remove(point);
                        Actions.ReplaceWithNew(polyline, newPolyLine);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        void JoinPolyLineSegments(FreePoint point)
        {
            var dependents = point.Dependents.OfType <Polyline>().ToArray();

            foreach (object obj in dependents)
            {
                if (obj is Polyline)
                {
                    Polyline polyline = (Polyline)obj;

                    if (polyline.Dependencies.Count <= 3)
                    {
                        return;
                    }

                    List <IFigure> NewPolyLinePoints = new List <IFigure>();

                    // Eliminate deleted point
                    for (int i = 0; i < polyline.Dependencies.Count; i++)
                    {
                        IPoint p1 = polyline.Dependencies[i] as IPoint;

                        if (p1.Coordinates.X != point.Coordinates.X &&
                            p1.Coordinates.Y != point.Coordinates.Y)
                        {
                            NewPolyLinePoints.Add(p1);
                        }
                    }

                    // create new polyline
                    var newPolyLine = Factory.CreatePolyline(Drawing, NewPolyLinePoints);
                    using (Drawing.ActionManager.CreateTransaction())
                    {
                        Actions.Remove(point);
                        Actions.ReplaceWithNew(polyline, newPolyLine);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private static void TearOffGeneralCase(IFigure figure)
        {
            Drawing drawing = figure.Drawing;

            using (drawing.ActionManager.CreateTransaction())
            {
                foreach (var dependency in figure.Dependencies.ToArray())
                {
                    var dependencyPoint = dependency as IPoint;
                    if (dependencyPoint == null)
                    {
                        // for now, can't tear off a figure
                        // that has a non-point dependency (such as a ParallelLine)
                        return;
                    }

                    if (dependencyPoint is FreePoint)
                    {
                        // no need to tear-off from an already free point
                        // since no one else uses this point
                        if (dependencyPoint.Dependents.Count == 1)
                        {
                            continue;
                        }
                        if (dependencyPoint.Dependents.Count == 2 && dependencyPoint.Dependents.OfType <LabelBase>().Count() > 0)
                        {
                            continue;
                        }
                    }

                    FreePoint newDependencyPoint = Factory.CreateFreePoint(drawing, dependencyPoint.Coordinates);
                    Actions.Add(figure.Drawing, newDependencyPoint);
                    Actions.ReplaceDependency(figure, dependencyPoint, newDependencyPoint);
                }
            }

            drawing.RaiseDisplayProperties(figure);
        }
Ejemplo n.º 20
0
        protected override void MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.RightButton == System.Windows.Input.MouseButtonState.Pressed)
            {
                AbortAndSetDefaultTool();
                return;
            }

            RemoveTempPoint();

            var underMouse = Drawing.Figures.HitTest(Coordinates(e));

            if (underMouse == null && ExpectingAPoint())
            {
                underMouse = CreatePointAtCurrentPosition(e);
            }

            AddFoundDependency(underMouse);

            if (FoundDependencies.Count < ExpectedDependencies.Count)
            {
                if (ExpectingAPoint())
                {
                    TempPoint = CreateTempPoint(e);
                    AddFoundDependency(TempPoint);
                    if (FoundDependencies.Count == ExpectedDependencies.Count)
                    {
                        CreateAndAddFigure();
                    }
                }
            }
            else
            {
                Finish(e);
            }
        }
Ejemplo n.º 21
0
        void JoinSegments(FreePoint point)
        {
            var dependents = point.Dependents.OfType<Segment>().ToArray();
            if (dependents.Length != 2)
            {
                return;
            }
            var line1 = dependents[0];
            var line2 = dependents[1];

            var otherPoint1 = line1.Dependencies.Without(point).FirstOrDefault();
            var otherPoint2 = line2.Dependencies.Without(point).FirstOrDefault();
            if (otherPoint1 == null || otherPoint2 == null)
            {
                return;
            }

            var segment = Factory.CreateSegment(Drawing, new[] { otherPoint1, otherPoint2 });

            using (Drawing.ActionManager.CreateTransaction())
            {
                RemovePointFromPolygons(point);
                Actions.Remove(line2);
                Actions.ReplaceWithNew(line1, segment);
                Actions.Remove(point);
            }
        }
Ejemplo n.º 22
0
 void RemovePointFromPolygons(FreePoint point)
 {
     foreach (var polygon in point.Dependents.OfType<PolygonBase>().ToList())
     {
         if (polygon.Dependencies.Count > 3)
         {
             RemovePointFromPolygon(point, polygon);
         }
     }
 }
Ejemplo n.º 23
0
 void RemovePointFromPolygon(FreePoint point, PolygonBase polygon)
 {
     Actions.RemoveDependency(polygon, point);
 }
Ejemplo n.º 24
0
 void RemovePointFromPolygon(FreePoint point, PolygonBase polygon)
 {
     Actions.RemoveDependency(polygon, point);
 }
Ejemplo n.º 25
0
        public static FreePoint CreateFreePoint()
        {
            FreePoint result = new FreePoint();

            return(result);
        }
Ejemplo n.º 26
0
 public static FreePoint CreateFreePoint(Drawing drawing, Point coordinates)
 {
     FreePoint result = new FreePoint() { Drawing = drawing };
     result.MoveTo(coordinates);
     return result;
 }
Ejemplo n.º 27
0
 public static FreePoint CreateFreePoint()
 {
     FreePoint result = new FreePoint();
     return result;
 }