Skip to content

Commit

Permalink
working export
Browse files Browse the repository at this point in the history
  • Loading branch information
fidoriel committed Nov 20, 2024
1 parent ece5930 commit 34d2e29
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/opencascade-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const OCCT_LIBS: &[&str] = &[
"TKBRep",
"TKPrim",
"TKDESTEP",
"TKDEIGES",
"TKDESTL",
"TKMesh",
"TKShHealing",
Expand Down
6 changes: 5 additions & 1 deletion crates/opencascade-sys/include/wrapper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,15 @@ inline IFSelect_ReturnStatus transfer_shape(STEPControl_Writer &writer, const To

inline void compute_model(IGESControl_Writer &writer) { writer.ComputeModel(); }

inline bool add_shape(IGESControl_Writer &writer, const TopoDS_Shape &theShape) { return writer.AddShape(theShape); }

inline IFSelect_ReturnStatus write_step(STEPControl_Writer &writer, rust::String theFileName) {
return writer.Write(theFileName.c_str());
}

inline void write_iges(IGESControl_Writer &writer, rust::String theFileName) { writer.Write(theFileName.c_str()); }
inline bool write_iges(IGESControl_Writer &writer, rust::String theFileName) {
return writer.Write(theFileName.c_str());
}

inline bool write_stl(StlAPI_Writer &writer, const TopoDS_Shape &theShape, rust::String theFileName) {
return writer.Write(theShape, theFileName.c_str());
Expand Down
3 changes: 2 additions & 1 deletion crates/opencascade-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,13 @@ pub mod ffi {
writer: Pin<&mut STEPControl_Writer>,
shape: &TopoDS_Shape,
) -> IFSelect_ReturnStatus;
pub fn add_shape(writer: Pin<&mut IGESControl_Writer>, shape: &TopoDS_Shape) -> bool;
pub fn compute_model(writer: Pin<&mut IGESControl_Writer>);
pub fn write_step(
writer: Pin<&mut STEPControl_Writer>,
filename: String,
) -> IFSelect_ReturnStatus;
pub fn write_iges(writer: Pin<&mut IGESControl_Writer>, filename: String);
pub fn write_iges(writer: Pin<&mut IGESControl_Writer>, filename: String) -> bool;

type StlAPI_Writer;

Expand Down
19 changes: 16 additions & 3 deletions crates/opencascade/src/primitives/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl Shape {
reader.pin_mut().TransferRoots(&ffi::Message_ProgressRange_ctor());

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

let inner = ffi::one_shape_iges(&reader);
Expand All @@ -536,9 +536,22 @@ impl Shape {

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());
ffi::write_iges(writer.pin_mut(), path.as_ref().to_string_lossy().to_string());
Ok(())
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]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/write_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn determine_format(extension: &OsStr) -> Option<Format> {
match extension.to_ascii_lowercase().as_bytes() {
b"step" | b"stp" => Some(Format::Step),
b"stl" => Some(Format::Stl),
b"iges" | b"stp" => Some(Format::Iges),
b"iges" | b"igs" => Some(Format::Iges),
_ => None,
}
}

0 comments on commit 34d2e29

Please sign in to comment.