Tue, 16 Apr 2013 14:36:56 +0300
Radial saving and reading from files
file.cpp | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.h | file | annotate | diff | comparison | revisions | |
str.cpp | file | annotate | diff | comparison | revisions | |
str.h | file | annotate | diff | comparison | revisions | |
types.cpp | file | annotate | diff | comparison | revisions | |
types.h | file | annotate | diff | comparison | revisions | |
zz_addObjectDialog.cpp | file | annotate | diff | comparison | revisions |
--- a/file.cpp Tue Apr 16 03:49:06 2013 +0300 +++ b/file.cpp Tue Apr 16 14:36:56 2013 +0300 @@ -357,6 +357,38 @@ return obj; } + + if (tokens[2] == "RADIAL") { + CHECK_TOKEN_COUNT (20) + CHECK_TOKEN_NUMBERS (4, 19) + + LDRadial::Type eType = LDRadial::NumTypes; + + for (int i = 0; i < LDRadial::NumTypes; ++i) { + if (str (LDRadial::radialTypeName ((LDRadial::Type) i)).toupper ().strip (' ') == tokens[3]) { + eType = (LDRadial::Type) i; + break; + } + } + + if (eType == LDRadial::NumTypes) + return new LDGibberish (zLine, str::mkfmt ("Unknown radial type %s", tokens[3].chars ())); + + LDRadial* obj = new LDRadial; + + obj->eRadialType = eType; // 3 + obj->dColor = atol (tokens[4]); // 4 + obj->dSegments = atol (tokens[5]); // 5 + obj->dDivisions = atol (tokens[6]); // 6 + obj->dRingNum = atol (tokens[7]); // 7 + + obj->vPosition = parseVertex (tokens, 8); // 8 - 10 + + for (short i = 0; i < 9; ++i) + obj->mMatrix[i] = atof (tokens[i + 11]); // 11 - 19 + + return obj; + } } LDComment* obj = new LDComment;
--- a/gui.cpp Tue Apr 16 03:49:06 2013 +0300 +++ b/gui.cpp Tue Apr 16 14:36:56 2013 +0300 @@ -563,7 +563,7 @@ { LDRadial* pRad = static_cast<LDRadial*> (obj); zText.format ("%d / %d %s", pRad->dSegments, pRad->dDivisions, - g_saRadialTypeNames[pRad->eRadialType]); + pRad->radialTypeName()); if (pRad->eRadialType == LDRadial::Ring || pRad->eRadialType == LDRadial::Cone) zText.appendformat (" %d", pRad->dRingNum); @@ -579,9 +579,9 @@ QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*) (null), QStringList (zText.chars()), 0); - item->setIcon (0, QIcon (str::mkfmt ("icons/%s.png", g_saObjTypeIcons[obj->getType ()]).chars())); + item->setIcon (0, getIcon (g_saObjTypeIcons[obj->getType ()])); - // Color gibberish red + // Color gibberish orange on red so it stands out. if (obj->getType() == OBJ_Gibberish) { item->setBackground (0, QColor ("#AA0000")); item->setForeground (0, QColor ("#FFAA00"));
--- a/ldtypes.cpp Tue Apr 16 03:49:06 2013 +0300 +++ b/ldtypes.cpp Tue Apr 16 14:36:56 2013 +0300 @@ -118,10 +118,7 @@ str LDSubfile::getContents () { str val = str::mkfmt ("1 %d %s ", dColor, vPosition.getStringRep (false).chars ()); - - for (short i = 0; i < 9; ++i) - val.appendformat ("%s ", ftoa (mMatrix[i]).chars()); - + val += mMatrix.getStringRep (); val += zFileName; return val; } @@ -525,14 +522,14 @@ vaCoords[i] += vVector; } -// ===========================================f================================== +// ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= LDRadial::LDRadial () { } -const char* g_saRadialTypeNames[] = { +static char const* g_saRadialTypeNames[] = { "Circle", "Cylinder", "Disc", @@ -542,6 +539,17 @@ null }; +char const* LDRadial::radialTypeName () { + return g_saRadialTypeNames[eRadialType]; +} + +char const* LDRadial::radialTypeName (const LDRadial::Type eType) { + return g_saRadialTypeNames[eType]; +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= std::vector<LDObject*> LDRadial::decompose (bool bTransform) { std::vector<LDObject*> paObjects; @@ -662,6 +670,9 @@ paObjects.push_back (pSeg); } break; + + default: + break; } } @@ -669,6 +680,8 @@ } str LDRadial::getContents () { - // TODO - return "0 !LDFORGE RADIAL"; + return str::mkfmt ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s", + str (radialTypeName()).toupper ().strip (' ').chars (), + dColor, dSegments, dDivisions, dRingNum, + vPosition.getStringRep (false).chars(), mMatrix.getStringRep().chars()); } \ No newline at end of file
--- a/ldtypes.h Tue Apr 16 03:49:06 2013 +0300 +++ b/ldtypes.h Tue Apr 16 14:36:56 2013 +0300 @@ -327,11 +327,11 @@ eRadialType (eRadialType), vPosition (vPosition), mMatrix (mMatrix), dDivisions (dDivisions), dSegments (dSegments), dRingNum (dRingNum) {} + char const* radialTypeName (); + static char const* radialTypeName (const LDRadial::Type eType); std::vector<LDObject*> decompose (bool bTransform); }; -extern const char* g_saRadialTypeNames[]; - // ============================================================================= // Object type names. Pass the return value of getType as the index to get a // string representation of the object's type.
--- a/str.cpp Tue Apr 16 03:49:06 2013 +0300 +++ b/str.cpp Tue Apr 16 14:36:56 2013 +0300 @@ -285,11 +285,11 @@ } // ============================================================================ -void str::strip (char c) { - strip ({c}); +str str::strip (char c) { + return strip ({c}); } -void str::strip (std::initializer_list<char> unwanted) { +str str::strip (std::initializer_list<char> unwanted) { str cache = text; uint oldlen = len(); @@ -308,10 +308,10 @@ *bufptr = '\0'; assert (bufptr <= buf + oldlen); - clear(); - append (buf); + str zResult = buf; + delete[] buf; - delete[] buf; + return zResult; } void str::insert (char* c, unsigned int pos) {
--- a/str.h Tue Apr 16 03:49:06 2013 +0300 +++ b/str.h Tue Apr 16 14:36:56 2013 +0300 @@ -159,8 +159,8 @@ std::vector<str> split (str del, bool bNoBlanks = false); - void strip (char c); - void strip (std::initializer_list<char> unwanted); + str strip (char c); + str strip (std::initializer_list<char> unwanted); // ====================================================================== // OPERATORS
--- a/types.cpp Tue Apr 16 03:49:06 2013 +0300 +++ b/types.cpp Tue Apr 16 14:36:56 2013 +0300 @@ -98,4 +98,19 @@ printf ("\n"); } +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +str matrix::getStringRep () { + str val; + for (short i = 0; i < 9; ++i) { + if (i > 0) + val += ' '; + + val.appendformat ("%s", ftoa (faValues[i]).chars()); + } + + return val; } \ No newline at end of file
--- a/types.h Tue Apr 16 03:49:06 2013 +0300 +++ b/types.h Tue Apr 16 14:36:56 2013 +0300 @@ -81,6 +81,7 @@ void zero (); void testOutput (); + str getStringRep(); }; #endif // __TYPES_H__ \ No newline at end of file
--- a/zz_addObjectDialog.cpp Tue Apr 16 03:49:06 2013 +0300 +++ b/zz_addObjectDialog.cpp Tue Apr 16 14:36:56 2013 +0300 @@ -75,7 +75,7 @@ qRadialType = new QComboBox; for (int i = 0; i < LDRadial::NumTypes; ++i) - qRadialType->addItem (g_saRadialTypeNames[i]); + qRadialType->addItem (LDRadial::radialTypeName ((LDRadial::Type) i)); connect (qRadialType, SIGNAL (currentIndexChanged (int)), this, SLOT (slot_radialTypeChanged (int)));