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 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 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 CCommandTestHistoryExample::RunCommand( const CRhinoCommandContext& context ) { CRhinoCommand::result rc = CRhinoCommand::failure; CRhinoGetObject go; go.SetCommandPrompt(L"Pick two curves"); go.SetGeometryFilter(CRhinoGetObject::curve_object); go.GetObjects(2,2); if( go.Result()== CRhinoGet::object && go.ObjectCount()==2) { CRhinoObjRef CObj0 = go.Object(0); 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,NULL,&history); rc = CRhinoCommand::success; } } } return rc; }
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 CCommandSampleMeshDir::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetGeometryFilter( CRhinoObject::mesh_object | CRhinoObject::surface_object | CRhinoObject::polysrf_object | CRhinoObject::instance_reference ); go.SetCommandPrompt( L"Select mesh, surface, or polysurface objects" ); go.GetObjects(1,0); if( go.Result() != CRhinoGet::object ) return CRhinoCommand::cancel; int i = 0; ON_SimpleArray<const CRhinoObject*> objects( go.ObjectCount() ); for( i = 0; i < go.ObjectCount(); i++ ) objects.Append( go.Object(i).Object() ); ON_ClassArray<CRhinoObjRef> render_meshes; int count = RhinoGetRenderMeshes( objects, render_meshes, true, false ); if( count > 0 ) { CMeshDirDrawCallback callback; callback.m_mesh_list.Reserve( count ); for( i = 0; i < render_meshes.Count(); i++ ) { const ON_Mesh* mesh = render_meshes[i].Mesh(); if( mesh ) callback.m_mesh_list.AppendNew().SetMesh( mesh ); } CRhinoGetOption go; go.SetCommandPrompt( L"Press Enter when done" ); go.AcceptNothing(); go.AddCommandOptionToggle( RHCMDOPTNAME(L"FaceNormals"), RHCMDOPTVALUE(L"No"), RHCMDOPTVALUE(L"Yes"), m_draw_face_normals, &m_draw_face_normals ); go.AddCommandOptionToggle( RHCMDOPTNAME(L"VertexNormals"), RHCMDOPTVALUE(L"No"), RHCMDOPTVALUE(L"Yes"), m_draw_vertex_normals, &m_draw_vertex_normals ); CRhinoGet::result res = CRhinoGet::nothing; for( ;; ) { callback.m_draw_face_normals = m_draw_face_normals; callback.m_draw_vertex_normals = m_draw_vertex_normals; CRhinoView::AddDrawCallback( &callback ); context.m_doc.Redraw( CRhinoView::regenerate_display_hint ); res = go.GetOption(); CRhinoView::RemoveDrawCallback( &callback ); if( res == CRhinoGet::option ) continue; break; } } context.m_doc.Redraw( CRhinoView::regenerate_display_hint ); 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 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 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; }
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 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 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 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 CCommandSampleUnrollSurface::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select surface or polysurface to unroll" ); go.SetGeometryFilter( CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object ); go.EnableSubObjectSelect( FALSE ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObject* pObject = go.Object(0).Object(); const ON_Brep* pBrep = go.Object(0).Brep(); if( 0 == pObject || 0 == pBrep ) return CRhinoCommand::failure; bool bExplode = false; ON_Brep* p3dBrep = 0; int i, type = -1; if(1 == pBrep->m_F.Count() ) { p3dBrep = pBrep->DuplicateFace( 0, false ); type = 0; } else { p3dBrep = static_cast<ON_Brep*>( pBrep->Duplicate() ); type = 1; } if( 0 == p3dBrep ) return CRhinoCommand::failure; p3dBrep->Compact(); for( i = 0; i < p3dBrep->m_F.Count(); i++ ) p3dBrep->RebuildEdges( p3dBrep->m_F[i], 0.00001, true, true ); p3dBrep->ShrinkSurfaces(); ReverseVReversedSurfaces( p3dBrep ); CRhinoUnroll Unroller( p3dBrep, context.m_doc.AbsoluteTolerance(), 0.1 ); int irc = Unroller.PrepareFaces(); if( 0 == irc ) { bool ok = Unroller.FlattenFaces(); if( ok ) { int flat_face_count = Unroller.CreateFlatBreps( bExplode, 2.0 ); if( flat_face_count ) { ON_SimpleArray<ON_Brep*> flat_breps; ON_ClassArray< ON_SimpleArray<ON_Curve*> > flat_curves; ON_ClassArray< ON_SimpleArray<ON_3dPoint> > flat_points; ON_ClassArray< ON_SimpleArray<ON_TextDot*> > flat_dots; Unroller.CollectResults( flat_breps, flat_curves, flat_points, flat_dots ); if( !bExplode && flat_breps.Count() > 1 ) { ON_Brep* pJoinedBrep = ON_Brep::New(); if( pJoinedBrep ) { for( i = 0; i < flat_breps.Count(); i++ ) { if( flat_breps[i] != 0 ) pJoinedBrep->Append( *flat_breps[i] ); } int joins = RhinoJoinBrepNakedEdges( *pJoinedBrep ); flat_breps.Empty(); flat_breps.Append( pJoinedBrep ); } } CRhinoObjectAttributes att = pObject->Attributes(); att.m_uuid = ON_nil_uuid; att.RemoveFromAllGroups(); for( i = 0; i < flat_breps.Count(); i++ ) { CRhinoBrepObject* flat_obj = new CRhinoBrepObject( att ); flat_obj->SetBrep( flat_breps[i] ); if( !context.m_doc.AddObject(flat_obj) ) delete flat_obj; // Don't leak... } } } delete p3dBrep; // Don't leak... } context.m_doc.Redraw(); 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; }
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 CGenUgello::RunCommand( const CRhinoCommandContext& context ) { Cscript1PlugIn& plugin = script1PlugIn(); if( !plugin.IsDlgVisible() ) { return CRhinoCommand::nothing; } /*GET A REFERENCE TO THE LAYER TABLE*/ CRhinoLayerTable& layer_table = context.m_doc.m_layer_table; CRhinoGetObject go9; go9.SetCommandPrompt( L"Select object to change name" ); go9.EnablePreSelect( TRUE ); go9.EnableSubObjectSelect( FALSE ); go9.GetObjects( 1, 1 ); if( go9.CommandResult() != CRhinoCommand::success ) return go9.CommandResult(); // Get the object reference const CRhinoObjRef& objref9 = go9.Object(0); // Get the object const CRhinoObject* obj9 = objref9.Object(); obj9->Select( false ); if( !obj9 ) return CRhinoCommand::failure; // Make copy of object attributes. This objects // holds an object's user-defined name. ON_3dmObjectAttributes obj_attribs9 = obj9->Attributes(); //Prompt for new object name CRhinoGetString gs1; //gs1.SetDefaultString( /*gs1.SetCommandPrompt( L"New object name" ); gs1.SetDefaultString( obj_attribs9.m_name ); gs1.AcceptNothing( TRUE ); gs1.GetString(); if( gs1.CommandResult() != CRhinoCommand::success ) return gs1.CommandResult();*/ // Get the string entered by the user // ON_wString obj_name1 = gs1.String(); // //obj_name.TrimLeftAndRight(); ////const wchar_t* prova5 = new(L"testo"); // //wchar_t name( L"testo" ); //const wchar_t* szName = gs1.String(); CTestUserData* ud = CTestUserData::Cast( obj_attribs9.GetUserData(ud->Id()) ); ON_wString obj_name = L"ugello22"; selectobjectbyuuid_s(context.m_doc,obj_name,true); //SelectObjectByUuid(context.m_doc,obj_attribs9.m_uuid,true); //begin calcolo il punto di intersezione per disegnare l'ugello double valore_ugello =(_wtof(plugin.m_dialog->ValIniezioneDisassamento)); ON_3dPoint inizio_linea (valore_ugello,0,0); ON_3dPoint fine_linea (valore_ugello,0,130); ON_Line line_ugello( inizio_linea, fine_linea ); const ON_LineCurve* crv3 = new ON_LineCurve(line_ugello); //crv3->DuplicateCurve // context.m_doc.AddCurveObject( line_ugello ); //begin deseleziona tutto const CRhinoLayer& layer = context.m_doc.m_layer_table.CurrentLayer(); ON_SimpleArray<CRhinoObject*> obj_list; int j, obj_count = context.m_doc.LookupObject( layer, obj_list ); for( j = 0; j < obj_count; j++ ) { CRhinoObject* obj = obj_list[j]; if( obj && obj->IsSelectable() ) obj->UnselectAllSubObjects(); //obj->Select(false); if( obj_count ) context.m_doc.Redraw(); } // end deseleziona tutto //const ON_Object* obj_ptr = context.m_doc.LookupDocumentObject(pvcurva, false); // CRhinoObjRef& objref5 = CRhinoObject* LookupObject(pvcurva); //SelectObjectByUuid( context.m_doc, pvcurva, true ); //const CRhinoObject* object = context.m_doc.LookupObject( pvcurva ); //ON_TextLog* text_log; //object->IsValid(); // inizio esempio // Select two curves to intersect CRhinoGetObject go; go.SetCommandPrompt( L"Seleziona la linea originale del Piano Visionale" ); go.SetGeometryFilter( ON::curve_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); // Validate input const ON_Curve* curveA = go.Object(0).Curve(); const ON_Curve* curveB = crv3;//go.Object(1).Curve(); if( 0 == curveA | 0 == curveB ) return CRhinoCommand::failure; // Calculate the intersection double intersection_tolerance = 0.001; double overlap_tolerance = 0.0; ON_SimpleArray<ON_X_EVENT> events; int count = curveA->IntersectCurve( curveB, events, intersection_tolerance, overlap_tolerance ); ON_3dPoint PuntoIntersezione; // Process the results if( count > 0 ) { ::RhinoApp().Print( L"Intersezione punto per ugello trovato"); int i; for( i = 0; i < events.Count(); i++ ) { const ON_X_EVENT& e = events[i]; context.m_doc.AddPointObject( e.m_A[0] ); if( e.m_A[0].DistanceTo(e.m_B[0]) > ON_EPSILON ) { context.m_doc.AddPointObject( e.m_B[0] ); context.m_doc.AddCurveObject( ON_Line(e.m_A[0], e.m_B[0]) ); PuntoIntersezione = e.m_B[0]; } } context.m_doc.Redraw(); } /* ON_UUID uuid = obj->Attributes().m_uuid; ON_wString str; ON_UuidToString( uuid, str ); ::RhinoApp().Print( L"The object's unique identifier is \"%s\".\n", str );*/ // fine esempio //const CRhinoObjRef& objref1 = ref; //era object /*const ON_LineCurve* GetLineCurve( const ON_Curve* pC5 ){ const ON_LineCurve* p = 0; if( pC5 != 0 ) p = ON_LineCurve::Cast( pC5 ); return p; // }*/ // // const ON_LineCurve* pC5 = ON_LineCurve::Cast( ref.Geometry() ); //// // ON_Line line1 = crv7->m_line; //// //ON_Line line1 = pC5-> // ON_3dVector v0 = line_ugello.to - line_ugello.from; //v0.Unitize(); //ON_3dVector v1 = line1.to - line1.from; //v1.Unitize(); //if( v0.IsParallelTo(v1) != 0 ) //{ // RhinoApp().Print( L"Selected lines are parallel.\n" ); // return nothing; //} // ON_Line ray0( line_ugello.from, line_ugello.from + v0 ); //ON_Line ray1( line1.from, line1.from + v1 ); //double s = 0, t = 0; //if( !ON_Intersect(ray0, ray1, &s, &t) ) //{ // RhinoApp().Print( L"No intersection found.\n" ); // return nothing; //} //ON_3dPoint pt0 = line_ugello.from + s * v0; //ON_3dPoint pt1 = line1.from + t * v1; //context.m_doc.AddPointObject( pt0 ); // //context.m_doc.Redraw(); //go5.g // const CRhinoObjRef& objref5 = go5.; //CRhinoGetObject; //CRhinoDoc::LookupDocumentObject( //begin calcolo il punto di intersezione per disegnare l'ugello ON_3dPoint bottom_pt = PuntoIntersezione; // l'altro punto, e.m_A[0], non e' preciso. double bottom_radius = 3.25; ON_Circle bottom_circle( bottom_pt, bottom_radius ); ON_3dPoint top_pt = PuntoIntersezione; top_pt.z+=8.0; double top_radius = 11; ON_Circle top_circle( top_pt, top_radius ); ON_RevSurface* revsrf = new ON_RevSurface; ON_LineCurve* pShapeCurve = new ON_LineCurve; revsrf->m_curve = pShapeCurve; pShapeCurve->m_dim = 3; pShapeCurve->m_line.from = bottom_circle.PointAt(0); pShapeCurve->m_line.to = top_circle.PointAt(0); pShapeCurve->m_t.Set(0, pShapeCurve->m_line.from.DistanceTo(pShapeCurve->m_line.to)); revsrf->m_axis.from = bottom_circle.Center(); revsrf->m_axis.to = top_circle.Center(); revsrf->m_angle[0] = revsrf->m_t[0] = 0.0; revsrf->m_angle[1] = revsrf->m_t[1] = 2.0*ON_PI; ON_Brep* tcone_brep = ON_BrepRevSurface(revsrf, TRUE, TRUE ); unsigned int first_sn = CRhinoObject::NextRuntimeObjectSerialNumber(); if( tcone_brep ) { CRhinoBrepObject* tcone_object = new CRhinoBrepObject(); tcone_object->SetBrep( tcone_brep ); if( context.m_doc.AddObject(tcone_object) ) context.m_doc.Redraw(); else delete tcone_object; } unsigned int next_sn = CRhinoObject::NextRuntimeObjectSerialNumber(); /*IF THE TWO ARE THE SAME, THEN NOTHING HAPPENED*/ if( first_sn == next_sn ) return CRhinoCommand::nothing; else { ON_wString obj_name = L"ugello"; SetNametoObject(context.m_doc,first_sn,obj_name,true); } ////// // CRhinoGetObject go; //go.SetCommandPrompt( L"Select edge of surface to extend" ); //go.SetGeometryFilter(CRhinoGetObject::edge_object); //go.SetGeometryAttributeFilter( CRhinoGetObject::edge_curve ); //go.GetObjects( 1, 1 ); //if( go.CommandResult() != CRhinoCommand::success ) // return go.CommandResult(); //const CRhinoObjRef& objref = go.Object(0); //const ON_Surface* srf = objref.Surface(); //if( !srf ) //{ // RhinoApp().Print( L"Unable to extend polysurfaces.\n" ); // return CRhinoCommand::nothing; //} //const ON_Brep* brep = objref.Brep(); //const ON_BrepFace* face = objref.Face(); //if( !brep | !face | face->m_face_index < 0 ) // return CRhinoCommand::failure; //if( !brep->IsSurface() ) //{ // RhinoApp().Print( L"Unable to extend trimmed surfaces.\n" ); // return CRhinoCommand::nothing; //} //const ON_BrepTrim* trim = objref.Trim(); //if( !trim ) // return CRhinoCommand::failure; //ON_Surface::ISO edge_index( trim->m_iso ); //int dir = edge_index % 2; //if( srf->IsClosed(1-dir) ) //{ // RhinoApp().Print(L"Unable to extend surface at seam.\n" ); // return CRhinoCommand::nothing; //} //if( edge_index < ON_Surface::W_iso | edge_index > ON_Surface::N_iso ) //{ // RhinoApp().Print( L"Selected edge must be an underlying surface edge.\n" ); // return CRhinoCommand::nothing; //} //ON_Surface* myface = srf->DuplicateSurface(); //if( !myface ) // return CRhinoCommand::failure; //bool rc = RhinoExtendSurface( myface, edge_index, 5.0, true); //if( rc ) //{ // ON_Brep* mybrep = new ON_Brep(); // mybrep->Create( myface ); // CRhinoBrepObject* obj = new CRhinoBrepObject(); // obj->SetBrep( mybrep ); // context.m_doc.ReplaceObject( CRhinoObjRef(objref.Object()), obj ); // context.m_doc.Redraw(); //} ///////// return CRhinoCommand::success; }
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 CCommandSampleConvertQuadsToTriangles::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select meshes to convert" ); go.SetGeometryFilter( CRhinoObject::mesh_object ); if( go.GetObjects(1,0) != CRhinoGet::object ) return CRhinoCommand::cancel; CRhinoGetOption gs; gs.AcceptNothing(); gs.SetCommandPrompt( L"Delete input?" ); gs.SetDefaultString( (m_delete_input)?L"Yes":L"No" ); int n_index = gs.AddCommandOption( RHCMDOPTNAME(L"No") ); int y_index = gs.AddCommandOption( RHCMDOPTNAME(L"Yes") ); switch( gs.GetOption() ) { case CRhinoGet::option: if( gs.Option()->m_option_index == n_index ) m_delete_input = false; else m_delete_input = true; break; case CRhinoGet::string: case CRhinoGet::nothing: break; default: return CRhinoCommand::cancel; } int num_converted = 0; for( int i = 0; i < go.ObjectCount(); i++ ) { CRhinoObjRef objref = go.Object(i); if( const CRhinoObject* pObject = objref.Object() ) { if( const ON_Mesh* pMesh = ON_Mesh::Cast(pObject->Geometry()) ) { ON_Mesh mesh(*pMesh); if( mesh.QuadCount() <= 0 ) continue; if( !mesh.ConvertQuadsToTriangles() ) continue; const CRhinoMeshObject* mesh_object = NULL; if( m_delete_input ) mesh_object = context.m_doc.ReplaceObject( objref, mesh ); else mesh_object = context.m_doc.AddMeshObject( mesh ); if( mesh_object ) num_converted++; } } } if( num_converted > 0 ) context.m_doc.Redraw(); RhinoApp().Print( L"%d meshes selected, %d meshes converted.\n", go.ObjectCount(), num_converted ); 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; }
CRhinoCommand::result CGenPianoVis::RunCommand( const CRhinoCommandContext& context ) { Cscript1PlugIn& plugin = script1PlugIn(); if( !plugin.IsDlgVisible() ) { return CRhinoCommand::nothing; } /*GET THE LAYER NAME*/ CRhinoGetString gs; gs.SetCommandPrompt( L"NAME OF LAYER WHICH CONTAINS VISIONAL PLANE : " ); gs.GetString(); if( gs.CommandResult() != CRhinoCommand::success ) { return gs.CommandResult(); } /*VALIDATE THE STRING*/ ON_wString layer_name = gs.String(); layer_name.TrimLeftAndRight(); if( layer_name.IsEmpty() ) { return CRhinoCommand::cancel; } /*GET A REFERENCE TO THE LAYER TABLE*/ CRhinoLayerTable& layer_table = context.m_doc.m_layer_table; /*FIND THE LAYER*/ int layer_index = layer_table.FindLayer(layer_name ); if( layer_index < 0 ) { RhinoApp().Print( L"LAYER \"%s\" DOES NOT EXIST.\n", layer_name ); } else { ON_Layer currentLayer; int numLayers = layer_table.LayerCount(); layer_table.SetCurrentLayerIndex(layer_index); for(int i = 0; i < numLayers; i++) { if(i != layer_index) { currentLayer = layer_table[i]; currentLayer.SetVisible(false); layer_table.ModifyLayer(currentLayer, i); } } context.m_doc.Redraw(); const CRhinoLayer& layer = context.m_doc.m_layer_table[layer_index]; ON_SimpleArray<CRhinoObject*> obj_list; int object_count = context.m_doc.LookupObject( layer, obj_list ); if( object_count > 0 ) { /********************************************************************/ //CRhinoObject* obj = obj_list[0]; //if( obj && obj->IsSelectable() ) //{ // obj->Select(true); // obj->Highlight(true); // m_doc.Redraw(); //} /********************************************************************/ //aniello gegin // Disable redrawing //CRhinoView::EnableDrawing( FALSE ); meglio tenerlo disabilitato altrimenti la schermata non si aggiorna. // Get the next runtime object serial number before scripting unsigned int first_sn = CRhinoObject::NextRuntimeObjectSerialNumber(); //aniello end ///////////////////// CRhinoGetObject gc; gc.SetCommandPrompt( L"SELECT LINE TO EXTEND" ); gc.SetGeometryFilter( CRhinoGetObject::curve_object ); gc.GetObjects( 1, 1 ); if(gc.CommandResult() == CRhinoCommand::success ) { const CRhinoObjRef& objref = gc.Object(0); const ON_Curve* pC = ON_Curve::Cast( objref.Geometry() ); ON_Curve* crv0 = pC->DuplicateCurve(); bool rc0 = RhinoExtendCurve(crv0, CRhinoExtend::Line, 1, 5); bool rc1 = RhinoExtendCurve(crv0, CRhinoExtend::Line, 0, 15); context.m_doc.ReplaceObject(objref, *crv0 ); context.m_doc.Redraw(); ///// begin prova memorizzazione id o name linea pv ////ON_UUID uuid1 = gc->Attributes().m_uuid; //// ON_UUID uuid1 = objref.ObjectUuid(); // //ON_UuidToString( uuid1, cvrPrima ); // const CRhinoObject* obj5 = objref.Object(); // ON_UUID uuid1 = obj5->Attributes().m_uuid; // pvcurva = uuid1; // ON_3dmObjectAttributes obj_attribs = obj5->Attributes(); // 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; // //ON_wString obj_name = (L"stringanome"); // obj_attribs.m_name = obj_name; // context.m_doc.ModifyObjectAttributes( objref, obj_attribs ); ///// end prova memorizzazione id o name linea pv ON_3dPoint p0 = crv0->PointAtStart(); ON_3dPoint p1 = crv0->PointAtEnd(); CRhinoGetNumber gn; //double default_value = 30; gn.SetCommandPrompt( L"ENTER ANTERIOR ANGLE FOR EXTENSION in grad: " ); gn.SetCommandPromptDefault(L"30"); gn.SetDefaultNumber(30); //gn.AcceptNothing(true); gn.GetNumber(); double alphaAngle = gn.Number(); gn.SetCommandPrompt( L"ENTER ANTERIOR LENGTH FOR EXTENSION in mm: " ); gn.SetCommandPromptDefault(L"80"); gn.SetDefaultNumber(80); gn.GetNumber(); double antLen = gn.Number(); gn.SetCommandPrompt( L"ENTER ANTERIOR FILLET RADIUS in mm: " ); gn.SetCommandPromptDefault(L"6"); gn.SetDefaultNumber(6); gn.GetNumber(); double antRad = gn.Number(); gn.SetCommandPrompt( L"ENTER POSTERIOR ANGLE FOR EXTENSION default <ALPHA + 10°= 40°> : " ); gn.SetCommandPromptDefault(L"40"); gn.SetDefaultNumber(40); gn.GetNumber(); double betaAngle = gn.Number(); gn.SetCommandPrompt( L"ENTER POSTERIOR LENGTH FOR EXTENSION in mm: " ); gn.SetCommandPromptDefault(L"80"); gn.SetDefaultNumber(80); gn.GetNumber(); double posLen = gn.Number(); gn.SetCommandPrompt( L"ENTER POSTERIOR FILLET RADIUS in mm: " ); gn.SetCommandPromptDefault(L"13"); gn.SetDefaultNumber(13); gn.GetNumber(); double posRad = gn.Number(); ON_3dPoint pointStart; ON_3dPoint pointEnd; //// Fillet radius //double radius = 1.0; // Do the fillet calculation double t0 = 0.0, t1 = 0.0; ON_Plane plane; plane.plane_equation.y = 1.0; pointStart = crv0->PointAtStart(); pointEnd = crv0->PointAtEnd(); ON_3dPoint point0((pointStart.x - posLen*cos(betaAngle*acos(-1.0)/180.0)), 0.0, (pointStart.z + posLen*sin(betaAngle*acos(-1.0)/180.0))); ON_3dPoint point1((pointEnd.x + antLen*cos(alphaAngle*acos(-1.0)/180.0)), 0.0, (pointEnd.z - antLen*sin(alphaAngle*acos(-1.0)/180.0))); /**********************************/ /*CREATE THE LINE CURVES TO FILLET*/ /**********************************/ ON_LineCurve curve0( pointStart, point0 ); //LINEA A SINISTRA IN FRONT VIEW ON_LineCurve curve1( point1, pointEnd ); //LINEA A DESTRA IN FRONT VIEW /***************************************************/ /*FILLET AT THE END/START POINTS OF THE LINE CURVES*/ /***************************************************/ double curve0_t = crv0->Domain().Max(); double curve1_t = curve1.Domain().Min(); ON_3dPoint PuntoAltezzaTacco = curve1.m_line.to; AltezzaTacco = PuntoAltezzaTacco; if( RhinoGetFilletPoints(curve1, *crv0, antRad, curve1_t, curve0_t, t1, t0, plane) ) { /*******************************/ /*TRIM BACK THE TWO LINE CURVES*/ /*******************************/ ON_Interval domain1( curve1.Domain().Min(), t1 ); curve1.Trim( domain1 ); ON_Interval domain0( crv0->Domain().Min(), t0 ); crv0->Trim( domain0 ); /**************************/ /*COMPUTE THE FILLET CURVE*/ /**************************/ ON_3dVector radial0 = curve1.PointAt(t1) - plane.Origin(); radial0.Unitize(); ON_3dVector radial1 = crv0->PointAt(t0) - plane.Origin(); radial1.Unitize(); double angle = acos( radial0 * radial1 ); ON_Plane fillet_plane( plane.Origin(), radial0, radial1 ); ON_Arc fillet( fillet_plane, plane.Origin(), antRad, angle ); /******************/ /*ADD THE GEOMETRY*/ /******************/ context.m_doc.AddCurveObject( curve1 ); context.m_doc.ReplaceObject(objref, *crv0 ); context.m_doc.AddCurveObject( fillet ); context.m_doc.Redraw(); } t0 = 0.0, t1 = 0.0; /*FILLET AT THE START POINTS OF THE LINE CURVES*/ curve0_t = crv0->Domain().Min(); curve1_t = curve0.Domain().Min(); if( RhinoGetFilletPoints(curve0, *crv0, posRad, curve1_t, curve0_t, t1, t0, plane) ) { // Trim back the two line curves ON_Interval domain0( t1, curve0.Domain().Max() ); curve0.Trim( domain0 ); ON_Interval domain1( t0, crv0->Domain().Max() ); crv0->Trim( domain1 ); /*COMPUTE THE FILLET CURVE*/ ON_3dVector radial0 = curve0.PointAt(t1) - plane.Origin(); radial0.Unitize(); ON_3dVector radial1 = crv0->PointAt(t0) - plane.Origin(); radial1.Unitize(); double angle = acos( radial0 * radial1 ); ON_Plane fillet_plane( plane.Origin(), radial0, radial1 ); ON_Arc fillet( fillet_plane, plane.Origin(), posRad, angle ); /*ADD THE GEOMETRY*/ context.m_doc.AddCurveObject( curve0 ); context.m_doc.ReplaceObject(objref, *crv0 ); context.m_doc.AddCurveObject( fillet ); context.m_doc.Redraw(); } /******************/ /*CLEAN UP OR LEAK*/ /******************/ delete crv0; crv0 = 0; // code temp // aniello begin // Get the next runtime object serial number after scripting unsigned int next_sn = CRhinoObject::NextRuntimeObjectSerialNumber(); // Enable redrawing //CRhinoView::EnableDrawing( TRUE ); // if the two are the same, then nothing happened /* if( first_sn == next_sn ) //return CRhinoCommand::nothing; return; */ //commento questo per far compilare :-) // The the pointers of all of the objects that were added during scripting ON_SimpleArray<const CRhinoObject*> objects; for( unsigned int sn = first_sn; sn < next_sn; sn++ ) { const CRhinoObject* obj = context.m_doc.LookupObjectByRuntimeSerialNumber( sn ); if( obj && !obj->IsDeleted() ) objects.Append( obj ); } /* // Sort and cull the list, as there may be duplicates if( objects.Count() > 1 ) { objects.HeapSort( CompareObjectPtr ); const CRhinoObject* last_obj = objects[objects.Count()-1]; for( int i = objects.Count()-2; i >= 0; i-- ) { const CRhinoObject* prev_obj = objects[i]; if( last_obj == prev_obj ) objects.Remove(i); else last_obj = prev_obj; } } */ // Do something with the list... for( int i = 0; i < objects.Count(); i++ ) { const CRhinoObject* obj = objects[i]; if( obj->IsSelectable(true) ) obj->Select( true ); } //aniello end //end code temp /*********************/ /*JOIN LINES TOGETHER*/ /*********************/ ON_SimpleArray<const ON_Curve*> lines; ON_SimpleArray<CRhinoObject*> objectsLine; ON_SimpleArray<ON_Curve*> output; double tolerance = context.m_doc.AbsoluteTolerance(); int LinesCount = context.m_doc.LookupObject( layer, objectsLine); if( LinesCount > 0 ) { for(int i = 0; i < LinesCount; i++) { const CRhinoCurveObject* curve_obj = CRhinoCurveObject::Cast( objectsLine[i] ); if( curve_obj ) { lines.Append(curve_obj->Curve()); } } } if( RhinoMergeCurves(lines, output, tolerance) ) { for(int i = 0; i < output.Count(); i++ ) { CRhinoCurveObject* crv = new CRhinoCurveObject; crv->SetCurve( output[i] ); if( context.m_doc.AddObject(crv) ) { crv->Select(); } else { delete crv; } } } /************************/ /*DELETE CHILDREN CURVES*/ /************************/ for(int i = 0; i < LinesCount; i++ ) { context.m_doc.DeleteObject(objectsLine[i]); } context.m_doc.Redraw(); /*************************/ /*END JOIN LINES TOGETHER*/ /*************************/ } }/*CHIUSURA IF( OBJECT_COUNT > 0 )*/ }/*CHIUSURA ELSE*/ return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleRemovePoints::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 CRhinoObjRef& obj_ref = go.Object(0); const CRhinoPointCloudObject* obj = CRhinoPointCloudObject::Cast( obj_ref.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; indices.QuickSort( &ON_CompareIncreasing<int> ); const CRhinoObjectAttributes& atts = obj->Attributes(); bool bColors = cloud.HasPointColors(); bool bNormals = cloud.HasPointNormals(); ON_PointCloud new_cloud; new_cloud.m_P.SetCapacity( index_count ); new_cloud.m_P.SetCount( index_count ); if( bColors ) { new_cloud.m_C.SetCapacity( index_count ); new_cloud.m_C.SetCount( index_count ); } if( bNormals ) { new_cloud.m_N.SetCapacity( index_count ); new_cloud.m_N.SetCount( index_count ); } ON_PointCloud dup_cloud( cloud ); dup_cloud.DestroyHiddenPointArray(); const int cloud_count = dup_cloud.PointCount(); int last_point_index = indices[indices.Count() - 1]; for( int i = cloud_count - 1; i >= 0; i-- ) { if( i == last_point_index ) { int last_array_index = indices.Count() - 1; new_cloud.m_P[last_array_index] = dup_cloud.m_P[i]; if( bColors ) new_cloud.m_C[last_array_index] = dup_cloud.m_C[i]; if( bNormals ) new_cloud.m_N[last_array_index] = dup_cloud.m_N[i]; dup_cloud.m_P.Remove( i ); if( bColors ) dup_cloud.m_C.Remove( i ); if( bNormals ) dup_cloud.m_N.Remove( i ); indices.Remove( last_array_index ); if( 0 == indices.Count() ) break; last_point_index = indices[indices.Count() - 1]; } } CRhinoPointCloudObject* new_cloud_obj = new CRhinoPointCloudObject( atts ); new_cloud_obj->SetPointCloud( new_cloud ); new_cloud.Destroy(); if( context.m_doc.AddObject(new_cloud_obj) ) { new_cloud_obj->Select(); } else { delete new_cloud_obj; return CRhinoCommand::failure; } dup_cloud.m_P.Shrink(); if( bColors ) dup_cloud.m_C.Shrink(); if( bNormals ) dup_cloud.m_N.Shrink(); CRhinoPointCloudObject* dup_cloud_obj = new CRhinoPointCloudObject( atts ); dup_cloud_obj->SetPointCloud( dup_cloud ); if( !context.m_doc.ReplaceObject(obj_ref, dup_cloud_obj) ) delete dup_cloud_obj; context.m_doc.Redraw(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleIntepCrvOnSrf::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject go; go.SetCommandPrompt( L"Select surface to draw curve on" ); go.SetGeometryFilter( CRhinoObject::surface_object); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); const CRhinoObject* obj = go.Object(0).Object(); const ON_BrepFace* face = go.Object(0).Face(); if( 0 == obj || 0 == face ) return CRhinoCommand::failure; ON_SimpleArray<ON_2dPoint> points2d(25); CRhinoGetPoint gp; gp.Constrain( *face, obj->Attributes().m_wire_density ); for(;;) { gp.ClearCommandOptions(); if( points2d.Count() < 1 ) gp.SetCommandPrompt( L"Start of curve" ); else if( points2d.Count() == 1 ) gp.SetCommandPrompt( L"Next point" ); else gp.SetCommandPrompt( L"Next point. Press Enter when done" ); gp.AcceptUndo( points2d.Count() > 0 ); gp.AcceptNothing(); CRhinoGet::result res = gp.GetPoint(); if( res == CRhinoGet::cancel) return CRhinoCommand::cancel; else if ( res == CRhinoGet::undo) { points2d.Remove(); // remove last point continue; } else if( res == CRhinoGet::point) { ON_2dPoint pt; if( gp.PointOnSurface(&pt.x, &pt.y) ) { int count = points2d.Count(); if( count > 0 ) { ON_2dVector v = *points2d.At(count-1) - pt; if ( v.IsTiny()) continue; } points2d.Append( pt ); } continue; } break; } const int count = points2d.Count(); if( count > 1) { // Check for closed curve int is_closed = 0; if( count > 3 ) { ON_2dPoint pt = points2d[0]; if( pt.DistanceTo(points2d[count-1]) < ON_SQRT_EPSILON ) is_closed = 1; } double tol = context.m_doc.AbsoluteTolerance(); ON_Curve* crv = RhinoInterpolatePointsOnSurface( *face, points2d, is_closed, tol, 1 ); if( crv ) { CRhinoCurveObject* crv_obj = new CRhinoCurveObject(); crv_obj->SetCurve( crv ); context.m_doc.AddObject( crv_obj ); context.m_doc.Redraw(); } return CRhinoCommand::success; } return CRhinoCommand::success; }
CRhinoCommand::result CCommandTestUVMesh::RunCommand( const CRhinoCommandContext& context ) { bool bDeleteInput = false; CRhinoGetObject go; go.SetCommandPrompt(L"Select untrimmed surface"); go.AddCommandOptionInteger(RHCMDOPTNAME(L"U"), &m_U, 0, 2); go.AddCommandOptionInteger(RHCMDOPTNAME(L"V"), &m_V, 0, 2); go.AddCommandOptionToggle(RHCMDOPTNAME(L"DeleteInput"), RHCMDOPTVALUE(L"No"), RHCMDOPTVALUE(L"Yes"), bDeleteInput, &bDeleteInput); go.SetGeometryFilter(CRhinoGetObject::surface_object); go.SetGeometryAttributeFilter(CRhinoGetObject::untrimmed_surface); CRhinoGet::result rs = CRhinoGet::no_result; while (CRhinoGet::cancel != rs && CRhinoGet::nothing != rs && CRhinoGet::object != rs) rs = go.GetObjects(1,1); if (CRhinoGet::cancel == rs) return CRhinoCommand::cancel; if (0 == go.ObjectCount()) return CRhinoCommand::failure; const CRhinoObject* pObj = go .Object(0).Object(); if (0 == pObj) return CRhinoCommand::failure; const ON_BrepFace* pBrepFace = go.Object(0).Face(); if (0 == pBrepFace) return CRhinoCommand::failure; const ON_Surface* pSurf = pBrepFace->SurfaceOf(); if (0 == pSurf) return CRhinoCommand::failure; ON_SimpleArray<double>UArray(m_U+1); ON_SimpleArray<double>VArray(m_V+1); double UDist, VDist; UDist = (pSurf->Domain(0).m_t[1]-pSurf->Domain(0).m_t[0])/m_U; VDist = (pSurf->Domain(1).m_t[1]-pSurf->Domain(1).m_t[0])/m_V; int i; for (i=0; i <= m_U; i++) UArray.Append(pSurf->Domain(0).m_t[0] + i*UDist); for (i=0; i <= m_V; i++) VArray.Append(pSurf->Domain(1).m_t[0] + i*VDist); //If m_U or m_V are large then there can be a slight difference between //pSurf->Domain(0).m_t[0] + (m_U-1)*UDist and pSurf->Domain(0).m_t[1] //ON_MeshSurface requires it to be less than or equal to pSurf->Domain(0).m_t[1] //05/24/06 TimH Fix for RR21194 double* d = UArray.Last(); if (pSurf->Domain(0).m_t[1] < *d) *d = pSurf->Domain(0).m_t[1]; d = VArray.Last(); if (pSurf->Domain(1).m_t[1] < *d) *d = pSurf->Domain(1).m_t[1]; ON_Mesh* pMeshOut = ON_MeshSurface(*pSurf, m_U+1, UArray.Array(), m_V+1, VArray.Array()); if (0 == pMeshOut) return CRhinoCommand::failure; CRhinoMeshObject* pMeshObj = new CRhinoMeshObject(pObj->Attributes()); if (0 == pMeshObj) { delete pMeshOut; return CRhinoCommand::failure; } pMeshObj->SetMesh(pMeshOut); if (true == bDeleteInput) context.m_doc.ReplaceObject(pObj, pMeshObj); else context.m_doc.AddObject(pMeshObj); context.m_doc.Redraw(); return CRhinoCommand::success; }
CRhinoCommand::result CCommandSampleGetPointOnMesh::RunCommand( const CRhinoCommandContext& context ) { // Pick a mesh CRhinoGetObject go; go.SetCommandPrompt( L"Select mesh" ); go.SetGeometryFilter( CRhinoGetObject::mesh_object ); go.GetObjects( 1, 1 ); if( go.CommandResult() != CRhinoCommand::success ) return go.CommandResult(); // Validate the pick const CRhinoMeshObject* mesh_object = CRhinoMeshObject::Cast( go.Object(0).Object() ); if( 0 == mesh_object ) return CRhinoCommand::failure; // Pick a point on the mesh ON_MESH_POINT point; int rc = RhinoGetPointOnMesh( mesh_object, L"Point on mesh", FALSE, point ); if( rc != 0 ) return CRhinoCommand::cancel; // Add the picked point and print results context.m_doc.AddPointObject( point.m_P ); RhinoApp().Print( L"Added point on face %d, with %g, %g, %g, %g as barycentric coordinates.\n", point.m_face_index, point.m_t[0], point.m_t[1], point.m_t[2], point.m_t[3] ); // Was the pick on a face? if( point.m_ci.m_type == ON_COMPONENT_INDEX::mesh_face ) { // Validate mesh if( point.m_mesh ) { ON_3dVector normal = ON_UNSET_POINT; // Does the mesh have face normals? if( point.m_mesh->HasFaceNormals() ) { // Get the face normal ON_3fVector normal = point.m_mesh->m_FN[point.m_ci.m_index]; } else { // Compute the face normal if( point.m_mesh->HasDoublePrecisionVertices() ) point.m_mesh->m_F[point.m_ci.m_index].ComputeFaceNormal( point.m_mesh->DoublePrecisionVertices().Array(), normal ); else point.m_mesh->m_F[point.m_ci.m_index].ComputeFaceNormal( point.m_mesh->m_V.Array(), normal ); } // Validate normal if( normal.IsValid() ) { // Add normal line, with arrow, and print results ON_Line line( point.m_P, point.m_P + normal ); ON_3dmObjectAttributes attributes; context.m_doc.GetDefaultObjectAttributes( attributes ); attributes.m_object_decoration = ON::end_arrowhead; context.m_doc.AddCurveObject( line, &attributes ); context.m_doc.Redraw(); ON_wString normal_str; RhinoFormatPoint( normal, normal_str ); RhinoApp().Print( L"Added line normal to face %d, with % as normal direction.\n", point.m_ci.m_index, normal_str ); } } } return CRhinoCommand::success; }