public void execute()
        {
            if (_myGraphic.ShapeType == "ellipse" || _myGraphic.ShapeType == "rectangle")
            {
                MathTool.getInstance().MoveStrokes(_myGraphic.Strokes, offset_x, offset_y);
                MathTool.getInstance().MoveStrokes(_myGraphic.textStrokeCollection, offset_x, offset_y);
                MathTool.getInstance().MoveStrokes(_myGraphic.PentagramStrokes, offset_x, offset_y);
                _myGraphic.Shape.Margin = new Thickness(_myGraphic.Shape.Margin.Left + offset_x, _myGraphic.Shape.Margin.Top + offset_y, 0, 0);
                //GraphicMathTool.getInstance().SearchRelationByPosition(_myGraphic, MyGraphics, _inkCollector);


                //修改直线
                List <GraphicLinkNode> glns = _inkCollector.Sketch.getGraphicLinkNodesBySelfMyGraphicID(_myGraphic.MyGraphicID);
                foreach (GraphicLinkNode gln in glns)
                {
                    MyGraphic relativeGraphic = _inkCollector.Sketch.getMyGraphicByID(gln.MyGraphicID);
                    if (relativeGraphic != null)
                    {
                        if (relativeGraphic.ShapeType == "arrow" || relativeGraphic.ShapeType == "loopArc" || relativeGraphic.ShapeType == "polylineArrow")
                        {
                            ZoomAndRotate(gln, relativeGraphic);
                        }
                        else if (relativeGraphic.ShapeType == "loopArcSelf")
                        {
                            ((System.Windows.Shapes.Line)relativeGraphic.Shape).X1 = ((System.Windows.Shapes.Line)relativeGraphic.Shape).X1 + offset_x;
                            ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y1 = ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y1 + offset_y;
                            ((System.Windows.Shapes.Line)relativeGraphic.Shape).X2 = ((System.Windows.Shapes.Line)relativeGraphic.Shape).X2 + offset_x;
                            ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y2 = ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y2 + offset_y;
                            MathTool.getInstance().MoveStrokes(relativeGraphic.Strokes, offset_x, offset_y);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public DeleteMyGraphicCommand(InkCollector inkcollector, MyGraphic myGraphic)
 {
     _inkcollector = inkcollector;
     _sketch       = _inkcollector.Sketch;
     _myGraphic    = myGraphic;
     _strokes      = myGraphic.Strokes;
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="strokeCollection"></param>
 /// <param name="offset_x"></param>
 /// <param name="offset_y"></param>
 public MyGraphicMoveCommand(MyGraphic myGraphic, double offset_x, double offset_y, InkCollector inkCollector)
 {
     this._myGraphic    = myGraphic;
     this.offset_x      = offset_x;
     this.offset_y      = offset_y;
     MyGraphics         = inkCollector.Sketch.MyGraphics;
     this._inkCollector = inkCollector;
 }
Beispiel #4
0
        public override void _presenter_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            InkCanvas inkCanvas  = (InkCanvas)sender;
            Stroke    lastStroke = inkCanvas.Strokes[inkCanvas.Strokes.Count - 1];

            if (analyze.RootNode.Strokes.IndexOf(lastStroke) == -1)
            {
                analyze.AddStroke(inkCanvas.Strokes[inkCanvas.Strokes.Count - 1]);
            }
            analyze.BackgroundAnalyze();
            string    analyzeStr = analyze.GetRecognizedString();
            MyGraphic MyGraphicContrainStroke = _inkCollector.Sketch.getMyGraphicContrainStroke(lastStroke);

            if (MyGraphicContrainStroke != null)
            {
                if (MyGraphicContrainStroke.textStrokeCollection.IndexOf(lastStroke) == -1)
                {
                    MyGraphicContrainStroke.addTextStroke(lastStroke);
                    MyGraphicContrainStroke.Text = analyzeStr;
                    //Console.WriteLine("analyzeStr:" + analyzeStr);
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// 增加一个graphic
 /// </summary>
 /// <param name="image"></param>
 public void AddMyGraphic(MyGraphic myGraphic)
 {
     foreach (Stroke s in myGraphic.Strokes)
     {
         if (_inkCanvas.Strokes.IndexOf(s) == -1)
         {
             _inkCanvas.Strokes.Add(s);
         }
     }
     foreach (Stroke s in myGraphic.textStrokeCollection)
     {
         if (_inkCanvas.Strokes.IndexOf(s) == -1)
         {
             _inkCanvas.Strokes.Add(s);
         }
     }
     if (myGraphic.PentagramStrokes != null)
     {
         _inkCanvas.Strokes.Add(myGraphic.PentagramStrokes);
     }
     _inkCanvas.Children.Add(myGraphic.Shape);
     Sketch.AddMyGraphic(myGraphic);
 }
Beispiel #6
0
        void _inkCanvas_StrokeCollected_StrokeInGraphic(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            InkCanvas inkCanvas  = (InkCanvas)sender;
            Stroke    lastStroke = inkCanvas.Strokes[inkCanvas.Strokes.Count - 1];

            if (analyze.RootNode.Strokes.IndexOf(lastStroke) == -1)
            {
                analyze.AddStroke(inkCanvas.Strokes[inkCanvas.Strokes.Count - 1]);
            }
            analyze.BackgroundAnalyze();
            string    analyzeStr = analyze.GetRecognizedString();
            MyGraphic MyGraphicContrainStroke = InkCollector.Sketch.getMyGraphicContrainStroke(lastStroke);

            if (MyGraphicContrainStroke != null)
            {
                if (MyGraphicContrainStroke.textStrokeCollection.IndexOf(lastStroke) == -1)
                {
                    MyGraphicContrainStroke.addTextStroke(lastStroke);
                    MyGraphicContrainStroke.Text = analyzeStr;
                    //Console.WriteLine("analyzeStr" + analyzeStr);
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// 删除graphic
 /// </summary>
 /// <param name="image"></param>
 public void RemoveMyGraphic(MyGraphic myGraphic)
 {
     _inkCanvas.Children.Remove(myGraphic.Shape);
     foreach (Stroke s in myGraphic.Strokes)
     {
         if (_inkCanvas.Strokes.IndexOf(s) != -1)
         {
             _inkCanvas.Strokes.Remove(s);
         }
     }
     foreach (Stroke s in myGraphic.textStrokeCollection)
     {
         if (_inkCanvas.Strokes.IndexOf(s) != -1)
         {
             _inkCanvas.Strokes.Remove(s);
         }
     }
     if (myGraphic.PentagramStrokes != null)
     {
         _inkCanvas.Strokes.Remove(myGraphic.PentagramStrokes);
     }
     GraphicMathTool.getInstance().searchExistRelationAndRemove(myGraphic, Sketch.MyGraphics, this);
     Sketch.RemoveMyGraphic(myGraphic);
 }
Beispiel #8
0
 /// <summary>
 /// 获得mg的下一个相连图形
 /// </summary>
 /// <param name="mg"></param>
 /// <returns></returns>
 public MyGraphic getNextMyGraphic(MyGraphic mg)
 {
     return getMyGraphicByID(getGraphicLinkNodeByID(mg.GraphicLinkNodeID).MyGraphicID);
 }
Beispiel #9
0
		/// <summary>
		/// 删除一个stroke
		/// </summary>
		/// <param name="stroke"></param>
		public void RemoveMyGraphic(MyGraphic myGraphic)
		{
			///删除一个stroke
			MyGraphics.Remove(myGraphic);
		}
Beispiel #10
0
		/// <summary>
		/// 在sketch中增加一个stroke
		/// </summary>
		/// <param name="stroke"></param>
		public void AddMyGraphic(MyGraphic myGraphic)
		{
			///增加一个stroke,列表,group等等
			MyGraphics.Add(myGraphic);
		}
 public _graphicpos(MyGraphic _g, double _left, double _top)
 {
     g = _g; left = _left; top = _top;
 }
 /// <summary>
 /// 这个辅助函数用来删掉一个子graphic
 /// </summary>
 public void Remove(MyGraphic g)
 {
     _graphicpos mgp = null;
     foreach (_graphicpos gp in _list)
     {
         if (gp.g == g)
         {
             mgp = gp;
             break;
         }
     }
     if (mgp != null)
     {
         _list.Remove(mgp);
     }
 }
 public override void Add(MyGraphic g, double left = 0.0f, double top = 0.0f)
 {
     g.Father = this;
     _list.Add(new _graphicpos(g, left, top));
     _currentindex = -1;
 }
 public AddMyGraphicCommand(InkCollector _inkCollector, MyGraphic myGraphic)
 {
     this._myGraphic    = myGraphic;
     this._inkCollector = _inkCollector;
 }
        private void ZoomAndRotate(GraphicLinkNode gln, MyGraphic relativeGraphic)
        {
            Matrix m1        = new Matrix();
            Matrix m2        = new Matrix();
            Matrix m3        = new Matrix();
            double zoomScale = 1;
            double preX1     = ((System.Windows.Shapes.Line)relativeGraphic.Shape).X1;
            double preY1     = ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y1;
            double preX2     = ((System.Windows.Shapes.Line)relativeGraphic.Shape).X2;
            double preY2     = ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y2;
            double nowX1     = preX1 + offset_x;
            double nowY1     = preY1 + offset_y;
            double nowX2     = preX2 + offset_x;
            double nowY2     = preY2 + offset_y;
            double preLength = MathTool.getInstance().distanceP2P(new StylusPoint(preX2, preY2), new StylusPoint(preX1, preY1));
            double nowLength;

            if (gln.Rule == "HeadIntersect")//修改第一个点
            {
                ((System.Windows.Shapes.Line)relativeGraphic.Shape).X1 = nowX1;
                ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y1 = nowY1;

                if (relativeGraphic.ShapeType == "arrow" || relativeGraphic.ShapeType == "loopArc")
                {
                    double angle1 = MathTool.getInstance().getAngleP2P(new StylusPoint(preX1, preY1), new StylusPoint(preX2, preY2));
                    double angle2 = MathTool.getInstance().getAngleP2P(new StylusPoint(nowX1, nowY1), new StylusPoint(preX2, preY2));
                    double angle  = angle2 - angle1;//旋转角度

                    nowLength = MathTool.getInstance().distanceP2P(new StylusPoint(preX2, preY2), new StylusPoint(nowX1, nowY1));

                    if (preLength == 0 || nowLength == 0)
                    {
                        zoomScale = 1;
                    }
                    else
                    {
                        zoomScale = nowLength / preLength;
                    }
                    m1.RotateAt(-angle, preX2, preY2);
                    m2.ScaleAt(zoomScale, zoomScale, preX2, preY2);
                    Matrix m = m1 * m2;

                    relativeGraphic.Strokes[0].Transform(m, true);
                    relativeGraphic.Strokes[0].DrawingAttributes.StylusTipTransform = new Matrix(1, 0, 0, 1, 0, 0);
                    relativeGraphic.Strokes[1].Transform(m1, true);

                    if (relativeGraphic.Strokes.Count == 3)//笔迹数为3时
                    {
                        relativeGraphic.Strokes[2].Transform(m1, true);
                    }
                }
            }
            else if (gln.Rule == "TailIntersect")//修改最后点
            {
                ((System.Windows.Shapes.Line)relativeGraphic.Shape).X2 = nowX2;
                ((System.Windows.Shapes.Line)relativeGraphic.Shape).Y2 = nowY2;

                if (relativeGraphic.ShapeType == "arrow" || relativeGraphic.ShapeType == "loopArc")
                {
                    double angle1 = MathTool.getInstance().getAngleP2P(new StylusPoint(preX2, preY2), new StylusPoint(preX1, preY1));
                    double angle2 = MathTool.getInstance().getAngleP2P(new StylusPoint(nowX2, nowY2), new StylusPoint(preX1, preY1));
                    double angle  = angle2 - angle1;//旋转角度

                    nowLength = MathTool.getInstance().distanceP2P(new StylusPoint(nowX2, nowY2), new StylusPoint(preX1, preY1));

                    if (preLength == 0 || nowLength == 0)
                    {
                        zoomScale = 1;
                    }
                    else
                    {
                        zoomScale = nowLength / preLength;
                    }

                    m1.RotateAt(-angle, preX1, preY1);
                    relativeGraphic.Strokes[0].Transform(m1, false);
                    m2.ScaleAt(zoomScale, zoomScale, preX1, preY1);
                    relativeGraphic.Strokes[0].Transform(m2, false);

                    //************************************
                    //用于计算箭头的头部移动位置
                    StylusPoint           p  = new StylusPoint(preX2, preY2);
                    StylusPointCollection ps = new StylusPointCollection();
                    ps.Add(p);
                    Stroke s = new Stroke(ps);
                    //*************************************
                    //箭的头部只旋转和移动,不缩放
                    if (relativeGraphic.Strokes.Count == 2)//笔迹数为2时
                    {
                        relativeGraphic.Strokes[1].Transform(m1, false);
                        s.Transform(m1, false);
                        m3.Translate(nowX2 - s.StylusPoints[0].X, nowY2 - s.StylusPoints[0].Y);
                        relativeGraphic.Strokes[1].Transform(m3, false);
                    }
                    else if (relativeGraphic.Strokes.Count == 3)//笔迹数为3时
                    {
                        relativeGraphic.Strokes[1].Transform(m1, false);
                        relativeGraphic.Strokes[2].Transform(m1, false);
                        s.Transform(m1, false);
                        m3.Translate(nowX2 - s.StylusPoints[0].X, nowY2 - s.StylusPoints[0].Y);
                        relativeGraphic.Strokes[1].Transform(m3, false);
                        relativeGraphic.Strokes[2].Transform(m3, false);
                    }
                }
            }
        }