Ejemplo n.º 1
0
            private void PinLoaded(Task <DTopic> tt)
            {
                DTopic t;

                if (tt.IsFaulted || !tt.IsCompleted || (t = tt.Result) == null)
                {
                    return;
                }
                loPin p;

                var chs = model.Manifest["Children"];

                if (chs.ValueType != JSC.JSValueType.Object || chs.Value == null)
                {
                    lv.TopicLoaded(t);
                    return;
                }
                var pd = chs[t.name];
                int ddr;

                if (pd.ValueType != JSC.JSValueType.Object || pd.Value == null || (ddr = JsLib.OfInt(pd, "ddr", 0)) == 0)
                {
                    lv.TopicLoaded(t);
                    return;
                }
                p = new loPin(this, t, ddr < 0);
                _pins.Add(p);
                lv.AddVisual(p);
                t.changed += pin_changed;

                lv.TopicLoaded(t);
                this.Render(3);
            }
Ejemplo n.º 2
0
 public loBinding(loPin input, loPin output, LogramView lv)
     : base(lv)
 {
     this.Input  = input;
     this.Output = output;
     lv.AddVisual(this);
 }
Ejemplo n.º 3
0
 private loVariable(DTopic model, LogramView lv)
     : base(lv)
 {
     this.model  = model;
     this.Output = new loPin(this, model, false);
     this.Input  = new loPin(this, model, true);
     Render(3);
 }
Ejemplo n.º 4
0
 public void SetFinish(loPin finish)
 {
     if (Input == null && !finish.IsInput)
     {
         Input = finish;
     }
     else if (Output == null && finish.IsFreeInput)
     {
         Output = finish;
     }
     Output.GetModel().SetField("cctor.LoBind", Input.GetModel().path);
     this.Dispose();
 }
Ejemplo n.º 5
0
 public loBinding(loPin start, LogramView lv)
     : base(lv)
 {
     if (start.IsInput)
     {
         this.Input  = null;
         this.Output = start;
     }
     else
     {
         this.Input  = start;
         this.Output = null;
     }
     Render(3);
     lv.AddVisual(this);
 }
Ejemplo n.º 6
0
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Right && e.RightButton == MouseButtonState.Released)
            {
                DTopic cur;
                if (selected != null && (cur = selected.GetModel()) != null)
                {
                    var cm = (this as Canvas).ContextMenu;
                    cm.ItemsSource = MenuItems(cur, selected);
                    cm.IsOpen      = true;
                }
                e.Handled = true;
                return;
            }
            else
            if (e.ChangedButton == MouseButton.Left && e.LeftButton == MouseButtonState.Released)
            {
                if (_mSelected != null && _mSelected.Length > 0)
                {
                    var    cp = e.GetPosition(this);
                    double r = 0, d = 0;
                    foreach (var el in _mSelected)
                    {
                        if (move)
                        {
                            el.SetLocation(new Vector(el.OriginalLocation.X + (cp.X - ScreenStartPoint.X), el.OriginalLocation.Y + (cp.Y - ScreenStartPoint.Y)), true);
                            d = Math.Max(d, el.Offset.Y + el.ContentBounds.Bottom);
                            r = Math.Max(r, el.Offset.X + el.ContentBounds.Right);
                        }
                        el.Select(false);
                    }
                    _mSelected = null;
                    if (move)
                    {
                        if (d + CELL_SIZE > this.Height)
                        {
                            _model.SetField("Logram.height", (int)(d + CELL_SIZE));
                        }
                        if (r + CELL_SIZE > this.Width)
                        {
                            _model.SetField("Logram.width", (int)(r + CELL_SIZE));
                        }
                    }
                }
                if (IsMouseCaptured)
                {
                    Cursor = Cursors.Arrow;
                    ReleaseMouseCapture();
                }
                else if (selected != null)
                {
                    loElement el;
                    loBinding w;
                    var       cp = e.GetPosition(this);
                    if ((el = selected as loElement) != null && move)
                    {
                        el.SetLocation(new Vector(el.OriginalLocation.X + (cp.X - ScreenStartPoint.X), el.OriginalLocation.Y + (cp.Y - ScreenStartPoint.Y)), true);
                        if (selected.Offset.Y + selected.ContentBounds.Bottom + CELL_SIZE > this.Height)
                        {
                            _model.SetField("Logram.height", (int)(selected.Offset.Y + selected.ContentBounds.Bottom + CELL_SIZE));
                        }
                        if (selected.Offset.X + selected.ContentBounds.Right + CELL_SIZE > this.Width)
                        {
                            _model.SetField("Logram.width", (int)(selected.Offset.X + selected.ContentBounds.Right + CELL_SIZE));
                        }
                    }
                    else if ((w = selected as loBinding) != null && (w.Output == null || w.Input == null))
                    {
                        loPin finish = GetVisual(cp.X, cp.Y) as loPin;
                        if (finish != null && ((w.Output == null && finish.GetModel() != w.Input.GetModel() && finish.IsFreeInput) || (w.Input == null && finish.GetModel() != w.Output.GetModel() && !finish.IsInput))) //-V3080 //-V3027
                        {
                            w.SetFinish(finish);
                        }
                        else
                        {
                            this.DeleteVisual(w);
                        }
                    }
                }
                else if (_multipleSelection)
                {
                    var cp = e.GetPosition(this);
                    _multipleSelection = false;
                    base.RemoveVisualChild(_mSelectVisual);
                    var objs = new List <loElement>();
                    GeometryHitTestParameters parameters;
                    {
                        double l, t, w, h;
                        if (cp.X - ScreenStartPoint.X < 0)
                        {
                            l = cp.X;
                            w = ScreenStartPoint.X - cp.X;
                        }
                        else
                        {
                            l = ScreenStartPoint.X;
                            w = cp.X - ScreenStartPoint.X;
                        }
                        if (cp.Y - ScreenStartPoint.Y < 0)
                        {
                            t = cp.Y;
                            h = ScreenStartPoint.Y - cp.Y;
                        }
                        else
                        {
                            t = ScreenStartPoint.Y;
                            h = cp.Y - ScreenStartPoint.Y;
                        }
                        parameters = new GeometryHitTestParameters(new RectangleGeometry(new Rect(l, t, w, h)));
                    }

                    VisualTreeHelper.HitTest(this, null, new HitTestResultCallback((hr) => {
                        var rez = (GeometryHitTestResult)hr;
                        var vis = hr.VisualHit as loElement;
                        if (vis != null && rez.IntersectionDetail == IntersectionDetail.FullyInside)
                        {
                            objs.Add(vis);
                        }
                        return(HitTestResultBehavior.Continue);
                    }), parameters);
                    if (objs.Count > 0)
                    {
                        if (objs.Count == 1)
                        {
                            selected = objs[0];
                        }
                        else
                        {
                            _mSelected = objs.ToArray();
                            foreach (var el in _mSelected)
                            {
                                el.Select(true);
                            }
                        }
                    }
                }
                else
                {
                    base.OnMouseUp(e);
                }
                move = false;
            }
            else
            {
                base.OnMouseUp(e);
            }
        }
Ejemplo n.º 7
0
            public override void Render(int chLevel)
            {
                int x, y;

                y = JsLib.OfInt(JsLib.GetField(model.Manifest, "Logram.top"), 0);
                x = JsLib.OfInt(JsLib.GetField(model.Manifest, "Logram.left"), 0);
                base.OriginalLocation = new Vector(x * CELL_SIZE, (y - 0.5) * CELL_SIZE);
                this.Offset           = OriginalLocation;


                FormattedText head = new FormattedText(model.name, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.Black);

                FormattedText[] textIp = new FormattedText[MAX_PINS];
                loPin[]         pinIp  = new loPin[MAX_PINS];
                int             cntIp  = 0;

                FormattedText[] textOp = new FormattedText[MAX_PINS];
                loPin[]         pinOp  = new loPin[MAX_PINS];
                int             cntOp  = 0;
                int             pos    = 0;
                double          wi     = CELL_SIZE;
                double          wo     = CELL_SIZE;

                var chs = model.Manifest["Children"];

                if (chs.ValueType != JSC.JSValueType.Object || chs.Value == null)
                {
                    return;
                }

                foreach (var p in _pins)
                {
                    var pd = chs[p.GetModel().name];
                    int ddr;
                    if (pd.ValueType != JSC.JSValueType.Object || pd.Value == null || (ddr = JsLib.OfInt(pd, "ddr", 0)) == 0)
                    {
                        continue;
                    }
                    var    ft = new FormattedText(p.GetModel().name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.White);
                    double cw = 7 + ft.WidthIncludingTrailingWhitespace;
                    if (ddr < 0) // Input
                    {
                        pos = -ddr - 1;
                        if (cntIp < pos + 1)
                        {
                            cntIp = pos + 1;
                        }
                        pinIp[pos]  = p;
                        textIp[pos] = ft;
                        if (pos == 0)
                        {
                            cw += 9;
                        }
                        wi = Math.Max(wi, cw);
                    }
                    else // Output
                    {
                        pos = ddr - 1;
                        if (cntOp < pos + 1)
                        {
                            cntOp = pos + 1;
                        }
                        pinOp[pos]  = p;
                        textOp[pos] = ft;
                        if (pos == 0)
                        {
                            cw += 9;
                        }
                        wo = Math.Max(wo, cw);
                    }
                }
                double width  = Math.Ceiling(Math.Max(head.WidthIncludingTrailingWhitespace, wi + wo) / CELL_SIZE) * CELL_SIZE;
                double height = Math.Max(cntIp * CELL_SIZE, cntOp * CELL_SIZE);

                if (height == 0) //-V3024
                {
                    return;
                }
                if (chLevel == 3)
                {
                    lv.MapRemove(this);
                    int cw = (int)width / CELL_SIZE;
                    int ch = 1 + (int)height / CELL_SIZE;
                    for (int i = cw; i >= 0; i--)
                    {
                        for (int j = ch - 1; j >= 0; j--)
                        {
                            lv.MapSet(0, x + i, y + j, this);
                            lv.MapSet(1, x + i, y + j, this);
                            lv.MapSet(2, x + i, y + j, this);
                            lv.MapSet(3, x + i, y + j, this);
                        }
                    }
                }
                base.VisualBitmapScalingMode = BitmapScalingMode.HighQuality;
                using (DrawingContext dc = this.RenderOpen()) {
                    dc.DrawRectangle(Brushes.White, null, new Rect(-2, 2, width + 4, height + CELL_SIZE - 2));
                    dc.DrawRectangle(_selected ? brItemSelected : brElementBody, null, new Rect(0, CELL_SIZE, width, height));
                    dc.DrawText(head, new Point((width - head.WidthIncludingTrailingWhitespace) / 2, 1));
                    int i;
                    for (i = 0; i < cntIp; i++)
                    {
                        if (textIp[i] != null && pinIp[i] != null)
                        {
                            if (i == 0)
                            {
                                wi = Math.Max((width - CELL_SIZE) / 2, Math.Ceiling((2 * textIp[i].WidthIncludingTrailingWhitespace) / CELL_SIZE) * CELL_SIZE / 2);
                            }
                            dc.DrawText(textIp[i], new Point(7, (i + 1) * CELL_SIZE + 1));
                        }
                    }
                    dc.DrawImage(App.GetIcon(JsLib.OfString(model.Manifest["icon"], null)), new Rect(wi, CELL_SIZE, CELL_SIZE, CELL_SIZE));
                    int inW = (int)width / CELL_SIZE;
                    for (i = 0; i < cntOp; i++)
                    {
                        if (textOp[i] != null && pinOp[i] != null)
                        {
                            dc.DrawText(textOp[i], new Point(width - 7 - textOp[i].WidthIncludingTrailingWhitespace, (i + 1) * CELL_SIZE + 1));
                        }
                    }
                }
                if (chLevel > 0)
                {
                    int i;
                    for (i = 0; i < cntIp; i++)
                    {
                        if (pinIp[i] != null)
                        {
                            pinIp[i].SetLocation(new Vector(0, i * CELL_SIZE + CELL_SIZE * 1.5), chLevel);
                        }
                    }
                    for (i = 0; i < cntOp; i++)
                    {
                        if (pinOp[i] != null)
                        {
                            pinOp[i].SetLocation(new Vector(width, i * CELL_SIZE + CELL_SIZE * 1.5), chLevel);
                        }
                    }
                }
            }