Exemple #1
0
        private void MouseDown(MouseEventArgs e, EventHandleStatus status)
        {
            Point viewPoint = _modelEditor.ToViewCoord(e.Location);

            if (e.Button == MouseButtons.Left)
            {
                IInternalSelection sel = _modelEditor.BindingEnvironment as IInternalSelection;
                //是否点中了锚点
                _currentElement = sel.GetActionElementAt(viewPoint, out _currentAnchorIndex);
                if (_currentElement != null && _currentAnchorIndex != -1)
                {
                    _startPoint    = viewPoint;
                    _prePoint      = _startPoint;
                    _oprType       = enumOprType.Anchor;
                    status.Handled = true;
                }
                else//点中了除锚点外的其它区域
                {
                    _currentElement = sel.Select(viewPoint);
                    if (_currentElement != null)
                    {
                        _startPoint    = viewPoint;
                        _prePoint      = _startPoint;
                        _oprType       = enumOprType.Move;
                        status.Handled = true;
                    }
                    _modelEditor.Render();
                }
            }
        }
Exemple #2
0
 private void MouseUp(MouseEventArgs e, EventHandleStatus status)
 {
     _prePoint           = Point.Empty;
     _startPoint         = Point.Empty;
     _currentElement     = null;
     _currentAnchorIndex = -1;
     _oprType            = enumOprType.None;
 }
Exemple #3
0
        private void AddActionInfoToEditor(ActionInfo info, Point point)
        {
            ActionElement ele = new ActionElement(info);

            ele.Location = ToViewCoord(point);
            _bindingEnvironment.Add(ele);
            _container.Invalidate();
        }
Exemple #4
0
 public void Add(ActionElement ele)
 {
     ele.Name = GetUniqueName(ele);
     _actionElements.Add(ele);
     if (_actionElements.Count == 3)
     {
         _actionElementLinks.Add(new ActionElementLink(_actionElements[0], _actionElements[1]));
         _actionElementLinks.Add(new ActionElementLink(_actionElements[1], _actionElements[2]));
         _actionElementLinks.Add(new ActionElementLink(_actionElements[2], _actionElements[0]));
     }
 }
Exemple #5
0
        private string GetUniqueName(ActionElement ele)
        {
            string exp = @"(?<NAME>\S*)\((?<ID>\d+)\)$";

            foreach (ActionElement e in _actionElements)
            {
                if (e.Name.ToUpper() == ele.Name.ToUpper())
                {
                    string name = ele.Name;
                    int    idx  = GetMaxIdx(ele.Name, exp);
                    return(name + "(" + idx.ToString() + ")");
                }
            }
            return(ele.Name);
        }
Exemple #6
0
        public static void LoadFrom(string[] assemblyDirs, string scriptfilename, out List <ActionElement> elements, out List <ActionElementLink> links)
        {
            elements = null;
            links    = null;
            using (TaskScriptParser parser = new TaskScriptParser(assemblyDirs))
            {
                ArgAutoBingdingEnvironment env = null;
                parser.FromTaskScriptFile(scriptfilename, out env);
                if (env == null || env.ActionArgSettings == null || env.ActionArgSettings.Length == 0)
                {
                    throw new Exception("脚本文件\"" + scriptfilename + "\"为空。");
                }
                Dictionary <int, ActionElement>            eles     = new Dictionary <int, ActionElement>();
                Dictionary <LinkObject, ActionElementLink> linkObjs = new Dictionary <LinkObject, ActionElementLink>();
                foreach (ActionArgCollection action in env.ActionArgSettings)
                {
                    ActionElement ele = GetActionElement(action);
                    eles.Add(action.Id, ele);
                    //
                    foreach (ActionArg arg in action.ActionArgs)
                    {
                        switch (arg.ArgType)
                        {
                        case enumArgType.Value:
                            break;

                        case enumArgType.Var:
                            break;

                        case enumArgType.Ref:
                            LinkObject lnkObj = GetLinkObject(linkObjs, action.Id, arg.RefActionId);
                            if (lnkObj != null)     //添加一条函数映射关系
                            {
                            }
                            else
                            {
                                ActionElement     refActionElement = GetActionElement(arg.RefActionId, eles);
                                ActionElementLink actionLnk        = new ActionElementLink(refActionElement, ele);
                                linkObjs.Add(new LinkObject(action.Id, arg.RefActionId), actionLnk);
                            }
                            break;
                        }
                    }
                }
                elements = new List <ActionElement>(eles.Values.ToArray());
                links    = new List <ActionElementLink>(linkObjs.Values.ToArray());
            }
        }
Exemple #7
0
 public ActionElementLink(ActionElement preAction, ActionElement nextAction)
 {
     _preActionElement  = preAction;
     _nextActionElement = nextAction;
 }
Exemple #8
0
        public static void GetLinkLine(ActionElement fAction, ActionElement tAction, out PointF fpt, out PointF tpt)
        {
            //直线点
            PointF p1 = new PointF(fAction.Location.X + fAction.Size.Width / 2, fAction.Location.Y + fAction.Size.Height / 2);

            fpt = p1;
            PointF p2 = new PointF(tAction.Location.X + tAction.Size.Width / 2, tAction.Location.Y + tAction.Size.Height / 2);
            //椭圆的点
            PointF ep1 = new PointF(tAction.Location.X, tAction.Location.Y + tAction.Size.Height / 2); //左边的点
            PointF ep2 = new PointF(tAction.Location.X + tAction.Size.Width / 2, tAction.Location.Y);  //上边的点

            //将这些点变换到直角坐标系
            PointF[] pts = new PointF[] { p1, p2, ep1, ep2 };
            Matrix   m   = new Matrix();

            m.Scale(1f, -1f);
            m.Translate(-(tAction.Location.X + tAction.Size.Width / 2), -(tAction.Location.Y + tAction.Size.Height / 2));
            m.TransformPoints(pts);
            p1  = pts[0];
            p2  = pts[1];
            ep1 = pts[2];
            ep2 = pts[3];
            //
            double x = 0, y = 0;

            //计算直线的参数
            if (Math.Abs(p2.X - p1.X) < float.Epsilon) //两个椭圆的中心都与Y轴重合
            {
                x = p1.X;
                if (p1.Y < p2.Y)
                {
                    y = ep2.Y - tAction.Size.Height;
                }
                else
                {
                    y = ep2.Y;
                }
            }
            else
            {
                float k = (p2.Y - p1.Y) / (p2.X - p1.X);
                //计算椭圆的参数
                float c = Math.Abs(ep1.X), d = Math.Abs(ep2.Y); //X^2/c + Y^2/d = 1
                c *= c;
                d *= d;
                //计算交点
                double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
                x1 = Math.Sqrt((c * d) / (d + c * k * k));
                x2 = -x1;
                y1 = k * x1;
                y2 = k * x2;
                //坐标反变换到屏幕坐标
                if (p1.X > 0)
                {
                    x = x1 > 0 ? x1 : x2;
                }
                else
                {
                    x = x1 > 0 ? x2 : x1;
                }
                if (p1.Y > 0)
                {
                    y = y1 > 0 ? y1 : y2;
                }
                else
                {
                    y = y1 > 0 ? y2 : y1;
                }
            }
            pts = new PointF[] { new PointF((float)x, (float)y) };
            m.Invert();
            m.TransformPoints(pts);
            tpt = pts[0];
            m.Dispose();
        }