Example #1
0
void GraphScene::init(InitType initType)
{
    // Remove all nodes from the scene (and thus also connecting edges)
    for (int row = 0; row < m_gridLayout->rowCount(); row++) {
        for (int column = 0; column < m_gridLayout->columnCount(); column++) {
            // If there is a node in that cell of the grid layout, remove it
            removeItem(static_cast<NodeItem *>(m_gridLayout->itemAt(row, column)));
        }
    }

    switch(initType) {                                      // Check how to init the scene
        case EmptyInit:
            setInputNode(NULL);                             // Reset input/output nodes
            setOuputNode(NULL);
            break;
        case StandardInit:
            NodeItem *n1 = new NodeItem(NULL, this);        // Create default input/output nodes
            n1->setName("1");
            m_gridLayout->addItem(n1, 0, 0);
            NodeItem *n2 = new NodeItem(NULL, this);
            n2->setName("2");
            m_gridLayout->addItem(n2, 0, 1);

            addEdge(n1, n2);                                // and wire them with an edge
            setInputNode(n1);                               // Set default input/output nodes
            setOuputNode(n2);
            break;
    }
    setSceneRect(QRectF());
    emit graphChanged();
}
Example #2
0
MultipannerNode::MultipannerNode(std::shared_ptr<Simulation> sim, std::shared_ptr<HrtfData> hrtf): SubgraphNode(Lav_OBJTYPE_MULTIPANNER_NODE, sim)  {
	hrtf_panner = createHrtfNode(sim, hrtf);
	amplitude_panner = createAmplitudePannerNode(sim);
	input=createGainNode(simulation);
	input->resize(1, 1);
	input->appendInputConnection(0, 1);
	input->appendOutputConnection(0, 1);
	input->connect(0, hrtf_panner, 0);
	input->connect(0, amplitude_panner, 0);
	appendOutputConnection(0, 0);
	setInputNode(input);
}
Example #3
0
PannerBankNode::PannerBankNode(std::shared_ptr<Simulation> sim, int pannerCount, std::shared_ptr<HrtfData> hrtf): SubgraphNode(Lav_OBJTYPE_PANNER_BANK_NODE, sim)  {
	if(pannerCount < 2) ERROR(Lav_ERROR_RANGE, "Must use at least 2 panners.");
	input_gain = createGainNode(simulation);
	output_gain =createGainNode(simulation);
	input_gain->resize(pannerCount, pannerCount);
	for(int i = 0; i < pannerCount; i++) {
		input_gain->appendInputConnection(i, 1);
		input_gain->appendOutputConnection(i, 1);
	}
	output_gain->resize(2, 2);
	output_gain->appendInputConnection(0, 2);
	output_gain->appendOutputConnection(0, 2);
	setInputNode(input_gain);
	setOutputNode(output_gain);
	for(int i = 0; i < pannerCount; i++) {
		panners.push_back(createMultipannerNode(simulation, hrtf));
		input_gain->connect(i, panners[i], 0);
		panners[i]->connect(0, output_gain, 0);
	}
	appendOutputConnection(0, 2);
}
Example #4
0
bool GraphScene::loadFrom(const QString &fileName)
{
    QFile file(fileName);
    if (file.exists() && file.open(QFile::ReadOnly)) {
        QTextStream stream(&file);
        QHash<QString, NodeItem *> nodes;                   // Temporary hashmap for faster lookup

        init(EmptyInit);                                    // Create an empty scene

        QString line;
        do {                                                // Iterate over all the lines in the file
            line = stream.readLine();                       // and split the line at ' ' characters
            const QStringList splittedLine = line.split(" ");
            if (splittedLine[0] == "node") {
                // Found a node, add it to the scene
                NodeItem *node = new NodeItem(NULL, this);
                node->setName(splittedLine[1]);
                NodeItem::NodeType nodeType = static_cast<NodeItem::NodeType>(splittedLine[2].toInt());
                switch (nodeType) {
                    case NodeItem::InputNode:
                        setInputNode(node);                 // We found the input node
                        break;
                    case NodeItem::OutputNode:
                        setOuputNode(node);                 // We found the ouput node
                        break;
                    case NodeItem::StandardNode:
                        // This should already be set by default but doesn't harm here
                        node->setNodeType(NodeItem::StandardNode);
                        break;
                }
                // There is obviously a (Matlab) formula attached, parse it...
                if (splittedLine.length() > 5) {
                    int formulaStart = line.indexOf('"');
                    QString formula = line;
                    formula.remove(0, formulaStart);
                    while (!formula.endsWith('"')) {        // Formula spans multiple lines
                        formula += '\n' + stream.readLine();
                    }
                    formula.chop(1);                        // Remove leading '"'
                    formula.remove(0, 1);                   // Remove trailing '"'
                    node->setFormula(formula);
                }

                nodes.insert(node->name(), node);
                m_gridLayout->addItem(node, splittedLine[3].toInt(), splittedLine[4].toInt());
            } else if (splittedLine[0] == "edge") {
                NodeItem *start = nodes[splittedLine[2]];   // Found an edge, add it to the scene
                NodeItem *end = nodes[splittedLine[3]];

                DirectedEdgeItem *edge = addEdge(start, end);
                edge->setName(splittedLine[1]);
                // There is obviously a (Matlab) formula attached, parse it...
                if (splittedLine.length() > 4) {
                    int formulaStart = line.indexOf('"');
                    QString formula = line;
                    formula.remove(0, formulaStart);
                    while (!formula.endsWith('"')) {        // Formula spans multiple lines
                        formula += '\n' + stream.readLine();
                    }
                    formula.chop(1);                        // Remove leading '"'
                    formula.remove(0, 1);                   // Remove trailing '"'
                    edge->setFormula(formula);
                }
            }
        } while (!line.isNull());

        emit graphChanged();
        file.close();
        return true;
    }
    return false;
}