CRhinoCommand::result CCommandSampleDimLinear2::RunCommand( const CRhinoCommandContext& context )
{
  ON_3dPoint origin( 1, 1, 0 );
  ON_3dPoint offset( 11, 1, 0 );
  ON_3dPoint pt( (offset.x-origin.x)/2, 3, 0 );
 
  CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
 
  ON_Plane plane( ON_xy_plane );
  plane.SetOrigin( origin );
  dim_obj->SetPlane( plane );

  double u, v;
  plane.ClosestPointTo( origin, &u, &v );
  dim_obj->SetPoint( 0, ON_2dPoint(u,v) );
 
  plane.ClosestPointTo( offset, &u, &v );
  dim_obj->SetPoint( 2, ON_2dPoint(u,v) );
 
  plane.ClosestPointTo( pt, &u, &v );

  ON_2dPoint p2d( u, v );
  dim_obj->UpdateDimPoints( p2d );
  dim_obj->UpdateText();
 
  if( context.m_doc.AddObject(dim_obj) )
    context.m_doc.Redraw();
  else
    delete dim_obj;

  return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleDimLinearOverride::RunCommand( const CRhinoCommandContext& context )
{
  // To override a property of a dimension, you must first create a child
  // dimension style. In this example, we will create a child dimension
  // style of the current dimension style, override the text alignment
  // property, and then assign it to a new linear dimension.

  // Get reference to dimension style table
  CRhinoDimStyleTable& dimstyle_table = context.m_doc.m_dimstyle_table;

  // Get the current dimension style
  const CRhinoDimStyle& dimstyle = dimstyle_table.CurrentDimStyle();

  // Create a new dimenstion style based on the current dimension style
  ON_DimStyle child_dimstyle(dimstyle);
  // Make this dimstyle a child of the current dimension style
  child_dimstyle.SetParentId(dimstyle.m_dimstyle_id);
  // Change the name of the child dimension style
  dimstyle_table.GetUnusedDimStyleName(child_dimstyle.m_dimstyle_name );

  // Override with the text alignment field
  child_dimstyle.SetFieldOverride(ON_DimStyle::fn_textalign, true);
  // Set text alignment field to horizontal
  child_dimstyle.SetTextAlignment(ON::dtHorizontal);

  // Add the new child dimension style
  int child_dimstyle_index = dimstyle_table.AddDimStyle(child_dimstyle, false);

  // Create a new linear dimension object
  CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
  // Set the dimension style to the newly added style
  dim_obj->SetStyleIndex(child_dimstyle_index);

  // Set some linear dimension points (example)
  dim_obj->SetPlane(ON_Plane::World_xy);
  dim_obj->SetPoint(0, ON_2dPoint(0.0, 0.0));
  dim_obj->SetPoint(2, ON_2dPoint(10,0) );
  ON_2dPoint dimline_point(5.0, 2.0);
  dim_obj->UpdateDimPoints(dimline_point);
  dim_obj->UpdateText();

  // Add linear dimension to the document
  CRhinoCommand::result rc = CRhinoCommand::success;
  if (context.m_doc.AddObject(dim_obj))
  {
    context.m_doc.Redraw();
  }
  else
  {
    delete dim_obj; // Don't leak...
    rc = CRhinoCommand::failure;
  }

  return rc;


  return CRhinoCommand::success;
}
Exemple #3
0
ON_2dPoint ON_Annotation::Point( int idx ) const
{
  if( idx >= 0 && idx < m_points.Count() )
    return m_points[idx];

  return ON_2dPoint( 0.0, 0.0 );
}
/*
Description:
  Creates a linear dimension based on the current dimension style.
Parameters:
  plane  - [in] The plane on which the dimension lies. 
                Often this is the active construction plane.
  origin – [in] The origin point.
  offset – [in] The offset point.
  point  – [in] The location point of the dimension line. 
Returns:
  A pointer to a CRhinoLinearDimension object if successful.
  NULL if not successful.
Remarks:
  Memory for the CRhinoLinearDimension object is allocated and becomes
  the responsibility of the caller.
*/
CRhinoLinearDimension* RhinoCreateLinearDimension(
  const ON_Plane& plane, 
  const ON_3dPoint& origin, 
  const ON_3dPoint& offset, 
  const ON_3dPoint& point
  )
{
  CRhinoLinearDimension* obj = 0;

  if (plane.IsValid() && origin.IsValid() && offset.IsValid() && point.IsValid())
  {
    obj = new CRhinoLinearDimension();
    if (obj)
    {
      ON_Plane dim_plane(plane);
      dim_plane.SetOrigin(origin);
      obj->SetPlane(dim_plane);

      // origin
      obj->SetPoint(0, ON_2dPoint(0,0));
 
      // offset
      ON_2dPoint p2;
      dim_plane.ClosestPointTo(offset, &p2.x, &p2.y);
      obj->SetPoint(2, p2);
 
      // dimension line point
      dim_plane.ClosestPointTo(point, &p2.x, &p2.y);
      obj->UpdateDimPoints(p2);
      obj->UpdateText();
    }
  }

  return obj;
}
ON_Surface::ISO
ON_SurfaceProxy::IsIsoparametric( // returns isoparametric status based on bounding box
    const ON_BoundingBox& box
) const
{
    // this is a virtual overide of an ON_Surface::IsIsoparametric
    const ON_BoundingBox* pbox = &box;
    ON_BoundingBox Tbox(	ON_2dPoint( box.m_min[1],box.m_min[0]),
                            ON_2dPoint( box.m_max[1],box.m_max[0]) );
    if(m_bTransposed)
        pbox = &Tbox;

    ON_Surface::ISO iso = m_surface->IsIsoparametric( *pbox);

    if( m_bTransposed) {
        switch(iso)
        {
        case x_iso:
            iso = y_iso;
            break;
        case y_iso:
            iso = x_iso;
            break;
        case W_iso:
            iso = S_iso;
            break;
        case S_iso:
            iso = W_iso;
            break;
        case N_iso:
            iso = E_iso;
            break;
        case E_iso:
            iso = N_iso;
            break;
        default:
            // intentionally ignoring other ON_Surface::ISO enum values
            break;
        }
    }
    return iso;
}
ON_2dPoint
BBNode::getClosestPointEstimate(const ON_3dPoint &pt, ON_Interval &u, ON_Interval &v)
{
    if (isLeaf()) {
	double uvs[5][2] = {{m_u.Min(), m_v.Min()}, {m_u.Max(), m_v.Min()},
	    {m_u.Max(), m_v.Max()}, {m_u.Min(), m_v.Max()},
	    {m_u.Mid(), m_v.Mid()}
	}; /* include the estimate */
	ON_3dPoint corners[5];
	const ON_Surface *surf = m_face->SurfaceOf();

	u = m_u;
	v = m_v;

	/* ??? pass these in from SurfaceTree::surfaceBBox() to avoid
	 * this recalculation?
	 */
	if (!surf->EvPoint(uvs[0][0], uvs[0][1], corners[0]) ||
	    !surf->EvPoint(uvs[1][0], uvs[1][1], corners[1]) ||
	    !surf->EvPoint(uvs[2][0], uvs[2][1], corners[2]) ||
	    !surf->EvPoint(uvs[3][0], uvs[3][1], corners[3]))
	{
	    throw new std::exception(); /* FIXME */
	}
	corners[4] = BBNode::m_estimate;

	/* find the point on the surface closest to pt */
	size_t mini = 0;
	double mindist = pt.DistanceTo(corners[mini]);
	double tmpdist;
	for (size_t i = 1; i < 5; i++) {
	    tmpdist = pt.DistanceTo(corners[i]);
	    TRACE("\t" << mindist << " < " << tmpdist);
	    if (tmpdist < mindist) {
		mini = i;
		mindist = tmpdist;
	    }
	}
	TRACE("Closest: " << mindist << "; " << PT2(uvs[mini]));
	return ON_2dPoint(uvs[mini][0], uvs[mini][1]);
    } else {
	if (m_children.size() > 0) {
	    BBNode *closestNode = m_children[0];
	    for (size_t i = 1; i < m_children.size(); i++) {
		closestNode = closer(pt, closestNode, m_children[i]);
		TRACE("\t" << PT(closestNode->m_estimate));
	    }
	    return closestNode->getClosestPointEstimate(pt, u, v);
	}
	throw new std::exception();
    }
}
/*
Description:
  Creates an aligned linear dimension based on the current dimension style.
Parameters:
  plane  - [in] The plane on which the dimension lies. 
                Often this is the active construction plane.
  origin – [in] The origin point.
  offset – [in] The offset point.
  point  – [in] The location point of the dimension line. 
Returns:
  A pointer to a CRhinoLinearDimension object if successful.
  NULL if not successful.
Remarks:
  Memory for the CRhinoLinearDimension object is allocated and becomes
  the responsibility of the caller.
*/
CRhinoLinearDimension* RhinoCreateAlignedDimension(
  const ON_Plane& plane, 
  const ON_3dPoint& origin, 
  const ON_3dPoint& offset, 
  const ON_3dPoint& point
  )
{
  CRhinoLinearDimension* obj = 0;

  if (plane.IsValid() && origin.IsValid() && offset.IsValid() && point.IsValid())
  {
    obj = new CRhinoLinearDimension();
    if (obj)
    {
      obj->SetAligned(TRUE);

      // Calculate rotation angle
      ON_Plane dim_plane(plane);
      dim_plane.SetOrigin( origin );

      double s[2], t[2];
      dim_plane.ClosestPointTo(origin, &s[0], &t[0]);
      dim_plane.ClosestPointTo(offset, &s[1], &t[1]);
      
      ON_2dVector angle(s[1]-s[0], t[1]-t[0]);
      angle.Unitize();

      dim_plane.Rotate(angle.y, angle.x, dim_plane.Normal());
      obj->SetPlane( dim_plane );
 
      // origin
      obj->SetPoint(0, ON_2dPoint(0,0));

      // offset
      ON_2dPoint p2;
      dim_plane.ClosestPointTo(offset, &p2.x, &p2.y);
      obj->SetPoint(2, p2);
 
      // dimension line point
      dim_plane.ClosestPointTo(point, &p2.x, &p2.y);
      obj->UpdateDimPoints(p2);
      obj->UpdateText();
    }
  }

  return obj;
}
Exemple #8
0
BOOL ON_HatchLine::IsValid( ON_TextLog* text_log) const
{
  bool rc = m_angle >= 0.0;
  if( !rc)
  {
    if( text_log)
      text_log->Print( "Angle ( %lf) must be >= 0.0\n", m_angle);
    return false;
  }
  rc = m_angle < ON_PI * 2.0;
  if( !rc)
  {
    if( text_log)
      text_log->Print( "Angle ( %lf) must be < 2*Pi.\n", m_angle);
    return false;
  }
  rc = m_base != ON_2dPoint( ON_UNSET_VALUE, ON_UNSET_VALUE);
  if( !rc)
  {
    if( text_log)
      text_log->Print( "Base is not a valid point.\n");
    return false;
  }
  rc = m_offset.x != ON_UNSET_VALUE;
  if( !rc)
  {
    if( text_log)
      text_log->Print( "Offset is not a valid vector.\n");
    return false;
  }
  rc = m_offset.y > ON_SQRT_EPSILON;
  if( !rc)
  {
    if( text_log)
      text_log->Print( "Offset.y ( %lf) must be > 0.0", m_offset.y);
    return false;
  }
  return true;
}
CRhinoCommand::result CCommandSampleShortPath::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Select surface for creating a short curve between two points on the surface" );
  go.SetGeometryFilter( CRhinoGetObject::surface_object );
  go.GetObjects( 1, 1 );
  if( go.CommandResult() != CRhinoCommand::success )
    return go.CommandResult();

  const ON_Surface* srf = go.Object(0).Surface();
  if( 0 == srf )
    return CRhinoCommand::failure;

  CRhinoGetPoint gp;
  gp.SetCommandPrompt( L"Start of curve" );
  gp.Constrain(*srf);
  gp.GetPoint();
  if( gp.CommandResult() != CRhinoCommand::success )
    return gp.CommandResult();

  double u0, v0;
  if( !gp.PointOnSurface(&u0, &v0) )
  {
    RhinoApp().Print( L"Point not on the surface.\n" );
    return CRhinoCommand::failure;
  }

  gp.SetCommandPrompt( L"End of curve" );
  gp.GetPoint();
  if( gp.CommandResult() != CRhinoCommand::success )
    return gp.CommandResult();

  double u1, v1;
  if( !gp.PointOnSurface(&u1, &v1) )
  {
    RhinoApp().Print( L"Point not on the surface.\n" );
    return CRhinoCommand::failure;
  }
  
  ON_3dPoint p0 = srf->PointAt( u0, v0 );
  ON_3dPoint p1 = srf->PointAt( u1, v1 );

  if( p0.DistanceTo(p1) < ON_SQRT_EPSILON )
  {
    RhinoApp().Print( L"Points must be distinct.\n" );
    return CRhinoCommand::nothing;
  }

  double tol = context.m_doc.AbsoluteTolerance();
  ON_Curve* crv = RhinoShortPath( *srf, ON_2dPoint(u0,v0), ON_2dPoint(u1,v1), tol );
  if( 0 == crv )
  {
    RhinoApp().Print( L"Failed to compute shortest path.\n" );
    return CRhinoCommand::nothing;
  }

  CRhinoCurveObject* crv_obj = new CRhinoCurveObject();
  crv_obj->SetCurve( crv );
  context.m_doc.AddObject( crv_obj );

  context.m_doc.Redraw();

  return CRhinoCommand::success;
}
Exemple #10
0
static ON_Brep *
generate_brep(int count, ON_3dPoint *points)
{
    ON_Brep *brep = new ON_Brep();

    /* make an arb8 */

    // VERTICES

    for (int i=0; i<count; i++) {
	brep->NewVertex(points[i], SMALL_FASTF);
    }

    ON_3dPoint p8 = ON_3dPoint(-1.0, 0.0, -1.0);
    ON_3dPoint p9 = ON_3dPoint(2.0, 0.0, -1.0);
    ON_3dPoint p10 = ON_3dPoint(2.0, 0.0, 3.5);
    ON_3dPoint p11 = ON_3dPoint(-1.0, 0.0, 3.5);

    brep->NewVertex(p8, SMALL_FASTF); // 8
    brep->NewVertex(p9, SMALL_FASTF); // 9
    brep->NewVertex(p10, SMALL_FASTF); // 10
    brep->NewVertex(p11, SMALL_FASTF); // 11

    // LEFT SEGMENTS

    // 0
    ON_Curve* segment01 = new ON_LineCurve(points[0], points[1]);
    segment01->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment01);

    // 1
    ON_Curve* segment12 = new ON_LineCurve(points[1], points[2]);
    segment12->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment12);

    // 2
    ON_Curve* segment23 = new ON_LineCurve(points[2], points[3]);
    segment23->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment23);

    // 3
    ON_Curve* segment30 = new ON_LineCurve(points[3], points[0]);
    segment30->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment30);

    // RIGHT SEGMENTS

    // 4
    ON_Curve* segment45 = new ON_LineCurve(points[5], points[4]);
    segment45->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment45);

    // 5
    ON_Curve* segment56 = new ON_LineCurve(points[6], points[5]);
    segment56->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment56);

    // 6
    ON_Curve* segment67 = new ON_LineCurve(points[7], points[6]);
    segment67->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment67);

    // 7
    ON_Curve* segment74 = new ON_LineCurve(points[4], points[7]);
    segment74->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment74);

    // HORIZONTAL SEGMENTS

    // 8
    ON_Curve* segment04 = new ON_LineCurve(points[0], points[4]);
    segment04->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment04);

    // 9
    ON_Curve* segment51 = new ON_LineCurve(points[5], points[1]);
    segment51->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment51);

    // 10
    ON_Curve* segment26 = new ON_LineCurve(points[2], points[6]);
    segment26->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment26);

    // 11
    ON_Curve* segment73 = new ON_LineCurve(points[7], points[3]);
    segment73->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment73);

    /* XXX */

    // 12
    ON_Curve* segment01prime = new ON_LineCurve(p8, p9);
    segment01prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment01prime);

    // 13
    ON_Curve* segment12prime = new ON_LineCurve(p9, p10);
    segment12prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment12prime);

    // 14
    ON_Curve* segment23prime = new ON_LineCurve(p10, p11);
    segment23prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment23prime);

    // 15
    ON_Curve* segment30prime = new ON_LineCurve(p11, p8);
    segment30prime->SetDomain(0.0, 1.0);
    brep->m_C3.Append(segment30prime);

    // SURFACES
    ON_NurbsSurface* surf0123 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf0123->SetKnot(0, 0, 0.0); surf0123->SetKnot(0, 1, 1.0); surf0123->SetKnot(1, 0, 0.0); surf0123->SetKnot(1, 1, 1.0);
    surf0123->SetCV(0, 0, points[0]);
    surf0123->SetCV(1, 0, points[1]);
    surf0123->SetCV(1, 1, points[2]);
    surf0123->SetCV(0, 1, points[3]);
    brep->m_S.Append(surf0123); /* 0 */

    ON_NurbsSurface* surf4765 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf4765->SetKnot(0, 0, 0.0); surf4765->SetKnot(0, 1, 1.0); surf4765->SetKnot(1, 0, 0.0); surf4765->SetKnot(1, 1, 1.0);
    surf4765->SetCV(0, 0, points[4]);
    surf4765->SetCV(1, 0, points[7]);
    surf4765->SetCV(1, 1, points[6]);
    surf4765->SetCV(0, 1, points[5]);
    brep->m_S.Append(surf4765); /* 1 */

    ON_NurbsSurface* surf0451 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf0451->SetKnot(0, 0, 0.0); surf0451->SetKnot(0, 1, 1.0); surf0451->SetKnot(1, 0, 0.0); surf0451->SetKnot(1, 1, 1.0);
    surf0451->SetCV(0, 0, points[0]);
    surf0451->SetCV(1, 0, points[4]);
    surf0451->SetCV(1, 1, points[5]);
    surf0451->SetCV(0, 1, points[1]);
    brep->m_S.Append(surf0451); /* 2 */

    ON_NurbsSurface* surf2673 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf2673->SetKnot(0, 0, 0.0); surf2673->SetKnot(0, 1, 1.0); surf2673->SetKnot(1, 0, 0.0); surf2673->SetKnot(1, 1, 1.0);
    surf2673->SetCV(0, 0, points[2]);
    surf2673->SetCV(1, 0, points[6]);
    surf2673->SetCV(1, 1, points[7]);
    surf2673->SetCV(0, 1, points[3]);
    brep->m_S.Append(surf2673); /* 3 */

    ON_NurbsSurface* surf1562 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf1562->SetKnot(0, 0, 0.0); surf1562->SetKnot(0, 1, 1.0); surf1562->SetKnot(1, 0, 0.0); surf1562->SetKnot(1, 1, 1.0);
    surf1562->SetCV(0, 0, points[1]);
    surf1562->SetCV(1, 0, points[5]);
    surf1562->SetCV(1, 1, points[6]);
    surf1562->SetCV(0, 1, points[2]);
    brep->m_S.Append(surf1562); /* 4 */

    ON_NurbsSurface* surf0374 = new ON_NurbsSurface(3 /*dimension*/, 0 /*nonrational*/, 2 /*u*/, 2 /*v*/, 2 /*#u*/, 2 /*#v*/);
    surf0374->SetKnot(0, 0, 0.0); surf0374->SetKnot(0, 1, 1.0); surf0374->SetKnot(1, 0, 0.0); surf0374->SetKnot(1, 1, 1.0);
    surf0374->SetCV(0, 0, points[0]);
    surf0374->SetCV(1, 0, points[3]);
    surf0374->SetCV(1, 1, points[7]);
    surf0374->SetCV(0, 1, points[4]);
    brep->m_S.Append(surf0374); /* 5 */


    // TRIM CURVES

    ON_Curve* trimcurve01 = new ON_LineCurve(ON_2dPoint(0, 0), ON_2dPoint(1, 0));
    trimcurve01->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve01); /* 0 */

    ON_Curve* trimcurve12 = new ON_LineCurve(ON_2dPoint(1, 0), ON_2dPoint(1, 1));
    trimcurve12->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve12); /* 1 */

    ON_Curve* trimcurve23 = new ON_LineCurve(ON_2dPoint(1, 1), ON_2dPoint(0, 1));
    trimcurve23->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve23); /* 2 */

    ON_Curve* trimcurve30 = new ON_LineCurve(ON_2dPoint(0, 1), ON_2dPoint(0, 0));
    trimcurve30->SetDomain(0.0, 1.0);
    brep->m_C2.Append(trimcurve30); /* 3 */

    // EDGES

    /* C3 curve */
    // left face edges
    brep->NewEdge(brep->m_V[0], brep->m_V[1], 0, NULL, SMALL_FASTF); /* 0 */
    brep->NewEdge(brep->m_V[1], brep->m_V[2], 1, NULL, SMALL_FASTF); /* 1 */
    brep->NewEdge(brep->m_V[2], brep->m_V[3], 2, NULL, SMALL_FASTF); /* 2 */
    brep->NewEdge(brep->m_V[3], brep->m_V[0], 3, NULL, SMALL_FASTF); /* 3 */

    // right face edges
    brep->NewEdge(brep->m_V[5], brep->m_V[4], 4, NULL, SMALL_FASTF); /* 4 */
    brep->NewEdge(brep->m_V[6], brep->m_V[5], 5, NULL, SMALL_FASTF); /* 5 */
    brep->NewEdge(brep->m_V[7], brep->m_V[6], 6, NULL, SMALL_FASTF); /* 6 */
    brep->NewEdge(brep->m_V[4], brep->m_V[7], 7, NULL, SMALL_FASTF); /* 7 */

    // horizontal face edges
    brep->NewEdge(brep->m_V[0], brep->m_V[4], 8, NULL, SMALL_FASTF); /* 8 */
    brep->NewEdge(brep->m_V[5], brep->m_V[1], 9, NULL, SMALL_FASTF); /* 9 */
    brep->NewEdge(brep->m_V[2], brep->m_V[6], 10, NULL, SMALL_FASTF); /* 10 */
    brep->NewEdge(brep->m_V[7], brep->m_V[3], 11, NULL, SMALL_FASTF); /* 11 */

    // XXX
    brep->NewEdge(brep->m_V[8], brep->m_V[9], 12, NULL, SMALL_FASTF); /* 12 */
    brep->NewEdge(brep->m_V[9], brep->m_V[10], 13, NULL, SMALL_FASTF); /* 13 */
    brep->NewEdge(brep->m_V[10], brep->m_V[11], 14, NULL, SMALL_FASTF); /* 14 */
    brep->NewEdge(brep->m_V[11], brep->m_V[8], 15, NULL, SMALL_FASTF); /* 15 */

    // FACES

    ON_BrepFace& face0123 = brep->NewFace(0);
    ON_BrepLoop& loop0123 = brep->NewLoop(ON_BrepLoop::outer, face0123); /* 0 */
    ON_BrepTrim& trim01 = brep->NewTrim(brep->m_E[0], false, loop0123, 0 /* trim */); /* m_T[0] */
    trim01.m_iso = ON_Surface::S_iso;
    trim01.m_type = ON_BrepTrim::mated;
    trim01.m_tolerance[0] = SMALL_FASTF;
    trim01.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim12 = brep->NewTrim(brep->m_E[1], false, loop0123, 1 /* trim */); /* 1 */
    trim12.m_iso = ON_Surface::E_iso;
    trim12.m_type = ON_BrepTrim::mated;
    trim12.m_tolerance[0] = SMALL_FASTF;
    trim12.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim23 = brep->NewTrim(brep->m_E[2], false, loop0123, 2 /* trim */); /* 2 */
    trim23.m_iso = ON_Surface::N_iso;
    trim23.m_type = ON_BrepTrim::mated;
    trim23.m_tolerance[0] = SMALL_FASTF;
    trim23.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim30 = brep->NewTrim(brep->m_E[3], false, loop0123, 3 /* trim */); /* 3 */
    trim30.m_iso = ON_Surface::W_iso;
    trim30.m_type = ON_BrepTrim::mated;
    trim30.m_tolerance[0] = SMALL_FASTF;
    trim30.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face4765 = brep->NewFace(1 /* surfaceID */);
    ON_BrepLoop& loop4765 = brep->NewLoop(ON_BrepLoop::outer, face4765); /* 1 */
    ON_BrepTrim& trim47 = brep->NewTrim(brep->m_E[7], false, loop4765, 0 /* trim */); /* 4 */
    trim47.m_iso = ON_Surface::S_iso;
    trim47.m_type = ON_BrepTrim::mated;
    trim47.m_tolerance[0] = SMALL_FASTF;
    trim47.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim76 = brep->NewTrim(brep->m_E[6], false, loop4765, 1 /* trim */); /* 5 */
    trim76.m_iso = ON_Surface::E_iso;
    trim76.m_type = ON_BrepTrim::mated;
    trim76.m_tolerance[0] = SMALL_FASTF;
    trim76.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim65 = brep->NewTrim(brep->m_E[5], false, loop4765, 2 /* trim */); /* 6 */
    trim65.m_iso = ON_Surface::N_iso;
    trim65.m_type = ON_BrepTrim::mated;
    trim65.m_tolerance[0] = SMALL_FASTF;
    trim65.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim54 = brep->NewTrim(brep->m_E[4], false, loop4765, 3 /* trim */); /* 7 */
    trim54.m_iso = ON_Surface::W_iso;
    trim54.m_type = ON_BrepTrim::mated;
    trim54.m_tolerance[0] = SMALL_FASTF;
    trim54.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face0451 = brep->NewFace(2);
    ON_BrepLoop& loop0451 = brep->NewLoop(ON_BrepLoop::outer, face0451); /* 2 */
    ON_BrepTrim& trim04 = brep->NewTrim(brep->m_E[8], false, loop0451, 0 /* trim */); /* 8 */
    trim04.m_iso = ON_Surface::S_iso;
    trim04.m_type = ON_BrepTrim::mated;
    trim04.m_tolerance[0] = SMALL_FASTF;
    trim04.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim45 = brep->NewTrim(brep->m_E[4], true, loop0451, 1 /* trim */); /* 9 */
    trim45.m_iso = ON_Surface::E_iso;
    trim45.m_type = ON_BrepTrim::mated;
    trim45.m_tolerance[0] = SMALL_FASTF;
    trim45.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim51 = brep->NewTrim(brep->m_E[9], false, loop0451, 2 /* trim */); /* 10 */
    trim51.m_iso = ON_Surface::N_iso;
    trim51.m_type = ON_BrepTrim::mated;
    trim51.m_tolerance[0] = SMALL_FASTF;
    trim51.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim10 = brep->NewTrim(brep->m_E[0], true, loop0451, 3 /* trim */); /* 11 */
    trim10.m_iso = ON_Surface::W_iso;
    trim10.m_type = ON_BrepTrim::mated;
    trim10.m_tolerance[0] = SMALL_FASTF;
    trim10.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face2673 = brep->NewFace(3);
    ON_BrepLoop& loop2673 = brep->NewLoop(ON_BrepLoop::outer, face2673); /* 3 */
    ON_BrepTrim& trim26 = brep->NewTrim(brep->m_E[10], false, loop2673, 0 /* trim */); /* 12 */
    trim26.m_iso = ON_Surface::S_iso;
    trim26.m_type = ON_BrepTrim::mated;
    trim26.m_tolerance[0] = SMALL_FASTF;
    trim26.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim67 = brep->NewTrim(brep->m_E[6], true, loop2673, 1 /* trim */); /* 13 */
    trim67.m_iso = ON_Surface::E_iso;
    trim67.m_type = ON_BrepTrim::mated;
    trim67.m_tolerance[0] = SMALL_FASTF;
    trim67.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim73 = brep->NewTrim(brep->m_E[11], false, loop2673, 2 /* trim */); /* 14 */
    trim73.m_iso = ON_Surface::N_iso;
    trim73.m_type = ON_BrepTrim::mated;
    trim73.m_tolerance[0] = SMALL_FASTF;
    trim73.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim32 = brep->NewTrim(brep->m_E[2], true, loop2673, 3 /* trim */); /* 15 */
    trim32.m_iso = ON_Surface::W_iso;
    trim32.m_type = ON_BrepTrim::mated;
    trim32.m_tolerance[0] = SMALL_FASTF;
    trim32.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face1562 = brep->NewFace(4);
    ON_BrepLoop& loop1562 = brep->NewLoop(ON_BrepLoop::outer, face1562); /* 4 */
    ON_BrepTrim& trim15 = brep->NewTrim(brep->m_E[9], true, loop1562, 0 /* trim */); /* 16 */
    trim15.m_iso = ON_Surface::S_iso;
    trim15.m_type = ON_BrepTrim::mated;
    trim15.m_tolerance[0] = SMALL_FASTF;
    trim15.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim56 = brep->NewTrim(brep->m_E[5], true, loop1562, 1 /* trim */); /* 17 */
    trim56.m_iso = ON_Surface::E_iso;
    trim56.m_type = ON_BrepTrim::mated;
    trim56.m_tolerance[0] = SMALL_FASTF;
    trim56.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim62 = brep->NewTrim(brep->m_E[10], true, loop1562, 2 /* trim */); /* 18 */
    trim62.m_iso = ON_Surface::N_iso;
    trim62.m_type = ON_BrepTrim::mated;
    trim62.m_tolerance[0] = SMALL_FASTF;
    trim62.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim21 = brep->NewTrim(brep->m_E[1], true, loop1562, 3 /* trim */); /* 19 */
    trim21.m_iso = ON_Surface::W_iso;
    trim21.m_type = ON_BrepTrim::mated;
    trim21.m_tolerance[0] = SMALL_FASTF;
    trim21.m_tolerance[1] = SMALL_FASTF;

    ON_BrepFace& face0374 = brep->NewFace(5);
    ON_BrepLoop& loop0374 = brep->NewLoop(ON_BrepLoop::outer, face0374); /* 5 */
    ON_BrepTrim& trim03 = brep->NewTrim(brep->m_E[3], true, loop0374, 0 /* trim */); /* 20 */
    trim03.m_iso = ON_Surface::S_iso;
    trim03.m_type = ON_BrepTrim::mated;
    trim03.m_tolerance[0] = SMALL_FASTF;
    trim03.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim37 = brep->NewTrim(brep->m_E[11], true, loop0374, 1 /* trim */); /* 21 */
    trim37.m_iso = ON_Surface::E_iso;
    trim37.m_type = ON_BrepTrim::mated;
    trim37.m_tolerance[0] = SMALL_FASTF;
    trim37.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim74 = brep->NewTrim(brep->m_E[7], true, loop0374, 2 /* trim */); /* 22 */
    trim74.m_iso = ON_Surface::N_iso;
    trim74.m_type = ON_BrepTrim::mated;
    trim74.m_tolerance[0] = SMALL_FASTF;
    trim74.m_tolerance[1] = SMALL_FASTF;
    ON_BrepTrim& trim40 = brep->NewTrim(brep->m_E[8], true, loop0374, 3 /* trim */); /* 23 */
    trim40.m_iso = ON_Surface::W_iso;
    trim40.m_type = ON_BrepTrim::mated;
    trim40.m_tolerance[0] = SMALL_FASTF;
    trim40.m_tolerance[1] = SMALL_FASTF;

    return brep;
}
Exemple #11
0
CRhinoCommand::result CGenCylinder::RunCommand( const CRhinoCommandContext& context )
{

	Cscript1PlugIn& plugin = script1PlugIn();
	if( !plugin.IsDlgVisible() )
	{
		return CRhinoCommand::nothing;
	}

	/*****************************************/
	/*CHECKING IF THERE IS ALREADY A CYLINDER*/
	/*****************************************/
	const CRhinoLayer& layer = context.m_doc.m_layer_table.CurrentLayer();
	ON_SimpleArray<CRhinoObject*> objects;
	int object_count = context.m_doc.LookupObject( layer, objects );
	const CRhinoBrepObject* brep_obj;
	const CRhinoCurveObject* curve_obj;
	const CRhinoSurfaceObject* surface_obj;
	int surf_count=0;
	if( object_count > 0 )
	{
		int brep_obj_count = 0;
		int polycurve_count = 0;
		const CRhinoObject* object = 0;
		for(int i = 0; i < object_count; i++ )
		{
			object = objects[ i ];
			/************************************/
			/*TRY CASTING AS A RHINO BREP OBJECT*/ 
			/************************************/
			brep_obj = CRhinoBrepObject::Cast( object );
			if( brep_obj && object->IsSolid())
			{
				brep_obj_count++;
			}
			/*******************************/
			/*TRY CASTING AS A CURVE OBJECT*/ 
			/*******************************/
			curve_obj = CRhinoCurveObject::Cast( object );
			if( curve_obj )
			{
				polycurve_count++;
			}
			//surface_obj = CRhinoSurfaceObject::Cast( object );
		 //   if( surface_obj )
		 //   {
			//surf_count++;
		 //   }
		}
		if( brep_obj_count == 0)
		{
			ON_3dPoint center_point( 0.0, 0.0, 0.0 );
			double radius = 63.5;
			int __count = plugin.m_dialog->m_comboAltTacco.GetCount();

			int nIndex = plugin.m_dialog->m_comboAltTacco.GetCurSel();
			CString strCBText;
			plugin.m_dialog->m_comboAltTacco.GetLBText( nIndex, strCBText);
			int height = _wtoi(strCBText);


			ON_3dPoint height_point( 0.0, 0.0, height);
			ON_3dVector zaxis = height_point - center_point;
			ON_Plane planeCir( center_point, zaxis );

			/*ADD CIRCLE FOR CYLINDER'S BASE*/
			ON_Circle circle( planeCir, radius );

			/*ADD CYLINDER*/
			ON_Cylinder cylinder( circle, zaxis.Length() );
			ON_Brep* brep = ON_BrepCylinder( cylinder, TRUE, TRUE );
			unsigned int first_SN;
			unsigned int next_SN;
			if( brep )
			{
				first_SN = CRhinoObject::NextRuntimeObjectSerialNumber();
				/********************/
				/*TRANSLATE CYLINDER*/
				/********************/
				int nIndex1 = plugin.m_dialog->AltezzaFondelloControllo.GetCurSel();
				CString strCBText1;
				plugin.m_dialog->AltezzaFondelloControllo.GetLBText( nIndex1, strCBText1);
				int altfondello = _wtoi(strCBText1);
				ON_wString obj_nameCyl = L"CILINDRO";
								
				
				brep->Translate(ON_3dVector( 0.0, 0.0, -altfondello));
				CRhinoBrepObject* cylinder_object = new CRhinoBrepObject();
				cylinder_object->SetBrep( brep );
				if( context.m_doc.AddObject(cylinder_object) )
				{
					context.m_doc.Redraw();
					next_SN = CRhinoObject::NextRuntimeObjectSerialNumber();
					if( first_SN == next_SN )
					{
						return CRhinoCommand::nothing;
					}
					else
					{
						SetNametoObject(context.m_doc,first_SN,obj_nameCyl,true);			  
					}
				}
				else
				{
					delete cylinder_object;
				}

				/*********************************************/
				/*               DA SISTEMARE                */
				/*********************************************/
				
				CRhinoSnapContext snap;
				bool dec1 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, (height - altfondello)));
				bool dec2 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, -altfondello));
				bool dec3 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, 0.0));
				if(dec1 && dec2)
				{
					CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
					ON_Plane plane( ON_zx_plane );
					plane.SetOrigin( ON_3dPoint(63.5, 0.0, 0.0) );
					dim_obj->SetPlane( plane );
					ON_3dPoint pt_1(63.5, 0.0, (height - altfondello));
					ON_3dPoint pt_2(63.5, 0.0, -altfondello);

					double u, v;
					plane.ClosestPointTo( pt_1, &u, &v );
					dim_obj->SetPoint( 0, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) );


					plane.ClosestPointTo( pt_2, &u, &v );
					dim_obj->SetPoint( 2, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) );

					dim_obj->UpdateText();
					 
					if( context.m_doc.AddObject(dim_obj) )
					{
						context.m_doc.Redraw();
					}		
					else
					{
						delete dim_obj;
					}
				}
				/*********************************************/
				/*               DA SISTEMARE                */
				/*********************************************/
				if(dec2 && dec3)
				{
					CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
					ON_Plane plane( ON_zx_plane );
					plane.SetOrigin( ON_3dPoint(63.5, 0.0, 0.0) );
					dim_obj->SetPlane( plane );
					ON_3dPoint pt_1(63.5, 0.0, 0.0);
					ON_3dPoint pt_2(63.5, 0.0, -altfondello);

					double u, v;
					plane.ClosestPointTo( pt_1, &u, &v );
					dim_obj->SetPoint( 0, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) );


					plane.ClosestPointTo( pt_2, &u, &v );
					dim_obj->SetPoint( 2, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) );

					dim_obj->UpdateText();
					 
					if( context.m_doc.AddObject(dim_obj) )
					{
						context.m_doc.Redraw();
					}		
					else
					{
						delete dim_obj;
					}
				}
				/*********************************************/
				/*               DA SISTEMARE  By Nello              */
				/*********************************************/
				
				ON_3dPoint provapunto2 = AltezzaTacco;
				ON_3dPoint provapunto(59.5,0,provapunto2.z);
				provapunto.z-=0.7;
				ON_3dPoint pt_1(59.5, 0.0, (height - altfondello));
				CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
					ON_Plane plane( ON_zx_plane );
					plane.SetOrigin(pt_1);
					dim_obj->SetPlane( plane );
					//ON_3dPoint pt_1(63.5, 0.0, 0.0);
					ON_3dPoint pt_2 = provapunto;

					double u, v;
					plane.ClosestPointTo( pt_1, &u, &v );
					dim_obj->SetPoint( 0, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) );


					plane.ClosestPointTo( pt_2, &u, &v );
					dim_obj->SetPoint( 2, ON_2dPoint(u, v) );
					dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) );

					dim_obj->UpdateText();
					 
					if( context.m_doc.AddObject(dim_obj) )
					{
						context.m_doc.Redraw();
					}		
					else
					{
						delete dim_obj;
					}
				
					/*INIZIO FUNZIONE CONTROLLO*/
			
					if ( (height - altfondello)>=provapunto.z+10){
						::RhinoApp().Print( L"Funzione controllo altezza OK");
					}
					else{
						::RhinoApp().Print( L"Funzione controllo altezza NOK: CONTROLLARE!! Il valore della testa e' minore del valore minimo di 10 mm. Occorre diminuire l'altezza del fondello o aumentare l'altezza dello stampo.");
					}


				/*********************************************/
				/*           CREATE FONDELLO PLANE           */
				/*********************************************/

				ON_3dPoint point0((63.5 + 20.0),0.0, 0.0);
				ON_3dPoint point1(-(63.5 + 20.0),0.0, 0.0);
				ON_LineCurve curve0( point0, point1 );

				context.m_doc.AddCurveObject(curve0);
				context.m_doc.Redraw();


				/******************************************************/
				/*****************************/
				/*USER GIVES NAME TO SURFACES*/ 
				/*****************************/
				unsigned int first_sn;
				unsigned int next_sn;
				ON_wString obj_name;
				object_count = context.m_doc.LookupObject( layer, objects );
				for(int i = 0; i < object_count; i++ )
				{
					object = objects[ i ];
					first_sn = CRhinoObject::NextRuntimeObjectSerialNumber();

					/*******************************/
					/*TRY CASTING AS A CURVE OBJECT*/ 
					/*******************************/
					curve_obj = CRhinoCurveObject::Cast( object );
					if( curve_obj )
					{
						const ON_Geometry* geo = curve_obj->Geometry();
						const ON_Curve* curve00 = ON_Curve::Cast(geo); 
						ON_3dPoint point  = curve00->PointAt(0.0);
						ON_3dPoint point_ = curve00->PointAt(1.0);
						if((point.z + point_.z)/2 > 0.0)
						{
							obj_name = L"SURFPV";
						}
						else
						{
							obj_name = L"SURFFO";
						}
						ON_3dPoint point0(point.x, (point.y + 70.0), point.z);
						ON_3dPoint point1(point.x, (point.y - 70.0), point.z);
						ON_LineCurve* curve = new ON_LineCurve();
						curve->SetStartPoint(point0);
						curve->SetEndPoint(point1);
						ON_SumSurface sumSurf0;
						sumSurf0.Create(*curve, *curve00);

						if( context.m_doc.AddSurfaceObject(sumSurf0) )
						{

							context.m_doc.Redraw();
							next_sn = CRhinoObject::NextRuntimeObjectSerialNumber();
							if( first_sn == next_sn )
							{
								return CRhinoCommand::nothing;
							}
							else
							{
								SetNametoObject(context.m_doc,first_sn,obj_name,true);			  
							}
						}

					}
				}/*CLOSED FOR*/

				//int R = 0;
				//object_count = context.m_doc.LookupObject( layer, objects );
				//for(int i = 0; i < object_count; i++)
				//{
				//	object = objects[ i ];
				//	const CRhinoCurveObject* surface_obj = CRhinoCurveObject::Cast(object);
				//	if(surface_obj)
				//	{
				//		R++;
				//	}
				//}

				 // // Get the string entered by the user
				 // ON_wString obj_name = gs.String();
				 // obj_name.TrimLeftAndRight();
				 //
				 // // Is name the same?
				 // if( obj_name.Compare(obj_attribs.m_name) == 0 )
					//return CRhinoCommand::nothing;
				 //
				 // // Modify the attributes of the object
				 // obj_attribs.m_name = obj_name;
				 // context.m_doc.ModifyObjectAttributes( objref, obj_attribs );
				 // if(selectobjectbyuuid_s(context.m_doc,obj_Surf[j],false))
				 // {
					//int R = 0;
				 // }



			  
			  ON_wString obj_Surf[2];
			  ON_wString name;
              obj_Surf[0] = L"SURFPV";
			  obj_Surf[1] = L"SURFFO";
			  object_count = context.m_doc.LookupObject( layer, objects );
			  int R = 0;
			  /************************/
			  /*TRY SPLITTING THE BREP*/
			  /************************/
			  for(int j = 0; j < 2; j++)
			  {
				  for(int i = 0; i < object_count; i++)
				  {
					  object = objects[ i ];

					  /*MAKE COPY OF OBJECT ATTRIBUTES. THIS OBJECTS*/ 
					  /*HOLDS AN OBJECT'S USER-DEFINED NAME.*/ 
					  ON_3dmObjectAttributes obj_attribs = object->Attributes();
			
					  name = object->Attributes().m_name;

					  surface_obj = CRhinoSurfaceObject::Cast( object );
					  if( surface_obj && !surface_obj->IsSolid())
					  {
						  ON_wString obj_SurfLoc = obj_Surf[j];

						  /*IS THE CUTTING SURFACE?*/
						  if( obj_SurfLoc.Compare(name) == 0 )
						  {							
							R++;
						  }
					  }/*CHIUSURA IF SUPERFICIE*/
				  } 
				 

				 // /************************/
				 // /*PICK THE BREP TO SPLIT*/ 
				 // /************************/
				 // CRhinoGetObject go;
				 // go.SetCommandPrompt( L"SELECT SOLID TO SPLIT" );
				 // go.SetGeometryFilter( CRhinoGetObject::polysrf_object  );//CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object 
				 // go.GetObjects( 1, 1 );
				 // if( go.CommandResult() != success )
				 // {
					//return go.CommandResult();
				 // }
				 // else
				 // {
					//	RhinoMessageBox(L"CYLINDER IS SELECTED", PlugIn()->PlugInName(), MB_OK | MB_ICONEXCLAMATION );
				 // }
				 //
				 // const CRhinoObjRef& split_ref = go.Object(0);
				 //
				 // const CRhinoObject* split_object = split_ref.Object();
				 // if( !split_object )
				 // {
					//return failure;
				 // }
				 //
				 // const ON_Brep* split = split_ref.Brep();
				 // if( !split )
				 // {
					//return failure;
				 // }

				 // ON_SimpleArray<ON_Brep*> pieces;
				 // double tol = context.m_doc.AbsoluteTolerance();
			 
				 // /***********************/
				 // /*PICK THE CUTTING BREP*/
				 // /***********************/
				 // go.SetCommandPrompt( L"SELECT CUTTING SURFACE OR POLYSUFACE" );
				 // go.SetGeometryFilter( CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object  ); 
				 // go.EnablePreSelect( FALSE );
				 // go.EnableDeselectAllBeforePostSelect( FALSE );
				 // go.GetObjects( 1, 2 );
				 // if( go.CommandResult() != success )
				 // {
					//return go.CommandResult();
				 // }

				 // const ON_Brep* cutter = go.Object(0).Brep();
				 // if( !cutter )
				 // {
					//return failure;
				 // }
				 //

				 // if( !RhinoBrepSplit(*split, *cutter, tol, pieces) )
				 // {
					//RhinoApp().Print( L"UNABLE TO SPLIT BREP.\n" );
				 // }
				 //
				 // int i, count = pieces.Count();
				 // if( count == 0 | count == 1 )
				 // {
					//if( count == 1 )
					//{
					//  delete pieces[0];
					//}
					//return nothing;
				 // }
				 //
				 // CRhinoObjectAttributes attrib = split_object->Attributes();
				 // attrib.m_uuid = ON_nil_uuid; 
				 //
				 // const CRhinoObjectVisualAnalysisMode* vam_list = split_object->m_analysis_mode_list;
				 //
				 // for( i = 0; i < count; i++ )
				 // {
					//CRhinoBrepObject* brep_object = new CRhinoBrepObject( attrib );
					//if( brep_object )
					//{
					//  brep_object->SetBrep( pieces[i] );
					//  if( context.m_doc.AddObject(brep_object) )
					//  {
					//	RhinoCopyAnalysisModes( vam_list, brep_object );

					//  }
					//  else
					//  {
					//	delete brep_object;
					//  }
					//}
				 // }
				 //
				 // context.m_doc.DeleteObject( split_ref ); 
				 // context.m_doc.Redraw();
			  }



		    /*CREATE A NEW LAYER*/
			  ON_Layer layer;
			  int layer_index = 0;
			  ON_Color color = ON_Color(0, 0, 0);
			  ON_wString layer_name_FONDELLO = L"FONDELLO";
			  layer.SetLayerName( layer_name_FONDELLO );
			  layer.SetPlotColor(color.Green());

			/*ADD THE LAYER TO THE LAYER TABLE*/ 
			  layer_index = context.m_doc.m_layer_table.AddLayer( layer );

			  ON_wString layer_name_MATRICE  = L"MATRICE";
			  layer.SetLayerName( layer_name_MATRICE );
			  layer.SetColor(color.Red());

			/*ADD THE LAYER TO THE LAYER TABLE*/ 
			  layer_index = context.m_doc.m_layer_table.AddLayer( layer );


			  ON_wString layer_name_FISSO    = L"FISSO";
			  layer.SetLayerName( layer_name_FISSO );
			  layer.SetColor(color.Blue());

			/*ADD THE LAYER TO THE LAYER TABLE*/ 
			  layer_index = context.m_doc.m_layer_table.AddLayer( layer );
	  
			  context.m_doc.Redraw();
			/*********************************************************/
			}
		}/*CLOSED IF OVER CHECKING BREP COUNT OBJECT*/
		else
		{
			RhinoMessageBox(L"THERE IS ALREADY A CYLINDER OBJECT", PlugIn()->PlugInName(), MB_OK | MB_ICONEXCLAMATION );
		}
	}
	/**********************************************************************/



  return CRhinoCommand::success;
}
Exemple #12
0
void ON_X_EVENT::Dump(ON_TextLog& text_log) const
{
  int j;

  text_log.Print("m_type: ");
  switch( m_type )
  {
  case ON_X_EVENT::no_x_event:
    text_log.Print("no_x_event");
    break;
  case ON_X_EVENT::ccx_point:
    text_log.Print("ccx_point");
    break;
  case ON_X_EVENT::ccx_overlap:
    text_log.Print("ccx_overlap");
    break;
  case ON_X_EVENT::csx_point:
    text_log.Print("csx_point");
    break;
  case ON_X_EVENT::csx_overlap:
    text_log.Print("csx_overlap");
    break;
  default:
    text_log.Print("illegal value");
    break;
  }
  text_log.Print("\n");
  text_log.PushIndent();

  switch( m_type )
  {
  case ON_X_EVENT::ccx_point:
  case ON_X_EVENT::csx_point:
    // don't use %g so the text_log double format can control display precision
    text_log.Print("curveA(");
    text_log.Print(m_a[0]);
    text_log.Print(") = \n");
    text_log.PushIndent();
    text_log.Print(m_A[0]);
    text_log.Print("\n");
    text_log.PopIndent();
    break;

  case ON_X_EVENT::ccx_overlap:
  case ON_X_EVENT::csx_overlap:
    // don't use %g so the text_log double format can control display precision
    text_log.Print("curveA(");
    text_log.Print(m_a[0]);
    text_log.Print(" to ");
    text_log.Print(m_a[1]);
    text_log.Print(") = \n");
    text_log.PushIndent();
    text_log.Print(m_A[0]);
    text_log.Print(" to ");
    text_log.Print(m_A[1]);
    text_log.Print("\n");
    text_log.PopIndent();
    break;

  case ON_X_EVENT::no_x_event:
    break;
  }

  switch( m_type )
  {
  case ON_X_EVENT::ccx_point:
    // don't use %g so the text_log double format can control display precision
    text_log.Print("curveB(");
    text_log.Print(m_b[0]);
    text_log.Print(") = \n");
    text_log.PushIndent();
    text_log.Print(m_B[0]);
    text_log.Print("\n");
    text_log.PopIndent();
    DumpDistanceABHelper(text_log,m_A[0],m_B[0]);
    break;

  case ON_X_EVENT::csx_point:
    // don't use %g so the text_log double format can control display precision
    text_log.Print("surfaceB");
    text_log.Print(ON_2dPoint(m_b[0],m_b[1]));
    text_log.Print(" = \n");
    text_log.PushIndent();
    text_log.Print(m_B[0]);
    text_log.Print("\n");
    text_log.PopIndent();
    DumpDistanceABHelper(text_log,m_A[0],m_B[0]);
    break;

  case ON_X_EVENT::ccx_overlap:
    // don't use %g so the text_log double format can control display precision
    text_log.Print("curveB(");
    text_log.Print(m_b[0]);
    text_log.Print(" to ");
    text_log.Print(m_b[1]);
    text_log.Print(") = \n");
    text_log.PushIndent();
    text_log.Print(m_B[0]);
    text_log.Print(" to ");
    text_log.Print(m_B[1]);
    text_log.Print("\n");
    text_log.PopIndent();
    DumpDistanceABHelper(text_log,m_A[0],m_B[0],m_A[1],m_B[1]);
    break;

  case ON_X_EVENT::csx_overlap:
    // don't use %g so the text_log double format can control display precision
    text_log.Print("surface(");
    text_log.Print(ON_2dPoint(m_b[0],m_b[1]));
    text_log.Print(" to ");
    text_log.Print(ON_2dPoint(m_b[2],m_b[3]));
    text_log.Print(") =  \n");
    text_log.PushIndent();
    text_log.Print(m_B[0]);
    text_log.Print(" to ");
    text_log.Print(m_B[1]);
    text_log.Print("\n");
    text_log.PopIndent();
    DumpDistanceABHelper(text_log,m_A[0],m_B[0],m_A[1],m_B[1]);
    break;

  case ON_X_EVENT::no_x_event:
    break;
  }

  text_log.Print("m_dirA[] = (");
  for ( j = 0; j < 2; j++ )
  {
    if (j)
    {
      text_log.Print(", ");
    }
    switch(m_dirA[j])
    {
    case ON_X_EVENT::no_x_dir:
      text_log.Print("no_x_dir");
      break;
    case ON_X_EVENT::at_end_dir:
      text_log.Print("at_end_dir");
      break;
    case ON_X_EVENT::from_above_dir:
      text_log.Print("from_above_dir");
      break;
    case ON_X_EVENT::from_below_dir:
      text_log.Print("from_below_dir");
      break;
    case ON_X_EVENT::from_on_dir:
      text_log.Print("from_on_dir");
      break;
    case ON_X_EVENT::to_above_dir:
      text_log.Print("to_above_dir");
      break;
    case ON_X_EVENT::to_below_dir:
      text_log.Print("to_below_dir");
      break;
    case ON_X_EVENT::to_on_dir:
      text_log.Print("to_on_dir");
      break;
    default:
      text_log.Print("illegal value");
      break;
    }
  }
  text_log.Print(")\n");

#if defined(OPENNURBS_PLUS_INC_)
  switch( m_type )
  {
  case ON_X_EVENT::ccx_point:
  case ON_X_EVENT::ccx_overlap:
    text_log.Print("cnodeA sn = %d,%d  ",m_cnodeA[0]?m_cnodeA[0]->m_nodesn:-1,m_cnodeA[1]?m_cnodeA[1]->m_nodesn:-1);
    text_log.Print("cnodeB sn = %d,%d\n",m_cnodeB[0]?m_cnodeB[0]->m_nodesn:-1,m_cnodeB[1]?m_cnodeB[1]->m_nodesn:-1);
    break;

  case ON_X_EVENT::csx_point:
  case ON_X_EVENT::csx_overlap:
    text_log.Print("cnodeA sn = %d,%d  ",m_cnodeA[0]?m_cnodeA[0]->m_nodesn:-1,m_cnodeA[1]?m_cnodeA[1]->m_nodesn:-1);
    text_log.Print("snodeB sn = %d,%d\n",m_snodeB[0]?m_snodeB[0]->m_nodesn:-1,m_snodeB[1]?m_snodeB[1]->m_nodesn:-1);
    break;
  }
#endif

  text_log.PopIndent();
}
int ON_Intersect(
      const ON_Line& line, 
      const ON_Circle& circle,
      double* line_t0,
      ON_3dPoint& circle_point0,
      double* line_t1,
      ON_3dPoint& circle_point1
      )
{
  // transform to coordinate system where equation of circle
  // is x^2 + y^2 = R^2 and solve for line parameter(s).
  ON_Xform xform;
  xform.ChangeBasis( circle.plane, ON_xy_plane );
  xform.ChangeBasis( ON_xy_plane, circle.plane );
  ON_Line L = line;
  L.Transform(xform);
  double r = fabs(circle.radius);
  double tol = r*ON_SQRT_EPSILON;
  if ( tol < ON_ZERO_TOLERANCE )
    tol = ON_ZERO_TOLERANCE;
  int xcnt;
  if (    fabs(L.from.x - L.to.x) <= tol 
       && fabs(L.from.y - L.to.y) <= tol
       && fabs(L.from.z - L.to.z) > tol )
  {
    xcnt = 0;
  }
  else
  {
    xcnt = Intersect2dLineCircle( ON_2dPoint(L.from), ON_2dPoint(L.to), r, tol, line_t0, line_t1 );
    if ( xcnt == 3 )
      xcnt = 1;
  }
  
  if ( xcnt == 0 )
  {
    if ( L.ClosestPointTo( circle.Center(), line_t0 ) )
    {
      xcnt = 1;
      *line_t1 = *line_t0;
    }
  }
  ON_3dPoint line_point1, line_point0 = line.PointAt(*line_t0);
  circle_point0 = circle.ClosestPointTo(line_point0);
  double d1, d0 = line_point0.DistanceTo(circle_point0);
  if ( xcnt == 2 ) 
  {
    line_point1 = line.PointAt(*line_t1);
    circle_point1 = circle.ClosestPointTo(line_point1);
    d1 = line_point1.DistanceTo(circle_point1);
  }
  else
  {
    line_point1 = line_point0;
    circle_point1 = circle_point0;
    d1 = d0;
  }
  if ( xcnt==2 && (d0 > tol && d1 > tol) )
  {
    xcnt = 1;
    if ( d0 <= d1 ) 
    {
      *line_t1 = *line_t0;
      line_point1 = line_point0;
      circle_point1 = circle_point0;
      d1 = d0;
    }
    else
    {
      *line_t0 = *line_t1;
      line_point0 = line_point1;
      circle_point0 = circle_point1;
      d0 = d1;
    }
  }
  if ( xcnt == 1 && d0 > tol )
  {
    // TODO: iterate to closest point
  }
  return xcnt;
}