Table of Contents

Class ChainCodeUtil

Namespace
Hi.Mech
Assembly
HiMech.dll

Chain code — a bracket notation for the connectivity of an assembly's anchors and branches, e.g. [Comp1][Comp2][Comp3];[Comp1][Comp4] — as static functions over the members of an IMechanism: Seed(string, IReadOnlyList<string>, out Asmb, out Anchor) materializes a fresh assembly and root from a code, CarryOver(IMechanism, Asmb, Dictionary<Anchor, Solid>) brings the transformers (each with the error-term mark of its branch) and solids of same-named components over from a previous mechanism, and DeriveChainCodes(IMechanism, Func<IReadOnlyList<Anchor>, int>) reads the code back from any assembly. The notation knows nothing but topology: every seeded branch carries a NoTransform, and which components play which role (a machine's mounts and axes, a fixture's anchors) is the mechanism's own convention, applied by it on top of the seeded triple.

Notation: each segment declares branches left to right — [O][Y];[Y][X];[X][w] pairs, or the concatenated sugar [O][Y][X][w]. Words merge by exact name across segments; [] is an anonymous component (each occurrence is a fresh one). A branch is named after the component farther from the ground anchor — the one that moves — so [O][Y] and [Y][O] both name the branch Y and differ only in direction. The first component of the whole code is the ground anchor, the root of the seeded assembly.

public static class ChainCodeUtil
Inheritance
ChainCodeUtil
Inherited Members

Properties

TokenRegex

One [word] token of a segment; group 1 is the word, empty for the anonymous [].

public static Regex TokenRegex { get; }

Property Value

Regex

Methods

CarryOver(IMechanism, Asmb, Dictionary<Anchor, Solid>)

Brings the transformer instances and solids of same-named components over from source into a freshly seeded assembly, so editing a code does not wash authored data away; a branch that takes a transformer takes the source branch's error-term mark (IsErrorTerm) with it. Transformers are matched by the arrow component's name first (a seeded branch is named after its arrow; an authored branch may carry an unrelated name or none) and by the branch's own name as the fallback (what axis discovery matches on, so a branch authored against the root direction still hands its transformer over); an ambiguous name — two source branches sharing it — hands nothing over rather than picking a winner. Solids travel by anchor name, unique names only. Anonymous components start fresh. A source with no assembly hands nothing over.

public static void CarryOver(IMechanism source, Asmb target, Dictionary<Anchor, Solid> targetAnchorToSolid)

Parameters

source IMechanism

The previous mechanism; null for none.

target Asmb

The seeded assembly whose branches and anchors receive the data.

targetAnchorToSolid Dictionary<Anchor, Solid>

The dictionary the carried solids are written to.

CodeToAnc(IMechanism)

The component words of a mechanism's own assembly mapped to their anchors; see the assembly overload.

public static Dictionary<string, Anchor> CodeToAnc(IMechanism m)

Parameters

m IMechanism

The mechanism.

Returns

Dictionary<string, Anchor>

Word to anchor; empty when the mechanism has no assembly.

CodeToAnc(Asmb, IEnumerable<Anchor>)

The component words mapped to their anchors — every named anchor of the assembly, the first one per name, minus the hidden ones.

public static Dictionary<string, Anchor> CodeToAnc(Asmb asmb, IEnumerable<Anchor> hidden = null)

Parameters

asmb Asmb

The assembly.

hidden IEnumerable<Anchor>

Anchors left out; null for none.

Returns

Dictionary<string, Anchor>

Word to anchor; empty when there is no assembly.

DeriveChainCode(IMechanism, Func<IReadOnlyList<Anchor>, int>)

public static string DeriveChainCode(IMechanism m, Func<IReadOnlyList<Anchor>, int> limbRank = null)

Parameters

m IMechanism

The mechanism.

limbRank Func<IReadOnlyList<Anchor>, int>

Optional ranking of the limbs; see the segments overload.

Returns

string

The joined code; empty when the mechanism has no root.

DeriveChainCode(Asmb, Anchor, IEnumerable<Anchor>, Func<IReadOnlyList<Anchor>, int>)

public static string DeriveChainCode(Asmb asmb, Anchor start, IEnumerable<Anchor> hidden = null, Func<IReadOnlyList<Anchor>, int> limbRank = null)

Parameters

asmb Asmb

The assembly.

start Anchor

The anchor the code starts from.

hidden IEnumerable<Anchor>

Anchors left out of the code, with their branches; null for none.

limbRank Func<IReadOnlyList<Anchor>, int>

Optional ranking of the limbs; see the segments overload.

Returns

string

The joined code; empty when there is no assembly or start.

DeriveChainCodes(IMechanism, Func<IReadOnlyList<Anchor>, int>)

Derives the chain code segments of a mechanism's own assembly, from its root; see the assembly overload.

public static List<string> DeriveChainCodes(IMechanism m, Func<IReadOnlyList<Anchor>, int> limbRank = null)

Parameters

m IMechanism

The mechanism.

limbRank Func<IReadOnlyList<Anchor>, int>

Optional ranking of the limbs; see the assembly overload.

Returns

List<string>

The segments; empty when the mechanism has no root.

DeriveChainCodes(Asmb, Anchor, IEnumerable<Anchor>, Func<IReadOnlyList<Anchor>, int>)

Derives the chain code segments of an assembly: every branch whose both ends are inside it — runtime attachments from other assemblies never leak in — exactly once, in its own direction, branches that continue one another merged into one limb. Limbs starting at start come first, then in the order limbRank gives (all equal when null), then by their first component's name; when no limb can start at start it is declared on its own.

public static List<string> DeriveChainCodes(Asmb asmb, Anchor start, IEnumerable<Anchor> hidden = null, Func<IReadOnlyList<Anchor>, int> limbRank = null)

Parameters

asmb Asmb

The assembly.

start Anchor

The anchor the code starts from, normally the root.

hidden IEnumerable<Anchor>

Anchors left out of the code, with their branches; null for none.

limbRank Func<IReadOnlyList<Anchor>, int>

Ranks a limb (its anchors, first to last); lower ranks come first. Null ranks every limb alike.

Returns

List<string>

The segments; empty when there is no assembly or start, or the start is hidden.

Exceptions

InvalidOperationException

Two components share a name, or an anonymous component takes part in more than one limb — the code could not be parsed back.

GetPathCodes(Asmb, Anchor, Anchor)

The component words along the anchor chain from from to to, the way GetAnchorChain(Anchor, Anchor) walks it.

public static List<string> GetPathCodes(Asmb asmb, Anchor from, Anchor to)

Parameters

asmb Asmb

The assembly.

from Anchor

The anchor the path starts at.

to Anchor

The anchor the path ends at.

Returns

List<string>

The words, first anchor first; empty when either end is missing or unreachable.

JoinSegments(IEnumerable<string>)

Joins segments back into the semicolon form.

public static string JoinSegments(IEnumerable<string> segments)

Parameters

segments IEnumerable<string>

The segments.

Returns

string

The joined code.

Seed(string, IReadOnlyList<string>, out Asmb, out Anchor)

Seeds a fresh assembly and root anchor from chain code segments: tokens merge by exact name, [] is anonymous, a branch declared twice is one branch, and the components must form one connected structure. The first component is the root; every branch is named after the component farther from it and carries a NoTransform.

public static void Seed(string asmbName, IReadOnlyList<string> segments, out Asmb asmb, out Anchor root)

Parameters

asmbName string

Name of the assembly to create.

segments IReadOnlyList<string>

The code segments; see the class summary for the notation.

asmb Asmb

The seeded assembly.

root Anchor

The root anchor: the code's first component.

Exceptions

ArgumentException

The code is empty, malformed or disconnected.

Seed(string, string, out Asmb, out Anchor)

Seeds a fresh assembly and root anchor from a semicolon-joined chain code; see the list overload.

public static void Seed(string asmbName, string chainCode, out Asmb asmb, out Anchor root)

Parameters

asmbName string

Name of the assembly to create.

chainCode string

The joined code, split by SplitSegments(string).

asmb Asmb

The seeded assembly.

root Anchor

The root anchor: the code's first component.

Exceptions

ArgumentException

The code is empty, malformed or disconnected.

SplitSegments(string)

Splits a semicolon-joined chain code into its trimmed, non-empty segments.

public static string[] SplitSegments(string chainCode)

Parameters

chainCode string

The joined code; null counts as empty.

Returns

string[]

The segments, possibly none.