Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:addcurve [2015/09/14] (current)
Line 1: Line 1:
 +====== Adding Curve Objects ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //Discusses how to add curve objects to Rhino using the Rhino C++ SDK.//
 +
 +=====Overview=====
 +Curve objects can be added to Rhino by using the following functions found on CRhinoDoc:
 +
 +  - CRhinoDoc::​AddCurveObject
 +  - CRhinoDoc::​AddObject
 +
 +For CRhinoDoc::​AddCurveObject,​ there are six overridden versions that will make curve objects from a variety of inputs, including:
 +
 +  - ON_Line - line definition objects
 +  - ON_Polyline - polyline definition objects
 +  - ON_Arc - arc definition objects
 +  - ON_Circle - circle definition objects
 +  - ON_BezierCurve - bezier curve objects
 +  - ON_Curve - ON_Curve-derived curve objects
 +
 +=====Examples=====
 +The 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 1=====
 +In this example, we define a circle, using ON_Circle, and pass the definition off to CRhinoDoc::​AddCurveObject.
 +
 +<code c++>
 +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();​
 +
 +</​code>​
 +===== Example 2=====
 +In 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.
 +
 +
 +<code c++>
 +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();​
 +
 +</​code>​
 +===== Example 3=====
 +In 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.
 +
 +
 +<code c++>
 +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;​
 +  }
 +}
 +
 +</​code>​
 +=====Discussion=====
 +What 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.
 +
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/addcurve.txt ยท Last modified: 2015/09/14 (external edit)