- circle mode can now do hi-res

Sat, 30 Aug 2014 16:08:05 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 30 Aug 2014 16:08:05 +0300
changeset 865
6d68840fcb26
parent 864
34033bc2ffb6
child 866
4951b737f8cb

- circle mode can now do hi-res

src/editmodes/circleMode.cc file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
src/mainWindow.h file | annotate | diff | comparison | revisions
src/partDownloader.cc file | annotate | diff | comparison | revisions
src/partDownloader.h file | annotate | diff | comparison | revisions
ui/ldforge.ui file | annotate | diff | comparison | revisions
--- a/src/editmodes/circleMode.cc	Sat Aug 30 14:54:10 2014 +0300
+++ b/src/editmodes/circleMode.cc	Sat Aug 30 16:08:05 2014 +0300
@@ -24,6 +24,7 @@
 #include "../ringFinder.h"
 #include "../primitives.h"
 #include "../glRenderer.h"
+#include "../mainWindow.h"
 
 CircleMode::CircleMode (GLRenderer* renderer) :
 	Super (renderer) {}
@@ -71,27 +72,28 @@
 void CircleMode::buildCircle()
 {
 	LDObjectList objs;
-	const int segs = LowResolution, divs = LowResolution; // TODO: make customizable
-	double dist0 = getCircleDrawDist (0),
-		dist1 = getCircleDrawDist (1);
+	const int segs (g_win->ringToolHiRes() ? HighResolution : LowResolution);
+	const int divs (segs); // TODO: make customizable
+	double dist0 (getCircleDrawDist (0));
+	double dist1 (getCircleDrawDist (1));
 	LDDocumentPtr refFile;
 	Matrix transform;
 	bool circleOrDisc = false;
 
 	if (dist1 < dist0)
-		std::swap<double> (dist0, dist1);
+		qSwap (dist0, dist1);
 
 	if (dist0 == dist1)
 	{
 		// If the radii are the same, there's no ring space to fill. Use a circle.
-		refFile = GetDocument ("4-4edge.dat");
+		refFile = GetDocument (MakeRadialFileName (::Circle, segs, segs, 0));
 		transform = getCircleDrawMatrix (dist0);
 		circleOrDisc = true;
 	}
 	elif (dist0 == 0 or dist1 == 0)
 	{
 		// If either radii is 0, use a disc.
-		refFile = GetDocument ("4-4disc.dat");
+		refFile = GetDocument (MakeRadialFileName (::Disc, segs, segs, 0));
 		transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1);
 		circleOrDisc = true;
 	}
@@ -102,10 +104,9 @@
 		{
 			// Get a ref file for this primitive. If we cannot find it in the
 			// LDraw library, generate it.
-			if ((refFile = ::GetDocument (MakeRadialFileName (::Ring, LowResolution, LowResolution, 
-cmp.num))) == null)
+			if ((refFile = ::GetDocument (MakeRadialFileName (::Ring, segs, segs, cmp.num))) == null)
 			{
-				refFile = GeneratePrimitive (::Ring, LowResolution, LowResolution, cmp.num);
+				refFile = GeneratePrimitive (::Ring, segs, segs, cmp.num);
 				refFile->setImplicit (false);
 			}
 
@@ -124,8 +125,8 @@
 		Axis localx, localy, localz;
 		renderer()->getRelativeAxes (localx, localy);
 		localz = (Axis) (3 - localx - localy);
-		double x0 = m_drawedVerts[0][localx],
-			y0 = m_drawedVerts[0][localy];
+		double x0 (m_drawedVerts[0][localx]);
+		double y0 (m_drawedVerts[0][localy]);
 
 		Vertex templ;
 		templ.setCoordinate (localx, x0);
@@ -181,88 +182,87 @@
 	if (m_drawedVerts.isEmpty())
 	{
 		renderer()->drawBlip (painter, renderer()->coordconv3_2 (renderer()->position3D()));
+		return;
 	}
-	else
+
+	QVector<Vertex> verts, verts2;
+	const double dist0 = getCircleDrawDist (0),
+		dist1 = (m_drawedVerts.size() >= 2) ? getCircleDrawDist (1) : -1;
+	const int segs (g_win->ringToolHiRes() ? HighResolution : LowResolution);
+	const double angleUnit = (2 * Pi) / segs;
+	Axis relX, relY;
+	QVector<QPoint> ringpoints, circlepoints, circle2points;
+
+	renderer()->getRelativeAxes (relX, relY);
+
+	// Calculate the preview positions of vertices
+	for (int i = 0; i < segs; ++i)
 	{
-		QVector<Vertex> verts, verts2;
-		const double dist0 = getCircleDrawDist (0),
-			dist1 = (m_drawedVerts.size() >= 2) ? getCircleDrawDist (1) : -1;
-		const int segs = LowResolution;
-		const double angleUnit = (2 * Pi) / segs;
-		Axis relX, relY;
-		QVector<QPoint> ringpoints, circlepoints, circle2points;
+		Vertex v (Origin);
+		v.setCoordinate (relX, m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist0));
+		v.setCoordinate (relY, m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist0));
+		verts << v;
 
-		renderer()->getRelativeAxes (relX, relY);
-
-		// Calculate the preview positions of vertices
-		for (int i = 0; i < segs; ++i)
+		if (dist1 != -1)
 		{
-			Vertex v = Origin;
-			v.setCoordinate (relX, m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist0));
-			v.setCoordinate (relY, m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist0));
-			verts << v;
-
-			if (dist1 != -1)
-			{
-				v.setCoordinate (relX, m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist1));
-				v.setCoordinate (relY, m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist1));
-				verts2 << v;
-			}
+			v.setCoordinate (relX, m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist1));
+			v.setCoordinate (relY, m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist1));
+			verts2 << v;
 		}
+	}
 
-		int i = 0;
-		for (const Vertex& v : verts + verts2)
-		{
-			// Calculate the 2D point of the vertex
-			QPoint point = renderer()->coordconv3_2 (v);
+	int i = 0;
+	for (const Vertex& v : verts + verts2)
+	{
+		// Calculate the 2D point of the vertex
+		QPoint point (renderer()->coordconv3_2 (v));
 
-			// Draw a green blip at where it is
-			renderer()->drawBlip (painter, point);
+		// Draw a green blip at where it is
+		renderer()->drawBlip (painter, point);
 
-			// Add it to the list of points for the green ring fill.
-			ringpoints << point;
+		// Add it to the list of points for the green ring fill.
+		ringpoints << point;
 
-			// Also add the circle points to separate lists
-			if (i < verts.size())
-				circlepoints << point;
-			else
-				circle2points << point;
+		// Also add the circle points to separate lists
+		if (i < verts.size())
+			circlepoints << point;
+		else
+			circle2points << point;
 
-			++i;
-		}
+		++i;
+	}
 
-		// Insert the first point as the seventeenth one so that
-		// the ring polygon is closed properly.
-		if (ringpoints.size() >= 16)
-			ringpoints.insert (16, ringpoints[0]);
+	// Insert the first point as the seventeenth one so that
+	// the ring polygon is closed properly.
+	if (ringpoints.size() >= segs)
+		ringpoints.insert (segs, ringpoints[0]);
 
-		// Same for the outer ring. Note that the indices are offset by 1
-		// because of the insertion done above bumps the values.
-		if (ringpoints.size() >= 33)
-			ringpoints.insert (33, ringpoints[17]);
+	// Same for the outer ring. Note that the indices are offset by 1
+	// because of the insertion done above bumps the values.
+	if (ringpoints.size() >= segs * 2 + 1)
+		ringpoints.insert (segs * 2 + 1, ringpoints[segs + 1]);
 
-		// Draw the ring
-		painter.setBrush ((m_drawedVerts.size() >= 2) ? m_polybrush : Qt::NoBrush);
-		painter.setPen (Qt::NoPen);
-		painter.drawPolygon (QPolygon (ringpoints));
+	// Draw the ring
+	painter.setBrush ((m_drawedVerts.size() >= 2) ? m_polybrush : Qt::NoBrush);
+	painter.setPen (Qt::NoPen);
+	painter.drawPolygon (QPolygon (ringpoints));
 
-		// Draw the circles
-		painter.setBrush (Qt::NoBrush);
-		painter.setPen (renderer()->linePen());
-		painter.drawPolygon (QPolygon (circlepoints));
-		painter.drawPolygon (QPolygon (circle2points));
+	// Draw the circles
+	painter.setBrush (Qt::NoBrush);
+	painter.setPen (renderer()->linePen());
+	painter.drawPolygon (QPolygon (circlepoints));
+	painter.drawPolygon (QPolygon (circle2points));
 
-		// Draw the current radius in the middle of the circle.
-		QPoint origin = renderer()->coordconv3_2 (m_drawedVerts[0]);
-		QString label = QString::number (dist0);
-		painter.setPen (renderer()->textPen());
-		painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label);
+	// Draw the current radius in the middle of the circle.
+	QPoint origin = renderer()->coordconv3_2 (m_drawedVerts[0]);
+	QString label = QString::number (dist0);
+	painter.setPen (renderer()->textPen());
+	painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label);
 
-		if (m_drawedVerts.size() >= 2)
-		{
-			painter.drawText (origin.x() - (metrics.width (label) / 2),
-				origin.y() + metrics.height(), QString::number (dist1));
-		}
+	if (m_drawedVerts.size() >= 2)
+	{
+		painter.drawText (origin.x() - (metrics.width (label) / 2),
+			origin.y() + metrics.height(), QString::number (dist1));
 	}
 }
 
--- a/src/mainWindow.cc	Sat Aug 30 14:54:10 2014 +0300
+++ b/src/mainWindow.cc	Sat Aug 30 16:08:05 2014 +0300
@@ -1056,6 +1056,20 @@
 
 // =============================================================================
 //
+bool MainWindow::ringToolHiRes() const
+{
+    return ui->ringToolHiRes->isChecked();
+}
+
+// =============================================================================
+//
+int MainWindow::ringToolSegments() const
+{
+    return ui->ringToolSegments->value();
+}
+
+// =============================================================================
+//
 QImage GetImageFromScreencap (uchar* data, int w, int h)
 {
 	// GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well.
--- a/src/mainWindow.h	Sat Aug 30 14:54:10 2014 +0300
+++ b/src/mainWindow.h	Sat Aug 30 16:08:05 2014 +0300
@@ -172,6 +172,9 @@
 	void saveShortcuts (QSettings* settings);
 	void applyToActions (std::function<void(QAction*)> function);
 
+    bool ringToolHiRes() const;
+    int ringToolSegments() const;
+
 public slots:
 	void updatePrimitives();
 	void changeCurrentFile();
--- a/src/partDownloader.cc	Sat Aug 30 14:54:10 2014 +0300
+++ b/src/partDownloader.cc	Sat Aug 30 16:08:05 2014 +0300
@@ -276,7 +276,7 @@
 		if (not req->isFinished())
 			return;
 
-		if (req->state() == DLRQ_Failed)
+        if (req->state() == PartDownloadRequest::State::Failed)
 			failed = true;
 	}
 
@@ -330,7 +330,7 @@
 //
 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) :
 	QObject (parent),
-	m_state (DLRQ_Requesting),
+    m_state (State::Requesting),
 	m_prompt (parent),
 	m_url (url),
 	m_destinaton (dest),
@@ -375,8 +375,8 @@
 
 	switch (state())
 	{
-		case DLRQ_Requesting:
-		case DLRQ_Downloading:
+        case State::Requesting:
+        case State::Downloading:
 		{
 			prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol));
 
@@ -390,10 +390,10 @@
 			prog->setValue (numBytesRead());
 		} break;
 
-		case DLRQ_Finished:
-		case DLRQ_Failed:
+        case State::Finished:
+        case State::Failed:
 		{
-			const QString text = (state() == DLRQ_Finished)
+            const QString text = (state() == State::Finished)
 				? "<b><span style=\"color: #080\">FINISHED</span></b>"
 				: "<b><span style=\"color: #800\">FAILED</span></b>";
 
@@ -427,10 +427,10 @@
 		if (isPrimary() and not prompt()->isAborted())
 			CriticalError (networkReply()->errorString());
 
-		setState (DLRQ_Failed);
+        setState (State::Failed);
 	}
-	elif (state() != DLRQ_Failed)
-		setState (DLRQ_Finished);
+    elif (state() != State::Failed)
+        setState (State::Finished);
 
 	setNumBytesRead (numBytesTotal());
 	updateToTable();
@@ -441,11 +441,11 @@
 		delete filePointer();
 		setFilePointer (null);
 
-		if (state() == DLRQ_Failed)
+        if (state() == State::Failed)
 			QFile::remove (filePath());
 	}
 
-	if (state() != DLRQ_Finished)
+    if (state() != State::Finished)
 	{
 		prompt()->checkIfFinished();
 		return;
@@ -488,7 +488,7 @@
 {
 	setNumBytesRead (recv);
 	setNumBytesTotal (total);
-	setState (DLRQ_Downloading);
+    setState (State::Downloading);
 	updateToTable();
 }
 
@@ -496,7 +496,7 @@
 //
 void PartDownloadRequest::readyRead()
 {
-	if (state() == DLRQ_Failed)
+    if (state() == State::Failed)
 		return;
 
 	if (filePointer() == null)
@@ -510,7 +510,7 @@
 		if (not filePointer()->open (QIODevice::WriteOnly))
 		{
 			CriticalError (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno)));
-			setState (DLRQ_Failed);
+            setState (State::Failed);
 			networkReply()->abort();
 			updateToTable();
 			prompt()->checkIfFinished();
@@ -525,7 +525,7 @@
 //
 bool PartDownloadRequest::isFinished() const
 {
-	return Eq (state(), DLRQ_Finished, DLRQ_Failed);
+    return Eq (state(), State::Finished, State::Failed);
 }
 
 // =============================================================================
--- a/src/partDownloader.h	Sat Aug 30 14:54:10 2014 +0300
+++ b/src/partDownloader.h	Sat Aug 30 16:08:05 2014 +0300
@@ -86,20 +86,20 @@
 
 // =============================================================================
 //
-enum PartDownloadRequestState
-{
-	DLRQ_Requesting,
-	DLRQ_Downloading,
-	DLRQ_Finished,
-	DLRQ_Failed,
-};
-
 class PartDownloadRequest : public QObject
 {
 public:
+    enum class State
+    {
+        Requesting,
+        Downloading,
+        Finished,
+        Failed,
+    };
+
 	Q_OBJECT
 	PROPERTY (public,	int,						tableRow,		setTableRow,		STOCK_WRITE)
-	PROPERTY (private,	PartDownloadRequestState,	state,			setState,			STOCK_WRITE)
+    PROPERTY (private,	State,                      state,			setState,			STOCK_WRITE)
 	PROPERTY (private,	PartDownloader*,			prompt,			setPrompt,			STOCK_WRITE)
 	PROPERTY (private,	QString,					url,			setURL,				STOCK_WRITE)
 	PROPERTY (private,	QString,					destinaton,		setDestination,		STOCK_WRITE)
--- a/ui/ldforge.ui	Sat Aug 30 14:54:10 2014 +0300
+++ b/ui/ldforge.ui	Sat Aug 30 16:08:05 2014 +0300
@@ -47,8 +47,8 @@
           <rect>
            <x>0</x>
            <y>0</y>
-           <width>233</width>
-           <height>426</height>
+           <width>237</width>
+           <height>414</height>
           </rect>
          </property>
          <attribute name="label">
@@ -70,13 +70,84 @@
           </item>
          </layout>
         </widget>
+        <widget class="QWidget" name="pageEditModeOptions">
+         <property name="geometry">
+          <rect>
+           <x>0</x>
+           <y>0</y>
+           <width>237</width>
+           <height>414</height>
+          </rect>
+         </property>
+         <attribute name="label">
+          <string>Edit Mode Options</string>
+         </attribute>
+         <layout class="QVBoxLayout" name="verticalLayout_4">
+          <item>
+           <widget class="QGroupBox" name="groupBox">
+            <property name="title">
+             <string>Ring Options</string>
+            </property>
+            <layout class="QVBoxLayout" name="verticalLayout_5">
+             <item>
+              <layout class="QFormLayout" name="formLayout">
+               <item row="0" column="1">
+                <widget class="QCheckBox" name="ringToolHiRes">
+                 <property name="text">
+                  <string>High resolution</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="1" column="0">
+                <widget class="QLabel" name="label">
+                 <property name="text">
+                  <string>Segments:</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="1" column="1">
+                <widget class="QSpinBox" name="ringToolSegments">
+                 <property name="enabled">
+                  <bool>false</bool>
+                 </property>
+                 <property name="minimum">
+                  <number>1</number>
+                 </property>
+                 <property name="maximum">
+                  <number>16</number>
+                 </property>
+                 <property name="value">
+                  <number>16</number>
+                 </property>
+                </widget>
+               </item>
+              </layout>
+             </item>
+            </layout>
+           </widget>
+          </item>
+          <item>
+           <spacer name="verticalSpacer">
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>20</width>
+              <height>40</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </widget>
         <widget class="QWidget" name="pagePrimitives">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>0</y>
-           <width>99</width>
-           <height>99</height>
+           <width>94</width>
+           <height>94</height>
           </rect>
          </property>
          <attribute name="label">
@@ -112,7 +183,7 @@
      <x>0</x>
      <y>0</y>
      <width>1010</width>
-     <height>28</height>
+     <height>26</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuFile">

mercurial