Table of Contents

Class Asmb

Namespace
Hi.Mech.Topo
Assembly
HiMech.dll

Collection of Anchor and Asmb.

Membership is a tree: every anchor and every assembly belongs to at most one parent, recorded on Parent and Parent. Change membership only through Add(Anchor), Add(Asmb), Remove(Anchor) and Remove(Asmb); the child collections are snapshots.

A member is addressed by a path of names relative to the assembly asked, joined by PathSeparator, one segment per assembly on the way down: "MillingTool.MillingCutter.CutterTip" asked of the equipment names the same anchor as "MillingCutter.CutterTip" asked of the tool. Any segment may give the member's GUID in braces instead, "MillingTool.{12345678}", which is how GetPath(Anchor) spells a member whose name cannot stand on its own. See GetAnchorByPath(string).

public class Asmb : IGetAsmb, IGetTopoIndex, IDisposable
Inheritance
Asmb
Implements
Inherited Members
Extension Methods

Constructors

Asmb()

Ctor.

public Asmb()

Asmb(Asmb)

Ctor.

public Asmb(Asmb parent)

Parameters

parent Asmb

parent

Asmb(Asmb, string)

Ctor.

public Asmb(Asmb parent, string name)

Parameters

parent Asmb

parent

name string

Name

Asmb(string)

Ctor.

public Asmb(string name)

Parameters

name string

Name

Fields

GuidSegmentClose

Closes a GUID segment of a path; see GuidSegmentOpen.

public const char GuidSegmentClose = '}'

Field Value

char

GuidSegmentMinDigits

The fewest hexadecimal digits a GUID segment must give; see GetAnchorByPath(string).

public const int GuidSegmentMinDigits = 8

Field Value

int

GuidSegmentOpen

Opens a GUID segment of a path, {12345678}; see GetAnchorByPath(string). A name starting with it cannot be addressed: see IsAddressableName(string).

public const char GuidSegmentOpen = '{'

Field Value

char

PathSeparator

Joins the segments of a path; see GetAnchorByPath(string). A name carrying it cannot be addressed: see IsAddressableName(string).

public const char PathSeparator = '.'

Field Value

char

Properties

ChildAncs

A snapshot of the direct child anchors.

public HashSet<Anchor> ChildAncs { get; }

Property Value

HashSet<Anchor>

ChildAsmbs

A snapshot of the direct child assemblies.

public HashSet<Asmb> ChildAsmbs { get; }

Property Value

HashSet<Asmb>

Guid

GUID.

public Guid Guid { get; }

Property Value

Guid

Name

Name.

public string Name { get; set; }

Property Value

string

Parent

The assembly this one belongs to; null for a root. Maintained by Add(Asmb) and Remove(Asmb).

public Asmb Parent { get; }

Property Value

Asmb

XName

Gets the XML name for the assembly.

public static string XName { get; }

Property Value

string

Methods

Add(Anchor)

Takes anc in as a direct child.

public bool Add(Anchor anc)

Parameters

anc Anchor

Returns

bool

false when it is already a child of this assembly

Exceptions

InvalidOperationException

The anchor belongs to another assembly; remove it from there first.

Add(Asmb)

Takes asmb in as a direct child.

public bool Add(Asmb asmb)

Parameters

asmb Asmb

Returns

bool

false when it is already a child of this assembly

Exceptions

InvalidOperationException

The assembly belongs to another parent, or is this assembly or one of its ancestors.

Ancestors()

The assemblies enclosing this one, nearest first.

public IEnumerable<Asmb> Ancestors()

Returns

IEnumerable<Asmb>

AncestorsAndSelf()

This assembly, then the assemblies enclosing it, nearest first.

public IEnumerable<Asmb> AncestorsAndSelf()

Returns

IEnumerable<Asmb>

CallAsmb(XElement, string, Dictionary<Guid, Asmb>, Dictionary<Guid, Anchor>, Dictionary<Guid, Branch>, IProgress<IMessage>)

Get asmb by the asmbXml. If the members of the target asmb do not exist on asmbs or ancs, the members will be generated; otherwise, the existed members are applied.

public static Asmb CallAsmb(XElement asmbXml, string baseDirectory, Dictionary<Guid, Asmb> asmbs = null, Dictionary<Guid, Anchor> ancs = null, Dictionary<Guid, Branch> brns = null, IProgress<IMessage> progress = null)

Parameters

asmbXml XElement

xml of asmb

baseDirectory string

Base directory path for resolving relative paths

asmbs Dictionary<Guid, Asmb>

existed asmb map

ancs Dictionary<Guid, Anchor>

existed anc map

brns Dictionary<Guid, Branch>

existed branch map

progress IProgress<IMessage>

Progress reporter for diagnostic messages emitted during construction.

Returns

Asmb

asmb

DescendantAnchors()

Every anchor inside this assembly at any depth: the direct children first, then those of each child assembly in the order of DescendantAsmbs().

public IEnumerable<Anchor> DescendantAnchors()

Returns

IEnumerable<Anchor>

DescendantAsmbs()

Every assembly inside this one, parents before children.

public IEnumerable<Asmb> DescendantAsmbs()

Returns

IEnumerable<Asmb>

DescendantAsmbsAndSelf()

This assembly and every assembly inside it, parents before children. Each child set is snapshotted when the walk reaches it.

public IEnumerable<Asmb> DescendantAsmbsAndSelf()

Returns

IEnumerable<Asmb>

Display(Bind, Anchor, params IGetAnchor[])

Display displayees according to the GetAnchor(). The fixed anchor is root. If the element of displayees is not IDisplayee or null Anchor, the element will be ignored.

public void Display(Bind bind, Anchor root, params IGetAnchor[] displayees)

Parameters

bind Bind

bind

root Anchor

fixed anchor

displayees IGetAnchor[]

element to be rendered

Display(Bind, Dictionary<Anchor, Mat4d>, params IGetAnchor[])

Display the displayees according to map. If displayees is null, do nothing.

public static void Display(Bind bind, Dictionary<Anchor, Mat4d> map, params IGetAnchor[] displayees)

Parameters

bind Bind

bind

map Dictionary<Anchor, Mat4d>

anchor to transformation map

displayees IGetAnchor[]

displayees

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Leaves the tree — this assembly is removed from its parent and its direct children are released (their Parent becomes null, so they can be re-homed) — then the child sets are disposed. Branches are left alone; see Detach().

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

ExpandToBox3d(Box3d, Anchor, params IGetAnchor[])

Expands a bounding box to include the assembly.

public void ExpandToBox3d(Box3d dst, Anchor root, params IGetAnchor[] displayees)

Parameters

dst Box3d

The bounding box to expand.

root Anchor

The root anchor for the calculation.

displayees IGetAnchor[]

The displayable objects to include in the calculation.

GetAnchorByGuid(Guid)

Finds an anchor in the assembly hierarchy by its GUID.

public Anchor GetAnchorByGuid(Guid guid)

Parameters

guid Guid

Returns

Anchor

The anchor with the specified GUID, or null if not found.

GetAnchorByGuid(string)

Finds an anchor in the assembly hierarchy by its GUID in text.

public Anchor GetAnchorByGuid(string guid)

Parameters

guid string

Returns

Anchor

The anchor with the specified GUID, or null if the text is no GUID or none matches.

GetAnchorByPath(string)

The anchor at path, relative to this assembly: one segment per assembly to descend through, then one for the anchor, joined by PathSeparator. A segment is either a name, matched exactly, or a GUID in braces — the whole GUID, with or without its dashes, or just its first GuidSegmentMinDigits-or-more hexadecimal digits, case-insensitive: “MachineTool.ToolBuckle”, “MachineTool.{12345678}", "{12345678-abcd-4321-8765-0123456789ab}.ToolBuckle”. An empty segment, such as a leading separator, matches nothing.

public Anchor GetAnchorByPath(string path)

Parameters

path string

Returns

Anchor

The anchor, or null when any segment matches nothing.

Exceptions

InvalidOperationException

A segment matches more than one sibling; the path cannot tell them apart.

GetAnchorChain(Anchor, Anchor)

Gets a chain of anchors from the head to the tail.

public List<Anchor> GetAnchorChain(Anchor head, Anchor tail)

Parameters

head Anchor

The starting anchor of the chain.

tail Anchor

The ending anchor of the chain.

Returns

List<Anchor>

A list of anchors representing the chain, or an empty list if no chain exists.

GetAnchoredDisplayeeList(Dictionary<Anchor, Solid>)

Gets a list of anchored displayable objects based on the provided anchor-to-solid mapping.

public List<IAnchoredDisplayee> GetAnchoredDisplayeeList(Dictionary<Anchor, Solid> anchorToSolidDictionary)

Parameters

anchorToSolidDictionary Dictionary<Anchor, Solid>

Dictionary mapping anchors to their corresponding solids.

Returns

List<IAnchoredDisplayee>

A list of anchored displayable objects.

GetAsmb()

Gets the key asmb.

public Asmb GetAsmb()

Returns

Asmb

The key asmb.

GetAsmbByPath(string)

The assembly at path, relative to this assembly: one segment per assembly to descend through, joined by PathSeparator; empty means this one. Segments are names or GUIDs in braces as for GetAnchorByPath(string).

public Asmb GetAsmbByPath(string path)

Parameters

path string

Returns

Asmb

The assembly, or null when any segment matches nothing.

Exceptions

InvalidOperationException

A segment matches more than one sibling; the path cannot tell them apart.

GetAsmbDraw(Anchor)

Gets an assembly drawing for visualization.

public AsmbDraw GetAsmbDraw(Anchor root)

Parameters

root Anchor

The root anchor for the drawing.

Returns

AsmbDraw

An assembly drawing object.

GetBox3d(Anchor, params IGetAnchor[])

Gets a bounding box for the assembly.

public Box3d GetBox3d(Anchor root, params IGetAnchor[] displayees)

Parameters

root Anchor

The root anchor for the calculation.

displayees IGetAnchor[]

The displayable objects to include in the calculation.

Returns

Box3d

A 3D bounding box containing the assembly.

GetBranchByGuid(Guid)

Finds a branch among InnerBranches() by its GUID.

public Branch GetBranchByGuid(Guid guid)

Parameters

guid Guid

Returns

Branch

The branch with the specified GUID, or null if not found.

GetBranchByGuid(string)

Finds a branch among InnerBranches() by its GUID in text.

public Branch GetBranchByGuid(string guid)

Parameters

guid string

Returns

Branch

The branch with the specified GUID, or null if the text is no GUID or none matches.

GetBranchChain(IGetAnchor, IGetAnchor)

Gets a chain of branches with their directions from the head anchor to the tail anchor through the branches of this assembly.

public List<DirectionBranchEntry> GetBranchChain(IGetAnchor head, IGetAnchor tail)

Parameters

head IGetAnchor

The starting anchor of the chain.

tail IGetAnchor

The ending anchor of the chain.

Returns

List<DirectionBranchEntry>

A list of direction-branch pairs representing the chain, or an empty list if no chain exists.

GetBranchsXml(IGetAnchor, string)

Gets the XML representation of the branches of this assembly reached from the specified root, in the order a depth-first walk meets them.

public XElement GetBranchsXml(IGetAnchor root, string baseDirectory)

Parameters

root IGetAnchor

The root anchor to start from. If null, uses the first descendant anchor.

baseDirectory string

The base directory for file references.

Returns

XElement

An XML element containing the branches.

GetHierarchyString()

Gets a string representation of the assembly hierarchy.

public string GetHierarchyString()

Returns

string

A string describing the assembly hierarchy.

GetMat4d(IGetAnchor, IGetAnchor)

Gets the transformation matrix between two anchors through the branches of this assembly.

public Mat4d GetMat4d(IGetAnchor root, IGetAnchor tail)

Parameters

root IGetAnchor

The source anchor for the transformation.

tail IGetAnchor

The target anchor for the transformation.

Returns

Mat4d

The 4x4 transformation matrix from root to tail; null when no chain connects them.

GetMat4dMap(IGetAnchor)

Gets a mapping of anchors to their transformation matrices relative to the root anchor.

public Dictionary<Anchor, Mat4d> GetMat4dMap(IGetAnchor root)

Parameters

root IGetAnchor

The root anchor to calculate transformations from.

Returns

Dictionary<Anchor, Mat4d>

A dictionary mapping anchors to their transformation matrices.

GetMat4dMapWithBlocks(IGetAnchor, params Anchor[])

Gets a mapping of anchors to their transformation matrices relative to the root anchor, walking only the anchors of this assembly and never entering a blocked one.

public Dictionary<Anchor, Mat4d> GetMat4dMapWithBlocks(IGetAnchor root, params Anchor[] blockeds)

Parameters

root IGetAnchor

The root anchor to calculate transformations from.

blockeds Anchor[]

Anchors the walk must not enter; use them to open a closed loop.

Returns

Dictionary<Anchor, Mat4d>

A dictionary mapping anchors to their transformation matrices.

GetPath(Anchor)

The path of anc relative to this assembly, the inverse of GetAnchorByPath(string). A segment is the member's name where that is addressable and unique among its siblings, else its GUID in braces, so every member inside this assembly has a path that leads back to it.

public string GetPath(Anchor anc)

Parameters

anc Anchor

Returns

string

The path; null when the anchor is not inside this assembly.

GetPath(Asmb)

The path of asmb relative to this assembly, the inverse of GetAsmbByPath(string); empty for this assembly itself. Segments are chosen as for GetPath(Anchor).

public string GetPath(Asmb asmb)

Parameters

asmb Asmb

Returns

string

The path; null when the assembly is not inside this one.

InnerBranches()

The branches whose both ends are anchors of this assembly, at any depth. A branch leaving the assembly, such as a runtime attachment hung on a buckle, is not one.

public IEnumerable<Branch> InnerBranches()

Returns

IEnumerable<Branch>

IsAddressableName(string)

Whether a name can stand as a path segment: not empty, free of PathSeparator, and not starting with GuidSegmentOpen. A member whose name is not, or whose name a sibling shares, is still addressed by its GUID segment; see GetPath(Anchor).

public static bool IsAddressableName(string name)

Parameters

name string

Returns

bool

Remove(Anchor)

Lets anc go; its branches stay attached.

public bool Remove(Anchor anc)

Parameters

anc Anchor

Returns

bool

false when it is not a direct child of this assembly

Remove(Asmb)

Lets asmb go, with everything inside it.

public bool Remove(Asmb asmb)

Parameters

asmb Asmb

Returns

bool

false when it is not a direct child of this assembly

ShowMat4dMap(Dictionary<Anchor, Mat4d>)

Show mat map in text on console.

public static void ShowMat4dMap(Dictionary<Anchor, Mat4d> map)

Parameters

map Dictionary<Anchor, Mat4d>

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToXElement(IGetAnchor, string)

Converts the assembly to an XML element.

public XElement ToXElement(IGetAnchor root, string baseDirectory)

Parameters

root IGetAnchor

The root anchor for the conversion.

baseDirectory string

The base directory for file references.

Returns

XElement

An XML element representing the assembly.

ToXElement(string)

Converts the assembly to an XML element.

public XElement ToXElement(string baseDirectory)

Parameters

baseDirectory string

The base directory for file references.

Returns

XElement

An XML element representing the assembly.