# HG changeset patch # User Santeri Piippo # Date 1515623940 -7200 # Node ID 04af56fa8ce6c8a9ebfa8a3eddc44049a55f6c5a # Parent ecb6ea961b1ed093715e11f4e8f64e8aa7da5977 added support for circular 8/-primitives diff -r ecb6ea961b1e -r 04af56fa8ce6 src/editmodes/circleMode.cpp --- 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 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); diff -r ecb6ea961b1e -r 04af56fa8ce6 src/mainwindow.cpp --- 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(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( + "%1%2", + numerator, + denominator + )); } // --------------------------------------------------------------------------------------------------------------------- diff -r ecb6ea961b1e -r 04af56fa8ce6 src/mainwindow.h --- 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 m_objectsInList; bool m_isSelectionLocked; QMap m_defaultShortcuts; + int m_circleToolDivisions = 16; private slots: void selectionChanged(); diff -r ecb6ea961b1e -r 04af56fa8ce6 src/mainwindow.ui --- 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 @@ - 0 + 1 0 0 - 234 - 407 + 233 + 371 @@ -75,8 +75,8 @@ 0 0 - 264 - 121 + 233 + 371 @@ -91,10 +91,10 @@ - - + + - High resolution + Divisions @@ -132,6 +132,28 @@ + + + + 1 + + + + 8 + + + + + 16 + + + + + 48 + + + + @@ -157,8 +179,8 @@ 0 0 - 96 - 86 + 233 + 371 @@ -194,7 +216,7 @@ 0 0 1010 - 29 + 31 @@ -788,7 +810,7 @@ - + :/icons/add-subfile.png:/icons/add-subfile.png @@ -1713,6 +1735,7 @@ + diff -r ecb6ea961b1e -r 04af56fa8ce6 src/primitives.cpp --- 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(descr) << LDSpawn(format("Name: %1", name)) << LDSpawn(format("Author: %1", author)) - << LDSpawn(format("!LDRAW_ORG Unofficial_%1Primitive", - divs == HighResolution ? "48_" : "")) + << LDSpawn(unofficialPrimitiveType(divs)) << LDSpawn(license) << LDSpawn() << LDSpawn(BfcStatement::CertifyCCW)