×

工业设计互动平台

手机短信,快捷登录

微信登录,快人一步

QQ登录

只需一步,快速开始

解释关于GH_Component, GH_Param 和 GH_Attributes

发布于 2014-11-7 0 点赞 0 评论 8035 浏览


感谢各位关注。新加入成员可以查看之前的消息记录。由于用户基础不一,我们要由浅入深,先讲基础操作,再讲工程实例,再到深入GHA开发,以及各种复杂算法。期间可能会穿插着来讲,可以直接回复问题,我们会尽量去解答。您觉得有用,请将此微信号分享给能用得着的朋友。
(本微信号文章如有转载请注明作者和出处,如用于商业用途请联系作者)
----------------------------------------------------------------------------------------------
下面原文链接是老婆大人在起点写的小说,有在起点上看小说的朋友希望能帮忙捧捧场,谢谢啦。
http://www.qdmm.com/MMWeb/2981855.aspx

-----------------------------------------------------------------------------------------------
我们来自江河梦小组(Scond Effect Group),工程用到gh,所以必须学习好GH插件,而大部分权威资料都来自国外,所以就组织组员翻译来自GH官方论坛的帖子,以便学习。本文由组员张桂钊翻译,GHA开发相关内容。

原文链接:http://www.grasshopper3d.com/forum/topics/clarification-about-gh-component-gh-param-and-gh-attributes?commentId=2985220%3AComment%3A1077714

Clarification about GH_Component, GH_Paramand GH_Attributes解释关于GH_Component,GH_Param GH_Attributes
·        Posted by Luca Colo on May 22, 2014 at 8:03am in VB,C# and Python Coding
·        SendMessage   ViewDiscussions
Hi,
嗨,
I'mcurrently trying to understand to what extent it is possible to customize yourown custom component.
我在想知道,我需要了解到什么程度就可以自定义自己的组件了。
Firstof all, I'd like some clarifications about the differences betweenGH_Component, GH_Attributes and GH_Param<T>
首先,想知道GH_Component, GH_Attributes GH_Param<T>之间的差异。
Frommine understanding:
这是我的理解:
BothGH_Component and GH_Param<T> derive from GH_ActiveObject class, whichimplements IGH_ActiveObject(which inherits from IGH_Document).
GH_Component GH_Param<T>都是源自与GH_ActiveObject 类,它实现IGH_ActiveObject(从IGH_Document中继承)
Inheritingfrom GH_Component or GH_Param<T> grants you the possibility to build (notfrom scratch) your own CustomComponent or your own CustomParam.
Whatis the difference between those two classes?
GH_Component或者 GH_Param<T>中继承(不是从无到有)这样才可能构建自己CustomComponent或者CustomParam,这两个类有什么差别?
AGH_Component is a class that inherits from the common base classGH_ActiveObject ("which is the base class for all objects on the canvasthat actually do something"), and its pecularity is to take n inputparameters (of type GH_"wrapper" <IGH_Goo>), to compute mresult parameters inside its own SolveIstance function, and to return thoseresults as output parameters.
AGH_Component是一个继承于GH_ActiveObject这个公共基础类的一个子类(GH_ActiveObject这个所有在画布能够做点什么的对象的基础类。),它的特性是n的输入参数(类GH_"wrapper" <IGH_Goo>),通过内部函数SolveIstance计算m结果参数,并返回这些结果参数作为输出参数。
AGH_Param<T> is a class that wraps an objects(which implements IGH_Goo).
AGH_Param<T>是一个封装类对象(实现IGH_Goo
Forexample, whenever you want to build a new complexDataType (which MUST implementIGH_Goo or extend an exisiting GH_Goo<T>), you will wrap this type in anew class that extends GH_Paramspan>complexDataType>.
例如,每当你想建立一个新的complexDataType(它必须实现IGH_Goo或者扩展现有的GH_Goo<T>),你就需要封装这个基于GH_Paramspan>complexDataType>扩展的新类
Doingso, you also grant the possibility to your complexDataType to have its own capsule, usable on the canvas.
这样做以后,你就可以基于complexDataType使其有了自己外形,可以哄在画布上了。

So,if you have to build a "basic" component, in one or both of those twoclasses you can find all you need.
所以,如果要建立一个“基本”组件,在这一个或者两个,能够找到自己所需要的。
Butwhat if you want to define how it displays (on the canvas), its layout, or itsevent handling?
但是,可以自定义如何显示(在画布上),布局,或者处理事件吗?
Inthe SDK documentation you can find an example suggesting you to use aIGH_Attributes<T> interface (or a GH_Attributes<T>).
在SDK文档中,可以找到一个例子,推荐你使用IGH_Attributes < T >界面(或GH_Attributes < T >)。
GH_Attributes<T>(where T is a class that implements IGH_DocumentObject) gives you all thefunctionalities to resolve the lack of configurability described above,overriding some of its methods.
GH_Attributes < T >(T是一个类实现IGH_DocumentObject)给你所有的功能来解决上述缺乏可配置性,覆盖它的一些方法。
Inthe same example, the class that extends GH_Param<T> and the other classthat extends GH_Attributes<T> bind themselves through the constructor ofGH_Attributes.
在相同的示例中,,它扩展了GH_Param < T >,另一个类,扩展了GH_Attributes < T>绑定通过GH_Attributes的构造函数。
Now:
现在请看下面:
- IfI want to define a GH_Attributes<T>, do I also have to provide itsrespective GH_Param?
如果我想定义一个GH_Attributes < T >,我也必须提供其各自GH_Param吗?
- Howshould I assign a GH_Attributes<T> to a GH_Component? (the only examplein documentation clarifies how to assign it to a GH_Param, not a GH_Component)
我该如何分配一个GH_Attributes GH_Component < T >?(唯一的示例文档GH_Param解释如何分配它,不是GH_Component)
-Isit right to say that this way opens every possibility to the a GH_Componentcustomization?
用这个方法打开这个自定义的GH_Component是正确的吗?
I'dbe very glad if you could correct what I said above, and it would be great tohave a complete example of a complex component (like "Legend", or"QuickGraph", ..).
我将非常高兴你能够正确理解和回答上我上面所说的,这个将是一个很好如何构建一个复杂组件的完整例子()
Whatis the GraphMapper Component? Is it a GH_Component, a GH_Param<T>,neither of those?
GraphMapper组件是什么?GH_Component,GH_Param < T>,其中的任何一个吗?
Irefer to those component because they group all the functionalities id like toimplement on a CustomComponent.
我指的是组件,因为它们这个组所有的功能我想像CustomComponent一样实现。
To bemore specific, how should I build a Component to make it receive inputs throughdefault wiring techniques and also through user interaction over the displayedcomponent itself (like GraphMapper)?
更具体地说,我该如何构建一个组件,使它接收输入通过默认的连接技术,也通过用户交互的显示组件本身(如GraphMapper)?
I canimage there will be a lot of code to write, but I'd like to know where to startfrom.
我能想象这个会用很到代码来写,但是我想知道从哪里开始。
Hopeeverything is clear,
希望搞清每件事。
Thanksin advance.
先谢谢各位了。
Luca
Luca
Tags: .NET, GH_Attributes, GH_Component, GH_Param, GUI, c#
ShareTwitterFacebook
Views: 156
  Permalink Reply by panhao on May 22, 2014 at 10:17am
GH_Component also has amethod called CreateAttributes().
GH_Component也有一个方法叫做CreateAttributes()
You can override it followingthe GH_Param tutorial.
你可以根据GH_Param的教程重写它。
The display class can beGH_Attributes or GH_ComponentAttributes.
显示类可能是GH_Attributes 或者GH_ComponentAttributes.
Your GraphMapper componentcan be a sub-class of GH_Param or GH_Component.And if you want to have moreindividual properties.
如果你想有更多的个人特性,GraphMapper组件可以是GH_Param或者的子类。
Inherit from GH_Component isbetter.
继承于GH_Component更好
Rendering methods inGH_Attributes are all form GDI+.
渲染方法GH_Attributes GDI +都是形式
  Permalink Reply by DavidRutten on May 22, 2014 at 10:37am
Hi Luca,
你好,Luca
you're pretty close, here'sthe basic breakdown.
如果你想了解,这里介绍几种的类。
All objects that want to bepart of a GH_Document must implement the IGH_DocumentObject interface.
所有对象要GH_Document必须实现IGH_DocumentObject接口的一部分。
This interface provides coremethods needed for all objects, such as Undo, Autosave, Display, Menu andTooltip functionality.
这个接口提供了核心方法所需的所有对象,如撤消、自动保存、显示、菜单和提示功能。
IGH_ActiveObjectextends upon IGH_DocumentObject and it provides methods used for participatingin the solution. (Incidentally this distinction is gone in GH2, I'm using asingle interface now which covers everything).
IGH_ActiveObject延伸IGH_DocumentObject和它提供的方法用于参与解决方案。(顺便说一下,这种区别是GH2是没有的,我现在使用单一接口涵盖一切)。
Some objects which onlyimplement IGH_DocumentObject are Jumps, Scribbles and Groups, pretty mucheverything else implements IGH_ActiveObject.
一些对象,只有实现IGH_DocumentObject跳跃,描述和组,实现IGH_ActiveObject几乎一切。
That's basically all you needto make your own objects, however making parameters and components from scratchis a boatload of work, so I've provided classes with basic implementations forthese types of object.
这基本上是所有你需要让自己的对象,然而从头制作参数和组件是一船的工作,所以我给类提供了基本的实现这些类型的对象。
Parameters (via the IGH_Paraminterface and several GH_Param<T> classes) maintain a data tree which isassociated with a specific type of IGH_Goo data. They have the logic build inthat allows them to communicate with other parameters via their input/outputwires.
参数(通过IGH_Param界面和几个GH_Param < T >类)维护数据树,与一个特定类型的IGH_Goo相关联的数据。他们中构建的逻辑,让他们与其他参数通过通信输入/输出电线。
Components tend to derivefrom GH_Component (or at the very least implement IGH_Component), as that classprovides all the bookkeeping methods for managing a collection of input andoutput parameters.
组件往往源自GH_Component(或至少实现IGH_Component),因为这类提供了所有的记账方法来管理一组输入和输出参数。
You are more than welcome toimplement IGH_ActiveObject from scratch, but you'll probably spend monthsgetting it right because there is a lot of stuff that matters.
欢迎你多来实现IGH_ActiveObject从头开始,但你可能会花几个月的时间是正确的,因为有很多重要的东西。
------------------------------------------------------------------------
Attributes are used primaryfor display purposes. Every object must be capable of creating and maintaininga class which ultimately implements IGH_Attributes. The attributes are incharge of rendering the object to the canvas, providing basic information aboutthe shape of an object, handling mouse and key events, responding correctly toselection actions, and (in GH1 anyway) maintaining the object hierarchy.Basically, it means that component attributes must be able to 'talk' to inputand output parameters, and the parameters need to be able to figure out theyare slaved to a component.
属性主要用于显示目的。每个对象必须能够创建和维护一个类最终实现IGH_Attributes。负责渲染对象的属性到画布上,提供基本对象的形状信息,处理鼠标和关键事件,正确选择行为的反应,(在GH1)维护对象的层次结构。基        本上,这意味着组件属性必须能够“说话”的输入和输出参数,以及参数需要能够找出他们奴役一个组件。
-----------------------------------------------------------------------
Usually it's sufficient toderive either from GH_Component or from GH_Param<T> (orGH_PersistentParam<T> or GH_GeometryParam<T>) and override thedefault attributes. Doing this allows you to change the way the object looksand to change the way the object responds to mouse events.
通常足以从GH_Component或来自GH_Param < T >(或GH_PersistentParam< T >或GH_GeometryParam < T >)和覆盖默认的属性。这样做允许您改变对象的外观和改变对象响应鼠标事件的方式。
What sort of exotic objectare you looking to create?
你想创建什么样异样的对象?
--
David Rutten
david@mcneel.com
  Permalink Reply by panhao on May 23, 2014 at 4:09am
Hello David
你好,David
It takes me about a week tounderstand the drawing sequence of the capsule.The class tree seems have too manybranches.And it makes the code difficult to read.You said Grasshopper2 will usea basic interface.A good news!
我花了大约一个星期了解容器的序列图。类树似乎有太多的分支。它使代码难以阅读。你说Grasshopper2将使用一个基本的界面。这是一个好消息!
Wherecould I get the latest news about Grasshopper2. Do you have a githubrepositoryCouldIput forward my proposals?
我在哪能获得GH2的最新消息,你有github库吗?我能提出些建议吗?
  Permalink Reply by DavidRutten on May 23, 2014 at 4:59am
You can certainly put forwardproposals. The code isn't currently available anywhere online and I don't knowif we will open source all of it. I'm rewriting the program from scratch,trying to achieve the following:
你当然可以提出建议。当前可用的代码并不是在任何地方都可以使用,我不知道我们是否将开放源码。我从头重写程序,试图实现如下:
§  DataTrees will be made more consistent. No more distinctionbetween DataTree<T> and GH_Structure<T:IGH_Goo>. All functionality(path mapping, grafting, simplifying) will be available directly on the coredatatree class itself.
§  DataTrees将更加一致。不再区分DataTree < T >和GH_Structure < T:IGH_Goo >。所有功能(路径映射,嫁接,简化)可以直接在核心datatree类本身。
§  Naming will follow standard .NET guidelines. Classes are nolonger prefixed with "GH_".
§  命名规则遵循.NET的规则,类不再有GH-这前缀了。
§  Functionality from attributes will be moved into objects,basically, objects need to be fully functional without any attributes.Attributes should only be necessary when the object is drawn on the screen.
§     属性的功能将进入对象,基本上,对象需要全功能没有任何属性。属性对象时应该只需要绘制在屏幕上。
§  
§  Multiple canvasses.
§  多画布
§  More events.
§  多事件
§  Unmutable types. I'm trying to make as many structs and classesunmutable as possible. This should vastly improve the reliability of theruntime and make it more threadsafe.
§  Unmutable类型。我试图让尽可能多的结构和类unmutable。这将大大提高运行时的可靠性,使其更多的线程安全的。
§  
§  Adding threaded and async overloads for time consumingoperations.
§     添加线程和异步耗时操作的过载。
§  
§  Disassociate the UI from specific frameworks (GDI+ or Direct2Dor WPF for example) and make it cross-platform.
§  使分离特定的UI框架(例如GDI + Direct2D或WPF)并使其跨平台。
§  
§  Improve basic consistency, both in naming and functionality.
§  ,在命名和功能上,提高基本的一致性
Although cleaning up the SDKis a major goal in GH2, do note that pretty much all the functionality isneeded to do what Grasshopper does. I.e., there won't be any less of it,hopefully just better structured.
虽然清理SDKGH2的一个主要的目标,注意,gh几乎所有的功能都是需要做什么就有什么,所以功能上不会减少,在结构变的更好。
--
David Rutten
david@mcneel.com
  Permalink Reply by panhao on May 24, 2014 at 7:03am
Is it possible to add aoption that write scripts in viusal studio and then use csharpCodeProvider tocompile and use Reflection to run.It is much more like what the C# componentdoes.Writing in visual studio is more convenient.Or if the new Grasshopper havea public class about C# Reflection...
是否可以添加一个选项,viusal studio编写脚本,然后使用csharpCodeProvider编译和使用反射来运行。它更像c#组件。写在visual studio更方便。或如果新gh有关于GH C#反射的公众类

Hope to see a powerful Grasshopper2.0.
希望GH2更好
  Permalink Reply by DavidRutten on May 24, 2014 at 8:21am
You can write (and debug)components in Visual Studio if you create a GHA project. Giulio wrote a set ofproject wizards for this so it should be very easy to set up. Is that not whatyou're after?
--
您可以编写和调试组件在Visual Studio如果你创建一个GHA项目。朱利奥为此写了一组项目向导,它应该很容易设置。应该难不倒你。
David Rutten
david@mcneel.com
  Permalink Reply by panhao on May 24, 2014 at 1:50pm
WellI have two ways to debug in VisualStudio while Rhino is running.Either reloadGrasshopper or use C# Reflection in C# component.Reloadinggrasshopper makes a lot of trouble when I need to change  parametersfrequently.Using C# Reflection in C# component  brings strange exceptionssometimes.Maybe I should understand how C# component works completely.That is a difficult task with Reflector.
我有两个方法来调试在VisualStudio犀牛正在运行。重新加载GH或使用c#反射在c#中组件。重载GH使得很多麻烦当我经常需要改变参数。使用c#反射在c#中有时组件带来了奇怪的例外。也许我应该完全理解c#组件是如何工作的。这是一个艰巨的任务与反射器。
  Permalink Reply by panhao on May 24, 2014 at 11:13pm
MaybeI can follow ReadFile component to write one.
也许我可以跟随ReadFile组件编写一个。

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

精彩回复

文明上网理性发言、请文明用语

成为第一个回答人