Added triangle count to viewport, added compile-time line length check

Sat, 13 Feb 2016 04:06:49 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 13 Feb 2016 04:06:49 +0200
changeset 1015
92c6ec099075
parent 1014
f0a8ecb6a357
child 1016
3b279b5e57d3

Added triangle count to viewport, added compile-time line length check

CMakeLists.txt file | annotate | diff | comparison | revisions
changelog.txt file | annotate | diff | comparison | revisions
src/basics.h file | annotate | diff | comparison | revisions
src/glRenderer.cpp file | annotate | diff | comparison | revisions
src/ldDocument.cpp file | annotate | diff | comparison | revisions
src/ldDocument.h file | annotate | diff | comparison | revisions
src/ldObject.cpp file | annotate | diff | comparison | revisions
src/ldObject.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Fri Jan 01 23:41:55 2016 +0200
+++ b/CMakeLists.txt	Sat Feb 13 04:06:49 2016 +0200
@@ -226,5 +226,12 @@
 		${LDFORGE_SOURCES}
 	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
 
+add_custom_target(lengthcheck ALL
+	COMMAND python
+		"${CMAKE_SOURCE_DIR}/tools/linelength.py"
+		${LDFORGE_SOURCES}
+		${LDFORGE_HEADERS}
+	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+
 add_dependencies (ldforge revision_check config_collection)
 install (TARGETS ldforge RUNTIME DESTINATION bin)
--- a/changelog.txt	Fri Jan 01 23:41:55 2016 +0200
+++ b/changelog.txt	Sat Feb 13 04:06:49 2016 +0200
@@ -6,6 +6,7 @@
 
 
 +	- Pressing Ctrl while drawing now causes the new line to become locked to cardinal directions, ala Gimp.
++	- Added triangle count display to the lower left corner of the viewport.
 -	- Selecting an invertnext'd object no longer selects the invertnext (reverted feature from 0.3, caused too many problems).
 
 
--- a/src/basics.h	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/basics.h	Sat Feb 13 04:06:49 2016 +0200
@@ -234,3 +234,8 @@
 {
 	return false;
 }
+
+inline void toggle (bool& a)
+{
+	a = not a;
+}
--- a/src/glRenderer.cpp	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/glRenderer.cpp	Sat Feb 13 04:06:49 2016 +0200
@@ -690,7 +690,13 @@
 		{
 			const int margin = 4;
 			painter.setPen (textPen());
-			painter.drawText (QPoint (margin, height() - (margin + metrics.descent())), currentCameraName());
+			painter.drawText (QPoint (margin, height() - margin - metrics.descent()), currentCameraName());
+
+			if (m_document)
+			{
+				painter.drawText(QPoint(margin, height() - margin - metrics.height() - metrics.descent()),
+					format("△ %1", m_document->triangleCount()));
+			}
 		}
 
 		// Tool tips
--- a/src/ldDocument.cpp	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/ldDocument.cpp	Sat Feb 13 04:06:49 2016 +0200
@@ -41,14 +41,14 @@
 	m_isCache (true),
 	m_verticesOutdated (true),
 	m_needVertexMerge (true),
+	m_needsReCache(true),
 	m_beingDestroyed (false),
+	m_needRecount(false),
+	m_savePosition(-1),
+	m_tabIndex(-1),
+	m_triangleCount(0),
 	m_gldata (new LDGLData),
-	m_manager (parent)
-{
-	setSavePosition (-1);
-	setTabIndex (-1);
-	m_needsReCache = true;
-}
+	m_manager (parent) {}
 
 LDDocument::~LDDocument()
 {
@@ -126,6 +126,21 @@
 	m_defaultName = value;
 }
 
+int LDDocument::triangleCount()
+{
+	if (m_needRecount)
+	{
+		m_triangleCount = 0;
+
+		for (LDObject* obj : m_objects)
+			m_triangleCount += obj->triangleCount();
+
+		m_needRecount = false;
+	}
+
+	return m_triangleCount;
+}
+
 void LDDocument::openForEditing()
 {
 	if (m_isCache)
@@ -599,6 +614,7 @@
 	m_objects << obj;
 	addKnownVertices (obj);
 	obj->setDocument (this);
+	m_needRecount = true;
 	m_window->renderer()->compileObject (obj);
 	return getObjectCount() - 1;
 }
@@ -621,6 +637,7 @@
 	history()->add (new AddHistoryEntry (pos, obj));
 	m_objects.insert (pos, obj);
 	obj->setDocument (this);
+	m_needRecount = true;
 	m_window->renderer()->compileObject (obj);
 	
 
@@ -662,6 +679,7 @@
 		}
 
 		m_objects.removeAt (idx);
+		m_needRecount = true;
 		obj->setDocument (nullptr);
 	}
 }
@@ -909,4 +927,9 @@
 void LDDocument::needVertexMerge()
 {
 	m_needVertexMerge = true;
-}
\ No newline at end of file
+}
+
+void LDDocument::needRecount()
+{
+	m_needRecount = true;
+}
--- a/src/ldDocument.h	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/ldDocument.h	Sat Feb 13 04:06:49 2016 +0200
@@ -77,6 +77,7 @@
 	void mergeVertices();
 	QString name() const;
 	void needVertexMerge();
+	void needRecount();
 	const LDObjectList& objects() const;
 	void openForEditing();
 	const QList<LDPolygon>& polygonData() const;
@@ -95,6 +96,7 @@
 	void setTabIndex (int value);
 	void swapObjects (LDObject* one, LDObject* other);
 	int tabIndex() const;
+	int triangleCount();
 	void undo();
 	void vertexChanged (const Vertex& a, const Vertex& b);
 
@@ -111,8 +113,10 @@
 	bool m_needVertexMerge;
 	bool m_needsReCache; // If true, next polygon inline of this document rebuilds stored polygon data.
 	bool m_beingDestroyed;
+	bool m_needRecount;
 	long m_savePosition;
 	int m_tabIndex;
+	int m_triangleCount;
 	QList<LDPolygon> m_polygonData;
 	QMap<LDObject*, QVector<Vertex>> m_objectVertices;
 	QVector<Vertex> m_vertices;
--- a/src/ldObject.cpp	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/ldObject.cpp	Sat Feb 13 04:06:49 2016 +0200
@@ -191,11 +191,11 @@
 QList<LDTriangle*> LDQuad::splitToTriangles()
 {
 	// Create the two triangles based on this quadrilateral:
-	// 0---3       0---3    3
-	// |   |       |  /    /|
-	// |   |  ==>  | /    / |
-	// |   |       |/    /  |
-	// 1---2       1    1---2
+	// 0───3       0───3    3
+	// │   │  --→  │  ╱    ╱│
+	// │   │  --→  │ ╱    ╱ │
+	// │   │  --→  │╱    ╱  │
+	// 1───2       1    1───2
 	LDTriangle* tri1 (new LDTriangle (vertex (0), vertex (1), vertex (3)));
 	LDTriangle* tri2 (new LDTriangle (vertex (1), vertex (2), vertex (3)));
 
@@ -248,6 +248,26 @@
 		document()->swapObjects (this, other);
 }
 
+int LDObject::triangleCount() const
+{
+	return 0;
+}
+
+int LDSubfileReference::triangleCount() const
+{
+	return fileInfo()->triangleCount();
+}
+
+int LDTriangle::triangleCount() const
+{
+	return 1;
+}
+
+int LDQuad::triangleCount() const
+{
+	return 2;
+}
+
 // =============================================================================
 //
 LDLine::LDLine (Vertex v1, Vertex v2, LDDocument* document) :
@@ -1185,17 +1205,20 @@
 	return m_fileInfo;
 }
 
-void LDSubfileReference::setFileInfo (LDDocument* document)
+void LDSubfileReference::setFileInfo (LDDocument* newReferee)
 {
-	changeProperty (this, &m_fileInfo, document);
+	changeProperty (this, &m_fileInfo, newReferee);
+
+	if (document())
+		document()->needRecount();
 
 	// If it's an immediate subfile reference (i.e. this subfile is in an opened document), we need to pre-compile the
 	// GL polygons for the document if they don't exist already.
-	if (document and
-		document->isCache() == false and
-		document->polygonData().isEmpty())
+	if (newReferee and
+		newReferee->isCache() == false and
+		newReferee->polygonData().isEmpty())
 	{
-		document->initializeCachedData();
+		newReferee->initializeCachedData();
 	}
 };
 
--- a/src/ldObject.h	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/ldObject.h	Sat Feb 13 04:06:49 2016 +0200
@@ -125,7 +125,7 @@
 	void setHidden (bool value);
 	void setVertex (int i, const Vertex& vert);
 	void swap (LDObject* other);
-	LDObject* topLevelParent();
+	virtual int triangleCount() const;
 	virtual LDObjectType type() const = 0;
 	virtual QString typeName() const = 0;
 	const Vertex& vertex (int i) const;
@@ -143,7 +143,6 @@
 	bool m_isHidden;
 	bool m_isSelected;
 	bool m_isDestroyed;
-	LDObject* m_parent;
 	LDDocument* m_document;
 	qint32 m_id;
 	LDColor m_color;
@@ -324,6 +323,7 @@
 	LDObjectList inlineContents (bool deep, bool render);
 	QList<LDPolygon> inlinePolygons();
 	void setFileInfo (LDDocument* fileInfo);
+	int triangleCount() const override;
 
 private:
 	LDDocument* m_fileInfo;
@@ -387,6 +387,7 @@
 
 public:
 	LDTriangle (Vertex const& v1, Vertex const& v2, Vertex const& v3, LDDocument* document = nullptr);
+	int triangleCount() const override;
 };
 
 //
@@ -410,6 +411,7 @@
 
 	// Split this quad into two triangles
 	QList<LDTriangle*> splitToTriangles();
+	int triangleCount() const override;
 };
 
 //
--- a/src/mainwindow.cpp	Fri Jan 01 23:41:55 2016 +0200
+++ b/src/mainwindow.cpp	Sat Feb 13 04:06:49 2016 +0200
@@ -119,8 +119,7 @@
 	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()));
 	circleToolSegmentsChanged(); // invoke it manually for initial label text
 
 	// Examine the toolsets and make a dictionary of tools

mercurial