开放源码:
RHINO三维图形开发平台
[7]
// 自定义曲线分段
CRhinoCommand::result CCommandmyChangeSeam::RunCommand( const CRhinoCommandContext& context )
{
for(;;) {
CRhinoDoc *doc = RhinoApp().ActiveDoc();
CRhinoGetObject get;
if(get.GetObjects(1,0) != CRhinoGetObject::object)
return CRhinoCommand::cancel;
CRhinoObjRef ōbjref = get.Object(0);
const ON_Curve *crv = ON_Curve::Cast(objref.Geometry());
objref = get.Object(1);
const ON_Point *pt = ON_Point::Cast(objref.Geometry());
ON_NurbsCurve nurbcrv;
crv->GetNurbForm(nurbcrv);
ON_3dPoint point = *pt;
double t;
if(crv->GetClosestPoint(point,&t) == FALSE)
break;
if(changeseam(nurbcrv,t) == FALSE)
break;
objref = get.Object(0);
doc->ReplaceObject(objref,nurbcrv);
doc->Redraw();
break;
}
return CRhinoCommand::success;
}
BOOL CCommandmyChangeSeam::changeseam(ON_NurbsCurve &crv, double t)
{
BOOL rc = crv.IsClosed();
if (rc == TRUE)
{
const ON_Interval old_dom = crv.Domain();
if(t == old_dom.m_t[0] || t == old_dom.m_t[1])
return rc;
if(old_dom.Includes(t))
{
ON_NurbsCurve left,right;
left=crv;
right=crv;
if(right.Trim(ON_Interval(t,old_dom.m_t[1]))==FALSE)
{
return FALSE;
}
if(left.Trim(ON_Interval(old_dom.m_t[0],t))==FALSE)
{
return FALSE;
}
crv=right;
crv.Append(left);
crv.SetDomain(t,t+old_dom.Length());
return TRUE;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
}
//
// END myChangeSeam command