Skip to content

Commit

Permalink
add missing code and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fidoriel committed Dec 3, 2024
1 parent bd20a21 commit 1396d91
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
38 changes: 37 additions & 1 deletion crates/opencascade/src/primitives/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl Shape {

reader.pin_mut().TransferRoots(&ffi::Message_ProgressRange_ctor());

let inner = ffi::one_shape(&reader);
let inner = ffi::one_shape_step(&reader);

Ok(Self { inner })
}
Expand All @@ -518,6 +518,42 @@ impl Shape {
Ok(())
}

pub fn read_iges(path: impl AsRef<Path>) -> Result<Self, Error> {
let mut reader = ffi::IGESControl_Reader_ctor();

let status = ffi::read_iges(reader.pin_mut(), path.as_ref().to_string_lossy().to_string());

reader.pin_mut().TransferRoots(&ffi::Message_ProgressRange_ctor());

if status != ffi::IFSelect_ReturnStatus::IFSelect_RetDone {
return Err(Error::IgesReadFailed);
}

let inner = ffi::one_shape_iges(&reader);

Ok(Self { inner })
}

pub fn write_iges(&self, path: impl AsRef<Path>) -> Result<(), Error> {
let mut writer = ffi::IGESControl_Writer_ctor();

let success = ffi::add_shape(writer.pin_mut(), &self.inner);

if !success {
return Err(Error::IgesWriteFailed);
}

ffi::compute_model(writer.pin_mut());
let success =
ffi::write_iges(writer.pin_mut(), path.as_ref().to_string_lossy().to_string());

if success {
Ok(())
} else {
Err(Error::IgesWriteFailed)
}
}

#[must_use]
pub fn union(&self, other: &Shape) -> BooleanShape {
let mut fuse_operation = ffi::BRepAlgoAPI_Fuse_ctor(&self.inner, &other.inner);
Expand Down
6 changes: 3 additions & 3 deletions docs/writing_bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ Standard_EXPORT TopoDS_Shape OneShape() const;
Unfortunately, this returns a bare `TopoDS_Shape` so we can't directly bind to it, we'll have to create a wrapper C++ function.

```rust
pub fn one_shape(reader: &STEPControl_Reader) -> UniquePtr<TopoDS_Shape>;
pub fn one_shape_step(reader: &STEPControl_Reader) -> UniquePtr<TopoDS_Shape>;
```

and

```c++
inline std::unique_ptr<TopoDS_Shape> one_shape(const STEPControl_Reader &reader) {
inline std::unique_ptr<TopoDS_Shape> one_shape_step(const STEPControl_Reader &reader) {
return std::unique_ptr<TopoDS_Shape>(new TopoDS_Shape(reader.OneShape()));
}
```
Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn from_step_file<P: AsRef<Path>>(path: P) -> Shape {
read_step(reader.pin_mut(), path.as_ref().to_string_lossy().to_string());
reader.pin_mut().TransferRoots(&Message_ProgressRange_ctor());

let inner = one_shape(&reader);
let inner = one_shape_step(&reader);

// Assuming a Shape struct has a UniquePtr<TopoDS_Shape> field called `inner`
Shape { inner }
Expand Down

0 comments on commit 1396d91

Please sign in to comment.