CRhinoCommand::result CCommandSampleAttributeUserDataGet::RunCommand( const CRhinoCommandContext& context ) { // Select object to retrieve user data CRhinoGetObject go; go.SetCommandPrompt( L"Select object to retrieve user data" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != success ) return go.CommandResult(); // Validate the selection const CRhinoObjRef& ref = go.Object(0); const CRhinoObject* obj = ref.Object(); if( !obj ) return CRhinoCommand::failure; // Get the selected object's attributes const CRhinoObjectAttributes& attribs = obj->Attributes(); // See if our user data is attached CSampleAttributeUserData* ud = CSampleAttributeUserData::Cast( attribs.GetUserData(ud->Id()) ); if( ud ) { // Print data members RhinoApp().Print( L"String = %s\n", ud->m_my_string ); RhinoApp().Print( L"Point = %f,%f,%f\n", ud->m_my_point.x, ud->m_my_point.y, ud->m_my_point.z ); } else { RhinoApp().Print( L"No user data attached.\n" ); } return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleHistory::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select two curves" ); go.SetGeometryFilter( CRhinoGetObject::curve_object ); go.GetObjects( 2, 2 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); if( 2 != go.ObjectCount() ) return CRhinoCommand::failure; CRhinoCommand::result rc = CRhinoCommand::failure; const CRhinoObjRef& CObj0 = go.Object( 0 ); const CRhinoObjRef& CObj1 = go.Object( 1 ); const ON_Curve* c0 = CObj0.Curve(); const ON_Curve* c1 = CObj1.Curve(); if( c0 && c1) { ON_Surface* pSrf = MakeBilinearSurface( *c0, *c1 ); ON_Brep brep; if( pSrf && brep.Create(pSrf) ) { CRhinoHistory history( *this ); WriteHistory( history, CObj0, CObj1 ); context.m_doc.AddBrepObject( brep, 0, &history ); rc = CRhinoCommand::success; } } return rc; }
CRhinoCommand::result CCommandSampleMeshFaceColor::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select mesh" ); go.SetGeometryFilter( CRhinoGetObject::mesh_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoMeshObject* mesh_obj = CRhinoMeshObject::Cast( go.Object(0).Object() ); if( 0 == mesh_obj ) return CRhinoCommand::failure; CSampleMeshFaceColorConduit conduit( mesh_obj->m_runtime_object_serial_number ); conduit.Enable(); context.m_doc.Regen(); CRhinoGetString gs; gs.SetCommandPrompt( L"Press <Enter> to continue" ); gs.AcceptNothing(); gs.GetString(); conduit.Disable(); context.m_doc.Regen(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandPlugIn2Get::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != success ) return go.CommandResult(); const CRhinoObject* object = go.Object(0).Object(); if( 0 == object ) return failure; ON_3dPoint point; ON_wString string; bool rc = GetPlugInUserData( object, point, string ); if( rc ) { ON_wString pointstr; RhinoFormatPoint( point, pointstr ); RhinoApp().Print( L"point = %s, string = %s\n", pointstr, string ); } else { RhinoApp().Print( L"Failed!\n" ); } return success; }
CRhinoCommand::result CCommandSamplePrintGripLocations::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select grips" ); go.SetGeometryFilter( CRhinoGetObject::grip_object ); 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++ ) { const CRhinoGripObject* grip = CRhinoGripObject::Cast( go.Object(i).Object() ); if( grip ) { ON_3dPoint point = grip->GripLocation(); ON_wString point_str; RhinoFormatPoint( point, point_str ); RhinoApp().Print( L"Grip %d = %s\n", i, point_str ); } } return CRhinoCommand::success; }
CRhinoCommand::result CCommandZAnalysisOn::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt(L"Select objects for Z analysis."); go.SetGeometryFilter( ON::brep_object | ON::mesh_object ); go.GetObjects(1,0); if( CRhinoCommand::success != go.CommandResult() ) return go.CommandResult(); ON_MeshParameters mp = CRhinoAppRenderMeshSettings::DefaultQualityMeshParameters(); context.m_doc.Properties().SetAnalysisMeshSettings( mp ); int count = 0; for( int i = 0; i < go.ObjectCount(); i++ ) { const CRhinoObject* rhino_object = go.Object(i).Object(); if( 0 == rhino_object ) continue; if( rhino_object->InAnalysisMode(theZAnalysisVAM.m_am_id) ) continue; const_cast<CRhinoObject*>(rhino_object)->DestroyMeshes( ON::analysis_mesh, true ); if( rhino_object->EnableAnalysisMode(theZAnalysisVAM.m_am_id, true) ) count++; } RhinoApp().Print( L"%d objects were put into Z analysis mode", count ); context.m_doc.Redraw(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandPlugIn2Add::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != success ) return go.CommandResult(); const CRhinoObject* object = go.Object(0).Object(); if( 0 == object ) return failure; CRhinoGetPoint gp; gp.SetCommandPrompt( L"Pick point" ); gp.GetPoint(); if( gp.CommandResult() != success ) return gp.CommandResult(); CRhinoGetString gs; gp.SetCommandPrompt( L"Description" ); gs.GetString(); if( gs.CommandResult() != success ) return gs.CommandResult(); bool rc = AddPlugInUserData( context.m_doc, object, gp.Point(), gs.String() ); RhinoApp().Print( L"%s\n", rc ? L"Succeeded!" : L"Failed!" ); return success; }
CRhinoCommand::result CCommandSampleTriangulatePolygon::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select closed planar polygon to triangulate" ); go.SetGeometryFilter( CRhinoGetObject::curve_object ); go.SetGeometryFilter( CRhinoGetObject::closed_curve ); go.EnableSubObjectSelect( FALSE ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObjRef& ref = go.Object(0); ON_3dPointArray vertices; const ON_PolylineCurve* pc = ON_PolylineCurve::Cast( ref.Curve() ); if( pc ) { vertices = pc->m_pline; } else { const ON_NurbsCurve* nc = ON_NurbsCurve::Cast( ref.Curve() ); if( nc ) nc->IsPolyline( &vertices ); } if( vertices.Count() < 5 ) { RhinoApp().Print( L"Curve not polygon with at least four sides.\n" ); return CRhinoCommand::nothing; } int* triangles = (int*)onmalloc( (vertices.Count()-3) * sizeof(int) * 3 ); if( 0 == triangles ) return CRhinoCommand::failure; // out of memory memset( triangles, 0, (vertices.Count()-3) * sizeof(int) * 3 ); int rc = RhinoTriangulate3dPolygon( vertices.Count()-1, 3, (const double*)vertices.Array(), 3, triangles); if( 0 == rc ) { int i; for( i = 0; i < vertices.Count()-3; i++ ) { ON_Polyline pline; pline.Append( vertices[triangles[i * 3]] ); pline.Append( vertices[triangles[i * 3 + 1]] ); pline.Append( vertices[triangles[i * 3 + 2]] ); pline.Append( pline[0] ); context.m_doc.AddCurveObject( pline ); } context.m_doc.Redraw(); } onfree( triangles ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleSelectVisibleMeshFaces::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt(L"Select mesh"); go.SetGeometryFilter(ON::mesh_object); go.EnablePreSelect(false); go.EnableUnselectObjectsOnExit(false); go.GetObjects(1, 1); if (go.CommandResult() != CRhinoCommand::success) return go.CommandResult(); CRhinoView* view = go.View(); if (0 == view) return CRhinoCommand::failure; const CRhinoMeshObject* mesh_obj = CRhinoMeshObject::Cast(go.Object(0).Object()); if (0 == mesh_obj) return CRhinoCommand::failure; ON_Mesh* mesh = const_cast<ON_Mesh*>(mesh_obj->Mesh()); if (0 == mesh) return CRhinoCommand::failure; mesh_obj->Select(false); context.m_doc.Redraw(); if (!mesh->HasFaceNormals()) mesh->ComputeFaceNormals(); ON_3fVector dir(view->ActiveViewport().VP().CameraZ()); double min_angle = 0.0; double max_angle = 90.0 * (ON_PI/180); for (int fi = 0; fi < mesh->m_F.Count(); fi++) { const ON_3fVector& norm = mesh->m_FN[fi]; double dot = ON_DotProduct(dir, norm) / (dir.Length() * norm.Length()); double angle = acos(dot); if (min_angle <= angle && angle <= max_angle) { ON_COMPONENT_INDEX ci(ON_COMPONENT_INDEX::mesh_face, fi); mesh_obj->SelectSubObject(ci, true, true); } } context.m_doc.Redraw(); CRhinoGetString gs; gs.SetCommandPrompt(L"Press <Enter> to continue"); gs.AcceptNothing(); gs.GetString(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleModifyBumpIntensity::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object to modify bump intensity" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObjRef& ref = go.Object(0); const CRhinoObject* obj = ref.Object(); if( 0 == obj ) return CRhinoCommand::failure; ON_Material material = obj->ObjectMaterial(); if( material.m_material_index < 0 ) { // I'm assuming the object already has a material. That is, // it is not just using the default material. RhinoApp().Print( L"Object does not have a material.\n" ); return CRhinoCommand::nothing; } int texture_index = material.FindTexture( 0, ON_Texture::bump_texture ); if( texture_index < 0 ) { // I'm assuming the object's material already has a bump. RhinoApp().Print( L"Object does not have a bump texture.\n" ); return CRhinoCommand::nothing; } ON_Texture& texture = material.m_textures[texture_index]; int blend_constant = ON_Round( texture.m_blend_constant_A * 100.0 ); CRhinoGetInteger gi; gi.SetCommandPrompt( L"New bump intensity" ); gi.SetDefaultInteger( blend_constant ); gi.SetLowerLimit( 0, false ); gi.SetUpperLimit( 100, false ); gi.GetInteger(); if( gi.CommandResult() != CRhinoCommand::success ) return gi.CommandResult(); texture.m_blend_constant_A = (double)gi.Number() / 100.0; if( texture.m_blend_constant_A < 1.0) texture.m_mode = ON_Texture::blend_texture; else texture.m_mode = ON_Texture::decal_texture; context.m_doc.m_material_table.ModifyMaterial( material, material.m_material_index ); context.m_doc.Redraw(); return success; }
CRhinoCommand::result CCommandSampleWindowPick::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select point cloud" ); go.SetGeometryFilter( CRhinoGetObject::pointset_object ); go.EnableSubObjectSelect( false ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoPointCloudObject* obj = CRhinoPointCloudObject::Cast( go.Object(0).Object() ); if( 0 == obj ) return CRhinoCommand::failure; const ON_PointCloud& cloud = obj->PointCloud(); obj->Select( false ); context.m_doc.Redraw(); CRhinoGetPoint gp; gp.SetCommandPrompt( L"Drag a window to select point cloud points" ); gp.ConstrainToTargetPlane(); gp.AcceptNothing(); gp.SetGetPointCursor( RhinoApp().m_default_cursor ); gp.Get2dRectangle(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); ON_SimpleArray<int> indices; const int index_count = RhWindowsSelectPointCloudPoints( gp.View(), cloud, gp.Rectangle2d(), indices ); if( 0 == index_count ) return CRhinoCommand::nothing; int i; for( i = 0; i < index_count; i++ ) obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), true ); context.m_doc.Redraw(); CRhinoGetString gs; gs.SetCommandPrompt( L"Press <Enter> to continue" ); gs.AcceptNothing(); gs.GetString(); for( i = 0; i < index_count; i++ ) obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), false ); context.m_doc.Redraw(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleSubCrvLength::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select curve to measure" ); go.SetGeometryFilter( CRhinoGetObject::curve_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObjRef& ref = go.Object(0); const ON_Curve* crv = ref.Curve(); if( !crv ) return CRhinoCommand::failure; CRhinoGetPoint gp; gp.SetCommandPrompt( L"First point on curve" ); gp.Constrain( *crv ); gp.GetPoint(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); double t0; if( !crv->GetClosestPoint(gp.Point(), &t0) ) return CRhinoCommand::nothing; gp.SetCommandPrompt( L"Second point on curve" ); gp.GetPoint(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); double t1; if( !crv->GetClosestPoint(gp.Point(), &t1) ) return CRhinoCommand::nothing; ON_Interval dom; if( t0 < t1 ) dom.Set( t0, t1 ); else dom.Set( t1, t0 ); double len; if( crv->GetLength(&len, 0.0, &dom) ) RhinoApp().Print( L"Subcurve length = %f.\n", len ); else RhinoApp().Print( L"Unable to calculate length of subcurve.\n" ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleRegionPick::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select point cloud" ); go.SetGeometryFilter( CRhinoGetObject::pointset_object ); go.EnableSubObjectSelect( false ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoPointCloudObject* obj = CRhinoPointCloudObject::Cast( go.Object(0).Object() ); if( 0 == obj ) return CRhinoCommand::failure; const ON_PointCloud& cloud = obj->PointCloud(); obj->Select( false ); context.m_doc.Redraw(); CRhGetRegionPoints gp; gp.SetCommandPrompt( L"Click and drag, or repeatedly click to lasso point cloud points. Press Enter when done" ); gp.AcceptNothing(); gp.SetGetPointCursor( RhinoApp().m_default_cursor ); gp.GetPoints(); if( gp.Result() == CRhinoGet::point ) return CRhinoCommand::cancel; ON_SimpleArray<int> indices; const int index_count = RhRegionSelectPointCloudPoints( gp.View(), cloud, gp.m_points, indices ); if( 0 == index_count ) return CRhinoCommand::nothing; int i; for( i = 0; i < index_count; i++ ) obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), true ); context.m_doc.Redraw(); CRhinoGetString gs; gs.SetCommandPrompt( L"Press <Enter> to continue" ); gs.AcceptNothing(); gs.GetString(); for( i = 0; i < index_count; i++ ) obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), false ); context.m_doc.Redraw(); return CRhinoCommand::success; }
void CSamplePickObjectsDialog::OnBnClickedPick() { // If our dialog contains controls that had values we cared about, // you will want to call UpdateData() before hiding the dialog. //UpdateData( TRUE ); // Hide this dialog PushPickButton( TRUE ); // Pick some objects CRhinoGetObject go; go.SetCommandPrompt( L"Pick objects" ); go.GetObjects( 1, 0 ); if( go.CommandResult() == CRhinoCommand::success ) { int count = go.ObjectCount(); ON_wString str; if( 1 == count ) str = L"1 object picked."; else str.Format( L"%d objects picked.", count ); m_message.SetWindowText( str ); } // Hide this dialog PushPickButton( FALSE ); // If our dialog contains controls that had values we cared about, // you will want to call UpdateData() before showing the dialog. //UpdateData( FALSE ); }
CRhinoCommand::result CCommandTestRemoveData::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObject* object = go.Object(0).Object(); if( 0 == object ) return CRhinoCommand::failure; AssociationData::RemoveData( context.m_doc, object ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandNewName::RunCommand( const CRhinoCommandContext& context ) { // Select an object to modify CRhinoGetObject go; go.SetCommandPrompt( L"Select object to change name" ); go.EnablePreSelect( TRUE ); go.EnableSubObjectSelect( FALSE ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); // Get the object reference const CRhinoObjRef& objref = go.Object(0); // Get the object const CRhinoObject* obj = objref.Object(); if( !obj ) return CRhinoCommand::failure; // Make copy of object attributes. This objects // holds an object's user-defined name. ON_3dmObjectAttributes obj_attribs = obj->Attributes(); // Prompt for new object name CRhinoGetString gs; gs.SetCommandPrompt( L"New object name" ); gs.SetDefaultString( obj_attribs.m_name ); gs.AcceptNothing( TRUE ); gs.GetString(); if( gs.CommandResult() != CRhinoCommand::success ) return gs.CommandResult(); // Get the string entered by the user ON_wString obj_name = gs.String(); obj_name.TrimLeftAndRight(); // Is name the same? if( obj_name.Compare(obj_attribs.m_name) == 0 ) return CRhinoCommand::nothing; // Modify the attributes of the object obj_attribs.m_name = obj_name; context.m_doc.ModifyObjectAttributes( objref, obj_attribs ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandPlugIn2Remove::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != success ) return go.CommandResult(); const CRhinoObject* object = go.Object(0).Object(); if( 0 == object ) return failure; bool rc = RemovePlugInUserData( context.m_doc, object ); RhinoApp().Print( L"%s\n", rc ? L"Succeeded!" : L"Failed!" ); return success; }
CRhinoCommand::result CCommandSampleMeshVertexLocation::RunCommand( const CRhinoCommandContext& context ) { // Select a mesh vertex CRhinoGetObject go; go.SetCommandPrompt( L"Select mesh vertex" ); go.SetGeometryFilter( CRhinoGetObject::meshvertex_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); // Get the mesh vertex reference const ON_MeshVertexRef* mesh_vertex_ref = go.Object(0).MeshVertex(); if( 0 == mesh_vertex_ref ) return CRhinoCommand::failure; // Get the mesh topology const ON_MeshTopology* mesh_top = mesh_vertex_ref->MeshTopology(); // Get the topological mesh vertex const ON_MeshTopologyVertex* mesh_top_vertex = mesh_vertex_ref->MeshTopologyVertex(); if( 0 == mesh_top || 0 == mesh_top_vertex ) return CRhinoCommand::failure; // Iterate through all of of the topological mesh edges, that reference // this topological mesh vertex, and see if one of the edges is a naked edge. bool bBoundaryVertex = false; for( int i = 0; i < mesh_top_vertex->m_tope_count; i++ ) { const ON_MeshTopologyEdge& mesh_top_edge = mesh_top->m_tope[mesh_top_vertex->m_topei[i]]; // If the edge has only one face, which means it is a naked edge, // then the vertex must be on a boundary edge. if( 1 == mesh_top_edge.m_topf_count ) { bBoundaryVertex = true; break; } } // Report results if( bBoundaryVertex ) RhinoApp().Print( L"Mesh vertex is on a boundary edge.\n" ); else RhinoApp().Print( L"Mesh vertex is on an interior edge.\n" ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandTestAddData::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select two objects to associate" ); go.GetObjects( 2, 2 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObject* object0 = go.Object(0).Object(); const CRhinoObject* object1 = go.Object(1).Object(); if( 0 == object0 || 0 == object1 ) return CRhinoCommand::failure; AssociationData::AddData( context.m_doc, object0, object0->Attributes().m_uuid, object1->Attributes().m_uuid ); AssociationData::AddData( context.m_doc, object1, object1->Attributes().m_uuid, object0->Attributes().m_uuid ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleFindCrvsOnSrf::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select surface" ); go.SetGeometryFilter( CRhinoGetObject::surface_object ); go.EnableSubObjectSelect( true ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const ON_BrepFace* face = go.Object(0).Face(); if( 0 == face ) return CRhinoCommand::failure; ON_BoundingBox face_bbox = face->BoundingBox(); double tol = context.m_doc.AbsoluteTolerance(); bool bRedraw = false; const CRhinoObject* obj = 0; CRhinoObjectIterator it( CRhinoObjectIterator::normal_objects, CRhinoObjectIterator::active_and_reference_objects ); for( obj = it.First(); obj; obj = it.Next() ) { const CRhinoCurveObject* crv_obj = CRhinoCurveObject::Cast( obj ); if( 0 == crv_obj ) continue; ON_BoundingBox crv_bbox = crv_obj->BoundingBox(); if( !face_bbox.Includes(crv_bbox) ) continue; if( !IsCurveOnFace(face, crv_obj->Curve(), tol) ) continue; crv_obj->Select( true ); bRedraw = true; } if( bRedraw ) context.m_doc.Redraw(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleAttributeUserDataAdd::RunCommand( const CRhinoCommandContext& context ) { // Select object to attach user data CRhinoGetObject go; go.SetCommandPrompt( L"Select object to attach user data" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != success ) return go.CommandResult(); // Validate the selection const CRhinoObjRef& ref = go.Object(0); const CRhinoObject* obj = ref.Object(); if( !obj ) return CRhinoCommand::failure; // Get the selected object's attributes const CRhinoObjectAttributes& attribs = obj->Attributes(); // See if our user data is already attached CSampleAttributeUserData* ud = CSampleAttributeUserData::Cast( attribs.GetUserData(ud->Id()) ); if( ud ) { RhinoApp().Print( L"User data already attached.\n" ); return CRhinoCommand::nothing; } // New up a copy of our user data and fill in the data members ud = new CSampleAttributeUserData(); ud->m_my_string = obj->ShortDescription( false ); ref.SelectionPoint( ud->m_my_point ); // Make a copy of the object's attributes ON_3dmObjectAttributes new_attribs( attribs ); // Attach our user data to this copy new_attribs.AttachUserData( ud ); // Replace the selected object's attributes context.m_doc.ModifyObjectAttributes( ref, new_attribs ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleObjectCursor::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object to delete" ); go.AcceptNothing( FALSE ); HCURSOR hCursor = SampleCursorPlugIn().Cursor(); if( 0 != hCursor ) RhinoSetCursor( hCursor ); go.GetObjects( 1, 1 ); if( 0 != hCursor ) RhinoSetCursor( 0 ); if (go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); context.m_doc.DeleteObject( go.Object(0) ); context.m_doc.Redraw(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandTestGetData::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select object" ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObject* object = go.Object(0).Object(); if( 0 == object ) return CRhinoCommand::failure; ON_UUID object0_uuid, object1_uuid; if( AssociationData::GetData(object, object0_uuid, object1_uuid) ) { ON_wString object0_str, object1_str; ON_UuidToString( object0_uuid, object0_str ); ON_UuidToString( object1_uuid, object1_str ); RhinoApp().Print( L"Object0 = %s\n", object0_str ); RhinoApp().Print( L"Object1 = %s\n", object1_str ); } return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleOrientOnCrv::SelectObjects( CRhinoXformObjectList& object_list ) { object_list.Empty(); CRhinoGetObject get; get.SetCommandPrompt( L"Select objects to orient" ); get.EnablePreSelect(); get.EnableSubObjectSelect( FALSE ); get.AcceptNothing(); get.GetObjects(1, 0); CRhinoCommand::result rc = get.CommandResult(); if( rc == CRhinoCommand::success ) { if( object_list.AddObjects( get ) < 1 ) rc = CRhinoCommand::failure; } return rc; }
CRhinoCommand::result CCommandSampleOrientOnCrv::GetPathCurve( const ON_Curve*& path_curve ) { CRhinoGetObject get; get.SetCommandPrompt( L"Select path curve" ); get.SetGeometryFilter( CRhinoGetObject::curve_object ); get.EnableDeselectAllBeforePostSelect( false ); get.EnablePreSelect( FALSE ); get.AcceptNothing(); get.GetObjects( 1, 1 ); CRhinoCommand::result rc = get.CommandResult(); if( rc == CRhinoCommand::success ) { CRhinoObjRef objRef = get.Object(0); path_curve = objRef.Curve(); if( !path_curve ) rc = CRhinoCommand::failure; } return rc; }
CRhinoCommand::result CCommandTestAnimator::RunCommand( const CRhinoCommandContext& context ) { // Select objects to animate CRhinoGetObject go; go.SetCommandPrompt( L"Select objects to animate" ); go.GetObjects( 1, 0 ); if( go.CommandResult() != success ) return go.CommandResult(); // Select path curve CRhinoGetObject gc; gc.SetCommandPrompt( L"Select path curve" ); gc.SetGeometryFilter( CRhinoGetObject::curve_object ); gc.SetGeometryAttributeFilter( CRhinoGetObject::open_curve ); gc.GetObjects( 1, 1 ); if( gc.CommandResult() != success ) return gc.CommandResult(); const ON_Curve* crv = gc.Object(0).Curve(); if( 0 == crv ) return failure; // Create an array of normalized curve parameters ON_SimpleArray<double> t_array( m_max_steps ); t_array.SetCount( m_max_steps ); int i = 0; for( i = 0; i < m_max_steps; i++ ) { double t = (double)i / ( (double)m_max_steps - 1 ); t_array[i] = t; } // Get the real parameters along the curve if( !crv->GetNormalizedArcLengthPoints(m_max_steps, t_array.Array(), t_array.Array()) ) return failure; // Create our dialog box with animatin slider... CTestAnimatorDlg dlg( CWnd::FromHandle(RhinoApp().MainWnd()) ); dlg.m_max_steps = m_max_steps; dlg.m_start = crv->PointAtStart(); // Get points along curve for( i = 0; i < m_max_steps; i++ ) { ON_3dPoint pt = crv->PointAt( t_array[i] ); dlg.m_points.Append( pt ); } // Hide objects and add them to callback's object array for( i = 0; i < go.ObjectCount(); i++ ) { CRhinoObjRef ref = go.Object(i); context.m_doc.HideObject( ref ); dlg.m_conduit.m_objects.Append( ref.Object() ); } // Do the dialog INT_PTR rc = dlg.DoModal(); // If OK was pressed, transform the objects. // Otherwise, just unhide them. for( i = 0; i < go.ObjectCount(); i++ ) { CRhinoObjRef ref = go.Object(i); context.m_doc.ShowObject( ref ); if( rc == IDOK ) { ON_Xform xform = dlg.m_conduit.m_xform; context.m_doc.TransformObject( ref, xform ); } } context.m_doc.Redraw( CRhinoView::regenerate_display_hint ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleLineMeshIntersect::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject gm; gm.SetCommandPrompt(L"Select mesh to intersect"); gm.SetGeometryFilter(CRhinoGetObject::mesh_object); gm.GetObjects(1, 1); if (gm.CommandResult() != CRhinoCommand::success) return gm.CommandResult(); const ON_Mesh* mesh = gm.Object(0).Mesh(); if (0 == mesh) return CRhinoCommand::failure; CRhinoGetObject gl; gl.SetCommandPrompt(L"Select line to intersect with"); gl.SetGeometryFilter(CRhinoGetObject::curve_object); gl.SetGeometryAttributeFilter(CRhinoGetObject::open_curve); gl.EnablePreSelect(FALSE); gl.EnableDeselectAllBeforePostSelect(FALSE); gl.GetObjects(1, 1); if (gl.CommandResult() != CRhinoCommand::success) return gl.CommandResult(); const ON_Curve* curve = gl.Object(0).Curve(); if (0 == curve) return CRhinoCommand::failure; const ON_LineCurve* line_curve = ON_LineCurve::Cast(curve); if (0 == line_curve) { RhinoApp().Print(L"Not a line curve.\n"); return CRhinoCommand::nothing; } ON_3dPointArray points; points.Append(line_curve->m_line.from); points.Append(line_curve->m_line.to); const ON_MeshTree* mesh_tree = mesh->MeshTree(true); if (mesh_tree) { ON_SimpleArray<ON_CMX_EVENT> cmx; if (mesh_tree->IntersectPolyline(2, points.Array(), cmx)) { for (int i = 0; i < cmx.Count(); i++) { RhinoApp().Print(L"Intesection found at face index = %d.\n", cmx[i].m_M[0].m_face_index); CRhinoPointObject* point_object = context.m_doc.AddPointObject(cmx[i].m_M[0].m_P); if (point_object) point_object->Select(); } context.m_doc.Redraw(); } if (1 == cmx.Count()) RhinoApp().Print(L"1 intesection found.\n"); else RhinoApp().Print(L"%d intesections found.\n", cmx.Count()); } return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleCageEdit::RunCommand( const CRhinoCommandContext& context ) { ON_Workspace ws; CRhinoCommand::result rc = CRhinoCommand::success; // Get the captive object CRhinoGetObject go; go.SetCommandPrompt( L"Select captive surface or polysurface" ); go.SetGeometryFilter( CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object ); go.GetObjects( 1, 1 ); rc = go.CommandResult(); if( CRhinoCommand::success != rc ) return rc; const CRhinoObject* captive = go.Object(0).Object(); if( 0 == captive ) return CRhinoCommand::failure; // Define the control line ON_Line line; CArgsRhinoGetLine args; rc = RhinoGetLine( args, line ); if( CRhinoCommand::success != rc ) return rc; // Get the curve parameters int degree = 3; int cv_count = 4; for(;;) { CRhinoGetOption gl; gl.SetCommandPrompt( L"NURBS Parameters" ); gl.AcceptNothing(); int d_opt = gl.AddCommandOptionInteger( RHCMDOPTNAME(L"Degree"), °ree, L"Curve degree", 1.0, 100.0 ); int p_opt = gl.AddCommandOptionInteger( RHCMDOPTNAME(L"PointCount"), &cv_count, L"Number of control points", 2.0, 100.0 ); gl.GetOption(); rc = gl.CommandResult(); if( CRhinoCommand::success != rc ) return rc; if( CRhinoGet::nothing == gl.Result() ) break; if( cv_count <= degree ) { if( CRhinoGet::option != gl.Result() ) continue; const CRhinoCommandOption* opt = go.Option(); if( 0 == opt ) continue; if( d_opt == opt->m_option_index ) cv_count = degree + 1; else degree = cv_count - 1; } } // Set up morph control ON_MorphControl* control = new ON_MorphControl(); control->m_varient = 1; // 1= curve // Specify the source line curve control->m_nurbs_curve0.Create( 3, false, 2, 2 ); control->m_nurbs_curve0.MakeClampedUniformKnotVector(); control->m_nurbs_curve0.SetCV( 0, line.from ); control->m_nurbs_curve0.SetCV( 1, line.to ); // Specify the destination NURBS curve control->m_nurbs_curve.Create( 3, false, degree + 1, cv_count ); control->m_nurbs_curve.MakeClampedUniformKnotVector(); double* g = ws.GetDoubleMemory( control->m_nurbs_curve.m_cv_count ); control->m_nurbs_curve.GetGrevilleAbcissae( g ); ON_Interval d = control->m_nurbs_curve.Domain(); double s = 0.0; int i; for( i = 0; i < control->m_nurbs_curve.m_cv_count; i++ ) { s = d.NormalizedParameterAt( g[i] ); control->m_nurbs_curve.SetCV( i, line.PointAt(s) ); } // Make sure domains match s = line.Length(); if( s > ON_SQRT_EPSILON ) control->m_nurbs_curve0.SetDomain( 0.0, s ); d = control->m_nurbs_curve0.Domain(); control->m_nurbs_curve.SetDomain( d[0], d[1] ); // Create the morph control object CRhinoMorphControl* control_object = new CRhinoMorphControl(); control_object->SetControl( control ); context.m_doc.AddObject( control_object ); // Set up the capture RhinoCaptureObject( control_object, const_cast<CRhinoObject*>(captive) ); // Clean up display context.m_doc.UnselectAll(); // Turn on the control grips control_object->EnableGrips( true ); context.m_doc.Redraw( CRhinoView::mark_display_hint ); return rc; }
CRhinoCommand::result CCommandSampleShortPath::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select surface for creating a short curve between two points on the surface" ); go.SetGeometryFilter( CRhinoGetObject::surface_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const ON_Surface* srf = go.Object(0).Surface(); if( 0 == srf ) return CRhinoCommand::failure; CRhinoGetPoint gp; gp.SetCommandPrompt( L"Start of curve" ); gp.Constrain(*srf); gp.GetPoint(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); double u0, v0; if( !gp.PointOnSurface(&u0, &v0) ) { RhinoApp().Print( L"Point not on the surface.\n" ); return CRhinoCommand::failure; } gp.SetCommandPrompt( L"End of curve" ); gp.GetPoint(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); double u1, v1; if( !gp.PointOnSurface(&u1, &v1) ) { RhinoApp().Print( L"Point not on the surface.\n" ); return CRhinoCommand::failure; } ON_3dPoint p0 = srf->PointAt( u0, v0 ); ON_3dPoint p1 = srf->PointAt( u1, v1 ); if( p0.DistanceTo(p1) < ON_SQRT_EPSILON ) { RhinoApp().Print( L"Points must be distinct.\n" ); return CRhinoCommand::nothing; } double tol = context.m_doc.AbsoluteTolerance(); ON_Curve* crv = RhinoShortPath( *srf, ON_2dPoint(u0,v0), ON_2dPoint(u1,v1), tol ); if( 0 == crv ) { RhinoApp().Print( L"Failed to compute shortest path.\n" ); return CRhinoCommand::nothing; } CRhinoCurveObject* crv_obj = new CRhinoCurveObject(); crv_obj->SetCurve( crv ); context.m_doc.AddObject( crv_obj ); context.m_doc.Redraw(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleOrientOnSrf::RunCommand( const CRhinoCommandContext& context ) { // Select objects to orient CRhinoGetObject go; go.SetCommandPrompt( L"Select objects to orient" ); go.EnableSubObjectSelect( FALSE ); go.EnableGroupSelect( TRUE ); go.GetObjects( 1, 0 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); // Point to orient from CRhinoGetPoint gp; gp.SetCommandPrompt( L"Point to orient from" ); gp.GetPoint(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); // Define source plane CRhinoView* view = gp.View(); if( 0 == view ) { view = RhinoApp().ActiveView(); if( 0 == view ) return CRhinoCommand::failure; } ON_Plane source_plane( view->Viewport().ConstructionPlane().m_plane ); source_plane.SetOrigin( gp.Point() ); // Surface to orient on CRhinoGetObject gs; gs.SetCommandPrompt( L"Surface to orient on" ); gs.SetGeometryFilter( CRhinoGetObject::surface_object ); gs.EnableSubObjectSelect( TRUE ); gs.EnableDeselectAllBeforePostSelect( false ); gs.EnableOneByOnePostSelect(); gs.GetObjects( 1, 1 ); if( gs.CommandResult() != CRhinoCommand::success ) return gs.CommandResult(); const CRhinoObjRef& ref = gs.Object(0); // Get selected surface object const CRhinoObject* obj = ref.Object(); if( 0 == obj ) return CRhinoCommand::failure; // Get selected surface (face) const ON_BrepFace* face = ref.Face(); if( 0 == face ) return CRhinoCommand::failure; // Unselect surface obj->Select( false ); // Point on surface to orient to gp.SetCommandPrompt( L"Point on surface to orient to" ); gp.Constrain( *face ); gp.GetPoint(); if( gp.CommandResult() != CRhinoCommand::success ) return gp.CommandResult(); // Do transformation CRhinoCommand::result rc = CRhinoCommand::failure; double u = 0.0, v = 0.0; if( face->GetClosestPoint(gp.Point(), &u, &v) ) { ON_Plane target_plane; if( face->FrameAt(u, v, target_plane) ) { // If the face orientation is opposite // of natural surface orientation, then // flip the plane's zaxis. if( face->m_bRev ) target_plane.CreateFromFrame( target_plane.origin, target_plane.xaxis, -target_plane.zaxis ); // Build transformation ON_Xform xform; xform.Rotation( source_plane, target_plane ); // Do the transformation. In this example, // we will copy the original objects bool bDeleteOriginal = false; int i; for( i = 0; i < go.ObjectCount(); i++ ) context.m_doc.TransformObject( go.Object(i), xform, bDeleteOriginal ); context.m_doc.Redraw(); rc = CRhinoCommand::success; } } return rc; }