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(); } } } }
private void DeleteLI(loItem el) { loBinding b = el as loBinding; DTopic t; if (b != null && (t = b.Output.GetModel()) != null) { t.SetField("cctor.LoBind", null); } else if ((t = el.GetModel()) != null && (t.Manifest == null || (JsLib.OfInt(t.Manifest, "attr", 0) & 1) != 1)) { t.Delete(); } }
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); } } }
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"]); } } } }
public LoVariable GetPin(Topic t) { LoVariable v; v = _pins.FirstOrDefault(z => z.Owner == t); if (v == null) { v = _pl.GetVariable(t); var ddr = _typeT != null?JsLib.OfInt(_typeT.GetState(), "Children." + t.name + ".ddr", 0) : 0; if (t.parent != _owner || ddr <= 0) { v.AddLink(this); } else { v.Source = this; } _pins.Add(v); } return(v); }
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 } }
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); }
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); }
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); } } } }