/// <summary>
        /// Add selected sliders
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddSelectedSliders(Object sender, EventArgs e)
        {
            try
            {
                IEnumerator <IGH_DocumentObject> enumerator = canvas.Document.Objects.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    IGH_DocumentObject current = enumerator.Current;
                    if (current != null)
                    {
                        if (current.Attributes.Selected)
                        {
                            if (current is GH_NumberSlider)
                            {
                                this.Params.Input[0].AddSource((IGH_Param)current, 0);
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            ExpireSolution(true);
        }
 /// <summary>
 ///  Height light a GH_DocumentObject.
 /// </summary>
 /// <param name="target">the GH_DocumentObject that needs to high light. </param>
 /// <param name="color">HighLight color.</param>
 /// <param name="radius"> cornerRadius. </param>
 /// <param name="showFunc"> whether to show. </param>
 /// <param name="renderLittleZoom">  whether render when zoom is less than 0.5. </param>
 public HighLightRect(IGH_DocumentObject target, Color color, int radius, Func <bool> showFunc = null,
                      bool renderLittleZoom = false)
     : base(target, showFunc, renderLittleZoom)
 {
     this.Color  = color;
     this.Radius = radius;
 }
        void DrawData(Grasshopper.Kernel.Data.IGH_Structure volatileData, IGH_DocumentObject docObject)
        {
            if (docObject is IGH_PreviewObject preview)
            {
                if (preview.Hidden)
                {
                    return;
                }
            }

            if (!volatileData.IsEmpty)
            {
                foreach (var value in volatileData.AllData(true))
                {
                    if (value is IGH_PreviewData)
                    {
                        bool isSelected = docObject.Attributes.Selected;
                        if (ActiveDefinition.PreviewFilter == GH_PreviewFilter.Selected && !isSelected)
                        {
                            continue;
                        }
                        var geometries = new List <Rhino.Geometry.GeometryBase>();
                        ExtractGeometry(value, ref geometries);
                        if (geometries.Count != 0)
                        {
                            geometries.ForEach(geometryBase => AddDrawable(geometryBase, isSelected));
                            docObject.ObjectChanged += ObjectChanged;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private bool ObjectFilter(IGH_DocumentObject obj)
        {
            var custom = Settings.FilterCustom;

            if (!string.IsNullOrEmpty(custom))
            {
                var split = custom.Split(',').Select(t => t.TrimStart().TrimEnd());
                if (split.Contains(obj.Name))
                {
                    return(false);
                }
            }
            if (obj is Grasshopper.Kernel.Special.GH_Cluster)
            {
                return(Settings.FilterComponents);
            }
            if (obj.GetType().Namespace == "Grasshopper.Kernel.Special")
            {
                return(Settings.FilterSpecial);
            }
            if (obj is IGH_Component || obj.ComponentGuid == galapagosID)
            {
                return(Settings.FilterComponents);
            }
            if (obj is IGH_Param)
            {
                return(Settings.FilterParameters);
            }
            if (!(obj is IGH_ActiveObject))
            {
                return(Settings.FilterGraphic);
            }
            return(false);
        }
        public IEnumerable <IModifiable> TargetObjects()
        {
            if (_targetIds.Count != _targetObjs.Count)
            {
                GH_Document doc = OnPingDocument();
                if (doc == null)
                {
                    return new IModifiable[] { }
                }
                ;

                _targetObjs.Clear();
                foreach (Guid id in _targetIds)
                {
                    IGH_DocumentObject obj = doc.FindObject(id, true);

                    if (obj == null)
                    {
                        _targetObjs.Add(null);
                        continue;
                    }
                    _targetObjs.Add(obj as IModifiable);
                }
            }

            return(_targetObjs);
        }
Beispiel #6
0
 private void OnObjectChanged(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
 {
     if (e.Type == GH_ObjectEventType.NickName)
     {
         ExpireSolution(true);
     }
 }
        internal PythonInstantiatorProxy(IGH_DocumentObject obj, object pythonType, dynamic operations, string location)
        {
            _operations = operations;
              _pythonType = pythonType;

            _location = string.Empty;
            _description = new GH_InstanceDescription(obj);
            Guid = obj.ComponentGuid;
            _icon = obj.Icon_24x24;
            _exposure = obj.Exposure;
            _obsolete = obj.Obsolete;
            _compliant = true;
            if (obj is IGH_ActiveObject)
            {
                IGH_ActiveObject actobj = (IGH_ActiveObject)obj;
                if (!actobj.SDKCompliancy(RhinoApp.ExeVersion, RhinoApp.ExeServiceRelease))
                {
                    this._compliant = false;
                }
            }
            Type = obj.GetType();
              this.LibraryGuid = GH_Convert.StringToGuid(location);
              this._location = location;
            if (this._location.Length > 0)
            {
                this._location = this._location.Replace("file:///", string.Empty);
                this._location = this._location.Replace("/", Convert.ToString(Path.DirectorySeparatorChar));
            }
        }
Beispiel #8
0
 void onObjectChanged(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
 {
     if (this.Locked)
     {
         this.disconnect();
     }
 }
Beispiel #9
0
        private static Bitmap GetObjectBitmap(IGH_DocumentObject obj, GH_Canvas canvas, int marginThickness = 10, int maxDistanceToWorkArea = 150)
        {
            #region Capture
            int width  = (int)(obj.Attributes.Bounds.Width + marginThickness);
            int height = (int)(obj.Attributes.Bounds.Height + marginThickness);

            GH_Viewport vp = new GH_Viewport(new System.Drawing.Point(width / 2, height / 2))
            {
                Width  = width,
                Height = height
            };
            vp.ComputeProjection();
            System.Drawing.Bitmap bitmap = canvas.GenerateHiResImageTile(vp, System.Drawing.Color.Transparent);
            canvas.Document.Dispose();
            canvas.Dispose();

            System.Drawing.Rectangle rect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            if (bitmap.Width > rect.Width - maxDistanceToWorkArea || bitmap.Height > rect.Height - maxDistanceToWorkArea)
            {
                float mul = Math.Min((rect.Width - maxDistanceToWorkArea) / (float)bitmap.Width, (rect.Height - maxDistanceToWorkArea) / (float)bitmap.Height);
                bitmap = new System.Drawing.Bitmap(bitmap, (int)(bitmap.Width * mul), (int)(bitmap.Height * mul));
            }
            #endregion

            return(bitmap);
        }
Beispiel #10
0
            public override GH_ObjectResponse RespondToMouseUp(GH_Canvas ghCanvas, GH_CanvasMouseEvent e)
            {
                mousePosition = e.CanvasLocation;
                IGH_DocumentObject targetDocumentObject = ghcDefaultPanel.OnPingDocument().FindObject(mousePosition, 1f);



                if (targetDocumentObject == null || targetDocumentObject == ghcDefaultPanel)
                {
                    return(GH_ObjectResponse.Release);
                }

                if (targetDocumentObject.ComponentGuid.ToString() == "59e0b89a-e487-49f8-bab8-b5bab16be14c") //panel
                {
                    ghcDefaultPanel.targetPanelComponentGuid = targetDocumentObject.InstanceGuid;
                    //MessageBox.Show("set target panel ok");

                    //else
                    //{
                    //ghcDefaultPanel.sourcePanelComponentGuid = targetDocumentObject.InstanceGuid;
                    //MessageBox.Show("set source panel ok");
                    //MessageBox.Show(string.Format("{0}", ghcDefaultPanel.sourcePanelComponentGuid));
                    //}

                    ghcDefaultPanel.ExpireSolution(true);
                    ghcDefaultPanel.AddWire();
                    return(GH_ObjectResponse.Release);
                }


                //ghcDefaultPanel.ExpireSolution(true);
                MessageBox.Show("Please select a panel");
                return(GH_ObjectResponse.Release);
            }
Beispiel #11
0
 void ObjectChanged(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
 {
     if (e.Type == GH_ObjectEventType.Preview)
     {
         Revit.RefreshActiveView();
     }
 }
        ////happens befor solution
        //private void OnScaleParam_ObjectChanged(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
        //{
        //    this.TempExtrCoordinates = new List<Drawing.Point>(this.ExtrCoordinates);
        //}

        //happens after solution
        private void OnScale_SolutionExpired(IGH_DocumentObject sender, GH_SolutionExpiredEventArgs e)
        {
            //((GH_Slider)sender).ValueChanged
            if (this.Params.Input[2].SourceCount > 0)
            {
                this.ExtractedCoordinates = this.TempExtrCoordinates2;
                this.TempExtrCoordinates2 = new List <Drawing.Point>();

                if (this.ifSaveAll)
                {
                    this.ExtractedColors = GetColors(this.ExtractedCoordinates, this.Bitmaps);
                }
                else
                {
                    this.ExtractedColors[0] = GetColors(this.ExtractedCoordinates, this.Bitmap);
                }

                this.UpdateValueOutputData();
                GH.Instances.ActiveCanvas.Document.NewSolution(false);
            }
            else
            {
                sender.SolutionExpired -= this.OnScale_SolutionExpired;
            }
        }
Beispiel #13
0
 private void ObjectChanged(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
 {
     if (e.Type == GH_ObjectEventType.Preview)
     {
         GhDrawingContext.NeedRedraw = true;
     }
 }
        internal PythonInstantiatorProxy(IGH_DocumentObject obj, object pythonType, dynamic operations, string location)
        {
            _operations = operations;
            _pythonType = pythonType;

            _location    = string.Empty;
            _description = new GH_InstanceDescription(obj);
            Guid         = obj.ComponentGuid;
            _icon        = obj.Icon_24x24;
            _exposure    = obj.Exposure;
            _obsolete    = obj.Obsolete;
            _compliant   = true;
            if (obj is IGH_ActiveObject)
            {
                IGH_ActiveObject actobj = (IGH_ActiveObject)obj;
                if (!actobj.SDKCompliancy(RhinoApp.ExeVersion, RhinoApp.ExeServiceRelease))
                {
                    this._compliant = false;
                }
            }
            Type             = obj.GetType();
            this.LibraryGuid = GH_Convert.StringToGuid(location);
            this._location   = location;
            if (this._location.Length > 0)
            {
                this._location = this._location.Replace("file:///", string.Empty);
                this._location = this._location.Replace("/", Convert.ToString(Path.DirectorySeparatorChar));
            }
        }
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            switch (channel)
            {
            case GH_CanvasChannel.Wires:
                graphics.FillEllipse(Brushes.HotPink, Bounds);
                foreach (IModifiable mod in Owner.TargetObjects())
                {
                    if (mod == null)
                    {
                        continue;
                    }

                    IGH_DocumentObject obj = mod as IGH_DocumentObject;
                    if (obj == null)
                    {
                        continue;
                    }

                    DrawTargetArrow(graphics, obj.Attributes.Bounds);
                }
                break;

            case GH_CanvasChannel.Objects:
                GH_Capsule capsule = GH_Capsule.CreateCapsule(InnerBounds, GH_Palette.Normal, InnerRadius, 0);
                capsule.Render(graphics, Selected, Owner.Locked, true);
                capsule.Dispose();

                string text = string.Format("{0:0.00}", Owner.Factor);
                Grasshopper.GUI.GH_GraphicsUtil.RenderCenteredText(graphics, text, GH_FontServer.Large, Color.Black, Pivot);
                break;
            }
        }
 void ObjectChanged(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
 {
     if (e.Type == GH_ObjectEventType.Preview)
     {
         PlugIn.SetNeetRedraw();
     }
 }
 private void ObjectWireChangedHandler(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
 {
     if (e.Type == GH_ObjectEventType.Sources)
     {
         this.UpdatePropertyNames();
     }
     ;
 }
Beispiel #18
0
        public static void AddAObjectToCanvas(IGH_DocumentObject obj, PointF pivot, bool update, GH_Canvas canvas, string init = null)
        {
            var functions = typeof(GH_Canvas).GetRuntimeMethods().Where(m => m.Name.Contains("InstantiateNewObject") && !m.IsPublic).ToArray();

            if (functions.Length > 0)
            {
                functions[0].Invoke(canvas, new object[] { obj, init, pivot, update });
            }
        }
Beispiel #19
0
        public static bool ShouldExcludeObject(IGH_DocumentObject obj)
        {
            if (_customFilters == null)
            {
                UpdateFilterHashset();
            }

            return(_customFilters.Contains(obj.Name) || _customFilters.Contains(obj.NickName));
        }
        private List <GH_NumberSlider> getConnectedSliders()
        {
            // Find the Guid for connected slides
            List <System.Guid> guids = new List <System.Guid>();                   //empty list for guids

            GH.Kernel.IGH_Param         selSlidersInput = this.Params.Input[0];    //ref for input where sliders are connected to this component
            IList <GH.Kernel.IGH_Param> sources         = selSlidersInput.Sources; //list of things connected on this input
            bool isAnythingConnected = sources.Any();                              //is there actually anything connected?

            // Find connected
            if (isAnythingConnected)
            {                                                                                                    //if something's connected,
                foreach (var source in sources)                                                                  //for each of these connected things:
                {
                    IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject;                      //for this connected thing, bring it into the code in a way where we can access its properties
                    GH.Kernel.Special.GH_NumberSlider mySlider = component as GH.Kernel.Special.GH_NumberSlider; //...then cast (?) it as a slider
                    if (mySlider == null)                                                                        //of course, if the thing isn't a slider, the cast doesn't work, so we get null. let's filter out the nulls
                    {
                        continue;
                    }
                    guids.Add(mySlider.InstanceGuid); //things left over are sliders and are connected to our input. save this guid.
                                                      //we now have a list of guids of sliders connected to our input, saved in list var 'mySlider'
                }
            }

            // Find all sliders.
            List <GH.Kernel.Special.GH_NumberSlider> sliders = new List <GH.Kernel.Special.GH_NumberSlider>();

            foreach (IGH_DocumentObject docObject in doc.Objects)
            {
                GH.Kernel.Special.GH_NumberSlider slider = docObject as GH.Kernel.Special.GH_NumberSlider;
                if (slider != null)
                {
                    // check if the slider is in the selected list
                    if (isAnythingConnected)
                    {
                        if (guids.Contains(slider.InstanceGuid))
                        {
                            sliders.Add(slider);
                        }
                    }
                    else
                    {
                        sliders.Add(slider);
                    }
                }
            }


            /*foreach (GH.Kernel.Special.GH_NumberSlider slider in sliders)
             * {
             *  names.Add(slider.NickName);
             * }*/

            return(sliders);
        }
Beispiel #21
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));
        }
Beispiel #22
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));
        }
Beispiel #23
0
        public static string GetNamedLocationWithObject(IGH_DocumentObject obj, string name, string suffix = ".txt", bool create = false)
        {
            string loc = GetGHObjectLocation(obj, create);

            if (loc == null)
            {
                return(null);
            }
            return(Path.GetDirectoryName(loc) + "\\" + name + suffix);
        }
        /// <summary>
        /// Set the text box like balloon.
        /// </summary>
        /// <param name="name"> the string that should be shown. </param>
        /// <param name="target"> the GH_DocumentObject that relay on.  </param>
        /// <param name="layout"> How to define the bounds. size for this label's size, rectangle for target's bounds. </param>
        /// <param name="renderSet"> render settings. </param>
        /// <param name="meansureString"> get the string's bounds. </param>
        /// <param name="showFunc"> whether to show. </param>
        /// <param name="renderLittleZoom"> whether render when zoom is less than 0.5. </param>
        public TextBox(string name, IGH_DocumentObject target, Func <SizeF, RectangleF, RectangleF> layout,
                       TextBoxRenderSet renderSet, Func <Graphics, string, Font, SizeF> meansureString = null, Func <bool> showFunc = null, bool renderLittleZoom = false)
            : base(target, showFunc, renderLittleZoom)
        {
            this.ShowName  = name;
            this.RenderSet = renderSet;
            this.Func      = layout;

            this.MeansureString = meansureString ?? ((x, y, z) => { return(x.MeasureString(y, z)); });
        }
        /*******************************************/

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            BH.Engine.Base.Compute.ClearCurrentEvents();

            try
            {
                // Get the input component
                IGH_Param source = Params.Input[0].Sources.FirstOrDefault();
                if (source == null)
                {
                    return;
                }
                IGH_DocumentObject        component = source.Attributes.GetTopLevel.DocObject;
                GH_Cluster                cluster   = source.Attributes.GetTopLevel.DocObject as GH_Cluster;
                List <IGH_DocumentObject> content   = cluster.Document("").Objects.ToList();

                List <GH_ClusterInputHook>  inputs     = content.OfType <GH_ClusterInputHook>().ToList();
                List <GH_ClusterOutputHook> outputs    = content.OfType <GH_ClusterOutputHook>().ToList();
                List <GH_Component>         components = content.OfType <GH_Component>().ToList();
                List <GH_Group>             groups     = content.OfType <GH_Group>().ToList();
                List <IGH_Param>            parameters = content.OfType <IGH_Param>().ToList();

                groups = groups.Except(groups.SelectMany(x => x.Objects().OfType <GH_Group>())).ToList();

                ClusterContent nodeContent = new ClusterContent
                {
                    Name   = cluster.NickName,
                    Inputs = inputs.Select(x => new DataParam {
                        Name        = x.NickName,
                        Description = x.Description,
                        TargetIds   = x.Recipients.Select(r => r.InstanceGuid).ToList(),
                        BHoM_Guid   = x.InstanceGuid
                    }).ToList(),
                    Outputs = outputs.Select(x => new ReceiverParam {
                        Name        = x.NickName,
                        Description = x.Description,
                        SourceId    = x.Sources.First().InstanceGuid,
                        BHoM_Guid   = x.InstanceGuid
                    }).ToList(),
                    InternalNodes = components.Select(x => ToNode(x)).Concat(parameters.Select(x => ToNode(x))).Where(x => x != null).ToList(),
                    NodeGroups    = ClearUnsafeGroups(groups.Select(x => x.ToNodeGroup()).ToList()),
                    BHoM_Guid     = cluster.InstanceGuid
                };

                nodeContent = nodeContent.PopulateTypes();

                DA.SetData(0, nodeContent);

                Helpers.ShowEvents(this, BH.Engine.Base.Query.CurrentEvents());
            }
            catch (Exception e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
            }
        }
Beispiel #26
0
        void DrawData(Grasshopper.Kernel.Data.IGH_Structure volatileData, IGH_DocumentObject docObject)
        {
            if (!volatileData.IsEmpty)
            {
                foreach (var value in volatileData.AllData(true))
                {
                    // First check for IGH_PreviewData to discard no graphic elements like strings, doubles, vectors...
                    if (value is IGH_PreviewData)
                    {
                        switch (value.ScriptVariable())
                        {
                        case Rhino.Geometry.Point3d point:    primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.Point(point))); break;

                        case Rhino.Geometry.Line line:        primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.LineCurve(line))); break;

                        case Rhino.Geometry.Rectangle3d rect: primitives.Add(new ParamPrimitive(docObject, rect.ToNurbsCurve())); break;

                        case Rhino.Geometry.Arc arc:          primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.ArcCurve(arc))); break;

                        case Rhino.Geometry.Circle circle:    primitives.Add(new ParamPrimitive(docObject, new Rhino.Geometry.ArcCurve(circle))); break;

                        case Rhino.Geometry.Ellipse ellipse:  primitives.Add(new ParamPrimitive(docObject, ellipse.ToNurbsCurve())); break;

                        case Rhino.Geometry.Curve curve:      primitives.Add(new ParamPrimitive(docObject, curve)); break;

                        case Rhino.Geometry.Mesh mesh:        primitives.Add(new ParamPrimitive(docObject, mesh)); break;

                        case Rhino.Geometry.Box box:
                        {
                            var boxMeshes = Rhino.Geometry.Mesh.CreateFromBox(box, 1, 1, 1);
                            if (boxMeshes != null)
                            {
                                primitives.Add(new ParamPrimitive(docObject, boxMeshes));
                            }
                        }
                        break;

                        case Rhino.Geometry.Brep brep:
                        {
                            var brepMeshes = Rhino.Geometry.Mesh.CreateFromBrep(brep, activeDefinition.PreviewCurrentMeshParameters());
                            if (brepMeshes != null)
                            {
                                var previewMesh = new Rhino.Geometry.Mesh();
                                previewMesh.Append(brepMeshes);

                                primitives.Add(new ParamPrimitive(docObject, previewMesh));
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
Beispiel #27
0
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            PythonComponent_OBSOLETE component_OBSOLETE = target as PythonComponent_OBSOLETE;
              if (component_OBSOLETE == null)
            return null;

              ZuiPythonComponent component_new = new ZuiPythonComponent();

              bool show_code_input = false;
              if (component_OBSOLETE.CodeInputVisible)
              {
            // see if the "code" input on the old component really has anything
            // hooked up to it.  If not, don't show the input
            show_code_input = component_OBSOLETE.Params.Input[0].SourceCount > 0;
              }
              component_new.CodeInputVisible = show_code_input;

              component_new.HideCodeOutput = component_OBSOLETE.HideCodeOutput;

              if (component_new.HideCodeOutput)
            component_new.Params.Output.RemoveAt(0);

              if (!component_new.CodeInputVisible)
            component_new.CodeInput = component_OBSOLETE.CodeInput;

              component_OBSOLETE.Dispose();

              if (GH_UpgradeUtil.SwapComponents(component_OBSOLETE, component_new))
              {
            bool toRhinoScript = (component_OBSOLETE.DocStorageMode == DocReplacement.DocStorage.AutomaticMarshal);
            {
              foreach (var c in component_new.Params.Input)
              {
            var sc = c as Param_ScriptVariable;
            if (sc == null) continue;

            if (toRhinoScript)
            {
              IGH_TypeHint newHint;
              if (PythonHints.ToNewRhinoscriptHint(sc.TypeHint, out newHint))
                sc.TypeHint = newHint;
            }
            else
            {
              PythonHints.ToNewRhinoCommonHint(sc);
            }
              }
            }

            component_new.CodeInputVisible = show_code_input;
            return component_new;
              }
              return null;
        }
        private void RawParam_ObjectChanged(IGH_DocumentObject sender, GH_ObjectChangedEventArgs e)
        {
            if (e.Type == GH_ObjectEventType.NickName)
            {
                _nickName = checkNickname(this.RawParam);

                if (this.ObjectNicknameChanged != null)
                {
                    this.ObjectNicknameChanged(this);
                }
            }
        }
Beispiel #29
0
        /*******************************************/

        private static void Canvas_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            GH_Canvas canvas = sender as GH_Canvas;

            if (canvas == null || !m_UseWireMenu)
            {
                return;
            }

            GH_WireInteraction wire = canvas.ActiveInteraction as GH_WireInteraction;

            if (wire != null)
            {
                // Get source
                FieldInfo sourceField = typeof(GH_WireInteraction).GetField("m_source", BindingFlags.NonPublic | BindingFlags.Instance);
                if (sourceField == null)
                {
                    return;
                }
                IGH_Param sourceParam = sourceField.GetValue(wire) as IGH_Param;

                // Get the source Type
                Type sourceType = GetSourceType(sourceParam);

                // Get IsInput
                FieldInfo inputField = typeof(GH_WireInteraction).GetField("m_dragfrominput", BindingFlags.NonPublic | BindingFlags.Instance);
                if (inputField == null)
                {
                    return;
                }
                bool isInput = (bool)inputField.GetValue(wire);

                // Save wire info
                m_LastWire = new WireInfo
                {
                    Wire       = wire,
                    Source     = sourceParam,
                    SourceType = sourceType,
                    IsInput    = isInput
                };

                try
                {
                    IGH_DocumentObject docObject = sourceParam.Attributes.GetTopLevel.DocObject;
                    m_LastWire.Tags = new HashSet <string> {
                        docObject.Category, docObject.SubCategory
                    };
                }
                catch { }

                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "- Created wire info.");
            }
        }
Beispiel #30
0
        public static void CreateNewObject(IGH_DocumentObject obj, IGH_Param target, bool isInputSide, int index = 0, float leftMove = 100, string init = null)
        {
            if (obj == null)
            {
                return;
            }

            PointF comRightCenter = new PointF(target.Attributes.Bounds.Left + (isInputSide ? -leftMove:(leftMove + target.Attributes.Bounds.Width)),
                                               target.Attributes.Bounds.Top + target.Attributes.Bounds.Height / 2);

            if (obj is GH_Component)
            {
                GH_Component com = obj as GH_Component;

                CanvasRenderEngine.AddAObjectToCanvas(com, comRightCenter, false, init);

                if (isInputSide)
                {
                    target.AddSource(com.Params.Output[index]);
                }
                else
                {
                    com.Params.Input[index].AddSource(target);
                }
                //com.Params.Output[outIndex].Recipients.Add(target);

                target.OnPingDocument().NewSolution(false);
            }
            else if (obj is IGH_Param)
            {
                IGH_Param param = obj as IGH_Param;

                CanvasRenderEngine.AddAObjectToCanvas(param, comRightCenter, false, init);

                if (isInputSide)
                {
                    target.AddSource(param);
                }
                else
                {
                    param.AddSource(target);
                }

                target.OnPingDocument().NewSolution(false);
            }
            else
            {
                target.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, LanguagableComponent.GetTransLation(new string[]
                {
                    "The added object is not a Component or Parameters!", "添加的对象不是一个运算器或参数!",
                }));
            }
        }
Beispiel #31
0
        protected override void Internal_Undo(GH_Document doc)
        {
            IGH_DocumentObject val = doc.FindObject(oldState.ComponentId, true);

            if (val == null || !(val is GH_SwitcherComponent))
            {
                throw new GH_UndoException("Switcher component with id[" + oldState.ComponentId + "] not found");
            }
            GH_SwitcherComponent component = (GH_SwitcherComponent)val;

            oldState.Apply(component, doc);
        }
Beispiel #32
0
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            PythonComponent_OBSOLETE component_OBSOLETE = target as PythonComponent_OBSOLETE;

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

            ZuiPythonComponent component_new = new ZuiPythonComponent();

            component_new.HiddenCodeInput = component_OBSOLETE.HiddenCodeInput;
            component_new.HiddenOutOutput = component_OBSOLETE.HiddenOutOutput;

            if (component_new.HiddenCodeInput)
            {
                component_new.Code = component_OBSOLETE.Code;
            }

            if (GH_UpgradeUtil.SwapComponents(component_OBSOLETE, component_new))
            {
                bool toRhinoScript = (component_OBSOLETE.DocStorageMode == DocReplacement.DocStorage.AutomaticMarshal);
                {
                    foreach (var c in component_new.Params.Input)
                    {
                        var sc = c as Param_ScriptVariable;
                        if (sc == null)
                        {
                            continue;
                        }

                        if (toRhinoScript)
                        {
                            IGH_TypeHint newHint;
                            if (PythonHints.ToNewRhinoscriptHint(sc.TypeHint, out newHint))
                            {
                                sc.TypeHint = newHint;
                            }
                        }
                        else
                        {
                            PythonHints.ToNewRhinoCommonHint(sc);
                        }
                    }
                }

                component_OBSOLETE.Dispose();

                return(component_new);
            }
            return(null);
        }
Beispiel #33
0
        public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
        {
            PythonComponent_OBSOLETE component_OBSOLETE = target as PythonComponent_OBSOLETE;
              if (component_OBSOLETE == null)
            return null;

              ZuiPythonComponent component_new = new ZuiPythonComponent();

              component_new.HiddenCodeInput = component_OBSOLETE.HiddenCodeInput;
              component_new.HiddenOutOutput = component_OBSOLETE.HiddenOutOutput;

              if (!component_new.HiddenCodeInput)
            component_new.Code = component_OBSOLETE.Code;

              if (GH_UpgradeUtil.SwapComponents(component_OBSOLETE, component_new))
              {
            bool toRhinoScript = (component_OBSOLETE.DocStorageMode == DocReplacement.DocStorage.AutomaticMarshal);
            {
              foreach (var c in component_new.Params.Input)
              {
            var sc = c as Param_ScriptVariable;
            if (sc == null) continue;

            if (toRhinoScript)
            {
              IGH_TypeHint newHint;
              if (PythonHints.ToNewRhinoscriptHint(sc.TypeHint, out newHint))
                sc.TypeHint = newHint;
            }
            else
            {
              PythonHints.ToNewRhinoCommonHint(sc);
            }
              }
            }

            component_OBSOLETE.Dispose();

            return component_new;
              }
              return null;
        }