Skip to content

Commit

Permalink
add a few requested functions to 7.15
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaer committed Mar 23, 2022
1 parent 4c9ea68 commit 1fa188c
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [7.15.0] - 2022-03-23
### Added
- (js, py) Added ViewportInfo.TargetPoint
- (js, py) Added BrepFace.CreateExtrusion
- (.net) Added two new Hatch creation routines (CreateFromBrep and Create). The Create version takes curve loop inputs to create the hatch.

### Changed
- Updated opennurbs source to be based on Rhino 7.15 version
Expand Down
24 changes: 24 additions & 0 deletions src/bindings/bnd_brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ void BND_BrepFace::SetTrackedPointer(ON_BrepFace* brepface, const ON_ModelCompon
BND_SurfaceProxy::SetTrackedPointer(brepface, compref);
}

BND_Brep* BND_BrepFace::CreateExtrusion(const class BND_Curve* pathCurve, bool cap) const
{
BND_Brep* rc = nullptr;
const ON_Brep* pConstBrep = m_brepface->Brep();
const ON_Curve* pConstCurve = pathCurve ? pathCurve->m_curve : nullptr;
if (pConstBrep && pConstCurve)
{
ON_Brep* pNewBrep = ON_Brep::New(*pConstBrep);
if (pNewBrep)
{
pNewBrep->DestroyMesh(ON::any_mesh);
int result = ON_BrepExtrudeFace(*pNewBrep, m_brepface->m_face_index, *pConstCurve, cap);
// 0 == failure, 1 or 2 == success
if (0 == result)
delete pNewBrep;
else
rc = new BND_Brep(pNewBrep, nullptr);
}
}
return rc;
}

BND_Brep* BND_BrepFace::DuplicateFace(bool duplicateMeshes)
{
const ON_Brep* parentBrep = m_brepface->Brep();
Expand Down Expand Up @@ -282,6 +304,7 @@ void initBrepBindings(pybind11::module& m)

py::class_<BND_BrepFace, BND_SurfaceProxy>(m, "BrepFace")
.def("UnderlyingSurface", &BND_BrepFace::UnderlyingSurface)
.def("CreateExtrusion", &BND_BrepFace::CreateExtrusion, py::arg("pathCurve"), py::arg("cap"))
.def("DuplicateFace", &BND_BrepFace::DuplicateFace, py::arg("duplicateMeshes"))
.def("DuplicateSurface", &BND_BrepFace::DuplicateSurface)
.def("GetMesh", &BND_BrepFace::GetMesh, py::arg("meshType"))
Expand Down Expand Up @@ -335,6 +358,7 @@ void initBrepBindings(void*)

class_<BND_BrepFace, base<BND_SurfaceProxy>>("BrepFace")
.function("underlyingSurface", &BND_BrepFace::UnderlyingSurface, allow_raw_pointers())
.function("createExtrusion", &BND_BrepFace::CreateExtrusion, allow_raw_pointers())
.function("duplicateFace", &BND_BrepFace::DuplicateFace, allow_raw_pointers())
.function("duplicateSurface", &BND_BrepFace::DuplicateSurface, allow_raw_pointers())
.function("getMesh", &BND_BrepFace::GetMesh, allow_raw_pointers())
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/bnd_brep.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class BND_BrepFace : public BND_SurfaceProxy
//int SurfaceIndex
//Collections.BrepLoopList Loops
//BrepLoop OuterLoop
//Brep CreateExtrusion(Curve pathCurve, bool cap)
class BND_Brep* CreateExtrusion(const class BND_Curve* pathCurve, bool cap) const;
//bool ShrinkFace(ShrinkDisableSide disableSide)
//override bool SetDomain(int direction, Interval domain)
class BND_Brep* DuplicateFace(bool duplicateMeshes);
Expand Down
12 changes: 6 additions & 6 deletions src/dotnet/opennurbs/opennurbs_brep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3090,20 +3090,20 @@ public Curve[] DuplicateEdgeCurves(bool nakedOnly)
}

/// <summary>
/// Duplicate naked edges of this Brep
/// Duplicate naked edges of this Brep.
/// </summary>
/// <param name="outer"></param>
/// <param name="inner"></param>
/// <returns></returns>
/// <param name="nakedOuter">Return naked edges that are part of an outer loop.</param>
/// <param name="nakedInner">Return naked edges that are part of an inner loop.</param>
/// <returns>Array of edge curves on success.</returns>
/// <since>5.7</since>
[ConstOperation]
public Curve[] DuplicateNakedEdgeCurves(bool outer, bool inner)
public Curve[] DuplicateNakedEdgeCurves(bool nakedOuter, bool nakedInner)
{
IntPtr const_ptr_this = ConstPointer();
using (var output = new SimpleArrayCurvePointer())
{
IntPtr output_curves_ptr = output.NonConstPointer();
UnsafeNativeMethods.ON_Brep_DuplicateEdgeCurves(const_ptr_this, output_curves_ptr, true, outer, inner);
UnsafeNativeMethods.ON_Brep_DuplicateEdgeCurves(const_ptr_this, output_curves_ptr, true, nakedOuter, nakedInner);
return output.ToNonConstArray();
}
}
Expand Down
52 changes: 52 additions & 0 deletions src/dotnet/opennurbs/opennurbs_hatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,58 @@ internal override GeometryBase DuplicateShallowHelper()
return new Hatch(IntPtr.Zero, null);
}

/// <summary>
/// Create a hatch from a planar face of a Brep
/// </summary>
/// <param name="brep"></param>
/// <param name="brepFaceIndex"></param>
/// <param name="hatchPatternIndex"></param>
/// <param name="rotationRadians"></param>
/// <param name="scale"></param>
/// <param name="basePoint"></param>
/// <returns></returns>
public static Hatch CreateFromBrep(Brep brep, int brepFaceIndex, int hatchPatternIndex, double rotationRadians, double scale, Point3d basePoint)
{
if (brep == null) throw new ArgumentNullException("brep");
IntPtr constPtrBrep = brep.ConstPointer();
IntPtr ptrHatch = UnsafeNativeMethods.ON_Hatch_HatchFromBrep(constPtrBrep, brepFaceIndex, hatchPatternIndex, rotationRadians, scale, basePoint);
GC.KeepAlive(brep);
return CreateGeometryHelper(ptrHatch, null) as Hatch;
}

/// <summary>
/// Create a hatch with a given set of outer and inner loops
/// </summary>
/// <param name="hatchPlane"></param>
/// <param name="outerLoop">2d closed curve representing outer boundary of hatch</param>
/// <param name="innerLoops">2d closed curves for inner boundaries</param>
/// <param name="hatchPatternIndex"></param>
/// <param name="rotationRadians"></param>
/// <param name="scale"></param>
/// <returns></returns>
public static Hatch Create(Plane hatchPlane, Curve outerLoop, IEnumerable<Curve> innerLoops, int hatchPatternIndex, double rotationRadians, double scale)
{
if (outerLoop == null) throw new ArgumentNullException("outerLoop");

IntPtr constPtrOuterloop = outerLoop.ConstPointer();
IntPtr ptrInnerLoops = System.IntPtr.Zero;
Runtime.InteropWrappers.SimpleArrayCurvePointer innerSimpleArray = null;
if (innerLoops != null)
{
innerSimpleArray = new Runtime.InteropWrappers.SimpleArrayCurvePointer(innerLoops);
ptrInnerLoops = innerSimpleArray.ConstPointer();
}

IntPtr ptrHatch = UnsafeNativeMethods.ON_Hatch_CreateFromLoops(hatchPlane, constPtrOuterloop, ptrInnerLoops, hatchPatternIndex, rotationRadians, scale);

if (innerSimpleArray != null)
innerSimpleArray.Dispose();
GC.KeepAlive(outerLoop);
GC.KeepAlive(innerLoops);

return CreateGeometryHelper(ptrHatch, null) as Hatch;
}

#if RHINO_SDK
/// <summary>
/// Constructs an array of <see cref="Hatch">hatches</see> from a set of curves.
Expand Down
28 changes: 28 additions & 0 deletions src/librhino3dm_native/on_hatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ RH_C_FUNCTION void ON_HatchPattern_SetFillType(ON_HatchPattern* pHatchPattern, i
}
}

RH_C_FUNCTION ON_Hatch* ON_Hatch_HatchFromBrep(const ON_Brep* constPtrBrep, int faceIndex, int patternIndex, double rotation, double scale, ON_3DPOINT_STRUCT basePt)
{
const ON_3dPoint* point = (const ON_3dPoint*)&basePt;
ON_Hatch* rc = ON_Hatch::HatchFromBrep(nullptr, constPtrBrep, faceIndex, patternIndex, rotation, scale, *point);
return rc;
}

RH_C_FUNCTION ON_Hatch* ON_Hatch_CreateFromLoops(ON_PLANE_STRUCT ps, const ON_Curve* outerLoop, const ON_SimpleArray<const ON_Curve*>* innerLoops, int patternIndex, double rotation, double scale)
{
if (nullptr == outerLoop)
return nullptr;
ON_Plane plane = FromPlaneStruct(ps);

ON_Hatch* rc = new ON_Hatch();
ON_SimpleArray<const ON_Curve*> loops;
loops.Append(outerLoop);
if (innerLoops)
{
loops.Append(innerLoops->Count(), innerLoops->Array());
}
if (!rc->Create(plane, loops, patternIndex, rotation, scale))
{
delete rc;
rc = nullptr;
}
return rc;
}

RH_C_FUNCTION int ON_Hatch_PatternIndex(const ON_Hatch* pConstHatch)
{
int rc = -1;
Expand Down

0 comments on commit 1fa188c

Please sign in to comment.