Mon, 15 Jul 2013 14:43:29 +0300
restructure; removed g_BBox
src/aboutDialog.h | file | annotate | diff | comparison | revisions | |
src/colors.h | file | annotate | diff | comparison | revisions | |
src/common.h | file | annotate | diff | comparison | revisions | |
src/docs.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/file.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/misc.h | file | annotate | diff | comparison | revisions | |
src/primitives.cpp | file | annotate | diff | comparison | revisions | |
src/types.cpp | file | annotate | diff | comparison | revisions | |
src/types.h | file | annotate | diff | comparison | revisions |
--- a/src/aboutDialog.h Mon Jul 15 13:52:46 2013 +0300 +++ b/src/aboutDialog.h Mon Jul 15 14:43:29 2013 +0300 @@ -21,6 +21,7 @@ #include <QDialog> #include "common.h" +#include "types.h" class QPushButton;
--- a/src/colors.h Mon Jul 15 13:52:46 2013 +0300 +++ b/src/colors.h Mon Jul 15 14:43:29 2013 +0300 @@ -24,8 +24,7 @@ #define MAX_COLORS 512 -class LDColor -{ +class LDColor { public: str name, hexcode; QColor faceColor, edgeColor; @@ -34,9 +33,13 @@ void initColors(); void parseLDConfig(); -uchar luma( QColor& col ); +uchar luma (QColor& col); // Safely gets a color with the given number or null if no such color. -LDColor* getColor( short colnum ); +LDColor* getColor (short colnum); -#endif // COLORS_H +// Main and edge color identifiers +static const short maincolor = 16; +static const short edgecolor = 24; + +#endif // COLORS_H \ No newline at end of file
--- a/src/common.h Mon Jul 15 13:52:46 2013 +0300 +++ b/src/common.h Mon Jul 15 14:43:29 2013 +0300 @@ -33,7 +33,6 @@ #include <QMutex> #include "config.h" -#include "types.h" #define APPNAME "LDForge" #define VERSION_MAJOR 0 @@ -59,17 +58,16 @@ #endif // RELEASE #define elif else if -#define G_TR QObject::tr - -extern File g_file_stdout; -extern File g_file_stderr; void doDevf (const char* func, const char* fmtstr, ...); // Version string identifier -str versionString (); +const char* versionString (); const char* versionMoniker (); -str fullVersionString (); +const char* fullVersionString (); + +// Null pointer +static const std::nullptr_t null = nullptr; #ifdef __GNUC__ # define FORMAT_PRINTF(M,N) __attribute__ ((format (printf, M, N))) @@ -154,22 +152,14 @@ #define FUNCNAME __func__ #endif // __GNUC__ -// printf replacement -#ifndef IN_IDE_PARSER -#define print(...) doPrint (g_file_stdout, {__VA_ARGS__}) -#define fprint(F, ...) doPrint (F, {__VA_ARGS__}) -#else -void print (const char* fmtstr, ...); -void fprint (File& f, const char* fmtstr, ...); -#endif -void doPrint (File& f, initlist<StringFormatArg> args); -void doPrint (FILE* f, initlist<StringFormatArg> args); // heh - // Replace assert with a version that shows a GUI dialog if possible #ifdef assert #undef assert #endif // assert +class QString; +typedef QString str; + void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr); void fatalError (const char* file, const ulong line, const char* funcname, str errmsg); @@ -179,66 +169,10 @@ #define fatal(MSG) \ fatalError (__FILE__, __LINE__, FUNCNAME, MSG) -// Main and edge color identifiers -static const short maincolor = 16; -static const short edgecolor = 24; - -static const short lores = 16; -static const short hires = 48; - -static const bool yup = true; -static const bool nope = false; - -static const str CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt", - NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt"; - -class ForgeWindow; -class LDObject; -class bbox; -class LDOpenFile; -class QApplication; - -// ----------------------------------------------------------------------------- -// Plural expression -template<class T> static inline const char* plural (T n) { - return (n != 1) ? "s" : ""; -} - -// ----------------------------------------------------------------------------- -// Templated clamp -template<class T> static inline T clamp (T a, T min, T max) { - return (a > max) ? max : (a < min) ? min : a; -} - -// Templated minimum -template<class T> static inline T min (T a, T b) { - return (a < b) ? a : b; -} - -// Templated maximum -template<class T> static inline T max (T a, T b) { - return (a > b) ? a : b; -} - -// Templated absolute value -template<class T> static inline T abs (T a) { - return (a >= 0) ? a : -a; -} - -// Quick QString to const char* conversion -static inline const char* qchars (const QString& qstr) { - return qstr.toStdString ().c_str (); -} - -static const double pi = 3.14159265358979323846f; - // ----------------------------------------------------------------------------- #ifdef IN_IDE_PARSER // KDevelop workarounds: # error IN_IDE_PARSER is defined (this code is only for KDevelop workarounds) -// Current function name -static const char* __func__ = ""; - # ifndef va_start # define va_start(va, arg) # endif // va_start @@ -247,44 +181,8 @@ # define va_end(va) # endif // va_end +static const char* __func__ = ""; // Current function name typedef void FILE; // :| #endif // IN_IDE_PARSER -// ----------------------------------------------------------------------------- -enum LogType { - LOG_Normal, - LOG_Warning, - LOG_Error, - LOG_Dev, -}; - -// log() - universal access to the message log. Defined here so that I don't have -// to include messagelog.h here and recompile everything every time that file changes. -void DoLog( std::initializer_list<StringFormatArg> args ); -#ifndef IN_IDE_PARSER -# define log(...) DoLog({ __VA_ARGS__ }); -#else -void log( const char* fmtstr, ... ); -#endif - -// ----------------------------------------------------------------------------- -// Vertex at (0, 0, 0) -extern const vertex g_origin; - -// ----------------------------------------------------------------------------- -// Pointer to the bounding box. -extern bbox g_BBox; - -// ----------------------------------------------------------------------------- -// Vector of all currently opened files. -extern vector<LDOpenFile*> g_loadedFiles; - -// ----------------------------------------------------------------------------- -// Pointer to the main application. -extern const QApplication* g_app; - -// ----------------------------------------------------------------------------- -// Identity matrix -extern const matrix g_identity; - #endif // COMMON_H \ No newline at end of file
--- a/src/docs.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/docs.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -21,6 +21,7 @@ #include <QDialogButtonBox> #include <QBoxLayout> #include "common.h" +#include "types.h" class DocumentViewer : public QDialog { public:
--- a/src/file.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/file.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -26,7 +26,6 @@ #include "config.h" #include "file.h" #include "misc.h" -#include "bbox.h" #include "gui.h" #include "history.h" #include "dialogs.h" @@ -450,7 +449,6 @@ g_loadedFiles << f; setCurrentFile (f); - g_BBox.reset(); g_win->R()->setFile (f); g_win->fullRefresh(); g_win->updateTitle(); @@ -515,9 +513,6 @@ file->setImplicit (false); setCurrentFile (file); - // Recalculate the bounding box - g_BBox.calculate(); - // Rebuild the object tree view now. g_win->fullRefresh(); g_win->updateTitle(); @@ -811,9 +806,6 @@ if (obj->getType() == LDObject::Vertex) PROP_NAME (vertices) << obj; - if (this == currentFile()) - g_BBox.calcObject (obj); - return numObjs() - 1; } @@ -823,9 +815,6 @@ void LDOpenFile::insertObj (const ulong pos, LDObject* obj) { m_history.add (new AddHistory (pos, obj)); m_objs.insert (pos, obj); - - if (this == currentFile()) - g_BBox.calcObject (obj); } // ============================================================================= @@ -835,10 +824,6 @@ ulong idx = obj->getIndex (this); m_history.add (new DelHistory (idx, obj)); m_objs.erase (idx); - - // Update the bounding box - if (this == currentFile()) - g_BBox.calculate (); } // =============================================================================
--- a/src/file.h Mon Jul 15 13:52:46 2013 +0300 +++ b/src/file.h Mon Jul 15 14:43:29 2013 +0300 @@ -164,6 +164,8 @@ LDOpenFile* currentFile(); void setCurrentFile (LDOpenFile* f); +extern vector<LDOpenFile*> g_loadedFiles; // Vector of all currently opened files. + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // =============================================================================
--- a/src/gldraw.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/gldraw.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -28,7 +28,6 @@ #include "config.h" #include "file.h" #include "gldraw.h" -#include "bbox.h" #include "colors.h" #include "gui.h" #include "misc.h"
--- a/src/ldtypes.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/ldtypes.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -23,6 +23,7 @@ #include "gui.h" #include "history.h" #include "gldraw.h" +#include "colors.h" // List of all LDObjects vector<LDObject*> g_LDObjects;
--- a/src/ldtypes.h Mon Jul 15 13:52:46 2013 +0300 +++ b/src/ldtypes.h Mon Jul 15 14:43:29 2013 +0300 @@ -51,6 +51,7 @@ class QListWidgetItem; class LDSubfileObject; +class LDOpenFile; // ============================================================================= // LDObject @@ -410,4 +411,10 @@ PROPERTY (str, filename, setFilename) }; +// Other common LDraw stuff +static const str CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt", + NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt"; +static const short lores = 16; +static const short hires = 48; + #endif // LDTYPES_H \ No newline at end of file
--- a/src/main.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/main.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -23,7 +23,6 @@ #include <QTextStream> #include "gui.h" #include "file.h" -#include "bbox.h" #include "misc.h" #include "config.h" #include "colors.h" @@ -32,10 +31,10 @@ vector<LDOpenFile*> g_loadedFiles; ForgeWindow* g_win = null; -bbox g_BBox; const QApplication* g_app = null; File g_file_stdout (stdout, File::Write); File g_file_stderr (stderr, File::Write); +static str g_versionString, g_fullVersionString; const vertex g_origin (0.0f, 0.0f, 0.0f); const matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); @@ -94,12 +93,16 @@ va_end (va); } -str versionString () { +const char* versionString () { + if (g_versionString.length() == 0) { #if VERSION_PATCH == 0 - return fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); + g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); #else - return fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); + g_versionString = fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); #endif // VERSION_PATCH + } + + return g_versionString.toStdString().c_str(); } const char* versionMoniker () { @@ -116,8 +119,11 @@ #endif // BUILD_ID } -str fullVersionString () { - return fmt ("v%1%2", versionString (), versionMoniker ()); +const char* fullVersionString () { + if (g_fullVersionString.length() == 0) + g_fullVersionString = fmt ("v%1%2", versionString (), versionMoniker ()); + + return g_fullVersionString.toStdString().c_str(); } static void bombBox (str msg) { @@ -145,7 +151,7 @@ errmsg += "."; #endif - printf ("%s\n", qchars (errmsg)); + printf ("%s\n", errmsg.toStdString().c_str()); #if BUILD_ID == BUILD_INTERNAL if (g_win)
--- a/src/misc.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/misc.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -22,7 +22,6 @@ #include "common.h" #include "misc.h" #include "gui.h" -#include "bbox.h" #include "dialogs.h" #include "ui_rotpoint.h" @@ -211,7 +210,7 @@ // ============================================================================= vertex rotPoint( const vector<LDObject*>& objs ) { - bbox box; + LDBoundingBox box; switch( edit_rotpoint ) {
--- a/src/misc.h Mon Jul 15 13:52:46 2013 +0300 +++ b/src/misc.h Mon Jul 15 14:43:29 2013 +0300 @@ -133,4 +133,31 @@ short m_pos; }; +// ----------------------------------------------------------------------------- +// Plural expression +template<class T> static inline const char* plural (T n) { + return (n != 1) ? "s" : ""; +} + +// ----------------------------------------------------------------------------- +// Templated clamp +template<class T> static inline T clamp (T a, T min, T max) { + return (a > max) ? max : (a < min) ? min : a; +} + +// Templated minimum +template<class T> static inline T min (T a, T b) { + return (a < b) ? a : b; +} + +// Templated maximum +template<class T> static inline T max (T a, T b) { + return (a > b) ? a : b; +} + +// Templated absolute value +template<class T> static inline T abs (T a) { + return (a >= 0) ? a : -a; +} + #endif // MISC_H \ No newline at end of file
--- a/src/primitives.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/primitives.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -25,6 +25,7 @@ #include "primitives.h" #include "ui_makeprim.h" #include "misc.h" +#include "colors.h" vector<PrimitiveCategory> g_PrimitiveCategories; static PrimitiveLister* g_activePrimLister = null;
--- a/src/types.cpp Mon Jul 15 13:52:46 2013 +0300 +++ b/src/types.cpp Mon Jul 15 14:43:29 2013 +0300 @@ -24,6 +24,8 @@ #include "common.h" #include "types.h" #include "misc.h" +#include "ldtypes.h" +#include "file.h" str DoFormat( vector<StringFormatArg> args ) { @@ -486,14 +488,14 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -bbox::bbox() { +LDBoundingBox::LDBoundingBox() { reset(); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void bbox::calculate() { +void LDBoundingBox::calculate() { reset(); if (!currentFile()) @@ -506,7 +508,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void bbox::calcObject (LDObject* obj) { +void LDBoundingBox::calcObject (LDObject* obj) { switch (obj->getType()) { case LDObject::Line: case LDObject::Triangle: @@ -533,10 +535,20 @@ } } +LDBoundingBox& LDBoundingBox::operator<< (const vertex& v) { + calcVertex (v); + return *this; +} + +LDBoundingBox& LDBoundingBox::operator<< (LDObject* obj) { + calcObject (obj); + return *this; +} + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void bbox::calcVertex (const vertex& v) { +void LDBoundingBox::calcVertex (const vertex& v) { for (const Axis ax : g_Axes) { if (v[ax] < m_v0[ax]) m_v0[ax] = v[ax]; @@ -551,7 +563,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void bbox::reset() { +void LDBoundingBox::reset() { m_v0[X] = m_v0[Y] = m_v0[Z] = 0x7FFFFFFF; m_v1[X] = m_v1[Y] = m_v1[Z] = 0xFFFFFFFF; @@ -561,7 +573,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -double bbox::size() const { +double LDBoundingBox::size() const { double xscale = (m_v0[X] - m_v1[X]); double yscale = (m_v0[Y] - m_v1[Y]); double zscale = (m_v0[Z] - m_v1[Z]); @@ -580,7 +592,7 @@ } // ============================================================================= -vertex bbox::center() const { +vertex LDBoundingBox::center() const { return vertex ( (m_v0[X] + m_v1[X]) / 2, (m_v0[Y] + m_v1[Y]) / 2,
--- a/src/types.h Mon Jul 15 13:52:46 2013 +0300 +++ b/src/types.h Mon Jul 15 14:43:29 2013 +0300 @@ -24,8 +24,7 @@ #include <vector> #include "common.h" -// Null pointer -static const std::nullptr_t null = nullptr; +class LDObject; typedef QChar qchar; typedef QString str; @@ -62,7 +61,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= // matrix -// +// // A mathematical 3 x 3 matrix // ============================================================================= class matrix { @@ -401,14 +400,6 @@ str m_val; }; -// Formatter function -str DoFormat (vector<StringFormatArg> args); -#ifndef IN_IDE_PARSER -#define fmt(...) DoFormat ({__VA_ARGS__}) -#else -str fmt (const char* fmtstr, ...); -#endif - // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= @@ -467,18 +458,18 @@ }; // ============================================================================= -// bbox +// LDBoundingBox // // The bounding box is the box that encompasses a given set of objects. // v0 is the minimum vertex, v1 is the maximum vertex. // ============================================================================= -class bbox { +class LDBoundingBox { READ_PROPERTY (bool, empty, setEmpty) READ_PROPERTY (vertex, v0, setV0) READ_PROPERTY (vertex, v1, setV1) public: - bbox(); + LDBoundingBox(); void reset(); void calculate(); double size() const; @@ -486,15 +477,39 @@ void calcVertex (const vertex& v); vertex center() const; - bbox& operator<< (LDObject* obj) { - calcObject (obj); - return *this; - } - - bbox& operator<< (const vertex& v) { - calcVertex (v); - return *this; - } + LDBoundingBox& operator<< (LDObject* obj); + LDBoundingBox& operator<< (const vertex& v); }; -#endif // TYPES_H +// Formatter function +str DoFormat (vector<StringFormatArg> args); + +// printf replacement +void doPrint (File& f, initlist<StringFormatArg> args); +void doPrint (FILE* f, initlist<StringFormatArg> args); // heh + +// log() - universal access to the message log. Defined here so that I don't have +// to include messagelog.h here and recompile everything every time that file changes. +void DoLog( std::initializer_list<StringFormatArg> args ); + +// Macros to access these functions +# ifndef IN_IDE_PARSER +#define fmt(...) DoFormat ({__VA_ARGS__}) +# define print(...) doPrint (g_file_stdout, {__VA_ARGS__}) +# define fprint(F, ...) doPrint (F, {__VA_ARGS__}) +# define log(...) DoLog({ __VA_ARGS__ }); +#else +str fmt (const char* fmtstr, ...); +void print (const char* fmtstr, ...); +void fprint (File& f, const char* fmtstr, ...); +void log( const char* fmtstr, ... ); +#endif + +extern File g_file_stdout; +extern File g_file_stderr; +extern const vertex g_origin; // Vertex at (0, 0, 0) +extern const matrix g_identity; // Identity matrix + +static const double pi = 3.14159265358979323846f; + +#endif // TYPES_H \ No newline at end of file