Example #1
0
        // let the base class take care of positioning the first line
        // however after choosing the end of that line becomes point 2 and point 1 is then moved (and point 3 is automatic)

        public override VerbResult Choose(EditableView.ClickPosition position)
        {
            PointF pt = position.Snapped;

            if (pt.ApproxEqual(LastDefined))
            {
                return(VerbResult.Rejected);
            }
            DiscardPath();

            switch (m_DefinedVertices)
            {
            case 1:
                SetLength(4);
                Vertices[2]       = pt;
                Vertices[1]       = Geometry.MidPoint(Vertices[0], Vertices[2]);
                m_DefinedVertices = 2;
                Float(position);
                return(VerbResult.Continuing);

            case 2:
                Float(position);
                if (Geometry.PointApproxOnLine(Vertices[0], Vertices[2], Vertices[1]))
                {
                    return(VerbResult.Rejected);
                }
                return(VerbResult.Completed);

            default: throw new InvalidOperationException();
            }
        }
Example #2
0
        public override VerbResult Float(EditableView.ClickPosition position)
        {
            PointF pt = position.Snapped;

            if (!m_PositionFixed)
            {
                var sz = GetSize();
                if (SingleClickPlacement)
                {
                    // In this case we are placing the centre
                    pt.X -= m_ImageSize.Width / NOMINALPIXELSPERMILLIMETRE * 0.5f;
                    pt.Y -= m_ImageSize.Height / NOMINALPIXELSPERMILLIMETRE * 0.5f;
                    //Debug.WriteLine(m_Bounds)
                }
                SetRectangle(new RectangleF(pt, sz));
            }
            else
            {
                SizeF newSize    = new SizeF(pt.X - Vertices[0].X, pt.Y - Vertices[0].Y);
                float imageRatio = (float)m_ImageSize.Width / m_ImageSize.Height;
                float adjustment = imageRatio / (newSize.Width / newSize.Height);
                // correction needed to the aspect ratio
                // we add on half each on width and height
                newSize.Width   *= (float)Math.Sqrt(adjustment);
                newSize.Height  /= (float)Math.Sqrt(adjustment);
                m_SizeAcceptable = DimensionAcceptable(newSize.Width, m_ImageSize.Width) && DimensionAcceptable(newSize.Height, m_ImageSize.Height);
                if (m_SizeAcceptable)
                {
                    SetRectangle(new RectangleF(Vertices[0], newSize));
                }
            }
            return(VerbResult.Continuing);
        }
Example #3
0
        public override VerbResult Float(EditableView.ClickPosition position)
        {
            if (m_DefinedVertices < 2)
            {
                return(base.Float(position));
            }
            // actually floating point 1 in this case and 0 and 2 are fixed
            PointF pt = position.Snapped;

            if (pt.Equals(Vertices[1]))
            {
                return(VerbResult.Unchanged);
            }

            // find point on base line closest to floating point.
            PointF closest = Geometry.ClosestPointOnLine(Vertices[0], Vertices[2], pt);
            // vector from that to float gives us the vector for the second axis (effectively it's ony the length that matters)
            PointF centre         = Geometry.MidPoint(Vertices[0], Vertices[2]);
            SizeF  halfSecondAxis = closest.VectorTo(pt);

            Vertices[1]  = centre + halfSecondAxis;
            Vertices[3]  = centre - halfSecondAxis;
            m_Acceptable = !Geometry.PointApproxOnLine(Vertices[0], Vertices[2], Vertices[1]);

            m_Bounds = CalculateBounds();
            DiscardPath();
            return(VerbResult.Continuing);
        }
Example #4
0
        public override VerbResult Float(EditableView.ClickPosition position)
        {
            if (m_DefinedVertices < 2)
            {
                return(base.Float(position));
            }
            // If pt.Equals(m_aVertices(2)) Then Return RectangleF.Empty ' polygon is unchanged - no need to do the further calculations
            // CANT DO THAT DUE TO ChangeSizeVerb
            Vertices[2] = position.Snapped;
            m_Bounds    = RectangleF.Empty;          // invalidate the bounds
            int direction = base.TurnDirection();

            if (direction == 0)
            {
                m_Acceptable = false;
                for (int index = 2; index <= m_Sides - 1; index++)
                {
                    Vertices[index] = Vertices[1];
                }
            }
            else
            {
                PlacePoints(direction);
                m_Acceptable = true;
            }
            return(VerbResult.Continuing);
        }
Example #5
0
 public override VerbResult Float(EditableView.ClickPosition pt)
 {
     if (m_DefinedVertices >= Vertices.Count)
     {
         Debug.Fail("Curve: Float no points are undetermined");
         return(VerbResult.Unchanged);
     }
     if (m_DefinedVertices == 0)
     {
         return(VerbResult.Continuing);                // don't think this actually happen, but just in case
     }
     if (Vertices[m_DefinedVertices].ApproxEqual(pt.Snapped))
     {
         return(VerbResult.Rejected);
     }
     if (m_DefinedVertices >= 2 && !m_Closed && pt.Exact.ApproxEqual(Vertices[0]))
     {
         // auto-close - complete will change to closed
         Vertices[m_DefinedVertices] = Vertices[0];
     }
     else
     {
         Vertices[m_DefinedVertices] = pt.Snapped;
     }
     SetControlPoints(m_DefinedVertices - 1);
     if (m_Closed)
     {
         SetControlPoints(0, 0);
     }
     DiscardDerived();
     return(VerbResult.Continuing);
 }
Example #6
0
 public override VerbResult Choose(EditableView.ClickPosition position)
 {
     if (!m_BaseLineFixed)
     {
         if (Float(position) == VerbResult.Rejected)
         {
             return(VerbResult.Rejected);
         }
         m_BaseLineFixed = true;
         if (m_Label == null)
         {
             m_Label = "";
         }
         FormatText(0);                 // will format the EmptyText prompt
         CaretGain();
         m_Bounds = CalculateBounds();
         return(VerbResult.Continuing);
     }
     else             // will complete the shape, fixing the text
     {
         if (string.IsNullOrEmpty(m_Label))
         {
             return(VerbResult.Rejected);
         }
         CaretLose();
         return(VerbResult.Completed);
     }
 }
Example #7
0
        public override VerbResult OtherVerb(EditableView.ClickPosition position, SAW.Functions.Codes code)
        {
            switch (code)
            {
            case SAW.Functions.Codes.Increment:
            case SAW.Functions.Codes.Decrement:
                int   delta = code == SAW.Functions.Codes.Increment ? 1 : -1;
                float step  = position.ScalarSnapStep(0);
                if (step <= 0)
                {
                    step = delta * Globals.Root.CurrentConfig.ReadSingle(Config.Radius_Step, 1);
                }
                else
                {
                    step *= delta;
                }
                SizeF vector = Vertices[0].VectorTo(Vertices[1]);
                float length = vector.Length();
                if (length + step < 5 || length < Geometry.NEGLIGIBLESMALL)
                {
                    return(VerbResult.Rejected);
                }
                Vertices[1] = Vertices[0] + vector.ChangeLength(length + step);
                m_Bounds    = RectangleF.Empty;
                return(VerbResult.Continuing);

            default:
                return(VerbResult.Rejected);
            }
        }
Example #8
0
        public override VerbResult Float(EditableView.ClickPosition position)
        {
            // let the base class take care of positioning the first line
            if (m_DefinedVertices < 2)
            {
                return(base.Float(position));
            }
            // need to calculate the coordinates of the fourth point.  We can add the 1>2 vector onto point 0
            Debug.Assert(Vertices.Count == 4);
            PointF newPoint = Geometry.PerpendicularPoint(Vertices[0], Vertices[1], position.Snapped);

            if (newPoint.Equals(Vertices[2]))
            {
                return(VerbResult.Unchanged);
            }
            if (newPoint.ApproxEqual(Vertices[1]))
            {
                return(VerbResult.Rejected);
            }
            Vertices[2] = newPoint;
            SizeF vector = Vertices[1].VectorTo(Vertices[2]);

            Vertices[3]  = PointF.Add(Vertices[0], vector);
            m_Bounds     = CalculateBounds();
            m_Acceptable = !VerticesFormLine(0);
            DiscardPath();
            return(VerbResult.Continuing);
        }
Example #9
0
 public override VerbResult Start(EditableView.ClickPosition position)
 {
     Element = new Item {
         Parent = this
     };
     SetUniqueID();
     return(Element.Start(position));
 }
Example #10
0
        public override VerbResult Float(EditableView.ClickPosition position)
        {
            // I think that the base class Float is sufficient, except that it does not  set m_bolAcceptable
            var eResult = base.Float(position);

            m_Acceptable = m_DefinedVertices >= 2 && !VerticesFormLine(0);
            return(eResult);
        }
Example #11
0
 public override VerbResult Cancel(EditableView.ClickPosition position)
 {
     if (!string.IsNullOrEmpty(m_Label))
     {
         return(Complete(position));
     }
     return(VerbResult.Destroyed);
 }
Example #12
0
 public override VerbResult Complete(EditableView.ClickPosition position)
 {
     if (!m_BaseLineFixed)
     {
         return(Choose(position));
     }
     return(CompleteRetrospective());
 }
Example #13
0
 public override VerbResult Float(EditableView.ClickPosition pt)
 {
     Vertices[Vertices.Count - 1] = pt.Snapped;
     UpdateLink(1, pt);
     PositionLine();
     m_Acceptable = !EndsEqual && !Vertices[0].ApproxEqual(Vertices[Vertices.Count - 1]);
     m_Bounds     = RectangleF.Empty;
     return(VerbResult.Continuing);
 }
Example #14
0
 public override VerbResult Start(EditableView.ClickPosition position)
 {
     m_Start = position.Snapped;
     base.Start(position);
     Vertices.Add(m_Start);
     Vertices.Add(m_Start);
     m_DefinedVertices = 2;             // sort of!
     return(VerbResult.Continuing);
 }
Example #15
0
 public override VerbResult Cancel(EditableView.ClickPosition position)
 {
     if (Vertices.Count != 2 || m_DefinedVertices != 1)
     {
         return(VerbResult.Unexpected);
     }
     // this can only happen when we have one vertex specified - it will always cancel the entire shape
     return(VerbResult.Destroyed);
 }
Example #16
0
 public override VerbResult Cancel(EditableView.ClickPosition position)
 {
     if (!m_PositionFixed)
     {
         return(VerbResult.Destroyed);
     }
     m_PositionFixed = false;
     SetDefaultSize();
     return(VerbResult.Continuing);
 }
Example #17
0
 public override VerbResult Choose(EditableView.ClickPosition position)
 {
     if (position.Snapped.ApproxEqual(LastDefined))
     {
         return(VerbResult.Rejected);
     }
     Float(position);
     FixVertex();
     return(VerbResult.Continuing);
 }
Example #18
0
 public override VerbResult Choose(EditableView.ClickPosition position)
 {
     Float(position);
     if (m_Bounds.Width < 1 || m_Bounds.Height < 1)
     {
         return(VerbResult.Rejected);
     }
     m_DefinedVertices = 4;
     return(VerbResult.Completed);
 }
Example #19
0
        private const float ADDMMPERDEGREE = 0.05f;      // ie 90deg = 4.5 extra (90° is the maximum considered)

        public override VerbResult Start(EditableView.ClickPosition position)
        {
            m_Targets = new List <PointF>();
            m_Targets.Add(position.Snapped);
            Debug.Assert(LineStyle != null && FillStyle != null);
            LineStyle.SetDefaults();
            FillStyle.Colour    = Color.Empty;
            FillStyle.Pattern   = FillStyleC.Patterns.Solid;
            g_dtLastTargetAdded = DateTime.Now;
            return(VerbResult.Continuing);
        }
Example #20
0
        public override VerbResult Start(EditableView.ClickPosition position)
        {
            base.AddLink(null, 0);
            base.AddLink(null, 0);
            VerbResult result = base.Start(position);

            UpdateLink(0, position);           // but we deliberately leave the other one floating; otherwise it would just point to the same socket
            m_Acceptable      = false;
            m_DefinedVertices = 2;             // not used by this class and confuses base class
            return(result);
        }
Example #21
0
 public override VerbResult Complete(EditableView.ClickPosition position)
 {
     if (Vertices.Count != 2 || m_DefinedVertices != 1)
     {
         return(VerbResult.Unexpected);
     }
     Vertices[1]       = position.Snapped;
     m_DefinedVertices = 2;
     m_Bounds          = RectangleF.Empty;
     return(VerbResult.Completed);
 }
Example #22
0
 public override VerbResult Start(EditableView.ClickPosition position)
 {
     m_Start = position.Snapped;
     m_End   = m_Start;
     if (MultiMode)
     {
         m_OriginalSelection = new List <Shape>();
         m_OriginalSelection.AddRange(position.Page.SelectedShapes);
     }
     return(VerbResult.Continuing);
 }
Example #23
0
 public override VerbResult Cancel(EditableView.ClickPosition position)
 {
     // unless overridden in a subclass this will remove one DEFINED vertex
     // and trim the vertex array to contain just the defined ones plus one floating
     // the vertex array may currently contain any number of other postulated ones
     if (m_DefinedVertices <= 1)
     {
         return(VerbResult.Destroyed);
     }
     DiscardVertex();
     return(VerbResult.Continuing);
 }
Example #24
0
        public override VerbResult Start(EditableView.ClickPosition position)
        {
            PointF pt = position.Snapped;

            Vertices[0]     = pt;
            Vertices[1]     = pt;
            m_BaseLineFixed = false;
            Debug.Assert(TextStyle != null);
            TextStyle.SetDefaults();
            TextStyle.Alignment = StringAlignment.Near;
            return(VerbResult.Continuing);
        }
Example #25
0
        public override VerbResult Choose(EditableView.ClickPosition position)
        {
            PointF point = position.Snapped;

            if (point.ApproxEqual(LastDefined))
            {
                return(VerbResult.Rejected);
            }
            Vertices[Vertices.Count - 1] = point;
            FixVertex();
            return(VerbResult.Continuing);
        }
Example #26
0
        public override AllowedActions Allows => AllowedActions.None;         // not actually used?

        #endregion

        #region Verbs

        public override VerbResult Cancel(EditableView.ClickPosition position)
        {
            if (!MultiMode)
            {
                position.Page.DeselectAll();
            }
            else
            {
                position.Page.SelectOnly(m_OriginalSelection);
            }
            return(VerbResult.Destroyed);
        }
Example #27
0
        public override VerbResult OtherVerb(EditableView.ClickPosition position, Functions.Codes code)
        {
            switch (code)
            {
            case Functions.Codes.Increment:
            case Functions.Codes.Decrement:
                int delta = code == Functions.Codes.Increment ? 1 : -1;
                return(ChangeSides(delta));

            default:
                return(VerbResult.Rejected);
            }
        }
Example #28
0
 public override VerbResult Cancel(EditableView.ClickPosition position)
 {
     if (!m_BaseLineFixed)
     {
         return(VerbResult.Destroyed);
     }
     if (!string.IsNullOrEmpty(m_Label))
     {
         return(Complete(position));
     }
     m_BaseLineFixed = false;
     CaretLose();
     return(VerbResult.Continuing);
 }
Example #29
0
 public override VerbResult Cancel(EditableView.ClickPosition position)
 {
     if (m_DefinedVertices <= 1)
     {
         return(VerbResult.Destroyed);
     }
     m_DefinedVertices -= 1;
     SetLength(m_DefinedVertices + 1);
     if (m_Closed)            // the final, closing vertex has been renumbered.  This will have been deleted off the end of the list
     {
         Vertices[Vertices.Count - 1] = Vertices[0];
     }
     return(VerbResult.Continuing);
 }
Example #30
0
 public override VerbResult Complete(EditableView.ClickPosition position)
 {
     if (Vertices.Count != 2 || m_DefinedVertices != 1)
     {
         return(VerbResult.Unexpected);
     }
     Float(position);
     m_DefinedVertices = 2;
     if (Vertices[0].ApproxEqual(Vertices[1]))
     {
         return(VerbResult.Destroyed);
     }
     return(VerbResult.Completed);
 }