Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 8
  • Loading branch information
fraguada committed Mar 7, 2024
2 parents c4f52f2 + 1f67fa4 commit 5d0fc7d
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 57 deletions.
1 change: 1 addition & 0 deletions cpp/SampleCommands/SampleCommands.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ClCompile Include="cmdSampleDrawZebraPreview.cpp" />
<ClCompile Include="cmdSampleDump3dmMaterialTextures.cpp" />
<ClCompile Include="cmdSampleDupEdge.cpp" />
<ClCompile Include="cmdSampleEnableGrips.cpp" />
<ClCompile Include="cmdSampleFrameRails.cpp" />
<ClCompile Include="cmdSampleGetMultipleSpecial.cpp" />
<ClCompile Include="cmdSampleGrid.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions cpp/SampleCommands/SampleCommands.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@
<ClCompile Include="cmdSampleDeleteFaces.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleEnableGrips.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SampleCommandsApp.h">
Expand Down
98 changes: 98 additions & 0 deletions cpp/SampleCommands/cmdSampleEnableGrips.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "stdafx.h"

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN SampleEnableGrips command
//

#pragma region SampleEnableGrips command

class CCommandSampleEnableGrips : public CRhinoCommand
{
public:
CCommandSampleEnableGrips();
UUID CommandUUID() override
{
// {B8A7E946-AE2C-4AFE-A24A-3E32186B206E}
static const GUID SampleEnableGripsCommand_UUID =
{ 0xB8A7E946, 0xAE2C, 0x4AFE, { 0xA2, 0x4A, 0x3E, 0x32, 0x18, 0x6B, 0x20, 0x6E } };
return SampleEnableGripsCommand_UUID;
}
const wchar_t* EnglishCommandName() override { return L"SampleEnableGrips"; }
CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};

// The one and only CCommandSampleEnableGrips object
static class CCommandSampleEnableGrips theSampleEnableGripsCommand;

CCommandSampleEnableGrips::CCommandSampleEnableGrips()
{
EnableUndo(false);
}

CRhinoCommand::result CCommandSampleEnableGrips::RunCommand(const CRhinoCommandContext& context)
{
CRhinoGetObject go;
go.SetCommandPrompt(L"Select objects for grip display");
go.EnableSubObjectSelect(false);
go.EnableGroupSelect();
go.GetObjects(1, 0);
if (go.CommandResult() != CRhinoCommand::success)
return go.CommandResult();

const int object_count = go.ObjectCount();
for (int i = 0; i < object_count; i++)
{
CRhinoObject* pObject = const_cast<CRhinoObject*>(go.Object(i).Object());
if (pObject)
{
pObject->EnableGrips(true);
if (nullptr == pObject->m_grips)
{
const CRhinoBrepObject* pBrepObject = CRhinoBrepObject::Cast(pObject);
if (pBrepObject)
{
const ON_Brep* pBrep = pBrepObject->Brep();
if (pBrep && pBrep->m_F.Count() > 1)
RhinoApp().Print(L"Cannot turn on grips for polysurfaces.\n");
}
else
{
const CRhinoMeshObject* pMeshObject = CRhinoMeshObject::Cast(pObject);
if (pMeshObject)
{
const ON_Mesh* pMesh = pMeshObject->Mesh();
if (pMesh && pMesh->m_V.Count() > 0)
RhinoApp().Print(L"Cannot turn on grips for meshes that have more than one million vertices.\n");
}
else
{
const CRhinoPointCloudObject* pPointCloudObject = CRhinoPointCloudObject::Cast(pObject);
if (pPointCloudObject)
{
if (pPointCloudObject->PointCloud().PointCount() > 0)
RhinoApp().Print(L"Cannot turn on grips for point clouds that have more than one million vertices.\n");
}
}
}
}
else
{
pObject->Select(false);
}
}
}

context.m_doc.Redraw();

return CRhinoCommand::success;
}

#pragma endregion

//
// END SampleEnableGrips command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
22 changes: 10 additions & 12 deletions cpp/SampleCommands/cmdSampleMoveGrips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ static class CCommandSampleMoveGrips theSampleMoveGripsCommand;

CRhinoCommand::result CCommandSampleMoveGrips::RunCommand(const CRhinoCommandContext& context)
{
CRhinoDoc* doc = context.Document();
if (nullptr == doc)
return CRhinoCommand::failure;

// Select grips to move
CRhinoGetObject go;
go.SetCommandPrompt(L"Select grips to move");
go.SetGeometryFilter(CRhinoGetObject::grip_object);
go.GetObjects(1, 0);
if (go.CommandResult() != success)
return go.CommandResult();

// Fancy class for managing selected objects and grips
CRhinoXformObjectList list;
if (list.AddObjects(go, true) < 1)
return CRhinoCommand::failure;

// Point to move from
CRhinoGetPoint gp;
gp.SetCommandPrompt(L"Point to move from");
gp.GetPoint();
Expand All @@ -52,6 +51,7 @@ CRhinoCommand::result CCommandSampleMoveGrips::RunCommand(const CRhinoCommandCon

ON_3dPoint from = gp.Point();

// Point to move to
gp.SetCommandPrompt(L"Point to move to");
gp.SetBasePoint(from);
gp.DrawLineFromPoint(from, TRUE);
Expand All @@ -61,27 +61,25 @@ CRhinoCommand::result CCommandSampleMoveGrips::RunCommand(const CRhinoCommandCon

ON_3dPoint to = gp.Point();

// Create a translation transformation
ON_Xform xform = ON_Xform::TranslationTransformation(to - from);
if (xform.IsValid())
{
// Transform the grip objects
int i;
for (i = 0; i < list.m_grips.Count(); i++)
for (int i = 0; i < list.m_grips.Count(); i++)
{
CRhinoGripObject* grip = list.m_grips[i];
if (grip)
grip->MoveGrip(xform);
}

// Replace the old owner with a new one
for (i = 0; i < list.m_grip_owners.Count(); i++)
{
RhinoUpdateGripOwner(list.m_grip_owners[i], false, 0);
}

doc->Redraw();
for (int i = 0; i < list.m_grip_owners.Count(); i++)
RhinoUpdateGripOwner(list.m_grip_owners[i], false, nullptr);
}

context.m_doc.Redraw();

return CRhinoCommand::success;
}

Expand Down
108 changes: 63 additions & 45 deletions cpp/SampleCommands/cmdSamplePipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class CCommandSamplePipe : public CRhinoCommand
{
public:
CCommandSamplePipe() { m_radius = 1.0; }
CCommandSamplePipe() = default;
~CCommandSamplePipe() = default;
UUID CommandUUID() override
{
Expand All @@ -24,18 +24,14 @@ class CCommandSamplePipe : public CRhinoCommand
CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override ;

private:
double m_radius;
double m_radius = 1.0;
};

// The one and only CCommandSamplePipe object
static class CCommandSamplePipe theSamplePipeCommand;

CRhinoCommand::result CCommandSamplePipe::RunCommand(const CRhinoCommandContext& context)
{
CRhinoDoc* doc = context.Document();
if (nullptr == doc)
return CRhinoCommand::failure;

CRhinoGetObject go;
go.SetCommandPrompt(L"Select path curve");
go.SetGeometryFilter(CRhinoGetObject::curve_object);
Expand All @@ -45,7 +41,7 @@ CRhinoCommand::result CCommandSamplePipe::RunCommand(const CRhinoCommandContext&
return go.CommandResult();

const ON_Curve* curve = go.Object(0).Curve();
if (0 == curve)
if (nullptr == curve)
return CRhinoCommand::failure;

CRhinoGetNumber gn;
Expand All @@ -58,70 +54,92 @@ CRhinoCommand::result CCommandSamplePipe::RunCommand(const CRhinoCommandContext&

m_radius = fabs(gn.Number());

ON_Interval dom = curve->Domain();

ON_SimpleArray<double> curve_params;
curve_params.Append(dom.NormalizedParameterAt(dom.Min()));
curve_params.Append(dom.NormalizedParameterAt(dom.Max()));
ON_SimpleArray<double> curve_params(2);
ON_Interval domain = curve->Domain();
curve_params.Append(domain.NormalizedParameterAt(domain.Min()));
curve_params.Append(domain.NormalizedParameterAt(domain.Max()));

ON_SimpleArray<double> radii;
radii.Append(m_radius); // radius at dom.Min()
radii.Append(m_radius); // radius at dom.Max()
ON_SimpleArray<double> radii(2);;
radii.Append(m_radius); // radius at domain.Min()
radii.Append(m_radius); // radius at domain.Max()

int blend_type = 0; // local blend
int cap_mode = 1; // flat cap
bool fit_rail = false; // don't fit
double abstol = context.m_doc.AbsoluteTolerance();
double angtol = context.m_doc.AngleToleranceRadians();
int blend_type = 0; // local blend
int cap_mode = 1; // flat cap
bool fit_rail = false; // don't fit
bool bUseExtrusions = true; // Create extrusion objects when possible

ON_SimpleArray<ON_Object*> results;
if (RhinoPipe(*curve, curve_params, radii, results, blend_type, cap_mode, fit_rail))
if (RhinoPipe(*curve, curve_params, radii, results, abstol, angtol, blend_type, cap_mode, fit_rail))
{
for (int i = 0; i < results.Count(); i++)
{
if (0 != results[i])
if (nullptr == results[i])
continue;

if (results[i]->ObjectType() == ON::extrusion_object)
{
if (results[i]->ObjectType() == ON::extrusion_object)
ON_Extrusion* pExtrusion = ON_Extrusion::Cast(results[i]);
if (pExtrusion)
{
if (bUseExtrusions)
{
CRhinoExtrusionObject* object = new CRhinoExtrusionObject();
object->SetExtrusion(ON_Extrusion::Cast(results[i]));
results[i] = 0; // object now owns the memory
if (!doc->AddObject(object))
delete object; // Don't leak...
CRhinoExtrusionObject* pExtrusionObject = new CRhinoExtrusionObject();
pExtrusionObject->SetExtrusion(pExtrusion);

results[i] = nullptr; // pExtrusionObject now owns this memory

if (!context.m_doc.AddObject(pExtrusionObject))
delete pExtrusionObject; // Don't leak...
}
else
{
ON_Extrusion* extrusion = ON_Extrusion::Cast(results[i]);
if (extrusion)
ON_Brep* pBrep = pExtrusion->BrepForm(nullptr, true);
if (pBrep)
{
ON_Brep* brep = extrusion->BrepForm(0, true);
if (brep)
{
CRhinoBrepObject* object = new CRhinoBrepObject();
object->SetBrep(brep);
if (!doc->AddObject(object))
delete object; // Don't leak...
}
delete results[i]; // Extrusion no longer needed...
results[i] = nullptr;

CRhinoBrepObject* pBrepObject = new CRhinoBrepObject();
pBrepObject->SetBrep(pBrep);

pBrep = nullptr; // pBrepObject now owns this memory

if (!context.m_doc.AddObject(pBrepObject))
delete pBrepObject; // Don't leak...
}
delete results[i]; // Don't leak...
results[i] = 0;
}
}
else
}
else if (results[i]->ObjectType() == ON::brep_object)
{
ON_Brep* pBrep = ON_Brep::Cast(results[i]);
if (pBrep)
{
CRhinoBrepObject* object = new CRhinoBrepObject();
object->SetBrep(ON_Brep::Cast(results[i]));
results[i] = 0; // object now owns the memory
if (!doc->AddObject(object))
delete object; // Don't leak...
CRhinoBrepObject* pBrepObject = new CRhinoBrepObject();
pBrepObject->SetBrep(pBrep);

results[i] = nullptr; // pBrepObject now owns this memory

if (!context.m_doc.AddObject(pBrepObject))
delete pBrepObject; // Don't leak...
}
}
}

doc->Redraw();
for (int i = 0; i < results.Count(); i++)
{
if (results[i])
{
delete results[i]; // Don't leak...
results[i] = nullptr;
}
}
}

context.m_doc.Redraw();

return CRhinoCommand::success;
}

Expand Down

0 comments on commit 5d0fc7d

Please sign in to comment.