Beispiel #1
0
        internal static bool BoundingIntersectWithLine(Bounding bounding, Line2 line)
        {
            Bounding lineBound = new Bounding(line.startPoint, line.endPoint);

            if (!bounding.IntersectWith(lineBound))
            {
                return(false);
            }

            if (bounding.Contains(line.startPoint) ||
                bounding.Contains(line.endPoint))
            {
                return(true);
            }

            CADPoint pkPnt1 = new CADPoint(bounding.left, bounding.bottom);
            CADPoint pkPnt2 = new CADPoint(bounding.left, bounding.top);
            CADPoint pkPnt3 = new CADPoint(bounding.right, bounding.top);
            CADPoint pkPnt4 = new CADPoint(bounding.right, bounding.bottom);

            double d1 = CADVector.Cross(line.startPoint - pkPnt1, line.endPoint - pkPnt1);
            double d2 = CADVector.Cross(line.startPoint - pkPnt2, line.endPoint - pkPnt2);
            double d3 = CADVector.Cross(line.startPoint - pkPnt3, line.endPoint - pkPnt3);
            double d4 = CADVector.Cross(line.startPoint - pkPnt4, line.endPoint - pkPnt4);

            if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Transform
        /// </summary>
        public override void TransformBy(Matrix3 transform)
        {
            CADPoint spnt = transform * this.startPoint;
            CADPoint epnt = transform * this.endPoint;
            CADPoint mpnt = transform * this.middlePoint;

            _center = transform * _center;
            _radius = (spnt - _center).Length;

            double sAngle = CADVector.SignedAngleInRadian(
                new CADVector(1, 0),
                spnt - _center);
            double eAngle = CADVector.SignedAngleInRadian(
                new CADVector(1, 0),
                epnt - _center);

            if (CADVector.SignedAngle(spnt - _center, mpnt - _center) >= 0)
            {
                this.startAngle = sAngle;
                this.endAngle   = eAngle;
            }
            else
            {
                this.startAngle = eAngle;
                this.endAngle   = sAngle;
            }
        }
Beispiel #3
0
        public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition)
        {
            switch (gripPoint.Type)
            {
            case GripPointType.End:
            {
                this.SetPointAt(index, newPosition);
            }
            break;

            case GripPointType.Mid:
            {
                int numOfVertices = NumberOfVertices;
                int i             = index - numOfVertices;
                if (i >= 0 && i <= numOfVertices - 1)
                {
                    int vIndex1st = i;
                    int vIndex2nd = i + 1;
                    if (vIndex2nd == numOfVertices)
                    {
                        vIndex2nd = 0;
                    }
                    CADVector t = newPosition - gripPoint.Position;
                    this.SetPointAt(vIndex1st, (CADPoint)gripPoint.xData1 + t);
                    this.SetPointAt(vIndex2nd, (CADPoint)gripPoint.xData2 + t);
                }
            }
            break;

            default:
                break;
            }
        }
Beispiel #4
0
 public static Matrix3 Scale(CADVector v)
 {
     return(new Matrix3(
                v.X, 0.0, 0.0,
                0.0, v.Y, 0.0,
                0.0, 0.0, 1.0));
 }
Beispiel #5
0
 public static Matrix3 Translate(CADVector v)
 {
     return(new Matrix3(
                1.0, 0.0, v.X,
                0.0, 1.0, v.Y,
                0.0, 0.0, 1.0));
 }
Beispiel #6
0
        internal static bool BoundingIntersectWithRay(Bounding bounding, Ray ray)
        {
            if (!ray.Bounding.IntersectWith(bounding))
            {
                return(false);
            }

            var pkPnt1 = new CADPoint(bounding.left, bounding.bottom);
            var pkPnt2 = new CADPoint(bounding.left, bounding.top);
            var pkPnt3 = new CADPoint(bounding.right, bounding.top);
            var pkPnt4 = new CADPoint(bounding.right, bounding.bottom);

            double d1 = CADVector.Cross(pkPnt1 - ray.basePoint, ray.direction);
            double d2 = CADVector.Cross(pkPnt2 - ray.basePoint, ray.direction);
            double d3 = CADVector.Cross(pkPnt3 - ray.basePoint, ray.direction);
            double d4 = CADVector.Cross(pkPnt4 - ray.basePoint, ray.direction);

            if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #7
0
        public override IEventResult OnMouseMove(IMouseEventArgs e)
        {
            if (e.IsRightPressed)
            {
                return(EventResult.Unhandled);
            }

            if (_step == Step.Step1_SelectObjects)
            {
            }
            else if (_step == Step.Step2_SpecifyBasePoint)
            {
            }
            else if (_step == Step.Step3_SpecifySecondPoint)
            {
                CADVector preTranslation = translation;
                _pathLine.endPoint = this.Pointer.CurrentSnapPoint;
                CADVector offset = translation - preTranslation;
                foreach (Entity copy in _copys)
                {
                    copy.Translate(offset);
                    copy.Draw();
                }

                _pathLine.endPoint = this.Pointer.CurrentSnapPoint;
                _pathLine.Draw();
            }

            return(EventResult.Handled);
        }
Beispiel #8
0
        public override IEventResult OnMouseMove(IMouseEventArgs e)
        {
            if (e.IsMiddlePressed)
            {
                return(EventResult.Handled);
            }

            switch (_step)
            {
            case Step.Step1_SpecifyCenter:
                break;

            case Step.Step2_SpecityStartPoint:
                _line.endPoint = this.Pointer.CurrentSnapPoint;
                _line.Draw();
                break;

            case Step.Step3_SpecifyEndPoint:
                double endAngle = CADVector.SignedAngleInRadian(
                    new CADVector(1, 0),
                    this.Pointer.CurrentSnapPoint - _arc.center);
                endAngle      = MathUtils.NormalizeRadianAngle(endAngle);
                _arc.endAngle = endAngle;
                _arc.Draw();

                _line.endPoint = this.Pointer.CurrentSnapPoint;
                _line.Draw();
                break;
            }

            return(EventResult.Handled);
        }
Beispiel #9
0
 public override void Translate(CADVector translation)
 {
     for (int i = 0; i < this.NumberOfVertices; ++i)
     {
         _vertices[i] += translation;
     }
 }
Beispiel #10
0
        public static void DrawRay(IDrawing owner, DrawingContext thisDC, Pen pen, CADPoint basePoint, CADVector direction, bool mdoelToCanvas = true)
        {
            CADVector dir;
            CADPoint  basePnt;

            if (mdoelToCanvas)
            {
                basePnt = owner.ModelToCanvas(basePoint);
                CADPoint otherPnt = owner.ModelToCanvas(basePoint + direction);
                dir = (otherPnt - basePnt).normalized;
            }
            else
            {
                basePnt = basePoint;
                dir     = direction;
                dir.Normalize();
            }

            double xk = double.MinValue;
            double yk = double.MinValue;

            if (basePnt.X > 0 && basePnt.X < 10000 &&
                basePnt.Y > 0 && basePnt.Y < 10000)
            {
                xk = 1;
                yk = 1;
            }
            else
            {
                if (dir.Y != 0)
                {
                    double k = -basePnt.Y / dir.Y;
                    if (k >= 0)
                    {
                        xk = basePnt.X + k * dir.X;
                    }
                }
                if (dir.X != 0)
                {
                    double k = -basePnt.X / dir.X;
                    if (k >= 0)
                    {
                        yk = basePnt.Y + k * dir.Y;
                    }
                }
            }

            if (xk > 0 ||
                (xk == 0 && dir.X * dir.Y >= 0) ||
                yk > 0 ||
                (yk == 0 && dir.X * dir.Y >= 0))
            {
                CADPoint epnt = basePnt + 10000 * dir;

                DrawLine(owner, thisDC, pen,
                         new CADPoint(basePnt.X, basePnt.Y),
                         new CADPoint(epnt.X, epnt.Y), false);
            }
        }
Beispiel #11
0
        public override void TransformBy(Matrix3 transform)
        {
            CADPoint refPnt = _basePoint + _direction;

            _basePoint = transform * _basePoint;
            refPnt     = transform * refPnt;
            _direction = (refPnt - _basePoint).normalized;
        }
Beispiel #12
0
        public override bool Read(string name, out CADVector value)
        {
            CADPoint tmp;
            var      ret = Read(name, out tmp);

            value = (CADVector)tmp;
            return(ret);
        }
Beispiel #13
0
        public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition)
        {
            if (index == 0)
            {
                _center = newPosition;
            }
            else if (index >= 1 && index <= 3)
            {
                CADPoint startPoint  = this.startPoint;
                CADPoint endPoint    = this.endPoint;
                CADPoint middlePoint = this.middlePoint;

                if (index == 1)
                {
                    startPoint  = newPosition;
                    middlePoint = (CADPoint)gripPoint.xData1;
                }
                else if (index == 2)
                {
                    endPoint    = newPosition;
                    middlePoint = (CADPoint)gripPoint.xData1;
                }
                else if (index == 3)
                {
                    middlePoint = newPosition;
                }

                Circle2 newCircle = Circle2.From3Points(
                    startPoint, middlePoint, endPoint);
                if (newCircle.radius > 0)
                {
                    CADVector xPositive  = new CADVector(1, 0);
                    double    startAngle = CADVector.SignedAngleInRadian(xPositive,
                                                                         startPoint - newCircle.center);
                    double endAngle = CADVector.SignedAngleInRadian(xPositive,
                                                                    endPoint - newCircle.center);
                    double middleAngle = CADVector.SignedAngleInRadian(xPositive,
                                                                       middlePoint - newCircle.center);
                    startAngle  = MathUtils.NormalizeRadianAngle(startAngle);
                    endAngle    = MathUtils.NormalizeRadianAngle(endAngle);
                    middleAngle = MathUtils.NormalizeRadianAngle(middleAngle);

                    _center = newCircle.center;
                    _radius = newCircle.radius;
                    if (AngleInArcRange(middleAngle, startAngle, endAngle))
                    {
                        this.startAngle = startAngle;
                        this.endAngle   = endAngle;
                    }
                    else
                    {
                        this.startAngle = endAngle;
                        this.endAngle   = startAngle;
                    }
                }
            }
        }
Beispiel #14
0
        public override IEventResult OnMouseDown(IMouseButtonEventArgs e)
        {
            switch (_step)
            {
            case Step.Step1_SpecifyCenter:
                if (e.IsLeftPressed)
                {
                    _arc         = presenter.AppendEntity(new Arc(), DBObjectState.Unconfirmed);
                    _arc.center  = this.Pointer.CurrentSnapPoint;
                    _arc.radius  = 0;
                    _arc.LayerId = this.document.currentLayerId;
                    _arc.Color   = this.document.currentColor;

                    _step = Step.Step2_SpecityStartPoint;

                    _line            = presenter.AppendEntity(new Line(), DBObjectState.Unconfirmed);
                    _line.startPoint = _arc.center;
                    _line.endPoint   = this.Pointer.CurrentSnapPoint;
                    _line.Draw();
                }
                break;

            case Step.Step2_SpecityStartPoint:
                if (e.IsLeftPressed)
                {
                    _arc.radius  = (_arc.center - this.Pointer.CurrentSnapPoint).Length;
                    _arc.LayerId = this.document.currentLayerId;
                    _arc.Color   = this.document.currentColor;

                    double startAngle = CADVector.SignedAngleInRadian(
                        new CADVector(1, 0),
                        this.Pointer.CurrentSnapPoint - _arc.center);
                    startAngle      = MathUtils.NormalizeRadianAngle(startAngle);
                    _arc.startAngle = startAngle;
                    _arc.endAngle   = startAngle;

                    _step = Step.Step3_SpecifyEndPoint;
                }
                break;

            case Step.Step3_SpecifyEndPoint:
                if (e.IsLeftPressed)
                {
                    double endAngle = CADVector.SignedAngleInRadian(
                        new CADVector(1, 0),
                        this.Pointer.CurrentSnapPoint - _arc.center);
                    endAngle      = MathUtils.NormalizeRadianAngle(endAngle);
                    _arc.endAngle = endAngle;

                    _arc.Draw();
                    _mgr.FinishCurrentCommand();
                }
                break;
            }

            return(EventResult.Handled);
        }
Beispiel #15
0
        public IEventResult OnMouseMove(IMouseEventArgs e)
        {
            if (e.IsMiddlePressed)
            {
                var pnt = new CADPoint(e.X, e.Y);
                _tempOffsetVector    = (m_MiddleBtnPressed_Point - pnt);
                _tempOffsetVector.Y *= -1;

                _drawing.Canvas.Redraw();
            }
            return(null);
        }
Beispiel #16
0
        public override bool Write(string name, CADVector value)
        {
            XmlElement elem = _xmldoc.CreateElement(name);

            if (elem == null)
            {
                return(false);
            }
            elem.InnerText = value.X.ToString() + ";" + value.Y.ToString();
            _curXmlNode.AppendChild(elem);

            return(true);
        }
Beispiel #17
0
 public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition)
 {
     if (index == 0)
     {
         _basePoint = newPosition;
     }
     else if (index == 1 || index == 2)
     {
         CADVector dir = (newPosition - _basePoint).normalized;
         if (!dir.Equals(new CADVector(0, 0)))
         {
             _direction = dir;
         }
     }
 }
Beispiel #18
0
        public override IEventResult OnMouseMove(IMouseEventArgs e)
        {
            if (e.IsMiddlePressed)
            {
                return(EventResult.Handled);
            }

            if (_currXline != null &&
                _step == Step.Step2_SpecifyOtherPoint)
            {
                CADVector dir = (this.Pointer.CurrentSnapPoint
                                 - _currXline.basePoint).normalized;
                if (dir.X != 0 || dir.Y != 0)
                {
                    _currXline.direction = dir;
                    _currXline.Draw();
                }
            }

            return(EventResult.Handled);
        }
Beispiel #19
0
        internal static bool BoundingIntersectWithXline(Bounding bounding, Xline xline)
        {
            CADPoint pkPnt1 = new CADPoint(bounding.left, bounding.bottom);
            CADPoint pkPnt2 = new CADPoint(bounding.left, bounding.top);
            CADPoint pkPnt3 = new CADPoint(bounding.right, bounding.top);
            CADPoint pkPnt4 = new CADPoint(bounding.right, bounding.bottom);

            double d1 = CADVector.Cross(pkPnt1 - xline.basePoint, xline.direction);
            double d2 = CADVector.Cross(pkPnt2 - xline.basePoint, xline.direction);
            double d3 = CADVector.Cross(pkPnt3 - xline.basePoint, xline.direction);
            double d4 = CADVector.Cross(pkPnt4 - xline.basePoint, xline.direction);

            if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #20
0
        public override IEventResult OnMouseDown(IMouseButtonEventArgs e)
        {
            switch (_step)
            {
            case Step.Step1_SpecifyBasePoint:
                if (e.IsLeftPressed)
                {
                    _currXline           = presenter.AppendEntity(new Xline(), DBObjectState.Unconfirmed);
                    _currXline.basePoint = this.Pointer.CurrentSnapPoint;
                    _currXline.LayerId   = this.document.currentLayerId;
                    _currXline.Color     = this.document.currentColor;

                    this.GotoStep(Step.Step2_SpecifyOtherPoint);
                }
                break;

            case Step.Step2_SpecifyOtherPoint:
                if (e.IsLeftPressed)
                {
                    CADVector dir = (this.Pointer.CurrentSnapPoint
                                     - _currXline.basePoint).normalized;
                    if (dir.X != 0 || dir.Y != 0)
                    {
                        _currXline.direction = dir;
                        _currXline.LayerId   = this.document.currentLayerId;
                        _currXline.Color     = this.document.currentColor;
                        _xlines.Add(_currXline);

                        _currXline = Drawing.AppendEntity((Xline)_currXline.Clone(), DBObjectState.Unconfirmed);
                        _currXline.Draw();
                        //_currXline = _currXline.Clone() as Xline;
                    }
                }
                break;
            }

            return(EventResult.Handled);
        }
Beispiel #21
0
        public override IEventResult OnMouseMove(IMouseEventArgs e)
        {
            switch (_step)
            {
            case Step.Step1_SelectObjects:
                break;

            case Step.Step2_SpecifyBasePoint:
                break;

            case Step.Step3_SpecifySecondPoint:
                CADVector preTranslation = translation;
                _pathLine.endPoint = this.Pointer.CurrentSnapPoint;

                CADVector offset = translation - preTranslation;
                foreach (Entity tempEntity in _tempItemsToDraw)
                {
                    tempEntity.Translate(offset);
                    tempEntity.Draw();
                }
                //foreach (CopyAction action in _actions)
                //{
                //    foreach (Entity entity in action.copyItems)
                //    {
                //        entity.Draw();
                //    }
                //}

                _pathLine.endPoint = this.Pointer.CurrentSnapPoint;
                _pathLine.Draw();
                break;

            default:
                break;
            }

            return(EventResult.Handled);
        }
Beispiel #22
0
 public override void Translate(CADVector translation)
 {
     _startPoint += translation;
     _endPoint   += translation;
 }
Beispiel #23
0
 public abstract bool Read(string name, out CADVector value);
Beispiel #24
0
 public CADVector MultiplyVector(CADVector v)
 {
     return(new CADVector(
                m11 * v.X + m12 * v.Y,
                m21 * v.X + m22 * v.Y));
 }
        public static void DrawXLine(IDrawing owner, DrawingContext thisDC, Pen pen, CADPoint basePoint, CADVector direction, bool mdoelToCanvas = true)
        {
            CADVector dir;
            CADPoint  basePnt;

            if (mdoelToCanvas)
            {
                basePnt = owner.ModelToCanvas(basePoint);
                CADPoint otherPnt = owner.ModelToCanvas(basePoint + direction);
                dir = (otherPnt - basePnt).normalized;
            }
            else
            {
                basePnt = basePoint;
                dir     = direction;
                dir.Normalize();
            }

            double xk = double.MinValue;
            double yk = double.MinValue;

            if (dir.Y != 0)
            {
                double k = basePnt.Y / dir.Y;
                xk = basePnt.X - k * dir.X;
            }
            if (dir.X != 0)
            {
                double k = basePnt.X / dir.X;
                yk = basePnt.Y - k * dir.Y;
            }

            if (xk > 0 ||
                (xk == 0 && dir.X * dir.Y >= 0))
            {
                CADPoint spnt = new CADPoint(xk, 0);
                if (dir.Y < 0)
                {
                    dir = -dir;
                }
                CADPoint epnt = spnt + 10000 * dir;

                DrawLine(owner, thisDC, pen,
                         new CADPoint((float)spnt.X, (float)spnt.Y),
                         new CADPoint((float)epnt.X, (float)epnt.Y), false);
            }
            else if (yk > 0 ||
                     (yk == 0 && dir.X * dir.Y >= 0))
            {
                CADPoint spnt = new CADPoint(0, yk);
                if (dir.X < 0)
                {
                    dir = -dir;
                }
                CADPoint epnt = spnt + 10000 * dir;

                DrawLine(owner, thisDC, pen,
                         new CADPoint((float)spnt.X, (float)spnt.Y),
                         new CADPoint((float)epnt.X, (float)epnt.Y), false);
            }
        }
Beispiel #26
0
 public CADVector MultiplyPoint(CADVector v)
 {
     return(new CADVector(
                m11 * v.X + m12 * v.Y + m13,
                m21 * v.X + m22 * v.Y + m23));
 }
 public virtual void DrawXLine(CADPoint basePoint, CADVector direction, bool mdoelToCanvas = true)
 {
     DrawXLine(_drawing, thisDC, Pen, basePoint, direction, mdoelToCanvas);
 }
 public virtual void DrawRay(CADPoint basePoint, CADVector direction, bool mdoelToCanvas = true)
 {
 }
Beispiel #29
0
 public abstract void Translate(CADVector translation);
Beispiel #30
0
 public override void Translate(CADVector translation)
 {
     _center += translation;
 }