Short Description fails to register with CustomObjects (RhinoCommon)


I am trying to create a widget that has exactly the same function as a mapping widget, where it records scaling, rotation and spacing of a pattern.

As opposed to a 3d box like the mapping widget, I just need a 2D rectangle widget which looks like the mapping widget with its dashed thickened lines and colors.
One should be able to rotate, scale and move them, but not deform the rectangle.
And upon selecting, the type would be pattern widget. (as in “1 pattern widget added to selection”)

Any advice on where I can begin with this task? @dale @stevebaer ?
.

This is my current but failed attempt at it.


    public class CustomPoint : CustomPointObject
    {
        private Color clr = Color.AliceBlue;
        public CustomPoint()
        {

        }

        public CustomPoint(Point3d at) : base(new Rhino.Geometry.Point(at))
        {
            

        }

        public override string ShortDescription(bool plural)
        {
            return plural ? "Widgets" : "Widget";
        }

        protected override void OnDraw(DrawEventArgs e)
        {
            e.Display.DrawCircle(new Circle(this.PointGeometry.Location, 1.0), clr);
            e.Display.Draw3dText(new Text3d("sdf", new Plane(this.PointGeometry.Location, new Vector3d(0, 0, 1)), 1), clr);
            //base.OnDraw(e);
        }

        protected override void OnAddToDocument(RhinoDoc doc)
        {
            base.OnAddToDocument(doc);
        }

        protected override void OnTransform(Transform transform)
        {
            base.OnTransform(transform);
        }

        protected override void OnPicked(PickContext context, IEnumerable<ObjRef> pickedItems)
        {
            if (clr == Color.Black)
                clr = Color.AliceBlue;
            else
                clr = Color.Black;

            base.OnPicked(context, pickedItems);
        }


        protected override void OnSelectionChanged()
        {

            base.OnSelectionChanged();
        }

        protected override IEnumerable<ObjRef> OnPick(PickContext context)
        {
            return base.OnPick(context);
        }
    }

Edit: I have figured out most of it.

    public class GradingCurve : CustomCurveObject
    {
        private Color clr = Color.AliceBlue;
        public GradingCurve()
        {
        }
        public GradingCurve(Polyline curve) : base(new PolylineCurve(curve))
        {

        }

        public override string ShortDescription(bool plural)
        {
            return plural ? "Grading Curves" : "Grading Curve";
        }

        protected override void OnDraw(DrawEventArgs e)
        {
            e.Display.DrawCircle(new Circle(this.PointGeometry.Location, 1.0), clr);
            e.Display.Draw3dText(new Text3d("sdf", new Plane(this.PointGeometry.Location, new Vector3d(0, 0, 1)), 1), clr);
            //base.OnDraw(e);
        }

        protected override void OnAddToDocument(RhinoDoc doc)
        {
            base.OnAddToDocument(doc);
        }

        protected override void OnTransform(Transform transform)
        {
            base.OnTransform(transform);
        }

        protected override void OnPicked(PickContext context, IEnumerable<ObjRef> pickedItems)
        {
            if (clr == Color.Black)
                clr = Color.AliceBlue;
            else
                clr = Color.Black;

            base.OnPicked(context, pickedItems);
        }

    }

Revisiting this topic again.
While I can change the name of the CustomPointObject, I don’t seem to be able to call the ShortDescription() method with CustomCurveObject.
In the prompt it is still showing as closed curve, as opposed to Grading Curve, which I have set.

Can anyone shed any lights on this?
@dale

The top of the What output reads “Grading Curve”, which is what your method returns.

– Dale

@dale
Thanks for replying!
But the return in the prompt still says “1 closed curve added to selection.”
As opposed to
“1 Grading Curve added to selection”

It’s quite inconsistent isn’t it?

I see the issue when selecting a single, non-point custom object.

https://mcneel.myjetbrains.com/youtrack/issue/RH-72837

– Dale

1 Like

RH-72837 is fixed in the latest WIP

1 Like

Same thing happened to CustomGripObject

  public class SampleCsRectangleGrip : CustomGripObject
  {

    public bool Active { get; set; }

    /// <summary>
    /// Constructor
    /// </summary>
    public SampleCsRectangleGrip()
    {
      Active = true;
    }

    /// <summary>
    /// RhinoObject override
    /// </summary>
    public override string ShortDescription(bool plural)
    {
      return plural ? "rectangle points" : "rectangle point";
    }
    protected override void OnDraw(DrawEventArgs e)
    {
      base.OnDraw(e);
      e.Display.DrawPoint(this.CurrentLocation, PointStyle.Circle, 1f, System.Drawing.Color.Red);
    }

  }

image

OnDraw / ShortDescription / OnSelectionChanged events are not triggered at all testing with the SampleCsRectangleGrips in rhino-develop-samples

e.g. I tried to change the grip style by overriding the OnDraw EventHandler, but fails to do so in CustomGripObject
@dale

push this as this is still unresolved.

The reason I need this is because I need to override the OnPick handler to have a larger PickContext for a CustomGripObject.
As it is now when the CustomGripObject is embeded in CustomObjectGrips, all the eventhandlers are not called.