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; }
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 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 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 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 CTraslRuota::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; ON_Layer currentLayer; int numLayers = layer_table.LayerCount(); for(int i = 0; i < numLayers; i++) { currentLayer = layer_table[i]; const CRhinoLayer& layer = layer_table[i]; currentLayer.SetVisible(true); layer_table.ModifyLayer(currentLayer, i); layer_table.SetCurrentLayerIndex(i); const CRhinoLayer& current_layer = layer_table.CurrentLayer(); int layer_index = layer_table.CurrentLayerIndex(); const CRhinoLayer& layer2 = layer_table[layer_index]; ON_SimpleArray<CRhinoObject*> obj_list; int j, obj_count = context.m_doc.LookupObject( layer2, obj_list ); for( j = 0; j < obj_count; j++ ) { CRhinoObject* obj = obj_list[j]; if( obj && obj->IsSelectable() ) obj->Select(); if( obj_count ) context.m_doc.Redraw(); } } context.m_doc.Redraw(); //inizio rotazione double m_angle=(_wtof(plugin.m_dialog->ValoreRotazione)); ON_Plane plane = RhinoActiveCPlane(); CRhinoGetObject go1; go1.GetObjects( 1, 0 ); int numero1 = go1.ObjectCount(); for( int k = 0; k < go1.ObjectCount(); k++ ) { // Get an object reference const CRhinoObjRef& ref = go1.Object(k); // Get the real object const CRhinoObject* obj = ref.Object(); if( !obj ) continue; ON_Xform xform; xform.Rotation( m_angle * ON_PI / 180.0, plane.zaxis, plane.Origin() ); context.m_doc.TransformObject( obj, xform, true, true, true ); context.m_doc.Redraw(); } //fine rotazione //inizio traslazione CRhinoGetObject go; int numero = go.ObjectCount(); go.GetObjects( 1, 0 ); for( int i = 0; i < go.ObjectCount(); i++ ) { // Get an object reference const CRhinoObjRef& ref = go.Object(i); // Get the real object const CRhinoObject* obj = ref.Object(); if( !obj ) continue; ON_Xform xform; xform.Rotation( m_angle * ON_PI / 180.0, plane.zaxis, plane.Origin() ); //context.m_doc.TransformObject( obj, xform, true, true, true ); context.m_doc.Redraw(); xform.Translation((_wtof(plugin.m_dialog->ValoreTraslazione)),0,0); context.m_doc.TransformObject( obj, xform, true, true, true ); context.m_doc.Redraw(); } // fine traslazione context.m_doc.Redraw(); 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; }