实现基于节点的图形界面? [英] Implementing a node-based graphical interface?

查看:244
本文介绍了实现基于节点的图形界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个节点界面,基本上是一个 DAG ,其中每个节点执行操作它的输入连接,并输出一些东西(您可以连接到另一个节点)

I would like to implement a nodal-interface, basically a DAG where each node performs an operation on it's input connections, and outputs something (which you can connect to another node)

一些示例应用程序:

  • Apples "Shake" - screenshot
  • The Foundrys "Nuke" - screenshot
  • MindNode - screenshot
  • vvvv - screenshots
  • Quartz Composer - screenshot

作为第一个目标,我想要一个只有2个节点的图形应用程序。一个数字,它只输出一个固定的数字和一个添加节点,它需要两个输入和输出两个的和。

As a first goal, I would like to have an graphical application with only 2 nodes. A "number" which simply outputs a fixed number, and an "Add" node, which takes two inputs and outputs the sum of the two.

正如人们已经回答 - 对于如何在代码中表示数据,我有一个粗略的想法,例如Python中的伪代码:

As people have answered so-far, I have a rough idea of how to represent the data in code, for example in Python'y looking pseudo-code:

class Number:
    def __init__(self, value):
        self.value = value

    def eval(self):
        return self.value

class Add:
    def __init__(self, input1, input2):
        self.input1 = input1
        self.input2 = input2

    def eval(self):
        return self.input1.eval() + self.input2.eval()


a = Number(20)
b = Number(72)

adder = Add(a, b)
print adder.eval()

我将如何围绕这个包装一个自定义GUI?如下所示,但手绘略少!

How would I got about wrapping a custom GUI around this? Something like the following, but slightly less hand-drawn!

我将从哪里开始?我现在打算在Objective-C / Cocoa中编写它,尽管我对其他语言的建议更加开放。

Where would I begin? I currently plan to write it in Objective-C/Cocoa, although I'm more than open to suggestions for other languages.

推荐答案

我将首先建模一些基本界面(在OOP意义上,而不是GUI感觉)。看来我会有一个节点接收一个输入和一个输出的集合。您没有指出数据类型有多广泛,但您需要一些合适的方法来表示输入/输出。对于您的第一个目标,这可能是一个整数。

I would start by modelling some basic interfaces (in the OOP sense, not the GUI sense). Seems to me you'll have a Node which will accept a collection of inputs and a single output. You didn't give any indication of how broad the data types are, but you'll want some suitable method of representing your inputs/outputs. For your first goal, this could be an integer.

在一些通用的C风格的OOP语言(希望是有道理的):

In some generic C style OOP language (hope it makes sense):

class Node<T> {
    Node<T>[] inputs;
    T eval();
}

class AdderNode extends Node<int> {
    int eval() {
        int accum = 0;
        for (inputs : i)
            accum += i.eval();
        return i;
    }
}

class ConstNode<int I> extends Node<int> {
    int eval() { return I; }
}

AdderNode a;
a.inputs.add(ConstNode<2>());
a.inputs.add(ConstNode<3>());
a.eval();

可以通过用一些抽象类,通用或接口替换int来扩展它。当然实际的实际情况会根据实际的语言而有所不同。

You could expand on this by replacing int with some abstract class, generic, or interface. Actual implementation will vary based on the actual language, of course.

这篇关于实现基于节点的图形界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆