Sat, 13 Jul 2013 19:02:48 +0300
Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
src/addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
src/bbox.cpp | file | annotate | diff | comparison | revisions | |
src/extprogs.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/gldraw.h | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.h | file | annotate | diff | comparison | revisions | |
src/primitives.cpp | file | annotate | diff | comparison | revisions |
--- a/src/addObjectDialog.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/addObjectDialog.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -60,7 +60,7 @@ case LDObject::Comment: le_comment = new QLineEdit; if (obj) - le_comment->setText (static_cast<LDComment*> (obj)->text); + le_comment->setText (static_cast<LDCommentObject*> (obj)->text); le_comment->setMinimumWidth (384); break; @@ -85,11 +85,11 @@ case LDObject::BFC: rb_bfcType = new RadioBox ("Statement", {}, 0, Qt::Vertical); - for (int i = 0; i < LDBFC::NumStatements; ++i) - rb_bfcType->addButton (LDBFC::statements[i]); + for (int i = 0; i < LDBFCObject::NumStatements; ++i) + rb_bfcType->addButton (LDBFCObject::statements[i]); if (obj) - rb_bfcType->setValue ((int) static_cast<LDBFC*> (obj)->type); + rb_bfcType->setValue ((int) static_cast<LDBFCObject*> (obj)->type); break; case LDObject::Subfile: @@ -116,7 +116,7 @@ // If this primitive is the one the current object points to, // select it by default - if (obj && static_cast<LDSubfile*> (obj)->fileInfo ()->name () == prim.name) + if (obj && static_cast<LDSubfileObject*> (obj)->fileInfo ()->name () == prim.name) tw_subfileList->setCurrentItem (item); } @@ -129,7 +129,7 @@ le_subfileName->setFocus (); if (obj) { - LDSubfile* ref = static_cast<LDSubfile*> (obj); + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); le_subfileName->setText (ref->fileInfo ()->name ()); } break; @@ -296,7 +296,7 @@ void AddObjectDialog::staticDialog (const LDObject::Type type, LDObject* obj) { setlocale (LC_ALL, "C"); - if (obj && obj->getType () == LDObject::Gibberish) + if (obj && obj->getType () == LDObject::Error) return; if (type == LDObject::Empty) @@ -329,7 +329,7 @@ switch (type) { case LDObject::Comment: { - LDComment* comm = initObj<LDComment> (obj); + LDCommentObject* comm = initObj<LDCommentObject> (obj); comm->text = dlg.le_comment->text (); } break; @@ -352,14 +352,14 @@ case LDObject::BFC: { - LDBFC* bfc = initObj<LDBFC> (obj); - bfc->type = (LDBFC::Type) dlg.rb_bfcType->value (); + LDBFCObject* bfc = initObj<LDBFCObject> (obj); + bfc->type = (LDBFCObject::Type) dlg.rb_bfcType->value (); } break; case LDObject::Vertex: { - LDVertex* vert = initObj<LDVertex> (obj); + LDVertexObject* vert = initObj<LDVertexObject> (obj); for (const Axis ax : g_Axes) vert->pos[ax] = dlg.dsb_coords[ax]->value (); @@ -378,7 +378,7 @@ return; } - LDSubfile* ref = initObj<LDSubfile> (obj); + LDSubfileObject* ref = initObj<LDSubfileObject> (obj); for (const Axis ax : g_Axes) ref->setCoordinate (ax, dlg.dsb_coords[ax]->value ());
--- a/src/bbox.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/bbox.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -61,7 +61,7 @@ case LDObject::Subfile: { - LDSubfile* ref = static_cast<LDSubfile*>( obj ); + LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj ); vector<LDObject*> objs = ref->inlineContents( true, true ); for( LDObject * obj : objs )
--- a/src/extprogs.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/extprogs.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -127,7 +127,7 @@ void writeObjects (vector<LDObject*>& objects, File& f) { for (LDObject* obj : objects) { if (obj->getType () == LDObject::Subfile) { - vector<LDObject*> objs = static_cast<LDSubfile*> (obj)->inlineContents (true, false); + vector<LDObject*> objs = static_cast<LDSubfileObject*> (obj)->inlineContents (true, false); writeObjects (objs, f); for (LDObject* obj : objs)
--- a/src/file.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/file.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -241,8 +241,8 @@ LDObject* obj = parseLine( line ); // Check for parse errors and warn about tthem - if( obj->getType () == LDObject::Gibberish ) { - log( "Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDGibberish*> (obj)->reason ); + if( obj->getType () == LDObject::Error ) { + log( "Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDErrorObject*> (obj)->reason ); if( m_warningsPointer ) { ( *m_warningsPointer )++; }} @@ -553,11 +553,11 @@ // If the second object in the list holds the file name, update that now. // Only do this if the file is explicitly open. If it's saved into a directory // called "s" or "48", prepend that into the name. - LDComment* fpathComment = null; + LDCommentObject* fpathComment = null; LDObject* first = object( 1 ); if( !implicit() && first != null && first->getType() == LDObject::Comment ) { - fpathComment = static_cast<LDComment*>( first ); + fpathComment = static_cast<LDCommentObject*>( first ); if( fpathComment->text.left( 6 ) == "Name: " ) { str newname; @@ -591,14 +591,14 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -#define CHECK_TOKEN_COUNT( N ) \ - if( tokens.size() != N ) \ - return new LDGibberish( line, "Bad amount of tokens" ); +#define CHECK_TOKEN_COUNT(N) \ + if (tokens.size() != N) \ + return new LDErrorObject (line, "Bad amount of tokens"); #define CHECK_TOKEN_NUMBERS( MIN, MAX ) \ for (ushort i = MIN; i <= MAX; ++i) \ if (!isNumber (tokens[i])) \ - return new LDGibberish (line, fmt ("Token #%1 was `%2`, expected a number", \ + return new LDErrorObject (line, fmt ("Token #%1 was `%2`, expected a number", \ (i + 1), tokens[i])); static vertex parseVertex( QStringList& s, const ushort n ) @@ -614,7 +614,7 @@ // ----------------------------------------------------------------------------- // This is the LDraw code parser function. It takes in a string containing LDraw // code and returns the object parsed from it. parseLine never returns null, -// the object will be LDGibberish if it could not be parsed properly. +// the object will be LDError if it could not be parsed properly. // ============================================================================= LDObject* parseLine( str line ) { @@ -623,14 +623,14 @@ if( tokens.size() <= 0 ) { // Line was empty, or only consisted of whitespace - return new LDEmpty; + return new LDEmptyObject; } if( tokens[0].length() != 1 || tokens[0][0].isDigit() == false ) - return new LDGibberish( line, "Illogical line code" ); + return new LDErrorObject( line, "Illogical line code" ); int num = tokens[0][0].digitValue(); - switch( num ) + switch (num) { case 0: { @@ -643,40 +643,37 @@ // Handle BFC statements if (tokens.size() > 2 && tokens[1] == "BFC") { - for (short i = 0; i < LDBFC::NumStatements; ++i) - if (comm == fmt ("BFC %1", LDBFC::statements [i])) - return new LDBFC ((LDBFC::Type) i); + for (short i = 0; i < LDBFCObject::NumStatements; ++i) + if (comm == fmt ("BFC %1", LDBFCObject::statements [i])) + return new LDBFCObject ((LDBFCObject::Type) i); // MLCAD is notorious for stuffing these statements in parts it // creates. The above block only handles valid statements, so we // need to handle MLCAD-style invertnext separately. if (comm == "BFC CERTIFY INVERTNEXT") - return new LDBFC (LDBFC::InvertNext); + return new LDBFCObject (LDBFCObject::InvertNext); } - if( tokens.size() > 2 && tokens[1] == "!LDFORGE" ) + if (tokens.size() > 2 && tokens[1] == "!LDFORGE") { // Handle LDForge-specific types, they're embedded into comments too - if( tokens[2] == "VERTEX" ) - { + if (tokens[2] == "VERTEX") { // Vertex (0 !LDFORGE VERTEX) CHECK_TOKEN_COUNT (7) CHECK_TOKEN_NUMBERS (3, 6) - LDVertex* obj = new LDVertex; + LDVertexObject* obj = new LDVertexObject; obj->setColor (tokens[3].toLong ()); for (const Axis ax : g_Axes) obj->pos[ax] = tokens[4 + ax].toDouble (); // 4 - 6 return obj; - } - elif( tokens[2] == "OVERLAY" ) - { - CHECK_TOKEN_COUNT( 9 ); - CHECK_TOKEN_NUMBERS( 5, 8 ) + } elif (tokens[2] == "OVERLAY") { + CHECK_TOKEN_COUNT (9); + CHECK_TOKEN_NUMBERS (5, 8) - LDOverlay* obj = new LDOverlay; + LDOverlayObject* obj = new LDOverlayObject; obj->setFilename( tokens[3] ); obj->setCamera( tokens[4].toLong() ); obj->setX( tokens[5].toLong() ); @@ -688,7 +685,7 @@ } // Just a regular comment: - LDComment* obj = new LDComment; + LDCommentObject* obj = new LDCommentObject; obj->text = comm; return obj; } @@ -708,9 +705,9 @@ // If we cannot open the file, mark it an error if( !load ) - return new LDGibberish( line, "Could not open referred file" ); + return new LDErrorObject( line, "Could not open referred file" ); - LDSubfile* obj = new LDSubfile; + LDSubfileObject* obj = new LDSubfileObject; obj->setColor( tokens[1].toLong() ); obj->setPosition( parseVertex( tokens, 2 )); // 2 - 4 @@ -729,7 +726,7 @@ CHECK_TOKEN_NUMBERS( 1, 7 ) // Line - LDLine* obj = new LDLine; + LDLineObject* obj = new LDLineObject; obj->setColor( tokens[1].toLong() ); for( short i = 0; i < 2; ++i ) obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 7 @@ -742,7 +739,7 @@ CHECK_TOKEN_NUMBERS( 1, 10 ) // Triangle - LDTriangle* obj = new LDTriangle; + LDTriangleObject* obj = new LDTriangleObject; obj->setColor( tokens[1].toLong() ); for( short i = 0; i < 3; ++i ) @@ -754,21 +751,21 @@ case 4: case 5: { - CHECK_TOKEN_COUNT( 14 ) - CHECK_TOKEN_NUMBERS( 1, 13 ) + CHECK_TOKEN_COUNT (14) + CHECK_TOKEN_NUMBERS (1, 13) // Quadrilateral / Conditional line - LDObject* obj = ( num == 4 ) ? ( (LDObject*) new LDQuad ) : ( (LDObject*) new LDCondLine ); + LDObject* obj = (num == 4) ? ((LDObject*) new LDQuadObject ) : ((LDObject*) new LDCondLineObject); obj->setColor( tokens[1].toLong() ); - for( short i = 0; i < 4; ++i ) + for (short i = 0; i < 4; ++i) obj->setVertex( i, parseVertex( tokens, 2 + ( i * 3 ))); // 2 - 13 return obj; } default: // Strange line we couldn't parse - return new LDGibberish( line, "Unknown line code number" ); + return new LDErrorObject (line, "Unknown line code number"); } } @@ -802,19 +799,19 @@ { if( obj->getType() == LDObject::Subfile ) { - LDSubfile* ref = static_cast<LDSubfile*>( obj ); + LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj ); LDOpenFile* fileInfo = getFile( ref->fileInfo()->name() ); if (fileInfo) ref->setFileInfo( fileInfo ); else - ref->replace( new LDGibberish( ref->raw(), "Could not open referred file" )); + ref->replace( new LDErrorObject( ref->raw(), "Could not open referred file" )); } // Reparse gibberish files. It could be that they are invalid because // of loading errors. Circumstances may be different now. - if( obj->getType() == LDObject::Gibberish ) - obj->replace( parseLine( static_cast<LDGibberish*>( obj )->contents )); + if( obj->getType() == LDObject::Error ) + obj->replace( parseLine( static_cast<LDErrorObject*>( obj )->contents )); } // Close all files left unused @@ -891,7 +888,7 @@ if( obj->getType() != LDObject::Subfile ) continue; - LDSubfile* ref = static_cast<LDSubfile*>( obj ); + LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj ); filesUsed << ref->fileInfo(); filesUsed << getFilesUsed( ref->fileInfo() ); }
--- a/src/gldraw.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/gldraw.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -102,12 +102,12 @@ m_panning = false; setFile (null); setDrawOnly (false); - resetAngles (); + resetAngles(); setMessageLog( null ); m_toolTipTimer = new QTimer (this); m_toolTipTimer->setSingleShot (true); - connect (m_toolTipTimer, SIGNAL (timeout ()), this, SLOT (slot_toolTipTimer ())); + connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); m_thickBorderPen = QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); m_thinBorderPen = m_thickBorderPen; @@ -115,7 +115,7 @@ // Init camera icons for (const GL::Camera cam : g_Cameras) { - str iconname = fmt ("camera-%1", tr (g_CameraNames[cam]).toLower ()); + str iconname = fmt ("camera-%1", tr (g_CameraNames[cam]).toLower()); CameraIcon* info = &m_cameraIcons[cam]; info->img = new QPixmap (getIcon (iconname)); @@ -127,11 +127,11 @@ m_depthValues[i] = 0.0f; } - calcCameraIcons (); + calcCameraIcons(); } // ============================================================================= -GLRenderer::~GLRenderer () { +GLRenderer::~GLRenderer() { for (int i = 0; i < 6; ++i) delete m_overlays[i].img; @@ -142,7 +142,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::calcCameraIcons () { +void GLRenderer::calcCameraIcons() { ushort i = 0; for (CameraIcon& info : m_cameraIcons) { @@ -151,13 +151,13 @@ 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; } } -void GLRenderer::initGLData () { +void GLRenderer::initGLData() { glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_POLYGON_OFFSET_FILL); @@ -172,34 +172,34 @@ } // ============================================================================= -void GLRenderer::resetAngles () { +void GLRenderer::resetAngles() { m_rotX = 30.0f; m_rotY = 325.f; m_panX = m_panY = m_rotZ = 0.0f; - zoomToFit (); + zoomToFit(); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::initializeGL () { - setBackground (); +void GLRenderer::initializeGL() { + setBackground(); glLineWidth (gl_linethickness); setAutoFillBackground (false); setMouseTracking (true); setFocusPolicy (Qt::WheelFocus); - compileAllObjects (); + compileAllObjects(); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -QColor GLRenderer::getMainColor () { +QColor GLRenderer::getMainColor() { QColor col (gl_maincolor); - if (!col.isValid ()) + if (!col.isValid()) return QColor (0, 0, 0); col.setAlpha (gl_maincolor_alpha * 255.f); @@ -207,10 +207,10 @@ } // ----------------------------------------------------------------------------- -void GLRenderer::setBackground () { +void GLRenderer::setBackground() { QColor col (gl_bgcolor); - if (!col.isValid ()) + if (!col.isValid()) return; col.setAlpha (255); @@ -227,7 +227,7 @@ void GLRenderer::setObjectColor (LDObject* obj, const ListType list) { QColor qcol; - if (!obj->isColored ()) + if (!obj->isColored()) return; if (list == GL::PickList) { @@ -249,54 +249,54 @@ } if ((list == BFCFrontList || list == BFCBackList) && - obj->getType () != LDObject::Line && - obj->getType () != LDObject::CondLine) + obj->getType() != LDObject::Line && + obj->getType() != LDObject::CondLine) { if (list == GL::BFCFrontList) qcol = QColor (40, 192, 0); else qcol = QColor (224, 0, 0); } else { - if (obj->color () == maincolor) - qcol = getMainColor (); + if (obj->color() == maincolor) + qcol = getMainColor(); else { - LDColor* col = getColor (obj->color ()); + LDColor* col = getColor (obj->color()); if( col ) qcol = col->faceColor; } - if (obj->color () == edgecolor) { + if (obj->color() == edgecolor) { qcol = luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black; LDColor* col; - if (!gl_blackedges && obj->parent () && (col = getColor (obj->parent ()->color ()))) + if (!gl_blackedges && obj->parent() && (col = getColor (obj->parent()->color()))) qcol = col->edgeColor; } - 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->color () != edgecolor) - qcol = getMainColor (); + 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; } } - 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 (obj->topLevelParent ()->selected ()) { + if (obj->topLevelParent()->selected()) { // Brighten it up for the select list. const uchar add = 51; @@ -315,15 +315,15 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::refresh () { - update (); - swapBuffers (); +void GLRenderer::refresh() { + update(); + swapBuffers(); } // ============================================================================= -void GLRenderer::hardRefresh () { - compileAllObjects (); - refresh (); +void GLRenderer::hardRefresh() { + compileAllObjects(); + refresh(); glLineWidth (gl_linethickness); } @@ -335,20 +335,20 @@ m_width = w; m_height = h; - calcCameraIcons (); + calcCameraIcons(); glViewport (0, 0, w, h); glMatrixMode (GL_PROJECTION); - glLoadIdentity (); + glLoadIdentity(); gluPerspective (45.0f, (double) w / (double) h, 1.0f, 10000.0f); glMatrixMode (GL_MODELVIEW); } -void GLRenderer::drawGLScene () { - if (file () == null) +void GLRenderer::drawGLScene() { + if (file() == null) return; - if (gl_wireframe && !picking ()) + if (gl_wireframe && !picking()) glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -356,9 +356,9 @@ if (m_camera != GLRenderer::Free) { glMatrixMode (GL_PROJECTION); - glPushMatrix (); + glPushMatrix(); - glLoadIdentity (); + glLoadIdentity(); glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f); glTranslatef (m_panX, m_panY, 0.0f); @@ -373,23 +373,23 @@ } } else { glMatrixMode (GL_MODELVIEW); - glPushMatrix (); - glLoadIdentity (); + glPushMatrix(); + glLoadIdentity(); glTranslatef (0.0f, 0.0f, -2.0f); - glTranslatef (m_panX, m_panY, -zoom ()); + glTranslatef (m_panX, m_panY, -zoom()); glRotatef (m_rotX, 1.0f, 0.0f, 0.0f); glRotatef (m_rotY, 0.0f, 1.0f, 0.0f); glRotatef (m_rotZ, 0.0f, 0.0f, 1.0f); } - const GL::ListType list = (!drawOnly () && m_picking) ? PickList : NormalList; + const GL::ListType list = (!drawOnly() && m_picking) ? PickList : NormalList; - if (gl_colorbfc && !m_picking && !drawOnly ()) { + if (gl_colorbfc && !m_picking && !drawOnly()) { glEnable (GL_CULL_FACE); - for (LDObject* obj : file ()->objs ()) { - if (obj->hidden ()) + for (LDObject* obj : file()->objs()) { + if (obj->hidden()) continue; glCullFace (GL_BACK); @@ -401,25 +401,25 @@ glDisable (GL_CULL_FACE); } else { - for (LDObject* obj : file ()->objs ()) { - if (obj->hidden ()) + for (LDObject* obj : file()->objs()) { + if (obj->hidden()) continue; glCallList (obj->glLists[list]); } } - if (gl_axes && !m_picking && !drawOnly ()) + if (gl_axes && !m_picking && !drawOnly()) glCallList (m_axeslist); - glPopMatrix (); + glPopMatrix(); glMatrixMode (GL_MODELVIEW); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); } // ============================================================================= vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const { - assert (camera () != Free); + assert (camera() != Free); vertex pos3d; const staticCameraMeta* cam = &g_staticCameras[m_camera]; @@ -429,8 +429,8 @@ negYFac = cam->negY ? -1 : 1; // Calculate cx and cy - these are the LDraw unit coords the cursor is at. - double cx = (-m_virtWidth + ((2 * pos2d.x () * m_virtWidth) / m_width) - m_panX); - double cy = (m_virtHeight - ((2 * pos2d.y () * m_virtHeight) / m_height) - m_panY); + double cx = (-m_virtWidth + ((2 * pos2d.x() * m_virtWidth) / m_width) - m_panX); + double cy = (m_virtHeight - ((2 * pos2d.y() * m_virtHeight) / m_height) - m_panY); if (snap) { cx = Grid::snap (cx, (Grid::Config) axisX); @@ -442,9 +442,9 @@ str tmp; pos3d = g_origin; - pos3d[axisX] = tmp.sprintf ("%.3f", cx).toDouble (); - pos3d[axisY] = tmp.sprintf ("%.3f", cy).toDouble (); - pos3d[3 - axisX - axisY] = depthValue (); + pos3d[axisX] = tmp.sprintf ("%.3f", cx).toDouble(); + pos3d[axisY] = tmp.sprintf ("%.3f", cy).toDouble(); + pos3d[3 - axisX - axisY] = depthValue(); return pos3d; } @@ -459,9 +459,9 @@ glGetFloatv (GL_MODELVIEW_MATRIX, m); - const double x = pos3d.x (); - const double y = pos3d.y (); - const double z = pos3d.z (); + const double x = pos3d.x(); + const double y = pos3d.y(); + const double z = pos3d.z(); vertex transformed; transformed[X] = (m[0] * x) + (m[1] * y) + (m[2] * z) + m[3]; @@ -480,50 +480,50 @@ void GLRenderer::paintEvent (QPaintEvent* ev) { Q_UNUSED (ev) - makeCurrent (); - m_virtWidth = zoom (); + makeCurrent(); + m_virtWidth = zoom(); m_virtHeight = (m_height * m_virtWidth) / m_width; - initGLData (); - drawGLScene (); + initGLData(); + drawGLScene(); QPainter paint (this); - QFontMetrics metrics = QFontMetrics (QFont ()); + QFontMetrics metrics = QFontMetrics (QFont()); paint.setRenderHint (QPainter::HighQualityAntialiasing); // If we wish to only draw the brick, stop here - if (drawOnly ()) + if (drawOnly()) return; - if (m_camera != Free && !picking ()) { + if (m_camera != Free && !picking()) { // Paint the overlay image if we have one const overlayMeta& overlay = m_overlays[m_camera]; if (overlay.img != null) { 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 ()); + 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()); paint.drawImage (targRect, *overlay.img, srcRect); } // Paint the coordinates onto the screen. str text = fmt( tr( "X: %1, Y: %2, Z: %3" ), m_hoverpos[X], m_hoverpos[Y], m_hoverpos[Z] ); - QFontMetrics metrics = QFontMetrics (font ()); + QFontMetrics metrics = QFontMetrics (font()); QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text); paint.setPen (m_darkbg ? Qt::white : Qt::black); - paint.drawText (m_width - textSize.width (), m_height - 16, textSize.width (), - textSize.height (), Qt::AlignCenter, text); + paint.drawText (m_width - textSize.width(), m_height - 16, textSize.width(), + textSize.height(), Qt::AlignCenter, text); // If we're drawing, draw the vertices onto the screen. - if (editMode () == Draw) { + if (editMode() == Draw) { const short blipsize = 8; int numverts = 4; if (!m_rectdraw) - numverts = m_drawedVerts.size () + 1; + numverts = m_drawedVerts.size() + 1; if (numverts > 0) { QPoint poly[4]; @@ -545,7 +545,7 @@ numverts = 4; } } else { - if (m_drawedVerts.size () > 0) { + if (m_drawedVerts.size() > 0) { // Get vertex information from m_rectverts for (int i = 0; i < numverts; ++i) { polyverts[i] = m_rectverts[i]; @@ -573,11 +573,11 @@ for (ushort i = 0; i < numverts; ++i) { QPoint& blip = poly[i]; - paint.drawEllipse (blip.x () - blipsize / 2, blip.y () - blipsize / 2, + paint.drawEllipse (blip.x() - blipsize / 2, blip.y() - blipsize / 2, blipsize, blipsize); // Draw their coordinates - paint.drawText (blip.x (), blip.y () - 8, polyverts[i].stringRep (true)); + paint.drawText (blip.x(), blip.y() - 8, polyverts[i].stringRep (true)); } } } @@ -588,12 +588,12 @@ // Draw a background for the selected camera paint.setPen (m_thinBorderPen); paint.setBrush (QBrush (QColor (0, 128, 160, 128))); - paint.drawRect (m_cameraIcons[camera ()].selRect); + paint.drawRect (m_cameraIcons[camera()].selRect); // Draw the actual icons for (CameraIcon& info : m_cameraIcons) { // Don't draw the free camera icon when in draw mode - if (&info == &m_cameraIcons[GL::Free] && editMode () != Select) + if (&info == &m_cameraIcons[GL::Free] && editMode() != Select) continue; paint.drawPixmap (info.destRect, *info.img, info.srcRect); @@ -606,7 +606,7 @@ const ushort margin = 4; str label; - label = fmt( fmtstr, tr( g_CameraNames[camera ()] )); + label = fmt( fmtstr, tr( g_CameraNames[camera()] )); paint.setPen (m_darkbg ? Qt::white : Qt::black); paint.drawText( QPoint( margin, height() - ( margin + metrics.descent() )), label ); } @@ -620,17 +620,17 @@ bord.setBrush (Qt::black); const ushort margin = 2; - ushort x0 = m_pos.x (), - y0 = m_pos.y (); + ushort x0 = m_pos.x(), + y0 = m_pos.y(); str label = fmt( fmtstr, tr( g_CameraNames[m_toolTipCamera] )); const ushort textWidth = metrics.width (label), - textHeight = metrics.height (), + textHeight = metrics.height(), fullWidth = textWidth + (2 * margin), fullHeight = textHeight + (2 * margin); - QRect area (m_pos.x (), m_pos.y (), fullWidth, fullHeight); + QRect area (m_pos.x(), m_pos.y(), fullWidth, fullHeight); if (x0 + fullWidth > m_width) x0 -= fullWidth; @@ -643,7 +643,7 @@ paint.drawRect (x0, y0, fullWidth, fullHeight); paint.setBrush (Qt::black); - paint.drawText (QPoint (x0 + margin, y0 + margin + metrics.ascent ()), label); + paint.drawText (QPoint (x0 + margin, y0 + margin + metrics.ascent()), label); } } } @@ -667,10 +667,10 @@ // If we're range-picking, draw a rectangle encompassing the selection area. if (m_rangepick && !m_picking && m_totalmove >= 10) { - const short x0 = m_rangeStart.x (), - y0 = m_rangeStart.y (), - x1 = m_pos.x (), - y1 = m_pos.y (); + const short x0 = m_rangeStart.x(), + y0 = m_rangeStart.y(), + x1 = m_pos.x(), + y1 = m_pos.y(); QRect rect (x0, y0, x1 - x0, y1 - y0); QColor fillColor = (m_addpick ? "#40FF00" : "#00CCFF"); @@ -685,13 +685,13 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::compileAllObjects () { - if (!file ()) +void GLRenderer::compileAllObjects() { + if (!file()) return; - m_knownVerts.clear (); + m_knownVerts.clear(); - for (LDObject* obj : file ()->objs ()) + for (LDObject* obj : file()->objs()) compileObject (obj); // Compile axes @@ -706,8 +706,8 @@ compileVertex (-ax.vert); } - glEnd (); - glEndList (); + glEnd(); + glEndList(); } // ============================================================================= @@ -718,7 +718,7 @@ void GLRenderer::compileSubObject (LDObject* obj, const GLenum gltype) { glBegin (gltype); - const short numverts = (obj->getType () != LDObject::CondLine) ? obj->vertices () : 2; + const short numverts = (obj->getType() != LDObject::CondLine) ? obj->vertices() : 2; if (g_glInvert == false) for (short i = 0; i < numverts; ++i) @@ -727,7 +727,7 @@ for (short i = numverts - 1; i >= 0; --i) compileVertex (obj->m_coords[i]); - glEnd (); + glEnd(); } // ============================================================================= @@ -736,7 +736,7 @@ void GLRenderer::compileList (LDObject* obj, const GLRenderer::ListType list) { setObjectColor (obj, list); - switch (obj->getType ()) { + switch (obj->getType()) { case LDObject::Line: compileSubObject (obj, GL_LINES); break; @@ -762,16 +762,16 @@ case LDObject::Subfile: { - LDSubfile* ref = static_cast<LDSubfile*> (obj); + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); vector<LDObject*> objs = ref->inlineContents (true, true); bool oldinvert = g_glInvert; - if (ref->transform ().determinant () < 0) + if (ref->transform().determinant() < 0) g_glInvert = !g_glInvert; - LDObject* prev = ref->prev (); - if (prev && prev->getType () == LDObject::BFC && static_cast<LDBFC*> (prev)->type == LDBFC::InvertNext) + LDObject* prev = ref->prev(); + if (prev && prev->getType() == LDObject::BFC && static_cast<LDBFCObject*> (prev)->type == LDBFCObject::InvertNext) g_glInvert = !g_glInvert; for (LDObject* obj : objs) { @@ -866,30 +866,30 @@ // Check if we selected a camera icon if (!m_rangepick) { for (CameraIcon& info : m_cameraIcons) { - if (info.destRect.contains (ev->pos ())) { + if (info.destRect.contains (ev->pos())) { setCamera (info.cam); goto end; } } } - switch (editMode ()) { + switch (editMode()) { case Draw: if (m_rectdraw) { - if (m_drawedVerts.size () == 2) { + if (m_drawedVerts.size() == 2) { endDraw (true); return; } } else { // If we have 4 verts, stop drawing. - if (m_drawedVerts.size () >= 4) { + if (m_drawedVerts.size() >= 4) { endDraw (true); return; } - if (m_drawedVerts.size () == 0 && ev->modifiers () & Qt::ShiftModifier) { + if (m_drawedVerts.size() == 0 && ev->modifiers() & Qt::ShiftModifier) { m_rectdraw = true; - updateRectVerts (); + updateRectVerts(); } } @@ -897,7 +897,7 @@ break; case Select: - if (!drawOnly ()) { + if (!drawOnly()) { if (m_totalmove < 10) m_rangepick = false; @@ -905,7 +905,7 @@ m_addpick = (m_keymods & Qt::ControlModifier); if (m_totalmove < 10 || m_rangepick) - pick (ev->x (), ev->y ()); + pick (ev->x(), ev->y()); } break; @@ -914,7 +914,7 @@ m_rangepick = false; } - if (wasMid && editMode () == Draw && m_drawedVerts.size () < 4 && m_totalmove < 10) { + if (wasMid && editMode() == Draw && m_drawedVerts.size() < 4 && m_totalmove < 10) { // Find the closest vertex to our cursor double mindist = 1024.0f; vertex closest; @@ -926,8 +926,8 @@ QPoint pos2d = coordconv3_2 (pos3d); // Measure squared distance - double dx = abs (pos2d.x () - curspos.x ()); - double dy = abs (pos2d.y () - curspos.y ()); + double dx = abs (pos2d.x() - curspos.x()); + double dy = abs (pos2d.y() - curspos.y()); double distsq = (dx * dx) + (dy * dy); if (distsq >= 1024.0f) // 32.0f ** 2 @@ -944,16 +944,16 @@ addDrawnVertex (closest); } - if (wasRight && m_drawedVerts.size () > 0) { + if (wasRight && m_drawedVerts.size() > 0) { // Remove the last vertex - m_drawedVerts.erase (m_drawedVerts.size () - 1); + m_drawedVerts.erase (m_drawedVerts.size() - 1); - if (m_drawedVerts.size () == 0) + if (m_drawedVerts.size() == 0) m_rectdraw = false; } end: - update (); + update(); m_totalmove = 0; } @@ -963,34 +963,34 @@ void GLRenderer::mousePressEvent (QMouseEvent* ev) { m_totalmove = 0; - if (ev->modifiers () & Qt::ControlModifier) { + if (ev->modifiers() & Qt::ControlModifier) { m_rangepick = true; - m_rangeStart.setX (ev->x ()); - m_rangeStart.setY (ev->y ()); + m_rangeStart.setX (ev->x()); + m_rangeStart.setY (ev->y()); m_addpick = (m_keymods & Qt::AltModifier); - ev->accept (); + ev->accept(); } - m_lastButtons = ev->buttons (); + m_lastButtons = ev->buttons(); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::mouseMoveEvent (QMouseEvent* ev) { - int dx = ev->x () - m_pos.x (); - int dy = ev->y () - m_pos.y (); + int dx = ev->x() - m_pos.x(); + int dy = ev->y() - m_pos.y(); m_totalmove += abs (dx) + abs (dy); - const bool left = ev->buttons () & Qt::LeftButton, - mid = ev->buttons () & Qt::MidButton, - shift = ev->modifiers () & Qt::ShiftModifier; + const bool left = ev->buttons() & Qt::LeftButton, + mid = ev->buttons() & Qt::MidButton, + shift = ev->modifiers() & Qt::ShiftModifier; if (mid || (left && shift)) { - m_panX += 0.03f * dx * (zoom () / 7.5f); - m_panY -= 0.03f * dy * (zoom () / 7.5f); + m_panX += 0.03f * dx * (zoom() / 7.5f); + m_panY -= 0.03f * dy * (zoom() / 7.5f); m_panning = true; - } elif (left && !m_rangepick && camera () == Free) { + } elif (left && !m_rangepick && camera() == Free) { m_rotX = m_rotX + (dy); m_rotY = m_rotY + (dx); @@ -1003,57 +1003,57 @@ m_toolTipTimer->start (1000); // Update 2d position - m_pos = ev->pos (); + m_pos = ev->pos(); // Calculate 3d position of the cursor - m_hoverpos = (camera () != Free) ? coordconv2_3 (m_pos, true) : g_origin; + m_hoverpos = (camera() != Free) ? coordconv2_3 (m_pos, true) : g_origin; // Update rect vertices since m_hoverpos may have changed - updateRectVerts (); + updateRectVerts(); - update (); + update(); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::keyPressEvent (QKeyEvent* ev) { - m_keymods = ev->modifiers (); + m_keymods = ev->modifiers(); } void GLRenderer::keyReleaseEvent (QKeyEvent* ev) { - m_keymods = ev->modifiers (); + m_keymods = ev->modifiers(); } // ============================================================================= void GLRenderer::wheelEvent (QWheelEvent* ev) { - makeCurrent (); + makeCurrent(); - zoomNotch (ev->delta () > 0); - setZoom (clamp<double> (zoom (), 0.01f, 10000.0f)); + zoomNotch (ev->delta() > 0); + setZoom (clamp<double> (zoom(), 0.01f, 10000.0f)); - update (); - ev->accept (); + update(); + ev->accept(); } // ============================================================================= void GLRenderer::leaveEvent (QEvent* ev) { Q_UNUSED (ev); m_drawToolTip = false; - m_toolTipTimer->stop (); - update (); + m_toolTipTimer->stop(); + update(); } // ============================================================================= void GLRenderer::contextMenuEvent (QContextMenuEvent* ev) { - g_win->spawnContextMenu (ev->globalPos ()); + g_win->spawnContextMenu (ev->globalPos()); } // ============================================================================= void GLRenderer::setCamera (const GL::Camera cam) { m_camera = cam; gl_camera = (int) cam; - g_win->updateEditModeActions (); + g_win->updateEditModeActions(); } // ============================================================================= @@ -1061,15 +1061,15 @@ // ============================================================================= void GLRenderer::pick (uint mouseX, uint mouseY) { GLint viewport[4]; - makeCurrent (); + makeCurrent(); // Use particularly thick lines while picking ease up selecting lines. glLineWidth (max<double> (gl_linethickness, 6.5f)); // Clear the selection if we do not wish to add to it. if (!m_addpick) { - vector<LDObject*> oldsel = g_win->sel (); - g_win->sel ().clear (); + vector<LDObject*> oldsel = g_win->sel(); + g_win->sel().clear(); for (LDObject* obj : oldsel) { obj->setSelected (false); @@ -1083,7 +1083,7 @@ glDisable (GL_DITHER); glClearColor (1.0f, 1.0f, 1.0f, 1.0f); - drawGLScene (); + drawGLScene(); glGetIntegerv (GL_VIEWPORT, viewport); @@ -1094,8 +1094,8 @@ // Determine how big an area to read - with range picking, we pick by // the area given, with single pixel picking, we use an 1 x 1 area. if (m_rangepick) { - x1 = m_rangeStart.x (); - y1 = m_rangeStart.y (); + x1 = m_rangeStart.x(); + y1 = m_rangeStart.y(); } else { x1 = x0 + 1; y1 = y0 + 1; @@ -1147,9 +1147,9 @@ if (!m_rangepick && m_addpick) { bool removed = false; - for (ulong i = 0; i < g_win->sel ().size(); ++i) { - if (g_win->sel ()[i] == obj) { - g_win->sel ().erase (i); + for (ulong i = 0; i < g_win->sel().size(); ++i) { + if (g_win->sel()[i] == obj) { + g_win->sel().erase (i); obj->setSelected (false); removed = true; removedObj = obj; @@ -1160,19 +1160,19 @@ break; } - g_win->sel () << obj; + g_win->sel() << obj; } delete[] pixeldata; // Remove duplicated entries - g_win->sel ().makeUnique (); + g_win->sel().makeUnique(); // Update everything now. - g_win->updateSelection (); + g_win->updateSelection(); // Recompile the objects now to update their color - for (LDObject* obj : g_win->sel ()) + for (LDObject* obj : g_win->sel()) compileObject (obj); if (removedObj) @@ -1185,8 +1185,8 @@ m_rangepick = false; glEnable (GL_DITHER); - setBackground (); - update (); + setBackground(); + update(); } // ============================================================================= @@ -1197,9 +1197,9 @@ SET_ACCESSOR (EditMode, GLRenderer::setEditMode) { m_editMode = val; - switch (editMode ()) { + switch (editMode()) { case Select: - unsetCursor (); + unsetCursor(); setContextMenuPolicy (Qt::DefaultContextMenu); break; @@ -1217,14 +1217,14 @@ // Clear the selection when beginning to draw. // FIXME: make the selection clearing stuff in ::pick a method and use it // here! This code doesn't update the GL lists. - g_win->sel ().clear (); - g_win->updateSelection (); - m_drawedVerts.clear (); + g_win->sel().clear(); + g_win->updateSelection(); + m_drawedVerts.clear(); break; } - g_win->updateEditModeActions (); - update (); + g_win->updateEditModeActions(); + update(); } READ_ACCESSOR( LDOpenFile*, GLRenderer::file ) @@ -1249,67 +1249,66 @@ LDObject* obj = null; if (m_rectdraw) { - LDQuad* quad = new LDQuad; + LDQuadObject* quad = new LDQuadObject; // Copy the vertices from m_rectverts - updateRectVerts (); + updateRectVerts(); - for (int i = 0; i < quad->vertices (); ++i) + for (int i = 0; i < quad->vertices(); ++i) quad->setVertex (i, m_rectverts[i]); quad->setColor (maincolor); obj = quad; } else { - switch (verts.size ()) { + switch (verts.size()) { case 1: // 1 vertex - add a vertex object - obj = new LDVertex; - static_cast<LDVertex*> (obj)->pos = verts[0]; + obj = new LDVertexObject; + static_cast<LDVertexObject*> (obj)->pos = verts[0]; obj->setColor (maincolor); break; case 2: // 2 verts - make a line - obj = new LDLine (verts[0], verts[1]); + obj = new LDLineObject (verts[0], verts[1]); obj->setColor (edgecolor); break; case 3: case 4: - obj = (verts.size () == 3) ? - static_cast<LDObject*> (new LDTriangle) : - static_cast<LDObject*> (new LDQuad); + obj = (verts.size() == 3) ? + static_cast<LDObject*> (new LDTriangleObject) : + static_cast<LDObject*> (new LDQuadObject); obj->setColor (maincolor); - for (ushort i = 0; i < obj->vertices (); ++i) + for (ushort i = 0; i < obj->vertices(); ++i) obj->setVertex (i, verts[i]); break; } } if (obj) { - file ()->openHistory (); - file ()->addObject (obj); + file()->openHistory(); + file()->addObject (obj); compileObject (obj); - g_win->fullRefresh (); - file ()->closeHistory (); + g_win->fullRefresh(); + file()->closeHistory(); } - m_drawedVerts.clear (); + m_drawedVerts.clear(); m_rectdraw = false; } static vector<vertex> getVertices (LDObject* obj) { vector<vertex> verts; - if (obj->vertices () >= 2) - for (int i = 0; i < obj->vertices (); ++i) + if (obj->vertices() >= 2) { + for (int i = 0; i < obj->vertices(); ++i) verts << obj->getVertex (i); - elif( obj->getType() == LDObject::Subfile ) - { - vector<LDObject*> objs = static_cast<LDSubfile*>( obj )->inlineContents( true, true ); + } elif( obj->getType() == LDObject::Subfile ) { + vector<LDObject*> objs = static_cast<LDSubfileObject*> (obj)->inlineContents (true, true); - for( LDObject* obj : objs ) { + for(LDObject* obj : objs) { verts << getVertices (obj); delete obj; } @@ -1321,12 +1320,11 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::compileObject( LDObject* obj ) -{ +void GLRenderer::compileObject (LDObject* obj) { deleteLists (obj); for (const GL::ListType listType : g_glListTypes) { - if (drawOnly () && listType != GL::NormalList) + if (drawOnly() && listType != GL::NormalList) continue; GLuint list = glGenLists (1); @@ -1335,13 +1333,13 @@ obj->glLists[listType] = list; compileList (obj, listType); - glEndList (); + glEndList(); } // Mark in known vertices of this object vector<vertex> verts = getVertices (obj); m_knownVerts << verts; - m_knownVerts.makeUnique (); + m_knownVerts.makeUnique(); obj->m_glinit = true; } @@ -1353,20 +1351,17 @@ uchar* cap = new uchar[4 * w * h]; m_screencap = true; - update (); + update(); m_screencap = false; // Capture the pixels glReadPixels (0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, cap); - // Restore the background - setBackground (); - return cap; } // ============================================================================= -void GLRenderer::slot_toolTipTimer () { +void GLRenderer::slot_toolTipTimer() { // We come here if the cursor has stayed in one place for longer than a // a second. Check if we're holding it over a camera icon - if so, draw // a tooltip. @@ -1374,7 +1369,7 @@ if (icon.destRect.contains (m_pos)) { m_toolTipCamera = icon.cam; m_drawToolTip = true; - update (); + update(); break; } } @@ -1452,11 +1447,11 @@ return true; } -void GLRenderer::clearOverlay () { - if (camera () == Free) +void GLRenderer::clearOverlay() { + if (camera() == Free) return; - overlayMeta& info = m_overlays[camera ()]; + overlayMeta& info = m_overlays[camera()]; delete info.img; info.img = null; @@ -1464,17 +1459,17 @@ } void GLRenderer::setDepthValue (double depth) { - assert (camera () < Free); - m_depthValues[camera ()] = depth; + assert (camera() < Free); + m_depthValues[camera()] = depth; } -double GLRenderer::depthValue () const { - assert (camera () < Free); - return m_depthValues[camera ()]; +double GLRenderer::depthValue() const { + assert (camera() < Free); + return m_depthValues[camera()]; } -const char* GLRenderer::cameraName () const { - return g_CameraNames[camera ()]; +const char* GLRenderer::cameraName() const { + return g_CameraNames[camera()]; } overlayMeta& GLRenderer::getOverlay (int newcam) { @@ -1482,15 +1477,15 @@ } void GLRenderer::zoomNotch (bool inward) { - if (zoom () > 15) - setZoom (zoom () * (inward ? 0.833f : 1.2f)); + if (zoom() > 15) + setZoom (zoom() * (inward ? 0.833f : 1.2f)); else - setZoom (zoom () + (inward ? -1.2f : 1.2f)); + setZoom (zoom() + (inward ? -1.2f : 1.2f)); } // ============================================================================= -void GLRenderer::zoomToFit () { - if (file () == null) { +void GLRenderer::zoomToFit() { + if (file() == null) { setZoom (30.0f); return; } @@ -1510,7 +1505,7 @@ m_picking = true; for (;;) { - if (zoom () > 10000.0f || zoom () < 0.0f) { + if (zoom() > 10000.0f || zoom() < 0.0f) { // Obviously, there's nothing to draw if we get here. // Default to 30.0f and break out. setZoom (30.0f); @@ -1520,7 +1515,7 @@ zoomNotch (inward); uchar* cap = new uchar[4 * w * h]; - drawGLScene (); + drawGLScene(); glReadPixels (0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, cap); uint32* imgdata = reinterpret_cast<uint32*> (cap); bool filled = false; @@ -1562,16 +1557,16 @@ ++run; } - setBackground (); + setBackground(); m_picking = false; } // ============================================================================= -void GLRenderer::updateRectVerts () { +void GLRenderer::updateRectVerts() { if (!m_rectdraw) return; - if (m_drawedVerts.size () == 0) { + if (m_drawedVerts.size() == 0) { for (int i = 0; i < 4; ++i) m_rectverts[i] = m_hoverpos; @@ -1579,14 +1574,14 @@ } vertex v0 = m_drawedVerts[0], - v1 = (m_drawedVerts.size () >= 2) ? m_drawedVerts[1] : m_hoverpos; + v1 = (m_drawedVerts.size() >= 2) ? m_drawedVerts[1] : m_hoverpos; const Axis ax = cameraAxis (false), ay = cameraAxis (true), az = (Axis) (3 - ax - ay); for (int i = 0; i < 4; ++i) - m_rectverts[i][az] = depthValue (); + m_rectverts[i][az] = depthValue(); m_rectverts[0][ax] = v0[ax]; m_rectverts[0][ay] = v0[ay]; @@ -1599,30 +1594,30 @@ } void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev) { - if (!(ev->buttons () & Qt::LeftButton) || editMode () != Select) + if (!(ev->buttons() & Qt::LeftButton) || editMode() != Select) return; - pick (ev->x (), ev->y ()); + pick (ev->x(), ev->y()); - if (g_win->sel ().size () == 0) + if (g_win->sel().size() == 0) return; file()->openHistory(); LDObject* obj = g_win->sel()[0]; - AddObjectDialog::staticDialog (obj->getType (), obj); + AddObjectDialog::staticDialog (obj->getType(), obj); file()->closeHistory(); - ev->accept (); + ev->accept(); } -LDOverlay* GLRenderer::findOverlayObject( GLRenderer::Camera cam ) +LDOverlayObject* GLRenderer::findOverlayObject( GLRenderer::Camera cam ) { - LDOverlay* ovlobj = null; + LDOverlayObject* ovlobj = null; for( LDObject* obj : *file() ) { - if( obj->getType() == LDObject::Overlay && static_cast<LDOverlay*>( obj )->camera() == cam ) + if( obj->getType() == LDObject::Overlay && static_cast<LDOverlayObject*>( obj )->camera() == cam ) { - ovlobj = static_cast<LDOverlay*>( obj ); + ovlobj = static_cast<LDOverlayObject*>( obj ); break; } } @@ -1642,7 +1637,7 @@ continue; overlayMeta& meta = m_overlays[cam]; - LDOverlay* ovlobj = findOverlayObject( cam ); + LDOverlayObject* ovlobj = findOverlayObject( cam ); if( !ovlobj && meta.img ) { @@ -1663,7 +1658,7 @@ continue; overlayMeta& meta = m_overlays[cam]; - LDOverlay* ovlobj = findOverlayObject( cam ); + LDOverlayObject* ovlobj = findOverlayObject( cam ); if( !meta.img && ovlobj ) { @@ -1684,7 +1679,7 @@ { // Inverse case: image is there but the overlay object is // not, thus create the object. - ovlobj = new LDOverlay; + ovlobj = new LDOverlayObject; // Find a suitable position to place this object. We want to place // this into the header, which is everything up to the first scemantic @@ -1715,7 +1710,7 @@ file()->insertObj( i, ovlobj ); if( found ) - file()->insertObj( i + 1, new LDEmpty ); + file()->insertObj( i + 1, new LDEmptyObject ); } }
--- a/src/gldraw.h Sat Jul 13 17:35:38 2013 +0300 +++ b/src/gldraw.h Sat Jul 13 19:02:48 2013 +0300 @@ -150,7 +150,7 @@ 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 - LDOverlay* findOverlayObject ( Camera cam ); + LDOverlayObject* findOverlayObject ( Camera cam ); void updateRectVerts (); void pick (uint mouseX, uint mouseY); // Perform object selection void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list
--- a/src/gui.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/gui.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -499,7 +499,7 @@ g_curfile->obj (0)->getType () == LDObject::Comment) { // Append title - LDComment* comm = static_cast<LDComment*> (g_curfile->obj (0)); + LDCommentObject* comm = static_cast<LDCommentObject*> (g_curfile->obj (0)); title += fmt (": %1", comm->text); } @@ -593,7 +593,7 @@ switch (obj->getType ()) { case LDObject::Comment: - descr = static_cast<LDComment*> (obj)->text; + descr = static_cast<LDCommentObject*> (obj)->text; // Remove leading whitespace while (descr[0] == ' ') @@ -615,17 +615,17 @@ } break; - case LDObject::Gibberish: - descr = fmt ("ERROR: %1", static_cast<LDGibberish*> (obj)->contents); + case LDObject::Error: + descr = fmt ("ERROR: %1", obj->raw()); break; case LDObject::Vertex: - descr = static_cast<LDVertex*> (obj)->pos.stringRep (true); + descr = static_cast<LDVertexObject*> (obj)->pos.stringRep (true); break; case LDObject::Subfile: { - LDSubfile* ref = static_cast<LDSubfile*> (obj); + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); descr = fmt ("%1 %2, (", ref->fileInfo ()->name (), ref->position ().stringRep (true)); @@ -639,12 +639,12 @@ break; case LDObject::BFC: - descr = LDBFC::statements[static_cast<LDBFC*> (obj)->type]; + descr = LDBFCObject::statements[static_cast<LDBFCObject*> (obj)->type]; break; case LDObject::Overlay: { - LDOverlay* ovl = static_cast<LDOverlay*>( obj ); + LDOverlayObject* ovl = static_cast<LDOverlayObject*>( obj ); descr = fmt( "[%1] %2 (%3, %4), %5 x %6", g_CameraNames[ovl->camera()], basename( ovl->filename() ), ovl->x(), ovl->y(), ovl->width(), ovl->height() ); } @@ -664,7 +664,7 @@ item->setIcon( getIcon( obj->typeName() )); // Color gibberish orange on red so it stands out. - if (obj->getType() == LDObject::Gibberish) { + if (obj->getType() == LDObject::Error) { item->setBackground (QColor ("#AA0000")); item->setForeground (QColor ("#FFAA00")); } elif (lv_colorize && obj->isColored () &&
--- a/src/gui_actions.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/gui_actions.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -56,27 +56,27 @@ newFile(); - const LDBFC::Type BFCType = - ui.rb_bfc_ccw->isChecked() ? LDBFC::CertifyCCW : - ui.rb_bfc_cw->isChecked() ? LDBFC::CertifyCW : - LDBFC::NoCertify; + const LDBFCObject::Type BFCType = + ui.rb_bfc_ccw->isChecked() ? LDBFCObject::CertifyCCW : + ui.rb_bfc_cw->isChecked() ? LDBFCObject::CertifyCW : + LDBFCObject::NoCertify; const str license = ui.rb_license_ca->isChecked() ? CALicense : ui.rb_license_nonca->isChecked() ? NonCALicense : ""; - *g_curfile << new LDComment (ui.le_title->text()); - *g_curfile << new LDComment ("Name: <untitled>.dat" ); - *g_curfile << new LDComment (fmt ("Author: %1", ui.le_author->text())); - *g_curfile << new LDComment (fmt ("!LDRAW_ORG Unofficial_Part")); + *g_curfile << new LDCommentObject (ui.le_title->text()); + *g_curfile << new LDCommentObject ("Name: <untitled>.dat" ); + *g_curfile << new LDCommentObject (fmt ("Author: %1", ui.le_author->text())); + *g_curfile << new LDCommentObject (fmt ("!LDRAW_ORG Unofficial_Part")); if (license != "") - *g_curfile << new LDComment (license); + *g_curfile << new LDCommentObject (license); - *g_curfile << new LDEmpty; - *g_curfile << new LDBFC (BFCType); - *g_curfile << new LDEmpty; + *g_curfile << new LDEmptyObject; + *g_curfile << new LDBFCObject (BFCType); + *g_curfile << new LDEmptyObject; g_win->fullRefresh(); } @@ -244,10 +244,10 @@ str refName; if (type == LDObject::Subfile) { - refName = static_cast<LDSubfile*> (g_win->sel()[0])->fileInfo()->name(); + refName = static_cast<LDSubfileObject*> (g_win->sel()[0])->fileInfo()->name(); for (LDObject* obj : g_win->sel()) - if (static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName) + if (static_cast<LDSubfileObject*> (obj)->fileInfo()->name() != refName) return; } @@ -256,7 +256,7 @@ if (obj->getType() != type) continue; - if (type == LDObject::Subfile && static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName) + if (type == LDObject::Subfile && static_cast<LDSubfileObject*> (obj)->fileInfo()->name() != refName) continue; g_win->sel() << obj;
--- a/src/gui_editactions.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/gui_editactions.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -126,7 +126,7 @@ vector<LDObject*> objs; if (obj->getType() == LDObject::Subfile) - objs = static_cast<LDSubfile*> (obj)->inlineContents (deep, true); + objs = static_cast<LDSubfileObject*> (obj)->inlineContents (deep, true); else continue; @@ -175,7 +175,7 @@ if (index == -1) return; - vector<LDTriangle*> triangles = static_cast<LDQuad*> (obj)->splitToTriangles(); + vector<LDTriangleObject*> triangles = static_cast<LDQuadObject*> (obj)->splitToTriangles(); // Replace the quad with the first triangle and add the second triangle // after the first one. @@ -206,8 +206,8 @@ ui.setupUi (dlg); ui.code->setText (obj->raw()); - if (obj->getType() == LDObject::Gibberish) - ui.errorDescription->setText (static_cast<LDGibberish*> (obj)->reason); + if (obj->getType() == LDObject::Error) + ui.errorDescription->setText (static_cast<LDErrorObject*> (obj)->reason); else { ui.errorDescription->hide(); ui.errorIcon->hide(); @@ -269,23 +269,23 @@ continue; short numLines; - LDLine* lines[4]; + LDLineObject* lines[4]; if (obj->getType() == LDObject::Quad) { numLines = 4; - LDQuad* quad = static_cast<LDQuad*> (obj); - lines[0] = new LDLine (quad->getVertex (0), quad->getVertex (1)); - lines[1] = new LDLine (quad->getVertex (1), quad->getVertex (2)); - lines[2] = new LDLine (quad->getVertex (2), quad->getVertex (3)); - lines[3] = new LDLine (quad->getVertex (3), quad->getVertex (0)); + LDQuadObject* quad = static_cast<LDQuadObject*> (obj); + lines[0] = new LDLineObject (quad->getVertex (0), quad->getVertex (1)); + lines[1] = new LDLineObject (quad->getVertex (1), quad->getVertex (2)); + lines[2] = new LDLineObject (quad->getVertex (2), quad->getVertex (3)); + lines[3] = new LDLineObject (quad->getVertex (3), quad->getVertex (0)); } else { numLines = 3; - LDTriangle* tri = static_cast<LDTriangle*> (obj); - lines[0] = new LDLine (tri->getVertex (0), tri->getVertex (1)); - lines[1] = new LDLine (tri->getVertex (1), tri->getVertex (2)); - lines[2] = new LDLine (tri->getVertex (2), tri->getVertex (0)); + LDTriangleObject* tri = static_cast<LDTriangleObject*> (obj); + lines[0] = new LDLineObject (tri->getVertex (0), tri->getVertex (1)); + lines[1] = new LDLineObject (tri->getVertex (1), tri->getVertex (2)); + lines[2] = new LDLineObject (tri->getVertex (2), tri->getVertex (0)); } for (short i = 0; i < numLines; ++i) { @@ -318,7 +318,7 @@ ulong idx = obj->getIndex (g_curfile); for (short i = 0; i < obj->vertices(); ++i) { - LDVertex* vert = new LDVertex; + LDVertexObject* vert = new LDVertexObject; vert->pos = obj->getVertex (i); vert->setColor (obj->color()); @@ -459,7 +459,7 @@ mo->setPosition (v); mo->setTransform (mo->transform() * transform); } elif (obj->getType() == LDObject::Vertex) { - LDVertex* vert = static_cast<LDVertex*> (obj); + LDVertexObject* vert = static_cast<LDVertexObject*> (obj); vertex v = vert->pos; rotateVertex (v, rotpoint, transform); vert->pos = v; @@ -652,7 +652,7 @@ if (obj->getType() != LDObject::CondLine) continue; - LDLine* repl = static_cast<LDCondLine*> (obj)->demote(); + LDLineObject* repl = static_cast<LDCondLineObject*> (obj)->demote(); g_win->R()->compileObject (repl); ++num; }
--- a/src/ldtypes.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/ldtypes.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -83,15 +83,14 @@ setVertex (i, v); } -LDGibberish::LDGibberish() {} -LDGibberish::LDGibberish (str contents, str reason) : contents (contents), reason (reason) {} +LDErrorObject::LDErrorObject() {} // ============================================================================= -str LDComment::raw() { +str LDCommentObject::raw() { return fmt ("0 %1", text); } -str LDSubfile::raw() { +str LDSubfileObject::raw() { str val = fmt ("1 %1 %2 ", color(), position()); val += transform().stringRep(); val += ' '; @@ -99,7 +98,7 @@ return val; } -str LDLine::raw() { +str LDLineObject::raw() { str val = fmt ("2 %1", color()); for (ushort i = 0; i < 2; ++i) @@ -108,7 +107,7 @@ return val; } -str LDTriangle::raw() { +str LDTriangleObject::raw() { str val = fmt ("3 %1", color()); for (ushort i = 0; i < 3; ++i) @@ -117,7 +116,7 @@ return val; } -str LDQuad::raw() { +str LDQuadObject::raw() { str val = fmt ("4 %1", color()); for (ushort i = 0; i < 4; ++i) @@ -126,7 +125,7 @@ return val; } -str LDCondLine::raw() { +str LDCondLineObject::raw() { str val = fmt ("5 %1", color()); // Add the coordinates @@ -136,22 +135,22 @@ return val; } -str LDGibberish::raw() { +str LDErrorObject::raw() { return contents; } -str LDVertex::raw() { +str LDVertexObject::raw() { return fmt ("0 !LDFORGE VERTEX %1 %2", color(), pos); } -str LDEmpty::raw() { +str LDEmptyObject::raw() { return ""; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -const char* LDBFC::statements[] = { +const char* LDBFCObject::statements[] = { "CERTIFY CCW", "CCW", "CERTIFY CW", @@ -160,28 +159,28 @@ "INVERTNEXT", }; -str LDBFC::raw() { - return fmt ("0 BFC %1", LDBFC::statements[type]); +str LDBFCObject::raw() { + return fmt ("0 BFC %1", LDBFCObject::statements[type]); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -vector<LDTriangle*> LDQuad::splitToTriangles() { +vector<LDTriangleObject*> LDQuadObject::splitToTriangles() { // Create the two triangles based on this quadrilateral: // 0---3 0---3 3 // | | | / /| // | | ==> | / / | // | | |/ / | // 1---2 1 1---2 - LDTriangle* tri1 = new LDTriangle (getVertex (0), getVertex (1), getVertex (3)); - LDTriangle* tri2 = new LDTriangle (getVertex (1), getVertex (2), getVertex (3)); + LDTriangleObject* tri1 = new LDTriangleObject (getVertex (0), getVertex (1), getVertex (3)); + LDTriangleObject* tri2 = new LDTriangleObject (getVertex (1), getVertex (2), getVertex (3)); // The triangles also inherit the quad's color tri1->setColor (color()); tri2->setColor (color()); - vector<LDTriangle*> triangles; + vector<LDTriangleObject*> triangles; triangles << tri1; triangles << tri2; return triangles; @@ -215,7 +214,7 @@ g_curfile->addToHistory (new SwapHistory (id(), other->id())); } -LDLine::LDLine (vertex v1, vertex v2) { +LDLineObject::LDLineObject (vertex v1, vertex v2) { setVertex (0, v1); setVertex (1, v2); } @@ -255,7 +254,7 @@ case LDObject::Subfile: { - LDSubfile* ref = static_cast<LDSubfile*> (obj); + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); matrix newMatrix = transform * ref->transform(); vertex newpos = ref->position(); @@ -276,7 +275,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -vector<LDObject*> LDSubfile::inlineContents (bool deep, bool cache) { +vector<LDObject*> LDSubfileObject::inlineContents (bool deep, bool cache) { vector<LDObject*> objs, objcache; // If we have this cached, just clone that @@ -296,7 +295,7 @@ // just add it into the objects normally. Also, we only cache immediate // subfiles and this is not one. Yay, recursion! if (deep && obj->getType() == LDObject::Subfile) { - LDSubfile* ref = static_cast<LDSubfile*> (obj); + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); vector<LDObject*> otherobjs = ref->inlineContents (true, false); @@ -461,35 +460,35 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void LDObject::move (vertex vect) { (void) vect; } -void LDEmpty::move (vertex vect) { (void) vect; } -void LDBFC::move (vertex vect) { (void) vect; } -void LDComment::move (vertex vect) { (void) vect; } -void LDGibberish::move (vertex vect) { (void) vect; } +void LDEmptyObject::move (vertex vect) { (void) vect; } +void LDBFCObject::move (vertex vect) { (void) vect; } +void LDCommentObject::move (vertex vect) { (void) vect; } +void LDErrorObject::move (vertex vect) { (void) vect; } -void LDVertex::move (vertex vect) { +void LDVertexObject::move (vertex vect) { pos += vect; } -void LDSubfile::move (vertex vect) { +void LDSubfileObject::move (vertex vect) { setPosition (position() + vect); } -void LDLine::move (vertex vect) { +void LDLineObject::move (vertex vect) { for (short i = 0; i < 2; ++i) setVertex (i, getVertex (i) + vect); } -void LDTriangle::move (vertex vect) { +void LDTriangleObject::move (vertex vect) { for (short i = 0; i < 3; ++i) setVertex (i, getVertex (i) + vect); } -void LDQuad::move (vertex vect) { +void LDQuadObject::move (vertex vect) { for (short i = 0; i < 4; ++i) setVertex (i, getVertex (i) + vect); } -void LDCondLine::move (vertex vect) { +void LDCondLineObject::move (vertex vect) { for (short i = 0; i < 4; ++i) setVertex (i, getVertex (i) + vect); } @@ -499,7 +498,7 @@ // ============================================================================= #define CHECK_FOR_OBJ(N) \ if( type == LDObject::N ) \ - return new LD##N; + return new LD##N##Object; LDObject* LDObject::getDefault (const LDObject::Type type) { CHECK_FOR_OBJ (Comment) @@ -511,7 +510,7 @@ CHECK_FOR_OBJ (Quad) CHECK_FOR_OBJ (Empty) CHECK_FOR_OBJ (BFC) - CHECK_FOR_OBJ (Gibberish) + CHECK_FOR_OBJ (Error) CHECK_FOR_OBJ (Vertex) CHECK_FOR_OBJ (Overlay) return null; @@ -521,12 +520,12 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void LDObject::invert() {} -void LDBFC::invert() {} -void LDEmpty::invert() {} -void LDComment::invert() {} -void LDGibberish::invert() {} +void LDBFCObject::invert() {} +void LDEmptyObject::invert() {} +void LDCommentObject::invert() {} +void LDErrorObject::invert() {} -void LDTriangle::invert() { +void LDTriangleObject::invert() { // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. // Thus, we swap 1 and 2. vertex tmp = getVertex (1); @@ -536,7 +535,7 @@ return; } -void LDQuad::invert() { +void LDQuadObject::invert() { // Quad: 0 -> 1 -> 2 -> 3 // rev: 0 -> 3 -> 2 -> 1 // Thus, we swap 1 and 3. @@ -545,7 +544,7 @@ setVertex (3, tmp); } -void LDSubfile::invert() { +void LDSubfileObject::invert() { // Subfiles are inverted when they're prefixed with // a BFC INVERTNEXT statement. Thus we need to toggle this status. // For flat primitives it's sufficient that the determinant is @@ -555,9 +554,9 @@ ulong idx = getIndex (g_curfile); if (idx > 0) { - LDBFC* bfc = dynamic_cast<LDBFC*> (prev()); + LDBFCObject* bfc = dynamic_cast<LDBFCObject*> (prev()); - if (bfc && bfc->type == LDBFC::InvertNext) { + if (bfc && bfc->type == LDBFCObject::InvertNext) { // This is prefixed with an invertnext, thus remove it. g_curfile->forgetObject (bfc); delete bfc; @@ -566,7 +565,7 @@ } // Not inverted, thus prefix it with a new invertnext. - LDBFC* bfc = new LDBFC (LDBFC::InvertNext); + LDBFCObject* bfc = new LDBFCObject (LDBFCObject::InvertNext); g_curfile->insertObj (idx, bfc); } @@ -578,19 +577,19 @@ line->setVertex (1, tmp); } -void LDLine::invert() { +void LDLineObject::invert() { invertLine (this); } -void LDCondLine::invert() { +void LDCondLineObject::invert() { invertLine (this); } -void LDVertex::invert() {} +void LDVertexObject::invert() {} // ============================================================================= -LDLine* LDCondLine::demote() { - LDLine* repl = new LDLine; +LDLineObject* LDCondLineObject::demote() { + LDLineObject* repl = new LDLineObject; for (int i = 0; i < repl->vertices(); ++i) repl->setVertex (i, getVertex (i)); @@ -610,16 +609,16 @@ } // ============================================================================= -str LDOverlay::raw() { +str LDOverlayObject::raw() { return fmt ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6", filename(), camera(), x(), y(), width(), height()); } -void LDOverlay::move (vertex vect) { +void LDOverlayObject::move (vertex vect) { Q_UNUSED (vect) } -void LDOverlay::invert() {} +void LDOverlayObject::invert() {} // ============================================================================= // Hook the set accessors of certain properties to this changeProperty function.
--- a/src/ldtypes.h Sat Jul 13 17:35:38 2013 +0300 +++ b/src/ldtypes.h Sat Jul 13 19:02:48 2013 +0300 @@ -23,13 +23,14 @@ #include "types.h" #define LDOBJ(T) \ - virtual ~LD##T() {} \ +public: \ + virtual ~LD##T##Object() {} \ virtual LDObject::Type getType() const override { \ return LDObject::T; \ } \ virtual str raw(); \ - virtual LD##T* clone() { \ - return new LD##T (*this); \ + virtual LD##T##Object* clone() { \ + return new LD##T##Object (*this); \ } \ virtual void move (vertex vVector); \ virtual void invert(); @@ -49,7 +50,7 @@ #define LDOBJ_NO_MATRIX LDOBJ_SETMATRIX( false ) class QListWidgetItem; -class LDSubfile; +class LDSubfileObject; // ============================================================================= // LDObject @@ -78,7 +79,7 @@ BFC, // Object represents a BFC statement Overlay, // Object contains meta-info about an overlay image. Comment, // Object represents a comment - Gibberish, // Object is the result of failed parsing + Error, // Object is the result of failed parsing Empty, // Object represents an empty line Unidentified, // Object is an uninitialized (SHOULD NEVER HAPPEN) NumTypes // Amount of object types @@ -163,24 +164,24 @@ }; // ============================================================================= -// LDGibberish +// LDErrorObject // // Represents a line in the LDraw file that could not be properly parsed. It is // represented by a (!) ERROR in the code view. It exists for the purpose of // allowing garbage lines be debugged and corrected within LDForge. The member // zContent contains the contents of the unparsable line. // ============================================================================= -class LDGibberish : public LDObject { -public: - LDOBJ (Gibberish) +class LDErrorObject : public LDObject { + LDOBJ (Error) LDOBJ_NAME (error) LDOBJ_VERTICES (0) LDOBJ_UNCOLORED LDOBJ_SCEMANTIC LDOBJ_NO_MATRIX - LDGibberish(); - LDGibberish (str _zContent, str _zReason); +public: + LDErrorObject(); + LDErrorObject (str contents, str reason) : contents (contents), reason (reason) {} // Content of this unknown line str contents; @@ -190,12 +191,11 @@ }; // ============================================================================= -// LDEmptyLine +// LDEmptyObject // // Represents an empty line in the LDraw code file. // ============================================================================= -class LDEmpty : public LDObject { -public: +class LDEmptyObject : public LDObject { LDOBJ (Empty) LDOBJ_VERTICES (0) LDOBJ_UNCOLORED @@ -204,13 +204,12 @@ }; // ============================================================================= -// LDComment +// LDCommentObject // // Represents a code-0 comment in the LDraw code file. Member text contains // the text of the comment. // ============================================================================= -class LDComment : public LDObject { -public: +class LDCommentObject : public LDObject { LDOBJ (Comment) LDOBJ_NAME (comment) LDOBJ_VERTICES (0) @@ -218,31 +217,41 @@ LDOBJ_NON_SCEMANTIC LDOBJ_NO_MATRIX - LDComment() {} - LDComment (str text) : text (text) {} +public: + LDCommentObject() {} + LDCommentObject (str text) : text (text) {} str text; // The text of this comment }; // ============================================================================= -// LDBFC +// LDBFCObject // // Represents a 0 BFC statement in the LDraw code. eStatement contains the type // of this statement. // ============================================================================= -class LDBFC : public LDObject { +class LDBFCObject : public LDObject { public: - enum Type { CertifyCCW, CCW, CertifyCW, CW, NoCertify, InvertNext, NumStatements }; - + enum Type { + CertifyCCW, + CCW, + CertifyCW, + CW, + NoCertify, + InvertNext, + NumStatements + }; + LDOBJ (BFC) LDOBJ_NAME (bfc) LDOBJ_VERTICES (0) LDOBJ_UNCOLORED LDOBJ_CUSTOM_SCEMANTIC { return (type == InvertNext); } LDOBJ_NO_MATRIX - - LDBFC() {} - LDBFC (const LDBFC::Type type) : type (type) {} + +public: + LDBFCObject() {} + LDBFCObject (const LDBFCObject::Type type) : type (type) {} // Statement strings static const char* statements[]; @@ -251,22 +260,21 @@ }; // ============================================================================= -// LDSubfile +// LDSubfileObject // // Represents a single code-1 subfile reference. // ============================================================================= -class LDSubfile : public LDObject, public LDMatrixObject { - PROPERTY (LDOpenFile*, fileInfo, setFileInfo) - -public: +class LDSubfileObject : public LDObject, public LDMatrixObject { LDOBJ (Subfile) LDOBJ_NAME (subfile) LDOBJ_VERTICES (0) LDOBJ_COLORED LDOBJ_SCEMANTIC LDOBJ_HAS_MATRIX + PROPERTY (LDOpenFile*, fileInfo, setFileInfo) - LDSubfile() { +public: + LDSubfileObject() { setLinkPointer (this); } @@ -276,14 +284,13 @@ }; // ============================================================================= -// LDLine +// LDLineObject // // Represents a single code-2 line in the LDraw code file. v0 and v1 are the end // points of the line. The line is colored with dColor unless uncolored mode is // set. // ============================================================================= -class LDLine : public LDObject { -public: +class LDLineObject : public LDObject { LDOBJ (Line) LDOBJ_NAME (line) LDOBJ_VERTICES (2) @@ -291,18 +298,18 @@ LDOBJ_SCEMANTIC LDOBJ_NO_MATRIX - LDLine() {} - LDLine (vertex v1, vertex v2); +public: + LDLineObject() {} + LDLineObject (vertex v1, vertex v2); }; // ============================================================================= -// LDCondLine +// LDCondLineObject // // Represents a single code-5 conditional line. The end-points v0 and v1 are // inherited from LDLine, c0 and c1 are the control points of this line. // ============================================================================= -class LDCondLine : public LDLine { -public: +class LDCondLineObject : public LDLineObject { LDOBJ (CondLine) LDOBJ_NAME (condline) LDOBJ_VERTICES (4) @@ -310,19 +317,19 @@ LDOBJ_SCEMANTIC LDOBJ_NO_MATRIX - LDCondLine() {} - LDLine* demote(); +public: + LDCondLineObject() {} + LDLineObject* demote(); }; // ============================================================================= -// LDTriangle +// LDTriangleObject // // Represents a single code-3 triangle in the LDraw code file. Vertices v0, v1 // and v2 contain the end-points of this triangle. dColor is the color the // triangle is colored with. // ============================================================================= -class LDTriangle : public LDObject { -public: +class LDTriangleObject : public LDObject { LDOBJ (Triangle) LDOBJ_NAME (triangle) LDOBJ_VERTICES (3) @@ -330,8 +337,9 @@ LDOBJ_SCEMANTIC LDOBJ_NO_MATRIX - LDTriangle() {} - LDTriangle (vertex v0, vertex v1, vertex v2) { +public: + LDTriangleObject() {} + LDTriangleObject (vertex v0, vertex v1, vertex v2) { setVertex (0, v0); setVertex (1, v1); setVertex (2, v2); @@ -339,12 +347,12 @@ }; // ============================================================================= -// LDQuad +// LDQuadObject // // Represents a single code-4 quadrilateral. v0, v1, v2 and v3 are the end points // of the quad, dColor is the color used for the quad. // ============================================================================= -class LDQuad : public LDObject { +class LDQuadObject : public LDObject { public: LDOBJ (Quad) LDOBJ_NAME (quad) @@ -353,21 +361,21 @@ LDOBJ_SCEMANTIC LDOBJ_NO_MATRIX - LDQuad() {} + LDQuadObject() {} // Split this quad into two triangles (note: heap-allocated) - vector<LDTriangle*> splitToTriangles(); + vector<LDTriangleObject*> splitToTriangles(); }; // ============================================================================= -// LDVertex +// LDVertexObject // // The vertex is an LDForce-specific extension which represents a single // vertex which can be used as a parameter to tools or to store coordinates // with. Vertices are a part authoring tool and they should not appear in // finished parts. // ============================================================================= -class LDVertex : public LDObject { +class LDVertexObject : public LDObject { public: LDOBJ (Vertex) LDOBJ_NAME (vertex) @@ -376,19 +384,18 @@ LDOBJ_NON_SCEMANTIC LDOBJ_NO_MATRIX - LDVertex() {} + LDVertexObject() {} vertex pos; }; // ============================================================================= -// LDOverlay +// LDOverlayObject // // Overlay image meta, stored in the header of parts so as to preserve overlay // information. // ============================================================================= -class LDOverlay : public LDObject { -public: +class LDOverlayObject : public LDObject { LDOBJ (Overlay) LDOBJ_NAME (overlay) LDOBJ_VERTICES (0)
--- a/src/primitives.cpp Sat Jul 13 17:35:38 2013 +0300 +++ b/src/primitives.cpp Sat Jul 13 19:02:48 2013 +0300 @@ -332,7 +332,7 @@ vertex v0( x0, 0.0f, z0 ), v1( x1, 0.0f, z1 ); - LDLine* line = new LDLine; + LDLineObject* line = new LDLineObject; line->setVertex( 0, v0 ); line->setVertex( 1, v1 ); line->setColor( edgecolor ); @@ -383,7 +383,7 @@ v2( x2, y2, z2 ), v3( x3, y3, z3 ); - LDQuad* quad = new LDQuad; + LDQuadObject* quad = new LDQuadObject; quad->setColor( maincolor ); quad->setVertex( 0, v0 ); quad->setVertex( 1, v1 ); @@ -419,7 +419,7 @@ // Disc negatives need to go the other way around, otherwise // they'll end up upside-down. - LDTriangle* seg = new LDTriangle; + LDTriangleObject* seg = new LDTriangleObject; seg->setColor( maincolor ); seg->setVertex( type == Disc ? 0 : 2, v0 ); seg->setVertex( 1, v1 ); @@ -455,7 +455,7 @@ v0[Z] *= num; } - LDCondLine* line = new LDCondLine; + LDCondLineObject* line = new LDCondLineObject; line->setColor( edgecolor ); line->setVertex( 0, v0 ); line->setVertex( 1, v1 ); @@ -524,13 +524,12 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void generatePrimitive() -{ - QDialog* dlg = new QDialog( g_win ); +void generatePrimitive() { + QDialog* dlg = new QDialog (g_win); Ui::MakePrimUI ui; - ui.setupUi( dlg ); + ui.setupUi (dlg); - if( !dlg->exec() ) + if (!dlg->exec()) return; int segs = ui.sb_segs->value(); @@ -544,32 +543,32 @@ ui.rb_ring->isChecked() ? Ring : Cone; // Make the description - str frac = ftoa( ( ( float ) segs ) / divs ); - str name = radialFileName( type, segs, divs, num ); + 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 ) + if (frac.indexOf (".") == -1) frac += ".0"; - if( type == Ring || type == Cone ) - descr = fmt( "%1 %2 x %3", primitiveTypeName( type ), num, frac ); + if (type == Ring || type == Cone) + descr = fmt ("%1 %2 x %3", primitiveTypeName (type), num, frac); else - descr = fmt( "%1 %2", primitiveTypeName( type ), frac ); + descr = fmt ("%1 %2", primitiveTypeName (type), frac); LDOpenFile* f = new LDOpenFile; f->setName( QFileDialog::getSaveFileName( null, QObject::tr( "Save Primitive" ), name )); - *f << new LDComment( descr ); - *f << new LDComment( fmt( "Name: %1", name )); - *f << new LDComment( fmt( "Author: LDForge" )); - *f << new LDComment( fmt( "!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "" )); - *f << new LDComment( CALicense ); - *f << new LDEmpty; - *f << new LDBFC( LDBFC::CertifyCCW ); - *f << new LDEmpty; - *f << makePrimitive( type, segs, divs, num ); + *f << new LDCommentObject (descr); + *f << new LDCommentObject (fmt ("Name: %1", name)); + *f << new LDCommentObject (fmt ("Author: LDForge")); + *f << new LDCommentObject (fmt ("!LDRAW_ORG Unofficial_%1Primitive", divs == hires ? "48_" : "")); + *f << new LDCommentObject (CALicense); + *f << new LDEmptyObject; + *f << new LDBFCObject (LDBFCObject::CertifyCCW); + *f << new LDEmptyObject; + *f << makePrimitive (type, segs, divs, num); - g_win->save( f, false ); + g_win->save (f, false); delete f; }