Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 8
  • Loading branch information
fraguada committed Oct 10, 2024
2 parents 6ced73b + cbb3c8d commit c9e4740
Show file tree
Hide file tree
Showing 54 changed files with 2,229 additions and 1,528 deletions.
7 changes: 6 additions & 1 deletion cpp/SampleCommands/SampleCommands.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="cmdSampleBlendCurve.cpp" />
<ClCompile Include="cmdSampleChangeDimStyle.cpp" />
<ClCompile Include="cmdSampleClosedCurveContainment.cpp" />
<ClCompile Include="cmdSampleCloseTabbedPanels.cpp" />
<ClCompile Include="cmdSampleComputeVertexColors.cpp" />
<ClCompile Include="cmdSampleCopyInPlace.cpp" />
<ClCompile Include="cmdSampleCPlaneWorld.cpp" />
<ClCompile Include="cmdSampleCsCachedTextureCoordinates.cpp" />
<ClCompile Include="cmdSampleDeleteFaces.cpp" />
<ClCompile Include="cmdSampleDrawSubD.cpp" />
<ClCompile Include="cmdSampleDrawSubDWires.cpp" />
<ClCompile Include="cmdSampleDrawZebraPreview.cpp" />
<ClCompile Include="cmdSampleDump3dmMaterialTextures.cpp" />
<ClCompile Include="cmdSampleDumpMeshCachedTextureCoordinates.cpp" />
Expand All @@ -27,6 +29,7 @@
<ClCompile Include="cmdSampleFrameRails.cpp" />
<ClCompile Include="cmdSampleGetMultipleSpecial.cpp" />
<ClCompile Include="cmdSampleGrid.cpp" />
<ClCompile Include="cmdSampleGroupUserData.cpp" />
<ClCompile Include="cmdSampleHidePoints.cpp" />
<ClCompile Include="cmdSampleMappingUvwTransform.cpp" />
<ClCompile Include="cmdSampleMergeSrf.cpp" />
Expand Down Expand Up @@ -216,6 +219,7 @@
<ClCompile Include="cmdSampleReadInstancesFromFile.cpp" />
<ClCompile Include="cmdSampleReduceMesh.cpp" />
<ClCompile Include="cmdSampleRemoveMeshVertices.cpp" />
<ClCompile Include="cmdSampleRenderSettings.cpp" />
<ClCompile Include="cmdSampleResetLayers.cpp" />
<ClCompile Include="cmdSampleRevolve.cpp" />
<ClCompile Include="cmdSampleRotate.cpp" />
Expand Down Expand Up @@ -304,6 +308,7 @@
<ClInclude Include="SampleCommandsPlugIn.h" />
<ClInclude Include="SampleDocumentUserData.h" />
<ClInclude Include="SampleDrawCallback.h" />
<ClInclude Include="SampleFunctions.h" />
<ClInclude Include="SampleObjectUserData.h" />
<ClInclude Include="SampleRectangleObject.h" />
<ClInclude Include="stdafx.h" />
Expand Down
17 changes: 16 additions & 1 deletion cpp/SampleCommands/SampleCommands.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,19 @@
<ClCompile Include="cmdSampleDumpMeshCachedTextureCoordinates.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleCsCachedTextureCoordinates.cpp">
<ClCompile Include="cmdSampleDrawSubDWires.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleDrawSubD.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleGroupUserData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleBlendCurve.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleRenderSettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down Expand Up @@ -893,6 +905,9 @@
<ClInclude Include="SampleDocumentUserData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SampleFunctions.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="SampleCommands.def">
Expand Down
84 changes: 33 additions & 51 deletions cpp/SampleCommands/SampleFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ double ON_CurveTorsion(const ON_Curve& curve, double t)
return tau;
}

/// <summary>
/// Create a blend curve with G0 continuity between two existing curves.
/// </summary>
/// <param name="crvA">Curve to blend from (blending will occur at curve end point).</param>
/// <param name="crvB">Curve to blend to (blending will occur at curve start point).</param>
/// <returns>An ON_Curve representing the blend between A and B.</returns>
/// <remarks>
/// CRITICAL: Memory for the resulting curve is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Curve* ON_BlendG0Curve(
const ON_Curve* crvA,
const ON_Curve* crvB
)
{
ON_Curve* rc = nullptr;
if (crvA && !crvA->IsClosed() && crvB && !crvB->IsClosed())
{
double ta = crvA->Domain().Max();
double tb = crvB->Domain().Min();

ON_3dPoint A = crvA->PointAt(ta);
ON_3dPoint B = crvB->PointAt(tb);

rc = new ON_LineCurve(A, B);
}
return rc;
}

/// <summary>
/// Create a blend curve with G1 continuity between two existing curves.
/// </summary>
Expand All @@ -46,7 +75,7 @@ ON_Curve* ON_BlendG1Curve(
)
{
ON_Curve* rc = nullptr;
if (crvA && crvB)
if (crvA && !crvA->IsClosed() && crvB && !crvB->IsClosed())
{
double ta = crvA->Domain().Max();
double tb = crvB->Domain().Min();
Expand Down Expand Up @@ -101,7 +130,7 @@ ON_Curve* ON_BlendG2Curve(
)
{
ON_Curve* rc = nullptr;
if (crvA && crvB)
if (crvA && !crvA->IsClosed() && crvB && !crvB->IsClosed())
{
double ta = crvA->Domain().Max();
double tb = crvB->Domain().Min();
Expand Down Expand Up @@ -259,53 +288,6 @@ HBITMAP ON_ReadBitmapPreviewImage(const wchar_t* pszFilePath)
return hBitmap;
}

/// <summary>
/// CRhinoHatchPatternTable helpers for system hatch patterns
/// </summary>
class CRhinoHatchTableHelper
{
public:
/// <summary>
/// Returns the Solid hatch pattern
/// </summary>
static const CRhinoHatchPattern* Solid(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch1 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch1(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch2 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch2(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch3 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch3(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the HatchDash hatch pattern
/// </summary>
static const CRhinoHatchPattern* HatchDash(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Grid hatch pattern
/// </summary>
static const CRhinoHatchPattern* Grid(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Grid60 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Grid60(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Plus hatch pattern
/// </summary>
static const CRhinoHatchPattern* Plus(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Squares hatch pattern
/// </summary>
static const CRhinoHatchPattern* Squares(CRhinoHatchPatternTable& table);

private:
static const CRhinoHatchPattern* FindOrCreateHatchPattern(CRhinoHatchPatternTable& table, const ON_HatchPattern& hatch_pattern);
};

const CRhinoHatchPattern* CRhinoHatchTableHelper::Solid(CRhinoHatchPatternTable& table)
{
return FindOrCreateHatchPattern(table, CRhinoHatchPattern::Solid);
Expand Down Expand Up @@ -367,7 +349,7 @@ const CRhinoHatchPattern* CRhinoHatchTableHelper::FindOrCreateHatchPattern(CRhin
/// Returns true if Rhino was started as a standalone executable.
/// Returns false if Rhino was started by some other application or process.
/// </summary>
static bool IsRhinoRunningAsExe()
bool IsRhinoRunningAsExe()
{
bool rc = false;
DWORD dwProcessId = ::GetCurrentProcessId();
Expand All @@ -390,7 +372,7 @@ static bool IsRhinoRunningAsExe()
/// <summary>
/// Returns true if Rhino has input focus.
/// </summary>
static bool RhinoHasFocus()
bool RhinoHasFocus()
{
// Retrieves a handle to the foreground window
HWND hWnd = ::GetForegroundWindow();
Expand Down
158 changes: 158 additions & 0 deletions cpp/SampleCommands/SampleFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#pragma once

/// <summary>
/// Evaluate torsion of a curve at a parmeter.
/// </summary>
/// <param name="curve">Curve to evaluate.</param>
/// <param name="t">Evaluation parameter.</param>
/// <returns>The torsion if successful.</returns>
/// <remarks>See Barrett O'Neill, Elementary Differential Geometry, page 69.</remarks>
double ON_CurveTorsion(const ON_Curve& curve, double t);

/// <summary>
/// Create a blend curve with G0 continuity between two existing curves.
/// </summary>
/// <param name="crvA">Curve to blend from (blending will occur at curve end point).</param>
/// <param name="crvB">Curve to blend to (blending will occur at curve start point).</param>
/// <returns>An ON_Curve representing the blend between A and B.</returns>
/// <remarks>
/// CRITICAL: Memory for the resulting curve is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Curve* ON_BlendG0Curve(
const ON_Curve* crvA,
const ON_Curve* crvB
);

/// <summary>
/// Create a blend curve with G1 continuity between two existing curves.
/// </summary>
/// <param name="crvA">Curve to blend from (blending will occur at curve end point).</param>
/// <param name="crvB">Curve to blend to (blending will occur at curve start point).</param>
/// <param name="bulgeA">Bulge factor at curveA end of blend. Values near 1.0 work best.</param>
/// <param name="bulgeB">Bulge factor at curveB end of blend. Values near 1.0 work best.</param>
/// <returns>An ON_Curve representing the blend between A and B.</returns>
/// <remarks>
/// CRITICAL: Memory for the resulting curve is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Curve* ON_BlendG1Curve(
const ON_Curve* crvA,
const ON_Curve* crvB,
double bulgeA,
double bulgeB
);

/// <summary>
/// Create a blend curve with G2 continuity between two existing curves.
/// </summary>
/// <param name="crvA">Curve to blend from (blending will occur at curve end point).</param>
/// <param name="crvB">Curve to blend to (blending will occur at curve start point).</param>
/// <param name="bulgeA">Bulge factor at curveA end of blend. Values near 1.0 work best.</param>
/// <param name="bulgeB">Bulge factor at curveB end of blend. Values near 1.0 work best.</param>
/// <returns>An ON_Curve representing the blend between A and B.</returns>
/// <remarks>
/// CRITICAL: Memory for the resulting curve is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Curve* ON_BlendG2Curve(
const ON_Curve* crvA,
const ON_Curve* crvB,
double bulgeA,
double bulgeB
);

/// <summary>
/// Get the BRep definition of a trimmed surface.
/// </summary>
/// <param name="srf">Surface that will be trimmed.</param>
/// <param name="crv2d">
/// Closed, 2d parameter space boundary curve that defines the
/// outer boundary of the trimmed surface.
/// </param>
/// <param name="tol">Tolerance for fitting 3d edge curves.</param>
/// <returns>
/// An ON_Brep representation of the trimmed surface with a single face.
/// </returns>
/// <remarks>
/// CRITICAL: Memory for the resulting BRep is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Brep* ON_BrepFromSurfaceAndBoundary(
const ON_Surface& srf,
const ON_Curve& crv2d,
double tol
);

/// <summary>
/// Returns the bitmap preview image from a 3dm file.
/// </summary>
/// <param name="pszFilePath">The full path to the 3dm file.</param>
/// <returns>An HBITMAP if successful, or nullptr if the 3dm file does not
/// contain a preview image or if there was an error reading the file.
/// </returns>
/// <remarks>
/// CRITICAL: Memory for the bitmap is allocated. It is the calling
/// functions responsibility to clean up the memory by calling the
/// Win32 DeleteObject() function.
/// </remarks>
HBITMAP ON_ReadBitmapPreviewImage(const wchar_t* pszFilePath);

/// <summary>
/// CRhinoHatchPatternTable helpers for system hatch patterns
/// </summary>
class CRhinoHatchTableHelper
{
public:
/// <summary>
/// Returns the Solid hatch pattern
/// </summary>
static const CRhinoHatchPattern* Solid(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch1 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch1(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch2 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch2(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch3 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch3(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the HatchDash hatch pattern
/// </summary>
static const CRhinoHatchPattern* HatchDash(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Grid hatch pattern
/// </summary>
static const CRhinoHatchPattern* Grid(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Grid60 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Grid60(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Plus hatch pattern
/// </summary>
static const CRhinoHatchPattern* Plus(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Squares hatch pattern
/// </summary>
static const CRhinoHatchPattern* Squares(CRhinoHatchPatternTable& table);

private:
static const CRhinoHatchPattern* FindOrCreateHatchPattern(CRhinoHatchPatternTable& table, const ON_HatchPattern& hatch_pattern);
};


/// <summary>
/// Returns true if Rhino was started as a standalone executable.
/// Returns false if Rhino was started by some other application or process.
/// </summary>
bool IsRhinoRunningAsExe();

/// <summary>
/// Returns true if Rhino has input focus.
/// </summary>
bool RhinoHasFocus();
13 changes: 11 additions & 2 deletions cpp/SampleCommands/cmdSampleAddNurbsCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ CRhinoCommand::result CCommandSampleAddNurbsCircle::RunCommand(const CRhinoComma
if (nullptr == doc)
return CRhinoCommand::failure;

// Specify dimension, degree and number of control points.
// The degree must be >= 1 and the number of control points
// must be >= (degree+1). The number of knots is always
// (number of control points + degree - 1).
int dimension = 3;
BOOL bIsRational = TRUE;
int order = 3; // order = degree + 1
bool bIsRational = true;
int degree = 2;
int order = degree + 1;
int cv_count = 9;
int knot_count = cv_count + degree - 1;

// Make a rational, degree 2 NURBS curve with 9 control points
ON_NurbsCurve nc(dimension, bIsRational, order, cv_count);
// Set the control points
nc.SetCV(0, ON_4dPoint(1.0, 0.0, 0.0, 1.0));
nc.SetCV(1, ON_4dPoint(0.707107, 0.707107, 0.0, 0.707107));
nc.SetCV(2, ON_4dPoint(0.0, 1.0, 0.0, 1.0));
Expand All @@ -48,6 +56,7 @@ CRhinoCommand::result CCommandSampleAddNurbsCircle::RunCommand(const CRhinoComma
nc.SetCV(6, ON_4dPoint(0.0, -1.0, 0.0, 1.0));
nc.SetCV(7, ON_4dPoint(0.707107, -0.707107, 0.0, 0.707107));
nc.SetCV(8, ON_4dPoint(1.0, 0.0, 0.0, 1.0));
// Set the 10 knots
nc.SetKnot(0, 0.0);
nc.SetKnot(1, 0.0);
nc.SetKnot(2, 0.5*ON_PI);
Expand Down
Loading

0 comments on commit c9e4740

Please sign in to comment.