Mon, 06 May 2013 00:10:56 +0300
cleanup
bbox.cpp | file | annotate | diff | comparison | revisions | |
bbox.h | file | annotate | diff | comparison | revisions | |
file.cpp | file | annotate | diff | comparison | revisions | |
gldraw.cpp | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.h | file | annotate | diff | comparison | revisions | |
zz_addObjectDialog.cpp | file | annotate | diff | comparison | revisions |
--- a/bbox.cpp Sun May 05 17:04:42 2013 +0300 +++ b/bbox.cpp Mon May 06 00:10:56 2013 +0300 @@ -112,29 +112,33 @@ // ============================================================================= void bbox::calcVertex (vertex v) { for (const Axis ax : g_Axes) { - if (v[ax] < v0[ax]) - v0[ax] = v[ax]; + if (v[ax] < m_v0[ax]) + m_v0[ax] = v[ax]; - if (v[ax] > v1[ax]) - v1[ax] = v[ax]; + if (v[ax] > m_v1[ax]) + m_v1[ax] = v[ax]; } + + m_empty = false; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void bbox::reset () { - v0[X] = v0[Y] = v0[Z] = +0x7FFFFFFF; - v1[X] = v1[Y] = v1[Z] = -0x7FFFFFFF; + m_v0[X] = m_v0[Y] = m_v0[Z] = +0x7FFFFFFF; + m_v1[X] = m_v1[Y] = m_v1[Z] = -0x7FFFFFFF; + + m_empty = true; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= double bbox::size () const { - double fXScale = (v0[X] - v1[X]); - double fYScale = (v0[Y] - v1[Y]); - double fZScale = (v0[Z] - v1[Z]); + double fXScale = (m_v0[X] - m_v1[X]); + double fYScale = (m_v0[Y] - m_v1[Y]); + double fZScale = (m_v0[Z] - m_v1[Z]); double fSize = fZScale; if (fXScale > fYScale) { @@ -152,7 +156,12 @@ // ============================================================================= vertex bbox::center () const { return vertex ( - (v0[X] + v1[X]) / 2, - (v0[Y] + v1[Y]) / 2, - (v0[Z] + v1[Z]) / 2); + (m_v0[X] + m_v1[X]) / 2, + (m_v0[Y] + m_v1[Y]) / 2, + (m_v0[Z] + m_v1[Z]) / 2); +} + +// ============================================================================= +bool bbox::empty() const { + return m_empty; } \ No newline at end of file
--- a/bbox.h Sun May 05 17:04:42 2013 +0300 +++ b/bbox.h Mon May 06 00:10:56 2013 +0300 @@ -31,16 +31,14 @@ // ============================================================================= class bbox { public: - vertex v0, v1; - bbox (); - void reset (); void calculate (); double size () const; void calcObject (LDObject* obj); void calcVertex (vertex v); vertex center () const; + bool empty () const; bbox& operator<< (LDObject* obj) { calcObject (obj); @@ -51,6 +49,13 @@ calcVertex (v); return *this; } + + const vertex& v0 () { return m_v0; } + const vertex& v1 () { return m_v1; } + +private: + vertex m_v0, m_v1; + bool m_empty; }; #endif // BBOX_H \ No newline at end of file
--- a/file.cpp Sun May 05 17:04:42 2013 +0300 +++ b/file.cpp Mon May 06 00:10:56 2013 +0300 @@ -404,7 +404,7 @@ // Handle BFC statements if (tokens.size() > 2 && tokens[1] == "BFC") { for (short i = 0; i < LDBFC::NumStatements; ++i) - if (comm == fmt ("BFC %s", LDBFC::saStatements [i])) + if (comm == fmt ("BFC %s", LDBFC::statements [i])) return new LDBFC ((LDBFC::Type) i); // MLCAD is notorious for stuffing these statements in parts it @@ -465,7 +465,7 @@ } LDComment* obj = new LDComment; - obj->zText = comm; + obj->text = comm; return obj; }
--- a/gldraw.cpp Sun May 05 17:04:42 2013 +0300 +++ b/gldraw.cpp Mon May 06 00:10:56 2013 +0300 @@ -213,7 +213,10 @@ // ============================================================================= static vector<short> g_daWarnedColors; void GLRenderer::setObjectColor (LDObject* obj) { - QColor qCol; + QColor qcol; + + if (!obj->isColored()) + return; if (m_picking) { // Make the color by the object's index color if we're picking, so we can @@ -241,9 +244,6 @@ return; } - if (obj->dColor == -1) - return; - #if 0 if (gl_colorbfc && obj->getType () != OBJ_Line && @@ -258,25 +258,25 @@ #endif if (obj->dColor == maincolor) - qCol = getMainColor (); + qcol = getMainColor (); else { color* col = getColor (obj->dColor); - qCol = col->qColor; + qcol = col->qColor; } if (obj->dColor == edgecolor) { - qCol = Qt::black; + qcol = Qt::black; color* col; if (!gl_blackedges && obj->parent != null && (col = getColor (obj->parent->dColor)) != null) - qCol = col->qEdge; + qcol = col->qEdge; } - if (qCol.isValid () == false) { + if (qcol.isValid () == false) { // The color was unknown. Use main color to make the object at least // not appear pitch-black. if (obj->dColor != edgecolor) - qCol = getMainColor (); + qcol = getMainColor (); // Warn about the unknown colors, but only once. for (short i : g_daWarnedColors) @@ -288,10 +288,10 @@ return; } - long r = qCol.red (), - g = qCol.green (), - b = qCol.blue (), - a = qCol.alpha (); + long r = qcol.red (), + g = qcol.green (), + b = qcol.blue (), + a = qcol.alpha (); // If it's selected, brighten it up, also pulse flash it if desired. if (g_win->isSelected (obj)) { @@ -608,10 +608,17 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::compileObjects () { - g_objOffset[0] = -(g_BBox.v0[X] + g_BBox.v1[X]) / 2; - g_objOffset[1] = -(g_BBox.v0[Y] + g_BBox.v1[Y]) / 2; - g_objOffset[2] = -(g_BBox.v0[Z] + g_BBox.v1[Z]) / 2; - g_storedBBoxSize = g_BBox.size (); + if (g_BBox.empty () == false) { + g_objOffset[X] = -(g_BBox.v0 ()[X] + g_BBox.v1 ()[X]) / 2; + g_objOffset[Y] = -(g_BBox.v0 ()[Y] + g_BBox.v1 ()[Y]) / 2; + g_objOffset[Z] = -(g_BBox.v0 ()[Z] + g_BBox.v1 ()[Z]) / 2; + g_storedBBoxSize = g_BBox.size (); + } else { + // use a default bbox if we need + g_objOffset[X] = g_objOffset[Y] = g_objOffset[Z] = 0; + g_storedBBoxSize = 5.0f; + } + printf ("size: %.3f\n", g_storedBBoxSize); if (!g_curfile) { printf ("renderer: no files loaded, cannot compile anything\n"); @@ -784,8 +791,6 @@ if (wasLeft) { if (m_planeDraw) { - printf ("vert: %s\n", m_hoverpos.stringRep (true).chars ()); - // If we picked an already-existing vertex, stop drawing for (vertex& vert : m_planeDrawVerts) { if (vert == m_hoverpos) { @@ -1094,8 +1099,6 @@ // If we accepted, clean the selection and create the object if (accept) { vector<vertex>& verts = m_planeDrawVerts; - printf ("accepted (%lu verts)\n", verts.size ()); - LDObject* obj = null; switch (verts.size ()) {
--- a/gui.cpp Sun May 05 17:04:42 2013 +0300 +++ b/gui.cpp Mon May 06 00:10:56 2013 +0300 @@ -460,7 +460,7 @@ { // Append title LDComment* comm = static_cast<LDComment*> (g_curfile->m_objs[0]); - title += fmt (": %s", comm->zText.chars()); + title += fmt (": %s", comm->text.chars()); } if (History::pos () != g_curfile->savePos) @@ -537,7 +537,7 @@ str zText; switch (obj->getType ()) { case OBJ_Comment: - zText = static_cast<LDComment*> (obj)->zText.chars(); + zText = static_cast<LDComment*> (obj)->text.chars(); // Remove leading whitespace while (~zText && zText[0] == ' ') @@ -616,7 +616,7 @@ case OBJ_BFC: { LDBFC* bfc = static_cast<LDBFC*> (obj); - zText = LDBFC::saStatements[bfc->eStatement]; + zText = LDBFC::statements[bfc->type]; } break; @@ -644,7 +644,7 @@ if (obj->getType() == OBJ_Gibberish) { item->setBackground (QColor ("#AA0000")); item->setForeground (QColor ("#FFAA00")); - } else if (lv_colorize && obj->dColor != -1 && + } else if (lv_colorize && obj->isColored () && obj->dColor != maincolor && obj->dColor != edgecolor) { // If the object isn't in the main or edge color, draw this @@ -898,8 +898,8 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -QPixmap getIcon (const char* sIconName) { - return (QPixmap (fmt (":/icons/%s.png", sIconName))); +QPixmap getIcon (const char* iconName) { + return (QPixmap (fmt (":/icons/%s.png", iconName))); } // ============================================================================= @@ -976,7 +976,7 @@ } // ============================================================================= -QAction* const& findAction (str name) { +QAction* findAction (str name) { for (actionmeta& meta : g_ActionMeta) if (name == meta.name) return *meta.qAct;
--- a/gui.h Sun May 05 17:04:42 2013 +0300 +++ b/gui.h Mon May 06 00:10:56 2013 +0300 @@ -190,17 +190,10 @@ bool confirm (str title, str msg); bool confirm (str msg); void critical (str msg); -QAction* const& findAction (str name); +QAction* findAction (str name); // ----------------------------------------------------------------------------- // Pointer to the instance of ForgeWindow. extern ForgeWindow* g_win; -// Is this still needed? -enum { - LDOLC_Icon, - LDOLC_Data, - NUM_LDOL_Columns -}; - #endif // GUI_H \ No newline at end of file
--- a/gui_editactions.cpp Sun May 05 17:04:42 2013 +0300 +++ b/gui_editactions.cpp Mon May 06 00:10:56 2013 +0300 @@ -519,7 +519,7 @@ LDObject* prev = g_curfile->object (idx - 1); LDBFC* bfc = dynamic_cast<LDBFC*> (prev); - if (bfc && bfc->eStatement == LDBFC::InvertNext) { + if (bfc && bfc->type == LDBFC::InvertNext) { // Object is prefixed with an invertnext, thus remove it. paHistory.push_back (new DelHistory ({idx - 1}, {bfc->clone ()}));
--- a/ldtypes.cpp Sun May 05 17:04:42 2013 +0300 +++ b/ldtypes.cpp Mon May 06 00:10:56 2013 +0300 @@ -62,55 +62,14 @@ parent = null; } -LDGibberish::LDGibberish () { - dColor = -1; -} - LDGibberish::LDGibberish (str _zContent, str _zReason) { zContents = _zContent; zReason = _zReason; - dColor = -1; -} - -LDEmpty::LDEmpty () { - dColor = -1; -} - -LDComment::LDComment () { - dColor = -1; -} - -LDSubfile::LDSubfile () { - -} - -LDLine::LDLine () { - -} - -LDTriangle::LDTriangle () { - -} - -LDQuad::LDQuad () { - -} - -LDCondLine::LDCondLine () { - -} - -LDVertex::LDVertex () { - -} - -LDBFC::LDBFC () { - } // ============================================================================= str LDComment::getContents () { - return fmt ("0 %s", zText.chars ()); + return fmt ("0 %s", text.chars ()); } str LDSubfile::getContents () { @@ -173,7 +132,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -const char* LDBFC::saStatements[] = { +const char* LDBFC::statements[] = { "CERTIFY CCW", "CCW", "CERTIFY CW", @@ -183,7 +142,7 @@ }; str LDBFC::getContents () { - return fmt ("0 BFC %s", LDBFC::saStatements[eStatement]); + return fmt ("0 BFC %s", LDBFC::statements[type]); } // ============================================================================= @@ -252,18 +211,6 @@ g_win->sel ().erase (g_win->sel ().begin() + i); } -LDComment::~LDComment () {} -LDCondLine::~LDCondLine () {} -LDEmpty::~LDEmpty () {} -LDGibberish::~LDGibberish () {} -LDLine::~LDLine () {} -LDQuad::~LDQuad () {} -LDSubfile::~LDSubfile () {} -LDTriangle::~LDTriangle () {} -LDVertex::~LDVertex () {} -LDBFC::~LDBFC () {} -LDRadial::~LDRadial () {} - // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= @@ -321,7 +268,7 @@ case OBJ_BFC: // Filter non-INVERTNEXT statements - if (static_cast<LDBFC*> (obj)->eStatement != LDBFC::InvertNext) + if (static_cast<LDBFC*> (obj)->type != LDBFC::InvertNext) continue; break; @@ -502,10 +449,6 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -LDRadial::LDRadial () { - -} - static char const* g_saRadialTypeNames[] = { "Circle", "Cylinder", @@ -683,7 +626,7 @@ short dNumerator = dSegments, dDenominator = dDivisions; - // Simplify the fractional part, but the denominator is at least 4. + // Simplify the fractional part, but the denominator must be at least 4. simplify (dNumerator, dDenominator); if (dDenominator < 4) {
--- a/ldtypes.h Sun May 05 17:04:42 2013 +0300 +++ b/ldtypes.h Mon May 06 00:10:56 2013 +0300 @@ -23,8 +23,8 @@ #include "types.h" #define IMPLEMENT_LDTYPE(T, NUMVERTS) \ - LD##T (); \ - virtual ~LD##T (); \ + LD##T () {} \ + virtual ~LD##T () {} \ virtual LDObjectType_e getType () const { \ return OBJ_##T; \ } \ @@ -35,7 +35,9 @@ virtual void move (vertex vVector); \ virtual short vertices () const { return NUMVERTS; } \ -#define LDOBJ_COLORED(V) virtual bool isColored () 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) class QListWidgetItem; class LDSubfile; @@ -149,7 +151,7 @@ class LDGibberish : public LDObject { public: IMPLEMENT_LDTYPE (Gibberish, 0) - LDOBJ_COLORED (false) + LDOBJ_UNCOLORED LDGibberish (str _zContent, str _zReason); @@ -168,7 +170,7 @@ class LDEmpty : public LDObject { public: IMPLEMENT_LDTYPE (Empty, 0) - LDOBJ_COLORED (false) + LDOBJ_UNCOLORED }; // ============================================================================= @@ -180,11 +182,11 @@ class LDComment : public LDObject { public: IMPLEMENT_LDTYPE (Comment, 0) - LDOBJ_COLORED (false) + LDOBJ_UNCOLORED - LDComment (str zText) : zText (zText) {} + LDComment (str zText) : text (zText) {} - str zText; // The text of this comment + str text; // The text of this comment }; // ============================================================================= @@ -206,14 +208,14 @@ }; IMPLEMENT_LDTYPE (BFC, 0) - LDOBJ_COLORED (false) + LDOBJ_UNCOLORED - LDBFC (const LDBFC::Type eType) : eStatement (eType) {} + LDBFC (const LDBFC::Type eType) : type (eType) {} // Statement strings - static const char* saStatements[]; + static const char* statements[]; - Type eStatement; + Type type; }; // ============================================================================= @@ -224,14 +226,15 @@ class LDSubfile : public LDObject { public: IMPLEMENT_LDTYPE (Subfile, 0) - LDOBJ_COLORED (true) + LDOBJ_COLORED - vertex vPosition; // Position of the subpart + vertex vPosition; // Position of the subpart (FIXME: should get rid of this) matrix<3> mMatrix; // Transformation matrix for the subpart str zFileName; // Filename of the subpart OpenFile* pFile; // Pointer to opened file for this subfile. null if unopened. - // Gets the inlined contents of this subfile. + // Inlines this subfile. Note that return type is an array of heap-allocated + // LDObject-clones, they must be deleted one way or another. std::vector<LDObject*> inlineContents (bool bDeepInline, bool bCache); }; @@ -245,7 +248,7 @@ class LDLine : public LDObject { public: IMPLEMENT_LDTYPE (Line, 2) - LDOBJ_COLORED (true) + LDOBJ_COLORED LDLine (vertex v1, vertex v2); }; @@ -259,7 +262,7 @@ class LDCondLine : public LDLine { public: IMPLEMENT_LDTYPE (CondLine, 4) - LDOBJ_COLORED (true) + LDOBJ_COLORED }; // ============================================================================= @@ -272,7 +275,7 @@ class LDTriangle : public LDObject { public: IMPLEMENT_LDTYPE (Triangle, 3) - LDOBJ_COLORED (true) + LDOBJ_COLORED LDTriangle (vertex _v0, vertex _v1, vertex _v2) { vaCoords[0] = _v0; @@ -290,9 +293,9 @@ class LDQuad : public LDObject { public: IMPLEMENT_LDTYPE (Quad, 4) - LDOBJ_COLORED (true) + LDOBJ_COLORED - // Split this quad into two triangles + // Split this quad into two triangles (note: heap-allocated) vector<LDTriangle*> splitToTriangles (); }; @@ -307,7 +310,7 @@ class LDVertex : public LDObject { public: IMPLEMENT_LDTYPE (Vertex, 0) // TODO: move vPosition to vaCoords[0] - LDOBJ_COLORED (true) + LDOBJ_COLORED vertex vPosition; }; @@ -334,7 +337,7 @@ }; IMPLEMENT_LDTYPE (Radial, 0) - LDOBJ_COLORED (true) + LDOBJ_COLORED LDRadial::Type eRadialType; vertex vPosition; @@ -346,10 +349,14 @@ eRadialType (eRadialType), vPosition (vPosition), mMatrix (mMatrix), dDivisions (dDivisions), dSegments (dSegments), dRingNum (dRingNum) {} - char const* radialTypeName (); + // Returns a set of objects that provide the equivalent of this radial. + // Note: objects are heap-allocated. std::vector<LDObject*> decompose (bool bTransform); + + // Compose a file name for this radial. str makeFileName (); + char const* radialTypeName (); static char const* radialTypeName (const LDRadial::Type eType); };
--- a/zz_addObjectDialog.cpp Sun May 05 17:04:42 2013 +0300 +++ b/zz_addObjectDialog.cpp Mon May 06 00:10:56 2013 +0300 @@ -59,7 +59,7 @@ case OBJ_Comment: le_comment = new QLineEdit; if (obj) - le_comment->setText (static_cast<LDComment*> (obj)->zText); + le_comment->setText (static_cast<LDComment*> (obj)->text); break; case OBJ_Line: @@ -80,17 +80,13 @@ break; case OBJ_BFC: - rb_bfcType = new RadioBox ("Statement", {}, 0, Qt::Horizontal); + rb_bfcType = new RadioBox ("Statement", {}, 0, Qt::Vertical); - for (int i = 0; i < LDBFC::NumStatements; ++i) { - if (i % (LDBFC::NumStatements / 2) == 0) - rb_bfcType->rowBreak (); - - rb_bfcType->addButton (new QRadioButton (LDBFC::saStatements[i])); - } + for (int i = 0; i < LDBFC::NumStatements; ++i) + rb_bfcType->addButton (new QRadioButton (LDBFC::statements[i])); if (obj) - rb_bfcType->setValue ((int) static_cast<LDBFC*> (obj)->eStatement); + rb_bfcType->setValue ((int) static_cast<LDBFC*> (obj)->type); break; case OBJ_Subfile: @@ -358,7 +354,7 @@ case OBJ_Comment: { LDComment* comm = initObj<LDComment> (obj); - comm->zText = dlg.le_comment->text (); + comm->text = dlg.le_comment->text (); } break; @@ -397,7 +393,7 @@ case OBJ_BFC: { LDBFC* bfc = initObj<LDBFC> (obj); - bfc->eStatement = (LDBFC::Type) dlg.rb_bfcType->value (); + bfc->type = (LDBFC::Type) dlg.rb_bfcType->value (); } break;