/// <summary> /// this function is going to check whether the target position index is smaller /// than the smallest child index in the tree. /// </summary> /// <param name="parents">dragged item parents</param> /// <param name="trgt">target IRebuild</param> /// <param name="aboveMe">the child that is lower than the target if there is one</param> /// <returns>true if index is beneath dependents, false otherwise</returns> private bool CheckWaterMarkIndexChildren(List<IRebuild> children, IRebuild trgt, ref IRebuild belowMe) { if (children.Contains(trgt)) return false; TreeNode target = FindNode(trgt); int tarDepth = 0; TheIndexOf(trgt, null, ref tarDepth); foreach (IRebuild irb in children) { //if((irb is IGroup) TreeNode child = FindNode(irb); int childDepth = 0; TheIndexOf(irb, null, ref childDepth); if (trgt is IGroup) // if the target is a group that contains a child, return false because we want to insert if ((trgt as IGroup).FindItem(irb) != null) { belowMe = irb; return false; } if (tarDepth > childDepth) { belowMe = irb; return false;//if the target depth } // is more than the child depth, then don't allow } return true; }
internal void Remove(IRebuild tag) { if (tag is IGroup) { IGroup g = FindGroup(tag.Label); Layout.Remove(g); } }
public bool Rebuild(IRebuild tag) { if (tag != null) tag.Update(ActiveSail); if (AutoBuild) { //List<IRebuild> updated = ActiveSail.Rebuild(tag); List<IRebuild> connected = ActiveSail.GetConnected(tag); List<IRebuild> succeeded = new List<IRebuild>(); List<IRebuild> failed = new List<IRebuild>(); DateTime before = DateTime.Now; if (connected != null) { foreach (IRebuild item in connected) { if (item.Update(ActiveSail)) succeeded.Add(item); else failed.Add(item); } //connected.ForEach(item => item.Update(ActiveSail)); } //two lists (failed and succeeded) // update succeeded // invalidate failed DateTime after = DateTime.Now; Console.WriteLine("{0} ms", (after - before).TotalMilliseconds); StringBuilder b = new StringBuilder("Rebuilt Succeeded:\n"); if (connected != null) { foreach (IRebuild item in succeeded)//succeeded { UpdateViews(item); b.AppendLine(item.ToString()); } if (failed.Count > 0) b.AppendLine("\nRebuilt Failed:\n"); foreach (IRebuild item in failed)//failed { View.Invalidate(item); Tree.Invalidate(item); b.AppendLine(item.ToString()); } View.Refresh(); } #if DEBUG MessageBox.Show(b.ToString()); #endif } else if (tag != null) UpdateViews(tag); return AutoBuild; }
/// <summary> /// Returns all IRebuild items that are above the tag /// </summary> /// <param name="tag">the item being used as a watermark, can be null</param> /// <returns>a List of IRebuild items</returns> public List<IRebuild> Watermark(IRebuild tag) { List<IRebuild> rets = new List<IRebuild>(); //watermark mould first (if any) if (Mould != null && Mould.Groups != null) for (int i = 0; i < Mould.Groups.Count; i++) { if (Mould.Groups[i].Watermark(tag, ref rets)) break;//break on finding tag } //watermark layout for (int i = 0; i < Layout.Count; i++) { if (Layout[i].Watermark(tag, ref rets)) break;//break on finding tag } return rets; }
public List<MouldCurve> WatermarkCur(IRebuild tag) { List<MouldCurve> eqs = new List<MouldCurve>(); foreach (IRebuild rb in Watermark(tag)) { if (rb is MouldCurve) eqs.Add(rb as MouldCurve); } return eqs; }
private void ColorCollection(IRebuild drg, List<IRebuild> items, Color color) { if (drg == null) return; items.ForEach(irb => { TreeNode found = FindNode(irb); if (drg is IGroup) { while (found.Parent.Tag != Sail) { found = found.Parent; if (found.Parent == null) break; } } else if (drg is MouldCurve || drg is Equation) { if (!(found.Tag is IGroup)) { found.BackColor = color; while (!(found.Tag is IGroup)) { found = found.Parent; if (found.Parent == null) break; } } } //if (found.Tag as IRebuild != drg) found.BackColor = color; }); }
public List<IRebuild> GetConnected(IRebuild tag) { List<IRebuild> connected = null; if (tag != null) { connected = new List<IRebuild>(); connected.Add(tag); } foreach (IRebuild item in Layout) { item.GetConnected(connected); } return connected; }
internal void SelectLayer(IRebuild curve) { Entity e = ActiveView.Entities.FirstOrDefault(ent => ent.EntityData == curve); if (e == null) return; SelectLayer(e.LayerIndex); }
internal void ShowOnly(IRebuild obj) { HideAll(); ToggleLayer(obj); }
internal void HideLayer(IRebuild p) { Entity e = ActiveView.Entities.FirstOrDefault(ent => ent.EntityData == p); if (e == null) return; this[0].Layers.TurnOff(e.LayerIndex);// = !this[0].Layers[e.LayerIndex].Visible; this[1].Layers.TurnOff(e.LayerIndex);// = !this[1].Layers[e.LayerIndex].Visible; Refresh(); }
internal void Invalidate(IRebuild item) { for (int i = 0; i < 2; i++) { for (int j = 0; j < this[i].Entities.Count; j++) { if (this[i].Entities[j].EntityData == item) { this[i].Entities[j].ColorMethod = colorMethodType.byEntity; this[i].Entities[j].Color = InvalidColor; } } } }
//private void toolStripMenuItem1_Click(object sender, EventArgs e) //{ // Warps.Controls.ColorWheelForm cwf = new Controls.ColorWheelForm(ActiveView); // cwf.Location = MousePosition; // cwf.Show(this); //} internal Layer GetLayer(IRebuild group) { return ActiveView.Layers.FirstOrDefault(ly => ly.Name == group.Label); }
public void Add(IRebuild g) { Entity[] groupEntities = g.CreateEntities(); devDept.Eyeshot.Labels.Label[] groupLabels = g.EntityLabel; if (groupEntities == null) return; int layerIndex = AddLayer(g.Label, Color.Black, true); for (int i = 0; i < groupEntities.Length; i++) { if (groupEntities[i].LayerIndex == 0) groupEntities[i].LayerIndex = layerIndex; Add(groupEntities[i], groupLabels); } }
//private void parallelRebuild(List<IRebuild> updated) //{ // Parallel.ForEach<IRebuild>(updated, item => // { // item.Update(); // }); //} private void UpdateViews(IRebuild item) { View.Remove(item); Tree.BeginUpdate(); if (item is IGroup) { View.Add(item as IGroup); (item as IGroup).WriteNode(); } else if (item is MouldCurve) { View.Add(item as MouldCurve); (item as MouldCurve).WriteNode(); } else if (item is Equation) { (item as Equation).WriteNode(); } Tree.Revalidate(item); Tree.EndUpdate(); }
/// <summary> /// this function is going to check whether the target position index is larger /// than the largest parent index in the tree. /// </summary> /// <param name="parents">dragged item parents</param> /// <param name="trgt">target IRebuild</param> /// <param name="aboveMe">the parent that is higher than the target if there is one</param> /// <returns>true if index is above dependents, false otherwise</returns> private bool CheckWaterMarkIndexParents(List<IRebuild> parents, IRebuild trgt, ref IRebuild aboveMe) { if (parents.Contains(trgt)) return false; TreeNode target = FindNode(trgt); int tarDepth = 0; TheIndexOf(trgt, null, ref tarDepth); foreach (IRebuild irb in parents) { TreeNode parent = FindNode(irb); int parDepth = 0; TheIndexOf(irb, null, ref parDepth); if (tarDepth < parDepth) { aboveMe = irb; return false;//if the target depth } // is less than the parent depth, then don't allow } return true; }
internal void ToggleLayer(IRebuild p) { Entity e; if (p is IMouldCurve) { e = ActiveView.Entities.FirstOrDefault(ent => ent.EntityData == p); if (e == null) return; this[0].Layers[e.LayerIndex].Visible = !this[0].Layers[e.LayerIndex].Visible; this[1].Layers[e.LayerIndex].Visible = !this[1].Layers[e.LayerIndex].Visible; } else if (p is CurveGroup) { foreach (IRebuild ir in (p as CurveGroup)) { e = ActiveView.Entities.FirstOrDefault(ent => ent.EntityData == ir); if (e == null) return; this[0].Layers[e.LayerIndex].Visible = !this[0].Layers[e.LayerIndex].Visible; this[1].Layers[e.LayerIndex].Visible = !this[1].Layers[e.LayerIndex].Visible; break; } } else { e = ActiveView.Entities.FirstOrDefault(ent => ent.EntityData == p); if (e == null) return; this[0].Layers[e.LayerIndex].Visible = !this[0].Layers[e.LayerIndex].Visible; this[1].Layers[e.LayerIndex].Visible = !this[1].Layers[e.LayerIndex].Visible; } Refresh(); }
private bool CheckWaterMarkIndexParents(List<IRebuild> parents, IRebuild trgt) { IRebuild throwAway = null; return CheckWaterMarkIndexParents(parents, trgt, ref throwAway); }
void TheIndexOf(IRebuild node, List<IGroup> nodes, ref int count) { if (nodes == null) nodes = Sail.Layout; foreach (IGroup tn in nodes) { count++; if (tn == node) return; if (tn is CurveGroup) { if ((tn as CurveGroup).Count > 0 && node is MouldCurve) { foreach (MouldCurve cur in (tn as CurveGroup)) { count++; if (cur == node) return; } } else if ((tn as CurveGroup).Count > 0 && node is GuideComb) { foreach (MouldCurve cur in (tn as CurveGroup)) { count++; if ((cur as GuideComb) == node) return; } } else count += (tn as CurveGroup).Count; } else if (tn is VariableGroup) { if ((tn as VariableGroup).Count > 0 && node is Equation) { foreach (KeyValuePair<string, Equation> eqs in (tn as VariableGroup)) { count++; if (eqs.Key == (node as Equation).Label) return; } } else count += (tn as VariableGroup).Count; } } return; }
/// <summary> /// Finds the parent group of the specified tag /// </summary> /// <param name="tag">the item to find the parent of</param> /// <returns>the containing IGroup, null if not found</returns> public IGroup FindGroup(IRebuild tag) { if (tag == null) return null; List<IRebuild> rets = new List<IRebuild>(); for (int i = Layout.Count - 1; i >= 0; i--) { if (Layout[i].Watermark(tag, ref rets)) return Layout[i]; } if (Mould != null && Mould.Groups != null) for (int i = 0; i < Mould.Groups.Count; i++) { //check group label if (Mould.Groups[i].Watermark(tag, ref rets)) return Mould.Groups[i];//return if match } return null; }
internal void Invalidate(IRebuild item) { TreeNode tn = FindNode(item); if (tn != null) { //tn.ForeColor = Color.White; tn.BackColor = Color.Firebrick; tn.EnsureVisible(); } }
//public List<MouldCurve> GetCurves(object tag) //{ // bool found = false; // List<MouldCurve> curves = new List<MouldCurve>(); // for (int i = 0; i < Layout.Count; i++) // { // if (Layout[i] is CurveGroup) // { // CurveGroup grp = Layout[i] as CurveGroup; // IEnumerable<MouldCurve> mcs = grp.GetCurves(tag); // curves.AddRange(mcs); // if (mcs.Count() != grp.Count) // break; // } // else if (Layout[i] is VariableGroup) // { // VariableGroup grp = Layout[i] as VariableGroup; // found = grp == tag as VariableGroup; // IEnumerable<KeyValuePair<string, Equation>> mcs = grp.GetEquations(tag); // if (mcs.Count() != grp.Count) // break; // if (found) // break; // } // else if (Layout[i] is YarnGroup) // { // YarnGroup grp = Layout[i] as YarnGroup; // found = grp == tag as YarnGroup; // if (found) // break; // } // } // return curves; //} //public List<KeyValuePair<string, Equation>> GetEquations(object tag) //{ // bool found = false; // List<KeyValuePair<string, Equation>> equations = new List<KeyValuePair<string, Equation>>(); // for (int i = 0; i < Layout.Count; i++) // { // if (Layout[i] is VariableGroup) // { // //continue; // VariableGroup grp = Layout[i] as VariableGroup; // found = grp == tag as VariableGroup; // IEnumerable<KeyValuePair<string, Equation>> mcs = grp.GetEquations(tag); // equations.AddRange(mcs); // if (mcs.Count() != grp.Count) // break; // if (found) // break; // } // else if (Layout[i] is CurveGroup) // { // CurveGroup grp = Layout[i] as CurveGroup; // found = grp == tag as CurveGroup; // IEnumerable<MouldCurve> mcs = grp.GetCurves(tag); // if (mcs.Count() != grp.Count) // break; // if (found) // break; // } // else if (Layout[i] is YarnGroup) // { // YarnGroup grp = Layout[i] as YarnGroup; // found = grp == tag as YarnGroup; // //IEnumerable<KeyValuePair<string, Equation>> mcs = grp.GetEquations(tag); // //if (mcs.Count() != grp.Count) // // break; // if (found) // break; // } // } // return equations; //} //public List<MouldCurve> GetAllCurves() //{ // List<MouldCurve> curves = new List<MouldCurve>(); // for (int i = 0; i < Layout.Count; i++) // { // if (Layout[i] is CurveGroup) // { // CurveGroup grp = Layout[i] as CurveGroup; // if (grp == null) // continue; // curves.AddRange(grp.GetAllCurves()); // } // } // return curves; //} //public MouldCurve FindCurve(string name, object tag) //{ // List<MouldCurve> curves = GetCurves(tag); // return curves.Find(curve => curve.Label == name); //} public List<IRebuild> Rebuild(IRebuild tag) { List<IRebuild> updated = null; if (tag != null) { updated = new List<IRebuild>(); updated.Add(tag); } foreach (IRebuild item in Layout) { item.Update(this);// (updated); } if (tag == null) WriteNode(); return updated; }
//internal void DeSelect(IGroup group) //{ // TreeNode found = FindNode(group); // if (found != null) // found.BackColor = Color.White; //} //internal void DeSelect(MouldCurve group) //{ // TreeNode found = FindNode(group); // if (found != null) // found.BackColor = Color.White; // m_seqtree.Refresh(); //} internal void Remove(IRebuild tag) { TreeNode found = FindNode(tag); if (found != null) SeqTree.Nodes.Remove(found); SeqTree.Refresh(); }
/// <summary> /// Returns all IRebuild items that are above the tag /// </summary> /// <param name="tag">the item being used as a watermark, can be null</param> /// <param name="Parent">the IGroup the item belongs too (REQUIRED IF YOU ARE ADDING A CURVE)</param> /// <returns></returns> public List<IRebuild> Watermark(IRebuild tag, IGroup Parent) { List<IRebuild> rets = new List<IRebuild>(); //watermark mould first (if any) if (Mould != null && Mould.Groups != null) for (int i = 0; i < Mould.Groups.Count; i++) { if (Mould.Groups[i].Watermark(tag, ref rets)) break;//break on finding tag } int index = -1; if (Parent != null) index = Layout.IndexOf(Parent); // if the Parent is not null, then don't allow the watermark to go below this group. //watermark layout for (int i = 0; i < Layout.Count; i++) { if (index > -1) { if (i <= index) if (Layout[i].Watermark(tag, ref rets)) break;//break on finding tag } else if (Layout[i].Watermark(tag, ref rets)) break;//break on finding tag } return rets; }
internal void Revalidate(IRebuild item) { TreeNode tn = FindNode(item); if (tn != null) { //tn.ForeColor = Color.Black; tn.BackColor = Color.White; } }
public List<Equation> WatermarkEqs(IRebuild tag) { List<Equation> eqs = new List<Equation>(); foreach (IRebuild rb in Watermark(tag)) { if (rb is Equation) eqs.Add(rb as Equation); } return eqs; }
private bool CheckWaterMarkIndexChildren(List<IRebuild> children, IRebuild trgt) { IRebuild throwAway = null; return CheckWaterMarkIndexChildren(children, trgt, ref throwAway); }
/// <summary> /// give it a sail reference and the watermark locations /// </summary> /// <param name="m_sail">Sail reference</param> /// <param name="group">watermark group</param> internal void Prep(Sail sail, IRebuild group) { m_sail = sail; AutoFillVariables = m_sail.Watermark(group).ToList<object>(); }
public int Delete(IRebuild tag) { if (AutoBuild) { //List<IRebuild> updated = ActiveSail.Rebuild(tag); List<IRebuild> connected = ActiveSail.GetConnected(tag); StringBuilder b = new StringBuilder("Invalid:\n"); foreach (IRebuild item in connected) { View.Invalidate(item); Tree.Invalidate(item); b.AppendLine(item.ToString()); } #if DEBUG MessageBox.Show(b.ToString()); #endif Tree.Remove(tag); ActiveSail.Remove(tag); View.Refresh(); EditMode = false; return connected.Count; } return -1; }