Class StepColorTree
- Namespace
- Hi.MachiningProcs
- Assembly
- HiNc.dll
A color tree the project defines: a step property whose value is the id of the leaf a step falls into, with a color per leaf. The nodes are tried in order; the first whose condition holds takes the step — a leaf colors it, a group hands it to the group's own children — and a node without a condition takes every step that reaches it. A tree is authored data, made to be built in a script with object initializers; what evaluates steps is the immutable CompiledStepColorTree that Compile() makes. Saved in the project file (StepColorTreeList).
public class StepColorTree : IMakeXmlSource
- Inheritance
-
StepColorTree
- Implements
- Inherited Members
- Extension Methods
Remarks
A tree read from XML this version does not understand — an element, a join or an operation it does not know, a number it cannot read — is kept as written in UnreadableSource and written back the same, with no nodes and nothing to compile, so a file keeps its data. A node without an id is numbered from NextId; one whose id is another's or out of range is given a new number; a file without NextId gets the largest id plus one. These are put right on the load and listed in LoadProblems.
Constructors
StepColorTree()
Default constructor.
public StepColorTree()
StepColorTree(XElement)
Constructor from XML: <StepColorTree Key Name NextId> holding its nodes,
<Leaf Id Name Hue_deg ValueKey> and <Group Id Name>, each with
an optional <When Join> of <Term Key Op Threshold/> elements and a
group with its children. Never throws: what cannot be read is kept as written
(UnreadableSource); what can be put right is (LoadProblems).
public StepColorTree(XElement src)
Parameters
srcXElementXML element; null keeps the defaults.
Properties
Key
The key the registry lists the tree under; a step file's column. Shares the key space of the step variables.
public string Key { get; set; }
Property Value
LoadProblems
What the load from XML put right: a node without an id, an id that was another node's or out of range, a NextId missing, behind or out of range. None refuses: the tree is numbered and compiles. Empty for a tree not read from XML, and for one not understood.
public IReadOnlyList<StepColorTreeProblem> LoadProblems { get; }
Property Value
Name
The name shown; null or empty shows Key. User text, not translated.
public string Name { get; set; }
Property Value
NextId
The id the next new node gets, 1 ≤ NextId < IdLimit. It only grows: a node is numbered from it when the tree is written, cloned or compiled, and a number is never given to a second node, so a deleted node's number stays free. Raised to the largest id plus one when it is behind; a value outside the range counts as none (NextIdOutOfRange), and the numbering starts over above the largest id.
public int NextId { get; set; }
Property Value
Nodes
The top-level nodes, in the order they are tried.
public List<StepColorNode> Nodes { get; set; }
Property Value
UnreadableSource
The XML the tree was read from when this version did not understand it; null for a tree that was read. Such a tree has no nodes, is written back as it was read, and is not registered.
public XElement UnreadableSource { get; }
Property Value
XName
Name for XML IO.
public static string XName { get; }
Property Value
Methods
Clone()
A deep copy, through XML: the copy is numbered as the tree is written, and carries the problems a load of that XML puts right (the ids a tree built by hand repeats, say).
public StepColorTree Clone()
Returns
Compile()
Compiles the tree for evaluation; null when a problem of FindProblems() refuses. A node not numbered yet is compiled with the id it would be written with.
public CompiledStepColorTree Compile()
Returns
FindProblems()
Finds what is wrong with the tree, as codes and places (StepColorTreeProblem), without reporting anything. A problem that refuses keeps the tree from compiling: a tree not understood when read, no key, an id that is another node's or out of range, a term without a key, a comparison without a threshold. The rest are warnings — the tree compiles as it is: more leaves than the Color Index Time Chart stripes one by one (MaxChartLeaves), a list without a node that takes every step, a node no step reaches, a condition without terms, a group without children, a hue outside 0 to 360, a NextId outside its range. A node not numbered yet (id 0) is no problem: it is numbered when the tree is written, cloned or compiled, and it is checked with the number it gets then.
public IReadOnlyList<StepColorTreeProblem> FindProblems()
Returns
GetLeaves()
The leaves, depth first: the order of the tree.
public IEnumerable<StepColorLeaf> GetLeaves()
Returns
GetReferencedKeys()
The keys of the step properties the tree refers to — every condition's keys and every leaf's value key — each once, in tree order.
public IReadOnlyList<string> GetReferencedKeys()
Returns
MakeXmlSource(string, string, bool)
Writes the tree. A node not numbered yet is written with the id it gets from
NextId, and NextId with the number after the last one given, so the
file is numbered whether or not the tree in memory is; the tree in memory is not changed.
A tree that was not understood when read is written as it was read. A character an XML
file cannot hold is written as a space, as for a step variable.
public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)
Parameters
Returns
WithKeyRenamed(string, string)
The tree with every reference to the step property oldKey — in
conditions and as a leaf's value key — changed to newKey: a copy when
the tree refers to it, else this very instance.
public StepColorTree WithKeyRenamed(string oldKey, string newKey)