| McNeel Wiki | |||||
| edit · print · help · all topics | |||||
Main Pages
Languages
| OverviewCurve objects can be added to Rhino by using the following functions found on CRhinoDoc:
For CRhinoDoc::AddCurveObject, there are six overridden versions that will make curve objects from a variety of inputs, including:
ExamplesThe following code samples will demonstrate three different ways of adding curves to Rhino. In these examples, we will create circle curves. But, there is no reason that we could create lines, polylines, arcs or any other type of curve. Example 1In this example, we define a circle, using ON_Circle, and pass the definition off to CRhinoDoc::AddCurveObject. ON_3dPoint center(0.0, 0.0, 0.0); double radius = 10.0; ON_Circle circle( center, radius ); CRhinoCurveObject* curve_object = context.m_doc.AddCurveObject( circle ); context.m_doc.Redraw(); Example 2In this example, we first define a circle. Then we create an ON_ArcCurve object from the circle definition. ON_ArcCurve is one of the many curve classes this is derived from ON_Curve. We then pass the ON_ArcCurve object off to CRhinoDoc::AddCurveObject. ON_3dPoint center(0.0, 0.0, 0.0); double radius = 10.0; ON_Circle circle( center, radius ); ON_ArcCurve arc_curve( circle ); CRhinoCurveObject* curve_object = context.m_doc.AddCurveObject( arc_curve ); context.m_doc.Redraw(); Example 3In this example, we will add a circle curve the brute force way. We first define a circle. Then we allocate a new ON_ArcCurve and pass the circle definition to its constructor. We then allocate a new CRhinoCurveObject and assign our ON_ArcCurve object pointer to it. Finally, we pass the pointer to the CRhinoCurveObject to CRhinoDoc::AddObject.
ON_3dPoint center(0.0, 0.0, 0.0);
double radius = 10.0;
ON_Circle circle( center, radius );
ON_ArcCurve* arc_curve = new ON_ArcCurve( circle );
if( arc_curve )
{
CRhinoCurveObject* curve_object = new CRhinoCurveObject();
if( curve_object )
{
// Set the curve to the curve object. Note,
// curve_object will delete arc_curve.
curve_object->SetCurve( arc_curve );
if( context.m_doc.AddObject(curve_object) )
context.m_doc.Redraw();
else
delete curve_object;
}
}
DiscussionWhat is interesting to note is that the code found in Example 3 is essentally what Rhino does inside of CRhinoDoc::AddCurveObject. All of the CRhinoDoc::AddCurveObject overrides are simply provided to make it easier for SDK developers to add curves to Rhino. | ||||
| rename · changes · history · subscriptions · lost and found · references · file upload | |||||