OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
io_step.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Capgemini Engineering Research and Development.
2//
3// This file is part of OCCT-Light software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Affero General Public License version 3 as published
7// by the Free Software Foundation, with an option to use any later version.
8// Consult the file LICENSE_AGPL_30.txt included in OCCT-Light distribution
9// for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of a commercial
12// license or contractual agreement.
13//
14// SPDX-License-Identifier: AGPL-3.0-or-later
15
21#ifndef OCCTL_HPP_IO_STEP_HPP
22#define OCCTL_HPP_IO_STEP_HPP
23
24#include <occtl/occtl_io_step.h>
25
26#include <occtl-hpp/core.hpp>
27#include <occtl-hpp/topo.hpp>
28
29#include <cstddef>
30#include <cstdint>
31#include <string>
32#include <utility>
33#include <vector>
34
35namespace occtl::io_step
36{
37
40{
41 bool read_color = true;
42 bool read_name = true;
43 bool read_layer = true;
44
45 [[nodiscard]] ::occtl_io_step_read_options_t to_c() const noexcept
46 {
47 ::occtl_io_step_read_options_t aOpts = OCCTL_IO_STEP_READ_OPTIONS_INIT;
48 aOpts.read_color = read_color ? 1 : 0;
49 aOpts.read_name = read_name ? 1 : 0;
50 aOpts.read_layer = read_layer ? 1 : 0;
51 return aOpts;
52 }
53};
54
57{
60 bool write_surface_curves = true;
61 bool write_tessellated = true;
62
63 [[nodiscard]] ::occtl_io_step_write_options_t to_c() const noexcept
64 {
65 ::occtl_io_step_write_options_t aOpts = OCCTL_IO_STEP_WRITE_OPTIONS_INIT;
66 aOpts.unit = unit;
67 aOpts.schema = schema;
68 aOpts.write_surface_curves = write_surface_curves ? 1 : 0;
69 aOpts.write_tessellated = write_tessellated ? 1 : 0;
70 return aOpts;
71 }
72};
73
76inline std::pair<Graph, NodeId> read(const std::string& thePath,
77 const ReadOptions& theOptions = ReadOptions{})
78{
79 ::occtl_graph_t* aRaw = nullptr;
80 ::occtl_node_id_t aRoot{};
81 const ::occtl_io_step_read_options_t aOpts = theOptions.to_c();
82 check(::occtl_io_step_read(thePath.c_str(), &aRaw, &aRoot, &aOpts));
83 return {Graph(aRaw), NodeId(aRoot)};
84}
85
88inline std::pair<Graph, NodeId> read_memory(const uint8_t* const theData,
89 const std::size_t theSize,
90 const ReadOptions& theOptions = ReadOptions{})
91{
92 ::occtl_graph_t* aRaw = nullptr;
93 ::occtl_node_id_t aRoot{};
94 const ::occtl_io_step_read_options_t aOpts = theOptions.to_c();
95 check(::occtl_io_step_read_memory(theData, theSize, &aRaw, &aRoot, &aOpts));
96 return {Graph(aRaw), NodeId(aRoot)};
97}
98
101inline std::pair<Graph, NodeId> read_memory(const std::vector<uint8_t>& theData,
102 const ReadOptions& theOptions = ReadOptions{})
103{
104 return read_memory(theData.empty() ? nullptr : theData.data(), theData.size(), theOptions);
105}
106
109inline void write(const Graph& theGraph,
110 const NodeId theRoot,
111 const std::string& thePath,
112 const WriteOptions& theOptions = WriteOptions{})
113{
114 const ::occtl_io_step_write_options_t aOpts = theOptions.to_c();
115 check(::occtl_io_step_write(theGraph.get(), theRoot.get(), thePath.c_str(), &aOpts));
116}
117
120inline std::vector<uint8_t> write_memory(const Graph& theGraph,
121 const NodeId theRoot,
122 const WriteOptions& theOptions = WriteOptions{})
123{
124 const ::occtl_io_step_write_options_t aOpts = theOptions.to_c();
125 std::size_t aSize = 0;
126 check(::occtl_io_step_write_memory(theGraph.get(), theRoot.get(), &aOpts, nullptr, 0, &aSize));
127
128 std::vector<uint8_t> aData(aSize);
130 theRoot.get(),
131 &aOpts,
132 aData.empty() ? nullptr : aData.data(),
133 aData.size(),
134 &aSize));
135 return aData;
136}
137
138} // namespace occtl::io_step
139
140#endif // OCCTL_HPP_IO_STEP_HPP
RAII handle for a topology graph. Mirrors occtl_graph_t.
Definition topo.hpp:1444
::occtl_graph_t * get() const noexcept
Borrows-it pointer to the underlying C handle, for direct ABI calls.
Definition topo.hpp:1494
Session-local identity of a graph node. Mirrors occtl_node_id_t.
Definition topo.hpp:52
::occtl_node_id_t get() const noexcept
Borrows-it view of the underlying C value type, for direct ABI calls.
Definition topo.hpp:64
C++ veneer for the core module.
void check(const ::occtl_status_t theStatus)
Throw on non-OK; otherwise a no-op.
Definition core.hpp:85
OCCT-Light: STEP file I/O (ISO 10303-21).
occtl_status_t occtl_io_step_write(const occtl_graph_t *graph, occtl_node_id_t root, const char *path, const occtl_io_step_write_options_t *options)
occtl_status_t occtl_io_step_write_memory(const occtl_graph_t *graph, occtl_node_id_t root, const occtl_io_step_write_options_t *options, uint8_t *out_data, size_t capacity, size_t *out_size)
@ OCCTL_IO_STEP_UNIT_MM
Definition occtl_io_step.h:49
occtl_status_t occtl_io_step_read_memory(const uint8_t *data, size_t size, occtl_graph_t **out_graph, occtl_node_id_t *out_root, const occtl_io_step_read_options_t *options)
@ OCCTL_IO_STEP_SCHEMA_AP242
Definition occtl_io_step.h:62
occtl_status_t occtl_io_step_read(const char *path, occtl_graph_t **out_graph, occtl_node_id_t *out_root, const occtl_io_step_read_options_t *options)
enum occtl_io_step_length_unit occtl_io_step_length_unit_t
enum occtl_io_step_schema occtl_io_step_schema_t
struct occtl_graph occtl_graph_t
Definition occtl_topo_types.h:152
Options for read. PascalCase mirror of occtl_io_step_read_options_t.
Definition io_step.hpp:40
Options for write. PascalCase mirror of occtl_io_step_write_options_t.
Definition io_step.hpp:57
Definition occtl_io_step.h:73
int32_t read_name
Definition occtl_io_step.h:77
int32_t read_layer
Definition occtl_io_step.h:78
int32_t read_color
Definition occtl_io_step.h:76
Definition occtl_io_step.h:87
int32_t write_surface_curves
Definition occtl_io_step.h:92
int32_t write_tessellated
Definition occtl_io_step.h:93
occtl_io_step_schema_t schema
Definition occtl_io_step.h:91
occtl_io_step_length_unit_t unit
Definition occtl_io_step.h:90
Definition occtl_topo_types.h:50
C++ veneer for the topo module.