Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:gettextdot [2015/09/14] (current)
Line 1: Line 1:
 +====== Picking Text Dots with CRhinoGetObject ======
 +====== C++, .NET ======
 +> **Version:​** //Rhino 4.0//
 +> **Summary:​** //​Demonstrates how to interactively select Text Dot objects with CRhinoGetObject.//​
 +
 +=====Question=====
 +I would like to allow the user to interactively select text dot objects from my plug-in command. But, I do not see a text dot geometry filter available for the CRhinoGetObject class. Is this possible?
 +
 +=====Answer=====
 +If CRhinoGetObject does not have filters to select what you want, then simply derive a new class from CRhinoGetObject and override the CustomGeometryFilter virtual function. From within this function, simply return true if the object meets your selection criteria.
 +
 +=====Example=====
 +The following example code demonstrates how to derive a new class from CRhinoGetObject and override the CustomGeometryFilter virtual function in order to allow for selection of just text dot objects. That is, those objects whose geometry member is ON_TextDot.
 +
 +===== C++ =====
 +<code c++>
 +
 +class CGetTextDotObject : public CRhinoGetObject
 +{
 +  bool CustomGeometryFilter(
 +const CRhinoObject* object,
 +const ON_Geometry* geometry,
 +ON_COMPONENT_INDEX component_index
 +) const;
 +};
 +
 +bool CGetTextDotObject::​CustomGeometryFilter(
 +    const CRhinoObject* object,
 +    const ON_Geometry* geometry,
 +    ON_COMPONENT_INDEX component_index
 +    ) const
 +{
 +  bool rc = false;
 +  if( geometry )
 +  {
 +    const ON_TextDot* p = ON_TextDot::​Cast( geometry );
 +    if( p )
 +      rc = true;
 +  }
 +  return rc;
 +}
 +
 +</​code>​
 +===== C# =====
 +<code c#>
 +
 +public class GetTextDotObject : RMA.Rhino.MRhinoGetObject
 +{
 +  public override bool CustomGeometryFilter(
 +IRhinoObject rh_object, ​
 +IOnGeometry geometry, ​
 +OnCOMPONENT_INDEX component_index
 +)
 +  {
 +    bool rc = false;
 +    IOnTextDot dot = OnTextDot.ConstCast(geometry);​
 +    if( dot != null )
 +      rc = true;
 +    return rc;
 +  }
 +}
 +
 +</​code>​
 +=====Usage=====
 +The following example code demonstrates how you can use the new class.
 +
 +===== C++ =====
 +<code c++>
 +
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CGetTextDotObject go;
 +  go.SetCommandPrompt( L"​Select text dots" );
 +  go.GetObjects( 1, 0 );
 +  if( go.CommandResult() != success )
 +    return go.CommandResult();​
 +
 +  const int object_count = go.ObjectCount();​
 +  int i;
 +  for( i = 0; i < object_count;​ i++ )
 +  {
 +    const ON_TextDot* p = ON_TextDot::​Cast( go.Object(i).Geometry() );
 +    if( p )
 +    {
 +      ON_wString sPoint;
 +      RhinoFormatPoint( p->​m_point,​ sPoint );
 +      RhinoApp().Print( L"​TextDot%d:​ point = (%s), text = \"​%s\"​\n", ​
 +  i, sPoint, p->​m_text );
 +    }
 +  }
 +
 +  return success;
 +}
 +
 +</​code>​
 +===== C# =====
 +<code c#>
 +
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  GetTextDotObject go = new GetTextDotObject();​
 +  go.SetCommandPrompt( "​Select text dots" );
 +  go.GetObjects( 1, 0 );
 +  if( go.CommandResult() != IRhinoCommand.result.success )
 +  return go.CommandResult();​
 +
 +  int object_count = go.ObjectCount();​
 +  int i = 0;
 +  for( i = 0; i < object_count;​ i++ )
 +  {
 +    IOnTextDot dot = OnTextDot.ConstCast(go.Object(i).Geometry());​
 +    if (dot != null)
 +    {
 +      string sPoint = ;
 +      RMA.Rhino.RhUtil.RhinoFormatPoint( dot.m_point,​ ref sPoint );
 +      RhUtil.RhinoApp().Print(string.Format("​TextDot{0}:​ point = ({1}), text = \"​{2}\"​\n", ​
 +  i, sPoint,​dot.m_text));​
 +    }
 +  }
 +
 +  return IRhinoCommand.result.success;​
 +}
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/gettextdot.txt ยท Last modified: 2015/09/14 (external edit)