#include "stdafx.h" //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// // // BEGIN TestAlberto command // class CCommandTestAlberto : public CRhinoCommand { public: CCommandTestAlberto() = default; ~CCommandTestAlberto() = default; UUID CommandUUID() override { // {7FB77009-684A-4F44-926B-E95991ACB868} static const GUID cmdTestAlbertoCommand_UUID = { 0x7FB77009, 0x684A, 0x4F44, { 0x92, 0x6B, 0xE9, 0x59, 0x91, 0xAC, 0xB8, 0x68 } }; return cmdTestAlbertoCommand_UUID; } const wchar_t* EnglishCommandName() override { return L"TestAlberto"; } CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override; }; // The one and only CCommandCMDTestOles object static class CCommandTestAlberto theCmdTestAlbertoCommand; CRhinoCommand::result CCommandTestAlberto::RunCommand(const CRhinoCommandContext& context) { CRhinoGetObject go; go.SetCommandPrompt(L"Select surface"); go.SetGeometryFilter(CRhinoGetObject::surface_object); go.GetObjects(1, 1); if (go.CommandResult() != CRhinoCommand::success) return go.CommandResult(); const CRhinoObjRef& objref = go.Object(0); const ON_Brep* brep = objref.Brep(); if (nullptr == brep) return CRhinoCommand::failure; const double tolerance = 0.005 / 3.6; ON_MeshParameters mp; mp.SetTolerance(tolerance); mp.SetGridAspectRatio(0.0); ON_SimpleArray meshes; brep->CreateMesh(mp, meshes); for (int i = 0; i < meshes.Count(); i++) { if (nullptr == meshes[i]) return CRhinoCommand::failure; const ON_MeshTopology& mesh_top = meshes[i]->Topology(); for (int ei = 0; ei < mesh_top.TopEdgeCount(); ei++) { ON_Line edge = mesh_top.TopEdgeLine(ei); ON_3dPoint edge_pt = edge.PointAt(0.5); ON_COMPONENT_INDEX ci = ON_COMPONENT_INDEX::UnsetComponentIndex; double u = ON_UNSET_VALUE; double v = ON_UNSET_VALUE; ON_3dPoint brep_pt = ON_3dPoint::UnsetPoint; if (RhinoBrepClosestPoint(*brep, edge_pt, &ci, &u, &v, &brep_pt, 0.0)) { double d = edge_pt.DistanceTo(brep_pt); RhinoApp().Print(L"Edge(%d), Distance = %g, Within tolerance = %ls\n", ei, d, d <= tolerance ? L"True" : L"False"); } } CRhinoMeshObject* mesh_obj = new CRhinoMeshObject(); mesh_obj->SetMesh(meshes[i]); meshes[i] = nullptr; context.m_doc.AddObject(mesh_obj); } context.m_doc.Redraw(); return CRhinoCommand::success; } // // END TestAlberto command // //////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////