Skip to content

Commit

Permalink
add iges import export
Browse files Browse the repository at this point in the history
  • Loading branch information
fidoriel committed Nov 20, 2024
1 parent ba2a149 commit a89fc8a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 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
20 changes: 19 additions & 1 deletion crates/opencascade-sys/include/wrapper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <IGESControl_Reader.hxx>
#include <IGESControl_Writer.hxx>
#include <Law_Function.hxx>
#include <Law_Interpol.hxx>
#include <NCollection_Array1.hxx>
Expand Down Expand Up @@ -361,7 +363,15 @@ inline IFSelect_ReturnStatus read_step(STEPControl_Reader &reader, rust::String
return reader.ReadFile(theFileName.c_str());
}

inline std::unique_ptr<TopoDS_Shape> one_shape(const STEPControl_Reader &reader) {
inline IFSelect_ReturnStatus read_iges(IGESControl_Reader &reader, rust::String theFileName) {
return reader.ReadFile(theFileName.c_str());
}

inline std::unique_ptr<TopoDS_Shape> one_shape_step(const STEPControl_Reader &reader) {
return std::unique_ptr<TopoDS_Shape>(new TopoDS_Shape(reader.OneShape()));
}

inline std::unique_ptr<TopoDS_Shape> one_shape_iges(const IGESControl_Reader &reader) {
return std::unique_ptr<TopoDS_Shape>(new TopoDS_Shape(reader.OneShape()));
}

Expand All @@ -370,10 +380,18 @@ inline IFSelect_ReturnStatus transfer_shape(STEPControl_Writer &writer, const To
return writer.Transfer(theShape, STEPControl_AsIs);
}

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 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
22 changes: 21 additions & 1 deletion crates/opencascade-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,35 +1146,55 @@ pub mod ffi {

// Data Import
type STEPControl_Reader;
type IGESControl_Reader;
type IFSelect_ReturnStatus;

#[cxx_name = "construct_unique"]
pub fn STEPControl_Reader_ctor() -> UniquePtr<STEPControl_Reader>;

#[cxx_name = "construct_unique"]
pub fn IGESControl_Reader_ctor() -> UniquePtr<IGESControl_Reader>;

pub fn read_step(
reader: Pin<&mut STEPControl_Reader>,
filename: String,
) -> IFSelect_ReturnStatus;
pub fn read_iges(
reader: Pin<&mut IGESControl_Reader>,
filename: String,
) -> IFSelect_ReturnStatus;
pub fn TransferRoots(
self: Pin<&mut STEPControl_Reader>,
progress: &Message_ProgressRange,
) -> i32;
pub fn one_shape(reader: &STEPControl_Reader) -> UniquePtr<TopoDS_Shape>;
pub fn TransferRoots(
self: Pin<&mut IGESControl_Reader>,
progress: &Message_ProgressRange,
) -> i32;
pub fn one_shape_step(reader: &STEPControl_Reader) -> UniquePtr<TopoDS_Shape>;
pub fn one_shape_iges(reader: &IGESControl_Reader) -> UniquePtr<TopoDS_Shape>;

// Data Export
type STEPControl_Writer;
type IGESControl_Writer;

#[cxx_name = "construct_unique"]
pub fn STEPControl_Writer_ctor() -> UniquePtr<STEPControl_Writer>;

#[cxx_name = "construct_unique"]
pub fn IGESControl_Writer_ctor() -> UniquePtr<IGESControl_Writer>;

pub fn transfer_shape(
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) -> bool;

type StlAPI_Writer;

Expand Down
4 changes: 4 additions & 0 deletions crates/opencascade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ pub enum Error {
StlWriteFailed,
#[error("failed to read STEP file")]
StepReadFailed,
#[error("failed to read IGES file")]
IgesReadFailed,
#[error("failed to read KiCAD PCB file: {0}")]
KicadReadFailed(#[from] kicad_parser::Error),
#[error("failed to write STEP file")]
StepWriteFailed,
#[error("failed to write IGES file")]
IgesWriteFailed,
#[error("failed to triangulate Shape")]
TriangulationFailed,
#[error("encountered a face with no triangulation")]
Expand Down
3 changes: 3 additions & 0 deletions examples/src/write_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct Args {
enum Format {
Step,
Stl,
Iges,
}

fn main() {
Expand All @@ -38,6 +39,7 @@ fn main() {
});

match format {
Format::Iges => model.write_iges(args.output).unwrap(),
Format::Step => model.write_step(args.output).unwrap(),
Format::Stl => model.write_stl(args.output).unwrap(),
}
Expand All @@ -47,6 +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"igs" => Some(Format::Iges),
_ => None,
}
}

0 comments on commit a89fc8a

Please sign in to comment.