Table of Contents

Class StlFile

Namespace
Hi.Geom
Assembly
HiGeom.dll

Represents an STL file with loading and saving capabilities. The mesh read from the file is kept in CacheStl until ReleaseStlCache() lets it go; after that GetStl() reads it back on every call and keeps nothing — from the file it came from, or from the last copy copy-on-save wrote when that file is gone — and ExpandToBox3d(ref box3d_t) answers from the bounds kept at the load.

public class StlFile : IStlSource, IGetStl, IMakeXmlSource, IExpandToBox3d, IDuplicate, ISourceFile, IToPresentDto, IReleaseStlCache
Inheritance
StlFile
Implements
Inherited Members
Extension Methods

Constructors

StlFile()

Ctor.

public StlFile()

StlFile(string)

Ctor.

public StlFile(string filePath)

Parameters

filePath string

file path

StlFile(string, string)

Initializes a new instance with the specified file path and optional base directory. If base directory is provided, the STL will be loaded immediately.

public StlFile(string filePath, string baseDirectory)

Parameters

filePath string

STL file path

baseDirectory string

Base directory to load file from

StlFile(XElement, string, IProgress<IMessage>)

Ctor.

public StlFile(XElement src, string baseDirectory, IProgress<IMessage> progress)

Parameters

src XElement

XML

baseDirectory string

Base directory path

progress IProgress<IMessage>

Progress reporter for diagnostic messages emitted during construction.

Properties

CacheStl

The resident mesh: read by the XML constructor and LoadStlByFile(string), or handed in. Null when nothing is loaded and after ReleaseStlCache() (GetStl() then reads the file again). A mesh handed in through the setter is the only copy there is and is not released until copy-on-save has written it to a file. Its bounds are taken once, at the set: a mesh changed in place afterwards has to be assigned again for ExpandToBox3d(ref box3d_t) to follow it.

public Stl CacheStl { get; set; }

Property Value

Stl

SourceFile

Stl file path.

public string SourceFile { get; set; }

Property Value

string

XName

Name for XML IO.

public static string XName { get; }

Property Value

string

Methods

Duplicate(params object[])

Creates a deep copy of the object, excluding any source file references.

public object Duplicate(params object[] res)

Parameters

res object[]

Optional parameters that may be needed during the duplication process

Returns

object

A new instance that is a deep copy of the original object

Remarks

A resident mesh is copied; the files the mesh is read back from and the bounds are carried, so the duplicate of a released instance reads its mesh back the same way and can be released itself.

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

dst box3d_t

Destination box, expanded in place

Remarks

The bounds kept at the load when the mesh was read from a file (the mesh itself may have been released since) or at the set for a mesh handed in; nothing when nothing is loaded. Never reads the file, never scans the mesh.

GetStl()

Gets the STL geometry data.

public Stl GetStl()

Returns

Stl

The STL geometry object

Exceptions

FileNotFoundException

A released mesh whose files are gone, named by the path the mesh came from.

LoadStlByFile(string)

Loads an STL file from the specified base directory into the cache

public Stl LoadStlByFile(string baseDirectory)

Parameters

baseDirectory string

The base directory where the file is located

Returns

Stl

The loaded STL object, or null if the file path is empty

Exceptions

FileNotFoundException

The file is not there; the XML constructor reports that on its progress sink instead of throwing.

LoadStlByFile(string, CancellationToken)

Loads an STL file from the specified base directory into the cache, with cooperative cancellation of the underlying read. A cancelled load throws OperationCanceledException and leaves CacheStl unchanged (the previous cache, if any, stays valid). A successful load makes the file the one GetStl() reads again after ReleaseStlCache().

public Stl LoadStlByFile(string baseDirectory, CancellationToken cancel)

Parameters

baseDirectory string

The base directory where the file is located

cancel CancellationToken

Token to cancel the read

Returns

Stl

The loaded STL object, or null if the file path is empty

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

baseDirectory string

The base directory for resolving relative paths

relFile string

The relative file path for the XML source

exhibitionOnly bool

if 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 (or Default when factory is null). Idempotent.

public static void Reg(XFactory factory = null)

Parameters

factory XFactory

ReleaseStlCache()

Lets go of the kept mesh when GetStl() produces it again.

public bool ReleaseStlCache()

Returns

bool

True when the kept mesh is gone (or already was) and GetStl() produces it again; false when the mesh has to stay as the only copy there is (a mesh handed in by hand, a file since deleted or overwritten), or when there is nothing to produce.

Remarks

The resident mesh is let go only while the file it was read from is still there, unchanged (same length and last write): copy-on-save (MakeXmlSource(string, string, bool)) writes that mesh into a project that lacks the file, so a mesh that is the only copy — handed in through CacheStl and not written anywhere yet, or whose file was deleted or overwritten since the load — stays. True again on a later call while the file, or the last copy copy-on-save wrote, is there; false once both are gone.

SaveStlToFile(string)

Saves the mesh to a file in the specified base directory: the resident mesh, or a released mesh read back. The copy written becomes the file the mesh is read back from when the file it came from is gone, and the file of a mesh that was handed in, which can be released from then on.

public void SaveStlToFile(string baseDirectory)

Parameters

baseDirectory string

The base directory where the file will be saved

Remarks

Does nothing when there is no path or no mesh — a released mesh whose files are all gone included: nothing is left to write, and the read side reports the missing file on the next load. A source file that was never loaded (missing on disk) must stay missing — the read side then reports a FileNotFoundException naming the path — rather than be replaced by a 0-byte STL, which reads back as an opaque “Stl Loading failed” and gets committed into project repositories.

ToPresentDto()

Convert StlFile to presentation DTO (Data Transfer Object) for JSON serialization. The returned object includes type metadata for web API presentation.

public object ToPresentDto()

Returns

object

DTO dictionary with Type and SourceFile keys