git-svn-id: svn://db.shs.com.ru/libs@660 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,14 +1,52 @@
|
||||
#include "primitiveeditor.h"
|
||||
#include "ui_primitiveeditor.h"
|
||||
#include <QMetaEnum>
|
||||
#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<QWidget *> all;
|
||||
QMetaEnum me = metaObject()->enumerator(0);
|
||||
for (int i=0; i<me.keyCount(); ++i)
|
||||
for (int i=0; i<me.keyCount(); ++i) {
|
||||
ui->comboPrimitives->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<QWidget *> 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user