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); } } } } }
private void WrapPanel_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { LBDesc tag; if (_selectedImage != null && (tag = _selectedImage.Tag as LBDesc) != null) { _readyToDrag = false; if (uiLogram.Model != null) { string name; string prefix = JsLib.OfString(tag.owner.State["namePrefix"], "U"); if (uiLogram.Model.children != null) { int i = 1; do { name = prefix + i.ToString("D02"); i++; } while(uiLogram.Model.children.Any(z => z.name == name)); } else { name = prefix + "01"; } uiLogram.Model.CreateAsync(name, tag.owner.State["default"], tag.owner.State["manifest"]); } _selectedImage = null; } }
public void ManifestChanged() { string ss = JsLib.OfString(_owner.GetField("cctor.LoBind"), null); Topic st; LoVariable sv; if (ss != null && _owner.Exist(ss, out st)) { sv = _src as LoVariable; if (sv == null || sv._owner != st) { sv = _pl.GetVariable(st); } } else { sv = null; } Source = sv; }
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); } } } }
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); } } }
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); } } } }