示例#1
0
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;



	  
}
示例#2
0
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;


}