- commit work done on header/body split experimental

Wed, 22 Oct 2014 20:19:53 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 22 Oct 2014 20:19:53 +0300
branch
experimental
changeset 916
bf08a6b42102
parent 912
3feb4d20092d
child 1357
e034b1d10147

- commit work done on header/body split

src/ldDocument.cc file | annotate | diff | comparison | revisions
src/ldDocument.h file | annotate | diff | comparison | revisions
src/ldHeader.cpp file | annotate | diff | comparison | revisions
src/ldHeader.h file | annotate | diff | comparison | revisions
--- a/src/ldDocument.cc	Thu Nov 06 15:44:11 2014 +0200
+++ b/src/ldDocument.cc	Wed Oct 22 20:19:53 2014 +0300
@@ -131,7 +131,8 @@
 	m_flags (0),
 	m_verticesOutdated (true),
 	m_needVertexMerge (true),
-	m_gldata (new LDGLData)
+	m_gldata (new LDGLData),
+	m_header (new LDHeader)
 {
 	*selfptr = LDDocumentPtr (this);
 	setSelf (*selfptr);
@@ -164,6 +165,7 @@
 	m_flags |= DOCF_IsBeingDestroyed;
 	delete m_history;
 	delete m_gldata;
+	delete m_header;
 }
 
 // =============================================================================
--- a/src/ldDocument.h	Thu Nov 06 15:44:11 2014 +0200
+++ b/src/ldDocument.h	Wed Oct 22 20:19:53 2014 +0300
@@ -27,6 +27,7 @@
 class OpenProgressDialog;
 struct LDGLData;
 class GLCompiler;
+class LDHeader;
 
 namespace LDPaths
 {
@@ -62,7 +63,6 @@
 //
 class LDDocument : public QObject
 {
-public:
 	PROPERTY (public,	QString,				name,			setName,			STOCK_WRITE)
 	PROPERTY (private,	LDObjectList,		objects, 		setObjects,			STOCK_WRITE)
 	PROPERTY (private,	LDObjectList,		cache, 			setCache,			STOCK_WRITE)
@@ -75,11 +75,7 @@
 	PROPERTY (public,	QList<LDPolygon>,	polygonData,	setPolygonData,		STOCK_WRITE)
 	PROPERTY (private,	LDDocumentFlags,	flags,			setFlags,			STOCK_WRITE)
 	PROPERTY (private,	LDDocumentWeakPtr,	self,			setSelf,			STOCK_WRITE)
-
-	QMap<LDObjectPtr, QVector<Vertex>> m_objectVertices;
-	QVector<Vertex> m_vertices;
-	bool m_verticesOutdated;
-	bool m_needVertexMerge;
+	PROPERTY (private,	LDHeader*,			header,			setHeader,			STOCK_WRITE)
 
 public:
 	LDDocument(LDDocumentPtr* selfptr);
@@ -170,6 +166,10 @@
 	friend class GLRenderer;
 
 private:
+	QMap<LDObjectPtr, QVector<Vertex>> m_objectVertices;
+	QVector<Vertex> m_vertices;
+	bool m_verticesOutdated;
+	bool m_needVertexMerge;
 	LDObjectList			m_sel;
 	LDGLData*				m_gldata;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldHeader.cpp	Wed Oct 22 20:19:53 2014 +0300
@@ -0,0 +1,136 @@
+#include "ldHeader.h"
+
+static const char* g_PartTypeNames[PARTTYPE_NUM_TYPES] =
+{
+	"Part",
+	"Subpart",
+	"Primitive",
+	"48_Primitive",
+	"Shortcut",
+	"Unofficial_Part",
+	"Unofficial_Subpart",
+	"Unofficial_Primitive",
+	"Unofficial_48_Primitive",
+	"Unofficial_Shortcut",
+};
+
+static const char g_HeaderBFCNames[] =
+{
+	"CCW",
+	"CW",
+	"NOCERTIFY",
+}
+
+QString LDHeader::serialize() const
+{
+	QStringList result;
+
+	// Title, name and part type
+	result << m_title;
+	result << "Name:" + m_name;
+	result << format ("0 !LDRAW_ORG %1 %2", g_PartTypeNames[int (partType())], qualifiers())
+
+	// License (if any, heh)
+	if (not license().isEmpty())
+		result << "0 !LICENSE " + license();
+
+	// Help text, if any
+	if (not help().isEmpty())
+	{
+		result << "";
+
+		for (QString const& a : keywords())
+			result << "0 !HELP " + a;
+	}
+
+	// BFC type - specs say this isn't mandatory for NOCERTIFY parts but
+	// highly recommended, so we'll add it in.
+	result << "";
+	result << "0 BFC " + g_HeaderBFCNames[int (headerBFC())];
+
+	// Category, if present
+	if (not category().isEmpty())
+	{
+		result << "";
+		result << "0 !CATEGORY " + category();
+	}
+
+	// Keywords, if any
+	if (not keywords.isEmpty())
+	{
+		if (category.isEmpty())
+			result << "";
+
+		for (QString const& a : keywords())
+			result << "0 !KEYWORDS " + a;
+	}
+
+	// Command line, if any
+	if (not commandLine().isEmpty())
+		result << "" << "0 !CMDLINE " + commandLine();
+
+	// History entries, if any
+	if (not history().isEmpty())
+	{
+		result << "";
+
+		for (LDHistoryEntry const& a : history())
+			result << a.serialize();
+	}
+
+	// Comments, if any
+	if (not comments().isEmpty())
+	{
+		result << "";
+
+		for (QString const& a : comments())
+			result << "0 // " + a;
+	}
+
+	result << "";
+	QString resultText;
+
+	// Wrap it all up into a single string
+	for (QString a : result)
+	{
+		// Remove trailing space
+		while (a.right (1) == " ")
+			a.chop (1);
+
+		result += a + "\r\n";
+	}
+
+	return result;
+}
+
+bool LDHeader::isUnofficial() const
+{
+	return m_partType >= PARTTYPE_FIRST_UNOFFICIAL;
+}
+
+void LDHeader::makeUnofficial()
+{
+	if (not isUnofficial())
+		m_partType += PARTTYPE_FIRST_UNOFFICIAL;
+}
+
+void LDHeader::makeOfficial()
+{
+	if (isUnofficial())
+		m_partType -= PARTTYPE_FIRST_UNOFFICIAL;
+}
+
+LDHistoryEntry::LDHistoryEntry() :
+	m_isRealName (false) {}
+
+QString LDHistoryEntry::serialize() const
+{
+	QString userblock;
+
+	if (isRealName())
+		userblock = format ("{%1}", username());
+	else
+		userblock = format ("[%1]", username());
+
+	return format ("0 !HISTORY %1 %2 %3", date().toString ("yyyy-MM-dd"), userblock, description);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldHeader.h	Wed Oct 22 20:19:53 2014 +0300
@@ -0,0 +1,67 @@
+#include "main.h"
+
+enum LDPartType
+{
+	PARTTYPE_PART,
+	PARTTYPE_SUBPART,
+	PARTTYPE_PRIMITIVE,
+	PARTTYPE_48_PRIMITIVE,
+	PARTTYPE_SHORTCUT,
+	PARTTYPE_UNOFFICIAL_PART,
+	PARTTYPE_UNOFFICIAL_SUBPART,
+	PARTTYPE_UNOFFICIAL_PRIMITIVE,
+	PARTTYPE_UNOFFICIAL_48_PRIMITIVE,
+	PARTTYPE_UNOFFICIAL_SHORTCUT,
+
+	PARTTYPE_NUM_TYPES,
+	PARTTYPE_FIRST = PARTTYPE_PART,
+	PARTTYPE_FIRST_UNOFFICIAL = PARTTYPE_UNOFFICIAL_PART
+};
+
+enum LDHeaderBFC
+{
+	HEADERBFC_CCW,
+	HEADERBFC_CW,
+	HEADERBFC_NOCERTIFY,
+};
+
+class LDHistoryEntry
+{
+	PROPERTY (public, QDate, date, setDate, STOCK_WRITE)
+	PROPERTY (public, QString, username, setUserName, STOCK_WRITE)
+	PROPERTY (public, QString, description, setDescription, STOCK_WRITE)
+
+	// If true, `username` is actually the real name and is written in curly braces
+	PROPERTY (public, bool, isRealName, setIsRealName, STOCK_WRITE)
+
+public:
+	LDHistoryEntry();
+	QString serialize() const;
+};
+
+class LDHeader
+{
+	PROPERTY (public, QString, title, setTitle, STOCK_WRITE)
+	PROPERTY (public, QString, name, setName, STOCK_WRITE)
+	PROPERTY (public, QStringList, help, setHelp, STOCK_WRITE)
+	PROPERTY (public, QString, license, setLicense, STOCK_WRITE)
+	PROPERTY (public, LDHeaderBFC, winding, setWinding, STOCK_WRITE)
+	PROPERTY (public, LDPartType, partType, setPartType, STOCK_WRITE)
+	PROPERTY (public, QString, qualifiers, setQualifiers, STOCK_WRITE)
+	PROPERTY (public, QString, category, setCategory, STOCK_WRITE)
+	PROPERTY (public, QStringList, keywords, setKeywords, STOCK_WRITE)
+	PROPERTY (public, QString, commandLine, setCommandLine, STOCK_WRITE)
+	PROPERTY (public, QStringList, comments, setComments, STOCK_WRITE)
+	PROPERTY (public, QList<LDHistoryEntry>, history, setHistory, STOCK_WRITE)
+
+public:
+	LDHeader();
+	~LDHeader();
+
+	DELETE_COPY (LDHeader)
+
+	bool isUnofficial() const;
+	void makeUnofficial();
+	void makeOfficial();
+	QString serialize() const;
+};

mercurial