Skip to content
Snippets Groups Projects
Commit 151e374c authored by jsiegle's avatar jsiegle
Browse files

Update GraphViewer rendering

parent 7886a44d
No related branches found
Tags v0.2.2
No related merge requests found
......@@ -24,14 +24,14 @@
#include "AccessClass.h"
#include "UI/UIComponent.h"
#include "UI/EditorViewport.h"
#include "UI/ProcessorList.h"
#include "UI/DataViewport.h"
#include "UI/ControlPanel.h"
#include "UI/MessageCenter.h"
#include "UI/GraphViewer.h"
#include "Audio/AudioComponent.h"
#include "Processors/ProcessorGraph.h"
// #include "UI/EditorViewport.h"
// #include "UI/ProcessorList.h"
// #include "UI/DataViewport.h"
// #include "UI/ControlPanel.h"
// #include "UI/MessageCenter.h"
// #include "UI/GraphViewer.h"
// #include "Audio/AudioComponent.h"
// #include "Processors/ProcessorGraph.h"
void AccessClass::setUIComponent(UIComponent* ui_)
{
......
......@@ -260,6 +260,9 @@ public:
/** Returns the editor of this processor's destination */
GenericEditor* getDestEditor();
/** Returns the editors a splitter or merger is connected to */
virtual Array<GenericEditor*> getConnectedEditors() { }
protected:
......
......@@ -161,6 +161,27 @@ int SplitterEditor::getPathForEditor(GenericEditor* editor)
}
Array<GenericEditor*> SplitterEditor::getConnectedEditors()
{
Array<GenericEditor*> editors;
Splitter* processor = (Splitter*) getProcessor();
for (int pathNum = 0; pathNum < 2; pathNum++)
{
processor->switchIO();
if (processor->getDestNode() != nullptr)
editors.add(processor->getDestNode()->getEditor());
else
editors.add(nullptr);
}
return editors;
}
void SplitterEditor::switchDest()
{
Splitter* processor = (Splitter*) getProcessor();
......
......@@ -50,6 +50,7 @@ public:
void switchIO(int i);
int getPathForEditor(GenericEditor* editor);
Array<GenericEditor*> getConnectedEditors();
private:
......
......@@ -104,7 +104,7 @@ bool Merger::stillHasSource()
void Merger::switchIO()
{
std::cout << "Merger switching source." << std::endl;
//std::cout << "Merger switching source." << std::endl;
if (activePath == 0)
{
......
......@@ -105,7 +105,7 @@ void Splitter::switchIO(int destNum)
void Splitter::switchIO()
{
std::cout << "Splitter switching source." << std::endl;
//std::cout << "Splitter switching source." << std::endl;
if (activePath == 0)
{
......
......@@ -38,7 +38,7 @@ GraphViewer::~GraphViewer()
void GraphViewer::addNode(GenericEditor* editor)
{
GraphNode* gn = new GraphNode(editor);
GraphNode* gn = new GraphNode(editor, this);
addAndMakeVisible(gn);
availableNodes.add(gn);
......@@ -56,6 +56,14 @@ void GraphViewer::removeNode(GenericEditor* editor)
}
void GraphViewer::removeAllNodes()
{
availableNodes.clear();
updateNodeLocations();
}
void GraphViewer::updateNodeLocations()
{
for (int i = 0; i < availableNodes.size(); i++)
......@@ -66,12 +74,6 @@ void GraphViewer::updateNodeLocations()
repaint();
}
void GraphViewer::removeAllNodes()
{
availableNodes.clear();
}
int GraphViewer::indexOfEditor(GenericEditor* editor)
{
int index = -1;
......@@ -87,6 +89,45 @@ int GraphViewer::indexOfEditor(GenericEditor* editor)
return index;
}
int GraphViewer::nodesAtLevel(int level)
{
int numNodes;
for (int i = 0; i < availableNodes.size(); i++)
{
if (availableNodes[i]->getLevel() == numNodes)
{
numNodes++;
}
}
return numNodes;
}
int GraphViewer::getHorizontalShift(GraphNode* gn)
{
int shift = 0;
for (int i = 0; i < availableNodes.size(); i++)
{
if (availableNodes[i] == gn)
{
break;
} else
{
if (availableNodes[i]->getLevel() == gn->getLevel())
{
shift++;
}
}
}
return shift;
}
void GraphViewer::paint(Graphics& g)
{
......@@ -98,25 +139,88 @@ void GraphViewer::paint(Graphics& g)
g.drawFittedText("open ephys", 40, 40, getWidth()-50, getHeight()-50, Justification::bottomRight, 100);
// for (int i = 0; i < availableNodes.size(); i++)
// {
// g.drawText(availableNodes[i]->getName(), 20, 20*i, getWidth()-20, 40, Justification::left, true);
// }
// draw connections
for (int i = 0; i < availableNodes.size(); i++)
{
if (!availableNodes[i]->isSplitter())
{
if (availableNodes[i]->getDest() != nullptr)
{
int indexOfDest = indexOfEditor(availableNodes[i]->getDest());
if (indexOfDest > -1)
connectNodes(i, indexOfDest, g);
}
} else {
Array<GenericEditor*> editors = availableNodes[i]->getConnectedEditors();
for (int path = 0; path < 2; path++)
{
int indexOfDest = indexOfEditor(editors[path]);
if (indexOfDest > -1)
connectNodes(i, indexOfDest, g);
}
}
}
}
void GraphViewer::connectNodes(int node1, int node2, Graphics& g)
{
Point<float> start = availableNodes[node1]->getCenterPoint();
Point<float> end = availableNodes[node2]->getCenterPoint();
Path linePath;
float x1 = start.getX();
float y1 = start.getY();
float x2 = end.getX();
float y2 = end.getY();
linePath.startNewSubPath (x1, y1);
linePath.cubicTo (x1, y1 + (y2 - y1) * 0.9f,
x2, y1 + (y2 - y1) * 0.1f,
x2, y2);
PathStrokeType stroke (2.0f);
g.strokePath(linePath, stroke);
}
/// ------------------------------------------------------
GraphNode::GraphNode(GenericEditor* ed)
GraphNode::GraphNode(GenericEditor* ed, GraphViewer* g)
{
editor = ed;
mouseOver = false;
labelFont = Font("Paragraph", 14, Font::plain);
gv = g;
}
GraphNode::~GraphNode()
{
}
int GraphNode::getLevel()
{
int level = -1;
GenericEditor* ed = editor;
while (ed != nullptr)
{
level += 1;
ed = ed->getSourceEditor();
}
return level;
}
void GraphNode::mouseEnter(const MouseEvent& m)
{
......@@ -141,65 +245,107 @@ bool GraphNode::hasEditor(GenericEditor* ed)
return false;
}
bool GraphNode::isSplitter()
{
return editor->isSplitter();
}
bool GraphNode::isMerger()
{
return editor->isMerger();
}
GenericEditor* GraphNode::getDest()
{
return editor->getDestEditor();
}
Array<GenericEditor*> GraphNode::getConnectedEditors()
{
return editor->getConnectedEditors();
}
const String GraphNode::getName()
{
return editor->getName();
}
Point<float> GraphNode::getCenterPoint()
{
Point<float> center = Point<float>(getX()+10, getY()+10);
return center;
}
void GraphNode::switchIO(int path)
{
}
void GraphNode::updateBoundaries()
{
int level = -1;
int chain = 0;
// float vertShift = -1;
// float horzShift = 0;
GenericEditor* ed = editor;
// GenericEditor* ed = editor;
while (ed != nullptr)
{
level++;
// while (ed != nullptr)
// {
// vertShift += 1;
GenericEditor* sourceEditor = ed->getSourceEditor();
// GenericEditor* sourceEditor = ed->getSourceEditor();
if (sourceEditor != nullptr)
{
if (sourceEditor->isSplitter())
{
if (sourceEditor->getPathForEditor(ed) == 1)
chain++;
}
}
ed = sourceEditor;
// if (sourceEditor != nullptr)
// {
// if (sourceEditor->isSplitter())
// {
// if (sourceEditor->getPathForEditor(ed) == 1)
// horzShift += 1;
// //else
// // horzShift -= 0.5;
// }
// }
// ed = sourceEditor;
}
// }
// ed = editor;
// if (ed->isSplitter())
// {
// horzShift += 0.5;
// }
setBounds(20+chain*140, 20+level*40, 150, 50);
// while (ed != nullptr)
// {
// GenericEditor* destEditor = ed->getDestEditor();
// if (destEditor != nullptr)
// {
// if (destEditor->isSplitter())
// {
// horzShift += 0.5;
// } else if (destEditor->isMerger())
// {
// if (destEditor->getPathForEditor(ed) == 1)
// horzShift += 1;
// }
// }
// ed = destEditor;
// }
int level = getLevel();
int horzShift = gv->getHorizontalShift(this);
setBounds(20+horzShift*140, 20+getLevel()*40, 150, 50);
}
void GraphNode::paint(Graphics& g)
{
if (editor->getDestEditor() != nullptr)
{
Line<float> line = Line<float>(10,10,10,50);
g.setColour(Colours::grey);
g.drawLine(line, 2.0f);
if (editor->isSplitter())
{
Path linePath;
float x1 = 10;
float y1 = 19;
float x2 = 150;
float y2 = 45;
linePath.startNewSubPath (x1, y1);
linePath.cubicTo (x1, y1 + (y2 - y1) * 0.33f,
x2, y1 + (y2 - y1) * 0.66f,
x2, y2);
PathStrokeType stroke (2.0f);
g.strokePath(linePath, stroke);
}
}
if (mouseOver)
{
......@@ -213,6 +359,4 @@ void GraphNode::paint(Graphics& g)
g.drawText(getName(), 25, 0, getWidth()-25, 20, Justification::left, true);
}
\ No newline at end of file
......@@ -43,7 +43,7 @@
class GraphNode : public Component
{
public:
GraphNode(GenericEditor* editor);
GraphNode(GenericEditor* editor, GraphViewer* g);
~GraphNode();
void mouseEnter(const MouseEvent& m);
......@@ -55,19 +55,32 @@ public:
void paint(Graphics& g);
void updateBoundaries();
Point<float> getCenterPoint();
GenericEditor* getDest();
Array<GenericEditor*> getConnectedEditors();
void switchIO(int path);
bool isSplitter();
bool isMerger();
const String getName();
int getLevel();
private:
GenericEditor* editor;
Font labelFont;
bool mouseOver;
GraphViewer* gv;
};
class GraphViewer : public Component, public AccessClass
class GraphViewer : public Component
{
public:
......@@ -81,8 +94,12 @@ public:
void removeNode(GenericEditor* editor);
void removeAllNodes();
int nodesAtLevel(int lvl);
int getHorizontalShift(GraphNode*);
private:
void connectNodes(int, int, Graphics&);
void updateNodeLocations();
int indexOfEditor(GenericEditor* editor);
......
......@@ -83,7 +83,6 @@ UIComponent::UIComponent(MainWindow* mainWindow_, ProcessorGraph* pgraph, AudioC
dataViewport->setUIComponent(this);
controlPanel->getAudioEditor()->setUIComponent(this);
controlPanel->setUIComponent(this);
graphViewer->setUIComponent(this);
processorGraph->updatePointers(); // needs to happen after processorGraph gets the right pointers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment