src/dialogs/generateprimitivedialog.cpp

Fri, 22 Jun 2018 15:03:50 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 22 Jun 2018 15:03:50 +0300
changeset 1424
737df8e904af
parent 1339
1f342d5abc85
permissions
-rw-r--r--

removed a duplicate member

1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
1 /*
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1147
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
1020
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
4 *
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
5 * This program is free software: you can redistribute it and/or modify
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
6 * it under the terms of the GNU General Public License as published by
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
8 * (at your option) any later version.
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
9 *
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
10 * This program is distributed in the hope that it will be useful,
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
13 * GNU General Public License for more details.
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
14 *
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
15 * You should have received a copy of the GNU General Public License
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
17 */
815a040d4039 Reformatted primitives.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1019
diff changeset
18
1147
a26568aa3cce Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
19 #include "../linetypes/modelobject.h"
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "generateprimitivedialog.h"
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include "ui_generateprimitivedialog.h"
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 GeneratePrimitiveDialog::GeneratePrimitiveDialog (QWidget* parent, Qt::WindowFlags f) :
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 QDialog (parent, f),
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 ui(*new Ui_GeneratePrimitiveDialog)
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 {
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 ui.setupUi (this);
1339
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
28 this->previousDivisions = ui.divisions->currentText().toInt();
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
29 connect(
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
30 ui.divisions,
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
31 &QComboBox::currentTextChanged,
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
32 [&]()
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
33 {
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
34 int divisions = ui.divisions->currentText().toInt();
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
35
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
36 // Scale the segments value to fit.
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
37 int newSegments = static_cast<int>(round(
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
38 ui.segments->value() * double(divisions) / this->previousDivisions
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
39 ));
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
40
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
41 ui.segments->setMaximum(divisions);
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
42 ui.segments->setValue(newSegments);
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
43 this->previousDivisions = divisions;
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
44 }
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
45 );
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 }
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 GeneratePrimitiveDialog::~GeneratePrimitiveDialog()
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 {
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 delete &ui;
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 }
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
55 PrimitiveModel GeneratePrimitiveDialog::primitiveModel() const
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 {
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
57 PrimitiveModel result;
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 result.type =
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
59 ui.typeCircle->isChecked() ? PrimitiveModel::Circle :
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
60 ui.typeCylinder->isChecked() ? PrimitiveModel::Cylinder :
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
61 ui.typeDisc->isChecked() ? PrimitiveModel::Disc :
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
62 ui.typeDiscNegative->isChecked() ? PrimitiveModel::DiscNegative :
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
63 ui.typeRing->isChecked() ? PrimitiveModel::Ring :
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
64 PrimitiveModel::Cone;
1339
1f342d5abc85 Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
65 result.divisions = ui.divisions->currentText().toInt();
1019
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 result.segments = ui.segments->value();
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 result.ringNumber = ui.ringNumber->value();
a2e4286adb0d Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 return result;
1053
2a48c0fff107 Refactor primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1020
diff changeset
69 }

mercurial