Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions crates/opencascade-sys/include/wrapper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TDF_Data.hxx>
#include <TDF_Label.hxx>
#include <TDF_Delta.hxx>
#include <TDF_Transaction.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Tool.hxx>
#include <gp.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
Expand All @@ -88,6 +95,105 @@
#include <gp_Trsf.hxx>
#include <gp_Vec.hxx>

// BEGIN Tdf stuff
typedef opencascade::handle<TDF_Data> HandleTdfData;
typedef opencascade::handle<TDF_Delta> HandleTdfDelta;

inline std::unique_ptr<HandleTdfData> TDF_Data_new() {
return std::unique_ptr<HandleTdfData>(new opencascade::handle<TDF_Data>(new TDF_Data()));
}

inline std::unique_ptr<TDF_Label> TDF_Data_root(const HandleTdfData& data) {
return std::unique_ptr<TDF_Label>(new TDF_Label(data->Root()));
}

inline std::unique_ptr<TDF_Label> TDF_Label_new_child(const TDF_Label& label) {
return std::unique_ptr<TDF_Label>(new TDF_Label(label.NewChild()));
}

inline bool TDF_Label_is_null(const TDF_Label& label) {
return label.IsNull();
}
inline std::unique_ptr<TDF_Transaction> TDF_Transaction_new(const HandleTdfData& data) {
return std::unique_ptr<TDF_Transaction>(new TDF_Transaction(data));
}

inline Standard_Integer TDF_Transaction_open(TDF_Transaction& transaction) {
return transaction.Open();
}

inline std::unique_ptr<HandleTdfDelta> TDF_Transaction_commit(TDF_Transaction& transaction) {
return std::unique_ptr<HandleTdfDelta>(new opencascade::handle<TDF_Delta>(transaction.Commit(true)));
}

inline void TDF_Transaction_abort(TDF_Transaction& transaction) {
transaction.Abort();
}

inline bool TDF_Transaction_is_open(const TDF_Transaction& transaction) {
return transaction.IsOpen();
}
inline std::unique_ptr<HandleTdfDelta> TDF_Data_undo(
HandleTdfData& data,
const HandleTdfDelta& delta
) {
return std::unique_ptr<HandleTdfDelta>(
new HandleTdfDelta(data->Undo(delta, Standard_True))
);
}

inline std::unique_ptr<TopoDS_Shape> TNaming_NamedShape_Get(
const Handle_TNaming_NamedShape& ns
) {
return std::unique_ptr<TopoDS_Shape>(new TopoDS_Shape(ns->Get()));
}

// BEGIN TNaming section of Tdf stuff



inline std::unique_ptr<TNaming_Builder> TNaming_Builder_ctor(const TDF_Label& label) {
return std::unique_ptr<TNaming_Builder>(new TNaming_Builder(label));
}

inline void TNaming_Builder_generated(TNaming_Builder& builder, const TopoDS_Shape& newShape) {
builder.Generated(newShape);
}

inline void TNaming_Builder_generated_with_old(TNaming_Builder& builder, const TopoDS_Shape& oldShape, const TopoDS_Shape& newShape) {
builder.Generated(oldShape, newShape);
}

inline void TNaming_Builder_modify(TNaming_Builder& builder, const TopoDS_Shape& oldShape, const TopoDS_Shape& newShape) {
builder.Modify(oldShape, newShape);
}

inline void TNaming_Builder_delete(TNaming_Builder& builder, const TopoDS_Shape& oldShape) {
builder.Delete(oldShape);
}

inline void TNaming_Builder_select(TNaming_Builder& builder, const TopoDS_Shape& shape, const TopoDS_Shape& inShape) {
builder.Select(shape, inShape);
}

inline std::unique_ptr<Handle_TNaming_NamedShape> TNaming_Builder_named_shape(
const TNaming_Builder& builder
) {
return std::unique_ptr<Handle_TNaming_NamedShape>(
new Handle_TNaming_NamedShape(builder.NamedShape())
);
}

inline std::unique_ptr<TopoDS_Shape> TNaming_Tool_original_shape(
const Handle_TNaming_NamedShape& ns
) {
return std::unique_ptr<TopoDS_Shape>(
new TopoDS_Shape(TNaming_Tool::OriginalShape(ns))
);
}
// END TNaming section of Tdf stuff
// END Tdf stuff

// Generic template constructor
template <typename T, typename... Args> std::unique_ptr<T> construct_unique(Args... args) {
return std::unique_ptr<T>(new T(args...));
Expand Down
60 changes: 60 additions & 0 deletions crates/opencascade-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,63 @@ pub mod ffi {
#[cxx_name = "construct_unique"]
pub fn Message_ProgressRange_ctor() -> UniquePtr<Message_ProgressRange>;

// TDF_Data management
type HandleTdfData;
type TDF_Label;
type TDF_Transaction;
type HandleTdfDelta;

pub fn TDF_Data_new() -> UniquePtr<HandleTdfData>;
pub fn TDF_Data_root(data: &HandleTdfData) -> UniquePtr<TDF_Label>;
pub fn TDF_Label_new_child(label: &TDF_Label) -> UniquePtr<TDF_Label>;
pub fn TDF_Label_is_null(label: &TDF_Label) -> bool;
pub fn TDF_Transaction_new(data: &HandleTdfData) -> UniquePtr<TDF_Transaction>;
pub fn TDF_Transaction_open(transaction: Pin<&mut TDF_Transaction>) -> i32;
pub fn TDF_Transaction_commit(
transaction: Pin<&mut TDF_Transaction>,
) -> UniquePtr<HandleTdfDelta>;
pub fn TDF_Transaction_abort(transaction: Pin<&mut TDF_Transaction>);
pub fn TDF_Transaction_is_open(transaction: &TDF_Transaction) -> bool;
pub fn TDF_Data_undo(
data: Pin<&mut HandleTdfData>,
delta: &HandleTdfDelta,
) -> UniquePtr<HandleTdfDelta>;

// TNaming
type TNaming_Builder;

pub fn TNaming_Builder_ctor(label: &TDF_Label) -> UniquePtr<TNaming_Builder>;
pub fn TNaming_Builder_generated(
builder: Pin<&mut TNaming_Builder>,
new_shape: &TopoDS_Shape,
);
pub fn TNaming_Builder_generated_with_old(
builder: Pin<&mut TNaming_Builder>,
old_shape: &TopoDS_Shape,
new_shape: &TopoDS_Shape,
);
pub fn TNaming_Builder_modify(
builder: Pin<&mut TNaming_Builder>,
old_shape: &TopoDS_Shape,
new_shape: &TopoDS_Shape,
);
pub fn TNaming_Builder_delete(builder: Pin<&mut TNaming_Builder>, old_shape: &TopoDS_Shape);
pub fn TNaming_Builder_select(
builder: Pin<&mut TNaming_Builder>,
shape: &TopoDS_Shape,
in_shape: &TopoDS_Shape,
);
type Handle_TNaming_NamedShape;

pub fn TNaming_Builder_named_shape(
builder: &TNaming_Builder,
) -> UniquePtr<Handle_TNaming_NamedShape>;

pub fn TNaming_Tool_original_shape(
ns: &Handle_TNaming_NamedShape,
) -> UniquePtr<TopoDS_Shape>;
pub fn TNaming_NamedShape_Get(ns: &Handle_TNaming_NamedShape) -> UniquePtr<TopoDS_Shape>;

// Handles
type HandleStandardType;
type HandleGeomCurve;
Expand Down Expand Up @@ -462,7 +519,9 @@ pub mod ffi {

pub fn IsNull(self: &TopoDS_Shape) -> bool;
pub fn IsEqual(self: &TopoDS_Shape, other: &TopoDS_Shape) -> bool;
pub fn IsSame(self: &TopoDS_Shape, other: &TopoDS_Shape) -> bool;
pub fn ShapeType(self: &TopoDS_Shape) -> TopAbs_ShapeEnum;
pub fn Location(self: &TopoDS_Shape) -> &TopLoc_Location;

type TopAbs_Orientation;
pub fn Orientation(self: &TopoDS_Shape) -> TopAbs_Orientation;
Expand Down Expand Up @@ -1246,6 +1305,7 @@ pub mod ffi {
pub fn IsDone(self: &BRepMesh_IncrementalMesh) -> bool;

type TopLoc_Location;
pub fn IsIdentity(self: &TopLoc_Location) -> bool;
#[cxx_name = "construct_unique"]
pub fn TopLoc_Location_ctor() -> UniquePtr<TopLoc_Location>;

Expand Down
1 change: 1 addition & 0 deletions crates/opencascade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod workplane;

mod law_function;
mod make_pipe_shell;
pub mod tdf;

#[derive(Error, Debug)]
pub enum Error {
Expand Down
8 changes: 8 additions & 0 deletions crates/opencascade/src/primitives/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,14 @@ impl Shape {
Self::from_shape(upgrader.Shape())
}

/// Reads the translation component of this shape's location transform.
/// For shapes with composed locations (e.g. nested assemblies), this
/// reflects the full composed transform, not just the outermost translation.
pub fn translation(&self) -> DVec3 {
let location = self.inner.as_ref().unwrap().Location();
let trsf = ffi::TopLoc_Location_Transformation(&location);
DVec3::new(trsf.Value(1, 4), trsf.Value(2, 4), trsf.Value(3, 4))
}
pub fn set_global_translation(&mut self, translation: DVec3) {
let mut transform = ffi::new_transform();
let translation_vec = make_vec(translation);
Expand Down
Loading