Mon, 08 Jul 2013 01:29:28 +0300
primitive generator: add conditional lines to cylinders; improved bad color handling
src/addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/messagelog.cpp | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/primitives.cpp | file | annotate | diff | comparison | revisions |
--- a/src/addObjectDialog.cpp Sun Jul 07 23:43:43 2013 +0300 +++ b/src/addObjectDialog.cpp Mon Jul 08 01:29:28 2013 +0300 @@ -242,10 +242,14 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void AddObjectDialog::setButtonBackground (QPushButton* button, short color) { +void AddObjectDialog::setButtonBackground (QPushButton* button, short colnum) { + color* col = getColor ( colnum ); + button->setIcon (getIcon ("palette")); button->setAutoFillBackground (true); - button->setStyleSheet (fmt ("background-color: %1", getColor (color)->hexcode)); + + if( col ) + button->setStyleSheet (fmt ("background-color: %1", col->hexcode)); } // =============================================================================
--- a/src/file.cpp Sun Jul 07 23:43:43 2013 +0300 +++ b/src/file.cpp Mon Jul 08 01:29:28 2013 +0300 @@ -223,10 +223,8 @@ // Check for parse errors and warn about tthem if( obj->getType () == LDObject::Gibberish ) { - log( "Couldn't parse line #%lu: %s\n", - m_progress + 1, static_cast<LDGibberish*> (obj)->reason ); - - log( "- Line was: %s\n", line ); + log( "Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDGibberish*> (obj)->reason ); + log( "- Line was: %1", line ); if( m_warningsPointer ) ( *m_warningsPointer )++;
--- a/src/gldraw.cpp Sun Jul 07 23:43:43 2013 +0300 +++ b/src/gldraw.cpp Mon Jul 08 01:29:28 2013 +0300 @@ -261,14 +261,16 @@ qcol = getMainColor (); else { color* col = getColor (obj->color ()); - qcol = col->faceColor; + + if( col ) + qcol = col->faceColor; } if (obj->color () == edgecolor) { qcol = luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black; color* col; - if (!gl_blackedges && obj->parent () != null && (col = getColor (obj->parent ()->color ())) != null) + if (!gl_blackedges && obj->parent () && (col = getColor (obj->parent ()->color ()))) qcol = col->edgeColor; }
--- a/src/messagelog.cpp Sun Jul 07 23:43:43 2013 +0300 +++ b/src/messagelog.cpp Mon Jul 08 01:29:28 2013 +0300 @@ -115,5 +115,7 @@ void DoLog( std::initializer_list<StringFormatArg> args ) { - g_win->addMessage( DoFormat( args )); + const str msg = DoFormat( args ); + g_win->addMessage( msg ); + print( "%1\n", msg ); } \ No newline at end of file
--- a/src/misc.cpp Sun Jul 07 23:43:43 2013 +0300 +++ b/src/misc.cpp Mon Jul 08 01:29:28 2013 +0300 @@ -289,6 +289,7 @@ // between locales (i.e. fails to read decimals properly). That is // quite undesired... setlocale( LC_NUMERIC, "C" ); + char* buf = new char[val.length()]; char* bufptr = &buf[0];
--- a/src/primitives.cpp Sun Jul 07 23:43:43 2013 +0300 +++ b/src/primitives.cpp Mon Jul 08 01:29:28 2013 +0300 @@ -308,31 +308,36 @@ return g_primListerMutex; } +double radialPoint( int i, int divs, double ( *func )( double )) +{ + return ( *func )(( i * 2 * pi ) / divs ); +} + vector<LDObject*> makePrimitive( PrimitiveType type, int segs, int divs, int num ) { vector<LDObject*> objs; for( int i = 0; i < segs; ++i ) { - double x0 = cos( ( i * 2 * pi ) / divs ), - x1 = cos( ( ( i + 1 ) * 2 * pi ) / divs ), - z0 = sin( ( i * 2 * pi ) / divs ), - z1 = sin( ( ( i + 1 ) * 2 * pi ) / divs ); - - LDObject* obj = null; + double x = radialPoint( i, divs, cos ), + nextX = radialPoint( i + 1, divs, cos ), + prevX = radialPoint(( i + 15 ) % 16, divs, cos ), + z = radialPoint( i, divs, sin ), + nextZ = radialPoint( i + 1, divs, sin ), + prevZ = radialPoint(( i + 15 ) % 16, divs, sin ); switch( type ) { case Circle: { - vertex v0( x0, 0.0f, z0 ), - v1( x1, 0.0f, z1 ); + vertex v0( x, 0.0f, z ), + v1( nextX, 0.0f, nextZ ); LDLine* line = new LDLine; line->setVertex( 0, v0 ); line->setVertex( 1, v1 ); line->setColor( edgecolor ); - obj = line; + objs << line; } break; @@ -345,25 +350,25 @@ if( type == Cylinder ) { - x2 = x1; - x3 = x0; - z2 = z1; - z3 = z0; + x2 = nextX; + x3 = x; + z2 = nextZ; + z3 = z; y0 = y1 = 0.0f; y2 = y3 = 1.0f; } else { - x2 = x1 * ( num + 1 ); - x3 = x0 * ( num + 1 ); - z2 = z1 * ( num + 1 ); - z3 = z0 * ( num + 1 ); + x2 = nextX * ( num + 1 ); + x3 = x * ( num + 1 ); + z2 = nextZ * ( num + 1 ); + z3 = z * ( num + 1 ); - x0 *= num; - x1 *= num; - z0 *= num; - z1 *= num; + x *= num; + nextX *= num; + z *= num; + nextZ *= num; if( type == Ring ) y0 = y1 = y2 = y3 = 0.0f; @@ -374,8 +379,8 @@ } } - vertex v0( x0, y0, z0 ), - v1( x1, y1, z1 ), + vertex v0( x, y0, z ), + v1( nextX, y1, nextZ ), v2( x2, y2, z2 ), v3( x3, y3, z3 ); @@ -385,7 +390,21 @@ quad->setVertex( 1, v1 ); quad->setVertex( 2, v2 ); quad->setVertex( 3, v3 ); - obj = quad; + objs << quad; + + LDCondLine* cond = null; + if( type == Cylinder ) + { + cond = new LDCondLine; + cond->setColor( edgecolor ); + cond->setVertex( 0, v0 ); + cond->setVertex( 1, v3 ); + cond->setVertex( 2, vertex( nextX, 0.0f, nextZ )); + cond->setVertex( 3, vertex( prevX, 0.0f, prevZ )); + } + + if( cond ) + objs << cond; } break; @@ -398,12 +417,12 @@ x2 = z2 = 0.0f; else { - x2 = ( x0 >= 0.0f ) ? 1.0f : -1.0f; - z2 = ( z0 >= 0.0f ) ? 1.0f : -1.0f; + x2 = ( x >= 0.0f ) ? 1.0f : -1.0f; + z2 = ( z >= 0.0f ) ? 1.0f : -1.0f; } - vertex v0( x0, 0.0f, z0 ), - v1( x1, 0.0f, z1 ), + vertex v0( x, 0.0f, z ), + v1( nextX, 0.0f, nextZ ), v2( x2, 0.0f, z2 ); // Disc negatives need to go the other way around, otherwise @@ -413,16 +432,13 @@ seg->setVertex( type == Disc ? 0 : 2, v0 ); seg->setVertex( 1, v1 ); seg->setVertex( type == Disc ? 2 : 0, v2 ); - obj = seg; + objs << seg; } break; default: break; } - - if( obj ) - objs << obj; } return objs; @@ -435,8 +451,7 @@ type == Cylinder ? "Cylinder" : type == Disc ? "Disc" : type == DiscNeg ? "Disc Negative" : - type == Ring ? "Ring" : - "Cone"; + type == Ring ? "Ring" : "Cone"; } static const str g_radialNameRoots[] =