Пример #1
0
 public ObjectProxy(IGH_ObjectProxy proxy)
 {
     this.FullName    = proxy.Desc.Name;
     this.Category    = string.IsNullOrEmpty(proxy.Desc.Category) ? "No Category" : proxy.Desc.Category;
     this.Subcategory = string.IsNullOrEmpty(proxy.Desc.SubCategory) ? "No SubCategory" : proxy.Desc.SubCategory;
     this.Description = proxy.Desc.Description;
     this.Icon        = CanvasRenderEngine.BitmapToBitmapImage(proxy.Icon);
     this.Guid        = proxy.Guid;
     this.Exposure    = proxy.Exposure;
     this.Location    = proxy.Location;
     foreach (var item in Grasshopper.Instances.ComponentServer.Libraries)
     {
         if (item.Id == proxy.LibraryGuid)
         {
             this.IsPlugin = !item.IsCoreLibrary;
             break;
         }
     }
 }
Пример #2
0
        public ComTypeInfo(IGH_ObjectProxy proxy)
        {
            this.Category    = proxy.Desc.HasCategory ? proxy.Desc.Category : LanguagableComponent.GetTransLation(new string[] { "<Unnamed Category>", "<未命名类别>" });
            this.Subcategory = proxy.Desc.HasSubCategory ? proxy.Desc.SubCategory : LanguagableComponent.GetTransLation(new string[] { "<Unnamed Subcategory>", "<未命名子类>" });
            this.Name        = proxy.Desc.Name;
            this.Description = proxy.Desc.Description;
            #region
            Bitmap bitmap = new Bitmap(proxy.Icon, 20, 20);
            this.Icon = CanvasRenderEngine.BitmapToBitmapImage(bitmap);
            #endregion

            this.Exposure = proxy.Exposure;
            this.Guid     = proxy.Guid;

            Isvalid = true;

            Type            type = proxy.Type;
            GH_AssemblyInfo lib  = null;

            if (type == null)
            {
                this.FullName = "";
            }
            else
            {
                this.FullName = type.FullName;
                lib           = GetGHLibrary(type);
            }

            this.IsPlugin = checkisPlugin(proxy, lib);

            if (lib != null)
            {
                this.AssemblyName   = lib.Name;
                this.AssemblyAuthor = lib.AuthorName;
            }

            this.Tip = CreateTip();
        }
Пример #3
0
        private bool checkisPlugin(IGH_ObjectProxy proxy, GH_AssemblyInfo lib)
        {
            PluginLocation = proxy.Location;
            if (lib == null)
            {
                ShowLocation = PluginLocation;
                return(true);
            }

            string loc2 = lib.Location;


            if (PluginLocation != loc2)
            {
                ShowLocation = loc2 + "\n \n" + PluginLocation;
                return(true);
            }
            else
            {
                ShowLocation = PluginLocation;
                return(!lib.IsCoreLibrary);
            }
        }
Пример #4
0
 public ParamGlassesProxy(IGH_ObjectProxy proxy)
     : base(proxy)
 {
     this.CreateObejct = proxy.CreateInstance;
 }
 public ExceptionProxy(IGH_ObjectProxy proxy, InfoGlassesComponent owner)
     : base(proxy)
 {
     this.AddOwner(owner);
 }
Пример #6
0
        private bool ObjectFilter(IGH_DocumentObject obj)
        {
            if (Settings.DisplayNicknames || Settings.DisplayCustomNicknames)
            {
                if (obj is GH_Panel || obj is GH_Group || obj is GH_NumberSlider)
                {
                    return(false);
                }
            }

            if (Settings.IsFilterCustomEnabled &&
                Settings.ShouldExcludeObject(obj))
            {
                return(false);
            }

            if (!Settings.FilterComponents &&
                (obj is GH_Cluster || obj is IGH_Component || obj.ComponentGuid == galapagosID))
            {
                return(false);
            }

            if (!Settings.FilterSpecial &&
                IsSpecialObject(obj))
            {
                return(false);
            }

            if (!Settings.FilterParameters &&
                obj is IGH_Param)
            {
                return(false);
            }

            if (!Settings.FilterGraphic &&
                !(obj is IGH_ActiveObject))
            {
                return(false);
            }

            if (Settings.DisplayCustomNicknames)
            {
                if (obj is IGH_Param param && param.Kind == GH_ParamKind.floating &&
                    (param.IconDisplayMode == GH_IconDisplayMode.name ||
                     param.IconDisplayMode == GH_IconDisplayMode.application && !Grasshopper.CentralSettings.CanvasObjectIcons))
                {
                    return(false);
                }
                var code = string.Join(".", obj.Category, obj.SubCategory, obj.Name);

                var id = obj.ComponentGuid;

                if (!_nicknamesCache.TryGetValue(code, out var defNick))
                {
                    IGH_ObjectProxy proxy = null;
                    if (id == clusterID || id == vbID || id == csID || id == pyID || id == Guid.Empty)
                    {
                        proxy = Grasshopper.Instances.ComponentServer.FindObjectByName(obj.Name, true, true);
                    }
                    else
                    {
                        proxy = Grasshopper.Instances.ComponentServer.EmitObjectProxy(id);
                    }

                    if (proxy != null)
                    {
                        defNick = proxy.Desc.NickName;
                        _nicknamesCache.Add(code, defNick);
                    }
                    else
                    {
                        if (obj is GH_Cluster)
                        {
                            return(obj.NickName != NameOfClusterComponent);
                        }

                        return(true);
                    }
                }

                return(!defNick.Equals(obj.NickName, StringComparison.OrdinalIgnoreCase));
            }

            return(true);
        }
Пример #7
0
        /*******************************************/

        private static void GlobalSearch_ItemSelected(object sender, oM.UI.ComponentRequest request)
        {
            try
            {
                GH_Canvas canvas = GH.Instances.ActiveCanvas;

                System.Drawing.PointF location = canvas.CursorCanvasPosition;
                if (request != null && request.Location != null)
                {
                    location = new System.Drawing.Point((int)request.Location.X, (int)request.Location.Y);
                }

                Caller node = null;
                if (request != null && request.CallerType != null)
                {
                    node = Activator.CreateInstance(request.CallerType) as Caller;
                }

                bool componentCreated = false;

                if (node != null)
                {
                    string initCode = "";
                    if (request.SelectedItem != null)
                    {
                        initCode = request.SelectedItem.ToJson();
                    }

                    componentCreated = canvas.InstantiateNewObject(node.Id, initCode, canvas.CursorCanvasPosition, true);
                }
                else if (request.SelectedItem is CustomItem)
                {
                    CustomItem item = request.SelectedItem as CustomItem;
                    if (item != null && item.Content is IGH_ObjectProxy)
                    {
                        IGH_ObjectProxy proxy = item.Content as IGH_ObjectProxy;
                        componentCreated = canvas.InstantiateNewObject(proxy.Guid, canvas.CursorCanvasPosition, true);
                    }
                }

                if (componentCreated && m_LastWire != null && m_LastWire.Source != null)
                {
                    GH_Component component = canvas.Document.Objects.Last() as GH_Component;
                    if (component != null)
                    {
                        Connect(component, m_LastWire);
                    }
                    else
                    {
                        IGH_Param param = canvas.Document.Objects.Last() as IGH_Param;
                        Connect(param, m_LastWire);
                    }

                    canvas.Invalidate();
                    if (component != null)
                    {
                        component.ExpireSolution(true);
                    }
                }

                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "- Item Selected : " + ((request != null && request.CallerType != null) ? request.CallerType.Name : "null") + ((m_LastWire != null) ? ". Used wire." : ""));
            }
            catch (Exception e)
            {
                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "- Error with item selection : " + e.Message);
            }

            m_LastWire = null;
        }