Ejemplo n.º 1
0
        private int ComputeW_ico(IGH_Component owner)
        {
            GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)owner;
            int num  = 24;
            int num2 = 0;
            int num3 = 0;

            foreach (IGH_Param componentInput in gH_SwitcherComponent.StaticData.GetComponentInputs())
            {
                int val = ((List <IGH_StateTag>)componentInput.StateTags).Count * 20;
                num3 = Math.Max(num3, val);
                num2 = Math.Max(num2, GH_FontServer.StringWidth(componentInput.NickName, StandardFont.font()));
            }
            num2  = Math.Max(num2 + 6, 12);
            num2 += num3;
            int num4 = 0;
            int num5 = 0;

            foreach (IGH_Param componentOutput in gH_SwitcherComponent.StaticData.GetComponentOutputs())
            {
                int val2 = ((List <IGH_StateTag>)componentOutput.StateTags).Count * 20;
                num5 = Math.Max(num5, val2);
                num4 = Math.Max(num4, GH_FontServer.StringWidth(componentOutput.NickName, StandardFont.font()));
            }
            num4  = Math.Max(num4 + 6, 12);
            num4 += num5;
            return(num2 + num + num4 + 6);
        }
Ejemplo n.º 2
0
        public static bool GetDataOrDefault(IGH_Component component, IGH_DataAccess DA, string name, out DB.Document document)
        {
            document = default;
            var _Document_ = component.Params.IndexOfInputParam(name);

            if (_Document_ < 0)
            {
                document = Revit.ActiveDBDocument;
                if (document?.IsValidObject != true)
                {
                    component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "There is no active Revit document");
                    return(false);
                }

                // In case the user has more than one document open we show which one this component is working on
                if (Revit.ActiveDBApplication.Documents.Size > 1)
                {
                    component.Message = document.Title.TripleDot(16);
                }
            }
            else
            {
                document = default;
                DA.GetData(_Document_, ref document);
                if (document?.IsValidObject != true)
                {
                    component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameter Document failed to collect data");
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates selection list for cell oritentation.
        /// </summary>
        /// <param name="index">Component input index. (first input is index 0)</param>
        /// <param name="offset">Vertical offset of the menu, to help with positioning.</param>
        public static void OrientSelect(ref IGH_Component Component, ref GH_Document GrasshopperDocument, int index, float offset)
        {
            // Instantiate  new value list
            var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
            vallist.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.Cycle;
            vallist.CreateAttributes();

            // Customise value list position
            float xCoord = (float)Component.Attributes.Pivot.X - 200;
            float yCoord = (float)Component.Attributes.Pivot.Y + index * 40 - offset;
            PointF cornerPt = new PointF(xCoord, yCoord);
            vallist.Attributes.Pivot = cornerPt;

            // Populate value list with our own data
            vallist.ListItems.Clear();
            var items = new List<Grasshopper.Kernel.Special.GH_ValueListItem>();
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Default", "0"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateZ", "1"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateY", "2"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateX", "3"));

            vallist.ListItems.AddRange(items);

            // Until now, the slider is a hypothetical object.
            // This command makes it 'real' and adds it to the canvas.
            GrasshopperDocument.AddObject(vallist, false);

            //Connect the new slider to this component
            Component.Params.Input[index].AddSource(vallist);
            Component.Params.Input[index].CollectData();
        }
Ejemplo n.º 4
0
        // The function that takes out the params from the source and target objects
        // it finds out which components are sources and targets and which node to connect them to.

        private List <IGH_Param> getParams(List <IGH_DocumentObject> g, int index, int counter, bool isInput)
        {
            List <IGH_Param> pList = new List <IGH_Param>();

            for (int i = -1; i < index; i++) /*for loop*/
            {
                foreach (IGH_DocumentObject o in g)
                {
                    if (o is IGH_Component)
                    {
                        IGH_Component p = o as IGH_Component;
                        if (isInput)
                        {
                            pList.Add(p.Params.Input[index]); /*i instead for index*/
                        }
                        else
                        if (i != index - 1)
                        {
                            pList.Add(p.Params.Output[i + 1 + counter]);
                        }
                    }
                    else
                    {
                        IGH_Param p = o as IGH_Param;
                        pList.Add(p);
                    }
                }
            }

            return(pList);
        }
Ejemplo n.º 5
0
        public static void AddOutputs(this IGH_Component gH_Component, int[] indexes, IGH_Param[] outputParams)
        {
            foreach (int index in indexes)
            {
                IGH_Param parameter = outputParams[index];

                if (gH_Component.Params.Output.Any(x => x.Name == parameter.Name))
                {
                    gH_Component.Params.UnregisterOutputParameter(gH_Component.Params.Output.First(x => x.Name == parameter.Name), true);
                }
                else
                {
                    int insertIndex = gH_Component.Params.Output.Count;
                    for (int i = 0; i < gH_Component.Params.Output.Count; i++)
                    {
                        int otherIndex = Array.FindIndex(outputParams, x => x.Name == gH_Component.Params.Output[i].Name);
                        if (otherIndex > index)
                        {
                            insertIndex = i;
                            break;
                        }
                    }

                    gH_Component.Params.RegisterOutputParam(parameter, insertIndex);
                }
                gH_Component.Params.OnParametersChanged();
            }
            gH_Component.ExpireSolution(true);
        }
 public static void ExpireOutput(this IGH_Component component, int output)
 {
     foreach (var receiver in component.Params.Output[output].Recipients)
     {
         receiver.ExpireSolution(true);
     }
 }
 public static void ExpireOutputs(this IGH_Component component, params int[] outputs)
 {
     foreach (var output in outputs)
     {
         component.ExpireOutput(output);
     }
 }
 public static void ExpireOutputs(this IGH_Component component, IEnumerable <int> outputs)
 {
     foreach (var output in outputs)
     {
         component.ExpireOutput(output);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Generates selection list for cell oritentation.
        /// </summary>
        /// <param name="index">Component input index. (first input is index 0)</param>
        /// <param name="offset">Vertical offset of the menu, to help with positioning.</param>
        public static void OrientSelect(ref IGH_Component Component, ref GH_Document GrasshopperDocument, int index, float offset)
        {
            // Instantiate  new value list
            var vallist = new Grasshopper.Kernel.Special.GH_ValueList();

            vallist.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.Cycle;
            vallist.CreateAttributes();

            // Customise value list position
            float  xCoord   = (float)Component.Attributes.Pivot.X - 200;
            float  yCoord   = (float)Component.Attributes.Pivot.Y + index * 40 - offset;
            PointF cornerPt = new PointF(xCoord, yCoord);

            vallist.Attributes.Pivot = cornerPt;

            // Populate value list with our own data
            vallist.ListItems.Clear();
            var items = new List <Grasshopper.Kernel.Special.GH_ValueListItem>();

            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Default", "0"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateZ", "1"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateY", "2"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateX", "3"));

            vallist.ListItems.AddRange(items);

            // Until now, the slider is a hypothetical object.
            // This command makes it 'real' and adds it to the canvas.
            GrasshopperDocument.AddObject(vallist, false);

            //Connect the new slider to this component
            Component.Params.Input[index].AddSource(vallist);
            Component.Params.Input[index].CollectData();
        }
        public static CanvasControlAttributes TaskCardAttributes(IGH_Component parent, TH_Task task)
        {
            var atts    = new CanvasControlAttributes(parent);
            var control = new TaskCardControl(atts, task);

            atts.Control = control;
            return(atts);
        }
Ejemplo n.º 11
0
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);
            Component = this;

            GrasshopperDocument = Instances.ActiveCanvas.Document;

            GHDEFNAME = RemoveSpecialCharacters(GrasshopperDocument.DisplayName.ToString());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 0. Setup input
            Component = this;
            GrasshopperDocument = this.OnPingDocument();
            //    Generate default input menu
            if (Component.Params.Input[0].SourceCount == 0) InputTools.GradientSelect(ref Component, ref GrasshopperDocument, 0, 11);

            // 1. Retrieve input
            int gradientType = 0;
            if (!DA.GetData(0, ref gradientType)) { return; }

            // 2. Initialize 
            string mathString = null;

            // 3. Define gradients here
            // Assume unitized domain ( 0<x<1 , 0<y<1, 0<z<1), where radius values range from minRadius (mathString=0) to maxRadius (mathString=1)
            // Based on this assumption, the actual values are scaled to the size of the bounding box of the lattice
            switch (gradientType)
            {
                case 0:     // Linear (X)
                    mathString = "Abs(x)";
                    break;
                case 1:     // Linear (Y)
                    mathString = "Abs(y)";
                    break;
                case 2:     // Linear (Z)
                    mathString = "Abs(z)";
                    break;
                case 3:     // Centered (X)
                    mathString = "Abs(2*x-1)";
                    break;
                case 4:     // Centered (Y)
                    mathString = "Abs(2*y-1)";
                    break;
                case 5:     // Centered (Z)
                    mathString = "Abs(2*z-1)";
                    break;
                case 6:     // Cylindrical (X)
                    mathString = "Sqrt(Abs(2*y-1)^2 + Abs(2*z-1)^2)/Sqrt(2)";
                    break;
                case 7:     // Cylindrical (Y)
                    mathString = "Sqrt(Abs(2*x-1)^2 + Abs(2*z-1)^2)/Sqrt(2)";
                    break;
                case 8:     // Cylindrical (Z)
                    mathString = "Sqrt(Abs(2*x-1)^2 + Abs(2*y-1)^2)/Sqrt(2)";
                    break;
                case 9:     // Spherical
                    mathString = "Sqrt(Abs(2*x-1)^2 + Abs(2*y-1)^2 + Abs(2*z-1)^2)/Sqrt(3)";
                    break;
                // If you add a new gradient, don't forget to add it in the value list (GradientSelect method)
            }

            // Output report
            DA.SetData(0, mathString);

        }
Ejemplo n.º 13
0
        public NormalAttributeWithControl(GH_Component owner, List <HuControl> ControlList) : base(owner)
        {
            this.Component     = owner;
            this.ControlList   = ControlList;
            this.ControlNumber = this.ControlList.Count;
            this.AttributeUtil = new AttributeUtil(owner);

            SetUpTimer();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Component Component           = this;
            GH_Document   GrasshopperDocument = this.OnPingDocument();

            // Create input parameters
            bool   trigger     = false;
            string sourceGroup = null;
            string targetGroup = null;
            int    sourceIndex = 0;
            int    targetIndex = 0;

            // Assign input data
            DA.GetData(0, ref sourceGroup);
            DA.GetData(1, ref targetGroup);
            DA.GetData(2, ref sourceIndex);
            DA.GetData(3, ref targetIndex);
            DA.GetData(4, ref trigger);


            // --------------------------------------------------------------------------------------------------------------------------
            if (!trigger)
            {
                return;
            }

            List <IGH_Param> targetParam = new List <IGH_Param>();
            List <IGH_Param> sourceParam = new List <IGH_Param>();

            foreach (IGH_DocumentObject docObject in GrasshopperDocument.Objects) //for every GH component in document
            {
                // if the pathname of the actual object is the same as the Pathname of the targetgroup
                // put the docObject in the group "gp" as a GH special group
                // then take out the Params of the target objects
                if (docObject.Attributes.PathName == "Group (" + targetGroup + ")")
                {
                    Grasshopper.Kernel.Special.GH_Group gp = docObject as Grasshopper.Kernel.Special.GH_Group;
                    targetParam = getParams(gp.Objects(), targetIndex, sourceIndex, true);
                }
                // the same as above but for the source objects
                else if (docObject.Attributes.PathName == "Group (" + sourceGroup + ")")
                {
                    Grasshopper.Kernel.Special.GH_Group gp = docObject as Grasshopper.Kernel.Special.GH_Group;
                    sourceParam = getParams(gp.Objects(), sourceIndex, sourceIndex, false);
                }
            }

            int nbI = targetParam.Count();
            int nbO = sourceParam.Count();
            int nb  = Math.Max(nbI, nbO);

            for (int i = 0; i < nb; i++)
            {
                targetParam[i % nbI].AddSource(sourceParam[i % nbO]);
            }
        }
Ejemplo n.º 15
0
        public static Bitmap GetObjectBitmap(IGH_DocumentObject obj, bool isInput, out IGH_Param dataParam, byte?index = null, int marginThickness = 10, int maxDistanceToWorkArea = 150)
        {
            dataParam = null;

            GH_Canvas canvas = new GH_Canvas();

            canvas.Document = new GH_Document();
            AddAObjectToCanvas(obj, new PointF(), false, canvas);
            obj.Attributes.Bounds = new System.Drawing.RectangleF(-obj.Attributes.Bounds.Width / 2, -obj.Attributes.Bounds.Height / 2,
                                                                  obj.Attributes.Bounds.Width, obj.Attributes.Bounds.Height);

            if (index.HasValue && obj is IGH_Component)
            {
                IGH_Component component  = obj as IGH_Component;
                IGH_Param     param      = null;
                RectangleF    renderRect = RectangleF.Empty;
                switch (isInput)
                {
                case true:
                    if (component.Params.Output.Count <= index.Value)
                    {
                        return(null);
                    }
                    param      = component.Params.Output[index.Value];
                    renderRect = param.Attributes.Bounds;
                    float move = obj.Attributes.Bounds.Right - renderRect.Right - 2;
                    renderRect = new RectangleF(new PointF(renderRect.X + move, renderRect.Y), renderRect.Size);
                    break;

                case false:
                    if (component.Params.Input.Count <= index.Value)
                    {
                        return(null);
                    }
                    param      = component.Params.Input[index.Value];
                    renderRect = param.Attributes.Bounds;
                    float move1 = obj.Attributes.Bounds.Left - renderRect.Left + 2;
                    renderRect = new RectangleF(new PointF(renderRect.X + move1, renderRect.Y), renderRect.Size);
                    break;
                }
                if (param != null && renderRect != RectangleF.Empty)
                {
                    dataParam = param;
                    canvas.CanvasPostPaintObjects += (cvs) =>
                    {
                        canvas.Graphics.DrawPath(new Pen(new SolidBrush(ColorExtension.OnColor), 2), TextBox.GetRoundRectangle(renderRect, 3));
                    };
                }
            }
            else if (index.HasValue && obj is IGH_Param)
            {
                dataParam = obj as IGH_Param;
            }

            return(GetObjectBitmap(obj, canvas, marginThickness, maxDistanceToWorkArea));
        }
Ejemplo n.º 16
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = OnPingDocument();

            string size       = "";
            string usage      = "";
            string energy     = "";
            string structural = "";

            bool input = false;

            if (!DA.GetData(0, ref input))
            {
                return;
            }

            if (input &&
                Params.Input[1].SourceCount == 0 &&
                Params.Input[2].SourceCount == 0 &&
                Params.Input[3].SourceCount == 0 &&
                Params.Input[4].SourceCount == 0)
            {
                CreateAccentList(SIZE_VALUES, "Building size", 1, 200, -20);
                CreateAccentList(USAGE_VALUES, "Building usage", 2, 275, -10);
                CreateAccentList(ENERGY_VALUES, "Energy preference", 3, 230, 0);
                CreateAccentList(STRUCTUAL_VALUES, "Structual material", 4, 202, 10);
                Message = "Component activated.";
            }

            if (!DA.GetData(1, ref size))
            {
                return;
            }
            if (!DA.GetData(2, ref usage))
            {
                return;
            }
            if (!DA.GetData(3, ref energy))
            {
                return;
            }
            if (!DA.GetData(4, ref structural))
            {
                return;
            }

            var outputList = new List <string>();

            outputList.Add(size);
            outputList.Add(usage);
            outputList.Add(energy);
            outputList.Add(structural);

            DA.SetDataList(0, outputList);
        }
Ejemplo n.º 17
0
 public SetComponentWindow(IGH_Component C, wObject W, string T, int R)
 {
     switch (T)
     {
     case "TextBox":
         TextBox A15 = (TextBox)C;
         A15.Elements[R] = W;
         break;
     }
 }
        public static void SwapGroups(GH_Document document, IGH_Component component, IGH_Component upgradedComponent)
        {
            var groups = document
                         .Objects
                         .OfType <GH_Group>()
                         .Where(gr => gr.ObjectIDs.Contains(component.InstanceGuid))
                         .ToList();

            groups.ForEach(g => g.AddObject(upgradedComponent.InstanceGuid));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Upgrade an existing object.
        /// </summary>
        /// <param name="target">Object to upgrade.</param>
        /// <param name="document">Document that contains the object.</param>
        /// <returns>
        /// The newly created object on success, null on failure.
        /// </returns>
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            IGH_Component component = target as IGH_Component;

            if (component == null)
            {
                return(null);
            }
            return(GH_UpgradeUtil.SwapComponents(component, this.UpgradeTo));
        }
Ejemplo n.º 20
0
            public AttribCompo(IGH_Component PythonInterfaceComponent)
                : base(PythonInterfaceComponent)
            {
                string Name = System.Environment.UserName;

                ChangedText = Resources.SavedPythonFile.Shellinit.Replace("##CreatedBy##", Name);
                ChangedText = ChangedText.Replace("##at##", at);

                thisIndex2 = Globals.index;
            }
        public StormCloudWindow(DesignToolVM designtoolvm, IGH_Component comp)
        {
            InitializeComponent();
            this.Component              = (InterOptComponent)comp;
            this.myDesignToolVM         = designtoolvm;
            this.myDesignToolVM.Pos     = new System.Windows.Media.Media3D.Point3D(0, 0, 20);
            this.myDesignToolVM.LookDir = new System.Windows.Media.Media3D.Vector3D(0, 0, -1);
            this.Pop.Minimum            = NCOL;

            this.DataContext = designtoolvm;
        }
Ejemplo n.º 22
0
        public ClusterComponentAttributes(IGH_Component component)
            : base(component)
        {
            MyComponent = (ClusterComponent)component;

            this.DesignMapSorted = new List <List <List <double> > >();
            this.ClusterAves     = new List <List <double> >();
            this.DesignMap       = new List <List <double> >();
            this.ClusterMaxs     = new List <List <double> >();
            this.ClusterMins     = new List <List <double> >();
        }
Ejemplo n.º 23
0
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            IGH_Component component = target as IGH_Component;

            if (component == null)
            {
                return(null);
            }

            IGH_Component swappedComp = GH_UpgradeUtil.SwapComponents(component, UpgradeTo);

            return(swappedComp);
        }
        public EffectsComponentAttributes(IGH_Component component)
            : base(component)
        {
            MyComponent = (EffectsComponent)component;


            this.EffectIndicesList = new List <List <int> >();
            this.DesignMapEffects  = new List <List <double> >();
            this.OverallAvg        = new List <double>();
            this.IndEffectsSum     = new List <List <List <List <double> > > >();
            this.IndEffectsAvg     = new List <List <List <double> > >();
            this.OverallEff        = new List <List <double> >();
        }
Ejemplo n.º 25
0
        public RectangleF LayoutComponentBox2(IGH_Component owner)
        {
            GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)owner;
            int val = Math.Max(gH_SwitcherComponent.StaticData.GetComponentInputSection().Count, gH_SwitcherComponent.StaticData.GetComponentOutputSection().Count) * 20;

            val = Math.Max(val, 24);
            int num = 24;

            if (!GH_Attributes <IGH_Component> .IsIconMode(owner.IconDisplayMode))
            {
                val = Math.Max(val, GH_Convert.ToSize((SizeF)GH_FontServer.MeasureString(owner.NickName, StandardFont.largeFont())).Width + 6);
            }
            return(GH_Convert.ToRectangle(new RectangleF(owner.Attributes.Pivot.X - 0.5f * (float)num, owner.Attributes.Pivot.Y - 0.5f * (float)val, num, val)));
        }
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            IGH_Component component = target as IGH_Component;

            if (component == null)
            {
                return(null);
            }
            GH_Component swappedComp = GH_UpgradeUtil.SwapComponents(component, this.UpgradeTo) as GH_Component;

            swappedComp.Params.Output[0].DataMapping = GH_DataMapping.Flatten;

            return(swappedComp);
        }
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            IGH_Component component = target as IGH_Component;

            if (component == null)
            {
                return(null);
            }

            IGH_Component upgradedComponent = GH_UpgradeUtil.SwapComponents(component, UpgradeTo);

            UpgradeUtils.SwapGroups(document, component, upgradedComponent);

            return(upgradedComponent);
        }
Ejemplo n.º 28
0
        public RectangleF LayoutBounds2(IGH_Component owner, RectangleF bounds)
        {
            GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)owner;

            foreach (IGH_Param item in gH_SwitcherComponent.StaticData.GetComponentInputSection())
            {
                bounds = RectangleF.Union(bounds, item.Attributes.Bounds);
            }
            foreach (IGH_Param item2 in gH_SwitcherComponent.StaticData.GetComponentOutputSection())
            {
                bounds = RectangleF.Union(bounds, item2.Attributes.Bounds);
            }
            bounds.Inflate(2f, 2f);
            return(bounds);
        }
        public StepperComponentAttributes(IGH_Component component)
            : base(component)
        {
            MyComponent = (StepperComponent)component;

            this.Gradient                 = new List <List <double> >();
            this.DifOne                   = new List <List <double> >();
            this.DifTwo                   = new List <List <double> >();
            this.DesignMapStepperOne      = new List <List <double> >();
            this.DesignMapStepperTwo      = new List <List <double> >();
            this.DesignMapStepperCombined = new List <List <double> >();
            this.ObjValsOne               = new List <List <double> >();
            this.ObjValsTwo               = new List <List <double> >();
            this.IsoPerf                  = new List <double>();
        }
Ejemplo n.º 30
0
 public ModelBuilder()
     : base("ModelBuilder", "BN Model",
            "Description",
            "Lab Mouse", "Model")
 {
     this.model            = null;
     this.priors           = null;
     this.BinRanges        = null;
     this.PSliders         = null;
     this.POutputs         = null;
     this.targets          = null;
     this.directory        = new List <string>();
     this.datagencomponent = null;
     this.doc         = null;
     this.csvfilepath = null;
 }
Ejemplo n.º 31
0
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            ValueListener_Component_DEPRECATED component = target as ValueListener_Component_DEPRECATED;

            if (component == null)
            {
                return(null);
            }
            IGH_Component swappedComp = GH_UpgradeUtil.SwapComponents(component, this.UpgradeTo);

            ValueListener_Component swappedValListener = swappedComp as ValueListener_Component;

            swappedValListener.AddEventsEnabled = component.AddEventsEnabled;
            swappedValListener.updateMessage();

            return(swappedComp);
        }
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            IGH_Component component = target as IGH_Component;

            if (component == null)
            {
                return(null);
            }

            IGH_Component upgradedComponent = GH_UpgradeUtil.SwapComponents(component, UpgradeTo);

            upgradedComponent.Params.Input[0].Access = GH_ParamAccess.item;
            upgradedComponent.Params.Input[2].Access = GH_ParamAccess.tree;
            UpgradeUtils.SwapGroups(document, component, upgradedComponent);

            return(upgradedComponent);
        }
 // Grasshopper.Kernel.Attributes.GH_ComponentAttributes
 public void LayoutInputParamsJR(IGH_Component owner, RectangleF componentBox)
 {
     int count = owner.Params.Input.Count;
     if (count == 0)
     {
         return;
     }
     int width = 0;
     try
     {
         System.Collections.Generic.List<IGH_Param>.Enumerator enumerator = owner.Params.Input.GetEnumerator();
         while (enumerator.MoveNext())
         {
             IGH_Param param = enumerator.Current;
             width = Math.Max(width, GH_FontServer.StringWidth(param.Name, paramfont));
         }
     }
     finally
     {
     }
     width = Math.Max(width + 6, 12);
     float pixelsPerParam = componentBox.Height / count;
     int arg_82_0 = 0;
     int num = count - 1;
     for (int i = arg_82_0; i <= num; i++)
     {
         IGH_Param param2 = owner.Params.Input[i];
         if (param2.Attributes == null)
         {
             param2.Attributes = new GH_LinkedParamAttributes(param2, owner.Attributes);
         }
         float X = componentBox.X - width;
         float Y = componentBox.Y + i * pixelsPerParam;
         float W = width - 3;
         float H = pixelsPerParam;
         IGH_Attributes arg_103_0 = param2.Attributes;
         PointF pivot = new PointF(X + 0.5f * width, Y + 0.5f * pixelsPerParam);
         arg_103_0.Pivot = pivot;
         IGH_Attributes arg_12A_0 = param2.Attributes;
         RectangleF @in = new RectangleF(X, Y, W, H);
         arg_12A_0.Bounds = GH_Convert.ToRectangle(@in);
     }
 }
Ejemplo n.º 34
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 0. Generate input menu list
            Component = this;
            GrasshopperDocument = this.OnPingDocument();
            // Only generate it if the input has no source
            if (Component.Params.Input[0].SourceCount == 0)
            {
                InputTools.TopoSelect(ref Component, ref GrasshopperDocument, 0, 11);
            }

            // 1. Retrieve input
            int cellType = 0;
            if (!DA.GetData(0, ref cellType)) { return; }

            // 2. Instantiate line list
            var lines = new List<Line>();

            // 3. Set cell size
            double d = 5;

            // 4. Switch statement for the different cell types
            switch (cellType)
            {
                // "GRID"
                case 0:
                    lines = GridLines(d);
                    break;
                // "X"
                case 1:
                    lines = XLines(d);
                    break;
                // "STAR"
                case 2:
                    lines = StarLines(d);
                    break;
                // "CROSS"
                case 3:
                    lines = CrossLines(d);                        
                    break;
                // "TESSERACT"
                case 4:
                    lines = TesseractLines(d);
                    break;
                // "VINTILES"
                case 5:
                    lines = VintileLines(d);
                    break;
                // "OCTET"
                case 6:
                    lines = OctetLines(d);
                    break;
                // "DIAMOND"
                case 7:
                    lines = DiamondLines(d);
                    break;
                // "HONEYCOMB"
                case 8:
                    lines = Honeycomb(d);
                    break;
                // "AUXETIC HONEYCOMB"
                case 9:
                    lines = AuxeticHoneycomb(d);
                    break;
            }

            // 5. Instantiate UnitCell object and check validity.
            var cell = new UnitCell(lines);
            if (!cell.isValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid cell - this is embarassing.");
            }

            // 6. Construct normalized cell lines (for optional output)
            var lines2 = new List<Line>();
            foreach (IndexPair nodePair in cell.NodePairs)
            {
                lines2.Add(new Line(cell.Nodes[nodePair.I], cell.Nodes[nodePair.J]));
            }

            // 7. Set output (as LatticeCellGoo)
            DA.SetData(0, new UnitCellGoo(cell));
            DA.SetDataList(1, lines2);
        }
Ejemplo n.º 35
0
 public HSAttributes(IGH_Component nComponent)
     : base(nComponent)
 {
     m_owner = (HSComponent)nComponent; 
 }
 public CustomAttributes2(IGH_Component owner)
     : base(owner)
 {
 }
Ejemplo n.º 37
0
 public SettingsComponentAttributes(IGH_Component SettingsComponent)
     : base(SettingsComponent)
 {
 }
Ejemplo n.º 38
0
 public TortugaComponentAttributes(IGH_Component MaterialEditor)
     : base(MaterialEditor)
 {
 }
Ejemplo n.º 39
0
    private List<string> __out = new List<string>(); //Do not modify this list directly.

    #endregion Fields

    #region Methods

    public override void InvokeRunScript(IGH_Component owner, object rhinoDocument, int iteration, List<object> inputs, IGH_DataAccess DA)
    {
        //Prepare for a new run...
        //1. Reset lists
        this.__out.Clear();
        this.__err.Clear();

        this.Component = owner;
        this.Iteration = iteration;
        this.GrasshopperDocument = owner.OnPingDocument();
        this.RhinoDocument = rhinoDocument as Rhino.RhinoDoc;

        this.owner = this.Component;
        this.runCount = this.Iteration;
        this. doc = this.RhinoDocument;

        //2. Assign input parameters
        Mesh Profile = default(Mesh);
        if (inputs[0] != null)
        {
          Profile = (Mesh)(inputs[0]);
        }

        List<Mesh> x = null;
        if (inputs[1] != null)
        {
          x = GH_DirtyCaster.CastToList<Mesh>(inputs[1]);
        }
        bool y = default(bool);
        if (inputs[2] != null)
        {
          y = (bool)(inputs[2]);
        }

        //3. Declare output parameters
          object A = null;

        //4. Invoke RunScript
        RunScript(Profile, x, y, ref A);

        try
        {
          //5. Assign output parameters to component...
            if (A != null)
          {
        if (GH_Format.TreatAsCollection(A))
        {
          IEnumerable __enum_A = (IEnumerable)(A);
          DA.SetDataList(1, __enum_A);
        }
        else
        {
          if (A is Grasshopper.Kernel.Data.IGH_DataTree)
          {
            //merge tree
            DA.SetDataTree(1, (Grasshopper.Kernel.Data.IGH_DataTree)(A));
          }
          else
          {
            //assign direct
            DA.SetData(1, A);
          }
        }
          }
          else
          {
        DA.SetData(1, null);
          }

        }
        catch (Exception ex)
        {
          this.__err.Add(string.Format("Script exception: {0}", ex.Message));
        }
        finally
        {
          //Add errors and messages...
          if (owner.Params.Output.Count > 0)
          {
        if (owner.Params.Output[0] is Grasshopper.Kernel.Parameters.Param_String)
        {
          List<string> __errors_plus_messages = new List<string>();
          if (this.__err != null) { __errors_plus_messages.AddRange(this.__err); }
          if (this.__out != null) { __errors_plus_messages.AddRange(this.__out); }
          if (__errors_plus_messages.Count > 0)
            DA.SetDataList(0, __errors_plus_messages);
        }
          }
        }
    }
 public BimVisualizerAttributes(IGH_Component component)
     : base(component)
 {
     _component = (BimVisualiser) component;
     _boundingBoxes = new List<RectangleF>();
 }