Skip to main content

Crate cadkit_capi

Crate cadkit_capi 

Source
Expand description

Stable C ABI over the cadkit facade.

The public contract is include/cadkit.h (hand-maintained; tests/header.rs checks that every exported symbol is declared there) and the header-only C++17 wrapper include/cadkit.hpp.

Design rules:

  • Every function returns a cadkit_status; output goes through out-pointers.
  • Every pointer argument is null-checked; no panic crosses the FFI boundary (catch_unwind turns it into cadkit_status::Panic).
  • The last error message is thread-local and owned by the library.
  • Documents are immutable after creation. Live handles are tracked in a registry so that a second cadkit_document_free or a use after free is reported as cadkit_status::InvalidHandle instead of corrupting memory (best effort: a freed address that is reused by a new document is indistinguishable from the new one).

Re-exports§

pub use cadkit;

Structs§

cadkit_document
Opaque document handle. Create with cadkit_read_*, release with cadkit_document_free.
cadkit_info
Summary of a document (plain data, no ownership).
cadkit_options
Read options. Zero in a numeric field selects the library default; NULL options select all defaults. Initialize with cadkit_options_init to be forward compatible.
cadkit_svg_options
SVG options. Initialize with cadkit_svg_options_init.

Enums§

cadkit_dxf_version
DXF output version. Values are part of the ABI.
cadkit_format
Detected file format. Values are part of the ABI.
cadkit_status
Result code of every fallible call. Values are part of the ABI.

Functions§

cadkit_bytes_free
Releases a binary buffer returned by this library; NULL and previously freed pointers are no-ops.
cadkit_citygml_preflight_tkgm⚠
Returns the local TKGM preflight report for native CityGML JSON. profile is required: city-model-tender or digital-building-registration. This never establishes official acceptance. Free the output with cadkit_string_free.
cadkit_citygml_read_json⚠
Reads a CityGML 2.0 XML buffer into its native object-graph JSON; release *out with cadkit_string_free.
cadkit_citygml_write_json⚠
Serializes native CityGML JSON to UTF-8 CityGML 2.0 XML; validation_options follows the Rust gml::ValidationOptions JSON contract (NULL selects defaults). Release *out with cadkit_string_free.
cadkit_detect⚠
Detects the format from the header. Returns CADKIT_FORMAT_UNKNOWN for NULL data.
cadkit_dgn_strip_seed⚠
Copies a DGN V8 seed without the drawing content of its model and without the document properties that name people or organisations (dgn::strip_seed_v8). options_json_text follows the Rust dgn::StripSeedOptions JSON contract (an unknown field is InvalidArgument) and options sets the read limits; NULL selects the defaults of either. On success *out / *out_len hold the seed (release with cadkit_bytes_free) and *report_json the dgn::StripSeedReport JSON (release with cadkit_string_free); on failure all three are NULL / 0. Names in the kept tables remain and are counted in the report; the result is not anonymous.
cadkit_document_convert_units⚠
Returns a new immutable document converted to the named length unit (e.g. “mm”, “meter”).
cadkit_document_explode_inserts⚠
Returns a new immutable document with block references expanded up to max_depth. Missing/cyclic/deeper references remain as inserts, as in Rust Document::explode_inserts.
cadkit_document_free⚠
Releases a document. NULL is a no-op; a handle that is not live returns CADKIT_INVALID_HANDLE and frees nothing. The handle must not be used afterwards.
cadkit_document_from_json⚠
Constructs a format-neutral document from its JSON representation.
cadkit_document_info⚠
Fills out with a summary of doc.
cadkit_document_info_json⚠
Returns the summary as a JSON object (format, version, application, counts, per-kind entity counts). *out is an owned string; free with cadkit_string_free.
cadkit_document_to_citygml⚠
Exports generic geometry as a UTF-8 CityGML 2.0 string; release *out with cadkit_string_free.
cadkit_document_to_citygml_with_report⚠
Returns JSON containing xml and an ExportReport. Free it with cadkit_string_free. metadata_only must be 0 (reject unsupported geometry) or 1 (retain it as metadata). Coordinates use the supplied CRS without conversion. Metadata is not rendered geometry.
cadkit_document_to_dgn⚠
Writes DGN V8 bytes using seed. Release *out with cadkit_bytes_free. options_json_text follows the Rust dgn::WriteOptions JSON contract; NULL selects defaults.
cadkit_document_to_dxf⚠
Writes the document as ASCII DXF of the given cadkit_dxf_version.
cadkit_document_to_dxf_bytes⚠
Writes DXF bytes with optional legacy code page; release with cadkit_bytes_free.
cadkit_document_to_json⚠
Serializes the document to JSON (UTF-8). *out is owned; free with cadkit_string_free.
cadkit_document_to_svg⚠
Renders one model as SVG. options may be NULL for defaults.
cadkit_inspect_bytes⚠
Inspects an in-memory header and returns owned summary JSON; free with cadkit_string_free.
cadkit_inspect_file⚠
Inspects a file header and returns owned summary JSON; free with cadkit_string_free.
cadkit_last_error_message
Returns the message of the last failed call on this thread, or an empty string.
cadkit_options_init⚠
Fills options with defaults.
cadkit_read_bytes⚠
Reads a drawing from memory. The buffer is not retained.
cadkit_read_file⚠
Reads a drawing from a UTF-8 file path. On success *out owns a document to free with cadkit_document_free; on failure *out is NULL.
cadkit_status_string
Returns a static description of a cadkit_status value. Never NULL; do not free.
cadkit_string_free⚠
Frees a string returned by a cadkit_document_* getter. NULL is a no-op.
cadkit_svg_options_init⚠
Fills options with defaults (model 0, 1600 px wide, white background, text and blocks on).
cadkit_version
Returns the library version, e.g. "0.1.0". Static; never NULL; do not free.