OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
io_stl.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_STL_HPP
22#define OCCTL_HPP_IO_STL_HPP
23
24#include <occtl/occtl_io_stl.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_stl
36{
37
40{
41 bool ascii_mode = false;
42
43 [[nodiscard]] ::occtl_io_stl_write_options_t to_c() const noexcept
44 {
45 ::occtl_io_stl_write_options_t aOpts = OCCTL_IO_STL_WRITE_OPTIONS_INIT;
46 aOpts.ascii_mode = ascii_mode ? 1 : 0;
47 return aOpts;
48 }
49};
50
53inline std::pair<Graph, NodeId> read(const std::string& thePath)
54{
55 ::occtl_graph_t* aRaw = nullptr;
56 ::occtl_node_id_t aRoot{};
57 check(::occtl_io_stl_read(thePath.c_str(), &aRaw, &aRoot));
58 return {Graph(aRaw), NodeId(aRoot)};
59}
60
63inline std::pair<Graph, NodeId> read_memory(const uint8_t* const theData, const std::size_t theSize)
64{
65 ::occtl_graph_t* aRaw = nullptr;
66 ::occtl_node_id_t aRoot{};
67 check(::occtl_io_stl_read_memory(theData, theSize, &aRaw, &aRoot));
68 return {Graph(aRaw), NodeId(aRoot)};
69}
70
73inline std::pair<Graph, NodeId> read_memory(const std::vector<uint8_t>& theData)
74{
75 return read_memory(theData.data(), theData.size());
76}
77
80inline void write(const Graph& theGraph,
81 const NodeId theRoot,
82 const std::string& thePath,
83 const WriteOptions& theOptions = WriteOptions{})
84{
85 const ::occtl_io_stl_write_options_t aOpts = theOptions.to_c();
86 check(::occtl_io_stl_write(theGraph.get(), theRoot.get(), thePath.c_str(), &aOpts));
87}
88
91inline std::vector<uint8_t> write_memory(const Graph& theGraph,
92 const NodeId theRoot,
93 const WriteOptions& theOptions = WriteOptions{})
94{
95 const ::occtl_io_stl_write_options_t aOpts = theOptions.to_c();
96 std::size_t aSize = 0;
97 check(::occtl_io_stl_write_memory(theGraph.get(), theRoot.get(), &aOpts, nullptr, 0, &aSize));
98 std::vector<uint8_t> aBytes(aSize);
100 theRoot.get(),
101 &aOpts,
102 aBytes.data(),
103 aBytes.size(),
104 &aSize));
105 aBytes.resize(aSize);
106 return aBytes;
107}
108
109} // namespace occtl::io_stl
110
111#endif // OCCTL_HPP_IO_STL_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: STL file I/O (stereolithography mesh format).
occtl_status_t occtl_io_stl_read_memory(const uint8_t *data, size_t size, occtl_graph_t **out_graph, occtl_node_id_t *out_root)
occtl_status_t occtl_io_stl_write_memory(const occtl_graph_t *graph, occtl_node_id_t root, const occtl_io_stl_write_options_t *options, uint8_t *out_data, size_t capacity, size_t *out_size)
occtl_status_t occtl_io_stl_write(const occtl_graph_t *graph, occtl_node_id_t root, const char *path, const occtl_io_stl_write_options_t *options)
occtl_status_t occtl_io_stl_read(const char *path, occtl_graph_t **out_graph, occtl_node_id_t *out_root)
struct occtl_graph occtl_graph_t
Definition occtl_topo_types.h:152
Options for write. PascalCase mirror of occtl_io_stl_write_options_t.
Definition io_stl.hpp:40
Definition occtl_io_stl.h:54
int32_t ascii_mode
Definition occtl_io_stl.h:57
Definition occtl_topo_types.h:50
C++ veneer for the topo module.