Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 8
fraguada committed Jan 24, 2025
2 parents 731dee3 + c9b3ca2 commit 13e8fa8
Showing 360 changed files with 3,869 additions and 3,760 deletions.
4 changes: 2 additions & 2 deletions cpp/SampleCommands/SampleCommandsPlugIn.cpp
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ RHINO_PLUG_IN_ICON_RESOURCE_ID(IDI_ICON1);

// Rhino plug-in developer declarations
RHINO_PLUG_IN_DEVELOPER_ORGANIZATION(L"Robert McNeel & Associates");
RHINO_PLUG_IN_DEVELOPER_ADDRESS(L"3670 Woodland Park Avenue North\r\nSeattle WA 98103");
RHINO_PLUG_IN_DEVELOPER_ADDRESS(L"146 North Canal Street, Suite 320\r\nSeattle WA 98103");
RHINO_PLUG_IN_DEVELOPER_COUNTRY(L"United States");
RHINO_PLUG_IN_DEVELOPER_PHONE(L"206-545-6877");
RHINO_PLUG_IN_DEVELOPER_FAX(L"206-545-7321");
@@ -273,4 +273,4 @@ HCURSOR CSampleCommandsPlugIn::SampleCursor()
if (0 == m_hCursor)
m_hCursor = (HCURSOR)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_SAMPLE_CURSOR), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
return m_hCursor;
}
}
90 changes: 90 additions & 0 deletions cpp/SampleCommands/SampleFunctions.cpp
Original file line number Diff line number Diff line change
@@ -388,3 +388,93 @@ bool RhinoHasFocus()
}
return false;
}

static HWND GetRealParent(HWND hWnd)
{
// To obtain a window's owner window, instead of using GetParent,
// use GetWindow with the GW_OWNER flag.
HWND hWndOwner = ::GetWindow(hWnd, GW_OWNER);
if (NULL != hWndOwner)
return hWndOwner;

// Obtain the parent window and not the owner
return GetAncestor(hWnd, GA_PARENT);
}

/// <summary>
/// Returns true if the Rhino main window has been re-parented to some other application window.
/// Returns true if the Rhino main window parent is the Windows Desktop.
/// </summary>
bool IsRhinoReparented()
{
HWND hParent = GetRealParent(RhinoApp().MainWnd());
HWND hDesktop = ::GetDesktopWindow();
return hParent != hDesktop;
}

/// <summary>
/// Returns module handle where "this" function is running in: EXE or DLL.
/// </summary>
HMODULE FancyGetModuleHandle()
{
HMODULE hModule = NULL;
::GetModuleHandleEx(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCTSTR)FancyGetModuleHandle,
&hModule
);
return hModule;
}


/// <summary>
/// Begin a CRhinoDoc undo record.
/// </summary>
/// <param name="doc">The active document.</param>
/// <param name="pszDescription">The undo description.</param>
CRhinoDocUndoRecordHelper::CRhinoDocUndoRecordHelper(CRhinoDoc& doc, const wchar_t* pszDescription)
{
m_docRuntimeSerialNumber = doc.RuntimeSerialNumber();
m_undoRecordSerialNumber = doc.BeginUndoRecord(pszDescription);
}

/// <summary>
/// Begin a CRhinoDoc undo record.
/// </summary>
/// <param name="docRuntimeSerialNumber">The active document's runtime serial number.</param>
/// <param name="pszDescription">The undo description.</param>
CRhinoDocUndoRecordHelper::CRhinoDocUndoRecordHelper(unsigned int docRuntimeSerialNumber, const wchar_t* pszDescription)
{
CRhinoDoc* pDoc = CRhinoDoc::FromRuntimeSerialNumber(docRuntimeSerialNumber);
if (pDoc)
{
m_docRuntimeSerialNumber = pDoc->RuntimeSerialNumber();
m_undoRecordSerialNumber = pDoc->BeginUndoRecord(pszDescription);
}
}

/// <summary>
/// Class destructor, ends the undo record.
/// </summary>
CRhinoDocUndoRecordHelper::~CRhinoDocUndoRecordHelper()
{
EndUndoRecord();
}

/// <summary>
/// Ends the undo record.
/// </summary>
/// <returns>true if the undo record was ended.</returns>
bool CRhinoDocUndoRecordHelper::EndUndoRecord()
{
bool rc = (m_docRuntimeSerialNumber > 0 && m_undoRecordSerialNumber > 0);
if (rc)
{
CRhinoDoc* pDoc = CRhinoDoc::FromRuntimeSerialNumber(m_docRuntimeSerialNumber);
if (pDoc)
rc = pDoc->EndUndoRecord(m_undoRecordSerialNumber);
m_docRuntimeSerialNumber = m_undoRecordSerialNumber = 0;
}
return rc;
}

52 changes: 52 additions & 0 deletions cpp/SampleCommands/SampleFunctions.h
Original file line number Diff line number Diff line change
@@ -156,3 +156,55 @@ bool IsRhinoRunningAsExe();
/// Returns true if Rhino has input focus.
/// </summary>
bool RhinoHasFocus();

/// <summary>
/// Returns true if the Rhino main window has been re-parented to some other application window.
/// Returns true if the Rhino main window parent is the Windows Desktop.
/// </summary>
bool IsRhinoReparented();

/// <summary>
/// Returns module handle where "this" function is running in: EXE or DLL.
/// </summary>
HMODULE FancyGetModuleHandle();


/// <summary>
/// CRhinoDoc::BeginUndoRecord and CRhinoDoc::EndUndoRecord helper.
/// Undo record will be ended when classes goes out of scope.
/// Useful in modeless user interface code that modifies document objects.
/// Not useful Rhino command, as Rhino's command handler tracks undo records.
/// </summary>
class CRhinoDocUndoRecordHelper
{
public:
/// <summary>
/// Begin a CRhinoDoc undo record.
/// </summary>
/// <param name="doc">The active document.</param>
/// <param name="pszDescription">The undo description.</param>
CRhinoDocUndoRecordHelper(CRhinoDoc& doc, const wchar_t* pszDescription);

/// <summary>
/// Begin a CRhinoDoc undo record.
/// </summary>
/// <param name="docRuntimeSerialNumber">The active document's runtime serial number.</param>
/// <param name="pszDescription">The undo description.</param>
CRhinoDocUndoRecordHelper(unsigned int docRuntimeSerialNumber, const wchar_t* pszDescription);

/// <summary>
/// Class destructor, ends the undo record.
/// </summary>
~CRhinoDocUndoRecordHelper();

/// <summary>
/// Ends the undo record.
/// </summary>
/// <returns>true if the undo record was ended.</returns>
/// <remarks>The class destructor calls this method.</returns>
bool EndUndoRecord();

private:
unsigned int m_docRuntimeSerialNumber = 0;
unsigned int m_undoRecordSerialNumber = 0;
};
2 changes: 1 addition & 1 deletion cpp/SampleCommands/cmdSampleAddNurbsCircle.cpp
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ CRhinoCommand::result CCommandSampleAddNurbsCircle::RunCommand(const CRhinoComma
int degree = 2;
int order = degree + 1;
int cv_count = 9;
int knot_count = cv_count + degree - 1;
//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);
70 changes: 70 additions & 0 deletions rhino.inside/cpp/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "pch.h"
#include "RhinoCore.h"

int wmain(int argc, wchar_t** argv)
{
// Load Rhino
CRhinoCore rhino_core(argc, argv);

// Geet the Rhino version number, etc.
int ver = RhinoApp().ExeVersion();
int sr = RhinoApp().ExeServiceRelease();
ON_wString date;
RhinoApp().GetBuildDate(date);
std::wstring str0(static_cast<const wchar_t*>(date));
std::wcout << "Rhino " << ver << "." << sr << " (" << str0 << ") loaded." << std::endl;

// Create a NURBS curve by interpolating points
ON_3dPointArray points(16);
points.Append(ON_3dPoint(0.0, 3.12494, 0.0));
points.Append(ON_3dPoint(7.01306, 3.31419, 0.0));
points.Append(ON_3dPoint(8.01888, 3.34416, 0.0));
points.Append(ON_3dPoint(9.02578, 3.37375, 0.0));
points.Append(ON_3dPoint(10.0338, 3.40260, 0.0));
points.Append(ON_3dPoint(11.0430, 3.43034, 0.0));
points.Append(ON_3dPoint(12.0533, 3.45659, 0.0));
points.Append(ON_3dPoint(13.0648, 3.48098, 0.0));
points.Append(ON_3dPoint(14.0776, 3.50313, 0.0));
points.Append(ON_3dPoint(15.0916, 3.52267, 0.0));
points.Append(ON_3dPoint(16.1068, 3.53923, 0.0));
points.Append(ON_3dPoint(17.1233, 3.55249, 0.0));
points.Append(ON_3dPoint(18.1410, 3.56222, 0.0));
points.Append(ON_3dPoint(19.1587, 3.56829, 0.0));
points.Append(ON_3dPoint(20.1758, 3.57091, 0.0));
points.Append(ON_3dPoint(30.3156, 3.45748, 0.0));

const int knot_style = 0; // uniform
ON_NurbsCurve* pCurve = RhinoInterpCurve(3, points, nullptr, nullptr, knot_style, nullptr);
if (pCurve)
{
double length = ON_UNSET_VALUE;
if (pCurve->GetLength(&length))
std::cout << "ON_NurbsCurve with " << length << " length created" << std::endl;

CRhinoCreateDocumentOptions options;
options.SetCreateHeadless(true);
int doc_runtime_serial_number = CRhinoDoc::CreateDocument(nullptr, &options);

CRhinoDoc* pDoc = CRhinoDoc::FromRuntimeSerialNumber(doc_runtime_serial_number);
pDoc->AddCurveObject(*pCurve, nullptr, nullptr, 0);
delete pCurve; // Don't leak

ON_wString path;
CRhinoFileUtilities::GetMyDocumentsFolder(path);
path += L"\\RhinoInsideConsoleCxx.3dm";

FILE* pFile = ON::OpenFile(static_cast<const wchar_t*>(path), L"wb");
if (nullptr != pFile)
{
ON_BinaryFile archive(ON::archive_mode::write3dm, pFile);
CRhinoFileWriteOptions fwo;
pDoc->Write3dmFile(archive, fwo);
ON::CloseFile(pFile);

std::wstring str1(static_cast<const wchar_t*>(path));
std::wcout << "Curve saved to " << str1 << std::endl;
}
}

system("pause");
}
28 changes: 28 additions & 0 deletions rhino.inside/cpp/RhinoCore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "pch.h"
#include "RhinoCore.h"

// https://learn.microsoft.com/en-us/cpp/build/reference/understanding-the-helper-function
static FARPROC WINAPI delayHookRhinoLibrary(unsigned dliNotify, PDelayLoadInfo pdli)
{
static const wchar_t* RhinoLibraryPath = L"C:\\Program Files\\Rhino 8\\System\\RhinoLibrary.dll";
if (dliNotify == dliNotePreLoadLibrary && pdli && _stricmp(pdli->szDll, "RhinoLibrary.dll") == 0)
return (FARPROC)LoadLibraryEx(RhinoLibraryPath, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
return nullptr;
}

static const PfnDliHook __pfnDliNotifyHook2 = delayHookRhinoLibrary;

// Exported from RhinoCore.dll
extern "C" HRESULT StartupInProcess(int argc, wchar_t** argv, const STARTUPINFO* pStartUpInfo, HWND hHostWnd);
extern "C" HRESULT ShutdownInProcess();

CRhinoCore::CRhinoCore(int argc, wchar_t** argv)
{
StartupInProcess(argc, argv, nullptr, HWND_DESKTOP);
}

CRhinoCore::~CRhinoCore()
{
ShutdownInProcess();
}

11 changes: 11 additions & 0 deletions rhino.inside/cpp/RhinoCore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

/// <summary>
/// RhinoCore.dll loader
/// </summary>
class CRhinoCore
{
public:
CRhinoCore(int argc, wchar_t** argv);
~CRhinoCore();
};
Loading

0 comments on commit 13e8fa8

Please sign in to comment.