Permalink
Browse files

Interface.

  • Loading branch information...
1 parent 60a5c75 commit 053b01e77e66f824d5f0e533f3a2ee146a51554b @mrbichel mrbichel committed Sep 28, 2012
@@ -24,7 +24,7 @@
04CAE09D15F5003F0073E46D /* simulator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE09C15F5003F0073E46D /* simulator.cpp */; };
04CAE09F15F504FB0073E46D /* flowControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE09E15F504FB0073E46D /* flowControl.cpp */; };
04CAE0A315F5052C0073E46D /* gui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE0A215F5052C0073E46D /* gui.cpp */; };
- 04CAE0A615F520590073E46D /* visualizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE0A515F520590073E46D /* visualizer.cpp */; };
+ 04CAE0A615F520590073E46D /* interface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04CAE0A515F520590073E46D /* interface.cpp */; };
BBAB23CB13894F3D00AA2426 /* GLUT.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = BBAB23BE13894E4700AA2426 /* GLUT.framework */; };
E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4328148138ABC890047C5CB /* openFrameworksDebug.a */; };
E45BE97B0E8CC7DD009D7055 /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE9710E8CC7DD009D7055 /* AGL.framework */; };
@@ -75,7 +75,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
- 04163F8D16105D7900382C5C /* installationControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = installationControl.h; sourceTree = "<group>"; };
042338EF15F691BC00E5AE1A /* changelog.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = changelog.txt; sourceTree = "<group>"; };
042338F215F691BC00E5AE1A /* install.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = install.xml; sourceTree = "<group>"; };
042338F315F691BC00E5AE1A /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE.txt; sourceTree = "<group>"; };
@@ -225,8 +224,8 @@
04CAE0A115F505210073E46D /* gui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gui.h; sourceTree = "<group>"; };
04CAE0A215F5052C0073E46D /* gui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gui.cpp; sourceTree = "<group>"; };
04CAE0A415F50CB80073E46D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
- 04CAE0A515F520590073E46D /* visualizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = visualizer.cpp; sourceTree = "<group>"; };
- 04CAE0A715F520660073E46D /* visualizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = visualizer.h; sourceTree = "<group>"; };
+ 04CAE0A515F520590073E46D /* interface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = interface.cpp; sourceTree = "<group>"; };
+ 04CAE0A715F520660073E46D /* interface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = interface.h; sourceTree = "<group>"; };
BBAB23BE13894E4700AA2426 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = ../../../libs/glut/lib/osx/GLUT.framework; sourceTree = "<group>"; };
E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = openFrameworksLib.xcodeproj; path = ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj; sourceTree = SOURCE_ROOT; };
E45BE9710E8CC7DD009D7055 /* AGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AGL.framework; path = /System/Library/Frameworks/AGL.framework; sourceTree = "<absolute>"; };
@@ -883,9 +882,8 @@
04CAE0A015F5050A0073E46D /* flowControl.h */,
04CAE0A115F505210073E46D /* gui.h */,
04CAE0A215F5052C0073E46D /* gui.cpp */,
- 04CAE0A515F520590073E46D /* visualizer.cpp */,
- 04CAE0A715F520660073E46D /* visualizer.h */,
- 04163F8D16105D7900382C5C /* installationControl.h */,
+ 04CAE0A515F520590073E46D /* interface.cpp */,
+ 04CAE0A715F520660073E46D /* interface.h */,
);
path = src;
sourceTree = SOURCE_ROOT;
@@ -1000,7 +998,7 @@
04CAE09D15F5003F0073E46D /* simulator.cpp in Sources */,
04CAE09F15F504FB0073E46D /* flowControl.cpp in Sources */,
04CAE0A315F5052C0073E46D /* gui.cpp in Sources */,
- 04CAE0A615F520590073E46D /* visualizer.cpp in Sources */,
+ 04CAE0A615F520590073E46D /* interface.cpp in Sources */,
0423390B15F69DFC00E5AE1A /* Color.cpp in Sources */,
0423390C15F69DFC00E5AE1A /* MSACoreGL.cpp in Sources */,
);
View
@@ -90,6 +90,7 @@ void Data::getStatEntries(Location* loc){
root = json_loads(responseStr.c_str(), &error);
int i;
+
DataPoint newPoints [2];
for(i = 0; i < json_array_size(root); i++)
@@ -105,14 +106,17 @@ void Data::getStatEntries(Location* loc){
maxStatEntry = amount;
}
-
+ newPoints[direction-1].sum += amount;
newPoints[direction-1].bikes.push_back(amount);
}
for(i = 0; i < 2; i++) {
- newPoints[i].loc = loc;
- dataPoints.push_back(newPoints[i]);
+
+ if (newPoints[i].sum != 0) {
+ newPoints[i].loc = loc;
+ dataPoints.push_back(newPoints[i]);
+ }
}
View
@@ -23,6 +23,7 @@ struct DataPoint {
string direction_name;
MSA::Interpolator1D bikes;
+ int sum;
Location * loc;
View
@@ -1,6 +1,7 @@
#pragma once
#include "ofMain.h"
+#include "data.h"
#include "defines.h"
struct Channel {
@@ -15,6 +16,8 @@ struct Channel {
bool lock; // when lock true the channel does not accept new valve commands
// maybe do a vector of waiting commands
+
+ Path * path;
};
class flowControl {
View
@@ -2,7 +2,7 @@
void Gui::setup(){
- ui = new ofxUICanvas(0,0,320,620);
+ ui = new ofxUICanvas(0,0,0,0);
ui->setDrawBack(true);
View
@@ -1,19 +0,0 @@
-#pragma once
-
-#include "ofMain.h"
-#include "data.h"
-#include "gui.h"
-#include "defines.h"
-
-class installationControl {
-public:
-
- void setup(Data * dataRef, Gui * guiRef);
- void update();
- void debugDraw();
-
- // data
- Data * data;
- Gui * gui;
-
-};
View
@@ -0,0 +1,221 @@
+#include "interface.h"
+
+void Interface::setup(Data * dataRef, Gui * guiRef, Simulator * simRef){
+ data = dataRef;
+ gui = guiRef;
+ sim = simRef;
+
+ maxLat = 55.7368;
+ minLat = 55.6108;
+ maxLng = 12.6293;
+ minLng = 12.4519;
+
+ pad = 8;
+
+}
+
+void Interface::update(){
+
+ // update locations for stuff that is clickable here ?
+
+}
+
+void Interface::draw() {
+
+ ofFill();
+ ofBackground(0, 0, 0);
+
+ float w = ofGetWidth();
+ float h = ofGetHeight();
+
+ // draw settings area
+ ofSetColor(50);
+ ofRect(0, 0, w*0.25, h*0.5);
+
+ // draw path selector area
+ ofSetColor(100);
+ ofRect(w*0.25, 0, w*0.25, h*0.5);
+
+ //drawPathList();
+
+ // draw map 50% 0, 100%, 60%
+ drawMap(w*0.5+pad, 0+pad, (w*0.5)-(2*pad), (h*0.5)-(2*pad));
+
+ // draw detail inspection view / path editor
+ ofSetColor(120);
+ ofRect(0, h*0.5, w*0.5, h*0.45);
+
+ drawDetailInspector(0, h*0.5, w*0.5, h*0.45);
+
+
+ // draw output view
+ ofSetColor(60);
+ ofRect(w*0.5, h*0.5, w*0.5, h*0.45);
+
+ // draw simulator control / timeline
+ ofSetColor(40);
+ ofRect(0, h*0.95, w, h*0.05);
+
+
+ /*for (int i=0; i<data->paths.size(); i++) {
+ drawPath(&data->paths[i]);
+ }
+
+ if (selectedPoint) {
+ drawInterpolation(&selectedPoint->bikes, 20., 800., 700., 400.);
+ }*/
+
+}
+
+void Interface::drawMap(float x, float y, float w, float h) {
+
+ ofSetColor(255);
+ ofNoFill();
+
+ for (int i=0; i<data->dataPoints.size(); i++) {
+
+ DataPoint * point = &data->dataPoints[i];
+
+ if(point->loc->lat != 0 && point->loc->lng != 0) {
+
+
+ float a = point->bikes.sampleAt(sim->elapsedFloat);
+
+ point->marker = ofPoint(ofMap(point->loc->lat, minLat, maxLat, x, x+w), ofMap(point->loc->lng, minLng, maxLng, y, y+h));
+
+ point->markerRadius = ofMap(a, 0, data->maxStatEntry, 2, 8);
+
+ ofCircle(point->marker, point->markerRadius);
+
+ }
+
+ }
+}
+
+void Interface::drawDetailInspector(float x, float y, float w, float h) {
+
+ // add modes so this can either display selected point or selected path
+
+ // draw point details
+ if (selectedPoint) {
+
+
+ drawInterpolation(&selectedPoint->bikes, x, y, w, h);
+ }
+
+}
+
+void Interface::drawInterpolation(MSA::Interpolator1D * ipo, float x, float y, float w, float h) {
+
+ for(int i=0; i < w; i++) {
+ ofCircle(x+i, ofMap(ipo->sampleAt(i/w), 0, data->maxStatEntry, y+h, y), 1);
+ }
+
+}
+
+void Interface::mousePressed(int x, int y, int button){
+ for (int i=0; i<data->dataPoints.size(); i++) {
+ DataPoint * point = &data->dataPoints[i];
+
+ if (ofDist(x,y,point->marker.x, point->marker.y) < point->markerRadius) {
+ selectedPoint = point;
+ }
+ }
+}
+
+
+void Interface::keyPressed(int key){
+ if(key == 'P') {
+ Path p;
+ data->paths.push_back(p);
+ }
+
+ if(selectedPoint) {
+ if(key == '1') {
+
+ data->paths[0].addPoint(selectedPoint);
+ }
+ }
+}
+
+
+void Interface::drawPath(Path * path) {
+
+ string s;
+
+ for(int i=0; i<path->points.size(); i++) {
+ s += path->points[i]->loc->name + " < -- > ";
+ }
+
+ ofDrawBitmapString(s, ofGetWidth()-800, 200);
+
+ if(path->points.size() > 0) {
+
+ for(int i=0; i < path->points.size(); i++) {
+ ofDrawBitmapString(ofToString(path->sum.at(i)), (ofGetWidth()-300)+(i*(300/10)), ofGetHeight()-20);
+ }
+
+ for(int p=0; p < 300; p++) {
+
+ float finto = p / float(300);
+
+ //cout<<ofToString(finto)<<endl;
+ float val = path->sum.sampleAt(finto);
+
+ ofCircle(ofGetWidth()-300+p, ofMap(val, 0, data->maxStatEntry, ofGetHeight()-20, 20), 1);
+ }
+ }
+}
+
+void Interface::drawTimeline(float x, float y, float w, float h) {
+
+ ofFill();
+ ofSetColor(100, 100, 100);
+
+ ofRect(x, y, w, h);
+ ofSetColor(255, 255, 255);
+ ofRect(x, y, ofMap(sim->simElapsedTime, 0, sim->simDuration, 0, w), h);
+
+ ofDrawBitmapString("Simulator time: " + sim->formatTime(sim->simElapsedTime) + " / " + sim->formatTime(sim->simDuration), 10, 40);
+
+ ofDrawBitmapString("Speed: " + ofToString(sim->speed), 10, 80);
+
+ ofDrawBitmapString("Real time: " + sim->formatTime(sim->realElapsedTime) + " / " + sim->formatTime(sim->realDuration), 10, 60);
+
+
+
+}
+
+/*void Interface::drawInterpolation(DataPoint * point) {
+
+ int width = 700;
+ int i;
+
+
+
+
+ ofSetColor(100, 259, 60, 255);
+ ofDrawBitmapString(point->direction_name, 20, ofGetHeight()-160);
+
+ ofSetColor(255, 255, 255, 255);
+
+ for(i=0; i < DATA_HOURS; i++) {
+ ofDrawBitmapString(ofToString(point->bikes.at(i)), 10+(i*(width/10)), ofGetHeight()-20);
+
+ }
+
+ ofDrawBitmapString(point->loc->name, 20, ofGetHeight()-200);
+
+ ofSetColor(100, 250, 60, 200);
+
+ for(i=0; i < width; i++) {
+
+ float finto = i / float(width);
+
+ //cout<<ofToString(finto)<<endl;
+ float val = point->bikes.sampleAt(finto);
+
+ ofCircle(10+i, ofMap(val, 0, data->maxStatEntry, ofGetHeight()-20, 20), 1);
+ }
+
+}*/
@@ -8,7 +8,7 @@
#include "simulator.h"
#include "defines.h"
-class Visualizer {
+class Interface {
public:
void setup(Data * dataRef, Gui * guiRef, Simulator * simRef);
void update();
@@ -26,24 +26,26 @@ class Visualizer {
double maxLat;
double maxLng;
- void debugDraw();
+ float pad;
+
void draw();
- void drawDataPoint(DataPoint * point);
- void drawPath(Path * path);
+ void drawMap(float x1, float y1, float w, float h);
+ void drawMapPoint(DataPoint * point);
+ void drawTimeline(float x1, float y1, float w, float h);
+
+ void drawDetailInspector(float x1, float y1, float w, float h);
- void drawMap();
+
+ void drawPath(Path * path);
void drawMapPoint();
void drawMapPath();
- void drawInterpolation(MSA::Interpolator1D * ipo, float width, float height, float max);
-
- void drawInterpolation(DataPoint * point);
- void drawTimeline();
+ void drawInterpolation(MSA::Interpolator1D * ipo, float x1, float y1, float w, float h);
Path * selectedPath;
Oops, something went wrong.

0 comments on commit 053b01e

Please sign in to comment.