CRhinoCommand::result CCommandSamplePolyline::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoCommand::result rc = CRhinoCommand::nothing;
  ON_Polyline pline;

  if( context.IsInteractive() )
  {
    // Our way...
	  CGetPolylinePoints gp;
    int count = gp.GetPoints();
    if( count > 1 )
    {
      pline = gp.m_point_array;
      if( pline.IsValid() )
        rc = CRhinoCommand::success;
    }
  }
  else
  {
    // The Rhino way...
    CArgsRhinoGetPolyline args;
    args.SetFirstPointPrompt( L"Start of polyline" );
    args.SetSecondPointPrompt( L"Next point of polyline" );
    rc = RhinoGetPolyline( args, pline );
  }

  if( rc == CRhinoCommand::success )
  {
    context.m_doc.AddCurveObject( pline );
    context.m_doc.Redraw();
  }

	return rc;
}
Esempio n. 2
0
RH_C_FUNCTION ON_SimpleArray<ON_Polyline*>* ON_Intersect_MeshMesh1(const ON_Mesh* pConstMeshA, const ON_Mesh* pConstMeshB, int* polyline_count, double tolerance)
{
  ON_SimpleArray<ON_Polyline*>* rc = NULL;
  if( polyline_count ) *polyline_count = 0;
  if( pConstMeshA && pConstMeshB && polyline_count )
  {
    ON_ClassArray<ON_MMX_Polyline> plines;
    ON_ClassArray<ON_MMX_Polyline> overlapplines;
    if(::ON_MeshMeshIntersect(pConstMeshA, pConstMeshB, plines, overlapplines, tolerance, tolerance))
    {
      rc = new ON_SimpleArray<ON_Polyline*>();
      for( int i=0; i<plines.Count(); i++ )
      {
        ON_Polyline* pl = new ON_Polyline();
        const ON_MMX_Polyline& mmxpoly = plines[i];
        int c = mmxpoly.Count();
        for( int j=0; j<c; j++ )
          pl->Append(mmxpoly[j].m_A.m_P);
        pl->Clean(ON_ZERO_TOLERANCE);
        if( !pl->IsValid() )
        {
          delete pl;
          continue;
        }
        rc->Append(pl);
      }
      for( int i=0; i<overlapplines.Count(); i++ )
      {
        ON_Polyline* pl = new ON_Polyline();
        const ON_MMX_Polyline& mmxpoly = overlapplines[i];
        int c = mmxpoly.Count();
        for( int j=0; i<c; i++ )
          pl->Append(mmxpoly[j].m_A.m_P);
        pl->Clean(ON_ZERO_TOLERANCE);
        if( !pl->IsValid() )
        {
          delete pl;
          continue;
        }
        rc->Append(pl);
      }
      *polyline_count = rc->Count();
    }
  }
  return rc;
}