TextDot Conduit

Hello ,

I need create a textDot conduit c#, I set like this;

              TextDot dot = new TextDot(dir ,center);
                dot.FontHeight = 25;
                e.Display.DrawDot(dot, System.Drawing.Color.White, System.Drawing.Color.Black, 
             System.Drawing.Color.Black);

This is ok , I need to put the background with a solid color, in this case it is possible to see the lines.

Any way to do this?

There are various stages at which you can draw. I think that if you override DrawForeground in your display conduit, you should’ve able to draw on top of everything else.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_DisplayConduit_DrawForeground.htm

@menno

Sorry, and how can I do this? do you have an example?

Thanks

Can you post your complete code of the display conduit?

@menno

I have making test on this piece of code, is mess ok’:

namespace StCam.Conduits
{
class GcodeConduit : Rhino.Display.DisplayConduit
{

    public GcodeConduit()
    {
    }
    protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
    {
       
        var rhinoscript_object = RhinoApp.GetPlugInObject("RhinoScript");
        var rs = (IRhinoScript)rhinoscript_object;
        //get todos os objectos
        var objs = rs.ObjectsByType(4, false);
        if (objs.ToString() == "")
            return;
        foreach (var item in objs)
        {
            if (rs.IsObjectHidden(item))
            {
                continue;
            }

            var tool = rs.GetUserText(item, "tool");
            if (tool.ToString() != "")
            {
                SetLineColor(tool.ToString(), item, e);
            }

            var dir = rs.GetUserText(item, "angulo");
            if (dir.ToString() != "") 
            {  

                double sentido = 0;
                if (double.Parse(dir) == 0) { continue; }
                else if (double.Parse(dir) < 0) { sentido = -90; }
                else if (double.Parse(dir) > 0) { sentido = 90; }


                var pontos = rs.DivideCurve(item, 10);
                int count = -1;
                foreach (var ponto in pontos)
                { 
                    count = count + 1;
                    if (count == 0)
                        continue;
                    if (count == pontos.Length - 1)
                        continue;

                    var param = rs.CurveClosestPoint(item, ponto);

                    dynamic domainStart;
                    domainStart = param;
                    var domainEnd = domainStart + 0.001;
                    var ponto1 = rs.EvaluateCurve(item, domainStart);
                    var ponto2 = rs.EvaluateCurve(item, domainEnd);

                    Point3d st = new Point3d(ponto1[0], ponto1[1], ponto1[2]);
                    Point3d se = new Point3d(ponto2[0], ponto2[1], ponto2[2]);
                    double degree = sentido * 0.0174532925;

                    Vector3d vec = new Vector3d(se - st);
                    vec.Rotate(degree, new Vector3d(0, 0, 1));

                    Line linha = new Line(st, vec, 3);

                    e.Display.DrawArrow(linha, System.Drawing.Color.Maroon ,15,15);
                }
                //cria texto visual do angulo inserido
                var center1 = rs.CurveMidPoint(item);
                Point3d center = new Point3d(center1[0], center1[1], center1[2]+5);
                //e.Display.Draw2dText(dir, System.Drawing.Color.Blue, center, false, 30);

                
                TextDot dot = new TextDot(dir ,center);
                
                dot.FontHeight = 25;
                e.Display.DrawDot(dot, System.Drawing.Color.White, System.Drawing.Color.Black, 
               System.Drawing.Color.Black);
            }
        }
    }

    private void SetLineColor(string tool,object linha, Rhino.Display.DrawEventArgs e)
    {
        var rhinoscript_object = RhinoApp.GetPlugInObject("RhinoScript");
        var rs = (IRhinoScript)rhinoscript_object;
        var doc = Rhino.RhinoDoc.ActiveDoc;

        var st = rs.CurveStartPoint(linha);
        var mi = rs.CurveMidPoint(linha);
        var en = rs.CurveEndPoint(linha);
        Point3d start = new Point3d(st[0], st[1], st[2]);
        Point3d mid = new Point3d(mi[0], mi[1], mi[2]);
        Point3d end = new Point3d(en[0], en[1], en[2]);

        //define a color
        System.Drawing.Color cor = new System.Drawing.Color();
        if (tool == "0") { cor = System.Drawing.Color.LightGray; }
        else if (tool == "1") { cor = System.Drawing.Color.Black; }
        else if (tool == "2") { cor = System.Drawing.Color.LightCyan; }
        else if (tool == "3") { cor = System.Drawing.Color.Green; }
        else if (tool == "4") { cor = System.Drawing.Color.Red; }
        else if (tool == "5") { cor = System.Drawing.Color.Blue; }
        else if (tool == "6") { cor = System.Drawing.Color.Yellow; }

        if (rs.IsCurveLinear(linha))
        {
            Line line = new Line(start, end);
            e.Display.DrawLine(line, cor,3);
        }
        else if (rs.IsArc(linha))
        {
            Arc curva = new Arc(start,mid,end);
            e.Display.DrawArc(curva, cor, 3);
        }
        else if (rs.IsCircle(linha))
        {
            var ce = rs.CircleCenterPoint(linha);
            Point3d center = new Point3d(ce[0], ce[1], ce[2]);
            Circle ciculo = new Circle(center,rs.CircleRadius(linha));
            e.Display.DrawCircle(ciculo, cor, 3);
        }
        else
        {
            //var divisor = rs.DivideCurve(linha, 50);
            var polyline = rs.ConvertCurveToPolyline(linha, false);
            var divisor = rs.CurvePoints(polyline);
            rs.DeleteObject(polyline);
            List<Point3d> listaPontos = new List<Point3d>();
            IEnumerable<Point3d> lista;
            foreach (var div in divisor)
            {
                Point3d ponto = new Point3d(div[0], div[1], div[2]);
                listaPontos.Add(ponto);

            }
            lista = listaPontos;

            e.Display.DrawPolyline(lista,cor,3);
        }
      
    }
}

partial class GcodeDirection
{
    static GcodeConduit m_draw_conduit;
    public static Result ConduitGcode(RhinoDoc doc, bool state)
    {
        if (state == false)
        {

            m_draw_conduit.Enabled = false;
            //m_draw_conduit = null;
        }
        else
        {
            m_draw_conduit = new GcodeConduit();

            // toggle conduit on/off
            m_draw_conduit.Enabled = true;

        }
        doc.Views.Redraw();
        return Result.Success;
    }
}

}

Ok, I see that you are drawing all geometry in DrawForeground. I have created a small example conduit to do what you want, see below.
The idea is that you draw geometry in PostDrawObjects and then anything that needs to be on top of everything else in DrawForeground. In the DrawForeground the depth-testing is off.

  public class Conduit : DisplayConduit
  {
    protected override void PostDrawObjects(DrawEventArgs e)
    {
      e.Display.DrawPolyline(new[] { new Point3d(0, 0, 0), new Point3d(10, 0, 0), new Point3d(10, 10, 0), new Point3d(0, 10, 0), new Point3d(0, 0, 0) }, Color.DarkGreen, 3);
      base.PostDrawObjects(e);
    }

    protected override void DrawForeground(DrawEventArgs e)
    {
      // don't do this
      //e.Display.DrawPolyline(new[] { new Point3d(0, 0, 0), new Point3d(10, 0, 0), new Point3d(10, 10, 0), new Point3d(0, 10, 0), new Point3d(0, 0, 0) }, Color.DarkGreen, 3);

      Point3d c = new Point3d(5, 10, 0);
      TextDot dot = new TextDot("hello", c);
      e.Display.DrawDot(dot, Color.White, Color.Black, Color.Black);
      
      base.DrawForeground(e);
    }
  }

image

@menno

Nice.

Thank you