diff --git a/Mapper.cpp b/Mapper.cpp index 4b4487b..89a034b 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -37,6 +37,16 @@ TextureMapper::TextureMapper(std::tr1::shared_ptr mapping) _topItem = _variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), QObject::tr("Texture mapping")); + if (std::tr1::dynamic_pointer_cast(textureMapping->getShape())) + { + Mesh* mesh = (Mesh*)textureMapping->getShape().get(); + _meshItem = _variantManager->addProperty(QVariant::Size, QObject::tr("Dimensions")); + _meshItem->setValue(QSize(mesh->nColumns(), mesh->nRows())); + _topItem->addSubProperty(_meshItem); + } + else + _meshItem = 0; + // Input shape. _inputItem = _variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), QObject::tr("Input shape")); @@ -69,6 +79,17 @@ void TextureMapper::setValue(QtProperty* property, const QVariant& value) it->second.first->setVertex(it->second.second, Point(p.x(), p.y())); qDebug() << "Changing vertex: " << it->second.second << " to " << p.x() << "," << p.y() << endl; } + else if (property == _meshItem) + { + std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(_mapping); + Q_CHECK_PTR(textureMapping); + + Mesh* outputMesh = static_cast(textureMapping->getShape().get()); + Mesh* inputMesh = static_cast(textureMapping->getInputShape().get()); + QSize size = (static_cast(property))->value().toSize(); + outputMesh->resize(size.width(), size.height()); + inputMesh->resize(size.width(), size.height()); + } emit valueChanged(); // qDebug() << "Property changed to " << property->propertyName() << " " << value.toPointF().x() << ", " << value.toPointF().y() << endl; @@ -211,9 +232,13 @@ void TextureMapper::_updateShapeProperty(QtProperty* shapeItem, Shape* shape) QList pointItems = shapeItem->subProperties(); for (int i=0; inVertices(); i++) { - QtVariantProperty* pointItem = (QtVariantProperty*)pointItems[i]; - Point p = shape->getVertex(i); - pointItem->setValue(QPointF(p.x, p.y)); + // XXX mesh control points are not added to properties + if (dynamic_cast(shape) == 0 && i < pointItems.size()) + { + QtVariantProperty* pointItem = (QtVariantProperty*)pointItems[i]; + Point p = shape->getVertex(i); + pointItem->setValue(QPointF(p.x, p.y)); + } } } diff --git a/Mapper.h b/Mapper.h index 8926c80..885e12b 100644 --- a/Mapper.h +++ b/Mapper.h @@ -147,11 +147,12 @@ private: QtProperty* _inputItem; QtProperty* _outputItem; + QtVariantProperty* _meshItem; + std::map > _propertyToVertex; void _buildShapeProperty(QtProperty* shapeItem, Shape* shape); void _updateShapeProperty(QtProperty* shapeItem, Shape* shape); }; - #endif /* MAPPER_H_ */ diff --git a/Shape.h b/Shape.h index 355f0bf..65e3436 100644 --- a/Shape.h +++ b/Shape.h @@ -116,6 +116,7 @@ public: return true; return false; } + /* Translate all vertices of shape by the vector (x,y) */ void translate(int x, int y) { @@ -319,6 +320,15 @@ public: _nRows++; } + void resize(int nColumns_, int nRows_) + { + Q_ASSERT(nColumns_ >= nColumns() && nRows_ >= nRows()); + while (nColumns_ != nColumns()) + addColumn(); + while (nRows_ != nRows()) + addRow(); + } + // void removeColumn(int columnId) // { // Q_ASSERT(columnId >= 1 && columnId < nColumns());