///<summary> This gets called when when the user runs this command.</summary>
    public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
    {
      MRhinoGetObject go = new MRhinoGetObject();
      go.SetCommandPrompt("Select edge curve");
      go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
      go.GetObjects(1, 1);
      if (go.CommandResult() != IRhinoCommand.result.success)
        return go.CommandResult();

      IRhinoObject obj = go.Object(0).Object();
      IOnBrep brep = go.Object(0).Brep();
      IOnBrepEdge edge = go.Object(0).Edge();
      if (null == obj || null == brep || null == edge)
        return IRhinoCommand.result.failure;

      MRhinoObjectAttributes attribs = new MRhinoObjectAttributes(obj.Attributes());
      if (attribs.GroupCount() > 0)
        attribs.RemoveFromAllGroups();

      for (int i = 0; i < edge.TrimCount(); i++)
      {
        IOnBrepTrim trim = edge.Trim(i);
        if (null != trim)
        {
          IOnBrepFace face = trim.Face();
          if (null != face)
          {
            OnBrep face_brep = brep.DuplicateFace(face.m_face_index, true);
            if (null != face_brep)
            {
              MRhinoBrepObject face_brep_obj = context.m_doc.AddBrepObject(face_brep, attribs);
              if (null != face_brep_obj)
                face_brep_obj.Select();
            }
          }
        }
      }

      context.m_doc.Redraw();

      return IRhinoCommand.result.success;
    }
Example #2
0
        public void SetBrep(IOnBrep brep)
        {
            if (null == brep || !brep.IsValid())
            {
                return;
            }

            m_brep = brep;

            int face_count = m_brep.m_F.Count();

            m_points.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);
            m_normals.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT);

            m_points.SetCount(0);
            m_normals.SetCount(0);

            for (int i = 0; i < face_count; i++)
            {
                IOnBrepFace face = m_brep.m_F[i];
                IOnBrepLoop loop = face.OuterLoop();
                if (null == loop)
                {
                    continue;
                }

                OnInterval udomain = face.Domain(0);
                OnInterval vdomain = face.Domain(1);

                if (loop.m_pbox.IsValid())
                {
                    OnInterval domain = new OnInterval();
                    domain.Set(loop.m_pbox.m_min.x, loop.m_pbox.m_max.x);
                    domain.Intersection(udomain);
                    if (domain.IsIncreasing())
                    {
                        udomain.Set(domain.Min(), domain.Max());
                    }
                    domain.Set(loop.m_pbox.m_min.y, loop.m_pbox.m_max.y);
                    domain.Intersection(vdomain);
                    if (domain.IsIncreasing())
                    {
                        vdomain.Set(domain.Min(), domain.Max());
                    }
                }

                bool bUntrimmed = m_brep.FaceIsSurface(i);

                ArrayOnInterval intervals = new ArrayOnInterval();
                bool            bRev      = face.m_bRev;

                for (double u = 0.0; u < SURFACE_ARROW_COUNT; u += 1.0)
                {
                    double d = u / (SURFACE_ARROW_COUNT - 1.0);
                    double s = udomain.ParameterAt(d);

                    intervals.SetCount(0);

                    if (bUntrimmed || RhUtil.RhinoGetIsoIntervals(face, 1, s, intervals) > 0)
                    {
                        for (double v = 0.0; v < SURFACE_ARROW_COUNT; v += 1.0)
                        {
                            d = v / (SURFACE_ARROW_COUNT - 1.0);
                            double t = vdomain.ParameterAt(d);

                            bool bAdd = bUntrimmed;
                            for (int k = 0; !bAdd && k < intervals.Count(); k++)
                            {
                                if (intervals[k].Includes(t))
                                {
                                    bAdd = true;
                                }
                            }

                            if (bAdd)
                            {
                                On3dPoint  pt  = new On3dPoint();
                                On3dVector du  = new On3dVector();
                                On3dVector dv  = new On3dVector();
                                On3dVector dir = new On3dVector();
                                if (face.EvNormal(s, t, ref pt, ref du, ref dv, ref dir))
                                {
                                    m_points.Append(pt);
                                    if (bRev)
                                    {
                                        dir.Reverse();
                                    }
                                    m_normals.Append(dir);
                                }
                            }
                        }
                    }
                }
            }
        }