Sat, 01 Jun 2013 20:09:31 +0300
Make LDObject's color and parent properties with accessors
--- a/src/addObjectDialog.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/addObjectDialog.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -33,11 +33,6 @@ #include "history.h" #include "widgets.h" -#define APPLY_COORDS(OBJ, N) \ - for (short i = 0; i < N; ++i) \ - for (const Axis ax : g_Axes) \ - OBJ->coords[i][ax] = dlg.dsb_coords[(i * 3) + ax]->value (); - // ============================================================================= class SubfileListItem : public QTreeWidgetItem { public: @@ -198,12 +193,12 @@ // Show a color edit dialog for the types that actually use the color if (defaults->isColored ()) { if (obj != null) - dColor = obj->color; + colnum = obj->color (); else - dColor = (type == LDObject::CondLine || type == LDObject::Line) ? edgecolor : maincolor; + colnum = (type == LDObject::CondLine || type == LDObject::Line) ? edgecolor : maincolor; pb_color = new QPushButton; - setButtonBackground (pb_color, dColor); + setButtonBackground (pb_color, colnum); connect (pb_color, SIGNAL (clicked ()), this, SLOT (slot_colorButtonClicked ())); } @@ -331,8 +326,8 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void AddObjectDialog::slot_colorButtonClicked () { - ColorSelectDialog::staticDialog (dColor, dColor, this); - setButtonBackground (pb_color, dColor); + ColorSelectDialog::staticDialog (colnum, colnum, this); + setButtonBackground (pb_color, colnum); } // ============================================================================= @@ -406,35 +401,15 @@ break; case LDObject::Line: - { - LDLine* line = initObj<LDLine> (obj); - line->color = dlg.dColor; - APPLY_COORDS (line, 2) - } - break; - case LDObject::Triangle: - { - LDTriangle* tri = initObj<LDTriangle> (obj); - tri->color = dlg.dColor; - APPLY_COORDS (tri, 3) - } - break; - case LDObject::Quad: - { - LDQuad* quad = initObj<LDQuad> (obj); - quad->color = dlg.dColor; - APPLY_COORDS (quad, 4) - } - break; - case LDObject::CondLine: - { - LDCondLine* line = initObj<LDCondLine> (obj); - line->color = dlg.dColor; - APPLY_COORDS (line, 4) - } + if (!obj) + obj = LDObject::getDefault (type); + + for (short i = 0; i < obj->vertices (); ++i) + for (const Axis ax : g_Axes) + obj->coords[i][ax] = dlg.dsb_coords[(i * 3) + ax]->value (); break; case LDObject::BFC: @@ -447,7 +422,6 @@ case LDObject::Vertex: { LDVertex* vert = initObj<LDVertex> (obj); - vert->color = dlg.dColor; for (const Axis ax : g_Axes) vert->pos[ax] = dlg.dsb_coords[ax]->value (); @@ -457,7 +431,6 @@ case LDObject::Radial: { LDRadial* pRad = initObj<LDRadial> (obj); - pRad->color = dlg.dColor; for (const Axis ax : g_Axes) pRad->pos[ax] = dlg.dsb_coords[ax]->value (); @@ -483,7 +456,6 @@ } LDSubfile* ref = initObj<LDSubfile> (obj); - ref->color = dlg.dColor; for (const Axis ax : g_Axes) ref->pos[ax] = dlg.dsb_coords[ax]->value (); @@ -498,6 +470,9 @@ break; } + if (obj->isColored ()) + obj->setColor (dlg.colnum); + if (newObject) { ulong idx = g_win->getInsertionPoint (); g_curfile->insertObj (idx, obj);
--- a/src/addObjectDialog.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/addObjectDialog.h Sat Jun 01 20:09:31 2013 +0300 @@ -69,7 +69,7 @@ void setButtonBackground (QPushButton* button, short color); char* currentSubfileName (); - short dColor; + short colnum; private slots: void slot_colorButtonClicked ();
--- a/src/bbox.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/bbox.h Sat Jun 01 20:09:31 2013 +0300 @@ -30,9 +30,9 @@ // v0 is the minimum vertex, v1 is the maximum vertex. // ============================================================================= class bbox { - READ_PROPERTY (bool, empty) - READ_PROPERTY (vertex, v0) - READ_PROPERTY (vertex, v1) + READ_PROPERTY (bool, empty, setEmpty) + READ_PROPERTY (vertex, v0, setV0) + READ_PROPERTY (vertex, v1, setV1) public: bbox ();
--- a/src/common.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/common.h Sat Jun 01 20:09:31 2013 +0300 @@ -86,52 +86,65 @@ #define NDEBUG // remove asserts #endif // RELEASE +#define PROP_NAME(GET) m_##GET + +#define READ_ACCESSOR(T, GET) \ + T const& GET () const { return PROP_NAME (GET); } + +#define SET_ACCESSOR(T, GET, SET) \ + T const& SET (T val) { PROP_NAME (GET) = val; return PROP_NAME (GET); } + // Read-only, private property with a get accessor -#define READ_PROPERTY(T, GET) \ +#define READ_PROPERTY(T, GET, SET) \ private: \ - T m_##GET; \ + T PROP_NAME (GET); \ + SET_ACCESSOR (T, GET, SET) \ public: \ - T const& GET () const { return m_##GET; } \ + READ_ACCESSOR (T, GET) // Same as above except not const #define MUTABLE_READ_PROPERTY(T, GET) \ private: \ - T m_##GET; \ + T PROP_NAME(GET); \ public: \ - T& GET () { return m_##GET; } \ + T& GET () { return PROP_NAME(GET); } // Read/write private property with get and set accessors -#define SET_ACCESSOR(T, GET, SET) \ - void SET (T val) { m_##GET = val; } - #define PROPERTY(T, GET, SET) \ - READ_PROPERTY(T, GET) \ - SET_ACCESSOR(T, GET, SET) - -#define MUTABLE_PROPERTY(T, GET, SET) \ - MUTABLE_READ_PROPERTY(T, GET) \ +private: \ + T PROP_NAME(GET); \ +public: \ + READ_ACCESSOR(T, GET) \ SET_ACCESSOR(T, GET, SET) // Property that triggers a callback when it is changed -#define CALLBACK_PROPERTY(T, GET, SET) \ - READ_PROPERTY(T, GET) \ - void callback_##SET (); \ - void SET (T val) { m_##GET = val; callback_##SET (); } +#define CALLBACK_PROPERTY(T, GET, SET, CALLBACK) \ +private: \ + T PROP_NAME(GET); \ +public: \ + READ_ACCESSOR(T, GET) \ + void CALLBACK (); \ + T const& SET (T val) { \ + PROP_NAME(GET) = val; \ + CALLBACK (); \ + return m_##GET; \ + } // Property with thread locking, use when multiple threads access the same property // Comes with a callback function for detecting when the value is changed. #define THREAD_PROPERTY(T, GET, SET) \ private: \ - T m_##GET; \ + T PROP_NAME (GET); \ QMutex m_threadLock_##GET; \ public: \ - const T& GET () const { return m_##GET; } \ + READ_ACCESSOR(T, GET) \ void callback_##SET (); \ - void SET (T val) { \ + T const& SET (T val) { \ m_threadLock_##GET.lock (); \ - m_##GET = val; \ + PROP_NAME (GET) = val; \ callback_##SET (); \ m_threadLock_##GET.unlock (); \ + return m_##GET; \ } #ifdef null
--- a/src/dialogs.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/dialogs.h Sat Jun 01 20:09:31 2013 +0300 @@ -168,8 +168,8 @@ // ============================================================================= class OpenProgressDialog : public QDialog { Q_OBJECT - READ_PROPERTY (ulong, progress) - CALLBACK_PROPERTY (ulong, numLines, setNumLines) + READ_PROPERTY (ulong, progress, setProgress) + CALLBACK_PROPERTY (ulong, numLines, setNumLines, callback_setNumLines) public: explicit OpenProgressDialog (QWidget* parent = null, Qt::WindowFlags f = 0);
--- a/src/extprogs.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/extprogs.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -155,7 +155,7 @@ void writeColorGroup (const short colnum, str fname) { vector<LDObject*> objects; for (LDObject*& obj : g_curfile->objs ()) { - if (obj->isColored () == false || obj->color != colnum) + if (obj->isColored () == false || obj->color () != colnum) continue; objects << obj;
--- a/src/file.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/file.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -627,7 +627,7 @@ CHECK_TOKEN_NUMBERS (3, 6) LDVertex* obj = new LDVertex; - obj->color = atol (tokens[3]); + obj->setColor (atol (tokens[3])); for (const Axis ax : g_Axes) obj->pos[ax] = atof (tokens[4 + ax]); // 4 - 6 @@ -653,11 +653,11 @@ LDRadial* obj = new LDRadial; - obj->radType = eType; // 3 - obj->color = atol (tokens[4]); // 4 - obj->segs = atol (tokens[5]); // 5 - obj->divs = atol (tokens[6]); // 6 - obj->ringNum = atol (tokens[7]); // 7 + obj->radType = eType; + obj->setColor (atol (tokens[4])); + obj->segs = atol (tokens[5]); + obj->divs = atol (tokens[6]); + obj->ringNum = atol (tokens[7]); obj->pos = parseVertex (tokens, 8); // 8 - 10 @@ -691,7 +691,7 @@ return new LDGibberish (line, "Could not open referred file"); LDSubfile* obj = new LDSubfile; - obj->color = atol (tokens[1]); + obj->setColor (atol (tokens[1])); obj->pos = parseVertex (tokens, 2); // 2 - 4 for (short i = 0; i < 9; ++i) @@ -709,7 +709,7 @@ // Line LDLine* obj = new LDLine; - obj->color = atol (tokens[1]); + obj->setColor (atol (tokens[1])); for (short i = 0; i < 2; ++i) obj->coords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 7 return obj; @@ -722,7 +722,7 @@ // Triangle LDTriangle* obj = new LDTriangle; - obj->color = atol (tokens[1]); + obj->setColor (atol (tokens[1])); for (short i = 0; i < 3; ++i) obj->coords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 10 @@ -737,7 +737,7 @@ // Quadrilateral LDQuad* obj = new LDQuad; - obj->color = atol (tokens[1]); + obj->setColor (atol (tokens[1])); for (short i = 0; i < 4; ++i) obj->coords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 13 @@ -752,7 +752,7 @@ // Conditional line LDCondLine* obj = new LDCondLine; - obj->color = atol (tokens[1]); + obj->setColor (atol (tokens[1])); for (short i = 0; i < 4; ++i) obj->coords[i] = parseVertex (tokens, 2 + (i * 3)); // 2 - 13
--- a/src/file.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/file.h Sat Jun 01 20:09:31 2013 +0300 @@ -126,9 +126,9 @@ class FileLoader : public QObject { Q_OBJECT - READ_PROPERTY (vector<LDObject*>, objs) - READ_PROPERTY (bool, done) - READ_PROPERTY (ulong, progress) + READ_PROPERTY (vector<LDObject*>, objs, setObjects) + READ_PROPERTY (bool, done, setDone) + READ_PROPERTY (ulong, progress, setProgress) PROPERTY (FILE*, filePointer, setFilePointer) PROPERTY (ulong*, warningsPointer, setWarningsPointer)
--- a/src/gldraw.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/gldraw.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -254,34 +254,34 @@ else qcol = QColor (224, 0, 0); } else { - if (obj->color == maincolor) + if (obj->color () == maincolor) qcol = getMainColor (); else { - color* col = getColor (obj->color); + color* col = getColor (obj->color ()); qcol = col->faceColor; } - if (obj->color == edgecolor) { + if (obj->color () == edgecolor) { qcol = luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black; color* col; - if (!gl_blackedges && obj->parent != null && (col = getColor (obj->parent->color)) != null) + if (!gl_blackedges && obj->parent () != null && (col = getColor (obj->parent ()->color ())) != null) qcol = col->edgeColor; } if (qcol.isValid () == false) { // The color was unknown. Use main color to make the object at least // not appear pitch-black. - if (obj->color != edgecolor) + if (obj->color () != edgecolor) qcol = getMainColor (); // Warn about the unknown colors, but only once. for (short i : g_warnedColors) - if (obj->color == i) + if (obj->color () == i) return; - printf ("%s: Unknown color %d!\n", __func__, obj->color); - g_warnedColors << obj->color; + printf ("%s: Unknown color %d!\n", __func__, obj->color ()); + g_warnedColors << obj->color (); return; } } @@ -1232,7 +1232,7 @@ updateRectVerts (); memcpy (quad->coords, m_rectverts, sizeof quad->coords); - quad->color = maincolor; + quad->setColor (maincolor); obj = quad; } else { switch (verts.size ()) { @@ -1240,13 +1240,13 @@ // 1 vertex - add a vertex object obj = new LDVertex; static_cast<LDVertex*> (obj)->pos = verts[0]; - obj->color = maincolor; + obj->setColor (maincolor); break; case 2: // 2 verts - make a line obj = new LDLine; - obj->color = edgecolor; + obj->setColor (edgecolor); for (ushort i = 0; i < 2; ++i) obj->coords[i] = verts[i]; break; @@ -1257,7 +1257,7 @@ static_cast<LDObject*> (new LDTriangle) : static_cast<LDObject*> (new LDQuad); - obj->color = maincolor; + obj->setColor (maincolor); for (ushort i = 0; i < obj->vertices (); ++i) obj->coords[i] = verts[i]; break;
--- a/src/gldraw.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/gldraw.h Sat Jun 01 20:09:31 2013 +0300 @@ -58,8 +58,8 @@ PROPERTY (bool, drawOnly, setDrawOnly) PROPERTY (double, zoom, setZoom) PROPERTY (LDOpenFile*, file, setFile) - READ_PROPERTY (bool, picking) - CALLBACK_PROPERTY (EditMode, editMode, setEditMode) + READ_PROPERTY (bool, picking, setPicking) + CALLBACK_PROPERTY (EditMode, editMode, setEditMode, callback_setEditMode) public: enum Camera { Top, Front, Left, Bottom, Back, Right, Free };
--- a/src/gui.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/gui.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -529,6 +529,8 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::slot_action () { + g_curfile->history ().open (); + // Get the action that triggered this slot. QAction* qAct = static_cast<QAction*> (sender ()); @@ -552,12 +554,14 @@ // We have the meta, now call the handler. (*pMeta->handler) (); + + g_curfile->history ().close (); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void ForgeWindow::deleteSelection (vector<ulong>* indicesPtr, vector<LDObject*>* objsPtr) { +void ForgeWindow::deleteSelection () { if (m_sel.size () == 0) return; @@ -565,11 +569,6 @@ // Delete the objects that were being selected for (LDObject* obj : selCopy) { - if (objsPtr && indicesPtr) { - *objsPtr << obj->clone (); - *indicesPtr << obj->getIndex (g_curfile); - } - g_curfile->forgetObject (obj); delete obj; } @@ -681,11 +680,11 @@ item->setBackground (QColor ("#AA0000")); item->setForeground (QColor ("#FFAA00")); } else if (lv_colorize && obj->isColored () && - obj->color != maincolor && obj->color != edgecolor) + obj->color () != maincolor && obj->color () != edgecolor) { // If the object isn't in the main or edge color, draw this // list entry in said color. - color* col = getColor (obj->color); + color* col = getColor (obj->color ()); if (col) item->setForeground (col->faceColor); } @@ -785,10 +784,10 @@ short newColor = col->index; for (LDObject* obj : m_sel) { - if (obj->color == -1) + if (obj->isColored () == false) continue; // uncolored object - obj->color = newColor; + obj->setColor (newColor); } fullRefresh (); @@ -856,14 +855,14 @@ short result = -1; for (LDObject* obj : m_sel) { - if (obj->color == -1) + if (obj->isColored () == false) continue; // doesn't use color - if (result != -1 && obj->color != result) + if (result != -1 && obj->color () != result) return -1; // No consensus in object color if (result == -1) - result = obj->color; + result = obj->color (); } return result; @@ -876,7 +875,7 @@ LDObject::Type result = LDObject::Unidentified; for (LDObject* obj : m_sel) { - if (result != LDObject::Unidentified && obj->color != result) + if (result != LDObject::Unidentified && obj->color () != result) return LDObject::Unidentified; if (result == LDObject::Unidentified) @@ -943,31 +942,24 @@ } // ======================================================================================================================================== -DelHistory* ForgeWindow::deleteObjVector (vector<LDObject*> objs) { +void ForgeWindow::deleteObjVector (vector<LDObject*> objs) { for (LDObject* obj : objs) { g_curfile->forgetObject (obj); delete obj; } - - return null; } // ======================================================================================================================================== -DelHistory* ForgeWindow::deleteSelection () { - return deleteObjVector (sel ()); -} - -// ======================================================================================================================================== -DelHistory* ForgeWindow::deleteByColor (const short colnum) { +void ForgeWindow::deleteByColor (const short colnum) { vector<LDObject*> objs; for (LDObject* obj : g_curfile->objs ()) { - if (!obj->isColored () || obj->color != colnum) + if (!obj->isColored () || obj->color () != colnum) continue; objs << obj; } - return deleteObjVector (objs); + deleteObjVector (objs); } // ======================================================================================================================================== @@ -1071,10 +1063,10 @@ if (!obj->isColored ()) continue; - if (counts.find (obj->color) == counts.end ()) - counts[obj->color] = 1; + if (counts.find (obj->color ()) == counts.end ()) + counts[obj->color ()] = 1; else - counts[obj->color]++; + counts[obj->color ()]++; } box->clear ();
--- a/src/gui.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/gui.h Sat Jun 01 20:09:31 2013 +0300 @@ -29,7 +29,6 @@ class ForgeWindow; class color; class QSplitter; -class DelHistory; class QToolButton; class QDialogButtonBox; class GLRenderer; @@ -109,7 +108,6 @@ void fullRefresh (); void refresh (); ulong getInsertionPoint (); - void deleteSelection (vector<ulong>* ulapIndices, vector<LDObject*>* papObjects); void updateToolBars (); void updateRecentFilesMenu (); void updateSelection (); @@ -120,9 +118,9 @@ LDObject::Type uniformSelectedType (); void scrollToSelection (); void spawnContextMenu (const QPoint pos); - DelHistory* deleteObjVector (vector<LDObject*> objs); - DelHistory* deleteSelection (); - DelHistory* deleteByColor (const short colnum); + void deleteObjVector (vector< LDObject* > objs); + void deleteSelection (); + void deleteByColor (const short int colnum); GLRenderer* R () { return m_renderer; } vector<LDObject*>& sel () { return m_sel; } void setQuickColorMeta (vector<quickColor>& quickColorMeta) {
--- a/src/gui_actions.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/gui_actions.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -217,14 +217,14 @@ MAKE_ACTION (selectByColor, "Select by Color", "select-color", "Select all objects by the given color.", CTRL_SHIFT (A)) { - short dColor = g_win->getSelectedColor (); + short colnum = g_win->getSelectedColor (); - if (dColor == -1) + if (colnum == -1) return; // no consensus on color g_win->sel ().clear (); for (LDObject* obj : g_curfile->objs ()) - if (obj->color == dColor) + if (obj->color () == colnum) g_win->sel () << obj; g_win->updateSelection ();
--- a/src/gui_editactions.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/gui_editactions.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -42,7 +42,7 @@ static bool copyToClipboard () { vector<LDObject*> objs = g_win->sel (); - if (objs.size() == 0) + if (objs.size () == 0) return false; // Clear the clipboard first. @@ -55,7 +55,7 @@ // separate objects so that modifying the existing ones does not affect // the clipboard. Thus, we add clones of the objects to the clipboard, not // the objects themselves. - for (ulong i = 0; i < objs.size(); ++i) + for (ulong i = 0; i < objs.size (); ++i) g_Clipboard << objs[i]->clone (); return true; @@ -65,13 +65,10 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (cut, "Cut", "cut", "Cut the current selection to clipboard.", CTRL (X)) { - vector<ulong> ulaIndices; - vector<LDObject*> copies; - if (!copyToClipboard ()) return; - g_win->deleteSelection (&ulaIndices, &copies); + g_win->deleteSelection (); } // ============================================================================= @@ -102,7 +99,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (del, "Delete", "delete", "Delete the selection", KEY (Delete)) { - g_win->deleteSelection (null, null); + g_win->deleteSelection (); } // ============================================================================= @@ -130,8 +127,7 @@ // Merge in the inlined objects for (LDObject* inlineobj : objs) { // This object is now inlined so it has no parent anymore. - inlineobj->parent = null; - + inlineobj->setParent (null); g_curfile->insertObj (idx++, inlineobj); } @@ -177,7 +173,7 @@ LDSubfile* prim = new LDSubfile; memcpy (&prim->pos, &rad->pos, sizeof rad->pos); // inherit position memcpy (&prim->transform, &rad->transform, sizeof rad->transform); // inherit matrix - prim->color = rad->color; // inherit color + prim->setColor (rad->color ()); // inherit color prim->fileName = name; prim->fileInfo = file; @@ -276,7 +272,7 @@ if (obj->isColored () == false) continue; - obj->color = colnum; + obj->setColor (colnum); g_win->R ()->compileObject (obj); } @@ -317,9 +313,8 @@ for (short i = 0; i < numLines; ++i) { ulong idx = obj->getIndex (g_curfile) + i + 1; - lines[i]->color = edgecolor; + lines[i]->setColor (edgecolor); g_curfile->insertObj (idx, lines[i]); - g_win->R ()->compileObject (lines[i]); } } @@ -341,7 +336,7 @@ for (short i = 0; i < obj->vertices(); ++i) { LDVertex* vert = new LDVertex; vert->pos = obj->coords[i]; - vert->color = obj->color; + vert->setColor (obj->color ()); g_curfile->insertObj (++idx, vert); g_win->R ()->compileObject (vert); @@ -540,7 +535,7 @@ if (obj->isColored () == false) continue; - obj->color = (obj->getType () == LDObject::Line || obj->getType () == LDObject::CondLine) ? edgecolor : maincolor; + obj->setColor ((obj->getType () == LDObject::Line || obj->getType () == LDObject::CondLine) ? edgecolor : maincolor); } g_win->fullRefresh (); @@ -654,7 +649,7 @@ // ================================================================================================= static bool isColorUsed (short colnum) { for (LDObject* obj : g_curfile->objs ()) - if (obj->isColored () && obj->color == colnum) + if (obj->isColored () && obj->color () == colnum) return true; return false; @@ -675,7 +670,7 @@ if (obj->isColored () == false) continue; - obj->color = colnum; + obj->setColor (colnum); g_win->R ()->compileObject (obj); }
--- a/src/history.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/history.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -46,3 +46,31 @@ ACTION (redo)->setEnabled (false); } +void History::open () { + if (opened ()) + return; + + setOpened (true); +} + +void History::close () { + if (!opened ()) + return; + + setOpened (false); + if (m_currentArchive.size () == 0) + return; + + while (pos () < size () - 1) + m_entries.erase (size () - 1); + + m_entries << m_currentArchive; + m_currentArchive.clear (); + setPos (pos () + 1); + updateActions (); +} + +void History::add (AbstractHistoryEntry* entry) { + assert (opened ()); + m_currentArchive << entry; +} \ No newline at end of file
--- a/src/history.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/history.h Sat Jun 01 20:09:31 2013 +0300 @@ -45,16 +45,30 @@ class History { PROPERTY (long, pos, setPos) + READ_PROPERTY (bool, opened, setOpened) public: + typedef vector<AbstractHistoryEntry*> list; + History (); void undo (); void redo (); void clear (); void updateActions (); + void open (); + void close (); + void add (AbstractHistoryEntry* entry); + long size () const { return m_entries.size (); } + + History& operator<< (AbstractHistoryEntry* entry) { + add (entry); + return *this; + } + private: - vector<vector<AbstractHistoryEntry*>> m_entries; + list m_currentArchive; + vector<list> m_entries; }; // =============================================================================
--- a/src/ldtypes.cpp Sat Jun 01 03:17:52 2013 +0300 +++ b/src/ldtypes.cpp Sat Jun 01 20:09:31 2013 +0300 @@ -61,7 +61,7 @@ // LDObject constructors LDObject::LDObject () { qObjListEntry = null; - parent = null; + setParent (null); m_hidden = false; m_selected = false; m_glinit = false; @@ -78,7 +78,7 @@ } str LDSubfile::getContents () { - str val = fmt ("1 %d %s ", color, pos.stringRep (false).chars ()); + str val = fmt ("1 %d %s ", color (), pos.stringRep (false).chars ()); val += transform.stringRep (); val += ' '; val += fileName; @@ -86,7 +86,7 @@ } str LDLine::getContents () { - str val = fmt ("2 %d", color); + str val = fmt ("2 %d", color ()); for (ushort i = 0; i < 2; ++i) val += fmt (" %s", coords[i].stringRep (false).chars ()); @@ -95,7 +95,7 @@ } str LDTriangle::getContents () { - str val = fmt ("3 %d", color); + str val = fmt ("3 %d", color ()); for (ushort i = 0; i < 3; ++i) val += fmt (" %s", coords[i].stringRep (false).chars ()); @@ -104,7 +104,7 @@ } str LDQuad::getContents () { - str val = fmt ("4 %d", color); + str val = fmt ("4 %d", color ()); for (ushort i = 0; i < 4; ++i) val += fmt (" %s", coords[i].stringRep (false).chars ()); @@ -113,7 +113,7 @@ } str LDCondLine::getContents () { - str val = fmt ("5 %d", color); + str val = fmt ("5 %d", color ()); // Add the coordinates for (ushort i = 0; i < 4; ++i) @@ -127,7 +127,7 @@ } str LDVertex::getContents () { - return fmt ("0 !LDFORGE VERTEX %d %s", color, pos.stringRep (false).chars()); + return fmt ("0 !LDFORGE VERTEX %d %s", color (), pos.stringRep (false).chars()); } str LDEmpty::getContents () { @@ -171,7 +171,7 @@ tri2->coords[2] = coords[3]; // The triangles also inherit the quad's color - tri1->color = tri2->color = color; + tri1->setColor (tri2->setColor (color ())); vector<LDTriangle*> triangles; triangles << tri1; @@ -249,8 +249,8 @@ break; } - if (obj->color == maincolor) - obj->color = parentcolor; + if (obj->color () == maincolor) + obj->setColor (parentcolor); } // ============================================================================= @@ -317,9 +317,9 @@ // Transform the objects for (LDObject* obj : objs) { // Set the parent now so we know what inlined this. - obj->parent = this; + obj->setParent (this); - transformObject (obj, transform, pos, color); + transformObject (obj, transform, pos, color ()); } return objs; @@ -414,13 +414,13 @@ // ============================================================================= LDObject* LDObject::topLevelParent () { - if (!parent) + if (!parent ()) return this; LDObject* it = this; - while (it->parent) - it = it->parent; + while (it->parent ()) + it = it->parent (); return it; } @@ -513,7 +513,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= vector<LDObject*> LDRadial::decompose (bool applyTransform) { - vector<LDObject*> paObjects; + vector<LDObject*> objs; for (short i = 0; i < segs; ++i) { double x0 = cos ((i * 2 * pi) / divs), @@ -532,13 +532,13 @@ v1.transform (transform, pos); } - LDLine* pLine = new LDLine; - pLine->coords[0] = v0; - pLine->coords[1] = v1; - pLine->color = edgecolor; - pLine->parent = this; + LDLine* line = new LDLine; + line->coords[0] = v0; + line->coords[1] = v1; + line->setColor (edgecolor); + line->setParent (this); - paObjects << pLine; + objs << line; } break; @@ -588,15 +588,15 @@ v3.transform (transform, pos); } - LDQuad* pQuad = new LDQuad; - pQuad->coords[0] = v0; - pQuad->coords[1] = v1; - pQuad->coords[2] = v2; - pQuad->coords[3] = v3; - pQuad->color = color; - pQuad->parent = this; + LDQuad* quad = new LDQuad; + quad->coords[0] = v0; + quad->coords[1] = v1; + quad->coords[2] = v2; + quad->coords[3] = v3; + quad->setColor (color ()); + quad->setParent (this); - paObjects << pQuad; + objs << quad; } break; @@ -622,14 +622,14 @@ v2.transform (transform, pos); } - LDTriangle* pSeg = new LDTriangle; - pSeg->coords[0] = v0; - pSeg->coords[1] = v1; - pSeg->coords[2] = v2; - pSeg->color = color; - pSeg->parent = this; + LDTriangle* seg = new LDTriangle; + seg->coords[0] = v0; + seg->coords[1] = v1; + seg->coords[2] = v2; + seg->setColor (color ()); + seg->setParent (this); - paObjects << pSeg; + objs << seg; } break; @@ -638,7 +638,7 @@ } } - return paObjects; + return objs; } // ============================================================================= @@ -647,7 +647,7 @@ str LDRadial::getContents () { return fmt ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s", str (radialTypeName()).upper ().strip (' ').c (), - color, segs, divs, ringNum, + color (), segs, divs, ringNum, pos.stringRep (false).chars(), transform.stringRep().chars()); } @@ -798,7 +798,7 @@ LDLine* LDCondLine::demote () { LDLine* repl = new LDLine; memcpy (repl->coords, coords, sizeof coords); - repl->color = color; + repl->setColor (color ()); replace (repl); return repl;
--- a/src/ldtypes.h Sat Jun 01 03:17:52 2013 +0300 +++ b/src/ldtypes.h Sat Jun 01 20:09:31 2013 +0300 @@ -77,6 +77,8 @@ class LDObject { PROPERTY (bool, hidden, setHidden) PROPERTY (bool, selected, setSelected) + PROPERTY (short, color, setColor) + PROPERTY (LDObject*, parent, setParent) public: // Object type codes. Codes are sorted in order of significance. @@ -102,19 +104,12 @@ // Index (i.e. line number) of this object long getIndex (LDOpenFile* pFile) const; - // Color used by this object. Comments, gibberish and empty entries - // do not use this field. - short color; - // OpenGL list for this object uint glLists[4]; // Vertices of this object vertex coords[4]; - // Object this object was referenced from, if any - LDObject* parent; - // Type enumerator of this object virtual LDObject::Type getType () const { return LDObject::Unidentified;