Пример #1
0
CRhinoCommand::result CCommandExposeSdk::RunCommand( const CRhinoCommandContext& context )
{
  // CCommandExposeSdk::RunCommand() is called when the user runs the "ExposeSdk"
  // command or the "ExposeSdk" command is run by a history operation.

  // TODO: Add command code here.

  // Rhino command that display a dialog box interface should also support
  // a command-line, or scriptable interface.

  ON_wString wStr;
  wStr.Format( L"The \"%s\" command is under construction.\n", EnglishCommandName() );
  if( context.IsInteractive() )
    RhinoMessageBox( wStr, PlugIn()->PlugInName(), MB_OK );
  else
	  RhinoApp().Print( wStr );

  // TODO: Return one of the following values:
  //   CRhinoCommand::success:  The command worked.
  //   CRhinoCommand::failure:  The command failed because of invalid input, inability
  //                            to compute the desired result, or some other reason
  //                            computation reason.
  //   CRhinoCommand::cancel:   The user interactively canceled the command 
  //                            (by pressing ESCAPE, clicking a CANCEL button, etc.)
  //                            in a Get operation, dialog, time consuming computation, etc.

  return CRhinoCommand::success;
}
void CTestRhinoDocPropsPage::OnBnClickedButton1()
{
  RhinoMessageBox( GetSafeHwnd(), L"Pick me button pressed", LocalPageTitle(), MB_OK );
}
void CMyRhinoDockBarDialog::OnBnClickedBtnok()
{
	RhinoMessageBox(L"CMyRhinoDockBarDialog::OnBnClickedBtnok()", L"Hello!" ,MB_OK);
}
Пример #4
0
CRhinoCommand::result CGenCylinder::RunCommand( const CRhinoCommandContext& context )
{

	Cscript1PlugIn& plugin = script1PlugIn();
	if( !plugin.IsDlgVisible() )
	{
		return CRhinoCommand::nothing;
	}

	/*****************************************/
	/*CHECKING IF THERE IS ALREADY A CYLINDER*/
	/*****************************************/
	const CRhinoLayer& layer = context.m_doc.m_layer_table.CurrentLayer();
	ON_SimpleArray<CRhinoObject*> objects;
	int object_count = context.m_doc.LookupObject( layer, objects );
	const CRhinoBrepObject* brep_obj;
	const CRhinoCurveObject* curve_obj;
	const CRhinoSurfaceObject* surface_obj;
	int surf_count=0;
	if( object_count > 0 )
	{
		int brep_obj_count = 0;
		int polycurve_count = 0;
		const CRhinoObject* object = 0;
		for(int i = 0; i < object_count; i++ )
		{
			object = objects[ i ];
			/************************************/
			/*TRY CASTING AS A RHINO BREP OBJECT*/ 
			/************************************/
			brep_obj = CRhinoBrepObject::Cast( object );
			if( brep_obj && object->IsSolid())
			{
				brep_obj_count++;
			}
			/*******************************/
			/*TRY CASTING AS A CURVE OBJECT*/ 
			/*******************************/
			curve_obj = CRhinoCurveObject::Cast( object );
			if( curve_obj )
			{
				polycurve_count++;
			}
			//surface_obj = CRhinoSurfaceObject::Cast( object );
		 //   if( surface_obj )
		 //   {
			//surf_count++;
		 //   }
		}
		if( brep_obj_count == 0)
		{
			ON_3dPoint center_point( 0.0, 0.0, 0.0 );
			double radius = 63.5;
			int __count = plugin.m_dialog->m_comboAltTacco.GetCount();

			int nIndex = plugin.m_dialog->m_comboAltTacco.GetCurSel();
			CString strCBText;
			plugin.m_dialog->m_comboAltTacco.GetLBText( nIndex, strCBText);
			int height = _wtoi(strCBText);


			ON_3dPoint height_point( 0.0, 0.0, height);
			ON_3dVector zaxis = height_point - center_point;
			ON_Plane planeCir( center_point, zaxis );

			/*ADD CIRCLE FOR CYLINDER'S BASE*/
			ON_Circle circle( planeCir, radius );

			/*ADD CYLINDER*/
			ON_Cylinder cylinder( circle, zaxis.Length() );
			ON_Brep* brep = ON_BrepCylinder( cylinder, TRUE, TRUE );
			unsigned int first_SN;
			unsigned int next_SN;
			if( brep )
			{
				first_SN = CRhinoObject::NextRuntimeObjectSerialNumber();
				/********************/
				/*TRANSLATE CYLINDER*/
				/********************/
				int nIndex1 = plugin.m_dialog->AltezzaFondelloControllo.GetCurSel();
				CString strCBText1;
				plugin.m_dialog->AltezzaFondelloControllo.GetLBText( nIndex1, strCBText1);
				int altfondello = _wtoi(strCBText1);
				ON_wString obj_nameCyl = L"CILINDRO";
								
				
				brep->Translate(ON_3dVector( 0.0, 0.0, -altfondello));
				CRhinoBrepObject* cylinder_object = new CRhinoBrepObject();
				cylinder_object->SetBrep( brep );
				if( context.m_doc.AddObject(cylinder_object) )
				{
					context.m_doc.Redraw();
					next_SN = CRhinoObject::NextRuntimeObjectSerialNumber();
					if( first_SN == next_SN )
					{
						return CRhinoCommand::nothing;
					}
					else
					{
						SetNametoObject(context.m_doc,first_SN,obj_nameCyl,true);			  
					}
				}
				else
				{
					delete cylinder_object;
				}

				/*********************************************/
				/*               DA SISTEMARE                */
				/*********************************************/
				
				CRhinoSnapContext snap;
				bool dec1 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, (height - altfondello)));
				bool dec2 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, -altfondello));
				bool dec3 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, 0.0));
				if(dec1 && dec2)
				{
					CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
					ON_Plane plane( ON_zx_plane );
					plane.SetOrigin( ON_3dPoint(63.5, 0.0, 0.0) );
					dim_obj->SetPlane( plane );
					ON_3dPoint pt_1(63.5, 0.0, (height - altfondello));
					ON_3dPoint pt_2(63.5, 0.0, -altfondello);

					double u, v;
					plane.ClosestPointTo( pt_1, &u, &v );
					dim_obj->SetPoint( 0, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) );


					plane.ClosestPointTo( pt_2, &u, &v );
					dim_obj->SetPoint( 2, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) );

					dim_obj->UpdateText();
					 
					if( context.m_doc.AddObject(dim_obj) )
					{
						context.m_doc.Redraw();
					}		
					else
					{
						delete dim_obj;
					}
				}
				/*********************************************/
				/*               DA SISTEMARE                */
				/*********************************************/
				if(dec2 && dec3)
				{
					CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
					ON_Plane plane( ON_zx_plane );
					plane.SetOrigin( ON_3dPoint(63.5, 0.0, 0.0) );
					dim_obj->SetPlane( plane );
					ON_3dPoint pt_1(63.5, 0.0, 0.0);
					ON_3dPoint pt_2(63.5, 0.0, -altfondello);

					double u, v;
					plane.ClosestPointTo( pt_1, &u, &v );
					dim_obj->SetPoint( 0, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) );


					plane.ClosestPointTo( pt_2, &u, &v );
					dim_obj->SetPoint( 2, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) );

					dim_obj->UpdateText();
					 
					if( context.m_doc.AddObject(dim_obj) )
					{
						context.m_doc.Redraw();
					}		
					else
					{
						delete dim_obj;
					}
				}
				/*********************************************/
				/*               DA SISTEMARE  By Nello              */
				/*********************************************/
				
				ON_3dPoint provapunto2 = AltezzaTacco;
				ON_3dPoint provapunto(59.5,0,provapunto2.z);
				provapunto.z-=0.7;
				ON_3dPoint pt_1(59.5, 0.0, (height - altfondello));
				CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
					ON_Plane plane( ON_zx_plane );
					plane.SetOrigin(pt_1);
					dim_obj->SetPlane( plane );
					//ON_3dPoint pt_1(63.5, 0.0, 0.0);
					ON_3dPoint pt_2 = provapunto;

					double u, v;
					plane.ClosestPointTo( pt_1, &u, &v );
					dim_obj->SetPoint( 0, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) );


					plane.ClosestPointTo( pt_2, &u, &v );
					dim_obj->SetPoint( 2, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) );

					dim_obj->UpdateText();
					 
					if( context.m_doc.AddObject(dim_obj) )
					{
						context.m_doc.Redraw();
					}		
					else
					{
						delete dim_obj;
					}
				
					/*INIZIO FUNZIONE CONTROLLO*/
			
					if ( (height - altfondello)>=provapunto.z+10){
						::RhinoApp().Print( L"Funzione controllo altezza OK");
					}
					else{
						::RhinoApp().Print( L"Funzione controllo altezza NOK: CONTROLLARE!! Il valore della testa e' minore del valore minimo di 10 mm. Occorre diminuire l'altezza del fondello o aumentare l'altezza dello stampo.");
					}


				/*********************************************/
				/*           CREATE FONDELLO PLANE           */
				/*********************************************/

				ON_3dPoint point0((63.5 + 20.0),0.0, 0.0);
				ON_3dPoint point1(-(63.5 + 20.0),0.0, 0.0);
				ON_LineCurve curve0( point0, point1 );

				context.m_doc.AddCurveObject(curve0);
				context.m_doc.Redraw();


				/******************************************************/
				/*****************************/
				/*USER GIVES NAME TO SURFACES*/ 
				/*****************************/
				unsigned int first_sn;
				unsigned int next_sn;
				ON_wString obj_name;
				object_count = context.m_doc.LookupObject( layer, objects );
				for(int i = 0; i < object_count; i++ )
				{
					object = objects[ i ];
					first_sn = CRhinoObject::NextRuntimeObjectSerialNumber();

					/*******************************/
					/*TRY CASTING AS A CURVE OBJECT*/ 
					/*******************************/
					curve_obj = CRhinoCurveObject::Cast( object );
					if( curve_obj )
					{
						const ON_Geometry* geo = curve_obj->Geometry();
						const ON_Curve* curve00 = ON_Curve::Cast(geo); 
						ON_3dPoint point  = curve00->PointAt(0.0);
						ON_3dPoint point_ = curve00->PointAt(1.0);
						if((point.z + point_.z)/2 > 0.0)
						{
							obj_name = L"SURFPV";
						}
						else
						{
							obj_name = L"SURFFO";
						}
						ON_3dPoint point0(point.x, (point.y + 70.0), point.z);
						ON_3dPoint point1(point.x, (point.y - 70.0), point.z);
						ON_LineCurve* curve = new ON_LineCurve();
						curve->SetStartPoint(point0);
						curve->SetEndPoint(point1);
						ON_SumSurface sumSurf0;
						sumSurf0.Create(*curve, *curve00);

						if( context.m_doc.AddSurfaceObject(sumSurf0) )
						{

							context.m_doc.Redraw();
							next_sn = CRhinoObject::NextRuntimeObjectSerialNumber();
							if( first_sn == next_sn )
							{
								return CRhinoCommand::nothing;
							}
							else
							{
								SetNametoObject(context.m_doc,first_sn,obj_name,true);			  
							}
						}

					}
				}/*CLOSED FOR*/

				//int R = 0;
				//object_count = context.m_doc.LookupObject( layer, objects );
				//for(int i = 0; i < object_count; i++)
				//{
				//	object = objects[ i ];
				//	const CRhinoCurveObject* surface_obj = CRhinoCurveObject::Cast(object);
				//	if(surface_obj)
				//	{
				//		R++;
				//	}
				//}

				 // // Get the string entered by the user
				 // ON_wString obj_name = gs.String();
				 // obj_name.TrimLeftAndRight();
				 //
				 // // Is name the same?
				 // if( obj_name.Compare(obj_attribs.m_name) == 0 )
					//return CRhinoCommand::nothing;
				 //
				 // // Modify the attributes of the object
				 // obj_attribs.m_name = obj_name;
				 // context.m_doc.ModifyObjectAttributes( objref, obj_attribs );
				 // if(selectobjectbyuuid_s(context.m_doc,obj_Surf[j],false))
				 // {
					//int R = 0;
				 // }



			  
			  ON_wString obj_Surf[2];
			  ON_wString name;
              obj_Surf[0] = L"SURFPV";
			  obj_Surf[1] = L"SURFFO";
			  object_count = context.m_doc.LookupObject( layer, objects );
			  int R = 0;
			  /************************/
			  /*TRY SPLITTING THE BREP*/
			  /************************/
			  for(int j = 0; j < 2; j++)
			  {
				  for(int i = 0; i < object_count; i++)
				  {
					  object = objects[ i ];

					  /*MAKE COPY OF OBJECT ATTRIBUTES. THIS OBJECTS*/ 
					  /*HOLDS AN OBJECT'S USER-DEFINED NAME.*/ 
					  ON_3dmObjectAttributes obj_attribs = object->Attributes();
			
					  name = object->Attributes().m_name;

					  surface_obj = CRhinoSurfaceObject::Cast( object );
					  if( surface_obj && !surface_obj->IsSolid())
					  {
						  ON_wString obj_SurfLoc = obj_Surf[j];

						  /*IS THE CUTTING SURFACE?*/
						  if( obj_SurfLoc.Compare(name) == 0 )
						  {							
							R++;
						  }
					  }/*CHIUSURA IF SUPERFICIE*/
				  } 
				 

				 // /************************/
				 // /*PICK THE BREP TO SPLIT*/ 
				 // /************************/
				 // CRhinoGetObject go;
				 // go.SetCommandPrompt( L"SELECT SOLID TO SPLIT" );
				 // go.SetGeometryFilter( CRhinoGetObject::polysrf_object  );//CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object 
				 // go.GetObjects( 1, 1 );
				 // if( go.CommandResult() != success )
				 // {
					//return go.CommandResult();
				 // }
				 // else
				 // {
					//	RhinoMessageBox(L"CYLINDER IS SELECTED", PlugIn()->PlugInName(), MB_OK | MB_ICONEXCLAMATION );
				 // }
				 //
				 // const CRhinoObjRef& split_ref = go.Object(0);
				 //
				 // const CRhinoObject* split_object = split_ref.Object();
				 // if( !split_object )
				 // {
					//return failure;
				 // }
				 //
				 // const ON_Brep* split = split_ref.Brep();
				 // if( !split )
				 // {
					//return failure;
				 // }

				 // ON_SimpleArray<ON_Brep*> pieces;
				 // double tol = context.m_doc.AbsoluteTolerance();
			 
				 // /***********************/
				 // /*PICK THE CUTTING BREP*/
				 // /***********************/
				 // go.SetCommandPrompt( L"SELECT CUTTING SURFACE OR POLYSUFACE" );
				 // go.SetGeometryFilter( CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object  ); 
				 // go.EnablePreSelect( FALSE );
				 // go.EnableDeselectAllBeforePostSelect( FALSE );
				 // go.GetObjects( 1, 2 );
				 // if( go.CommandResult() != success )
				 // {
					//return go.CommandResult();
				 // }

				 // const ON_Brep* cutter = go.Object(0).Brep();
				 // if( !cutter )
				 // {
					//return failure;
				 // }
				 //

				 // if( !RhinoBrepSplit(*split, *cutter, tol, pieces) )
				 // {
					//RhinoApp().Print( L"UNABLE TO SPLIT BREP.\n" );
				 // }
				 //
				 // int i, count = pieces.Count();
				 // if( count == 0 | count == 1 )
				 // {
					//if( count == 1 )
					//{
					//  delete pieces[0];
					//}
					//return nothing;
				 // }
				 //
				 // CRhinoObjectAttributes attrib = split_object->Attributes();
				 // attrib.m_uuid = ON_nil_uuid; 
				 //
				 // const CRhinoObjectVisualAnalysisMode* vam_list = split_object->m_analysis_mode_list;
				 //
				 // for( i = 0; i < count; i++ )
				 // {
					//CRhinoBrepObject* brep_object = new CRhinoBrepObject( attrib );
					//if( brep_object )
					//{
					//  brep_object->SetBrep( pieces[i] );
					//  if( context.m_doc.AddObject(brep_object) )
					//  {
					//	RhinoCopyAnalysisModes( vam_list, brep_object );

					//  }
					//  else
					//  {
					//	delete brep_object;
					//  }
					//}
				 // }
				 //
				 // context.m_doc.DeleteObject( split_ref ); 
				 // context.m_doc.Redraw();
			  }



		    /*CREATE A NEW LAYER*/
			  ON_Layer layer;
			  int layer_index = 0;
			  ON_Color color = ON_Color(0, 0, 0);
			  ON_wString layer_name_FONDELLO = L"FONDELLO";
			  layer.SetLayerName( layer_name_FONDELLO );
			  layer.SetPlotColor(color.Green());

			/*ADD THE LAYER TO THE LAYER TABLE*/ 
			  layer_index = context.m_doc.m_layer_table.AddLayer( layer );

			  ON_wString layer_name_MATRICE  = L"MATRICE";
			  layer.SetLayerName( layer_name_MATRICE );
			  layer.SetColor(color.Red());

			/*ADD THE LAYER TO THE LAYER TABLE*/ 
			  layer_index = context.m_doc.m_layer_table.AddLayer( layer );


			  ON_wString layer_name_FISSO    = L"FISSO";
			  layer.SetLayerName( layer_name_FISSO );
			  layer.SetColor(color.Blue());

			/*ADD THE LAYER TO THE LAYER TABLE*/ 
			  layer_index = context.m_doc.m_layer_table.AddLayer( layer );
	  
			  context.m_doc.Redraw();
			/*********************************************************/
			}
		}/*CLOSED IF OVER CHECKING BREP COUNT OBJECT*/
		else
		{
			RhinoMessageBox(L"THERE IS ALREADY A CYLINDER OBJECT", PlugIn()->PlugInName(), MB_OK | MB_ICONEXCLAMATION );
		}
	}
	/**********************************************************************/



  return CRhinoCommand::success;
}