跳到主要内容

SaveOptions / LoadOptions

C++: phynexis::utils::SaveOptions, LoadOptions, SaveVtkOptions, FileFormat Python: phynexis.utils.SaveOptions, LoadOptions, SaveVtkOptions, FileFormat Header: src/utils/serde/save_options.hpp

Configuration objects for file save/load operations used by Shape.save_to() / Shape.load_from() and other serializable types.

FileFormat​

Enum defining supported file formats.

ValueDescription
FileFormat.AutoInfer from file extension
FileFormat.JsonJSON format
FileFormat.BinaryBinary format
FileFormat.VTKVTK format
FileFormat.StlSTL mesh format
FileFormat.OffOFF mesh format

SaveOptions​

Constructor​

SaveOptions()​

Default: overwrite=True, create_directories=True, format_hint=Auto.

Properties​

PropertyTypeAccessDescription
overwriteboolread/writeOverwrite existing files
create_directoriesboolread/writeCreate parent directories
format_hintFormatHintread/writeFormat override hint

SaveVtkOptions​

Inherits from SaveOptions. Adds VTK-specific settings.

Constructor​

SaveVtkOptions()​

Default: binary=False, use_double=False.

Properties​

PropertyTypeAccessDescription
binaryboolread/writeWrite VTK in binary mode
use_doubleboolread/writeUse double precision

LoadOptions​

Constructor​

LoadOptions()​

Default: create_directories=False, format_hint=Auto.

Properties​

PropertyTypeAccessDescription
create_directoriesboolread/writeCreate parent directories
format_hintFormatHintread/writeFormat override hint

Example​

import phynexis

# Save options with JSON format
opt = phynexis.utils.SaveOptions()
opt.overwrite = True
opt.create_directories = True
opt.format_hint.value = phynexis.utils.FileFormat.Json
print("format:", opt.format_hint.value)

# VTK options
vtk_opt = phynexis.utils.SaveVtkOptions()
vtk_opt.binary = True
vtk_opt.use_double = True
print("vtk binary:", vtk_opt.binary)

# Load options
load_opt = phynexis.utils.LoadOptions()
load_opt.create_directories = False
print("load create_dirs:", load_opt.create_directories)

Output:

format: FileFormat.Json
vtk binary: True
load create_dirs: False

Format Utility Functions​

Top-level utility functions for resolving file formats.

format_from_extension(ext)​

Look up the FileFormat enum value from a file extension (with dot).

Parameters:

ParameterTypeDescription
extstrFile extension including dot, e.g. ".stl"

Returns: FileFormat

format_from_path(path)​

Look up the FileFormat enum value from a file path by extracting its extension.

Parameters:

ParameterTypeDescription
pathstrFile path

Returns: FileFormat

join_path_file(path, file)​

Join a base directory path and a filename.

Parameters:

ParameterTypeDescription
pathstrBase directory path
filestrFilename

Returns: str

Example:

import phynexis

# Format resolution
fmt_ext = phynexis.utils.format_from_extension(".stl")
print("from .stl:", fmt_ext)

fmt_path = phynexis.utils.format_from_path("/data/model.stl")
print("from path:", fmt_path)

# Path joining
joined = phynexis.utils.join_path_file("/output", "result.txt")
print("joined:", joined)

Output:

from .stl: FileFormat.Stl
from path: FileFormat.Stl
joined: /output/result.txt