Exemplo n.º 1
0
 public override bool Draw(RenderingParameters parameters)
 {
     if (parameters is RhinoRenderingParameters && RenderCurve != null)
     {
         RhinoRenderingParameters rParams = (RhinoRenderingParameters)parameters;
         if (RenderCurve is RC.LineCurve && Dotted) //?
         {
             RC.Line line = ((RC.LineCurve)RenderCurve).Line;
             if (Dotted)
             {
                 rParams.Display.DrawDottedLine(line, Material.Diffuse);
             }
             else
             {
                 rParams.Display.DrawLine(line, Material.Diffuse);
             }
         }
         else
         {
             rParams.Display.DrawCurve(RenderCurve, Material.Diffuse, 3);
         }
         double arrS = ToRC.Convert(0.3);
         if (ArrowStart)
         {
             rParams.Display.DrawArrowHead(RenderCurve.PointAtStart - arrS * RenderCurve.TangentAtStart, -RenderCurve.TangentAtStart, Material.Diffuse, 0, arrS);
         }
         if (ArrowEnd)
         {
             rParams.Display.DrawArrowHead(RenderCurve.PointAtEnd + arrS * RenderCurve.TangentAtEnd, RenderCurve.TangentAtEnd, Material.Diffuse, 0, arrS);
         }
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
        protected override void OnDynamicDraw(GetPointDrawEventArgs e)
        {
            IAction action = Core.Instance.Actions.CurrentAction;

            if (action != null)
            {
                PreviewParameters pParam;
                if (SelectionPoints == null)
                {
                    Point3d basePt;
                    TryGetBasePoint(out basePt);
                    pParam = new PreviewParameters(true, null, FromRC.Convert(e.CurrentPoint), FromRC.Convert(basePt));
                }
                else
                {
                    IList <Vector> sPts = new List <Vector>();
                    foreach (Vector pt in SelectionPoints)
                    {
                        sPts.Add(pt);
                        // Draw points:
                        e.Display.DrawPoint(ToRC.Convert(pt), PointStyle.X, 3, System.Drawing.Color.Orange);
                    }
                    sPts.Add(FromRC.Convert(e.CurrentPoint));
                    pParam = new PreviewParameters(true, null, sPts);
                }
                DisplayLayer previewLayer = action.PreviewLayer(pParam);
                if (previewLayer != null)
                {
                    var rParam = new RhinoRenderingParameters(e);
                    previewLayer.Draw(rParam);
                }
            }

            base.OnDynamicDraw(e);
        }
Exemplo n.º 3
0
 public override bool CastTo <Q>(ref Q target)
 {
     if (typeof(Q).IsAssignableFrom(typeof(GH_Point)))
     {
         target = (Q)((object)new GH_Point(ToRC.Convert(Value.Position)));
         return(true);
     }
     return(base.CastTo <Q>(ref target));
 }
Exemplo n.º 4
0
        public void DrawViewportWires(GH_PreviewWireArgs args)
        {
            if (Value != null)
            {
                args.Pipeline.DrawPoint(ToRC.Convert(Value.Position), RD.PointStyle.X, 8, args.Color);

                /*Mesh mesh = SupportMesh;
                 * if (mesh != null) args.Pipeline.DrawMeshWires(mesh, args.Color);*/
            }
        }
Exemplo n.º 5
0
 public override bool Draw(RenderingParameters parameters)
 {
     if (parameters is RhinoRenderingParameters && _Label != null)
     {
         RhinoRenderingParameters rParams = (RhinoRenderingParameters)parameters;
         var scrPt = rParams.Display.Viewport.WorldToClient(ToRC.Convert(_Label.Position));
         scrPt.X += 2;
         scrPt.Y -= 2;
         rParams.Display.Draw2dText(_Label.Text, System.Drawing.Color.GhostWhite, scrPt, !_Label.HorizontalSetOut.IsEdge());
         return(true);
     }
     return(false);
 }
 public override bool Draw(RenderingParameters parameters)
 {
     if (parameters is RhinoRenderingParameters && _CoordinateSystem != null)
     {
         RhinoRenderingParameters rParams = (RhinoRenderingParameters)parameters;
         if (_CoordinateSystem is CartesianCoordinateSystem)
         {
             CartesianCoordinateSystem cSystem = (CartesianCoordinateSystem)_CoordinateSystem;
             rParams.Display.DrawDirectionArrow(ToRC.Convert(cSystem.Origin), ToRC.ConvertVector(cSystem.X), System.Drawing.Color.LightGray);
             rParams.Display.DrawDirectionArrow(ToRC.Convert(cSystem.Origin), ToRC.ConvertVector(cSystem.Y), System.Drawing.Color.Gray);
             rParams.Display.DrawDirectionArrow(ToRC.Convert(cSystem.Origin), ToRC.ConvertVector(cSystem.Z), System.Drawing.Color.Orange);
         }
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Host.EnsureInitialisation();

            LinearElementCollection elements = Core.Instance.ActiveDocument.Model.Elements.LinearElements;

            foreach (LinearElement lEl in elements)
            {
                if (!lEl.IsDeleted)
                {
                    Extrusion extrusion = ToRC.ConvertToExtrusion(lEl);
                    Guid      guid      = Guid.Empty;
                    if (extrusion != null)
                    {
                        guid = RhinoOutput.BakeExtrusion(extrusion);
                    }
                    else
                    {
                        Brep brep = ToRC.ConvertToBrep(lEl);
                        if (brep != null)
                        {
                            guid = RhinoOutput.Bake(brep);
                        }
                    }
                    if (guid != Guid.Empty)
                    {
                        RhinoOutput.SetObjectName(guid, lEl.Name);
                        if (lEl.Family != null)
                        {
                            RhinoOutput.SetObjectUserString(guid, "Family", lEl.Family.Name);
                            if (lEl.Family.GetPrimaryMaterial() != null)
                            {
                                RhinoOutput.SetObjectUserString(guid, "Material", lEl.Family.GetPrimaryMaterial().Name);
                            }
                            if (lEl.Family.Profile != null)
                            {
                                RhinoOutput.SetObjectUserString(guid, "Profile", lEl.Family.Profile.ToString());
                            }
                        }
                    }
                }
            }
            Host.Instance.Refresh();

            return(Result.Success);
        }
Exemplo n.º 8
0
        public void DrawViewportWires(GH_PreviewWireArgs args)
        {
            if (Value?.Geometry != null)
            {
                if (Value.Geometry is FB.Line)
                {
                    args.Pipeline.DrawLine(
                        new Line(ToRC.Convert(Value.Geometry.StartPoint), ToRC.Convert(Value.Geometry.EndPoint)), args.Color);
                }
                else if (Value.Geometry is FB.Arc)
                {
                    args.Pipeline.DrawArc(
                        new Arc(ToRC.Convert(Value.Geometry.StartPoint), ToRC.Convert(Value.Geometry.PointAt(0.5)), ToRC.Convert(Value.Geometry.EndPoint)),
                        args.Color);
                }

                args.Pipeline.DrawMeshWires(SectionMesh, args.Color);
            }
        }
Exemplo n.º 9
0
 public override bool CastTo <Q>(ref Q target)
 {
     if (typeof(Q).IsAssignableFrom(typeof(ElementGoo)))
     {
         target = (Q)(object)new ElementGoo(Value);
         return(true);
     }
     else if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
     {
         target = (Q)((object)new GH_Curve(ToRC.Convert(Value.Geometry)));
         return(true);
     }
     else if (typeof(Q).IsAssignableFrom(typeof(GH_Line)))
     {
         if (Value.Geometry is FB.Line)
         {
             target = (Q)((object)new GH_Line(ToRC.ConvertToLine((FB.Line)Value.Geometry)));
             return(true);
         }
     }
     else if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh)))
     {
         if (SectionMesh != null)
         {
             target = (Q)((object)new GH_Mesh(SectionMesh));
             return(true);
         }
     }
     else if (typeof(Q).IsAssignableFrom(typeof(GH_Surface)))
     {
         var surface = ToRC.ConvertToExtrusion(Value);
         target = (Q)(object)new GH_Surface(surface);
         return(surface != null);
     }
     else if (typeof(Q).IsAssignableFrom(typeof(GH_Brep)))
     {
         target = (Q)(object)new GH_Brep(ToRC.ConvertToBrep(Value));
         return(true);
     }
     return(base.CastTo <Q>(ref target));
 }
Exemplo n.º 10
0
        public override bool CastTo <Q>(ref Q target)
        {
            if (typeof(Q).IsAssignableFrom(typeof(ElementGoo)))
            {
                target = (Q)(object)new ElementGoo(Value);
                return(true);
            }
            else if (typeof(Q).IsAssignableFrom(typeof(GH_Surface)))
            {
                var surface = ToRC.Convert(Value.Geometry) as Surface;
                target = (Q)(object)new GH_Surface(surface);
                return(surface != null);
            }
            else if (typeof(Q).IsAssignableFrom(typeof(GH_Brep)))
            {
                var surface = ToRC.Convert(Value.Geometry) as Brep;
                target = (Q)(object)new GH_Brep(surface);
                return(surface != null);
            }

            return(false);
        }
 /// <summary>
 /// Wrap an object in goo, if possible
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 protected object FormatForOutput(object obj, ExecutionInfo exInfo)
 {
     if (obj is Vector)
     {
         return(ToRC.Convert((Vector)obj));
     }
     else if (obj is Curve)
     {
         return(ToRC.Convert((Curve)obj));
     }
     else if (obj is CurveCollection)
     {
         return(ToRC.Convert((CurveCollection)obj));
     }
     else if (obj is VertexGeometry)
     {
         return(ToRC.Convert((VertexGeometry)obj));
     }
     else if (obj is VertexGeometryCollection)
     {
         return(ToRC.Convert((VertexGeometryCollection)obj));
     }
     else if (obj is LinearElement)
     {
         return(new LinearElementGoo((LinearElement)obj, exInfo));
     }
     else if (obj is LinearElementCollection)
     {
         return(LinearElementGoo.Convert((LinearElementCollection)obj));
     }
     else if (obj is PanelElement)
     {
         return(new PanelElementGoo((PanelElement)obj));
     }
     else if (obj is PanelElementCollection)
     {
         return(PanelElementGoo.Convert((PanelElementCollection)obj));
     }
     else if (obj is Element)
     {
         return(new ElementGoo((Element)obj));
     }
     else if (obj is ElementCollection)
     {
         return(ElementGoo.Convert((ElementCollection)obj));
     }
     else if (obj is SectionFamily)
     {
         return(new SectionFamilyGoo((SectionFamily)obj));
     }
     else if (obj is SectionFamilyCollection)
     {
         return(SectionFamilyGoo.Convert((SectionFamilyCollection)obj));
     }
     else if (obj is BuildUpFamily)
     {
         return(new BuildUpFamilyGoo((BuildUpFamily)obj));
     }
     else if (obj is BuildUpFamilyCollection)
     {
         return(BuildUpFamilyGoo.Convert((BuildUpFamilyCollection)obj));
     }
     else if (obj is Node)
     {
         return(new NodeGoo((Node)obj, exInfo));
     }
     else if (obj is NodeCollection)
     {
         return(NodeGoo.Convert((NodeCollection)obj, exInfo));
     }
     else if (obj is Nucleus.Model.Material)
     {
         return(new MaterialGoo((Nucleus.Model.Material)obj));
     }
     else if (obj is MaterialCollection)
     {
         return(MaterialGoo.Convert((MaterialCollection)obj));
     }
     else if (obj is Bool6D)
     {
         return(new Bool6DGoo((Bool6D)obj));
     }
     else if (obj is FilePath)
     {
         return(obj.ToString());
     }
     //Add more types here
     return(obj);
 }
        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            IAction              action = (IAction)Activator.CreateInstance(ActionType, true);
            NicknameConverter    nC     = new NicknameConverter();
            IList <PropertyInfo> inputs = ActionBase.ExtractInputParameters(ActionType);

            foreach (PropertyInfo pInfo in inputs)
            {
                Type pType = pInfo.PropertyType;
                ActionInputAttribute inputAtt = ActionInputAttribute.ExtractFrom(pInfo);
                if (inputAtt != null && inputAtt.Parametric)
                {
                    string name        = pInfo.Name;
                    string nickname    = string.IsNullOrEmpty(inputAtt.ShortName) ? nC.Convert(pInfo.Name) : inputAtt.ShortName;
                    string description = inputAtt.CapitalisedDescription;
                    if (pType == typeof(double))
                    {
                        pManager.AddNumberParameter(name, nickname, description, GH_ParamAccess.item, (double)pInfo.GetValue(action, null));
                    }
                    else if (pType == typeof(int))
                    {
                        pManager.AddIntegerParameter(name, nickname, description, GH_ParamAccess.item, (int)pInfo.GetValue(action, null));
                    }
                    else if (pType == typeof(string))
                    {
                        pManager.AddTextParameter(name, nickname, description, GH_ParamAccess.item, (string)pInfo.GetValue(action, null));
                    }
                    else if (pType == typeof(bool))
                    {
                        //Special case when the input is a 'Write' toggle - default off!
                        pManager.AddBooleanParameter(name, nickname, description, GH_ParamAccess.item, name == "Write" ? false : (bool)pInfo.GetValue(action, null));
                    }
                    else if (pType == typeof(Vector))
                    {
                        pManager.AddPointParameter(name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (typeof(IList <Vector>).IsAssignableFrom(pType)) //Vector list
                    {
                        pManager.AddPointParameter(name, nickname, description, GH_ParamAccess.list);
                    }
                    else if (pType.IsAssignableFrom(typeof(Plane)))
                    {
                        pManager.AddPlaneParameter(name, nickname, description, GH_ParamAccess.item, ToRC.Convert((Plane)pInfo.GetValue(action, null)));
                    }
                    else if (pType == typeof(Line))
                    {
                        pManager.AddLineParameter(name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (pType == typeof(Angle))
                    {
                        pManager.AddAngleParameter(name, nickname, description, GH_ParamAccess.item, (Angle)pInfo.GetValue(action, null));
                    }
                    else if (typeof(Curve).IsAssignableFrom(pType))
                    {
                        pManager.AddCurveParameter(name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (typeof(CurveCollection).IsAssignableFrom(pType))
                    {
                        pManager.AddCurveParameter(name, nickname, description, GH_ParamAccess.list);
                    }
                    else if (typeof(LinearElement).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new LinearElementParam();
                        pManager.AddParameter(param, name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (typeof(PanelElement).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new PanelElementParam();
                        pManager.AddParameter(param, name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (typeof(Element).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new ElementParam();
                        pManager.AddParameter(param, name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (typeof(LinearElementCollection).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new LinearElementParam();
                        pManager.AddParameter(param, name, nickname, description, ParamAccess(inputAtt));
                    }
                    else if (typeof(PanelElementCollection).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new PanelElementParam();
                        pManager.AddParameter(param, name, nickname, description, ParamAccess(inputAtt));
                    }
                    else if (typeof(ElementCollection).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new ElementParam();
                        pManager.AddParameter(param, name, nickname, description, ParamAccess(inputAtt));
                    }
                    else if (pType == typeof(Node))
                    {
                        IGH_Param param = new NodeParam();
                        pManager.AddParameter(param, name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (pType == typeof(NodeCollection))
                    {
                        IGH_Param param = new NodeParam();
                        pManager.AddParameter(param, name, nickname, description, ParamAccess(inputAtt));
                    }
                    else if (typeof(Nucleus.Model.Material).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new MaterialParam();
                        pManager.AddParameter(param, name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (typeof(MaterialCollection).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new MaterialParam();
                        pManager.AddParameter(param, name, nickname, description, ParamAccess(inputAtt));
                    }
                    else if (typeof(SectionFamily).IsAssignableFrom(pType))
                    {
                        IGH_Param param = new SectionFamilyParam();
                        pManager.AddParameter(param, name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (pType == typeof(Bool6D))
                    {
                        IGH_Param param = new Bool6DParam();
                        pManager.AddParameter(param, name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (pType == typeof(FilePath))
                    {
                        pManager.AddTextParameter(name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (pType == typeof(VertexGeometry))
                    {
                        pManager.AddGeometryParameter(name, nickname, description, GH_ParamAccess.item);
                    }
                    else if (pType == typeof(VertexGeometryCollection))
                    {
                        pManager.AddGeometryParameter(name, nickname, description, ParamAccess(inputAtt));
                    }
                    else if (pType == typeof(ActionTriggerInput))
                    {
                        pManager.AddGenericParameter(name, nickname, description, GH_ParamAccess.tree);
                    }
                    else if (pType == typeof(Direction))
                    {
                        pManager.AddTextParameter(name, nickname, description, GH_ParamAccess.item, pInfo.GetValue(action, null)?.ToString());
                    }
                    else if (pType == typeof(CoordinateSystemReference))
                    {
                        pManager.AddTextParameter(name, nickname, description, GH_ParamAccess.item, pInfo.GetValue(action, null)?.ToString());
                    }
                    else if (pType.IsEnum)
                    {
                        pManager.AddTextParameter(name, nickname, description, GH_ParamAccess.item, pInfo.GetValue(action, null)?.ToString());
                    }
                    else
                    {
                        pManager.AddGenericParameter(pInfo.Name, nickname, description, GH_ParamAccess.item);
                    }

                    if (inputAtt.Required == false)
                    {
                        pManager[pManager.ParamCount - 1].Optional = true;
                    }

                    //TODO
                }
            }
        }
 protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e)
 {
     base.CalculateBoundingBox(e);
     RC.BoundingBox bBox = ToRC.Convert(Core.Instance.ActiveDocument.Model.BoundingBox);
     e.IncludeBoundingBox(bBox);
 }