public static void Load(XElement root) { foreach (XElement color in root.Element("Features").Elements("Feature")) { var nm = (string)color.Attribute("nm"); if ((nm == null) || Global.Instance.FeatureLitDict.ContainsKey(nm)) { throw new ArgumentException("nm"); } if ((string)color.Attribute("color") == null) { throw new ArgumentException("color"); } Clr clr = Clr.FromName((string)color.Attribute("color")); new FeatureLit(nm, clr); } }
public StepI(XElement xml, Song song, int measureOffset) : base(xml, song, measureOffset) { this.mode = int.Parse((string)xml.Attribute("mode")); string img = (string)xml.Attribute("img"); if (img != null) { if (!Global.Instance.BitMapImgs.TryGetValue(Path.GetFileNameWithoutExtension(img), out bmi)) { throw new Exception($"BMI '{img}' not found."); } } var wrk = (string)xml.Attribute("color"); if (wrk != null) { var clrs = new List <SD.Color>(); bool wrap = true; foreach (var clr in wrk.Split(',').Select(clr => clr.Trim())) { if (clr == "wrap") { wrap = true; } else if (clr == "nowrap") { wrap = false; } else { clrs.Add(Clr.FromName(clr)); } } this.palet = new PaletPS(clrs, wrap); } StepTransition trans = null; var nam = (string)xml.Attribute("transition"); if (nam != null) { if (!Global.Instance.StepTransitionDict.TryGetValue(nam, out trans)) { throw new Exception($"Transition '{nam}' not found."); } } else { } if (trans == null) { throw new Exception($"Expecting transition name or transitions element."); } Transition = trans; var regx = (string)xml.Attribute("regex"); if (regx == null) { throw new Exception($"Regex not found."); } regex = new Regex(regx, RegexOptions.IgnoreCase | RegexOptions.Compiled); wrk = (string)xml.Attribute("selector"); if (wrk != null) { selector = SLD.DynamicExpression.CompileLambda <Lit, bool>(wrk); } wrk = (string)xml.Attribute("orderby"); if (wrk != null) { orderby = SLD.DynamicExpression.CompileLambda <Lit, int>(wrk); } wrk = (string)xml.Attribute("groupby"); if (wrk != null) { groupby = SLD.DynamicExpression.CompileLambda <Lit, int>(wrk); } }
private static void bldView(XElement root, XElement vu, List <GECEStrand> strndlst, int rowoff, int coloff, Point3D offset, Func <Lit, float> xexp, Func <Lit, float> yexp, Func <Lit, float> zexp, Func <Lit, int> cirexp, Func <Lit, float> theexp, string nm, View view) { int blb = 0; int rgbt = 0; foreach (XElement lit in vu.Elements()) { string el = lit.Name.LocalName.ToLower(); switch (el) { case "view": { XAttribute attrb; int nurowoff = rowoff, nucoloff = coloff; attrb = lit.Attribute("rowoff"); if (!string.IsNullOrEmpty((string)attrb)) { nurowoff += (Int32)attrb; } attrb = lit.Attribute("coloff"); if (!string.IsNullOrEmpty((string)attrb)) { nucoloff += (Int32)attrb; } string nunm = nm + ":"; if (lit.Attribute("nm") != null) { nunm += (string)lit.Attribute("nm"); } Point3D nuoffset = new Point3D(); float nuscale = 1.0f; attrb = lit.Attribute("offset"); if (!string.IsNullOrEmpty((string)attrb)) { nuoffset = (Point3D)attrb; } attrb = lit.Attribute("scale"); if (!string.IsNullOrEmpty((string)attrb)) { nuscale = (float)attrb; } nuoffset = nuoffset + offset; string vunm = (string)lit.Attribute("view"); XElement vunu = root.Element("Views").Elements("View").Where(x => (string)x.Attribute("nm") == vunm).First(); if (vunu == null) { throw new Exception("view required"); } Func <Lit, float> nuxexp = xexp, nuyexp = yexp, nuzexp = zexp; object a = xexp; attrb = vunu.Attribute("xexp") ?? lit.Attribute("xexp"); if (!string.IsNullOrEmpty((string)attrb)) { nuxexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, vu); } attrb = vunu.Attribute("yexp") ?? lit.Attribute("yexp"); if (!string.IsNullOrEmpty((string)attrb)) { nuyexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, vu); } attrb = vunu.Attribute("zexp") ?? lit.Attribute("zexp"); if (!string.IsNullOrEmpty((string)attrb)) { nuzexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, vu); } attrb = vunu.Attribute("cirexp") ?? lit.Attribute("cirexp"); if (!string.IsNullOrEmpty((string)attrb)) { cirexp = SLD.DynamicExpression.CompileLambda <Lit, int>((string)attrb, lit); } attrb = vunu.Attribute("theexp") ?? lit.Attribute("theexp"); if (!string.IsNullOrEmpty((string)attrb)) { theexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, lit); } List <GECEStrand> strndnu = strndlst; if (lit.Attribute("strand") != null) { string strnds = (string)lit.Attribute("strand"); strndnu = new List <GECEStrand>(); foreach (string strndnm in strnds.Split(',')) { GECEStrand strand; if (!Global.Instance.StrandDict.TryGetValue(strndnm, out strand)) { throw new Exception($"Strand does not exist: {strndnm}"); } strndnu.Add(strand); } } bldView(root, vunu, strndnu, nurowoff, nucoloff, nuoffset, nuxexp, nuyexp, nuzexp, cirexp, theexp, nunm, view); } break; case "rgb": { if (strndlst == null) { throw new Exception($"Strand is required before lite: {nm}:{blb.ToString()}"); } bool hasexp = (xexp != null) && (yexp != null) && (zexp != null); int cnt = 0, rowinc = 0, colinc = 0, cirinc = 0; //float xinc = 0, yinc = 0, zinc = 0; XAttribute attrb; Point3D ptoffset = new Point3D(); if (lit.Attribute("repeat") != null) { cnt = (Int32)lit.Attribute("repeat"); attrb = lit.Attribute("rowinc"); if (!string.IsNullOrEmpty((string)attrb)) { rowinc = (Int32)attrb; } attrb = lit.Attribute("colinc"); if (!string.IsNullOrEmpty((string)attrb)) { colinc = (Int32)attrb; } if ((colinc == 0) && (rowinc == 0)) { throw new Exception("rowinc or colinc in required with cnt"); } attrb = lit.Attribute("cirinc"); if (!string.IsNullOrEmpty((string)attrb)) { cirinc = (Int32)attrb; } attrb = lit.Attribute("ptoffset"); if (string.IsNullOrEmpty((string)attrb)) { if (!hasexp) { throw new ArgumentNullException("ptoffset"); } } else { ptoffset = (Point3D)attrb; } } int rw = (Int32)lit.Attribute("row"); int cl = (Int32)lit.Attribute("col"); int cir = 0; if ((string)lit.Attribute("cir") != null) { cir = (Int32)lit.Attribute("cir"); } attrb = lit.Attribute("cirexp"); if (!string.IsNullOrEmpty((string)attrb)) { cirexp = SLD.DynamicExpression.CompileLambda <Lit, int>((string)attrb, lit); } Point3D point = new Point3D(); attrb = lit.Attribute("pt"); if (string.IsNullOrEmpty((string)attrb)) { if (!hasexp) { throw new MissingFieldException("pt"); } } else { point = (Point3D)attrb; } GECEStrand strand; if (strndlst.Count == 1) { strand = strndlst[0]; } else { if (lit.Attribute("strandndx") == null) { throw new Exception("strandndx is required."); } int strandndx = (Int32)lit.Attribute("strandndx"); strand = strndlst[strandndx]; } Point3D repoffset = new Point3D(); int cndlndxz = 0; bool candlesticks = (lit.Attribute("candlestick") != null); if (candlesticks) { Global.Instance.FeatureLitDict.TryGetValue("CandleStick", out FeatureLit flit); cndlndxz = flit.GlobalIndex; Global.Instance.FeatureLitDict.TryGetValue("CandleShade", out flit); cndlndxz |= flit.GlobalIndex << 16; } do { Clr clr = Colors.DarkGray; if (lit.Attribute("color") != null) { clr = Clr.FromName((string)lit.Attribute("color")); } RGBLit rgb = new GECELit(nm + ":" + blb.ToString()) { Strnd = strand, Index = strand.lites.Count, Row = rw, Column = cl, Circle = cir, Clr = clr, }; if (hasexp) { point = new Point3D((xexp != null) ? xexp(rgb) : 0, (yexp != null) ? yexp(rgb) : 0, (zexp != null) ? zexp(rgb) : 0); } rgb.Pt = point + offset + repoffset; if (cirexp != null) { rgb.Circle = cirexp(rgb); } if (theexp != null) { rgb.Theta = theexp(rgb); } rgb.Row += rowoff; rgb.Column += coloff; if (candlesticks) { Global.Instance.CandleVertices.Add(new IndexPoint3D(rgb.Pt, cndlndxz)); } if ((string)lit.Attribute("ndx") != null) { rgb.Index = (Int32)lit.Attribute("ndx"); } strand.lites.Add(rgb); view.LitArray.Add(rgb); blb++; rw += rowinc; cl += colinc; cir += cirinc; repoffset += ptoffset; cnt--; } while (cnt > 0); } break; case "mono": { int rw = (Int32)lit.Attribute("row"); int cl = (Int32)lit.Attribute("col"); int cir = 0; if ((string)lit.Attribute("cir") != null) { cir = (Int32)lit.Attribute("cir"); } Clr clr = Colors.DarkGray; if (lit.Attribute("color") != null) { clr = Clr.FromName((string)lit.Attribute("color")); } MonoLit mono = new MonoLit(nm + ":" + blb.ToString(), clr) { //Strnd = strnd, Row = rw + rowoff, Column = cl + coloff, Circle = cir, MarqueNdx = string.IsNullOrEmpty((string)lit.Attribute("mrqrow")) ? -1 : (int)lit.Attribute("mrqrow"), MarqueMask = (uint)(string.IsNullOrEmpty((string)lit.Attribute("mrqcol")) ? 0 : (1 << (int)lit.Attribute("mrqcol"))), }; if ((string)lit.Attribute("ndx") != null) { mono.Index = (Int32)lit.Attribute("ndx"); } Point3D point = new Point3D(); XAttribute attrb = lit.Attribute("point"); if (!string.IsNullOrEmpty((string)attrb)) { point = (Point3D)attrb; } else if (xexp != null && yexp != null && zexp != null) { point = new Point3D(xexp(mono), yexp(mono), zexp(mono)); } else { throw new MissingFieldException("point"); } mono.Pt = point + offset; view.LitArray.Add(mono); blb++; } break; case "line": { XAttribute attrb = lit.Attribute("color"); var clr = FeatureLit.FromName(string.IsNullOrEmpty((string)attrb) ? "Red" : (string)attrb); int repeat = 1; Point3D ptoffset = new Point3D(); attrb = lit.Attribute("repeat"); if (!string.IsNullOrEmpty((string)attrb)) { repeat = (int)attrb; attrb = lit.Attribute("ptoffset"); if (string.IsNullOrEmpty((string)attrb)) { throw new ArgumentNullException("ptoffset"); } ptoffset = (Point3D)attrb; } List <Point3D> pts = new List <Point3D>(); for (int ndx = 1; ; ndx++) { attrb = lit.Attribute("pt" + ndx.ToString()); if (string.IsNullOrEmpty((string)attrb)) { break; } pts.Add((Point3D)attrb); } attrb = lit.Attribute("close"); bool close = (!string.IsNullOrEmpty((string)attrb)); var repoffset = new Point3D(); for (int ndx = 0; ndx < repeat; ndx++) { short startNdx = (short)Global.Instance.LineVertices.Count; foreach (var pt in pts) { Global.Instance.LineIndices.Add((short)Global.Instance.LineVertices.Count); Global.Instance.LineVertices.Add(new IndexPoint3D(pt + offset + repoffset, clr.GlobalIndex)); } if (close) { Global.Instance.LineIndices.Add(startNdx); } Global.Instance.LineIndices.Add(-1); repoffset += ptoffset; } } break; case "triangle": { XAttribute attrb = lit.Attribute("color"); var clr = FeatureLit.FromName(string.IsNullOrEmpty((string)attrb) ? "Red" : (string)attrb); for (int ndx = 1; ; ndx++) { attrb = lit.Attribute("pt" + ndx.ToString()); if (string.IsNullOrEmpty((string)attrb)) { break; } Point3D pt = (Point3D)attrb + offset; Global.Instance.TriIndices.Add((short)Global.Instance.TriVertices.Count); Global.Instance.TriVertices.Add(new IndexPoint3D(pt, clr.GlobalIndex)); } Global.Instance.TriIndices.Add(-1); } break; case "dmx": { var dmxStrand = Global.Instance.DMXStrand; DMXLit dmx = new DMXLit(nm + ":dmx:" + rgbt++) { Strnd = dmxStrand, Index = dmxStrand.lites.Count, Clr = Clr.FromName("darkred"), }; dmxStrand.lites.Add(dmx); view.LitArray.Add(dmx); foreach (XElement trig in lit.Elements()) { string tri = trig.Name.LocalName.ToLower(); switch (tri) { case "triangle": { bool alldark = ((string)trig.Attribute("alldark")) != null; for (int ndx = 1; ; ndx++) { XAttribute attrb = trig.Attribute("pt" + ndx); if (string.IsNullOrEmpty((string)attrb)) { break; } Point3D pt = (Point3D)attrb + offset; dmx.AddPoint(pt); Global.Instance.TriIndices.Add((short)Global.Instance.TriVertices.Count); Global.Instance.TriVertices.Add(new IndexPoint3D(pt, dmx.GlobalIndex | ((!alldark && ndx == 3) ? 0 : 0x00010000))); } Global.Instance.TriIndices.Add(-1); } break; } } } break; //case "rgbtriangle": // { // XAttribute attrb; // string distance = string.Empty; // attrb = lit.Attribute("color"); // if (string.IsNullOrEmpty((string)attrb)) // throw new Exception("rgbTriangle requires 'color' attrb."); // Clr clr = Clr.FromName((string)attrb); // DMXLit rgb = new DMXLit(nm + ":rgbt:" + rgbt++) // { // Strnd = dmxStrand, // Index = dmxStrand.lites.Count, // Clr = clr, // }; // if ((string)lit.Attribute("ndx") != null) // rgb.Index = (Int32)lit.Attribute("ndx"); // dmxStrand.lites.Add(rgb); // view.LitArray.Add(rgb); // for (int ndx = 1; ; ndx++) // { // attrb = lit.Attribute("pt" + ndx); // if (string.IsNullOrEmpty((string)attrb)) break; // Point3D pt = (Point3D)attrb + offset; // attrb = lit.Attribute("clr" + ndx); // if (attrb != null) // rgb.LiteNdx.Add(Global.Instance.TriVertices.Count); // else // rgb.DimNdx.Add(Global.Instance.TriVertices.Count); // Global.Instance.TriIndices.Add((short)Global.Instance.TriVertices.Count); // Global.Instance.TriVertices.Add(new ColorPoint3D(pt, clr)); // } // Global.Instance.TriIndices.Add(-1); // } // break; } } //LitGrp.Build(vu, nm, rowoff, coloff); //LitGrpSeq.Build(vu, nm); }