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 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 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 CCommandSamplePrePostSelect::RunCommand( const CRhinoCommandContext& context ) { double dValue = m_dValue; int nValue = m_nValue; CRhinoGetObject go; go.SetGeometryFilter( CRhinoGetObject::curve_object ); go.EnableGroupSelect( TRUE ); go.EnableSubObjectSelect( FALSE ); /*int d_option_index =*/ go.AddCommandOptionNumber( RHCMDOPTNAME(L"Double"), &dValue, L"Double value", FALSE, 1.0, 99.9 ); /*int n_option_index =*/ go.AddCommandOptionInteger( RHCMDOPTNAME(L"Integer"), &nValue, L"Integer value", 1, 99 ); bool bHavePreselectedObjects = false; for( ;; ) { CRhinoGet::result res = go.GetObjects( 1, 0 ); if( res == CRhinoGet::option ) { go.EnablePreSelect( FALSE ); go.EnableAlreadySelectedObjectSelect( true ); go.EnableClearObjectsOnEntry( false ); go.EnableDeselectAllBeforePostSelect( false ); go.EnableUnselectObjectsOnExit( false ); continue; } else if( res != CRhinoGet::object ) return CRhinoCommand::cancel; if( go.ObjectsWerePreSelected() ) { bHavePreselectedObjects = true; go.EnablePreSelect( FALSE ); go.EnableAlreadySelectedObjectSelect( true ); go.EnableClearObjectsOnEntry( false ); go.EnableDeselectAllBeforePostSelect( false ); go.EnableUnselectObjectsOnExit( false ); continue; } break; } if( bHavePreselectedObjects ) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for( int i = 0; i < go.ObjectCount(); i++ ) { const CRhinoObject* object = go.Object(i).Object(); if( 0 != object ) object->Select( false ); } context.m_doc.Redraw(); } int object_count = go.ObjectCount(); m_dValue = dValue; m_nValue = nValue; RhinoApp().Print( L"Select object count = %d\n", object_count ); RhinoApp().Print( L"Value of double = %f\n", m_dValue ); RhinoApp().Print( L"Value of integer = %d\n", m_nValue ); 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; }