コード例 #1
0
ファイル: EditorState.cs プロジェクト: wieslawsoltes/SpiroNet
        public EditorState()
        {
            _tool = EditorTool.Spiro;
            _mode = EditorMode.Create;

            _displayKnots = true;
            _displayGuides = true;

            _snapX = 15.0;
            _snapY = 15.0;
            _enableSnap = true;

            _shape = null;
            _hitTreshold = 7;
            _hitTresholdSquared = 49;
            _hitSetShapes = new HashSet<SpiroShape>();
            _hitSetPoints = new HashSet<int>();
            _hitListShapes = new ObservableCollection<SpiroShape>();
            _hitListPoints = new ObservableCollection<int>();
            _isStroked = true;
            _isFilled = false;
            _isClosed = true;
            _isTagged = false;
            _pointType = SpiroPointType.G4;

            _isCaptured = false;
            _snapTreshold = 10.0;
            _snapMode = GuideSnapMode.Point | GuideSnapMode.Middle | GuideSnapMode.Intersection | GuideSnapMode.Horizontal | GuideSnapMode.Vertical;
            _snapPointRadius = 3.5;
            _snapPoint = default(GuidePoint);
            _haveSnapPoint = false;
        }
コード例 #2
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private static bool TryToRunSpiro(SpiroShape shape, IBezierContext bc)
        {
            if (shape == null || bc == null)
            {
                return(false);
            }

            try
            {
                var points = shape.Points.ToArray();
                if (shape.IsTagged)
                {
                    return(Spiro.TaggedSpiroCPsToBezier0(points, bc));
                }
                else
                {
                    return(Spiro.SpiroCPsToBezier0(points, points.Length, shape.IsClosed, bc));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }

            return(false);
        }
コード例 #3
0
ファイル: EditorState.cs プロジェクト: qipa/SpiroNet
        public EditorState()
        {
            _tool = EditorTool.Spiro;
            _mode = EditorMode.Create;

            _displayKnots  = true;
            _displayGuides = true;

            _snapX      = 15.0;
            _snapY      = 15.0;
            _enableSnap = true;

            _shape              = null;
            _hitTreshold        = 7;
            _hitTresholdSquared = 49;
            _hitSetShapes       = new HashSet <SpiroShape>();
            _hitSetPoints       = new HashSet <int>();
            _hitListShapes      = new ObservableCollection <SpiroShape>();
            _hitListPoints      = new ObservableCollection <int>();
            _isStroked          = true;
            _isFilled           = false;
            _isClosed           = true;
            _isTagged           = false;
            _pointType          = SpiroPointType.G4;

            _isCaptured      = false;
            _snapTreshold    = 10.0;
            _snapMode        = GuideSnapMode.Point | GuideSnapMode.Middle | GuideSnapMode.Intersection | GuideSnapMode.Horizontal | GuideSnapMode.Vertical;
            _snapPointRadius = 3.5;
            _snapPoint       = default(GuidePoint);
            _haveSnapPoint   = false;
        }
コード例 #4
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void NewPointAt(SpiroShape shape, double x, double y, int index)
        {
            var point = new SpiroControlPoint();

            point.X    = x;
            point.Y    = y;
            point.Type = _state.PointType;
            shape.Points.Insert(index, point);
        }
コード例 #5
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void NewPoint(SpiroShape shape, double x, double y)
        {
            var point = new SpiroControlPoint();

            point.X    = x;
            point.Y    = y;
            point.Type = _state.PointType;
            shape.Points.Add(point);
        }
コード例 #6
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void SetPointPosition(SpiroShape shape, int index, double x, double y)
        {
            var old   = shape.Points[index];
            var point = new SpiroControlPoint();

            point.X             = x;
            point.Y             = y;
            point.Type          = old.Type;
            shape.Points[index] = point;
        }
コード例 #7
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void SetPointType(SpiroShape shape, int index, SpiroPointType type)
        {
            var old   = shape.Points[index];
            var point = new SpiroControlPoint();

            point.X             = old.X;
            point.Y             = old.Y;
            point.Type          = type;
            shape.Points[index] = point;
        }
コード例 #8
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void InsertPoint(double x, double y, SpiroShape hitShape, int hitShapePointIndex)
        {
            // Insert new point.
            SpiroShape shape = hitShape;
            int        index = hitShapePointIndex + 1;

            NewPointAt(shape, x, y, index);

            RunSpiro(shape);
        }
コード例 #9
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void RemovePoint(SpiroShape shape, int index)
        {
            shape.Points.RemoveAt(index);

            if (shape.Points.Count == 0)
            {
                RemoveShape(shape);
            }
            else
            {
                RunSpiro(shape);
            }
        }
コード例 #10
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void SetPointPositionDelta(SpiroShape shape, int index, double dx, double dy)
        {
            var    old   = shape.Points[index];
            double x     = old.X + dx;
            double y     = old.Y + dy;
            double sx    = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
            double sy    = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;
            var    point = new SpiroControlPoint();

            point.X             = sx;
            point.Y             = sy;
            point.Type          = old.Type;
            shape.Points[index] = point;
        }
コード例 #11
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void Select(SpiroShape hitShape, int hitShapePointIndex)
        {
            if (!_state.HitSetShapes.Contains(hitShape))
            {
                // Select shape.
                _state.HitSetShapes.Add(hitShape);
                _state.HitListShapes.Add(hitShape);
                // Select point.
                _state.HitSetPoints.Add(hitShapePointIndex);
                _state.HitListPoints.Add(hitShapePointIndex);
            }

            // Update point type.
            if (hitShapePointIndex != -1)
            {
                _state.PointType = hitShape.Points[hitShapePointIndex].Type;
            }

            _invalidate();
        }
コード例 #12
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void RunSpiro(SpiroShape shape)
        {
            if (shape == null)
            {
                return;
            }

            var bc     = new PathBezierContext();
            var result = TryToRunSpiro(shape, bc);

            if (_data.ContainsKey(shape))
            {
                _data[shape]  = result ? bc.ToString() : null;
                _knots[shape] = result ? bc.GetKnots() : null;
            }
            else
            {
                _data.Add(shape, result ? bc.ToString() : null);
                _knots.Add(shape, result ? bc.GetKnots() : null);
            }
        }
コード例 #13
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private void Select(SpiroShape hitShape)
        {
            if (!_state.HitSetShapes.Contains(hitShape))
            {
                // Select shape.
                _state.HitSetShapes.Add(hitShape);
                _state.HitListShapes.Add(hitShape);
                // Deselect point.
                _state.HitSetPoints.Add(-1);
                _state.HitListPoints.Add(-1);
            }

            // Update shape info.
            if (hitShape != null)
            {
                _state.IsStroked = hitShape.IsStroked;
                _state.IsFilled  = hitShape.IsFilled;
                _state.IsClosed  = hitShape.IsClosed;
                _state.IsTagged  = hitShape.IsTagged;
            }

            _invalidate();
        }
コード例 #14
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
 private void SetPointPositionDelta(SpiroShape shape, int index, double dx, double dy)
 {
     var old = shape.Points[index];
     double x = old.X + dx;
     double y = old.Y + dy;
     double sx = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
     double sy = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;
     var point = new SpiroControlPoint();
     point.X = sx;
     point.Y = sy;
     point.Type = old.Type;
     shape.Points[index] = point;
 }
コード例 #15
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
 private void SetPointPosition(SpiroShape shape, int index, double x, double y)
 {
     var old = shape.Points[index];
     var point = new SpiroControlPoint();
     point.X = x;
     point.Y = y;
     point.Type = old.Type;
     shape.Points[index] = point;
 }
コード例 #16
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private void Select(SpiroShape hitShape)
        {
            if (!_state.HitSetShapes.Contains(hitShape))
            {
                // Select shape.
                _state.HitSetShapes.Add(hitShape);
                _state.HitListShapes.Add(hitShape);
                // Deselect point.
                _state.HitSetPoints.Add(-1);
                _state.HitListPoints.Add(-1);
            }

            // Update shape info.
            if (hitShape != null)
            {
                _state.IsStroked = hitShape.IsStroked;
                _state.IsFilled = hitShape.IsFilled;
                _state.IsClosed = hitShape.IsClosed;
                _state.IsTagged = hitShape.IsTagged;
            }

            _invalidate();
        }
コード例 #17
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private void Select(SpiroShape hitShape, int hitShapePointIndex)
        {
            if (!_state.HitSetShapes.Contains(hitShape))
            {
                // Select shape.
                _state.HitSetShapes.Add(hitShape);
                _state.HitListShapes.Add(hitShape);
                // Select point.
                _state.HitSetPoints.Add(hitShapePointIndex);
                _state.HitListPoints.Add(hitShapePointIndex);
            }

            // Update point type.
            if (hitShapePointIndex != -1)
            {
                _state.PointType = hitShape.Points[hitShapePointIndex].Type;
            }

            _invalidate();
        }
コード例 #18
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private void RunSpiro(SpiroShape shape)
        {
            if (shape == null)
                return;

            var bc = new PathBezierContext();
            var result = TryToRunSpiro(shape, bc);
            if (_data.ContainsKey(shape))
            {
                _data[shape] = result ? bc.ToString() : null;
                _knots[shape] = result ? bc.GetKnots() : null;
            }
            else
            {
                _data.Add(shape, result ? bc.ToString() : null);
                _knots.Add(shape, result ? bc.GetKnots() : null);
            }
        }
コード例 #19
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
 private void RemoveShape(SpiroShape shape)
 {
     _drawing.Shapes.Remove(shape);
     _data.Remove(shape);
     _knots.Remove(shape);
 }
コード例 #20
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private static bool HitTestForShape(IList<SpiroShape> shapes, double x, double y, double treshold, out SpiroShape hitShape, out int hitShapePointIndex)
        {
            for (int i = 0; i < shapes.Count; i++)
            {
                var bc = new HitTestBezierContext(x, y);
                var shape = shapes[i];
                int knontIndex;

                try
                {
                    if (!TryToRunSpiro(shape, bc))
                        continue;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                    continue;
                }

                if (bc.Report(out knontIndex) < treshold)
                {
                    hitShape = shape;
                    hitShapePointIndex = knontIndex;
                    return true;
                }
            }

            hitShape = null;
            hitShapePointIndex = -1;
            return false;
        }
コード例 #21
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
 private void NewPointAt(SpiroShape shape, double x, double y, int index)
 {
     var point = new SpiroControlPoint();
     point.X = x;
     point.Y = y;
     point.Type = _state.PointType;
     shape.Points.Insert(index, point);
 }
コード例 #22
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
 private void NewPoint(SpiroShape shape, double x, double y)
 {
     var point = new SpiroControlPoint();
     point.X = x;
     point.Y = y;
     point.Type = _state.PointType;
     shape.Points.Add(point);
 }
コード例 #23
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private static bool HitTestForPoint(IList <SpiroShape> shapes, double x, double y, double tresholdSquared, out SpiroShape hitShape, out int hitShapePointIndex)
        {
            foreach (var shape in shapes)
            {
                for (int i = 0; i < shape.Points.Count; i++)
                {
                    var point    = shape.Points[i];
                    var distance = DistanceSquared(x, y, point.X, point.Y);
                    if (distance < tresholdSquared)
                    {
                        hitShape           = shape;
                        hitShapePointIndex = i;
                        return(true);
                    }
                }
            }

            hitShape           = null;
            hitShapePointIndex = -1;
            return(false);
        }
コード例 #24
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
 private void SetPointType(SpiroShape shape, int index, SpiroPointType type)
 {
     var old = shape.Points[index];
     var point = new SpiroControlPoint();
     point.X = old.X;
     point.Y = old.Y;
     point.Type = type;
     shape.Points[index] = point;
 }
コード例 #25
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private void RemovePoint(SpiroShape shape, int index)
        {
            shape.Points.RemoveAt(index);

            if (shape.Points.Count == 0)
            {
                RemoveShape(shape);
            }
            else
            {
                RunSpiro(shape);
            }
        }
コード例 #26
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private static bool HitTestForPoint(IList<SpiroShape> shapes, double x, double y, double tresholdSquared, out SpiroShape hitShape, out int hitShapePointIndex)
        {
            foreach (var shape in shapes)
            {
                for (int i = 0; i < shape.Points.Count; i++)
                {
                    var point = shape.Points[i];
                    var distance = DistanceSquared(x, y, point.X, point.Y);
                    if (distance < tresholdSquared)
                    {
                        hitShape = shape;
                        hitShapePointIndex = i;
                        return true;
                    }
                }
            }

            hitShape = null;
            hitShapePointIndex = -1;
            return false;
        }
コード例 #27
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
 private void RemoveShape(SpiroShape shape)
 {
     _drawing.Shapes.Remove(shape);
     _data.Remove(shape);
     _knots.Remove(shape);
 }
コード例 #28
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private static bool TryToRunSpiro(SpiroShape shape, IBezierContext bc)
        {
            if (shape == null || bc == null)
                return false;

            try
            {
                var points = shape.Points.ToArray();
                if (shape.IsTagged)
                    return Spiro.TaggedSpiroCPsToBezier0(points, bc);
                else
                    return Spiro.SpiroCPsToBezier0(points, points.Length, shape.IsClosed, bc);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }

            return false;
        }
コード例 #29
0
ファイル: SpiroEditor.cs プロジェクト: nagyistge/SpiroNet
        private static bool HitTestForShape(IList <SpiroShape> shapes, double x, double y, double treshold, out SpiroShape hitShape, out int hitShapePointIndex)
        {
            for (int i = 0; i < shapes.Count; i++)
            {
                var bc    = new HitTestBezierContext(x, y);
                var shape = shapes[i];
                int knontIndex;

                try
                {
                    if (!TryToRunSpiro(shape, bc))
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                    continue;
                }

                if (bc.Report(out knontIndex) < treshold)
                {
                    hitShape           = shape;
                    hitShapePointIndex = knontIndex;
                    return(true);
                }
            }

            hitShape           = null;
            hitShapePointIndex = -1;
            return(false);
        }
コード例 #30
0
ファイル: SpiroPlate.cs プロジェクト: dandanyouxiang/SpiroNet
        public static IList <SpiroShape> ToShapes(string plate)
        {
            if (string.IsNullOrEmpty(plate))
            {
                return(null);
            }

            var shapes    = new ObservableCollection <SpiroShape>();
            var newLine   = Environment.NewLine.ToCharArray();
            var separator = new char[] { ' ', '\t' };
            var trim      = new char[] { '(', ')' };
            var options   = StringSplitOptions.RemoveEmptyEntries;
            var lines     = plate.Split(newLine, options).Select(x => x.Trim().Trim(trim).Split(separator, options));

            SpiroShape shape = null;

            foreach (var line in lines)
            {
                if (line.Length == 0 || line[0] == "plate")
                {
                    continue;
                }

                switch (line[0][0])
                {
                case 'v':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.Corner, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                break;

                case 'o':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.G4, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                break;

                case 'c':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.G2, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                break;

                case '[':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.Left, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                break;

                case ']':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.Right, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                break;

                case 'z':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 1)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.End, "0", "0"));
                    }
                    else if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.End, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }

                    shapes.Add(shape);
                    shape = null;
                }
                break;

                case '{':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.OpenContour, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                break;

                case '}':
                {
                    if (shape == null)
                    {
                        shape = NewShape();
                    }

                    if (line.Length == 3)
                    {
                        shape.Points.Add(NewPoint(SpiroPointType.EndOpenContour, line[1], line[2]));
                    }
                    else
                    {
                        throw new FormatException();
                    }

                    shapes.Add(shape);
                    shape = null;
                }
                break;

                default:
                    throw new FormatException();
                }
            }

            if (shape != null)
            {
                shape.IsTagged = false;
                shapes.Add(shape);
                shape = null;
            }

            return(shapes);
        }
コード例 #31
0
ファイル: SpiroEditor.cs プロジェクト: wieslawsoltes/SpiroNet
        private void InsertPoint(double x, double y, SpiroShape hitShape, int hitShapePointIndex)
        {
            // Insert new point.
            SpiroShape shape = hitShape;
            int index = hitShapePointIndex + 1;
            NewPointAt(shape, x, y, index);

            RunSpiro(shape);
        }