Class GeneralMechanism
General Mechanism: the pure-topology IMechanism — an
assembly, a root anchor and the solids on the anchors, nothing else. It
is the file type of the Mechanism Builder (.GeneralMechanism) and
the side file a machine file points at for its topology.
public class GeneralMechanism : IMakeXmlSource, IMechanism, ITopo, IGetAsmb, IGetAnchoredDisplayeeList, IGetAnchorToSolidDictionary, IAnchoredDisplayee, IGetAnchor, IGetTopoIndex, IDisplayee, IExpandToBox3d
- Inheritance
-
GeneralMechanism
- Implements
- Inherited Members
- Extension Methods
Remarks
The XML IO is according to self-contained principle; the three members are read and written by MechanismXml.
Constructors
GeneralMechanism()
Initializes a new instance of the GeneralMechanism class.
public GeneralMechanism()
GeneralMechanism(Asmb, Anchor, Dictionary<Anchor, Solid>)
Initializes a mechanism from its three members, adopting the instances as they are — the way an assembly seeded by ChainCodeUtil or read by MechanismXml becomes a stand-alone mechanism.
public GeneralMechanism(Asmb asmb, Anchor root, Dictionary<Anchor, Solid> anchorToSolid)
Parameters
asmbAsmbThe key assembly.
rootAnchorThe root anchor, inside
asmb.anchorToSolidDictionary<Anchor, Solid>The solid dictionary, keyed by anchors of
asmb; kept as the live instance.
Exceptions
- ArgumentNullException
Any member is null.
- ArgumentException
The root anchor is not inside the assembly.
GeneralMechanism(XElement, string, IProgress<IMessage>)
Initializes a new instance of the GeneralMechanism class from XML.
public GeneralMechanism(XElement src, string baseDirectory, IProgress<IMessage> progress)
Parameters
srcXElementThe XML element containing the mechanism data.
baseDirectorystringThe base directory for resolving relative file paths.
progressIProgress<IMessage>Progress reporter for diagnostic messages emitted during construction.
Properties
AnchorToSolid
Gets the dictionary mapping anchors to their corresponding solids.
public Dictionary<Anchor, Solid> AnchorToSolid { get; }
Property Value
Asmb
Gets the assembly containing the mechanism components.
public Asmb Asmb { get; }
Property Value
Root
Gets the root anchor of the mechanism.
public Anchor Root { get; }
Property Value
XName
Name for XML IO.
public static string XName { get; }
Property Value
Methods
Display(Bind)
Display function called in DispEngine rendering loop.
public void Display(Bind bind)
Parameters
bindBindBind with DispEngine. See Bind.
ExpandToBox3d(ref box3d_t)
Expands the destination box.
This function is usually used to compute the bounding box of elements.
box3d_t is a value type, so the destination is passed by reference
(the C++ expand_to_box3d(box3&) shape); an implementation writes
dst = dst.Expanded(...) or forwards ref dst to its parts.
public void ExpandToBox3d(ref box3d_t dst)
Parameters
dstbox3d_tDestination box, expanded in place
GetAnchor()
Get key anchor. (i.e. root anchor)
public Anchor GetAnchor()
Returns
- Anchor
key anchor
GetAnchorToSolidDictionary()
public Dictionary<Anchor, Solid> GetAnchorToSolidDictionary()
Returns
- Dictionary<Anchor, Solid>
A dictionary where keys are anchors and values are their associated solids.
GetAnchoredDisplayeeList()
Gets a list of anchored displayable objects.
public List<IAnchoredDisplayee> GetAnchoredDisplayeeList()
Returns
- List<IAnchoredDisplayee>
A list of IAnchoredDisplayee objects
GetAsmb()
Gets the key asmb.
public Asmb GetAsmb()
Returns
- Asmb
The key asmb.
MakeXmlSource(string, string, bool)
Creates an XML representation of the object. This method may also generate additional resources such as related files.
public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)
Parameters
baseDirectorystringThe base directory for resolving relative paths
relFilestringThe relative file path for the XML source
exhibitionOnlyboolif true, the extended file creation is suppressed.
Returns
- XElement
An XML element representing the object's state
Remarks
For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied.
The baseDirectory is typically the folder at the nearest configuration file folder.
Since the folder can be moving with the configuration file.
Reg(XFactory)
Registers this type's deserializer with the given XFactory
and chains Reg(factory) on dependents. Idempotent.
public static void Reg(XFactory factory = null)
Parameters
factoryXFactory