Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:transformbrep [2015/09/14] (current)
Line 1: Line 1:
 +====== Transforming Brep Objects ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to transform brep, or boundary representation,​ objects. //
  
 +======C++======
 +===== Method 1 - The Short Way=====
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select brep" );
 +  go.SetGeometryFilter( ON::​brep_object );
 +  go.GetObjects(1,​1);​
 +  if( go.CommandResult() != success )
 +    return go.CommandResult();​
 +
 +  CRhinoObjRef ref = go.Object(0);​
 +
 +  // Simple translation transformation
 +  ON_Xform xform;
 +  xform.Translation( ON_3dVector(18,​-18,​-25) );
 +
 +  context.m_doc.TransformObject( ref, xform );
 +  context.m_doc.Redraw();​
 +
 +  return success;
 +}
 +
 +</​code>​
 +
 +=====Method 2 - The Long Way=====
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CRhinoGetObject go; 
 +  go.SetCommandPrompt( L"​Select brep" ); 
 +  go.SetGeometryFilter( ON::​brep_object ); 
 +  go.GetObjects(1,​1);​
 +  if( go.CommandResult() != success )
 +    return go.CommandResult();​
 +
 +  const CRhinoObjRef&​ ref = go.Object(0);​
 +  const CRhinoObject* obj = ref.Object();​
 +  if( !obj )
 +    return failure;
 +  const ON_Brep* brep = ref.Brep();
 +  if( !brep )
 +    return failure;
 +  ON_Brep* dupe = brep->​Duplicate();​
 +  if( !dupe )
 +    return failure;
 +
 +  // Simple translation transformation
 +  ON_Xform xform;
 +  xform.Translation( ON_3dVector(18,​-18,​-25) );
 +
 +  if( !dupe->​Transform( xform ) )
 +  {
 +    RhinoApp().Print( L"​Unable to transform object.\n"​ );
 +    delete dupe;
 +    return failure;
 +  }
 +
 +  ON_3dmObjectAttributes attribs = obj->​Attributes();​
 +  context.m_doc.AddBrepObject( *dupe, &​attribs );
 +
 +  // Since CRhinoDoc::​AddBrepObject() make a copy of the input
 +  // brep, we are responsible for deleting the original. Otherwise
 +  // we will leak memory;
 +  delete dupe;
 +  // Delete the selected object
 +  context.m_doc.DeleteObject( ref );
 +  context.m_doc.Redraw();​
 +  return success;
 +}
 +
 +</​code>​
 +
 +{{tag>​Developer cplusplus}}
developer/sdksamples/transformbrep.txt ยท Last modified: 2015/09/14 (external edit)