Mon, 06 May 2013 15:39:45 +0300
Further work on ext programs, LDObjectType_e integrated into LDObject
--- a/bbox.cpp Mon May 06 12:50:20 2013 +0300 +++ b/bbox.cpp Mon May 06 15:39:45 2013 +0300 @@ -46,7 +46,7 @@ // ============================================================================= void bbox::calcObject (LDObject* obj) { switch (obj->getType ()) { - case OBJ_Line: + case LDObject::Line: { LDLine* line = static_cast<LDLine*> (obj); for (short i = 0; i < 2; ++i) @@ -54,7 +54,7 @@ } break; - case OBJ_Triangle: + case LDObject::Triangle: { LDTriangle* tri = static_cast<LDTriangle*> (obj); for (short i = 0; i < 3; ++i) @@ -62,7 +62,7 @@ } break; - case OBJ_Quad: + case LDObject::Quad: { LDQuad* quad = static_cast<LDQuad*> (obj); for (short i = 0; i < 4; ++i) @@ -70,7 +70,7 @@ } break; - case OBJ_CondLine: + case LDObject::CondLine: { LDCondLine* line = static_cast<LDCondLine*> (obj); for (short i = 0; i < 4; ++i) @@ -78,7 +78,7 @@ } break; - case OBJ_Subfile: + case LDObject::Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); vector<LDObject*> objs = ref->inlineContents (true, true); @@ -90,7 +90,7 @@ } break; - case OBJ_Radial: + case LDObject::Radial: { LDRadial* rad = static_cast<LDRadial*> (obj); vector<LDObject*> objs = rad->decompose (true);
--- a/extprogs.cpp Mon May 06 12:50:20 2013 +0300 +++ b/extprogs.cpp Mon May 06 15:39:45 2013 +0300 @@ -105,10 +105,116 @@ return true; } -bool g_processDone = false; +// ============================================================================= +void writeSelection (str fname) { + // Write the input file + FILE* fp = fopen (fname, "w"); + if (!fp) { + critical (fmt ("Couldn't open temporary file %s for writing.\n", fname.chars ())); + return; + } + + for (LDObject* obj : g_win->sel ()) { + str line = fmt ("%s\r\n", obj->getContents ().chars ()); + fwrite (line.chars(), 1, ~line, fp); + } + + fclose (fp); +} + +// ============================================================================= +void runUtilityProcess (extprog prog, QStringList argv) { + QTemporaryFile input, output; + str inputname, outputname; + + if (!mkTempFile (input, inputname) || !mkTempFile (output, outputname)) + return; + + QProcess proc; + + // Init stdin + FILE* stdinfp = fopen (inputname, "w"); + + // Begin! + proc.setStandardInputFile (inputname); + proc.start (prog_ytruder.value, argv); + + // Write an enter - one is expected + char enter[2] = "\n"; + enter[1] = '\0'; + fwrite (enter, 1, sizeof enter, stdinfp); + fflush (stdinfp); + + // Wait while it runs + proc.waitForFinished (); + + if (proc.exitStatus () == QProcess::CrashExit) { + processError (prog, proc); + return; + } +} // ============================================================================= -void runYtruder () { +void insertOutput (str fname, bool replace) { + // Read the output file + FILE* fp = fopen (fname, "r"); + if (!fp) { + critical (fmt ("Couldn't open temporary file %s for reading.\n", fname.chars ())); + return; + } + + ComboHistory* cmb = new ComboHistory ({}); + std::vector<LDObject*> objs = loadFileContents (fp, null), + copies; + std::vector<ulong> indices; + + ulong idx = g_win->getInsertionPoint (); + + // If we replace the objects, delete the selection now. + if (replace) { + vector<ulong> indices; + vector<LDObject*> cache, + sel = g_win->sel (); + + for (LDObject* obj : sel) { + indices.push_back (obj->getIndex (g_curfile)); + cache.push_back (obj->clone ()); + + g_curfile->forgetObject (obj); + delete obj; + } + } + + // Insert the new objects + g_win->sel ().clear (); + for (LDObject* obj : objs) { + if (!obj->isSchemantic ()) { + delete obj; + continue; + } + + g_curfile->insertObj (idx, obj); + indices.push_back (idx); + copies.push_back (obj->clone ()); + g_win->sel ().push_back (obj); + + ++idx; + } + + if (indices.size() > 0) + cmb->paEntries.push_back (new AddHistory ({indices, copies})); + + if (cmb->paEntries.size () > 0) + History::addEntry (cmb); + else + delete cmb; + + fclose (fp); + g_win->refresh (); +} + +// ============================================================================= +MAKE_ACTION (ytruder, "Ytruder", "ytruder", "Extrude selected lines to a given plane", KEY (F8)) { if (prog_ytruder.value.len () == 0) { noPathConfigured (Ytruder); return; @@ -148,75 +254,18 @@ const double depth = dsb_depth->w ()->value (), condAngle = dsb_condAngle->w ()->value (); - QTemporaryFile in, out, input; - str inname, outname, inputname; - FILE* fp; - - if (!mkTempFile (in, inname) || !mkTempFile (out, outname) || !mkTempFile (input, inputname)) - return; + QTemporaryFile indat, outdat; + str inDATName, outDATName; - QProcess proc; - QStringList argv ({(axis == X) ? "-x" : (axis == Y) ? "-y" : "-z", - (mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r", - fmt ("%f", depth), "-a", fmt ("%f", condAngle), inname, outname}); - - printf ("cmdline: %s ", prog_ytruder.value.chars ()); - for (QString& arg : argv) - printf ("%s ", qchars (arg)); - printf ("\n"); - - // Write the input file - fp = fopen (inname, "w"); - if (!fp) + if (!mkTempFile (indat, inDATName) || !mkTempFile (outdat, outDATName)) return; - for (LDObject* obj : g_win->sel ()) { - str line = fmt ("%s\r\n", obj->getContents ().chars ()); - fwrite (line.chars(), 1, ~line, fp); - } - fclose (fp); - - // Init stdin - FILE* stdinfp = fopen (inputname, "w"); - - // Begin! - proc.setStandardInputFile (inputname); - proc.setStandardOutputFile ("blarg"); - proc.start (prog_ytruder.value, argv); - - // Write an enter - one is expected - char enter[2] = "\n"; - enter[1] = '\0'; - fwrite (enter, 1, sizeof enter, stdinfp); - fflush (stdinfp); - - // Wait while it runs - proc.waitForFinished (); + QStringList argv ({(axis == X) ? "-x" : (axis == Y) ? "-y" : "-z", + (mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r", + fmt ("%f", depth), "-a", fmt ("%f", condAngle), inDATName, outDATName + }); - if (proc.exitStatus () == QProcess::CrashExit) { - processError (Ytruder, proc); - return; - } - - // Read the output file - fp = fopen (outname, "r"); - if (!fp) - fprintf (stderr, "couldn't read %s\n", outname.chars ()); - - std::vector<LDObject*> objs = loadFileContents (fp, null), - copies; - std::vector<ulong> indices; - - g_win->sel ().clear (); - for (LDObject* obj : objs) { - ulong idx = g_curfile->addObject (obj); - indices.push_back (idx); - copies.push_back (obj->clone ()); - } - - History::addEntry (new AddHistory ({indices, copies})); - - fclose (fp); - g_win->sel () = objs; - g_win->refresh (); + writeSelection (inDATName); + runUtilityProcess (Ytruder, argv); + insertOutput (outDATName, false); } \ No newline at end of file
--- a/extprogs.h Mon May 06 12:50:20 2013 +0300 +++ b/extprogs.h Mon May 06 15:39:45 2013 +0300 @@ -29,6 +29,4 @@ DATHeader }; -void runYtruder (); - #endif // EXTPROGS_H \ No newline at end of file
--- a/file.cpp Mon May 06 12:50:20 2013 +0300 +++ b/file.cpp Mon May 06 15:39:45 2013 +0300 @@ -128,7 +128,7 @@ assert (obj != null); // Check for parse errors and warn about tthem - if (obj->getType() == OBJ_Gibberish) { + if (obj->getType() == LDObject::Gibberish) { logf (LOG_Warning, "Couldn't parse line #%lu: %s\n", lnum, static_cast<LDGibberish*> (obj)->zReason.chars()); @@ -586,7 +586,7 @@ // Go through all objects in the current file and reload the subfiles for (LDObject* obj : g_curfile->m_objs) { - if (obj->getType() == OBJ_Subfile) { + if (obj->getType() == LDObject::Subfile) { // Note: ref->pFile is invalid right now since all subfiles were closed. LDSubfile* ref = static_cast<LDSubfile*> (obj); OpenFile* pFile = loadSubfile (ref->zFileName); @@ -601,7 +601,7 @@ // Reparse gibberish files. It could be that they are invalid because // the file could not be opened. Circumstances may be different now. - if (obj->getType() == OBJ_Gibberish) + if (obj->getType() == LDObject::Gibberish) obj->replace (parseLine (static_cast<LDGibberish*> (obj)->zContents)); } }
--- a/gldraw.cpp Mon May 06 12:50:20 2013 +0300 +++ b/gldraw.cpp Mon May 06 15:39:45 2013 +0300 @@ -246,8 +246,8 @@ #if 0 if (gl_colorbfc && - obj->getType () != OBJ_Line && - obj->getType () != OBJ_CondLine) + obj->getType () != LDObject::Line && + obj->getType () != LDObject::CondLine) { if (bBackSide) glColor4f (0.9f, 0.0f, 0.0f, 1.0f); @@ -663,7 +663,7 @@ void GLRenderer::compileSubObject (LDObject* obj, const GLenum gltype) { glBegin (gltype); - const short numverts = (obj->getType () != OBJ_CondLine) ? obj->vertices () : 2; + const short numverts = (obj->getType () != LDObject::CondLine) ? obj->vertices () : 2; for (short i = 0; i < numverts; ++i) compileVertex (obj->vaCoords[i]); @@ -678,11 +678,11 @@ setObjectColor (obj); switch (obj->getType ()) { - case OBJ_Line: + case LDObject::Line: compileSubObject (obj, GL_LINES); break; - case OBJ_CondLine: + case LDObject::CondLine: glLineStipple (1, 0x6666); glEnable (GL_LINE_STIPPLE); @@ -691,15 +691,15 @@ glDisable (GL_LINE_STIPPLE); break; - case OBJ_Triangle: + case LDObject::Triangle: compileSubObject (obj, GL_TRIANGLES); break; - case OBJ_Quad: + case LDObject::Quad: compileSubObject (obj, GL_QUADS); break; - case OBJ_Subfile: + case LDObject::Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); vector<LDObject*> objs = ref->inlineContents (true, true); @@ -711,7 +711,7 @@ } break; - case OBJ_Radial: + case LDObject::Radial: { LDRadial* pRadial = static_cast<LDRadial*> (obj); std::vector<LDObject*> objs = pRadial->decompose (true); @@ -725,7 +725,7 @@ #if 0 TODO: find a proper way to draw vertices without having them be affected by zoom. - case OBJ_Vertex: + case LDObject::Vertex: { LDVertex* pVert = static_cast<LDVertex*> (obj); LDTriangle* pPoly;
--- a/gui.cpp Mon May 06 12:50:20 2013 +0300 +++ b/gui.cpp Mon May 06 15:39:45 2013 +0300 @@ -461,7 +461,7 @@ title += fmt (": %s", basename (g_curfile->m_filename.chars())); if (g_curfile->m_objs.size() > 0 && - g_curfile->m_objs[0]->getType() == OBJ_Comment) + g_curfile->m_objs[0]->getType() == LDObject::Comment) { // Append title LDComment* comm = static_cast<LDComment*> (g_curfile->m_objs[0]); @@ -541,7 +541,7 @@ for (LDObject* obj : g_curfile->m_objs) { str zText; switch (obj->getType ()) { - case OBJ_Comment: + case LDObject::Comment: zText = static_cast<LDComment*> (obj)->text.chars(); // Remove leading whitespace @@ -549,10 +549,10 @@ zText -= -1; break; - case OBJ_Empty: + case LDObject::Empty: break; // leave it empty - case OBJ_Line: + case LDObject::Line: { LDLine* line = static_cast<LDLine*> (obj); zText.format ("%s, %s", @@ -561,7 +561,7 @@ } break; - case OBJ_Triangle: + case LDObject::Triangle: { LDTriangle* triangle = static_cast<LDTriangle*> (obj); zText.format ("%s, %s, %s", @@ -571,7 +571,7 @@ } break; - case OBJ_Quad: + case LDObject::Quad: { LDQuad* quad = static_cast<LDQuad*> (obj); zText.format ("%s, %s, %s, %s", @@ -582,7 +582,7 @@ } break; - case OBJ_CondLine: + case LDObject::CondLine: { LDCondLine* line = static_cast<LDCondLine*> (obj); zText.format ("%s, %s, %s, %s", @@ -593,16 +593,16 @@ } break; - case OBJ_Gibberish: + case LDObject::Gibberish: zText.format ("ERROR: %s", static_cast<LDGibberish*> (obj)->zContents.chars()); break; - case OBJ_Vertex: + case LDObject::Vertex: zText.format ("%s", static_cast<LDVertex*> (obj)->vPosition.stringRep (true).chars()); break; - case OBJ_Subfile: + case LDObject::Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); @@ -618,14 +618,14 @@ } break; - case OBJ_BFC: + case LDObject::BFC: { LDBFC* bfc = static_cast<LDBFC*> (obj); zText = LDBFC::statements[bfc->type]; } break; - case OBJ_Radial: + case LDObject::Radial: { LDRadial* pRad = static_cast<LDRadial*> (obj); zText.format ("%d / %d %s", pRad->dSegments, pRad->dDivisions, pRad->radialTypeName()); @@ -646,7 +646,7 @@ item->setIcon (getIcon (g_saObjTypeIcons[obj->getType ()])); // Color gibberish orange on red so it stands out. - if (obj->getType() == OBJ_Gibberish) { + if (obj->getType() == LDObject::Gibberish) { item->setBackground (QColor ("#AA0000")); item->setForeground (QColor ("#FFAA00")); } else if (lv_colorize && obj->isColored () && @@ -836,14 +836,14 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -LDObjectType_e ForgeWindow::uniformSelectedType () { - LDObjectType_e eResult = OBJ_Unidentified; +LDObject::Type ForgeWindow::uniformSelectedType () { + LDObject::Type eResult = LDObject::Unidentified; for (LDObject* obj : m_sel) { - if (eResult != OBJ_Unidentified && obj->dColor != eResult) - return OBJ_Unidentified; + if (eResult != LDObject::Unidentified && obj->dColor != eResult) + return LDObject::Unidentified; - if (eResult == OBJ_Unidentified) + if (eResult == LDObject::Unidentified) eResult = obj->getType (); }
--- a/gui.h Mon May 06 12:50:20 2013 +0300 +++ b/gui.h Mon May 06 15:39:45 2013 +0300 @@ -133,7 +133,7 @@ void updateGridToolBar (); bool isSelected (LDObject* obj); short getSelectedColor(); - LDObjectType_e uniformSelectedType (); + LDObject::Type uniformSelectedType (); void scrollToSelection (); void spawnContextMenu (const QPoint pos); GLRenderer* R () { return m_renderer; }
--- a/gui_actions.cpp Mon May 06 12:50:20 2013 +0300 +++ b/gui_actions.cpp Mon May 06 15:39:45 2013 +0300 @@ -119,39 +119,39 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (newSubfile, "New Subfile", "add-subfile", "Creates a new subfile reference.", 0) { - AddObjectDialog::staticDialog (OBJ_Subfile, null); + AddObjectDialog::staticDialog (LDObject::Subfile, null); } MAKE_ACTION (newLine, "New Line", "add-line", "Creates a new line.", 0) { - AddObjectDialog::staticDialog (OBJ_Line, null); + AddObjectDialog::staticDialog (LDObject::Line, null); } MAKE_ACTION (newTriangle, "New Triangle", "add-triangle", "Creates a new triangle.", 0) { - AddObjectDialog::staticDialog (OBJ_Triangle, null); + AddObjectDialog::staticDialog (LDObject::Triangle, null); } MAKE_ACTION (newQuad, "New Quadrilateral", "add-quad", "Creates a new quadrilateral.", 0) { - AddObjectDialog::staticDialog (OBJ_Quad, null); + AddObjectDialog::staticDialog (LDObject::Quad, null); } MAKE_ACTION (newCondLine, "New Conditional Line", "add-condline", "Creates a new conditional line.", 0) { - AddObjectDialog::staticDialog (OBJ_CondLine, null); + AddObjectDialog::staticDialog (LDObject::CondLine, null); } MAKE_ACTION (newComment, "New Comment", "add-comment", "Creates a new comment.", 0) { - AddObjectDialog::staticDialog (OBJ_Comment, null); + AddObjectDialog::staticDialog (LDObject::Comment, null); } MAKE_ACTION (newBFC, "New BFC Statement", "add-bfc", "Creates a new BFC statement.", 0) { - AddObjectDialog::staticDialog (OBJ_BFC, null); + AddObjectDialog::staticDialog (LDObject::BFC, null); } MAKE_ACTION (newVertex, "New Vertex", "add-vertex", "Creates a new vertex.", 0) { - AddObjectDialog::staticDialog (OBJ_Vertex, null); + AddObjectDialog::staticDialog (LDObject::Vertex, null); } MAKE_ACTION (newRadial, "New Radial", "add-radial", "Creates a new radial.", 0) { - AddObjectDialog::staticDialog (OBJ_Radial, null); + AddObjectDialog::staticDialog (LDObject::Radial, null); } MAKE_ACTION (editObject, "Edit Object", "edit-object", "Edits this object.", 0) { @@ -216,16 +216,16 @@ if (g_win->sel ().size () == 0) return; - LDObjectType_e eType = g_win->uniformSelectedType (); + LDObject::Type eType = g_win->uniformSelectedType (); - if (eType == OBJ_Unidentified) + if (eType == LDObject::Unidentified) return; // If we're selecting subfile references, the reference filename must also // be uniform. str zRefName; - if (eType == OBJ_Subfile) { + if (eType == LDObject::Subfile) { zRefName = static_cast<LDSubfile*> (g_win->sel ()[0])->zFileName; for (LDObject* pObj : g_win->sel ()) @@ -238,7 +238,7 @@ if (obj->getType() != eType) continue; - if (eType == OBJ_Subfile && static_cast<LDSubfile*> (obj)->zFileName != zRefName) + if (eType == LDObject::Subfile && static_cast<LDSubfile*> (obj)->zFileName != zRefName) continue; g_win->sel ().push_back (obj);
--- a/gui_editactions.cpp Mon May 06 12:50:20 2013 +0300 +++ b/gui_editactions.cpp Mon May 06 15:39:45 2013 +0300 @@ -128,7 +128,7 @@ vector<ulong> ulaRefIndices, ulaBitIndices; for (LDObject* obj : sel) { - if (obj->getType() != OBJ_Subfile) + if (obj->getType() != LDObject::Subfile) continue; ulaRefIndices.push_back (obj->getIndex (g_curfile)); @@ -144,9 +144,9 @@ vector<LDObject*> objs; - if (obj->getType() == OBJ_Subfile) + if (obj->getType() == LDObject::Subfile) objs = static_cast<LDSubfile*> (obj)->inlineContents (bDeep, true); - else if (obj->getType() == OBJ_Radial) + else if (obj->getType() == LDObject::Radial) objs = static_cast<LDRadial*> (obj)->decompose (true); else continue; @@ -191,7 +191,7 @@ // Store stuff first for history archival for (LDObject* obj : objs) { - if (obj->getType() != OBJ_Quad) + if (obj->getType() != LDObject::Quad) continue; ulaIndices.push_back (obj->getIndex (g_curfile)); @@ -199,7 +199,7 @@ } for (LDObject* obj : objs) { - if (obj->getType() != OBJ_Quad) + if (obj->getType() != LDObject::Quad) continue; // Find the index of this quad @@ -281,13 +281,13 @@ vector<LDObject*> paObjs; for (LDObject* obj : objs) { - if (obj->getType() != OBJ_Quad && obj->getType() != OBJ_Triangle) + if (obj->getType() != LDObject::Quad && obj->getType() != LDObject::Triangle) continue; short dNumLines; LDLine* lines[4]; - if (obj->getType() == OBJ_Quad) { + if (obj->getType() == LDObject::Quad) { dNumLines = 4; LDQuad* quad = static_cast<LDQuad*> (obj); @@ -460,8 +460,8 @@ bool bEdited = false; switch (obj->getType ()) { - case OBJ_Line: - case OBJ_CondLine: + case LDObject::Line: + case LDObject::CondLine: { // For lines, we swap the vertices. I don't think that a // cond-line's control points need to be swapped, do they? @@ -476,7 +476,7 @@ } break; - case OBJ_Triangle: + case LDObject::Triangle: { // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. // Thus, we swap 1 and 2. @@ -491,7 +491,7 @@ } break; - case OBJ_Quad: + case LDObject::Quad: { // Quad: 0 -> 1 -> 2 -> 3 // rev: 0 -> 3 -> 2 -> 1 @@ -507,8 +507,8 @@ } break; - case OBJ_Subfile: - case OBJ_Radial: + case LDObject::Subfile: + case LDObject::Radial: { // Subfiles and radials are inverted when they're prefixed with // a BFC INVERTNEXT statement. Thus we need to toggle this status. @@ -586,9 +586,9 @@ // Calculate center vertex for (LDObject* obj : sel) { - if (obj->getType () == OBJ_Subfile) + if (obj->getType () == LDObject::Subfile) box << static_cast<LDSubfile*> (obj)->vPosition; - else if (obj->getType () == OBJ_Radial) + else if (obj->getType () == LDObject::Radial) box << static_cast<LDRadial*> (obj)->vPosition; else box << obj; @@ -601,17 +601,17 @@ if (obj->vertices ()) for (short i = 0; i < obj->vertices (); ++i) queue.push_back (&obj->vaCoords[i]); - else if (obj->getType () == OBJ_Subfile) { + else if (obj->getType () == LDObject::Subfile) { LDSubfile* ref = static_cast<LDSubfile*> (obj); queue.push_back (&ref->vPosition); ref->mMatrix = ref->mMatrix * transform; - } else if (obj->getType () == OBJ_Radial) { + } else if (obj->getType () == LDObject::Radial) { LDRadial* rad = static_cast<LDRadial*> (obj); queue.push_back (&rad->vPosition); rad->mMatrix = rad->mMatrix * transform; - } else if (obj->getType () == OBJ_Vertex) + } else if (obj->getType () == LDObject::Vertex) queue.push_back (&static_cast<LDVertex*> (obj)->vPosition); } @@ -676,7 +676,7 @@ indices.push_back (obj->getIndex (g_curfile)); oldCopies.push_back (obj->clone ()); - obj->dColor = (obj->getType () == OBJ_Line || obj->getType () == OBJ_CondLine) ? edgecolor : maincolor; + obj->dColor = (obj->getType () == LDObject::Line || obj->getType () == LDObject::CondLine) ? edgecolor : maincolor; newCopies.push_back (obj->clone ()); } @@ -684,11 +684,4 @@ History::addEntry (new EditHistory (indices, oldCopies, newCopies)); g_win->refresh (); } -} - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -MAKE_ACTION (ytruder, "Ytruder", "ytruder", "Extrude selected lines to a given plane", KEY (F8)) { - runYtruder (); } \ No newline at end of file
--- a/history.cpp Mon May 06 12:50:20 2013 +0300 +++ b/history.cpp Mon May 06 15:39:45 2013 +0300 @@ -292,7 +292,7 @@ for (long i = ulaRefIndices.size() - 1; i >= 0; --i) { ulong idx = ulaRefIndices[i]; - assert (g_curfile->object (idx)->getType () == OBJ_Subfile); + assert (g_curfile->object (idx)->getType () == LDObject::Subfile); LDSubfile* ref = static_cast<LDSubfile*> (g_curfile->object (idx)); vector<LDObject*> objs = ref->inlineContents (bDeep, false);
--- a/history.h Mon May 06 12:50:20 2013 +0300 +++ b/history.h Mon May 06 15:39:45 2013 +0300 @@ -189,9 +189,9 @@ public: IMPLEMENT_HISTORY_TYPE (Combo) - const std::vector<HistoryEntry*> paEntries; + std::vector<HistoryEntry*> paEntries; - ComboHistory (const std::vector<HistoryEntry*> paEntries) : paEntries (paEntries) {} + ComboHistory (std::vector<HistoryEntry*> paEntries) : paEntries (paEntries) {} }; // =============================================================================
--- a/ldforge.pro Mon May 06 12:50:20 2013 +0300 +++ b/ldforge.pro Mon May 06 15:39:45 2013 +0300 @@ -33,13 +33,14 @@ zz_newPartDialog.h \ zz_setContentsDialog.h -SOURCES += bbox.cpp \ +SOURCES += \ + gldraw.cpp \ + gui.cpp \ + bbox.cpp \ colors.cpp \ config.cpp \ extprogs.cpp \ file.cpp \ - gldraw.cpp \ - gui.cpp \ gui_actions.cpp \ gui_editactions.cpp \ history.cpp \
--- a/ldtypes.cpp Mon May 06 12:50:20 2013 +0300 +++ b/ldtypes.cpp Mon May 06 15:39:45 2013 +0300 @@ -216,15 +216,15 @@ // ============================================================================= static void transformObject (LDObject* obj, matrix<3> transform, vertex pos, short parentcolor) { switch (obj->getType()) { - case OBJ_Line: - case OBJ_CondLine: - case OBJ_Triangle: - case OBJ_Quad: + case LDObject::Line: + case LDObject::CondLine: + case LDObject::Triangle: + case LDObject::Quad: for (short i = 0; i < obj->vertices (); ++i) obj->vaCoords[i].transform (transform, pos); break; - case OBJ_Subfile: + case LDObject::Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); @@ -259,14 +259,14 @@ for (LDObject* obj : pFile->m_objs) { // Skip those without schemantic meaning switch (obj->getType ()) { - case OBJ_Comment: - case OBJ_Empty: - case OBJ_Gibberish: - case OBJ_Unidentified: - case OBJ_Vertex: + case LDObject::Comment: + case LDObject::Empty: + case LDObject::Gibberish: + case LDObject::Unidentified: + case LDObject::Vertex: continue; - case OBJ_BFC: + case LDObject::BFC: // Filter non-INVERTNEXT statements if (static_cast<LDBFC*> (obj)->type != LDBFC::InvertNext) continue; @@ -279,7 +279,7 @@ // Got another sub-file reference, inline it if we're deep-inlining. If not, // just add it into the objects normally. Also, we only cache immediate // subfiles and this is not one. Yay, recursion! - if (bDeepInline && obj->getType() == OBJ_Subfile) { + if (bDeepInline && obj->getType() == LDObject::Subfile) { LDSubfile* ref = static_cast<LDSubfile*> (obj); vector<LDObject*> otherobjs = ref->inlineContents (true, false); @@ -364,8 +364,8 @@ if (objs.size() == 0) return "nothing"; // :) - for (long i = 0; i < NUM_ObjectTypes; ++i) { - LDObjectType_e objType = (LDObjectType_e) i; + for (long i = 0; i < LDObject::NumTypes; ++i) { + LDObject::Type objType = (LDObject::Type) i; ulong objCount = 0; for (LDObject* obj : objs) @@ -381,7 +381,7 @@ str noun = fmt ("%s%s", g_saObjTypeNames[objType], PLURAL (objCount)); // Plural of "vertex" is "vertices". Stupid English. - if (objType == OBJ_Vertex && objCount != 1) + if (objType == LDObject::Vertex && objCount != 1) noun = "vertices"; text.appendformat ("%lu %s", objCount, noun.chars ()); @@ -623,41 +623,41 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= str LDRadial::makeFileName () { - short dNumerator = dSegments, - dDenominator = dDivisions; + short numer = dSegments, + denom = dDivisions; // Simplify the fractional part, but the denominator must be at least 4. - simplify (dNumerator, dDenominator); + simplify (numer, denom); - if (dDenominator < 4) { - const short dFactor = (4 / dDenominator); + if (denom < 4) { + const short factor = (4 / denom); - dNumerator *= dFactor; - dDenominator *= dFactor; + numer *= factor; + denom *= factor; } // Compose some general information: prefix, fraction, root, ring number - str zPrefix = (dDivisions == 16) ? "" : fmt ("%d/", dDivisions); - str zFrac = fmt ("%d-%d", dNumerator, dDenominator); - str zRoot = g_saRadialNameRoots[eRadialType]; - str zRingNum = (eRadialType == Ring || eRadialType == Cone) ? fmt ("%d", dRingNum) : ""; + str prefix = (dDivisions == 16) ? "" : fmt ("%d/", dDivisions); + str frac = fmt ("%d-%d", numer, denom); + str root = g_saRadialNameRoots[eRadialType]; + str ringNum = (eRadialType == Ring || eRadialType == Cone) ? fmt ("%d", dRingNum) : ""; // Truncate the root if necessary (7-16rin4.dat for instance). // However, always keep the root at least 2 characters. - short dExtra = (~zFrac + ~zRingNum + ~zRoot) - 8; - zRoot -= min<short> (max<short> (dExtra, 0), 2); + short extra = (~frac + ~ringNum + ~root) - 8; + root -= min<short> (max<short> (extra, 0), 2); // Stick them all together and return the result. - return fmt ("%s%s%s%s", zPrefix.chars(), zFrac.chars (), zRoot.chars (), zRingNum.chars ()); + return fmt ("%s%s%s%s", prefix.chars(), frac.chars (), root.chars (), ringNum.chars ()); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= #define CHECK_FOR_OBJ(N) \ - if (type == OBJ_##N) \ + if (type == LDObject::##N) \ return new LD##N; -LDObject* LDObject::getDefault (const LDObjectType_e type) { +LDObject* LDObject::getDefault (const LDObject::Type type) { CHECK_FOR_OBJ (Comment) CHECK_FOR_OBJ (BFC) CHECK_FOR_OBJ (Line)
--- a/ldtypes.h Mon May 06 12:50:20 2013 +0300 +++ b/ldtypes.h Mon May 06 15:39:45 2013 +0300 @@ -25,8 +25,8 @@ #define IMPLEMENT_LDTYPE(T, NUMVERTS) \ LD##T () {} \ virtual ~LD##T () {} \ - virtual LDObjectType_e getType () const { \ - return OBJ_##T; \ + virtual LDObject::Type getType () const { \ + return LDObject::T; \ } \ virtual str getContents (); \ virtual LD##T* clone () { \ @@ -39,31 +39,14 @@ #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) +#define LDOBJ_CUSTOM_SCHEMANTIC virtual bool isSchemantic () const +#define LDOBJ_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return true; } +#define LDOBJ_NON_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return false; } + class QListWidgetItem; class LDSubfile; // ============================================================================= -// LDObjectType_e -// -// Object type codes. Codes are sorted in order of significance. -// ============================================================================= -enum LDObjectType_e { - OBJ_Subfile, // Object represents a sub-file reference - OBJ_Radial, // Object represents a generic radial - OBJ_Quad, // Object represents a quadrilateral - OBJ_Triangle, // Object represents a triangle - OBJ_Line, // Object represents a line - OBJ_CondLine, // Object represents a conditional line - OBJ_Vertex, // Object is a vertex, LDForge extension object - OBJ_BFC, // Object represents a BFC statement - OBJ_Comment, // Object represents a comment - OBJ_Gibberish, // Object is the result of failed parsing - OBJ_Empty, // Object represents an empty line - OBJ_Unidentified, // Object is an uninitialized (SHOULD NEVER HAPPEN) - NUM_ObjectTypes // Amount of object types -}; - -// ============================================================================= // LDObject // // Base class object for all LD* types. Each LDObject represents a single line @@ -73,6 +56,23 @@ // ============================================================================= class LDObject { public: + // Object type codes. Codes are sorted in order of significance. + enum Type { + Subfile, // Object represents a sub-file reference + Radial, // Object represents a generic radial + Quad, // Object represents a quadrilateral + Triangle, // Object represents a triangle + Line, // Object represents a line + CondLine, // Object represents a conditional line + Vertex, // Object is a vertex, LDForge extension object + BFC, // Object represents a BFC statement + Comment, // Object represents a comment + Gibberish, // 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 + }; + LDObject (); virtual ~LDObject (); @@ -93,8 +93,8 @@ LDObject* parent; // Type enumerator of this object - virtual LDObjectType_e getType () const { - return OBJ_Unidentified; + virtual LDObject::Type getType () const { + return LDObject::Unidentified; }; // A string that represents this line @@ -121,23 +121,28 @@ LDObject* topLevelParent (); // Number of vertices this object has - virtual short vertices () const { - return 0; - } + virtual short vertices () const { return 0; } // Is this object colored? - virtual bool isColored () const { - return false; - } + virtual bool isColored () const { return false; } + + // Does this object have meaning in the part model? + virtual bool isSchemantic () const { return false; } // Returns a sample object by the given value - static LDObject* getDefault (const LDObjectType_e type); + static LDObject* getDefault (const LDObject::Type type); static void moveObjects (std::vector<LDObject*> objs, const bool bUp); static str objectListContents (const std::vector<LDObject*>& objs); // Object list entry for this object QListWidgetItem* qObjListEntry; + + uint32 groups () const { return m_groups; } + void setGroups (const uint32 groups) { m_groups = groups; } + +private: + uint32 m_groups; }; // ============================================================================= @@ -152,6 +157,7 @@ public: IMPLEMENT_LDTYPE (Gibberish, 0) LDOBJ_UNCOLORED + LDOBJ_SCHEMANTIC LDGibberish (str _zContent, str _zReason); @@ -171,6 +177,7 @@ public: IMPLEMENT_LDTYPE (Empty, 0) LDOBJ_UNCOLORED + LDOBJ_NON_SCHEMANTIC }; // ============================================================================= @@ -183,6 +190,7 @@ public: IMPLEMENT_LDTYPE (Comment, 0) LDOBJ_UNCOLORED + LDOBJ_NON_SCHEMANTIC LDComment (str zText) : text (zText) {} @@ -209,6 +217,7 @@ IMPLEMENT_LDTYPE (BFC, 0) LDOBJ_UNCOLORED + LDOBJ_CUSTOM_SCHEMANTIC { return (type == InvertNext); } LDBFC (const LDBFC::Type eType) : type (eType) {} @@ -227,6 +236,7 @@ public: IMPLEMENT_LDTYPE (Subfile, 0) LDOBJ_COLORED + LDOBJ_SCHEMANTIC vertex vPosition; // Position of the subpart (FIXME: should get rid of this) matrix<3> mMatrix; // Transformation matrix for the subpart @@ -249,6 +259,7 @@ public: IMPLEMENT_LDTYPE (Line, 2) LDOBJ_COLORED + LDOBJ_SCHEMANTIC LDLine (vertex v1, vertex v2); }; @@ -263,6 +274,7 @@ public: IMPLEMENT_LDTYPE (CondLine, 4) LDOBJ_COLORED + LDOBJ_SCHEMANTIC }; // ============================================================================= @@ -276,6 +288,7 @@ public: IMPLEMENT_LDTYPE (Triangle, 3) LDOBJ_COLORED + LDOBJ_SCHEMANTIC LDTriangle (vertex _v0, vertex _v1, vertex _v2) { vaCoords[0] = _v0; @@ -294,6 +307,7 @@ public: IMPLEMENT_LDTYPE (Quad, 4) LDOBJ_COLORED + LDOBJ_SCHEMANTIC // Split this quad into two triangles (note: heap-allocated) vector<LDTriangle*> splitToTriangles (); @@ -311,6 +325,7 @@ public: IMPLEMENT_LDTYPE (Vertex, 0) // TODO: move vPosition to vaCoords[0] LDOBJ_COLORED + LDOBJ_NON_SCHEMANTIC vertex vPosition; }; @@ -338,6 +353,7 @@ IMPLEMENT_LDTYPE (Radial, 0) LDOBJ_COLORED + LDOBJ_SCHEMANTIC LDRadial::Type eRadialType; vertex vPosition;
--- a/zz_addObjectDialog.cpp Mon May 06 12:50:20 2013 +0300 +++ b/zz_addObjectDialog.cpp Mon May 06 15:39:45 2013 +0300 @@ -45,7 +45,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -AddObjectDialog::AddObjectDialog (const LDObjectType_e type, LDObject* obj, QWidget* parent) : +AddObjectDialog::AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent) : QDialog (parent) { short coordCount = 0; @@ -56,30 +56,30 @@ lb_typeIcon->setPixmap (icon); switch (type) { - case OBJ_Comment: + case LDObject::Comment: le_comment = new QLineEdit; if (obj) le_comment->setText (static_cast<LDComment*> (obj)->text); break; - case OBJ_Line: + case LDObject::Line: coordCount = 6; break; - case OBJ_Triangle: + case LDObject::Triangle: coordCount = 9; break; - case OBJ_Quad: - case OBJ_CondLine: + case LDObject::Quad: + case LDObject::CondLine: coordCount = 12; break; - case OBJ_Vertex: + case LDObject::Vertex: coordCount = 3; break; - case OBJ_BFC: + case LDObject::BFC: rb_bfcType = new RadioBox ("Statement", {}, 0, Qt::Vertical); for (int i = 0; i < LDBFC::NumStatements; ++i) @@ -89,7 +89,7 @@ rb_bfcType->setValue ((int) static_cast<LDBFC*> (obj)->type); break; - case OBJ_Subfile: + case LDObject::Subfile: coordCount = 3; enum { @@ -141,7 +141,7 @@ } break; - case OBJ_Radial: + case LDObject::Radial: coordCount = 3; lb_radType = new QLabel ("Type:"); @@ -187,7 +187,7 @@ if (obj != null) dColor = obj->dColor; else - dColor = (type == OBJ_CondLine || type == OBJ_Line) ? edgecolor : maincolor; + dColor = (type == LDObject::CondLine || type == LDObject::Line) ? edgecolor : maincolor; pb_color = new QPushButton; setButtonBackground (pb_color, dColor); @@ -207,10 +207,10 @@ layout->addWidget (lb_typeIcon, 0, 0); switch (type) { - case OBJ_Line: - case OBJ_CondLine: - case OBJ_Triangle: - case OBJ_Quad: + case LDObject::Line: + case LDObject::CondLine: + case LDObject::Triangle: + case LDObject::Quad: // Apply coordinates if (obj) { for (short i = 0; i < coordCount / 3; ++i) @@ -219,15 +219,15 @@ } break; - case OBJ_Comment: + case LDObject::Comment: layout->addWidget (le_comment, 0, 1); break; - case OBJ_BFC: + case LDObject::BFC: layout->addWidget (rb_bfcType, 0, 1); break; - case OBJ_Radial: + case LDObject::Radial: layout->addWidget (rb_radType, 1, 1, 3, 1); layout->addWidget (cb_radHiRes, 1, 2); layout->addWidget (lb_radSegments, 2, 2); @@ -240,7 +240,7 @@ dsb_coords[i]->setValue (static_cast<LDRadial*> (obj)->vPosition.coord (i)); break; - case OBJ_Subfile: + case LDObject::Subfile: layout->addWidget (tw_subfileList, 1, 1); layout->addWidget (le_subfileName, 2, 1); @@ -336,7 +336,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void AddObjectDialog::staticDialog (const LDObjectType_e type, LDObject* obj) { +void AddObjectDialog::staticDialog (const LDObject::Type type, LDObject* obj) { const bool newObject = (obj == null); AddObjectDialog dlg (type, obj); @@ -351,14 +351,14 @@ backup = obj->clone (); switch (type) { - case OBJ_Comment: + case LDObject::Comment: { LDComment* comm = initObj<LDComment> (obj); comm->text = dlg.le_comment->text (); } break; - case OBJ_Line: + case LDObject::Line: { LDLine* line = initObj<LDLine> (obj); line->dColor = dlg.dColor; @@ -366,7 +366,7 @@ } break; - case OBJ_Triangle: + case LDObject::Triangle: { LDTriangle* tri = initObj<LDTriangle> (obj); tri->dColor = dlg.dColor; @@ -374,7 +374,7 @@ } break; - case OBJ_Quad: + case LDObject::Quad: { LDQuad* quad = initObj<LDQuad> (obj); quad->dColor = dlg.dColor; @@ -382,7 +382,7 @@ } break; - case OBJ_CondLine: + case LDObject::CondLine: { LDCondLine* line = initObj<LDCondLine> (obj); line->dColor = dlg.dColor; @@ -390,14 +390,14 @@ } break; - case OBJ_BFC: + case LDObject::BFC: { LDBFC* bfc = initObj<LDBFC> (obj); bfc->type = (LDBFC::Type) dlg.rb_bfcType->value (); } break; - case OBJ_Vertex: + case LDObject::Vertex: { LDVertex* vert = initObj<LDVertex> (obj); vert->dColor = dlg.dColor; @@ -407,7 +407,7 @@ } break; - case OBJ_Radial: + case LDObject::Radial: { LDRadial* pRad = initObj<LDRadial> (obj); pRad->dColor = dlg.dColor; @@ -423,7 +423,7 @@ } break; - case OBJ_Subfile: + case LDObject::Subfile: { str name = dlg.le_subfileName->text (); if (~name == 0)
--- a/zz_addObjectDialog.h Mon May 06 12:50:20 2013 +0300 +++ b/zz_addObjectDialog.h Mon May 06 15:39:45 2013 +0300 @@ -35,8 +35,8 @@ Q_OBJECT public: - AddObjectDialog (const LDObjectType_e type, LDObject* obj, QWidget* parent = null); - static void staticDialog (const LDObjectType_e type, LDObject* obj); + AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent = null); + static void staticDialog (const LDObject::Type type, LDObject* obj); QLabel* lb_typeIcon;
--- a/zz_historyDialog.cpp Mon May 06 12:50:20 2013 +0300 +++ b/zz_historyDialog.cpp Mon May 06 15:39:45 2013 +0300 @@ -101,18 +101,18 @@ // Determine a common type for these objects. If all objects are of the same // type, we display its addition icon. Otherwise, we draw a subfile addition // one as a default. - LDObjectType_e eCommonType = OBJ_Unidentified; + LDObject::Type eCommonType = LDObject::Unidentified; for (LDObject* obj : subentry->paObjs) { - if (eCommonType == OBJ_Unidentified or obj->getType() == eCommonType) + if (eCommonType == LDObject::Unidentified or obj->getType() == eCommonType) eCommonType = obj->getType (); else { - eCommonType = OBJ_Unidentified; + eCommonType = LDObject::Unidentified; break; } } // Set the icon based on the common type decided above. - if (eCommonType == OBJ_Unidentified) + if (eCommonType == LDObject::Unidentified) entryIcon = getIcon ("add-subfile"); else entryIcon = getIcon (fmt ("add-%s", g_saObjTypeIcons[eCommonType]));
--- a/zz_setContentsDialog.cpp Mon May 06 12:50:20 2013 +0300 +++ b/zz_setContentsDialog.cpp Mon May 06 15:39:45 2013 +0300 @@ -40,7 +40,7 @@ "standard</a> for further information."); le_contents->setMinimumWidth (384); - if (obj->getType() == OBJ_Gibberish) { + if (obj->getType() == LDObject::Gibberish) { lb_error = new QLabel; lb_error->setText (fmt ("<span style=\"color: #900\">%s</span>", static_cast<LDGibberish*> (obj)->zReason.chars())); @@ -59,7 +59,7 @@ QHBoxLayout* layout2 = new QHBoxLayout; - if (obj->getType() == OBJ_Gibberish) { + if (obj->getType() == LDObject::Gibberish) { layout2->addWidget (lb_errorIcon); layout2->addWidget (lb_error); }