Removed the two string arrays containing object types and icon names, moved these as LDObjects' virtual functions

Sun, 07 Jul 2013 15:08:38 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 07 Jul 2013 15:08:38 +0300
changeset 357
9c954c222996
parent 356
08398f57aba3
child 358
7885fa5b09c5

Removed the two string arrays containing object types and icon names, moved these as LDObjects' virtual functions

src/addObjectDialog.cpp file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/ldtypes.cpp file | annotate | diff | comparison | revisions
src/ldtypes.h file | annotate | diff | comparison | revisions
--- a/src/addObjectDialog.cpp	Sun Jul 07 03:36:30 2013 +0300
+++ b/src/addObjectDialog.cpp	Sun Jul 07 15:08:38 2013 +0300
@@ -54,6 +54,7 @@
 	setlocale (LC_ALL, "C");
 	
 	short coordCount = 0;
+	str typeName = LDObject::typeName( type );
 	
 	switch (type) {
 	case LDObject::Comment:
@@ -135,11 +136,11 @@
 		}
 	
 	default:
-		critical (fmt ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, g_saObjTypeNames[type]));
+		critical (fmt ("Unhandled LDObject type %1 (%2) in AddObjectDialog", (int) type, typeName));
 		return;
 	}
 	
-	QPixmap icon = getIcon (fmt ("add-%1", g_saObjTypeIcons[type]));
+	QPixmap icon = getIcon (fmt ("add-%1", typeName));
 	LDObject* defaults = LDObject::getDefault (type);
 	
 	lb_typeIcon = new QLabel;
@@ -230,10 +231,9 @@
 		layout->addLayout (qCoordLayout, 0, 1, (coordCount / 3), 3);
 	}
 	
-	layout->addWidget (makeButtonBox (*this), 5, 0, 1, 4);
-	setLayout (layout);
-	setWindowTitle (fmt (APPNAME ": New %1",
-		g_saObjTypeNames[type]));
+	layout->addWidget( makeButtonBox( *this ), 5, 0, 1, 4 );
+	setLayout( layout );
+	setWindowTitle( fmt( tr( "Edit %1" ), typeName ));
 	
 	setWindowIcon (icon);
 	delete defaults;
--- a/src/gui.cpp	Sun Jul 07 03:36:30 2013 +0300
+++ b/src/gui.cpp	Sun Jul 07 15:08:38 2013 +0300
@@ -651,7 +651,7 @@
 			break;
 		
 		default:
-			descr = g_saObjTypeNames[obj->getType ()];
+			descr = obj->typeName();
 			break;
 		}
 		
@@ -661,7 +661,7 @@
 		}
 		
 		QListWidgetItem* item = new QListWidgetItem (descr);
-		item->setIcon (getIcon (g_saObjTypeIcons[obj->getType ()]));
+		item->setIcon( getIcon( obj->typeName() ));
 		
 		// Color gibberish orange on red so it stands out.
 		if (obj->getType() == LDObject::Gibberish) {
--- a/src/ldtypes.cpp	Sun Jul 07 03:36:30 2013 +0300
+++ b/src/ldtypes.cpp	Sun Jul 07 15:08:38 2013 +0300
@@ -24,37 +24,6 @@
 #include "history.h"
 #include "gldraw.h"
 
-char const* g_saObjTypeNames[] = {
-	"subfile",
-	"quadrilateral",
-	"triangle",
-	"line",
-	"condline",
-	"vertex",
-	"bfc",
-	"overlay",
-	"comment",
-	"unknown",
-	"empty",
-	"unidentified",
-};
-
-// Should probably get rid of this array sometime
-char const* g_saObjTypeIcons[] = {
-	"subfile",
-	"quad",
-	"triangle",
-	"line",
-	"condline",
-	"vertex",
-	"bfc",
-	"overlay",
-	"comment",
-	"error",
-	"empty",
-	"error",
-};
-
 // List of all LDObjects
 vector<LDObject*> g_LDObjects;
 
@@ -388,6 +357,14 @@
 		g_win->R ()->compileObject (obj);
 }
 
+str LDObject::typeName( LDObject::Type type )
+{
+	LDObject* obj = LDObject::getDefault( type );
+	str name = obj->typeName();
+	delete obj;
+	return name;
+}
+
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
@@ -412,7 +389,7 @@
 		if (!firstDetails)
 			text += ", ";
 		
-		str noun = fmt ("%1%2", g_saObjTypeNames[objType], plural (objCount));
+		str noun = fmt ("%1%2", typeName( objType ), plural( objCount ));
 		
 		// Plural of "vertex" is "vertices". Stupid English.
 		if (objType == LDObject::Vertex && objCount != 1)
--- a/src/ldtypes.h	Sun Jul 07 03:36:30 2013 +0300
+++ b/src/ldtypes.h	Sun Jul 07 15:08:38 2013 +0300
@@ -34,18 +34,19 @@
 	virtual void move (vertex vVector); \
 	virtual void invert ();
 
-#define LDOBJ_VERTICES(V) virtual short vertices () const { return V; }
-#define LDOBJ_SETCOLORED(V) virtual bool isColored () const { return V; }
-#define LDOBJ_COLORED LDOBJ_SETCOLORED (true)
-#define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false)
+#define LDOBJ_NAME( N )        virtual str typeName() const { return #N; }
+#define LDOBJ_VERTICES( V )    virtual short vertices() const { return V; }
+#define LDOBJ_SETCOLORED( V )  virtual bool isColored() const { return V; }
+#define LDOBJ_COLORED          LDOBJ_SETCOLORED( true )
+#define LDOBJ_UNCOLORED        LDOBJ_SETCOLORED( false )
 
-#define LDOBJ_CUSTOM_SCEMANTIC virtual bool isScemantic () const
-#define LDOBJ_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return true; }
-#define LDOBJ_NON_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return false; }
+#define LDOBJ_CUSTOM_SCEMANTIC virtual bool isScemantic() const
+#define LDOBJ_SCEMANTIC        LDOBJ_CUSTOM_SCEMANTIC { return true; }
+#define LDOBJ_NON_SCEMANTIC    LDOBJ_CUSTOM_SCEMANTIC { return false; }
 
-#define LDOBJ_SETMATRIX(V) virtual bool hasMatrix () const { return V; }
-#define LDOBJ_HAS_MATRIX LDOBJ_SETMATRIX (true)
-#define LDOBJ_NO_MATRIX LDOBJ_SETMATRIX (false)
+#define LDOBJ_SETMATRIX(V)     virtual bool hasMatrix() const { return V; }
+#define LDOBJ_HAS_MATRIX       LDOBJ_SETMATRIX( true )
+#define LDOBJ_NO_MATRIX        LDOBJ_SETMATRIX( false )
 
 class QListWidgetItem;
 class LDSubfile;
@@ -153,6 +154,10 @@
 	// Does this object have meaning in the part model?
 	virtual bool isScemantic () const { return false; }
 	
+	// Type name of this object
+	virtual str typeName() const { return "unknown"; }
+	static str typeName( LDObject::Type type );
+	
 	// Returns a sample object by the given value
 	static LDObject* getDefault (const LDObject::Type type);
 	
@@ -190,6 +195,7 @@
 class LDGibberish : public LDObject {
 public:
 	LDOBJ (Gibberish)
+	LDOBJ_NAME( error )
 	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_SCEMANTIC
@@ -228,6 +234,7 @@
 class LDComment : public LDObject {
 public:
 	LDOBJ (Comment)
+	LDOBJ_NAME( comment )
 	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_NON_SCEMANTIC
@@ -250,6 +257,7 @@
 	enum Type { CertifyCCW, CCW, CertifyCW, CW, NoCertify, InvertNext, NumStatements };
 	
 	LDOBJ (BFC)
+	LDOBJ_NAME( bfc )
 	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
 	LDOBJ_CUSTOM_SCEMANTIC { return (type == InvertNext); }
@@ -274,6 +282,7 @@
 	
 public:
 	LDOBJ (Subfile)
+	LDOBJ_NAME( subfile )
 	LDOBJ_VERTICES (0)
 	LDOBJ_COLORED
 	LDOBJ_SCEMANTIC
@@ -298,6 +307,7 @@
 class LDLine : public LDObject {
 public:
 	LDOBJ (Line)
+	LDOBJ_NAME( line )
 	LDOBJ_VERTICES (2)
 	LDOBJ_COLORED
 	LDOBJ_SCEMANTIC
@@ -316,6 +326,7 @@
 class LDCondLine : public LDLine {
 public:
 	LDOBJ (CondLine)
+	LDOBJ_NAME( condline )
 	LDOBJ_VERTICES (4)
 	LDOBJ_COLORED
 	LDOBJ_SCEMANTIC
@@ -335,6 +346,7 @@
 class LDTriangle : public LDObject {
 public:
 	LDOBJ (Triangle)
+	LDOBJ_NAME( triangle )
 	LDOBJ_VERTICES (3)
 	LDOBJ_COLORED
 	LDOBJ_SCEMANTIC
@@ -357,6 +369,7 @@
 class LDQuad : public LDObject {
 public:
 	LDOBJ (Quad)
+	LDOBJ_NAME( quad )
 	LDOBJ_VERTICES (4)
 	LDOBJ_COLORED
 	LDOBJ_SCEMANTIC
@@ -379,6 +392,7 @@
 class LDVertex : public LDObject {
 public:
 	LDOBJ (Vertex)
+	LDOBJ_NAME( vertex )
 	LDOBJ_VERTICES (0) // TODO: move pos to vaCoords[0]
 	LDOBJ_COLORED
 	LDOBJ_NON_SCEMANTIC
@@ -399,6 +413,7 @@
 {
 public:
 	LDOBJ( Overlay )
+	LDOBJ_NAME( overlay )
 	LDOBJ_VERTICES( 0 )
 	LDOBJ_UNCOLORED
 	LDOBJ_NON_SCEMANTIC
@@ -411,12 +426,4 @@
 	PROPERTY( str, filename, setFilename )
 };
 
-// =============================================================================
-// Object type names. Pass the return value of getType as the index to get a
-// string representation of the object's type.
-extern const char* g_saObjTypeNames[];
-
-// Icons for these types
-extern const char* g_saObjTypeIcons[];
-
 #endif // LDTYPES_H
\ No newline at end of file

mercurial