Exemplo n.º 1
0
 private void ModelChanged(DTopic.Art a, DTopic t)
 {
     if (t == _model)
     {
         if (a == DTopic.Art.type)
         {
             this.Width  = JsLib.OfInt(JsLib.GetField(_model.Manifest, "Logram.width"), 32 * CELL_SIZE);
             this.Height = JsLib.OfInt(JsLib.GetField(_model.Manifest, "Logram.height"), 18 * CELL_SIZE);
         }
     }
     else if (t.parent == _model)
     {
         if (a == DTopic.Art.addChild)
         {
             t.GetAsync(null).ContinueWith(MChildrenLoad, TaskScheduler.FromCurrentSynchronizationContext());
         }
         else if (a == DTopic.Art.RemoveChild)
         {
             foreach (var it in _visuals.OfType <loElement>().Where(z => z.GetModel() == t).ToArray())
             {
                 it.Dispose();
             }
         }
     }
 }
Exemplo n.º 2
0
 private void ChildChanged(DTopic.Art a, DTopic t)
 {
     if (t.parent == _model)
     {
         if (JsLib.OfString(JsLib.GetField(t.Manifest, "cctor.LoBlock"), null) != null)
         {
             if (a == DTopic.Art.addChild)
             {
                 var b = _visuals.OfType <loBlock>().FirstOrDefault(z => z.GetModel() == t);
                 if (b == null)
                 {
                     loBlock.Create(t, this);
                 }
             }
         }
         else
         {
             if (a == DTopic.Art.addChild)
             {
                 var p = _visuals.OfType <loVariable>().FirstOrDefault(z => z.GetModel() == t);
                 if (p == null)
                 {
                     loVariable.Create(t, this);
                     TopicLoaded(t);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        private void miTrace_Click(object sender, RoutedEventArgs e)
        {
            DTopic t;
            var    mi = sender as MenuItem;

            if (mi == null || (t = mi.Tag as DTopic) == null)
            {
                return;
            }
            bool ic = JsLib.ofBool(JsLib.GetField(t.Manifest, "Logram.trace"), false);

            t.SetField("Logram.trace", !ic);
        }
Exemplo n.º 4
0
        private void ExportI1(XElement x, bool isRoot = false)
        {
            XElement xCur = isRoot ? x : new XElement("i", new XAttribute("n", this.name));

            var tmp = JsLib.GetField(this._manifest, "attr");

            if (tmp.IsNumber && (((int)tmp) & 0x0C) != 0 && this._state.Exists)
            {
                xCur.Add(new XAttribute("s", JsLib.Stringify(this._state)));
            }
            tmp = JsLib.GetField(this._manifest, "version");
            string  vs;
            Version v;

            if (tmp.ValueType == JSC.JSValueType.String && !string.IsNullOrEmpty(vs = tmp.Value as string) && vs.StartsWith("¤VR") && Version.TryParse(vs.Substring(3), out v))
            {
                tmp = JsLib.Clone(this._manifest);
                tmp.DeleteProperty("version");
                xCur.Add(new XAttribute("m", JsLib.Stringify(tmp)));
                if (!isRoot)
                {
                    xCur.Add(new XAttribute("ver", v.ToString()));
                }
            }
            else
            {
                xCur.Add(new XAttribute("m", JsLib.Stringify(this._manifest)));
            }
            if (isRoot)
            {
                var now = DateTime.Now;
                xCur.Add(new XAttribute("ver", (new Version(0, 4, (now.Year % 100) * 100 + now.Month, now.Day * 1000 + (int)(now.TimeOfDay.TotalDays * 1000)).ToString())));
            }
            else
            {
                x.Add(xCur);
            }
            if (this._children != null)
            {
                var ch = this._children.ToArray();
                for (int i = 0; i < ch.Length; i++)
                {
                    var tt = ch[i].GetAsync(null);
                    tt.Wait();
                    if (tt.IsCompleted && !tt.IsFaulted && tt.Result != null)
                    {
                        tt.Result.ExportI1(xCur);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public ObservableCollection <Control> MenuItems(DTopic t, loItem ctrl)
        {
            var l = new ObservableCollection <Control>();

            JSC.JSValue v1;
            MenuItem    mi;

            mi = new MenuItem()
            {
                Header = "Open in new tab", Tag = t
            };
            mi.Click += miOpen_Click;
            l.Add(mi);
            mi = new MenuItem()
            {
                Header = "Show in Workspace", Tag = t
            };
            mi.Click += miShow_Click;
            l.Add(mi);

            l.Add(new Separator());
            if (ctrl is loPin)
            {
                bool ic = JsLib.ofBool(JsLib.GetField(t.Manifest, "Logram.trace"), false);
                mi = new MenuItem()
                {
                    Header = "Trace", Tag = t, IsCheckable = true, IsChecked = ic
                };
                mi.Click += miTrace_Click;
                l.Add(mi);
                l.Add(new Separator());
            }
            if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.Object)
            {
                var ad = new Dictionary <string, JSC.JSValue>();
                Jso2Acts(v1, ad);
                FillContextMenu(t, l, ad);
            }
            else if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.String)
            {
                t.GetAsync(v1.Value as string).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                t.Connection.CoreTypes.GetAsync(null).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext());
            }
            return(l);
        }
Exemplo n.º 6
0
            public override void SetLocation(Vector loc, bool save)
            {
                int topCell = (int)(loc.Y / CELL_SIZE + 0.5);

                if (topCell < 0)
                {
                    topCell = 0;
                }
                int leftCell = (int)(loc.X / CELL_SIZE);

                if (leftCell < 0)
                {
                    leftCell = 0;
                }

                if (save)
                {
                    var lo = JsLib.GetField(model.Manifest, "Logram");
                    int xo, yo;
                    xo = JsLib.OfInt(JsLib.GetField(lo, "left"), 0);
                    yo = JsLib.OfInt(JsLib.GetField(lo, "top"), 0);

                    if (xo == leftCell && yo == topCell) // refresh wires
                    {
                        this.Dispatcher.BeginInvoke(new Action <int>(this.Render), System.Windows.Threading.DispatcherPriority.DataBind, 3);
                    }
                    else
                    {
                        lo = JsLib.SetField(lo, "top", topCell);
                        lo = JsLib.SetField(lo, "left", leftCell);
                        model.SetField("Logram", lo);
                    }
                }
                else
                {
                    this.Offset = new Vector(leftCell * CELL_SIZE, (topCell - 0.5) * CELL_SIZE);
                    foreach (var p in _pins)
                    {
                        p.Render(2);
                    }
                }
            }
Exemplo n.º 7
0
        private void Create(Topic parent, string path, JSC.JSValue state, JSC.JSValue manifest)
        {
            var t = Topic.I.Get(parent, path, true, _owner, false, false);

            Topic.I.Fill(t, state, manifest, _owner);
            JSC.JSValue typeS, typeV, ChL;
            Topic       typeT;

            if (manifest != null && (typeS = manifest["type"]).ValueType == JSC.JSValueType.String && !string.IsNullOrWhiteSpace(typeS.Value as string) &&
                Topic.root.Get("/$YS/TYPES").Exist(typeS.Value as string, out typeT) && (typeV = typeT.GetState()) != null && typeV.ValueType == JSC.JSValueType.Object && typeV.Value != null &&
                (ChL = typeV["Children"]).ValueType == JSC.JSValueType.Object && ChL.Value != null)
            {
                foreach (var ch in ChL)
                {
                    if ((JsLib.OfInt(JsLib.GetField(ch.Value, "manifest.attr"), 0) & (int)Topic.Attribute.Required) != 0)
                    {
                        Create(t, ch.Key, ch.Value["default"], ch.Value["manifest"]);
                    }
                }
            }
        }
Exemplo n.º 8
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);
                double width = 0;

                base.OriginalLocation = new Vector(x * CELL_SIZE, (y - 0.5) * CELL_SIZE);
                this.Offset           = OriginalLocation;

                using (DrawingContext dc = this.RenderOpen()) {
                    FormattedText ft = new FormattedText(model.name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, LFont, CELL_SIZE * 0.7, Brushes.White);
                    width = Math.Ceiling((ft.WidthIncludingTrailingWhitespace + 11) / CELL_SIZE) * CELL_SIZE;
                    dc.DrawRoundedRectangle(_selected ? brItemSelected : brElementBody, null, new Rect(0, 1, width - 1, CELL_SIZE - 3), CELL_SIZE / 4, CELL_SIZE / 4); //-V3041
                    ft.MaxTextHeight = CELL_SIZE - 3;
                    ft.MaxTextWidth  = width - 11;
                    dc.DrawText(ft, new Point(5, 1));
                }
                if (chLevel == 3)
                {
                    lv.MapRemove(this);
                    for (int w = (int)(width / CELL_SIZE + 0.5); w >= 0; w--)
                    {
                        lv.MapSet(0, x + w, y, this);
                        lv.MapSet(1, x + w, y, this);
                        lv.MapSet(2, x + w, y, this);
                        lv.MapSet(3, x + w, y, this);
                    }
                }

                if (chLevel > 1)
                {
                    Output.SetLocation(new Vector(width, CELL_SIZE / 2), chLevel); //-V3041
                    Input.SetLocation(new Vector(0, CELL_SIZE / 2), chLevel);      //-V3041
                }
            }
Exemplo n.º 9
0
        private void CheckCCtor(Perform p)
        {
            SortedList <string, JSValue> lo = null, ln = null, lc = null;
            JSValue to = null, tn = p.src.GetField("type"), vn;

            if (p.art == Perform.Art.changedField)
            {
                JSValue o = JsLib.GetField(p.old_o as JSValue, "cctor"), n = p.src.GetField("cctor");
                to = JsLib.GetField(p.old_o as JSValue, "type");
                if (!object.ReferenceEquals(o, n))
                {
                    JsLib.Propertys(ref lo, o);
                    JsLib.Propertys(ref ln, n);
                }
            }
            else if (p.art == Perform.Art.create)
            {
                JsLib.Propertys(ref ln, p.src.GetField("cctor"));
            }
            else if (p.art == Perform.Art.remove)
            {
                JsLib.Propertys(ref lo, p.src.GetField("cctor"));
            }
            else
            {
                return;
            }
            if (!object.ReferenceEquals(to, tn))
            {
                Topic tt;
                if (to != null && to.ValueType == JSValueType.String && to.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(to.Value as string, out tt))
                {
                    JsLib.Propertys(ref lo, JsLib.GetField(tt.GetState(), "cctor"));
                }
                if (tn != null && tn.ValueType == JSValueType.String && tn.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(tn.Value as string, out tt))
                {
                    JsLib.Propertys(ref ln, JsLib.GetField(tt.GetState(), "cctor"));
                }
            }
            if (lo != null && ln != null)
            {
                foreach (var k in lo.Where(z => ln.ContainsKey(z.Key)).Select(z => z.Key).ToArray())
                {
                    vn = ln[k];
                    if (!JSValue.ReferenceEquals(lo[k], vn))
                    {
                        if (lc == null)
                        {
                            lc = new SortedList <string, JSValue>();
                        }
                        lc.Add(k, vn);
                    }
                    lo.Remove(k);
                    ln.Remove(k);
                }
            }

            if (lo != null)
            {
                ProcessCCtor(lo, p.src, Perform.Art.remove);
            }
            if (ln != null)
            {
                ProcessCCtor(ln, p.src, Perform.Art.create);
            }
            if (lc != null)
            {
                ProcessCCtor(lc, p.src, Perform.Art.changedField);
            }
        }
Exemplo n.º 10
0
        private void FillContextMenu(DTopic owner, ObservableCollection <Control> l, Dictionary <string, JSC.JSValue> _acts)
        {
            JSC.JSValue v2;
            MenuItem    mi;
            MenuItem    ma = new MenuItem()
            {
                Header = "Add"
            };

            if (_acts != null)
            {
                List <RcUse> resource = new List <RcUse>();
                string       rName;
                JSC.JSValue  tmp1;
                KeyValuePair <string, JSC.JSValue> rca;
                string rcs;
                // fill used resources
                if (owner.children != null)
                {
                    foreach (var ch in owner.children)
                    {
                        if ((tmp1 = JsLib.GetField(ch.Manifest, "MQTT-SN.tag")).ValueType != JSC.JSValueType.String || string.IsNullOrEmpty(rName = tmp1.Value as string))
                        {
                            rName = ch.name;
                        }
                        rca = _acts.FirstOrDefault(z => z.Key == rName);
                        if (rca.Value == null || (tmp1 = rca.Value["rc"]).ValueType != JSC.JSValueType.String || string.IsNullOrEmpty(rcs = tmp1.Value as string))
                        {
                            continue;
                        }
                        foreach (string curRC in rcs.Split(',').Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 1))
                        {
                            int pos;
                            if (!int.TryParse(curRC.Substring(1), out pos))
                            {
                                continue;
                            }
                            for (int i = pos - resource.Count; i >= 0; i--)
                            {
                                resource.Add(RcUse.None);
                            }
                            if (curRC[0] != (char)RcUse.None && (curRC[0] != (char)RcUse.Shared || resource[pos] != RcUse.None))
                            {
                                resource[pos] = (RcUse)curRC[0];
                            }
                        }
                    }
                }
                // Add menuitems
                foreach (var kv in _acts)
                {
                    if ((bool)kv.Value["willful"])
                    {
                        continue;
                    }
                    bool busy = false;
                    if ((tmp1 = kv.Value["rc"]).ValueType == JSC.JSValueType.String && !string.IsNullOrEmpty(rcs = tmp1.Value as string)) // check used resources
                    {
                        foreach (string curRC in rcs.Split(',').Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 1))
                        {
                            int pos;
                            if (!int.TryParse(curRC.Substring(1), out pos))
                            {
                                continue;
                            }
                            if (pos < resource.Count && ((curRC[0] == (char)RcUse.Exclusive && resource[pos] != RcUse.None) || (curRC[0] == (char)RcUse.Shared && resource[pos] != RcUse.None && resource[pos] != RcUse.Shared)))
                            {
                                busy = true;
                                break;
                            }
                        }
                    }
                    if (busy)
                    {
                        continue;
                    }
                    mi = new MenuItem()
                    {
                        Header = kv.Key.Replace("_", "__"), Tag = JsLib.SetField(kv.Value, "mi_path", owner.name + "/" + kv.Key)
                    };
                    if ((v2 = kv.Value["icon"]).ValueType == JSC.JSValueType.String)
                    {
                        mi.Icon = new Image()
                        {
                            Source = App.GetIcon(v2.Value as string), Height = 16, Width = 16
                        };
                    }
                    else
                    {
                        mi.Icon = new Image()
                        {
                            Source = App.GetIcon(kv.Key), Height = 16, Width = 16
                        };
                    }
                    if ((v2 = kv.Value["hint"]).ValueType == JSC.JSValueType.String)
                    {
                        mi.ToolTip = v2.Value;
                    }
                    mi.Click += miAdd_Click;
                    if ((v2 = kv.Value["menu"]).ValueType == JSC.JSValueType.String && kv.Value.Value != null)
                    {
                        AddSubMenu(ma, v2.Value as string, mi);
                    }
                    else
                    {
                        ma.Items.Add(mi);
                    }
                }
            }
            if (ma.HasItems)
            {
                if (ma.Items.Count < 5)
                {
                    foreach (var sm in ma.Items.OfType <System.Windows.Controls.Control>())
                    {
                        l.Add(sm);
                    }
                }
                else
                {
                    l.Add(ma);
                }
                l.Add(new Separator());
            }
            //if((v2 = owner.Manifest["Action"]).ValueType == JSC.JSValueType.Object) {
            //  FillActions(l, v2);
            //}
            //Uri uri;
            //if(System.Windows.Clipboard.ContainsText(System.Windows.TextDataFormat.Text)
            //  && Uri.TryCreate(System.Windows.Clipboard.GetText(System.Windows.TextDataFormat.Text), UriKind.Absolute, out uri)
            //  && _owner.Connection.server == uri.DnsSafeHost) {
            //  mi = new MenuItem() { Header = "Paste", Icon = new Image() { Source = App.GetIcon("component/Images/Edit_Paste.png"), Width = 16, Height = 16 } };
            //  mi.Click += miPaste_Click;
            //  l.Add(mi);
            //}
            //mi = new MenuItem() { Header = "Cut", Icon = new Image() { Source = App.GetIcon("component/Images/Edit_Cut.png"), Width = 16, Height = 16 } };
            //mi.IsEnabled = !IsGroupHeader && !IsRequired;
            //mi.Click += miCut_Click;
            //l.Add(mi);
            mi = new MenuItem()
            {
                Header = "Delete", Icon = new Image()
                {
                    Source = App.GetIcon("component/Images/Edit_Delete.png"), Width = 16, Height = 16
                }, Tag = owner
            };
            mi.Click    += miDelete_Click;
            mi.IsEnabled = (owner.Manifest == null || (JsLib.OfInt(owner.Manifest["attr"], 0) & 1) != 1);
            l.Add(mi);
        }
Exemplo n.º 11
0
        private void LogramView_Drop(object sender, DragEventArgs e)
        {
            var pos = e.GetPosition(this);
            int y   = (int)(pos.Y / CELL_SIZE + 0.5);

            if (y < 0)
            {
                y = 0;
            }
            int x = (int)(pos.X / CELL_SIZE);

            if (x < 0)
            {
                x = 0;
            }
            DTopic t;

            if (e.Data.GetDataPresent(typeof(DTopic)) && (t = e.Data.GetData(typeof(DTopic)) as DTopic) != null)
            {
                if (JsLib.OfString(JsLib.GetField(t.Manifest, "type"), null) == "Ext/LBDescr")
                {
                    if (t.State.ValueType == JSC.JSValueType.Object && t.State.Value != null)
                    {
                        string name;
                        string prefix = JsLib.OfString(t.State["namePrefix"], "U");
                        if (Model.children != null)
                        {
                            int i = 1;
                            do
                            {
                                name = prefix + i.ToString("D02");
                                i++;
                            } while(Model.children.Any(z => z.name == name));
                        }
                        else
                        {
                            name = prefix + "01";
                        }
                        Model.CreateAsync(name, t.State["default"], JsLib.SetField(JsLib.SetField(t.State["manifest"], "Logram.top", y), "Logram.left", x));
                    }
                }
                else if ((e.AllowedEffects & DragDropEffects.Link) == DragDropEffects.Link)
                {
                    string name = t.name;
                    if (Model.children != null && Model.children.Any(z => z.name == name))
                    {
                        if (t.parent == null || (name = t.parent.name + "_" + t.name) == null || Model.children.Any(z => z.name == name))
                        {
                            int i = 1;
                            do
                            {
                                name = string.Format("{0}_{1}", t.name, i);
                                i++;
                            } while(Model.children.Any(z => z.name == name));
                        }
                    }
                    var m  = JSC.JSObject.CreateObject();
                    var ml = JSC.JSObject.CreateObject();
                    ml["top"]   = y;
                    ml["left"]  = x;
                    m["Logram"] = ml;
                    var mc = JSC.JSObject.CreateObject();
                    mc["LoBind"] = t.path;
                    m["cctor"]   = mc;
                    m["attr"]    = 0;
                    Model.CreateAsync(name, t.State, m);
                    if (string.IsNullOrEmpty(JsLib.OfString(JsLib.GetField(t.Manifest, "cctor.LoBind"), null)))
                    {
                        t.SetField("cctor.LoBind", Model.path + "/" + name);
                    }
                }
            }
        }
Exemplo n.º 12
0
            public static void Publish(Perform cmd)
            {
                SubRec sb;
                Topic  t = cmd.src;

                if ((cmd.art == Perform.Art.subscribe || cmd.art == Perform.Art.subAck) && (sb = cmd.o as SubRec) != null)
                {
                    try {
                        sb.func(cmd, sb);
                    }
                    catch (Exception ex) {
                        Log.Warning("{0}.{1}({2}) - {3}", sb.func.Method.DeclaringType.Name, sb.func.Method.Name, cmd.ToString(), ex.ToString());
                    }
                }
                else
                {
                    if (t._subRecords != null)
                    {
                        for (int i = t._subRecords.Count - 1; i >= 0; i--)
                        {
                            sb = t._subRecords[i];
                            if (((sb.mask & SubRec.SubMask.OnceOrAll) != SubRec.SubMask.None || ((sb.mask & SubRec.SubMask.Chldren) == SubRec.SubMask.Chldren && sb.setTopic == t.parent)) &&
                                (cmd.art != Perform.Art.changedState || (sb.mask & SubRec.SubMask.Value) == SubRec.SubMask.Value) &&
                                (cmd.art != Perform.Art.changedField || ((sb.mask & SubRec.SubMask.Field) == SubRec.SubMask.Field && !object.ReferenceEquals(JsLib.GetField(cmd.old_o as JSValue, sb.prefix ?? string.Empty), JsLib.GetField(t._manifest, sb.prefix ?? string.Empty))))
                                )
                            {
                                try {
                                    //Log.Debug("$ {0} <= {1}", sb.ToString(), cmd.ToString());
                                    sb.func(cmd, sb);
                                }
                                catch (Exception ex) {
                                    Log.Warning("{0}.{1}({2}) - {3}", sb.func.Method.DeclaringType.Name, sb.func.Method.Name, cmd.ToString(), ex.ToString());
                                }
                            }
                        }
                    }
                }
            }
Exemplo n.º 13
0
            public override void Render(int chLevel)
            {
                if (model == null || model.State == null || model.Manifest == null)
                {
                    return;
                }
                if (_mode != 0 && chLevel == 3)
                {
                    var src_s = JsLib.OfString(JsLib.GetField(model.Manifest, "cctor.LoBind"), null);
                    if (src_s == null)
                    {
                        _mode = 1;
                    }
                    else if (_source == null || _source.path != src_s || (_mode == 2 && _srcBinding == null && lv._dataIsLoaded))
                    {
                        model.GetAsync(src_s).ContinueWith(SourceLoaded, TaskScheduler.FromCurrentSynchronizationContext());
                        return;
                    }
                    if (_mode != 2 && _srcBinding != null)
                    {
                        _source = null;
                        _srcBinding.Dispose();
                        _srcBinding = null;
                    }
                }
                this.Offset = _owner.Offset + _ownerOffset;
                if (chLevel == 3)
                {
                    lv.MapRemove(this);
                    lv.MapSet(_mode == 0 ? 3 : 0, (int)(Offset.X / CELL_SIZE + 0.5), (int)(Offset.Y / CELL_SIZE + 0.5), this);
                }

                var   tc = model.State.ValueType;
                Brush br;

                switch (tc)
                {
                case JSC.JSValueType.Object:
                    if (model.State is ByteArray || model.State.Value is ByteArray)
                    {
                        br = brByteArray;
                    }
                    else
                    {
                        br = Brushes.MediumOrchid;
                    }
                    break;

                case JSC.JSValueType.String:
                    br = Brushes.Gold;
                    break;

                case JSC.JSValueType.Double:
                case JSC.JSValueType.Integer: {
                    double val = (double)model.State;
                    br = val > 0 ? (val == 1 ? Brushes.LawnGreen : Brushes.LightSeaGreen) : (val == 0 ? brValueFalse : Brushes.DodgerBlue); //-V3024
                }
                break;

                case JSC.JSValueType.Boolean:
                    br = (bool)model.State.Value ? Brushes.LawnGreen : brValueFalse; //-V3095
                    break;

                default:
                    br = Brushes.Black;
                    break;
                }
                bool ic = (!(_owner is loVariable) || _mode == 0) && JsLib.ofBool(JsLib.GetField(model.Manifest, "Logram.trace"), false);

                if (!ic && chLevel == 1 && this.brush == br)
                {
                    return;
                }
                this.brush = br;
                string val_s = string.Empty;

                if (ic)
                {
                    var v = model.State;
                    if (v != null)
                    {
                        switch (v.ValueType)
                        {
                        case JSC.JSValueType.Boolean:
                        case JSC.JSValueType.Integer:
                        case JSC.JSValueType.String:
                            val_s = v.Value.ToString();
                            break;

                        case JSC.JSValueType.Double: {
                            double d = (double)v;
                            int    p = (int)Math.Log10(Math.Abs(d));
                            switch (p)
                            {
                            case -2:
                                val_s = d.ToString("0.000##");
                                break;

                            case -1:
                                val_s = d.ToString("0.00##");
                                break;

                            case 0:
                                val_s = d.ToString("0.0##");
                                break;

                            case 1:
                                val_s = d.ToString("0.##");
                                break;

                            case 2:
                                val_s = d.ToString("0.#");
                                break;

                            case 3:
                                val_s = d.ToString("0.#");
                                break;

                            case 4:
                                val_s = d.ToString("0");
                                break;

                            default:
                                val_s = d.ToString("G4");
                                break;
                            }
                        }
                        break;

                        case JSC.JSValueType.Date: {
                            var dt = (v.Value as JSL.Date).ToDateTime();
                            val_s = dt.ToString("yyMMdd HH:mm:ss");
                            break;
                        }
                        }
                    }
                }
                using (DrawingContext dc = this.RenderOpen()) {
                    if (_mode == 3)
                    {
                        dc.DrawRectangle(_selected ? brItemSelected : this.brush, null, new Rect(-2, -5, 4, 10));
                    }
                    else
                    {
                        dc.DrawEllipse(_selected ? brItemSelected : this.brush, null, new Point(0, 0), 3, 3);
                    }
                    if (ic)
                    {
                        var   ft = new FormattedText(val_s, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.Black);
                        Point p;
                        if (_mode == 0)
                        {
                            p = new Point(2, 2 - CELL_SIZE);
                        }
                        else
                        {
                            p = new Point(-2 - ft.WidthIncludingTrailingWhitespace, 2 - CELL_SIZE);
                        }
                        dc.DrawText(ft, p);
                    }
                }
                if (_mode != 0 && _srcBinding != null && chLevel > 1)
                {
                    _srcBinding.Render(chLevel);
                }
                if (_mode == 0 && chLevel > 0)
                {
                    foreach (loBinding w in _connections.ToArray())
                    {
                        w.Render(chLevel);
                    }
                }
            }
Exemplo n.º 14
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);
                        }
                    }
                }
            }
Exemplo n.º 15
0
            public TwiDevice(Topic owner, TWI twi)
            {
                this.owner = owner;
                this._twi  = twi;
                JSC.JSValue jSrc;
                var         jType = owner.GetField("type");
                Topic       tt;

                if (jType.ValueType == JSC.JSValueType.String && jType.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(jType.Value as string, out tt) &&
                    (jSrc = JsLib.GetField(tt.GetState(), "src")).ValueType == JSC.JSValueType.String)
                {
                }
                else
                {
                    jSrc = null;
                }
                if (jSrc != null)
                {
                    try {
                        _ctx = new JSC.Context(JsExtLib.Context);
                        _ctx.DefineVariable("setTimeout").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetTimeout)));
                        _ctx.DefineVariable("setInterval").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetInterval)));
                        _ctx.DefineVariable("setAlarm").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, JSC.JSValue, JSC.JSValue>(SetAlarm)));

                        var f = _ctx.Eval(jSrc.Value as string) as JSL.Function;
                        if (f != null)
                        {
                            if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly)
                            {
                                this._self = JSC.JSObject.create(new JSC.Arguments {
                                    f.prototype
                                });
                            }
                            else
                            {
                                this._self = JSC.JSObject.CreateObject();
                            }
                            _self["GetState"] = JSC.JSValue.Marshal(new Func <string, JSC.JSValue>(GetState));
                            _self["SetState"] = JSC.JSValue.Marshal(new Action <string, JSC.JSValue>(SetState));
                            _self["GetField"] = JSC.JSValue.Marshal(new Func <string, string, JSC.JSValue>(GetField));
                            _self["TwiReq"]   = JSC.JSValue.Marshal(new Func <int[], Task <JSC.JSValue> >(_twi.TwiReq));

                            if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly)
                            {
                                _self = f.Construct(_self, new JSC.Arguments());
                            }
                            else
                            {
                                f.Call(_self, new JSC.Arguments()); // Call constructor
                            }
                        }
                    }
                    catch (Exception ex) {
                        Log.Warning("{0}.ctor() - {1}", owner.path, ex.Message);
                    }
                }
                else
                {
                    Log.Warning("{0} constructor is not defined", owner.path);
                }
            }
Exemplo n.º 16
0
        public void ManifestChanged()
        {
            JSC.JSValue jSrc;
            var         jType = _owner.GetField("type");
            Topic       tt;

            if (jType.ValueType == JSC.JSValueType.String && jType.Value != null && Topic.root.Get("$YS/TYPES", false).Exist(jType.Value as string, out tt) &&
                _typeT != tt && (jSrc = JsLib.GetField(tt.GetState(), "src")).ValueType == JSC.JSValueType.String)
            {
                _typeT = tt;
            }
            else
            {
                jSrc = null;
            }
            if (jSrc != null)
            {
                try {
                    _ctx = new JSC.Context(JsExtLib.Context);
                    _ctx.DefineVariable("setTimeout").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetTimeout)));
                    _ctx.DefineVariable("setInterval").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, int, JSC.JSValue>(SetInterval)));
                    _ctx.DefineVariable("setAlarm").Assign(JSC.JSValue.Marshal(new Func <JSC.JSValue, JSC.JSValue, JSC.JSValue>(SetAlarm)));

                    var f = _ctx.Eval(jSrc.Value as string) as JSL.Function;
                    if (f != null)
                    {
                        if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly)
                        {
                            this._self = JSC.JSObject.create(new JSC.Arguments {
                                f.prototype
                            });
                        }
                        else
                        {
                            this._self = JSC.JSObject.CreateObject();
                        }
                        var cf = _self.GetProperty("Calculate");
                        _calcFunc = (cf as JSL.Function) ?? (cf.Value as JSL.Function);

                        _self["GetState"] = JSC.JSValue.Marshal(new Func <string, JSC.JSValue>(GetState));
                        _self["SetState"] = JSC.JSValue.Marshal(new Action <string, JSC.JSValue>(SetState));
                        _self["GetField"] = JSC.JSValue.Marshal(new Func <string, string, JSC.JSValue>(GetField));

                        if (f.RequireNewKeywordLevel == JSL.RequireNewKeywordLevel.WithNewOnly)
                        {
                            _self = f.Construct(_self, new JSC.Arguments());
                        }
                        else
                        {
                            f.Call(_self, new JSC.Arguments()); // Call constructor
                        }
                    }
                }
                catch (Exception ex) {
                    Log.Warning("{0}.ctor() - {1}", _owner.path, ex.Message);
                }
            }
            else
            {
                if (!_owner.disposed)
                {
                    Log.Warning("{0} constructor is not defined", _owner.path);
                }
            }
        }