Internal Modules#
These are internal modules used by volmdlr. They are documented here for reference but are not part of the public API.
Marching Cubes#
Module for marching cube algorithm. Should be moved to volmdlr_tools when cad_simplification module will be moved.
- volmdlr.marching_cubes.marching_cubes(matrix_based_voxelization: MatrixBasedVoxelization) Mesh3D#
Perform the marching cubes algorithm on a given MatrixBasedVoxelization.
- Parameters:
matrix_based_voxelization – The input voxelization to perform the marching cubes algorithm on.
- Returns:
A Mesh3D object as the result of the marching cubes algorithm.
OCAF#
Define OCAF object to easily manipulate open cascade OCAF framework.
This is used to read and write step files with metadata associated to the shapes like colors and names.
- class volmdlr.ocaf.Datum(wrapped)#
Bases:
DimTolObjectsWrapping class for a XCAFDimTolObjects_DatumGeomToleranceObject.
- get_data()#
Get Datum data (under construction).
- Returns:
dict containing datum semantic data.
- get_modifiers()#
Get annotation modifiers.
- get_value() str#
Get datum name.
- class volmdlr.ocaf.DimTolObjects(wrapped)#
Bases:
objectDimTolObjects wrapper class.
- Extra = '(),.+-±:/°"⌀'#
- FCF_symbols = 'ⒺⒻⓁⓂⓅⓈⓉⓊ'#
- GDT_symbols = '⏤⏥○⌭⌒⌓⏊∠⫽⌯⌖◎↗⌰'#
- get_modifiers()#
Get annotation modifiers.
- get_name() str#
Get object name.
- Returns:
The name of the object as a string.
- Return type:
str
- get_presentation()#
Get PMI graphic representation as TopoDS_Shape.
- Returns:
- get_value() float#
Get numerical value for tolerance or dimension (always in meters).
- property shapes: list[TopoDS_Shape]#
Get datums related with this GeomTolerance.
- class volmdlr.ocaf.Dimension(wrapped)#
Bases:
DimTolObjectsWrapping class for a XCAFDimTolObjects_DimensionObject.
- get_data()#
Get semantic data of the PMI annotation.
- Returns:
dict containing Dimension semantic data.
- get_representation() str#
Get PMI semantic representation as a string.
- Returns:
The semantic data of the GeomTolerance object.
- property type: str#
Return the type of the dimension as a string.
- Possible values:
Location_None
Location_CurvedDistance
Location_LinearDistance
Location_LinearDistance_FromCenterToOuter
Location_LinearDistance_FromCenterToInner
Location_LinearDistance_FromOuterToCenter
Location_LinearDistance_FromOuterToOuter
Location_LinearDistance_FromOuterToInner
Location_LinearDistance_FromInnerToCenter
Location_LinearDistance_FromInnerToOuter
Location_LinearDistance_FromInnerToInner
Location_Angular
Location_Oriented
Location_WithPath
Size_CurveLength
Size_Diameter
Size_SphericalDiameter
Size_Radius
Size_SphericalRadius
Size_ToroidalMinorDiameter
Size_ToroidalMajorDiameter
Size_ToroidalMinorRadius
Size_ToroidalMajorRadius
Size_ToroidalHighMajorDiameter
Size_ToroidalLowMajorDiameter
Size_ToroidalHighMajorRadius
Size_ToroidalLowMajorRadius
Size_Thickness
Size_Angular
Size_WithPath
CommonLabel
DimensionPresentation
- class volmdlr.ocaf.GeomTolerance(wrapped)#
Bases:
DimTolObjectsWrapping class for a XCAFDimTolObjects_GeomToleranceObject.
- get_data()#
Get Datum data (under construction).
- Returns:
dict containing GeomTolerance semantic data.
- get_datum_representation()#
Get representation from the datums associated with the tolerance.
- get_representation() str#
Get PMI semantic representation as a string.
- Returns:
The semantic data of the GeomTolerance object.
- property symbol#
Return tolerance symbol.
- property type: str#
Return the type of the tolerance as a string.
- class volmdlr.ocaf.Metadata(title: str | None = '', metadata_type: str | None = '', value: str | None = '', units: str | None = '', category: str | None = '', name: str = '')#
Bases:
DessiaObjectA class to store metadata about a CAD file.
- class volmdlr.ocaf.OCAF(doc: TDocStd_Document, name: str = '')#
Bases:
DessiaObjectClass for encapsulating and allow a more fluid and pythonic way to manipulate a XDE document.
- For more detail about OCAF, please refer to:
https://dev.opencascade.org/doc/overview/html/occt_user_guides__ocaf.html
- static add_child(label: TDF_Label)#
Add a new child on an automatic generated tag in the given label and returns the label of this child.
- Parameters:
label (TDF_Label) – The parent label where the child will be added.
- Returns:
The label of the newly added child.
- Return type:
TDF_Label
- babylon_data(merge_meshes=True, show_curves: bool = False)#
Get babylonjs data.
- Returns:
Dictionary with babylon data.
- static child_iterator(label: TDF_Label)#
Iterate over all child of a given label.
- static create_empty_doc(doc_format: str = 'BinOcaf')#
Initialize an empty OCAF document.
- Parameters:
doc_format (str) –
The format of the document. Available formats:
Binary formats - ‘BinLOcaf’, ‘BinOcaf’, ‘BinXCAF’, ‘TObjBin’ XML formats - ‘XmlLOcaf’, ‘XmlOcaf’, ‘XmlXCAF’, ‘TObjXml’
- Returns:
The initialized empty OCAF document.
- Return type:
TDocStd_Document
- classmethod dict_to_object(dict_: Dict[str, Any], *args, **kwargs) OCAF#
Create a OCAF from a dictionary.
- classmethod empty(doc_format: str = 'BinOcaf')#
Instantiate an empty OCAF object.
- Parameters:
doc_format (str) –
The format of the document. Available formats:
Binary formats - ‘BinOcaf’, ‘BinXCAF’, ‘TObjBin’ XML formats - ‘XmlLOcaf’, ‘XmlOcaf’, ‘XmlXCAF’, ‘TObjXml’
- static find_attribute(label, guid)#
Reimplementation of the TDF_Label::FindAttribute method in Python.
- Parameters:
label (TDF_Label) – The label to search in.
guid (Standard_GUID) – The GUID of the attribute to find.
- Returns:
A tuple where the first element is a boolean indicating if the attribute was found, and the second element is the found attribute handle.
- Return type:
(bool, TDF_Attribute)
- classmethod from_doc_stream(stream: BytesIO, name: str = '') OCAF#
Create a OCAF object from a stream.
- classmethod from_file(path: str, name: str = '')#
Instantiate a OCAF object from a CAF file (Open Cacade internal file).
- Parameters:
path (str) – The path to the CAF file.
- Returns:
An instance of OCAF initialized with the contents of the file.
- Return type:
- Raises:
ValueError – If the file format is not supported.
- classmethod from_step(path: str, reading_unit: Literal['M', 'MM'] = 'M')#
Load a STEP model from the specified path.
- Parameters:
path – The path to the STEP file.
reading_unit – The unit of measurement used to read the STEP file. Default is “M” (meters).
- Returns:
A list of model shapes with associated metadata.
- classmethod from_step_stream(stream: BinaryFile, reading_unit: Literal['M', 'MM'] = 'M')#
Load a STEP model from the specified path.
- Parameters:
stream – The stream of the STEP file.
reading_unit – The unit of measurement used to read the STEP file. Default is “M” (meters).
- Returns:
A list of model shapes with associated metadata.
- get_children_metadata(shape, shape_set, parent_label=None) dict#
Check if the children shapes of a parent shape have associated metadata to it.
For now, this mechanism is only used for to associated different colors o a Solid shape.
- Parameters:
shape – Parent shape.
shape_set – Shape set of from which shape belongs.
parent_label – The parent label if it’s available.
- Returns:
If the shape has any children shape data a dictionary with the data is returned, otherwise an empty
dictionary is returned.
- get_color(label: ~OCP.TDF.TDF_Label, color_type: ~OCP.Quantity.Quantity_TypeOfColor = <Quantity_TypeOfColor.Quantity_TOC_RGB: 0>) tuple[float, float, float, float]#
Get the color associated to a given label.
- Parameters:
label – A TopoDS_Shape.
color_type – Specifies how to read the color.
- get_color_from_shape(shape: ~OCP.TopoDS.TopoDS_Shape, color_type: ~OCP.Quantity.Quantity_TypeOfColor = <Quantity_TypeOfColor.Quantity_TOC_RGB: 0>) tuple[float, float, float, float]#
Get the color associated to a given shape.
- Parameters:
shape – A TopoDS_Shape.
color_type – Specifies how to read the color.
- get_doc_nodes_data(shape_set: BRepTools_ShapeSet | None = None, leaf=False)#
Read document and return a dictionary of node data.
- Parameters:
shape_set (BRepTools_ShapeSet) – (Optional) The ShapeSet of the shapes of the document. If not given, we get the root shapes of the document.
leaf (bool) – If True, only leaf nodes are considered.
- Returns:
A dictionary containing node data.
- Return type:
dict
- get_gdt_presentations()#
Return a list containing all GD&T representations.
- Returns:
list[TopoDS_Compound]
- get_label_from_shape(shape: TopoDS_Shape)#
Get shape’s label.
- get_metadata(label: TDF_Label) list[Metadata]#
Retrieve metadata associated with a given label in the OCAF document.
This method reads the metadata from a TDF_Label that was previously set using the TDataStd_NamedData attribute. The metadata fields returned include title, type, value, unit, and category.
- Parameters:
label – The label from which to retrieve the metadata. This label typically represents a shape in the document.
- Returns:
A dictionary containing the metadata associated with the label. The keys are: - ‘title’ (str): The title or description of the metadata. - ‘type’ (str): The type of metadata. - ‘value’ (float): A numerical value associated with the metadata. - ‘units’ (str): The unit of measurement for the value of this metadata. - ‘category’ (str): The category to which the metadata belongs.
Get the XCAFDimTolObjects_DatumObject(s) related to a XCAFDimTolObjects_GeomToleranceObject.
- Parameters:
tolerance_label – The geometric tolerance object.
- Returns:
A list of related DatumObject instances.
- get_shape_metadata(shape: TopoDS_Shape) ShapeMetadata#
Get all metadata related to a given shape.
- Parameters:
shape – A TopoDS_Shape.
- Returns:
A Metadata object.
- get_shape_metadata_from_label(label: TDF_Label) ShapeMetadata#
Get all metadata related to a given shape.
- Parameters:
label – The TDF_Label related to the TopoDS_Shape.
- Returns:
A dictionary contai
- get_shape_name(shape: TopoDS_Shape) str#
Get shape’s name.
- Parameters:
shape (TopoDS_Shape) – A shape conatained in the CAF document.
- Returns:
The name associated to the given label
- Return type:
str
- static get_shape_name_from_label(label: TDF_Label) str#
Get shape’s name from its document label.
- Parameters:
label (TDF_Label) – Label of the shape.
- Returns:
The name associated to the given label
- Return type:
str
- print()#
Print document structure.
- read_gdt() tuple[list[GeomTolerance], list[Dimension], list[Datum]]#
Read Geometric Dimensioning and Tolerancing (GD&T) data from an OCAF document.
This method extracts and wraps geometric tolerances, dimensions, and datums into corresponding objects, returning them as lists.
- Returns:
A tuple containing three lists: - A list of GeomTolerance objects representing geometric tolerances. - A list of Dimension objects representing dimensions. - A list of Datum objects representing datums.
- Return type:
tuple[list[GeomTolerance], list[Dimension], list[Datum]]
- save(file: str | BytesIO) bool#
Save the document in the specified format.
- Extensions correspondeces:
.cbf for “BinOcaf” documents
.bxf for “BinXCAF” documents
.xml for “XmlOcaf” and “XmlXCAF” documents
- Parameters:
file (Union[str, io.BytesIO]) – The name of the file where the document will be saved.
- Returns:
True if the document was saved successfully, False otherwise.
- Return type:
bool
- set_color(label: TDF_Label, color: Quantity_ColorRGBA)#
Set color given color to a given label.
- static set_metadata(label: TDF_Label, metadata_list: list[Metadata]) None#
Associates a list of metadata entries with the given label in the OCAF document.
Each as a separate sub-label to allow multiple metadata entries.
- Parameters:
label – The label to which the metadata should be associated.
metadata_list – A list of Metadata dataclass instances to associate.
- static set_name(label: TDF_Label, name: str)#
Set name given color to a given label.
- static shape_iterator(shape: TopoDS_Shape)#
Iterate through all the children of a given shape.
- shapes() list[TopoDS_Shape]#
Return a list of all top-level shapes which are free (i.e. not referred by any other).
- Returns:
A list of all top-level shapes which are free.
- Return type:
list[TopoDS_Shape]
- to_dict(*args, **kwargs) Dict[str, Any]#
Serialize a 3-dimensional Shape into a dictionary.
- to_doc_stream() BytesIO#
Export OCAF document as a stream.
- write_step(path: str, preferences: StepWriterPreferences | None = None)#
Write STEP file with the document data.
- Parameters:
path (str) – The path to the STEP file.
preferences – Step writer preferences
- write_step_stream(stream: BinaryFile, preferences: StepWriterPreferences | None = None)#
Write STEP file with the document data.
- Parameters:
stream – A dessia file
preferences – Step writer preferences
- class volmdlr.ocaf.StepWriterPreferences(precision_mode: int = 1, assembly: int = 2, schema: str = 'AP214IS', surfacecurve_mode: int = 0, unit: str = 'M')#
Bases:
objectA dataclass for storing and modifying the STEP writer preferences.
Attributes#
- precision_modeint
The mode for controlling the precision of the written STEP file. Possible values are -1 (Least), 0 (Average), 1 (Greatest), and 2 (Session). Default value is 1.
The mode for controlling the assembly structure in the written STEP file.
- assemblyint
Possible values are 0 (Off), 1 (On), and 2 (Auto). Default value is 2.
- schemastr
The schema for the written STEP file. Possible values are ‘AP214CD’, ‘AP214DIS’, ‘AP203’, ‘AP214IS’, and ‘AP242DIS’. Default value is ‘AP214CD’.
- surfacecurve_modeint
The mode for controlling the writing of surface curves in the written STEP file. Possible values are 0 (Off) and 1 (On). Default value is 0.
- unitstr
The unit for the written STEP file. Possible values are ‘M’ (meters), ‘MM’ (millimeters), ‘INCH’ (inches), and ‘FT’ (feet). Default value is ‘M’.
- assembly: int = 2#
- precision_mode: int = 1#
- schema: str = 'AP214IS'#
- surfacecurve_mode: int = 0#
- unit: str = 'M'#
- volmdlr.ocaf.step_reader_setup(reading_unit: Literal['M', 'MM'] = 'M') STEPCAFControl_Reader#
Set step reader up.
Shape Healing#
Module with functions to fix problematic shapes.
- volmdlr.shape_healing.fix_shape(shape: TopoDS_Shape) TopoDS_Shape#
Fix shape using OCP (Open CASCADE Python wrapper).
- Parameters:
shape – The TopoDS_Shape to fix
- Returns:
The fixed shape
Templates#
volmdlr to babylonjs templates.