Sat, 05 Oct 2013 12:51:13 +0300
a bit more cleanup
--- a/src/addObjectDialog.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/addObjectDialog.h Sat Oct 05 12:51:13 2013 +0300 @@ -69,4 +69,4 @@ void slot_subfileTypeChanged(); }; -#endif // ZZ_ADDOBJECTDIALOG_H +#endif // LDFORGE_ADDOBJECTDIALOG_H
--- a/src/colorSelectDialog.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/colorSelectDialog.h Sat Oct 05 12:51:13 2013 +0300 @@ -50,4 +50,4 @@ void drawColorInfo(); }; -#endif // COLORSELECTOR_H +#endif // LDFORGE_COLORSELECTOR_H
--- a/src/common.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/common.h Sat Oct 05 12:51:13 2013 +0300 @@ -20,8 +20,8 @@ // This file is included one way or another in every source file of LDForge. // Stuff defined and included here is universally included. -#ifndef COMMON_H -#define COMMON_H +#ifndef LDFORGE_COMMON_H +#define LDFORGE_COMMON_H #include <stdio.h> #include <stdlib.h> @@ -68,15 +68,15 @@ #endif // __GNUC__ #ifdef WIN32 -#define DIRSLASH "\\" -#define DIRSLASH_CHAR '\\' +# define DIRSLASH "\\" +# define DIRSLASH_CHAR '\\' #else // WIN32 -#define DIRSLASH "/" -#define DIRSLASH_CHAR '/' +# define DIRSLASH "/" +# define DIRSLASH_CHAR '/' #endif // WIN32 #ifdef RELEASE -#define NDEBUG // remove asserts +# define NDEBUG // remove asserts #endif // RELEASE #define PROP_NAME(GET) m_##GET @@ -142,27 +142,19 @@ #define FUNCNAME __func__ #endif // __GNUC__ -// Replace assert with a version that shows a GUI dialog if possible +// Replace assert with a version that shows a GUI dialog if possible. +// On Windows I just can't get the actual error messages otherwise. #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); +#define assert(N) ((N) ? (void) 0 : assertionFailure (__FILE__, __LINE__, FUNCNAME, #N)) // Version string identifier -str versionString(); -str versionMoniker(); -str fullVersionString(); - -#define assert(N) \ - ((N) ? (void) 0 : assertionFailure (__FILE__, __LINE__, FUNCNAME, #N)) - -#define fatal(MSG) \ - fatalError (__FILE__, __LINE__, FUNCNAME, MSG) +QString versionString(); +QString versionMoniker(); +QString fullVersionString(); // ----------------------------------------------------------------------------- #ifdef IN_IDE_PARSER // KDevelop workarounds: @@ -180,4 +172,4 @@ typedef void FILE; // :| #endif // IN_IDE_PARSER -#endif // COMMON_H +#endif // LDFORGE_COMMON_H
--- a/src/config.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/config.h Sat Oct 05 12:51:13 2013 +0300 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef LDFORGE_CONFIG_H +#define LDFORGE_CONFIG_H #include "common.h" @@ -243,4 +243,4 @@ } }; -#endif // CONFIG_H +#endif // LDFORGE_CONFIG_H
--- a/src/configDialog.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/configDialog.h Sat Oct 05 12:51:13 2013 +0300 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef CONFIGDIALOG_H -#define CONFIGDIALOG_H +#ifndef LDFORGE_CONFIGDIALOG_H +#define LDFORGE_CONFIGDIALOG_H #include "gui.h" #include <QDialog> @@ -114,4 +114,4 @@ virtual void keyPressEvent (QKeyEvent* ev) override; }; -#endif // CONFIGDIALOG_H +#endif // LDFORGE_CONFIGDIALOG_H
--- a/src/dialogs.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/dialogs.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -84,7 +84,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void OverlayDialog::fillDefaults (int newcam) -{ overlayMeta& info = g_win->R()->getOverlay (newcam); +{ LDGLOverlay& info = g_win->R()->getOverlay (newcam); radioDefault<int> (newcam, m_cameraArgs); if (info.img != null)
--- a/src/dialogs.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/dialogs.h Sat Oct 05 12:51:13 2013 +0300 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef DIALOGS_H -#define DIALOGS_H +#ifndef LDFORGE_DIALOGS_H +#define LDFORGE_DIALOGS_H #include <QDialog> #include "common.h" @@ -135,4 +135,4 @@ void slot_mail(); }; -#endif // DIALOGS_H +#endif // LDFORGE_DIALOGS_H
--- a/src/file.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/file.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -53,8 +53,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- namespace LDPaths -{ - static str pathError; +{ static str pathError; struct { str LDConfigPath; @@ -99,12 +98,15 @@ str getError() { return pathError; } + str ldconfig() { return pathInfo.LDConfigPath; } + str prims() { return pathInfo.primsPath; } + str parts() { return pathInfo.partsPath; } @@ -123,11 +125,11 @@ // ----------------------------------------------------------------------------- LDFile::~LDFile() { // Clear everything from the model -for (LDObject * obj : objects()) + for (LDObject* obj : objects()) delete obj; // Clear the cache as well -for (LDObject * obj : cache()) + for (LDObject* obj : cache()) delete obj; // Remove this file from the list of files @@ -141,18 +143,20 @@ // If we just closed the current file, we need to set the current // file as something else. if (this == LDFile::current()) - { // If we closed the last file, create a blank one. - if (countExplicitFiles() == 0) + { bool found = false; + + // Try find an explicitly loaded file - if we can't find one, + // we need to create a new file to switch to. + for (LDFile* file : g_loadedFiles) + { if (!file->implicit()) + { LDFile::setCurrent (file); + found = true; + break; + } + } + + if (!found) newFile(); - else - { // Find the first explicit file loaded - int idx = 0; - - while (g_loadedFiles[idx]->implicit()) - idx++; - - LDFile::setCurrent (g_loadedFiles[idx]); - } } g_win->updateFileList(); @@ -229,15 +233,16 @@ return f; if (subdirs) - { // Look in sub-directories: parts and p. Also look in net_downloadpath. - for (const str & topdir : initlist<str> ( { io_ldpath, net_downloadpath })) - - for (const str & subdir : initlist<str> ( { "parts", "p" })) + { // Look in sub-directories: parts and p. Also look in net_downloadpath, since that's + // where we download parts from the PT to. + for (const str& topdir : initlist<str> ({ io_ldpath, net_downloadpath })) + { for (const str& subdir : initlist<str> ({ "parts", "p" })) { fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath); if (f->open (fullPath, File::Read)) return f; } + } } // Did not find the file.
--- a/src/gldraw.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/gldraw.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -38,11 +38,7 @@ #include "messagelog.h" #include "moc_gldraw.cpp" -static const struct staticCameraMeta -{ const char glrotate[3]; - const Axis axisX, axisY; - const bool negX, negY; -} g_staticCameras[6] = +static const LDFixedCameraInfo g_FixedCameras[6] = { {{ 1, 0, 0 }, X, Z, false, false }, {{ 0, 0, 0 }, X, Y, false, true }, {{ 0, 1, 0 }, Z, Y, true, true }, @@ -89,12 +85,12 @@ GL::Free }; -const struct GLAxis +const struct LDGLAxis { const QColor col; const vertex vert; } g_GLAxes[3] = { { QColor (255, 0, 0), vertex (10000, 0, 0) }, - { QColor (80, 192, 0), vertex (0, 10000, 0) }, + { QColor (80, 192, 0), vertex (0, 10000, 0) }, { QColor (0, 160, 192), vertex (0, 0, 10000) }, }; @@ -124,7 +120,7 @@ m_thinBorderPen.setWidth (1); // Init camera icons -for (const GL::Camera cam : g_Cameras) + for (const GL::Camera cam : g_Cameras) { str iconname = fmt ("camera-%1", tr (g_CameraNames[cam]).toLower()); CameraIcon* info = &m_cameraIcons[cam]; @@ -146,23 +142,31 @@ { for (int i = 0; i < 6; ++i) delete m_overlays[i].img; -for (CameraIcon & info : m_cameraIcons) + for (CameraIcon& info : m_cameraIcons) delete info.img; } // ============================================================================= +// Calculates the "hitboxes" of the camera icons so that we can tell when the +// cursor is pointing at the camera icon. // ----------------------------------------------------------------------------- void GLRenderer::calcCameraIcons() -{ ushort i = 0; +{ int i = 0; -for (CameraIcon & info : m_cameraIcons) - { const long x1 = (m_width - (info.cam != Free ? 48 : 16)) + ( (i % 3) * 16) - 1, - y1 = ( (i / 3) * 16) + 1; + for (CameraIcon& info : m_cameraIcons) + { // MATH + const long x1 = (m_width - (info.cam != Free ? 48 : 16)) + ((i % 3) * 16) - 1, + y1 = ((i / 3) * 16) + 1; info.srcRect = QRect (0, 0, 16, 16); info.destRect = QRect (x1, y1, 16, 16); - info.selRect = QRect (info.destRect.x(), info.destRect.y(), - info.destRect.width() + 1, info.destRect.height() + 1); + info.selRect = QRect ( + info.destRect.x(), + info.destRect.y(), + info.destRect.width() + 1, + info.destRect.height() + 1 + ); + ++i; } } @@ -293,11 +297,11 @@ qcol = getMainColor(); // Warn about the unknown colors, but only once. - for (short i : g_warnedColors) + for (short i : g_warnedColors) if (obj->color() == i) return; - printf ("%s: Unknown color %d!\n", __func__, obj->color()); + print ("%1: Unknown color %2!\n", __func__, obj->color()); g_warnedColors << obj->color(); return; } @@ -318,10 +322,10 @@ } glColor4f ( - ( (double) r) / 255.0f, - ( (double) g) / 255.0f, - ( (double) b) / 255.0f, - ( (double) a) / 255.0f); + ((double) r) / 255.0f, + ((double) g) / 255.0f, + ((double) b) / 255.0f, + ((double) a) / 255.0f); } // ============================================================================= @@ -376,9 +380,9 @@ glTranslatef (m_panX, m_panY, 0.0f); if (m_camera != Front && m_camera != Back) - { glRotatef (90.0f, g_staticCameras[m_camera].glrotate[0], - g_staticCameras[m_camera].glrotate[1], - g_staticCameras[m_camera].glrotate[2]); + { glRotatef (90.0f, g_FixedCameras[m_camera].glrotate[0], + g_FixedCameras[m_camera].glrotate[1], + g_FixedCameras[m_camera].glrotate[2]); } // Back camera needs to be handled differently @@ -404,7 +408,7 @@ if (gl_colorbfc && !m_picking && !drawOnly()) { glEnable (GL_CULL_FACE); - for (LDObject * obj : file()->objects()) + for (LDObject* obj : file()->objects()) { if (obj->hidden()) continue; @@ -418,7 +422,7 @@ glDisable (GL_CULL_FACE); } else -{ for (LDObject * obj : file()->objects()) + { for (LDObject* obj : file()->objects()) { if (obj->hidden()) continue; @@ -443,7 +447,7 @@ { assert (camera() != Free); vertex pos3d; - const staticCameraMeta* cam = &g_staticCameras[m_camera]; + const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; const Axis axisX = cam->axisX; const Axis axisY = cam->axisY; const short negXFac = cam->negX ? -1 : 1, @@ -476,7 +480,7 @@ // ----------------------------------------------------------------------------- QPoint GLRenderer::coordconv3_2 (const vertex& pos3d) const { GLfloat m[16]; - const staticCameraMeta* cam = &g_staticCameras[m_camera]; + const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; const Axis axisX = cam->axisX; const Axis axisY = cam->axisY; const short negXFac = cam->negX ? -1 : 1, @@ -522,7 +526,7 @@ if (m_camera != Free && !picking()) { // Paint the overlay image if we have one - const overlayMeta& overlay = m_overlays[m_camera]; + const LDGLOverlay& overlay = m_overlays[m_camera]; if (overlay.img != null) { QPoint v0 = coordconv3_2 (m_overlays[m_camera].v0), @@ -752,7 +756,7 @@ glNewList (m_axeslist, GL_COMPILE); glBegin (GL_LINES); -for (const GLAxis & ax : g_GLAxes) +for (const LDGLAxis & ax : g_GLAxes) { qglColor (ax.col); compileVertex (ax.vert); compileVertex (-ax.vert); @@ -1400,7 +1404,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const -{ const staticCameraMeta* cam = &g_staticCameras[m_camera]; +{ const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; relX = cam->axisX; relY = cam->axisY; } @@ -1505,7 +1509,7 @@ { if (camid == (GL::Camera) - 1) camid = m_camera; - const staticCameraMeta* cam = &g_staticCameras[camid]; + const LDFixedCameraInfo* cam = &g_FixedCameras[camid]; return (y) ? cam->axisY : cam->axisX; } @@ -1513,7 +1517,7 @@ // ----------------------------------------------------------------------------- bool GLRenderer::setupOverlay (GL::Camera cam, str file, int x, int y, int w, int h) { QImage* img = new QImage (file); - overlayMeta& info = getOverlay (cam); + LDGLOverlay& info = getOverlay (cam); if (img->isNull()) { critical (tr ("Failed to load overlay image!")); @@ -1539,8 +1543,8 @@ const Axis x2d = cameraAxis (false, cam), y2d = cameraAxis (true, cam); - double negXFac = g_staticCameras[cam].negX ? -1 : 1, - negYFac = g_staticCameras[cam].negY ? -1 : 1; + double negXFac = g_FixedCameras[cam].negX ? -1 : 1, + negYFac = g_FixedCameras[cam].negY ? -1 : 1; info.v0 = info.v1 = g_origin; info.v0[x2d] = - (info.ox * info.lw * negXFac) / img->width(); @@ -1565,7 +1569,7 @@ { if (camera() == Free) return; - overlayMeta& info = m_overlays[camera()]; + LDGLOverlay& info = m_overlays[camera()]; delete info.img; info.img = null; @@ -1594,7 +1598,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -overlayMeta& GLRenderer::getOverlay (int newcam) +LDGLOverlay& GLRenderer::getOverlay (int newcam) { return m_overlays[newcam]; } @@ -1619,8 +1623,8 @@ bool firstrun = true; const uint32 white = 0xFFFFFFFF; bool inward = true; - ulong run = 0; - const ushort w = m_width, h = m_height; + int run = 0; + const int w = m_width, h = m_height; glClearColor (1.0, 1.0, 1.0, 1.0); glDisable (GL_DITHER); @@ -1762,7 +1766,7 @@ { if (cam == Free) continue; - overlayMeta& meta = m_overlays[cam]; + LDGLOverlay& meta = m_overlays[cam]; LDOverlay* ovlobj = findOverlayObject (cam); if (!ovlobj && meta.img) @@ -1781,7 +1785,7 @@ { if (cam == Free) continue; - overlayMeta& meta = m_overlays[cam]; + LDGLOverlay& meta = m_overlays[cam]; LDOverlay* ovlobj = findOverlayObject (cam); if (!meta.img && ovlobj)
--- a/src/gldraw.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/gldraw.h Sat Oct 05 12:51:13 2013 +0300 @@ -39,7 +39,7 @@ }; // Meta for overlays -struct overlayMeta +struct LDGLOverlay { vertex v0, v1; ushort ox, oy; double lw, lh; @@ -47,6 +47,12 @@ QImage* img; }; +struct LDFixedCameraInfo +{ const char glrotate[3]; + const Axis axisX, axisY; + const bool negX, negY; +}; + // ============================================================================= // GLRenderer // @@ -84,7 +90,7 @@ void drawGLScene(); void endDraw (bool accept); QColor getMainColor(); - overlayMeta& getOverlay (int newcam); + LDGLOverlay& getOverlay (int newcam); void hardRefresh(); void initGLData(); void overlaysFromObjects(); @@ -123,28 +129,44 @@ { QPixmap* img; QRect srcRect, destRect, selRect; Camera cam; - } m_cameraIcons[7]; + }; - QTimer* m_toolTipTimer; - Qt::MouseButtons m_lastButtons; + CameraIcon m_cameraIcons[7]; + QTimer* m_toolTipTimer; + Qt::MouseButtons m_lastButtons; Qt::KeyboardModifiers m_keymods; - ulong m_totalmove; - vertex m_hoverpos; - double m_virtWidth, m_virtHeight, m_rotX, m_rotY, m_rotZ, m_panX, m_panY; - bool m_darkbg, m_rangepick, m_addpick, m_drawToolTip, m_screencap; - QPoint m_pos, m_globalpos, m_rangeStart; - QPen m_thickBorderPen, m_thinBorderPen; - Camera m_camera, m_toolTipCamera; - uint m_axeslist; - ushort m_width, m_height; - List<vertex> m_drawedVerts; - bool m_rectdraw; - vertex m_rectverts[4]; - QColor m_bgcolor; - double m_depthValues[6]; - overlayMeta m_overlays[6]; - List<vertex> m_knownVerts; - bool m_panning; + ulong m_totalmove; + vertex m_hoverpos; + double m_virtWidth, + m_virtHeight, + m_rotX, + m_rotY, + m_rotZ, + m_panX, + m_panY; + bool m_darkbg, + m_rangepick, + m_addpick, + m_drawToolTip, + m_screencap; + QPoint m_pos, + m_globalpos, + m_rangeStart; + QPen m_thickBorderPen, + m_thinBorderPen; + Camera m_camera, + m_toolTipCamera; + GLuint m_axeslist; + int m_width, + m_height; + List<vertex> m_drawedVerts; + bool m_rectdraw; + vertex m_rectverts[4]; + QColor m_bgcolor; + double m_depthValues[6]; + LDGLOverlay m_overlays[6]; + List<vertex> m_knownVerts; + bool m_panning; void addDrawnVertex (vertex m_hoverpos); void calcCameraIcons(); // Compute geometry for camera icons
--- a/src/gui.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/gui.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -653,7 +653,7 @@ void ForgeWindow::slot_editObject (QListWidgetItem* listitem) { LDObject* obj = null; -for (LDObject * it : LDFile::current()->objects()) + for (LDObject* it : LDFile::current()->objects()) { if (it->qObjListEntry == listitem) { obj = it; break; @@ -694,13 +694,12 @@ void ForgeWindow::save (LDFile* f, bool saveAs) { str path = f->name(); - if (path.length() == 0 || saveAs) + if (saveAs || path.isEmpty()) { path = QFileDialog::getSaveFileName (g_win, tr ("Save As"), - LDFile::current()->name(), tr ("LDraw files (*.dat *.ldr)")); + LDFile::current()->name(), tr ("LDraw files (*.dat *.ldr)")); - if (path.length() == 0) - { // User didn't give a file name. This happens if the user cancelled - // saving in the save file dialog. Abort. + if (path.isEmpty()) + { // User didn't give a file name, abort. return; } }
--- a/src/gui_actions.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/gui_actions.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -230,12 +230,6 @@ // ============================================================================= // ----------------------------------------------------------------------------- -DEFINE_ACTION (MakePrimitive, 0) -{ generatePrimitive(); -} - -// ============================================================================= -// ----------------------------------------------------------------------------- DEFINE_ACTION (Edit, 0) { if (g_win->sel().size() != 1) return;
--- a/src/history.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/history.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -37,7 +37,7 @@ { if (m_changesets.size() == 0 || pos() == -1) return; - const list& set = changeset (pos()); + const Changeset& set = changeset (pos()); g_fullRefresh = false; // Iterate the list in reverse and undo all actions @@ -60,7 +60,7 @@ { if (pos() == (long) m_changesets.size()) return; - const list& set = changeset (pos() + 1); + const Changeset& set = changeset (pos() + 1); g_fullRefresh = false; // Redo things - in the order as they were done in the first place @@ -80,8 +80,8 @@ // ============================================================================= // ----------------------------------------------------------------------------- void History::clear() -{ for (List<AbstractHistoryEntry*> set : m_changesets) - for (AbstractHistoryEntry* change : set) +{ for (Changeset set : m_changesets) + for (auto change : set) delete change; m_changesets.clear();
--- a/src/history.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/history.h Sat Oct 05 12:51:13 2013 +0300 @@ -37,7 +37,7 @@ READ_PROPERTY (bool, opened, setOpened) public: - typedef List<AbstractHistoryEntry*> list; + typedef List<AbstractHistoryEntry*> Changeset; enum Type { Del, @@ -66,13 +66,13 @@ return *this; } - inline const list& changeset (long pos) const + inline const Changeset& changeset (long pos) const { return m_changesets[pos]; } private: - list m_currentArchive; - List<list> m_changesets; + Changeset m_currentArchive; + List<Changeset> m_changesets; }; // =============================================================================
--- a/src/main.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/main.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -94,18 +94,14 @@ // ============================================================================= // ----------------------------------------------------------------------------- void doPrint (FILE* fp, initlist<StringFormatArg> args) -{ if (fp == stdout) - doPrint (g_file_stdout, args); - - elif (fp == stderr) - doPrint (g_file_stderr, args); - else - fatal ("unknown FILE* argument"); +{ str msg = DoFormat (args); + fwrite (msg.toStdString().c_str(), 1, msg.length(), fp); + fflush (fp); } // ============================================================================= // ----------------------------------------------------------------------------- -str versionString() +QString versionString() { if (g_versionString.length() == 0) { #if VERSION_PATCH == 0 @@ -120,7 +116,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -str versionMoniker() +QString versionMoniker() { #if BUILD_ID == BUILD_INTERNAL return "Internal"; @@ -137,34 +133,17 @@ // ============================================================================= // ----------------------------------------------------------------------------- -str fullVersionString() +QString fullVersionString() { return fmt ("v%1 %2", versionString(), versionMoniker()); } // ============================================================================= // ----------------------------------------------------------------------------- -static void bombBox (str msg) -{ msg.replace ("\n", "<br />"); - - QMessageBox box (null); - const QMessageBox::StandardButton btn = QMessageBox::Close; - box.setWindowTitle ("Fatal Error"); - box.setIconPixmap (getIcon ("bomb")); - box.setWindowIcon (getIcon ("ldforge")); - box.setText (msg); - box.addButton (btn); - box.button (btn)->setText ("Damn it"); - box.setDefaultButton (btn); - box.exec(); -} - -// ============================================================================= -// ----------------------------------------------------------------------------- void assertionFailure (const char* file, const ulong line, const char* funcname, const char* expr) { str errmsg = fmt ("File: %1\nLine: %2:\nFunction %3:\n\nAssertion `%4' failed", file, line, funcname, expr); -#if BUILD_ID == BUILD_INTERNAL +#ifndef RELEASE errmsg += ", aborting."; #else errmsg += "."; @@ -172,27 +151,22 @@ printf ("%s\n", errmsg.toStdString().c_str()); -#if BUILD_ID == BUILD_INTERNAL - +#ifndef RELEASE if (g_win) g_win->deleteLater(); - bombBox (errmsg); + errmsg.replace ("\n", "<br />"); + + QMessageBox box (null); + const QMessageBox::StandardButton btn = QMessageBox::Close; + box.setWindowTitle ("Fatal Error"); + box.setIconPixmap (getIcon ("bomb")); + box.setWindowIcon (getIcon ("ldforge")); + box.setText (errmsg); + box.addButton (btn); + box.button (btn)->setText ("Damn it"); + box.setDefaultButton (btn); + box.exec(); abort(); #endif -} - -// ============================================================================= -// ----------------------------------------------------------------------------- -void fatalError (const char* file, const ulong line, const char* funcname, str msg) -{ str errmsg = fmt ("Aborting over a call to fatal():\nFile: %1\nLine: %2\nFunction: %3\n\n%4", - file, line, funcname, msg); - - print ("%1\n", errmsg); - - if (g_win) - g_win->deleteLater(); - - bombBox (errmsg); - abort(); -} +} \ No newline at end of file
--- a/src/primitives.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/primitives.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -484,48 +484,33 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void generatePrimitive() -{ PrimitivePrompt* dlg = new PrimitivePrompt (g_win); - - if (!dlg->exec()) - return; - - int segs = dlg->ui->sb_segs->value(); - int divs = dlg->ui->cb_hires->isChecked() ? hires : lores; - int num = dlg->ui->sb_ringnum->value(); - PrimitiveType type = - dlg->ui->rb_circle->isChecked() ? Circle : - dlg->ui->rb_cylinder->isChecked() ? Cylinder : - dlg->ui->rb_disc->isChecked() ? Disc : - dlg->ui->rb_ndisc->isChecked() ? DiscNeg : - dlg->ui->rb_ring->isChecked() ? Ring : Cone; - - // Make the description - str frac = ftoa ( ( (float) segs) / divs); +LDFile* generatePrimitive (PrimitiveType type, int segs, int divs, int num) +{ // Make the description + str frac = ftoa (((float) segs) / divs); str name = radialFileName (type, segs, divs, num); str descr; - + // Ensure that there's decimals, even if they're 0. if (frac.indexOf (".") == -1) frac += ".0"; - + if (type == Ring || type == Cone) { str spacing = - (num < 10) ? " " : - (num < 100) ? " " : ""; - + (num < 10) ? " " : + (num < 100) ? " " : ""; + descr = fmt ("%1 %2%3 x %4", primitiveTypeName (type), spacing, num, frac); } else descr = fmt ("%1 %2", primitiveTypeName (type), frac); - + // Prepend "Hi-Res" if 48/ primitive. if (divs == hires) descr.insert (0, "Hi-Res "); - + LDFile* f = new LDFile; f->setName (QFileDialog::getSaveFileName (null, QObject::tr ("Save Primitive"), name)); - + f->addObjects ( { new LDComment (descr), new LDComment (fmt ("Name: %1", name)), @@ -536,19 +521,28 @@ new LDBFC (LDBFC::CertifyCCW), new LDEmpty, }); - + f->addObjects (makePrimitive (type, segs, divs, num)); + return f; +} - g_win->save (f, false); - delete f; +// ============================================================================= +// ----------------------------------------------------------------------------- +LDFile* getPrimitive (PrimitiveType type, int segs, int divs, int num) +{ str name = radialFileName (type, segs, divs, num); + LDFile* f = getFile (name); + if (f != null) + return f; + + return generatePrimitive (type, segs, divs, num); } // ============================================================================= // ----------------------------------------------------------------------------- PrimitivePrompt::PrimitivePrompt (QWidget* parent, Qt::WindowFlags f) : - QDialog (parent, f) +QDialog (parent, f) { - + ui = new Ui_MakePrimUI; ui->setupUi (this); connect (ui->cb_hires, SIGNAL (toggled (bool)), this, SLOT (hiResToggled (bool))); @@ -564,9 +558,33 @@ // ----------------------------------------------------------------------------- void PrimitivePrompt::hiResToggled (bool on) { ui->sb_segs->setMaximum (on ? hires : lores); - + // If the current value is 16 and we switch to hi-res, default the // spinbox to 48. if (on && ui->sb_segs->value() == lores) ui->sb_segs->setValue (hires); } + +// ============================================================================= +// ----------------------------------------------------------------------------- +DEFINE_ACTION (MakePrimitive, 0) +{ PrimitivePrompt* dlg = new PrimitivePrompt (g_win); + + if (!dlg->exec()) + return; + + int segs = dlg->ui->sb_segs->value(); + int divs = dlg->ui->cb_hires->isChecked() ? hires : lores; + int num = dlg->ui->sb_ringnum->value(); + PrimitiveType type = + dlg->ui->rb_circle->isChecked() ? Circle : + dlg->ui->rb_cylinder->isChecked() ? Cylinder : + dlg->ui->rb_disc->isChecked() ? Disc : + dlg->ui->rb_ndisc->isChecked() ? DiscNeg : + dlg->ui->rb_ring->isChecked() ? Ring : Cone; + + LDFile* f = generatePrimitive (type, segs, divs, num); + + g_win->save (f, false); + delete f; +} \ No newline at end of file
--- a/src/primitives.h Thu Oct 03 21:48:11 2013 +0300 +++ b/src/primitives.h Sat Oct 05 12:51:13 2013 +0300 @@ -24,6 +24,7 @@ #include <QRegExp> #include <QDialog> +class LDFile; class Ui_MakePrimUI; class PrimitiveCategory; struct Primitive @@ -103,6 +104,10 @@ void hiResToggled (bool on); }; -void generatePrimitive(); +LDFile* generatePrimitive (PrimitiveType type, int segs, int divs, int num); + +// Gets a primitive by the given specs. If the primitive cannot be found, it will +// be automatically generated. +LDFile* getPrimitive (PrimitiveType type, int segs, int divs, int num); #endif // PRIMITIVES_H
--- a/src/types.cpp Thu Oct 03 21:48:11 2013 +0300 +++ b/src/types.cpp Sat Oct 05 12:51:13 2013 +0300 @@ -411,9 +411,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- bool File::atEnd() const -{ if (!m_textstream) - fatal ("cannot use atEnd on a null file"); - +{ assert (m_textstream != null); return m_textstream->atEnd(); }