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 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; }