diff --git a/qglengine/qglview_test/qglview_window.cpp b/qglengine/qglview_test/qglview_window.cpp index 784e23e..0829c30 100644 --- a/qglengine/qglview_test/qglview_window.cpp +++ b/qglengine/qglview_test/qglview_window.cpp @@ -88,6 +88,7 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView sceneTree->assignQGLView(view->view()); matEditor->assignQGLView(view->view()); objectEditor->assignQGLView(view->view()); + primitiveEditor->assignQGLView(view->view()); session.load(); diff --git a/qglengine/widgets/primitiveeditor.cpp b/qglengine/widgets/primitiveeditor.cpp index 84b815a..402d413 100644 --- a/qglengine/widgets/primitiveeditor.cpp +++ b/qglengine/widgets/primitiveeditor.cpp @@ -1,14 +1,52 @@ #include "primitiveeditor.h" #include "ui_primitiveeditor.h" #include +#include "glprimitives.h" +#include "glmesh.h" PrimitiveEditor::PrimitiveEditor(QWidget *parent) : QWidget(parent), ui(new Ui::PrimitiveEditor) { + view = 0; ui->setupUi(this); + editors[Plane] << ui->widgetWidth; + editors[Plane] << ui->widgetLength; + editors[Cube] << ui->widgetWidth; + editors[Cube] << ui->widgetLength; + editors[Cube] << ui->widgetHeight; + editors[Ellipsoid] << ui->widgetWidth; + editors[Ellipsoid] << ui->widgetLength; + editors[Ellipsoid] << ui->widgetHeight; + editors[Ellipsoid] << ui->widgetSegments; + editors[Ellipsoid] << ui->widgetSegments2; + editors[Disc] << ui->widgetWidth; + editors[Disc] << ui->widgetLength; + editors[Disc] << ui->widgetSegments; + editors[Disc] << ui->widgetAngle; + editors[Cone] << ui->widgetWidth; + editors[Cone] << ui->widgetLength; + editors[Cone] << ui->widgetHeight; + editors[Cone] << ui->widgetSegments; + editors[Cylinder] << ui->widgetWidth; + editors[Cylinder] << ui->widgetLength; + editors[Cylinder] << ui->widgetHeight; + editors[Cylinder] << ui->widgetSegments; + editors[Torus] << ui->widgetRadius1; + editors[Torus] << ui->widgetRadius2; + editors[Torus] << ui->widgetSegments; + editors[Torus] << ui->widgetSegments2; + editors[Torus] << ui->widgetAngle; + QSet all; QMetaEnum me = metaObject()->enumerator(0); - for (int i=0; icomboPrimitives->addItem(me.key(i)); + all.unite(editors[(PrimitiveType)me.value(i)].toSet()); + } + all_editors = all.toList(); + foreach (QWidget * w, all_editors) { + if (w->layout()) w->layout()->setContentsMargins(0, layout()->spacing(), 0, 0); + } + ui->comboPrimitives->setCurrentIndex(Plane); } @@ -22,9 +60,78 @@ void PrimitiveEditor::assignQGLView(QGLView * v) { // connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); // connect(view, SIGNAL(objectsPositionChanged()), this, SLOT(selectionChanged())); // connect(view->scene(), SIGNAL(treeChanged()), this, SLOT(selectionChanged())); - // selectionChanged(); +// selectionChanged(); } void PrimitiveEditor::showEditors() { + foreach (QWidget * w, all_editors) w->hide(); + PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex(); + QList wds = editors[pt]; + foreach (QWidget * w, wds) w->show(); +} + + +void PrimitiveEditor::on_buttonAdd_clicked() { + if (!view) return; + Mesh * m = 0; + PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex(); + switch (pt) { + case Plane: + m = Primitive::plane(ui->spinWidth->value(), + ui->spinLength->value()); + break; + case Cube: + m = Primitive::cube(ui->spinWidth->value(), + ui->spinLength->value(), + ui->spinHeight->value()); + break; + case Ellipsoid: + m = Primitive::ellipsoid(ui->spinSegments->value(), + ui->spinSegments2->value(), + ui->spinWidth->value(), + ui->spinLength->value(), + ui->spinHeight->value()); + break; + case Disc: + m = Primitive::disc(ui->spinSegments->value(), + ui->spinWidth->value(), + ui->spinLength->value(), + true, + ui->spinAngle->value()); + break; + case Cone: + m = Primitive::cone(ui->spinSegments->value(), + ui->spinWidth->value(), + ui->spinLength->value(), + ui->spinHeight->value()); + break; + case Cylinder: + m = Primitive::cylinder(ui->spinSegments->value(), + ui->spinWidth->value(), + ui->spinLength->value(), + ui->spinHeight->value()); + break; + case Torus: + m = Primitive::torus(ui->spinSegments->value(), + ui->spinSegments2->value(), + ui->spinRadius->value(), + ui->spinRadius2->value(), + ui->spinAngle->value()); + break; + } + if (m) { + if (ui->flipNormals->isChecked()) m->flipNormals(); + ObjectBase * o = new ObjectBase(m); + o->setColor(ui->colorButton->color()); + o->setName(ui->comboPrimitives->currentText()); + view->scene()->addObject(o); + view->scene()->selectObject(o); + delete m; + } +} + + +void PrimitiveEditor::on_comboPrimitives_currentIndexChanged(int index) { + showEditors(); } diff --git a/qglengine/widgets/primitiveeditor.h b/qglengine/widgets/primitiveeditor.h index 437cf0d..0d18570 100644 --- a/qglengine/widgets/primitiveeditor.h +++ b/qglengine/widgets/primitiveeditor.h @@ -17,6 +17,10 @@ public: Plane, Cube, Ellipsoid, + Disc, + Cone, + Cylinder, + Torus }; Q_ENUMS(PrimitiveType) @@ -33,7 +37,11 @@ protected: Ui::PrimitiveEditor *ui; QGLView * view; QMap > editors; + QList all_editors; +private slots: + void on_buttonAdd_clicked(); + void on_comboPrimitives_currentIndexChanged(int index); }; diff --git a/qglengine/widgets/primitiveeditor.ui b/qglengine/widgets/primitiveeditor.ui index 994f6b3..eff9f93 100644 --- a/qglengine/widgets/primitiveeditor.ui +++ b/qglengine/widgets/primitiveeditor.ui @@ -6,23 +6,41 @@ 0 0 - 575 - 608 + 360 + 536 Form - + + + 0 + + + 0 + + + 0 + + + 0 + - - + + + + 0 + 0 + + 0 + 0 @@ -30,262 +48,310 @@ 0 - - - Width: - + + + + 0 + + + 0 + + + 0 + + + + + Width: + + + + + + + 1.000000000000000 + + + + - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Length: - + + + + 0 + + + 0 + + + 0 + + + + + Length: + + + + + + + 1.000000000000000 + + + + - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Height - + + + + 0 + + + 0 + + + 0 + + + + + Height + + + + + + + 1.000000000000000 + + + + - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Radius 1: - + + + + 0 + + + 0 + + + 0 + + + + + Radius 1: + + + + + + + 1.000000000000000 + + + + - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Radius 2: - + + + + 0 + + + 0 + + + 0 + + + + + Radius 2: + + + + + + + 1.000000000000000 + + + + - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Angle: - + + + + 0 + + + 0 + + + 0 + + + + + Angle: + + + + + + + 360.000000000000000 + + + 360.000000000000000 + + + 4.500000000000000 + + + 90.000000000000000 + + + ° + + + QSlider::TicksAbove + + + 90 + + + + - - - 360.000000000000000 - - - 360.000000000000000 - - - 4.500000000000000 - - - 90.000000000000000 - - - ° - - - QSlider::TicksAbove - - - 90 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Segments: - + + + + 0 + + + 0 + + + 0 + + + + + Segments: + + + + + + + 1 + + + 1000 + + + 1 + + + QAbstractSpinBox::AdaptiveDecimalStepType + + + 16 + + + + - - - 2 - - - 1000 - - - 1 - - - QAbstractSpinBox::AdaptiveDecimalStepType - - - 16 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Segments 2: - + + + + 0 + + + 0 + + + 0 + + + + + Segments 2: + + + + + + + 1 + + + 1000 + + + 1 + + + QAbstractSpinBox::AdaptiveDecimalStepType + + + 16 + + + + - - - 2 - - - 1000 - - - 1 - - - QAbstractSpinBox::AdaptiveDecimalStepType - - - 16 - + + + + 0 + + + 0 + + + 0 + + + + + Color: + + + + + + + + 255 + 255 + 255 + + + + + @@ -306,7 +372,7 @@ 20 - 220 + 176 @@ -356,6 +422,11 @@ QWidget
spinslider.h
+ + ColorButton + QPushButton +
colorbutton.h
+
EComboBox QComboBox