Class Asmb
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
parentAsmbparent
Asmb(Asmb, string)
Ctor.
public Asmb(Asmb parent, string name)
Parameters
Asmb(string)
Ctor.
public Asmb(string name)
Parameters
Fields
GuidSegmentClose
Closes a GUID segment of a path; see GuidSegmentOpen.
public const char GuidSegmentClose = '}'
Field Value
GuidSegmentMinDigits
The fewest hexadecimal digits a GUID segment must give; see GetAnchorByPath(string).
public const int GuidSegmentMinDigits = 8
Field Value
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
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
Properties
ChildAncs
A snapshot of the direct child anchors.
public HashSet<Anchor> ChildAncs { get; }
Property Value
ChildAsmbs
A snapshot of the direct child assemblies.
public HashSet<Asmb> ChildAsmbs { get; }
Property Value
Guid
GUID.
public Guid Guid { get; }
Property Value
Name
Name.
public string Name { get; set; }
Property Value
Parent
The assembly this one belongs to; null for a root. Maintained by Add(Asmb) and Remove(Asmb).
public Asmb Parent { get; }
Property Value
XName
Gets the XML name for the assembly.
public static string XName { get; }
Property Value
Methods
Add(Anchor)
Takes anc in as a direct child.
public bool Add(Anchor anc)
Parameters
ancAnchor
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
asmbAsmb
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
AncestorsAndSelf()
This assembly, then the assemblies enclosing it, nearest first.
public IEnumerable<Asmb> AncestorsAndSelf()
Returns
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
asmbXmlXElementxml of asmb
baseDirectorystringBase directory path for resolving relative paths
asmbsDictionary<Guid, Asmb>existed asmb map
ancsDictionary<Guid, Anchor>existed anc map
brnsDictionary<Guid, Branch>existed branch map
progressIProgress<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
DescendantAsmbs()
Every assembly inside this one, parents before children.
public IEnumerable<Asmb> DescendantAsmbs()
Returns
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
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
bindBindbind
rootAnchorfixed anchor
displayeesIGetAnchor[]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
bindBindbind
mapDictionary<Anchor, Mat4d>anchor to transformation map
displayeesIGetAnchor[]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
disposingbool
ExpandToBox3d(Box3d, Anchor, params IGetAnchor[])
Expands a bounding box to include the assembly.
public void ExpandToBox3d(Box3d dst, Anchor root, params IGetAnchor[] displayees)
Parameters
dstBox3dThe bounding box to expand.
rootAnchorThe root anchor for the calculation.
displayeesIGetAnchor[]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
guidGuid
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
guidstring
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
pathstring
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
Returns
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
anchorToSolidDictionaryDictionary<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
pathstring
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
rootAnchorThe 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
rootAnchorThe root anchor for the calculation.
displayeesIGetAnchor[]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
guidGuid
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
guidstring
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
headIGetAnchorThe starting anchor of the chain.
tailIGetAnchorThe 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
rootIGetAnchorThe root anchor to start from. If null, uses the first descendant anchor.
baseDirectorystringThe 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
rootIGetAnchorThe source anchor for the transformation.
tailIGetAnchorThe 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
rootIGetAnchorThe 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
rootIGetAnchorThe root anchor to calculate transformations from.
blockedsAnchor[]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
ancAnchor
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
asmbAsmb
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
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
namestring
Returns
Remove(Anchor)
Lets anc go; its branches stay attached.
public bool Remove(Anchor anc)
Parameters
ancAnchor
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
asmbAsmb
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
mapDictionary<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
rootIGetAnchorThe root anchor for the conversion.
baseDirectorystringThe 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
baseDirectorystringThe base directory for file references.
Returns
- XElement
An XML element representing the assembly.