From 4639a228c6de5ffb68761ad14d3d1775ac658494 Mon Sep 17 00:00:00 2001 From: Tats Date: Sun, 5 Jan 2014 18:07:19 -0500 Subject: [PATCH] Resolved all compilation errors from merging --- MainWindow.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++- MainWindow.h | 3 +- Mapper.cpp | 24 +++++++------- MapperGLCanvas.cpp | 20 +++++------ MappingManager.cpp | 3 +- MappingManager.h | 2 ++ Shape.cpp | 64 +++++++++++++++++------------------ Shape.h | 51 ++++++++++++++++++---------- libremapping.pro | 3 ++ 9 files changed, 178 insertions(+), 75 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index e177dac..b4233f8 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -22,6 +22,8 @@ #include "ProjectWriter.h" #include "ProjectReader.h" +MainWindow* MainWindow::instance = 0; + MainWindow::MainWindow() { if (!instance) @@ -621,7 +623,7 @@ void MainWindow::setCurrentFile(const QString &fileName) setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("LibreMapping Project"))); } -bool MainWindow::importFile(const QString &fileName) +bool MainWindow::importMediaFile(const QString &fileName) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { @@ -736,3 +738,82 @@ QString MainWindow::strippedName(const QString &fullFileName) { return QFileInfo(fullFileName).fileName(); } + +void MainWindow::startOscReceiver() +{ +#ifdef HAVE_OSC + int port = config_osc_receive_port; + std::ostringstream os; + os << port; + osc_interface.reset(new OscInterface(this, os.str())); + if (port != 0) + { + osc_interface->start(); + } + osc_timer = new QTimer(this); // FIXME: memleak? + connect(osc_timer, SIGNAL(timeout()), this, SLOT(pollOscInterface())); + osc_timer->start(); +#endif +} + +void MainWindow::pollOscInterface() +{ +#ifdef HAVE_OSC + osc_interface->consume_commands(); +#endif +} + +void MainWindow::applyOscCommand(QVariantList & command) +{ + bool VERBOSE = true; + + if (VERBOSE) + { + std::cout << "MainWindow::applyOscCommand: Receive OSC: "; + for (int i = 0; i < command.size(); ++i) + { + if (command.at(i).type() == QVariant::Int) + { + std::cout << command.at(i).toInt() << " "; + } + else if (command.at(i).type() == QVariant::Double) + { + std::cout << command.at(i).toDouble() << " "; + } + else if (command.at(i).type() == QVariant::String) + { + std::cout << command.at(i).toString().toStdString() << " "; + } + else + { + std::cout << "(?) "; + } + } + std::cout << std::endl; + std::cout.flush(); + } + + if (command.size() < 2) + return; + if (command.at(0).type() != QVariant::String) + return; + if (command.at(1).type() != QVariant::String) + return; + std::string path = command.at(0).toString().toStdString(); + std::string typetags = command.at(1).toString().toStdString(); + + // Handle all OSC messages here + if (path == "/image/uri" && typetags == "s") + { + std::string image_uri = command.at(2).toString().toStdString(); + std::cout << "TODO load /image/uri " << image_uri << std::endl; + } + else if (path == "/add/quad") + addMesh(); + else if (path == "/add/triangle") + addTriangle(); + else if (path == "/project/save") + save(); + else if (path == "/project/open") + open(); +} diff --git a/MainWindow.h b/MainWindow.h index 49d2646..8a30080 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -48,6 +48,7 @@ public: ~MainWindow(); static MainWindow& getInstance(); static void setInstance(MainWindow* inst); + void applyOscCommand(QVariantList & command); protected: // Events. @@ -88,7 +89,7 @@ private: bool loadFile(const QString &fileName); bool saveFile(const QString &fileName); void setCurrentFile(const QString &fileName); - bool importFile(const QString &fileName); + bool importMediaFile(const QString &fileName); void addLayerItem(uint layerId); void clearWindow(); QString strippedName(const QString &fullFileName); diff --git a/Mapper.cpp b/Mapper.cpp index 349a21a..b266e36 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -78,9 +78,9 @@ void TextureMapper::setValue(QtProperty* property, const QVariant& value) QPointF p = value.toPointF(); Shape* shape = it->second.first; int v = it->second.second; - if (shape->getVertex(v).toQPointF() != p) + if (*shape->getVertex(v) != p) { - shape->setVertex(v, Point(p)); + shape->setVertex(v, p); emit valueChanged(); } } @@ -165,8 +165,8 @@ void TextureMapper::drawShapeContour(const Shape& shape, int lineWidth, const QC for (int i = 0; i < shape.nVertices()+1; i++) { glVertex2f( - shape.getVertex(i % shape.nVertices()).x, - shape.getVertex(i % shape.nVertices()).y + shape.getVertex(i % shape.nVertices())->x(), + shape.getVertex(i % shape.nVertices())->y() ); } glEnd(); @@ -181,8 +181,8 @@ void TextureMapper::_buildShapeProperty(QtProperty* shapeItem, Shape* shape) QtVariantProperty* pointItem = _variantManager->addProperty(QVariant::PointF, QObject::tr("Point %1").arg(i)); - Point p = shape->getVertex(i); - pointItem->setValue(QPointF(p.x, p.y)); + Point *p = shape->getVertex(i); + pointItem->setValue(*p); shapeItem->addSubProperty(pointItem); _propertyToVertex[pointItem] = std::make_pair(shape, i); @@ -199,8 +199,8 @@ void TextureMapper::_updateShapeProperty(QtProperty* shapeItem, Shape* shape) if (i < pointItems.size()) { QtVariantProperty* pointItem = (QtVariantProperty*)pointItems[i]; - Point p = shape->getVertex(i); - pointItem->setValue(QPointF(p.x, p.y)); + Point *p = shape->getVertex(i); + pointItem->setValue(*p); } } } @@ -297,11 +297,11 @@ void MeshTextureMapper::_doDraw() for (int i = 0; i < 4; i++) { Util::correctGlTexCoord( - (inputQuad.getVertex(i).x - texture->getX()) / (GLfloat) texture->getWidth(), - (inputQuad.getVertex(i).y - texture->getY()) / (GLfloat) texture->getHeight()); + (inputQuad.getVertex(i)->x() - texture->getX()) / (GLfloat) texture->getWidth(), + (inputQuad.getVertex(i)->y() - texture->getY()) / (GLfloat) texture->getHeight()); glVertex2f( - outputQuad.getVertex(i).x, - outputQuad.getVertex(i).y + outputQuad.getVertex(i)->x(), + outputQuad.getVertex(i)->y() ); } glEnd(); diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 8c7bf17..1c7ccd7 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -156,8 +156,8 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) p->setX(event->x()); p->setY(event->y()); - glueVertex(shape, &p); - shape->setVertex(_active_vertex, p); + glueVertex(shape, p); + shape->setVertex(_active_vertex, *p); update(); emit shapeChanged(getCurrentShape()); @@ -172,15 +172,15 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) { if (_shapefirstgrab == false) { - shape->translate(event->x() - p.x, event->y() - p.y); + shape->translate(event->x() - p.x(), event->y() - p.y()); update(); emit shapeChanged(getCurrentShape()); } else _shapefirstgrab = false; } - p.x = event->x(); - p.y = event->y(); + p.setX( event->x() ); + p.setY( event->y() ); } } @@ -275,12 +275,12 @@ void MapperGLCanvas::glueVertex(Shape *orig, Point *p) { for (int vertex = 0; vertex < shape->nVertices(); vertex++) { - Point v = shape->getVertex(vertex); - if ((abs(v.x - p->x) < dist_stick) && - (abs(v.y - p->y) < dist_stick)) + Point *v = shape->getVertex(vertex); + if ((abs(v->x() - p->x()) < dist_stick) && + (abs(v->y() - p->y()) < dist_stick)) { - p->x = v.x; - p->y = v.y; + p->setX(v->x()); + p->setY(v->y()); } } } diff --git a/MappingManager.cpp b/MappingManager.cpp index cbcfacf..1a6259b 100644 --- a/MappingManager.cpp +++ b/MappingManager.cpp @@ -52,7 +52,8 @@ uint MappingManager::addPaint(Paint::ptr paint) uint MappingManager::addImage(const QString imagePath, int frameWidth, int frameHeight) { - Image* img = new Image(imagePath); + std::string name = _nameAllocator.allocateName("image_"); + Image* img = new Image(name.c_str(), imagePath); img->setPosition( (frameWidth - img->getWidth() ) / 2.0f, (frameHeight - img->getHeight()) / 2.0f ); diff --git a/MappingManager.h b/MappingManager.h index dda2701..a82bbd0 100644 --- a/MappingManager.h +++ b/MappingManager.h @@ -45,6 +45,8 @@ private: std::vector layerVector; std::map layerMap; + NameAllocator _nameAllocator; + public: /// Returns the list of mappings associated with given paint. std::map getPaintMappings(const Paint::ptr paint) const; diff --git a/Shape.cpp b/Shape.cpp index b31b6c8..af583b3 100644 --- a/Shape.cpp +++ b/Shape.cpp @@ -23,34 +23,34 @@ bool Shape::includesPoint(int x, int y) { Point *prev = NULL, *cur; int left = 0, right = 0, maxy, miny; - for (std::vector::iterator it = vertices.begin() ; it != - vertices.end(); it++) + for (std::vector::iterator it = vertices.begin() ; + it != vertices.end(); it++) { if (!prev) { - prev = &vertices.back(); + prev = vertices.back(); } - cur = &(*it); - miny = std::min(cur->y, prev->y); - maxy = std::max(cur->y, prev->y); + cur = *it; + miny = std::min(cur->y(), prev->y()); + maxy = std::max(cur->y(), prev->y()); if (y > miny && y < maxy) { - if (prev->x == cur->x) + if (prev->x() == cur->x()) { - if (x < cur->x) + if (x < cur->x()) right++; else left++; } else { - double slope = (cur->y - prev->y) / (cur->x - prev->x); - double offset = cur->y - slope * cur->x; + double slope = (cur->y() - prev->y()) / (cur->x() - prev->x()); + double offset = cur->y() - slope * cur->x(); int xintersect = int((y - offset ) / slope); if (x < xintersect) right++; else left++; } } - prev = &(*it); + prev = *it; } if (right % 2 && left % 2) return true; @@ -60,18 +60,18 @@ bool Shape::includesPoint(int x, int y) void Shape::translate(int x, int y) { - for (std::vector::iterator it = vertices.begin() ; it != - vertices.end(); ++it) + for (std::vector::iterator it = vertices.begin() ; + it != vertices.end(); ++it) { - it->x += x; - it->y += y; + (*it)->setX((*it)->x() + x); + (*it)->setY((*it)->y() + y); } } -Mesh::Mesh(Point p1, Point p2, Point p3, Point p4, int nColumns, int nRows) +Mesh::Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4, int nColumns, int nRows) : Quad(p1, p2, p3, p4), _nColumns(0), _nRows(0) { Q_ASSERT(nColumns >= 2 && nRows >= 2); @@ -129,21 +129,21 @@ void Mesh::addColumn() for (int y=0; y Mesh::getQuads() const for (int j=0; j > Mesh::getQuads2d() const for (int j=0; j #include #include + /** * Point (or vertex) on the 2-D canvas. */ - Q_DECLARE_METATYPE (qreal) class Point: public QObject, public QPointF { Q_OBJECT + public: Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) Q_INVOKABLE Point(qreal x, qreal y): QPointF(x,y) {} Q_INVOKABLE Point(): QPointF(0,0) {} + signals: void xChanged(); void yChanged(); @@ -61,6 +63,11 @@ public slots: QPointF::setY(y); emit yChanged(); } + void setValue(const QPointF& p) + { + setX(p.x()); + setY(p.y()); + } }; @@ -72,7 +79,7 @@ class Shape public: typedef std::tr1::shared_ptr ptr; Shape() {} - Shape(std::vector vertices_) : + Shape(std::vector vertices_) : vertices(vertices_) {} virtual ~Shape() {} @@ -81,20 +88,20 @@ public: int nVertices() const { return vertices.size(); } - Point getVertex(int i) const + Point* getVertex(int i) const { return vertices[i]; } - void setVertex(int i, Point v) + void setVertex(int i, QPointF v) { - vertices[i] = v; + vertices[i]->setValue(v); } void setVertex(int i, double x, double y) { - vertices[i].setX(x); - vertices[i].setY(y); + vertices[i]->setX(x); + vertices[i]->setY(y); } virtual const char * getShapeType() = 0; @@ -114,7 +121,15 @@ public: } protected: - std::vector vertices; + std::vector vertices; + + void _addVertex(const QPointF& vertex) + { + Point* v = new Point(); + v->setValue(vertex); + + vertices.push_back(v); + } }; /** @@ -124,12 +139,12 @@ class Quad : public Shape { public: Quad() {} - Quad(Point p1, Point p2, Point p3, Point p4) + Quad(QPointF p1, QPointF p2, QPointF p3, QPointF p4) { - vertices.push_back(p1); - vertices.push_back(p2); - vertices.push_back(p3); - vertices.push_back(p4); + _addVertex(p1); + _addVertex(p2); + _addVertex(p3); + _addVertex(p4); } virtual ~Quad() {} @@ -143,11 +158,11 @@ class Triangle : public Shape { public: Triangle() {} - Triangle(Point p1, Point p2, Point p3) + Triangle(QPointF p1, QPointF p2, QPointF p3) { - vertices.push_back(p1); - vertices.push_back(p2); - vertices.push_back(p3); + _addVertex(p1); + _addVertex(p2); + _addVertex(p3); } virtual ~Triangle() {} virtual const char * getShapeType() { return "triangle"; } @@ -158,7 +173,7 @@ public: Mesh() : _nColumns(0), _nRows(0) { init(1, 1); } - Mesh(Point p1, Point p2, Point p3, Point p4, int nColumns=2, int nRows=2); + Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4, int nColumns=2, int nRows=2); virtual ~Mesh() {} void resizeVertices2d(std::vector< std::vector >& vertices2d, int nColumns, int nRows); diff --git a/libremapping.pro b/libremapping.pro index 3a800cf..7bd984c 100644 --- a/libremapping.pro +++ b/libremapping.pro @@ -3,6 +3,7 @@ TEMPLATE = app HEADERS = \ DestinationGLCanvas.h \ Facade.h \ + Layer.h \ MainWindow.h \ Mapper.h \ MapperGLCanvas.h \ @@ -20,6 +21,7 @@ SOURCES = \ Controller.cpp \ DestinationGLCanvas.cpp \ Facade.cpp \ + Layer.cpp \ MainWindow.cpp \ Mapper.cpp \ MapperGLCanvas.cpp \ @@ -27,6 +29,7 @@ SOURCES = \ NameAllocator.cpp \ ProjectReader.cpp \ ProjectWriter.cpp \ + Shape.cpp \ SourceGLCanvas.cpp \ Util.cpp \ main.cpp