Thu, 11 Jan 2018 00:39:00 +0200
added support for circular 8/-primitives
src/editmodes/circleMode.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.ui | file | annotate | diff | comparison | revisions | |
src/primitives.cpp | file | annotate | diff | comparison | revisions |
--- a/src/editmodes/circleMode.cpp Wed Jan 10 23:07:01 2018 +0200 +++ b/src/editmodes/circleMode.cpp Thu Jan 11 00:39:00 2018 +0200 @@ -77,8 +77,8 @@ void CircleMode::buildCircle() { LDObjectList objs; - const int segments(m_window->ringToolSegments()); - const int divisions(m_window->ringToolHiRes() ? HighResolution : LowResolution); + const int segments = m_window->ringToolSegments(); + const int divisions = m_window->ringToolDivisions(); double dist0(getCircleDrawDist(0)); double dist1(getCircleDrawDist(1)); LDDocument* refFile; @@ -186,7 +186,7 @@ if (m_drawedVerts.isEmpty()) return 0.0; - const int divisions(m_window->ringToolHiRes() ? HighResolution : LowResolution); + const int divisions = m_window->ringToolDivisions(); QPointF originspot(renderer()->convert3dTo2d(m_drawedVerts.first())); QLineF bearing(originspot, renderer()->mousePositionF()); QLineF bearing2(originspot, QPointF(originspot.x(), 0.0)); @@ -215,8 +215,8 @@ QVector<QPointF> innerverts2d, outerverts2d; const double innerdistance(getCircleDrawDist(0)); const double outerdistance(m_drawedVerts.size() >= 2 ? getCircleDrawDist(1) : -1); - const int divisions(m_window->ringToolHiRes() ? HighResolution : LowResolution); - const int segments(m_window->ringToolSegments()); + const int divisions = m_window->ringToolDivisions(); + const int segments = m_window->ringToolSegments(); const double angleUnit(2 * Pi / divisions); Axis relX, relY; renderer()->getRelativeAxes(relX, relY);
--- a/src/mainwindow.cpp Wed Jan 10 23:07:01 2018 +0200 +++ b/src/mainwindow.cpp Thu Jan 11 00:39:00 2018 +0200 @@ -118,9 +118,15 @@ loadShortcuts(); setMinimumSize(300, 200); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(doLastSecondCleanup())); - connect(ui.ringToolHiRes, SIGNAL(clicked(bool)), this, SLOT(ringToolHiResClicked(bool))); - connect(ui.ringToolSegments, SIGNAL(valueChanged(int)), - this, SLOT(circleToolSegmentsChanged())); + connect( + ui.ringToolSegments, SIGNAL(valueChanged(int)), + this, SLOT(circleToolSegmentsChanged()) + ); + connect( + ui.ringToolDivisions, SIGNAL(currentIndexChanged(int)), + this, SLOT(circleToolDivisionsChanged()) + ); + circleToolSegmentsChanged(); // invoke it manually for initial label text // Examine the toolsets and make a dictionary of tools @@ -1143,9 +1149,9 @@ // --------------------------------------------------------------------------------------------------------------------- // -bool MainWindow::ringToolHiRes() const +int MainWindow::ringToolDivisions() const { - return ui.ringToolHiRes->isChecked(); + return m_circleToolDivisions; } // --------------------------------------------------------------------------------------------------------------------- @@ -1155,30 +1161,28 @@ return ui.ringToolSegments->value(); } -// --------------------------------------------------------------------------------------------------------------------- -// -void MainWindow::ringToolHiResClicked(bool checked) +void MainWindow::circleToolDivisionsChanged() { - if (checked) - { - ui.ringToolSegments->setMaximum(HighResolution); - ui.ringToolSegments->setValue(ui.ringToolSegments->value() * 3); - } - else - { - ui.ringToolSegments->setValue(ui.ringToolSegments->value() / 3); - ui.ringToolSegments->setMaximum(LowResolution); - } + int newDivisions = ui.ringToolDivisions->currentText().toInt(); + float ratio = float(newDivisions) / m_circleToolDivisions; + int newSegments = static_cast<int>(round(ringToolSegments() * ratio)); + m_circleToolDivisions = newDivisions; + ui.ringToolSegments->setMaximum(newDivisions); + ui.ringToolSegments->setValue(newSegments); } // --------------------------------------------------------------------------------------------------------------------- // void MainWindow::circleToolSegmentsChanged() { - int numerator(ui.ringToolSegments->value()); - int denominator(ui.ringToolHiRes->isChecked() ? HighResolution : LowResolution); + int numerator = ui.ringToolSegments->value(); + int denominator = ringToolDivisions(); Simplify(numerator, denominator); - ui.ringToolSegmentsLabel->setText(format("%1 / %2", numerator, denominator)); + ui.ringToolSegmentsLabel->setText(format( + "<sup>%1</sup>∕<sub>%2</sub>", + numerator, + denominator + )); } // ---------------------------------------------------------------------------------------------------------------------
--- a/src/mainwindow.h Wed Jan 10 23:07:01 2018 +0200 +++ b/src/mainwindow.h Thu Jan 11 00:39:00 2018 +0200 @@ -98,7 +98,7 @@ GLRenderer* renderer(); void refresh(); void refreshObjectList(); - bool ringToolHiRes() const; + int ringToolDivisions() const; int ringToolSegments() const; bool save(LDDocument* doc, bool saveAs); void saveShortcuts(); @@ -120,10 +120,10 @@ public slots: void actionTriggered(); + void circleToolDivisionsChanged(); void circleToolSegmentsChanged(); void closeTab(int tabindex); void historyTraversed(); - void ringToolHiResClicked(bool clicked); void tabSelected(); void updatePrimitives(); @@ -151,6 +151,7 @@ DoubleMap<LDObject*, QListWidgetItem*> m_objectsInList; bool m_isSelectionLocked; QMap<QAction*, QKeySequence> m_defaultShortcuts; + int m_circleToolDivisions = 16; private slots: void selectionChanged();
--- a/src/mainwindow.ui Wed Jan 10 23:07:01 2018 +0200 +++ b/src/mainwindow.ui Thu Jan 11 00:39:00 2018 +0200 @@ -40,15 +40,15 @@ <item> <widget class="QToolBox" name="toolBox"> <property name="currentIndex"> - <number>0</number> + <number>1</number> </property> <widget class="QWidget" name="pageDocument"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>234</width> - <height>407</height> + <width>233</width> + <height>371</height> </rect> </property> <attribute name="label"> @@ -75,8 +75,8 @@ <rect> <x>0</x> <y>0</y> - <width>264</width> - <height>121</height> + <width>233</width> + <height>371</height> </rect> </property> <attribute name="label"> @@ -91,10 +91,10 @@ <layout class="QVBoxLayout" name="verticalLayout_5"> <item> <layout class="QFormLayout" name="formLayout"> - <item row="0" column="1"> - <widget class="QCheckBox" name="ringToolHiRes"> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> <property name="text"> - <string>High resolution</string> + <string>Divisions</string> </property> </widget> </item> @@ -132,6 +132,28 @@ </item> </layout> </item> + <item row="0" column="1"> + <widget class="QComboBox" name="ringToolDivisions"> + <property name="currentIndex"> + <number>1</number> + </property> + <item> + <property name="text"> + <string>8</string> + </property> + </item> + <item> + <property name="text"> + <string>16</string> + </property> + </item> + <item> + <property name="text"> + <string>48</string> + </property> + </item> + </widget> + </item> </layout> </item> </layout> @@ -157,8 +179,8 @@ <rect> <x>0</x> <y>0</y> - <width>96</width> - <height>86</height> + <width>233</width> + <height>371</height> </rect> </property> <attribute name="label"> @@ -194,7 +216,7 @@ <x>0</x> <y>0</y> <width>1010</width> - <height>29</height> + <height>31</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -788,7 +810,7 @@ </action> <action name="actionNewSubfile"> <property name="icon"> - <iconset resource="../ldforge.qrc"> + <iconset> <normaloff>:/icons/add-subfile.png</normaloff>:/icons/add-subfile.png</iconset> </property> <property name="text"> @@ -1713,6 +1735,7 @@ </widget> <resources> <include location="../ldforge.qrc"/> + <include location="../ldforge.qrc"/> </resources> <connections/> </ui>
--- a/src/primitives.cpp Wed Jan 10 23:07:01 2018 +0200 +++ b/src/primitives.cpp Thu Jan 11 00:39:00 2018 +0200 @@ -591,6 +591,16 @@ return prefix + frac + root + numstr + ".dat"; } +const char* unofficialPrimitiveType(int divisions) +{ + if (divisions == 48) + return "!LDRAW_ORG Unofficial_48_Primitive"; + else if (divisions == 8) + return "!LDRAW_ORG Unofficial_8_Primitive"; + else + return "!LDRAW_ORG Unofficial_Primitive"; +} + // ============================================================================= // LDDocument* GeneratePrimitive(PrimitiveType type, int segs, int divs, int num) @@ -636,8 +646,7 @@ objs << LDSpawn<LDComment>(descr) << LDSpawn<LDComment>(format("Name: %1", name)) << LDSpawn<LDComment>(format("Author: %1", author)) - << LDSpawn<LDComment>(format("!LDRAW_ORG Unofficial_%1Primitive", - divs == HighResolution ? "48_" : "")) + << LDSpawn<LDComment>(unofficialPrimitiveType(divs)) << LDSpawn<LDComment>(license) << LDSpawn<LDEmpty>() << LDSpawn<LDBfc>(BfcStatement::CertifyCCW)