# HG changeset patch # User Santeri Piippo # Date 1369398236 -10800 # Node ID c4b96bc41298cd3828de8c9e1a067407d078600d # Parent 6e80f038e8df209e9709ad2353535acc23519b23 Made a vector class which wraps around std::vector... finally I have an operator<< for the thing. diff -r 6e80f038e8df -r c4b96bc41298 src/configDialog.cpp --- a/src/configDialog.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/configDialog.cpp Fri May 24 15:23:56 2013 +0300 @@ -442,7 +442,7 @@ else idx = quickColorItems.size(); - quickColorMeta.insert (quickColorMeta.begin() + idx, entry); + quickColorMeta.insert (idx, entry); entry = quickColorMeta[idx]; } @@ -456,9 +456,8 @@ if (lw_quickColors->selectedItems().size() == 0) return; - QListWidgetItem* qItem = lw_quickColors->selectedItems ()[0]; - ulong ulIdx = getItemRow (qItem, quickColorItems); - quickColorMeta.erase (quickColorMeta.begin () + ulIdx); + QListWidgetItem* item = lw_quickColors->selectedItems ()[0]; + quickColorMeta.erase (getItemRow (item, quickColorItems)); updateQuickColorList (); } @@ -543,7 +542,7 @@ } // ============================================================================= -long ConfigDialog::getItemRow (QListWidgetItem* qItem, std::vector& haystack) { +long ConfigDialog::getItemRow (QListWidgetItem* qItem, vector& haystack) { long i = 0; for (QListWidgetItem* it : haystack) { diff -r 6e80f038e8df -r c4b96bc41298 src/configDialog.h --- a/src/configDialog.h Fri May 24 04:34:20 2013 +0300 +++ b/src/configDialog.h Fri May 24 15:23:56 2013 +0300 @@ -68,8 +68,8 @@ QListWidget* lw_quickColors; QPushButton* pb_addColor, *pb_delColor, *pb_changeColor, *pb_addColorSeparator, *pb_moveColorUp, *pb_moveColorDown, *pb_clearColors; - std::vector quickColorItems; - std::vector quickColorMeta; + vector quickColorItems; + vector quickColorMeta; // ========================================================================= // Grid tab @@ -95,7 +95,7 @@ void pickColor (strconfig& cfg, QPushButton* qButton); void updateQuickColorList (quickColorMetaEntry* pSel = null); void setShortcutText (QListWidgetItem* qItem, actionmeta meta); - long getItemRow (QListWidgetItem* qItem, std::vector& haystack); + long getItemRow (QListWidgetItem* qItem, vector& haystack); str makeColorToolBarString (); QListWidgetItem* getSelectedQuickColor (); QList getShortcutSelection (); diff -r 6e80f038e8df -r c4b96bc41298 src/dialogs.cpp --- a/src/dialogs.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/dialogs.cpp Fri May 24 15:23:56 2013 +0300 @@ -115,7 +115,7 @@ } void OverlayDialog::fillDefaults (int newcam) { - overlayMeta& info = g_overlays[newcam]; + overlayMeta& info = g_win->R ()->getOverlay (newcam); if (info.img != null) { le_fpath->setText (info.fname); @@ -409,17 +409,17 @@ (idx == NonCA) ? "Not redistributable : see NonCAreadme.txt" : null; - objs.push_back (new LDComment (dlg.le_name->text ())); - objs.push_back (new LDComment ("Name: .dat")); - objs.push_back (new LDComment (fmt ("Author: %s", author.chars()))); - objs.push_back (new LDComment (fmt ("!LDRAW_ORG Unofficial_Part"))); + objs << new LDComment (dlg.le_name->text ()); + objs << new LDComment ("Name: .dat"); + objs << new LDComment (fmt ("Author: %s", author.chars())); + objs << new LDComment (fmt ("!LDRAW_ORG Unofficial_Part")); if (license != null) - objs.push_back (new LDComment (fmt ("!LICENSE %s", license))); + objs << new LDComment (fmt ("!LICENSE %s", license)); - objs.push_back (new LDEmpty); - objs.push_back (new LDBFC (BFCType)); - objs.push_back (new LDEmpty); + objs << new LDEmpty; + objs << new LDBFC (BFCType); + objs << new LDEmpty; g_win->fullRefresh (); } diff -r 6e80f038e8df -r c4b96bc41298 src/dialogs.h --- a/src/dialogs.h Fri May 24 04:34:20 2013 +0300 +++ b/src/dialogs.h Fri May 24 15:23:56 2013 +0300 @@ -66,7 +66,7 @@ public: explicit ReplaceCoordsDialog (QWidget* parent = null, Qt::WindowFlags f = 0); - std::vector< int > axes () const; + vector< int > axes () const; double searchValue () const; double replacementValue () const; diff -r 6e80f038e8df -r c4b96bc41298 src/extprogs.cpp --- a/src/extprogs.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/extprogs.cpp Fri May 24 15:23:56 2013 +0300 @@ -106,7 +106,7 @@ } // ============================================================================= -void writeObjects (std::vector& objects, FILE* fp) { +void writeObjects (vector& objects, FILE* fp) { for (LDObject* obj : objects) { if (obj->getType () == LDObject::Subfile) { vector objs = static_cast (obj)->inlineContents (true, false); @@ -127,7 +127,7 @@ } } -void writeObjects (std::vector& objects, str fname) { +void writeObjects (vector& objects, str fname) { // Write the input file FILE* fp = fopen (fname, "w"); if (!fp) { @@ -153,7 +153,7 @@ // ============================================================================= void writeColorGroup (const short colnum, str fname) { - std::vector objects; + vector objects; for (LDObject*& obj : g_curfile->objs ()) { if (obj->isColored () == false || obj->color != colnum) continue; @@ -217,9 +217,9 @@ } ComboHistory* cmb = new ComboHistory (); - std::vector objs = loadFileContents (fp, null), + vector objs = loadFileContents (fp, null), copies; - std::vector indices; + vector indices; // If we replace the objects, delete the selection now. if (replace) diff -r 6e80f038e8df -r c4b96bc41298 src/file.cpp --- a/src/file.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/file.cpp Fri May 24 15:23:56 2013 +0300 @@ -237,7 +237,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -std::vector loadFileContents (FILE* fp, ulong* numWarnings, bool* ok) { +vector loadFileContents (FILE* fp, ulong* numWarnings, bool* ok) { vector lines; vector objs; @@ -323,7 +323,7 @@ ulong numWarnings; bool ok; - std::vector objs = loadFileContents (fp, &numWarnings, &ok); + vector objs = loadFileContents (fp, &numWarnings, &ok); if (!ok) { load = oldLoad; @@ -831,7 +831,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void LDOpenFile::insertObj (const ulong pos, LDObject* obj) { - m_objs.insert (m_objs.begin () + pos, obj); + m_objs.insert (pos, obj); if (this == g_curfile) g_BBox.calcObject (obj); @@ -842,16 +842,16 @@ // ============================================================================= void LDOpenFile::forgetObject (LDObject* obj) { // Find the index for the given object - ulong ulIndex; - for (ulIndex = 0; ulIndex < (ulong)m_objs.size(); ++ulIndex) - if (m_objs[ulIndex] == obj) + ulong idx; + for (idx = 0; idx < (ulong)m_objs.size(); ++idx) + if (m_objs[idx] == obj) break; // found it - if (ulIndex >= m_objs.size ()) + if (idx >= m_objs.size ()) return; // was not found // Erase it from memory - m_objs.erase (m_objs.begin() + ulIndex); + m_objs.erase (idx); // Update the bounding box if (this == g_curfile) @@ -861,7 +861,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -std::vector g_PartList; +vector g_PartList; void initPartList () { logf ("%s: initializing parts.lst\n", __func__); diff -r 6e80f038e8df -r c4b96bc41298 src/file.h --- a/src/file.h Fri May 24 04:34:20 2013 +0300 +++ b/src/file.h Fri May 24 15:23:56 2013 +0300 @@ -51,9 +51,6 @@ PROPERTY (long, savePos, setSavePos) public: - typedef std::vector::iterator it; - typedef std::vector::const_iterator c_it; - LDOpenFile (); ~LDOpenFile (); @@ -75,11 +72,6 @@ void insertObj (const ulong pos, LDObject* obj); ulong numObjs () const { return m_objs.size (); } void setObject (ulong idx, LDObject* obj); - - it begin () { return m_objs.begin (); } - it end () { return m_objs.end (); } - c_it cbegin () const { return m_objs.cbegin (); } - c_it cend () const { return m_objs.cend (); } }; // Close all current loaded files and start off blank. @@ -120,7 +112,7 @@ // Init and parse parts.lst void initPartList (); -std::vector loadFileContents (FILE* fp, ulong* numWarnings, bool* ok = null); +vector loadFileContents (FILE* fp, ulong* numWarnings, bool* ok = null); extern vector g_loadedFiles; extern vector g_PartList; @@ -131,7 +123,7 @@ class FileLoader : public QObject { Q_OBJECT - READ_PROPERTY (std::vector, objs) + READ_PROPERTY (vector, objs) READ_PROPERTY (bool, done) READ_PROPERTY (ulong, progress) PROPERTY (FILE*, filePointer, setFilePointer) diff -r 6e80f038e8df -r c4b96bc41298 src/gldraw.cpp --- a/src/gldraw.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/gldraw.cpp Fri May 24 15:23:56 2013 +0300 @@ -47,9 +47,6 @@ { { 0, -1, 0 }, Z, Y, false, true }, }; -overlayMeta g_overlays[6]; -double g_depthValues[6]; - cfg (str, gl_bgcolor, "#CCCCD9"); cfg (str, gl_maincolor, "#707078"); cfg (float, gl_maincolor_alpha, 1.0); @@ -120,8 +117,8 @@ } for (int i = 0; i < 6; ++i) { - g_overlays[i].img = null; - g_depthValues[i] = 0.0f; + m_overlays[i].img = null; + m_depthValues[i] = 0.0f; } calcCameraIcons (); @@ -133,7 +130,7 @@ delete info.img; for (int i = 0; i < 6; ++i) - delete g_overlays[i].img; + delete m_overlays[i].img; } // ============================================================================= @@ -491,10 +488,10 @@ if (m_camera != Free) { // Paint the overlay image if we have one - const overlayMeta& overlay = g_overlays[m_camera]; + const overlayMeta& overlay = m_overlays[m_camera]; if (overlay.img != null) { - QPoint v0 = coordconv3_2 (g_overlays[m_camera].v0), - v1 = coordconv3_2 (g_overlays[m_camera].v1); + QPoint v0 = coordconv3_2 (m_overlays[m_camera].v0), + v1 = coordconv3_2 (m_overlays[m_camera].v1); QRect targRect (v0.x (), v0.y (), abs (v1.x () - v0.x ()), abs (v1.y () - v0.y ())), srcRect (0, 0, overlay.img->width (), overlay.img->height ()); @@ -516,7 +513,7 @@ textSize.height (), Qt::AlignCenter, text); // If we're drawing, draw the vertices onto the screen. - if (m_editMode == Draw) { + if (editMode () == Draw) { ushort numverts; if (!m_rectdraw) @@ -761,7 +758,7 @@ case LDObject::Radial: { LDRadial* rad = static_cast (obj); - std::vector objs = rad->decompose (true); + vector objs = rad->decompose (true); bool oldinvert = g_glInvert; if (rad->transform.determinant () < 0) @@ -901,7 +898,7 @@ if (wasRight && m_drawedVerts.size () > 0) { // Remove the last vertex - m_drawedVerts.erase (m_drawedVerts.end () - 1); + m_drawedVerts.erase (m_drawedVerts.size () - 1); if (m_drawedVerts.size () == 0) m_rectdraw = false; @@ -1011,7 +1008,7 @@ // Clear the selection if we do not wish to add to it. if (!m_addpick) { - std::vector oldsel = g_win->sel (); + vector oldsel = g_win->sel (); g_win->sel ().clear (); for (LDObject* obj : oldsel) { @@ -1092,7 +1089,7 @@ for (ulong i = 0; i < g_win->sel ().size(); ++i) { if (g_win->sel ()[i] == obj) { - g_win->sel ().erase (g_win->sel ().begin () + i); + g_win->sel ().erase (i); obj->setSelected (false); removed = true; removedObj = obj; @@ -1110,11 +1107,10 @@ // Remove duplicate entries. For this to be effective, the vector must be // sorted first. - std::vector& sel = g_win->sel (); - std::sort (sel.begin(), sel.end ()); - std::vector::iterator pos = std::unique (sel.begin (), sel.end ()); + vector& sel = g_win->sel (); + std::sort (sel.begin (), sel.end ()); + vector::it pos = std::unique (sel.begin (), sel.end ()); sel.resize (std::distance (sel.begin (), pos)); - // Update everything now. g_win->updateSelection (); @@ -1137,8 +1133,8 @@ } // ============================================================================= -void GLRenderer::setEditMode (EditMode mode) { - switch (mode) { +void GLRenderer::callback_setEditMode () { + switch (editMode ()) { case Select: unsetCursor (); setContextMenuPolicy (Qt::DefaultContextMenu); @@ -1164,8 +1160,6 @@ break; } - m_editMode = mode; - g_win->updateEditModeActions (); update (); } @@ -1320,7 +1314,7 @@ return; QImage* img = new QImage (dlg.fpath ().chars ()); - overlayMeta& info = g_overlays[camera ()]; + overlayMeta& info = getOverlay (camera ()); if (img->isNull ()) { critical ("Failed to load overlay image!"); @@ -1329,7 +1323,7 @@ } delete info.img; // delete the old image - + info.fname = dlg.fpath (); info.lw = dlg.lwidth (); info.lh = dlg.lheight (); @@ -1367,21 +1361,25 @@ if (camera () == Free) return; - overlayMeta& info = g_overlays[camera ()]; + overlayMeta& info = m_overlays[camera ()]; delete info.img; info.img = null; } void GLRenderer::setDepthValue (double depth) { assert (camera () < Free); - g_depthValues[camera ()] = depth; + m_depthValues[camera ()] = depth; } double GLRenderer::depthValue () const { assert (camera () < Free); - return g_depthValues[camera ()]; + return m_depthValues[camera ()]; } const char* GLRenderer::cameraName () const { return g_CameraNames[camera ()]; +} + +overlayMeta& GLRenderer::getOverlay (int newcam) { + return m_overlays[newcam]; } \ No newline at end of file diff -r 6e80f038e8df -r c4b96bc41298 src/gldraw.h --- a/src/gldraw.h Fri May 24 04:34:20 2013 +0300 +++ b/src/gldraw.h Fri May 24 15:23:56 2013 +0300 @@ -31,6 +31,20 @@ class QSpinBox; class QLineEdit; +enum EditMode { + Select, + Draw +}; + +// Meta for overlays +struct overlayMeta { + vertex v0, v1; + ushort ox, oy; + double lw, lh; + str fname; + QImage* img; +}; + // ============================================================================= // GLRenderer // @@ -43,49 +57,48 @@ PROPERTY (double, zoom, setZoom) READ_PROPERTY (bool, picking) + CALLBACK_PROPERTY (EditMode, editMode, setEditMode) public: enum Camera { Top, Front, Left, Bottom, Back, Right, Free }; - enum EditMode { Select, Draw }; enum ListType { NormalList, PickList, BFCFrontList, BFCBackList }; GLRenderer (QWidget* parent = null); ~GLRenderer (); - Camera camera () const { return m_camera; } - Axis cameraAxis (bool y); - const char* cameraName () const; - void clearOverlay (); - void compileObject (LDObject* obj); - void compileAllObjects (); - double depthValue () const; - EditMode editMode () const { return m_editMode; } - void endDraw (bool accept); - QColor getMainColor (); - void hardRefresh (); - void refresh (); - void resetAngles (); - uchar* screencap (ushort& w, ushort& h); - void setBackground (); - void setCamera (const Camera cam); - void setDepthValue (double depth); - void setEditMode (const EditMode mode); - void setupOverlay (); + Camera camera () const { return m_camera; } + Axis cameraAxis (bool y); + const char* cameraName () const; + void clearOverlay (); + void compileObject (LDObject* obj); + void compileAllObjects (); + double depthValue () const; + void endDraw (bool accept); + QColor getMainColor (); + overlayMeta& getOverlay (int newcam); + void hardRefresh (); + void refresh (); + void resetAngles (); + uchar* screencap (ushort& w, ushort& h); + void setBackground (); + void setCamera (const Camera cam); + void setDepthValue (double depth); + void setupOverlay (); - static void deleteLists (LDObject* obj); + static void deleteLists (LDObject* obj); protected: - void contextMenuEvent (QContextMenuEvent* ev); - void initializeGL (); - void keyPressEvent (QKeyEvent* ev); - void keyReleaseEvent (QKeyEvent* ev); - void leaveEvent (QEvent* ev); - void mousePressEvent (QMouseEvent* ev); - void mouseMoveEvent (QMouseEvent* ev); - void mouseReleaseEvent (QMouseEvent* ev); - void paintEvent (QPaintEvent* ev); - void resizeGL (int w, int h); - void wheelEvent (QWheelEvent* ev); + void contextMenuEvent (QContextMenuEvent* ev); + void initializeGL (); + void keyPressEvent (QKeyEvent* ev); + void keyReleaseEvent (QKeyEvent* ev); + void leaveEvent (QEvent* ev); + void mousePressEvent (QMouseEvent* ev); + void mouseMoveEvent (QMouseEvent* ev); + void mouseReleaseEvent (QMouseEvent* ev); + void paintEvent (QPaintEvent* ev); + void resizeGL (int w, int h); + void wheelEvent (QWheelEvent* ev); private: QTimer* m_toolTipTimer; @@ -100,21 +113,22 @@ Camera m_camera, m_toolTipCamera; uint m_axeslist; ushort m_width, m_height; - std::vector m_drawedVerts; - EditMode m_editMode; + vector m_drawedVerts; bool m_rectdraw; QColor m_bgcolor; + double m_depthValues[6]; + overlayMeta m_overlays[6]; - void calcCameraIcons (); // Compute geometry for camera icons - void clampAngle (double& angle) const; // Clamps an angle to [0, 360] - void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object - void compileSubObject (LDObject* obj, const GLenum gltype); // Sub-routine for object compiling - void compileVertex (const vertex& vrt); // Compile a single vertex to a list - vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point - QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point - void drawGLScene () const; // Paint the GL scene - void pick (uint mouseX, uint mouseY); // Perform object selection - void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list + void calcCameraIcons (); // Compute geometry for camera icons + void clampAngle (double& angle) const; // Clamps an angle to [0, 360] + void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object + void compileSubObject (LDObject* obj, const GLenum gltype); // Sub-routine for object compiling + void compileVertex (const vertex& vrt); // Compile a single vertex to a list + vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point + QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point + void drawGLScene () const; // Paint the GL scene + void pick (uint mouseX, uint mouseY); // Perform object selection + void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list private slots: void slot_toolTipTimer (); @@ -131,17 +145,7 @@ GL::BFCBackList, }; -// Meta for overlays -struct overlayMeta { - vertex v0, v1; - ushort ox, oy; - double lw, lh; - str fname; - QImage* img; -}; - extern const GL::Camera g_Cameras[7]; extern const char* g_CameraNames[7]; -extern overlayMeta g_overlays[6]; #endif // GLDRAW_H \ No newline at end of file diff -r 6e80f038e8df -r c4b96bc41298 src/gui.cpp --- a/src/gui.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/gui.cpp Fri May 24 15:23:56 2013 +0300 @@ -285,7 +285,7 @@ delete recent; m_recentFiles.clear (); - std::vector files = io_recentfiles.value / "@"; + vector files = io_recentfiles.value / "@"; for (long i = files.size() - 1; i >= 0; --i) { str file = files[i]; @@ -428,8 +428,8 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -std::vector parseQuickColorMeta () { - std::vector meta; +vector parseQuickColorMeta () { + vector meta; for (str colorname : gui_colortoolbar.value / ":") { if (colorname == "|") { @@ -552,11 +552,11 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void ForgeWindow::deleteSelection (vector* ulapIndices, std::vector* papObjects) { +void ForgeWindow::deleteSelection (vector* ulapIndices, vector* papObjects) { if (m_sel.size () == 0) return; - std::vector selCopy = m_sel; + vector selCopy = m_sel; // Delete the objects that were being selected for (LDObject* obj : selCopy) { @@ -726,7 +726,7 @@ if (m_renderer->picking ()) return; - std::vector priorSelection = m_sel; + vector priorSelection = m_sel; // Get the objects from the object list selection m_sel.clear (); @@ -777,8 +777,8 @@ if (col == null) return; - std::vector indices; - std::vector colors; + vector indices; + vector colors; short newColor = col->index; for (LDObject* obj : m_sel) { @@ -944,7 +944,7 @@ } // ======================================================================================================================================== -DelHistory* ForgeWindow::deleteObjVector (const std::vector objs) { +DelHistory* ForgeWindow::deleteObjVector (vector objs) { vector indices; vector cache; @@ -982,7 +982,7 @@ // ======================================================================================================================================== void ForgeWindow::updateEditModeActions () { - const GL::EditMode mode = R ()->editMode (); + const EditMode mode = R ()->editMode (); const size_t numModeActions = (sizeof g_modeActionNames / sizeof *g_modeActionNames); assert ((size_t) mode < numModeActions); @@ -992,7 +992,7 @@ act->setCheckable (true); act->setChecked (i == (size_t) mode); - if (i != GL::Select) + if (i != Select) act->setEnabled (R ()->camera () != GL::Free); } } diff -r 6e80f038e8df -r c4b96bc41298 src/gui.h --- a/src/gui.h Fri May 24 04:34:20 2013 +0300 +++ b/src/gui.h Fri May 24 15:23:56 2013 +0300 @@ -109,7 +109,7 @@ void fullRefresh (); void refresh (); ulong getInsertionPoint (); - void deleteSelection (vector* ulapIndices, std::vector* papObjects); + void deleteSelection (vector* ulapIndices, vector* papObjects); void updateToolBars (); void updateRecentFilesMenu (); void updateSelection (); @@ -120,12 +120,12 @@ LDObject::Type uniformSelectedType (); void scrollToSelection (); void spawnContextMenu (const QPoint pos); - DelHistory* deleteObjVector (const std::vector objs); + DelHistory* deleteObjVector (vector objs); DelHistory* deleteSelection (); DelHistory* deleteByColor (const short colnum); GLRenderer* R () { return m_renderer; } - std::vector& sel () { return m_sel; } - void setQuickColorMeta (std::vector& quickColorMeta) { + vector& sel () { return m_sel; } + void setQuickColorMeta (vector& quickColorMeta) { m_colorMeta = quickColorMeta; } void setStatusBarText (str text); @@ -145,11 +145,11 @@ QSplitter* m_splitter; str m_msglogHTML; QToolBar* m_colorToolBar; - std::vector m_toolBars; - std::vector m_sel; - std::vector m_colorMeta; - std::vector m_colorButtons; - std::vector m_recentFiles; + vector m_toolBars; + vector m_sel; + vector m_colorMeta; + vector m_colorButtons; + vector m_recentFiles; void createMenuActions (); void createMenus (); @@ -171,7 +171,7 @@ // ----------------------------------------------------------------------------- // Other GUI-related stuff not directly part of ForgeWindow: QPixmap getIcon (const char* sIconName); -std::vector parseQuickColorMeta (); +vector parseQuickColorMeta (); bool confirm (str title, str msg); bool confirm (str msg); void critical (str msg); diff -r 6e80f038e8df -r c4b96bc41298 src/gui_actions.cpp --- a/src/gui_actions.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/gui_actions.cpp Fri May 24 15:23:56 2013 +0300 @@ -310,9 +310,9 @@ return; } - std::vector historyCopies; - std::vector historyIndices; - std::vector objs = loadFileContents (fp, null); + vector historyCopies; + vector historyIndices; + vector objs = loadFileContents (fp, null); g_win->sel ().clear (); @@ -342,8 +342,8 @@ QVBoxLayout* const layout = new QVBoxLayout; QTextEdit* const te_edit = new QTextEdit; QDialogButtonBox* const bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - std::vector historyCopies; - std::vector historyIndices; + vector historyCopies; + vector historyIndices; layout->addWidget (te_edit); layout->addWidget (bbx_buttons); @@ -430,11 +430,11 @@ // ========================================================================================================================================= MAKE_ACTION (modeSelect, "Select Mode", "mode-select", "Select objects from the camera view.", CTRL (1)) { - g_win->R ()->setEditMode (GL::Select); + g_win->R ()->setEditMode (Select); } MAKE_ACTION (modeDraw, "Draw Mode", "mode-draw", "Draw objects into the camera view.", CTRL (2)) { - g_win->R ()->setEditMode (GL::Draw); + g_win->R ()->setEditMode (Draw); } // ========================================================================================================================================= diff -r 6e80f038e8df -r c4b96bc41298 src/gui_editactions.cpp --- a/src/gui_editactions.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/gui_editactions.cpp Fri May 24 15:23:56 2013 +0300 @@ -261,7 +261,7 @@ if (lIndex == -1) return; - std::vector triangles = static_cast (obj)->splitToTriangles (); + vector triangles = static_cast (obj)->splitToTriangles (); // Replace the quad with the first triangle and add the second triangle // after the first one. @@ -317,7 +317,7 @@ short colnum; short defcol = -1; - std::vector objs = g_win->sel (); + vector objs = g_win->sel (); // If all selected objects have the same color, said color is our default // value to the color selection dialog. @@ -325,8 +325,8 @@ // Show the dialog to the user now and ask for a color. if (ColorSelectDialog::staticDialog (colnum, defcol, g_win)) { - std::vector indices; - std::vector colornums; + vector indices; + vector colornums; for (LDObject* obj : objs) { if (obj->isColored () == false) @@ -522,7 +522,7 @@ // History. // ============================================================================= MAKE_ACTION (invert, "Invert", "invert", "Reverse the winding of given objects.", CTRL_SHIFT (W)) { - std::vector sel = g_win->sel (); + vector sel = g_win->sel (); ComboHistory* history = new ComboHistory; for (LDObject* obj : sel) { @@ -541,9 +541,9 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= static void doRotate (const short l, const short m, const short n) { - std::vector sel = g_win->sel (); + vector sel = g_win->sel (); vertex origin; - std::vector queue; + vector queue; const double angle = (pi * currentGrid ().confs[Grid::Angle]->value) / 180; // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2 diff -r 6e80f038e8df -r c4b96bc41298 src/history.cpp --- a/src/history.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/history.cpp Fri May 24 15:23:56 2013 +0300 @@ -29,7 +29,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= namespace History { - std::vector s_entries; + vector s_entries; static long s_pos = -1; // ========================================================================= @@ -38,7 +38,7 @@ // remove them now for (ulong i = s_pos + 1; i < s_entries.size(); ++i) { delete s_entries[i]; - s_entries.erase (s_entries.begin() + i); + s_entries.erase (i); } s_entries.push_back (entry); @@ -96,7 +96,7 @@ } // ========================================================================= - std::vector& entries () { + vector& entries () { return s_entries; } } @@ -191,8 +191,8 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -std::vector ListMoveHistory::getObjects (short ofs) { - std::vector objs; +vector ListMoveHistory::getObjects (short ofs) { + vector objs; for (ulong idx : ulaIndices) objs.push_back (g_curfile->object (idx + ofs)); @@ -201,13 +201,13 @@ } void ListMoveHistory::undo () { - std::vector objs = getObjects (bUp ? -1 : 1); + vector objs = getObjects (bUp ? -1 : 1); LDObject::moveObjects (objs, !bUp); g_win->buildObjList (); } void ListMoveHistory::redo () { - std::vector objs = getObjects (0); + vector objs = getObjects (0); LDObject::moveObjects (objs, bUp); g_win->buildObjList (); } @@ -277,7 +277,7 @@ ulong idx = ulaIndices[i]; LDQuad* pQuad = static_cast (g_curfile->object (idx)); - std::vector paTriangles = pQuad->splitToTriangles (); + vector paTriangles = pQuad->splitToTriangles (); g_curfile->setObject (idx, paTriangles[0]); g_curfile->insertObj (idx + 1, paTriangles[1]); @@ -324,7 +324,7 @@ } InlineHistory::~InlineHistory () { - for (LDSubfile* ref : paRefs) + for (LDSubfile* const ref : paRefs) delete ref; } @@ -336,13 +336,13 @@ void MoveHistory::undo () { const vertex vInverse = -vVector; - for (ulong i : ulaIndices) + for (const ulong& i : ulaIndices) g_curfile->object (i)->move (vInverse); g_win->fullRefresh (); } void MoveHistory::redo () { - for (ulong i : ulaIndices) + for (const ulong& i : ulaIndices) g_curfile->object (i)->move (vVector); g_win->fullRefresh (); } diff -r 6e80f038e8df -r c4b96bc41298 src/history.h --- a/src/history.h Fri May 24 04:34:20 2013 +0300 +++ b/src/history.h Fri May 24 15:23:56 2013 +0300 @@ -94,12 +94,12 @@ public: IMPLEMENT_HISTORY_TYPE (Edit) - std::vector ulaIndices; - std::vector paOldObjs, paNewObjs; + vector ulaIndices; + vector paOldObjs, paNewObjs; EditHistory () {} - EditHistory (std::vector ulaIndices, std::vector paOldObjs, - std::vector paNewObjs) : + EditHistory (vector ulaIndices, vector paOldObjs, + vector paNewObjs) : ulaIndices (ulaIndices), paOldObjs (paOldObjs), paNewObjs (paNewObjs) {} void addEntry (LDObject* const oldObj, LDObject* const newObj); @@ -114,10 +114,10 @@ public: IMPLEMENT_HISTORY_TYPE (ListMove) - std::vector ulaIndices; + vector ulaIndices; bool bUp; - std::vector getObjects (short ofs); + vector getObjects (short ofs); ListMoveHistory (vector ulaIndices, const bool bUp) : ulaIndices (ulaIndices), bUp (bUp) {} }; @@ -134,11 +134,11 @@ IMPLEMENT_HISTORY_TYPE (Add) - std::vector ulaIndices; - std::vector paObjs; + vector ulaIndices; + vector paObjs; const Type eType; - AddHistory (std::vector ulaIndices, std::vector paObjs, + AddHistory (vector ulaIndices, vector paObjs, const Type eType = Other) : ulaIndices (ulaIndices), paObjs (paObjs), eType (eType) {} }; @@ -150,10 +150,10 @@ public: IMPLEMENT_HISTORY_TYPE (QuadSplit) - std::vector ulaIndices; - std::vector paQuads; + vector ulaIndices; + vector paQuads; - QuadSplitHistory (std::vector ulaIndices, std::vector paQuads) : + QuadSplitHistory (vector ulaIndices, vector paQuads) : ulaIndices (ulaIndices), paQuads (paQuads) {} }; @@ -164,12 +164,12 @@ public: IMPLEMENT_HISTORY_TYPE (Inline) - const std::vector ulaBitIndices, ulaRefIndices; - const std::vector paRefs; + const vector ulaBitIndices, ulaRefIndices; + const vector paRefs; const bool bDeep; - InlineHistory (const std::vector ulaBitIndices, const std::vector ulaRefIndices, - const std::vector paRefs, const bool bDeep) : + InlineHistory (const vector ulaBitIndices, const vector ulaRefIndices, + const vector paRefs, const bool bDeep) : ulaBitIndices (ulaBitIndices), ulaRefIndices (ulaRefIndices), paRefs (paRefs), bDeep (bDeep) {} }; @@ -180,10 +180,10 @@ public: IMPLEMENT_HISTORY_TYPE (Move) - const std::vector ulaIndices; + const vector ulaIndices; const vertex vVector; - MoveHistory (const std::vector ulaIndices, const vertex vVector) : + MoveHistory (const vector ulaIndices, const vertex vVector) : ulaIndices (ulaIndices), vVector (vVector) {} }; @@ -194,12 +194,12 @@ public: IMPLEMENT_HISTORY_TYPE (Combo) - std::vector paEntries; + vector paEntries; ComboHistory () {} - ComboHistory (std::vector paEntries) : paEntries (paEntries) {} + ComboHistory (vector paEntries) : paEntries (paEntries) {} - void addEntry (HistoryEntry* entry) { if (entry) paEntries.push_back (entry); } + void addEntry (HistoryEntry* entry) { if (entry) paEntries << entry; } ulong numEntries () const { return paEntries.size (); } ComboHistory& operator<< (HistoryEntry* entry) { addEntry (entry); return *this;} }; @@ -214,7 +214,7 @@ void clear (); void updateActions (); long pos (); - std::vector& entries (); + vector& entries (); }; #endif // HISTORY_H \ No newline at end of file diff -r 6e80f038e8df -r c4b96bc41298 src/ldtypes.cpp --- a/src/ldtypes.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/ldtypes.cpp Fri May 24 15:23:56 2013 +0300 @@ -216,7 +216,7 @@ // Remove this object from the selection array if it is there. for (ulong i = 0; i < g_win->sel ().size(); ++i) if (g_win->sel ()[i] == this) - g_win->sel ().erase (g_win->sel ().begin() + i); + g_win->sel ().erase (i); // Delete the GL lists GL::deleteLists (this); @@ -339,7 +339,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void LDObject::moveObjects (std::vector objs, const bool bUp) { +void LDObject::moveObjects (vector objs, const bool bUp) { // If we move down, we need to iterate the array in reverse order. const long start = bUp ? 0 : (objs.size() - 1); const long end = bUp ? objs.size() : -1; @@ -378,7 +378,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -str LDObject::objectListContents (const std::vector& objs) { +str LDObject::objectListContents (const vector& objs) { bool firstDetails = true; str text = ""; @@ -512,8 +512,8 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -std::vector LDRadial::decompose (bool applyTransform) { - std::vector paObjects; +vector LDRadial::decompose (bool applyTransform) { + vector paObjects; for (short i = 0; i < segs; ++i) { double x0 = cos ((i * 2 * pi) / divs), diff -r 6e80f038e8df -r c4b96bc41298 src/ldtypes.h --- a/src/ldtypes.h Fri May 24 04:34:20 2013 +0300 +++ b/src/ldtypes.h Fri May 24 15:23:56 2013 +0300 @@ -157,8 +157,8 @@ // Returns a sample object by the given value static LDObject* getDefault (const LDObject::Type type); - static void moveObjects (std::vector objs, const bool bUp); - static str objectListContents (const std::vector& objs); + static void moveObjects (vector objs, const bool bUp); + static str objectListContents (const vector& objs); // Object list entry for this object QListWidgetItem* qObjListEntry; @@ -273,7 +273,7 @@ // 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 inlineContents (bool deep, bool cache); + vector inlineContents (bool deep, bool cache); }; // ============================================================================= @@ -405,7 +405,7 @@ // Returns a set of objects that provide the equivalent of this radial. // Note: objects are heap-allocated. - std::vector decompose (bool applyTransform); + vector decompose (bool applyTransform); // Compose a file name for this radial. str makeFileName (); diff -r 6e80f038e8df -r c4b96bc41298 src/misc.h --- a/src/misc.h Fri May 24 04:34:20 2013 +0300 +++ b/src/misc.h Fri May 24 15:23:56 2013 +0300 @@ -108,7 +108,7 @@ } private: - std::vector m_tokens; + vector m_tokens; short m_pos; }; diff -r 6e80f038e8df -r c4b96bc41298 src/string.cpp --- a/src/string.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/string.cpp Fri May 24 15:23:56 2013 +0300 @@ -107,7 +107,7 @@ } vector String::split (String del) const { - std::vector res; + vector res; size_t a = 0; // Find all separators and store the text left to them. diff -r 6e80f038e8df -r c4b96bc41298 src/string.h --- a/src/string.h Fri May 24 04:34:20 2013 +0300 +++ b/src/string.h Fri May 24 15:23:56 2013 +0300 @@ -22,8 +22,7 @@ #include #include #include - -using std::vector; +#include "types.h" // ========================================================================================================================================= char* dynafmt (const char* fmtstr, va_list va, ulong size); diff -r 6e80f038e8df -r c4b96bc41298 src/types.h --- a/src/types.h Fri May 24 04:34:20 2013 +0300 +++ b/src/types.h Fri May 24 15:23:56 2013 +0300 @@ -19,8 +19,11 @@ #ifndef TYPES_H #define TYPES_H +#include #include "common.h" +class String; +typedef String str; typedef unsigned int uint; typedef unsigned short ushort; typedef unsigned long ulong; @@ -36,7 +39,6 @@ typedef uint64_t uint64; template using initlist = std::initializer_list; -using std::vector; enum Axis { X, Y, Z }; static const Axis g_Axes[3] = {X, Y, Z}; @@ -113,4 +115,104 @@ double m_coords[3]; }; + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +// vector +// +// Array class that wraps around vector +// ============================================================================= +template class vector { +public: + typedef typename std::vector::iterator it; + typedef typename std::vector::const_iterator c_it; + + vector () {} + vector (initlist vals) { + m_vect = vals; + } + + it begin () { + return m_vect.begin (); + } + + c_it begin () const { + return m_vect.cbegin (); + } + + it end () { + return m_vect.end (); + } + + c_it end () const { + return m_vect.cend (); + } + + void erase (ulong pos) { + assert (pos < size ()); + m_vect.erase (m_vect.begin () + pos); + } + + void push_back (const T& value) { + m_vect.push_back (value); + } + + bool pop (T& val) { + if (size () == 0) + return false; + + val = m_vect[size () - 1]; + erase (size () - 1); + return true; + } + + vector& operator<< (const T& value) { + push_back (value); + return *this; + } + + bool operator>> (T& value) { + return pop (value); + } + + vector reverse () const { + vector rev; + + for (const T& val : m_vect) + rev << val; + + return rev; + } + + void clear () { + m_vect.clear (); + } + + void insert (ulong pos, const T& value) { + m_vect.insert (m_vect.begin () + pos, value); + } + + ulong size () const { + return m_vect.size (); + } + + T& operator[] (ulong n) { + assert (n < size ()); + return m_vect[n]; + } + + const T& operator[] (ulong n) const { + assert (n < size ()); + return m_vect[n]; + } + + void resize (std::ptrdiff_t size) { + m_vect.resize (size); + } + +private: + std::vector m_vect; +}; + #endif // TYPES_H \ No newline at end of file diff -r 6e80f038e8df -r c4b96bc41298 src/widgets.cpp --- a/src/widgets.cpp Fri May 24 04:34:20 2013 +0300 +++ b/src/widgets.cpp Fri May 24 15:23:56 2013 +0300 @@ -127,11 +127,11 @@ emit valueChanged (newid); } -RadioBox::iter RadioBox::begin() { +RadioBox::it RadioBox::begin() { return m_objects.begin (); } -RadioBox::iter RadioBox::end() { +RadioBox::it RadioBox::end() { return m_objects.end (); } @@ -154,8 +154,8 @@ connect (box, SIGNAL (stateChanged (int)), this, SLOT (buttonChanged ())); } -std::vector CheckBoxGroup::checkedValues () const { - std::vector vals; +vector CheckBoxGroup::checkedValues () const { + vector vals; for (const auto& kv : m_vals) if (kv.second->isChecked ()) diff -r 6e80f038e8df -r c4b96bc41298 src/widgets.h --- a/src/widgets.h Fri May 24 04:34:20 2013 +0300 +++ b/src/widgets.h Fri May 24 15:23:56 2013 +0300 @@ -38,7 +38,7 @@ Q_OBJECT public: - typedef std::vector::iterator iter; + typedef vector::it it; explicit RadioBox (QWidget* parent = null) : QGroupBox (parent) { init (Qt::Vertical); } explicit RadioBox () { init (Qt::Vertical); } @@ -48,8 +48,8 @@ void addButton (const char* entry); void addButton (QRadioButton* button); - iter begin (); - iter end (); + it begin (); + it end (); void init (Qt::Orientation orient); bool isChecked (int n) const; void rowBreak (); @@ -67,8 +67,8 @@ void valueChanged (int val); private: - std::vector m_objects; - std::vector m_layouts; + vector m_objects; + vector m_layouts; QBoxLayout* m_coreLayout; QBoxLayout* m_currentLayout; bool m_vert;