Wed, 20 Mar 2013 01:58:05 +0200
Added triangle, quad and condline to the add object dialog
bbox.cpp | file | annotate | diff | comparison | revisions | |
common.h | file | annotate | diff | comparison | revisions | |
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 | |
zz_addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_addObjectDialog.h | file | annotate | diff | comparison | revisions |
--- a/bbox.cpp Tue Mar 19 21:52:38 2013 +0200 +++ b/bbox.cpp Wed Mar 20 01:58:05 2013 +0200 @@ -59,10 +59,8 @@ case OBJ_CondLine: { LDCondLine* line = static_cast<LDCondLine*> (obj); - for (short i = 0; i < 2; ++i) { + for (short i = 0; i < 4; ++i) checkVertex (line->vaCoords[i]); - checkVertex (line->vaControl[i]); - } } break;
--- a/common.h Tue Mar 19 21:52:38 2013 +0200 +++ b/common.h Wed Mar 20 01:58:05 2013 +0200 @@ -53,6 +53,10 @@ #define DIRSLASH "/" #endif // WIN32 +static const double fMaxCoord = 10000.0; +static const short dMainColor = 16; +static const short dEdgeColor = 24; + using std::vector; class ForgeWindow;
--- a/file.cpp Tue Mar 19 21:52:38 2013 +0200 +++ b/file.cpp Wed Mar 20 01:58:05 2013 +0200 @@ -323,11 +323,8 @@ LDCondLine* obj = new LDCondLine; obj->dColor = getWordInt (zLine, 1); - for (short i = 0; i < 2; ++i) - obj->vaCoords[i] = parseVertex (zLine, 2 + (i * 3)); // 2 - 7 - - for (short i = 0; i < 2; ++i) - obj->vaControl[i] = parseVertex (zLine, 8 + (i * 3)); // 8 - 13 + for (short i = 0; i < 4; ++i) + obj->vaCoords[i] = parseVertex (zLine, 2 + (i * 3)); // 2 - 13 return obj; }
--- a/gui.cpp Tue Mar 19 21:52:38 2013 +0200 +++ b/gui.cpp Wed Mar 20 01:58:05 2013 +0200 @@ -26,6 +26,7 @@ #include "zz_setContentsDialog.h" #include "zz_configDialog.h" #include "zz_addObjectDialog.h" +#include "misc.h" #define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ @@ -274,44 +275,19 @@ } void ForgeWindow::slot_newLine () { - LDLine* line = new LDLine; - - memset (line->vaCoords, 0, sizeof line->vaCoords); - line->dColor = 24; - - g_CurrentFile->addObject (line); - refresh (); + AddObjectDialog::staticDialog (OBJ_Line, this); } void ForgeWindow::slot_newTriangle () { - LDTriangle* tri = new LDTriangle; - - memset (tri->vaCoords, 0, sizeof tri->vaCoords); - tri->dColor = 16; - - g_CurrentFile->addObject (tri); - refresh (); + AddObjectDialog::staticDialog (OBJ_Triangle, this); } void ForgeWindow::slot_newQuad () { - LDQuad* quad = new LDQuad; - - memset (quad->vaCoords, 0, sizeof quad->vaCoords); - quad->dColor = 16; - - g_CurrentFile->addObject (quad); - refresh (); + AddObjectDialog::staticDialog (OBJ_Quad, this); } void ForgeWindow::slot_newCondLine () { - LDCondLine* line = new LDCondLine; - - memset (line->vaCoords, 0, sizeof line->vaCoords); - memset (line->vaControl, 0, sizeof line->vaControl); - line->dColor = 24; - - g_CurrentFile->addObject (line); - refresh (); + AddObjectDialog::staticDialog (OBJ_CondLine, this); } void ForgeWindow::slot_newComment () { @@ -416,46 +392,6 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -static QIcon IconForObjectType (LDObject* obj) { - switch (obj->getType ()) { - case OBJ_Empty: - return QIcon ("icons/empty.png"); - - case OBJ_Line: - return QIcon ("icons/line.png"); - - case OBJ_Quad: - return QIcon ("icons/quad.png"); - - case OBJ_Subfile: - return QIcon ("icons/subfile.png"); - - case OBJ_Triangle: - return QIcon ("icons/triangle.png"); - - case OBJ_CondLine: - return QIcon ("icons/condline.png"); - - case OBJ_Comment: - return QIcon ("icons/comment.png"); - - case OBJ_Vector: - return QIcon ("icons/vector.png"); - - case OBJ_Vertex: - return QIcon ("icons/vertex.png"); - - case OBJ_Gibberish: - case OBJ_Unidentified: - return QIcon ("icons/error.png"); - } - - return QIcon (); -} - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= void ForgeWindow::buildObjList () { if (!g_CurrentFile) return; @@ -481,7 +417,6 @@ break; // leave it empty case OBJ_Line: - case OBJ_CondLine: { LDLine* line = static_cast<LDLine*> (obj); zText.format ("%s, %s", @@ -511,6 +446,17 @@ } break; + case OBJ_CondLine: + { + LDCondLine* line = static_cast<LDCondLine*> (obj); + zText.format ("%s, %s, %s, %s", + line->vaCoords[0].getStringRep (true).chars(), + line->vaCoords[1].getStringRep (true).chars(), + line->vaCoords[2].getStringRep (true).chars(), + line->vaCoords[3].getStringRep (true).chars()); + } + break; + case OBJ_Gibberish: zText.format ("ERROR: %s", static_cast<LDGibberish*> (obj)->zContents.chars()); @@ -524,6 +470,21 @@ zText.format ("%s", static_cast<LDVertex*> (obj)->vPosition.getStringRep(true).chars()); break; + case OBJ_Subfile: + { + LDSubfile* ref = static_cast<LDSubfile*> (obj); + + zText.format ("%s %s, (", + ref->zFileName.chars(), ref->vPosition.getStringRep (true).chars()); + + for (short i = 0; i < 9; ++i) + zText.appendformat ("%s%s", + ftoa (ref->faMatrix[i]).chars(), (i != 8) ? " " : ""); + + zText += ')'; + } + break; + default: zText = g_saObjTypeNames[obj->getType ()]; break; @@ -531,7 +492,7 @@ QTreeWidgetItem* item = new QTreeWidgetItem ((QTreeWidget*) (nullptr), QStringList (zText.chars()), 0); - item->setIcon (0, IconForObjectType (obj)); + item->setIcon (0, QIcon (g_saObjTypeIcons[obj->getType ()])); // Color gibberish red if (obj->getType() == OBJ_Gibberish) {
--- a/ldtypes.cpp Tue Mar 19 21:52:38 2013 +0200 +++ b/ldtypes.cpp Wed Mar 20 01:58:05 2013 +0200 @@ -166,14 +166,10 @@ str LDCondLine::getContents () { str val = str::mkfmt ("5 %d", dColor); - // Add the coordinates of end points - for (ushort i = 0; i < 2; ++i) + // Add the coordinates + for (ushort i = 0; i < 4; ++i) val.appendformat (" %s", vaCoords[i].getStringRep (false).chars ()); - // Add the control points - for (ushort i = 0; i < 2; ++i) - val.appendformat (" %s", vaControl[i].getStringRep (false).chars ()); - return val; }
--- a/ldtypes.h Tue Mar 19 21:52:38 2013 +0200 +++ b/ldtypes.h Wed Mar 20 01:58:05 2013 +0200 @@ -170,7 +170,8 @@ public: IMPLEMENT_LDTYPE (CondLine) - vertex vaControl[2]; // Control points + short dColor; // Color of this line + vertex vaCoords[4]; // End points + control points of this line }; // =============================================================================
--- a/zz_addObjectDialog.cpp Tue Mar 19 21:52:38 2013 +0200 +++ b/zz_addObjectDialog.cpp Wed Mar 20 01:58:05 2013 +0200 @@ -21,25 +21,73 @@ #include "zz_addObjectDialog.h" #include "file.h" +#define APPLY_COORDS(OBJ, N) \ + for (short i = 0; i < N; ++i) { \ + OBJ->vaCoords[i].x = dlg.qaCoordinates[(i * 3) + 0]->value (); \ + OBJ->vaCoords[i].y = dlg.qaCoordinates[(i * 3) + 1]->value (); \ + OBJ->vaCoords[i].z = dlg.qaCoordinates[(i * 3) + 2]->value (); \ + } + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= AddObjectDialog::AddObjectDialog (const LDObjectType_e type, QWidget* parent) : QDialog (parent) { + short dCoordCount = 0; + qTypeIcon = new QLabel; qTypeIcon->setPixmap (QPixmap (g_saObjTypeIcons[type])); - qCommentLine = new QLineEdit; + switch (type) { + case OBJ_Comment: + qCommentLine = new QLineEdit; + break; + case OBJ_Line: + dCoordCount = 6; + break; + case OBJ_Triangle: + dCoordCount = 9; + break; + case OBJ_Quad: + case OBJ_CondLine: + dCoordCount = 12; + break; + default: + break; + } + + for (short i = 0; i < dCoordCount; ++i) { + qaCoordinates[i] = new QDoubleSpinBox; + qaCoordinates[i]->setMaximumWidth (96); + qaCoordinates[i]->setMinimum (-fMaxCoord); + qaCoordinates[i]->setMaximum (fMaxCoord); + } IMPLEMENT_DIALOG_BUTTONS - QGridLayout* layout = new QGridLayout; - layout->addWidget (qTypeIcon, 0, 0); - layout->addWidget (qCommentLine, 0, 1); - layout->addWidget (qButtons, 1, 1); + QGridLayout* const qLayout = new QGridLayout; + qLayout->addWidget (qTypeIcon, 0, 0); + + switch (type) { + case OBJ_Comment: + qLayout->addWidget (qCommentLine, 0, 1); + break; + default: + break; + } - setLayout (layout); + if (dCoordCount > 0) { + QGridLayout* const qCoordLayout = new QGridLayout; + + for (short i = 0; i < dCoordCount; ++i) + qCoordLayout->addWidget (qaCoordinates[i], (i / 3), (i % 3)); + + qLayout->addLayout (qCoordLayout, 0, 1); + } + + qLayout->addWidget (qButtons, 1, 1); + setLayout (qLayout); setWindowTitle (str::mkfmt (APPNAME_DISPLAY " - new %s", g_saObjTypeNames[type]).chars()); @@ -60,8 +108,56 @@ comm->zText = dlg.qCommentLine->text (); g_CurrentFile->addObject (comm); window->refresh (); - break; + } + break; + + case OBJ_Line: + { + LDLine* line = new LDLine; + line->dColor = dEdgeColor; + + APPLY_COORDS (line, 2) + + g_CurrentFile->addObject (line); + window->refresh (); + } + break; + + case OBJ_Triangle: + { + LDTriangle* tri = new LDTriangle; + tri->dColor = dMainColor; + + APPLY_COORDS (tri, 3) + + g_CurrentFile->addObject (tri); + window->refresh (); } + break; + + case OBJ_Quad: + { + LDQuad* quad = new LDQuad; + quad->dColor = dMainColor; + + APPLY_COORDS (quad, 4) + + g_CurrentFile->addObject (quad); + window->refresh (); + } + break; + + case OBJ_CondLine: + { + LDCondLine* line = new LDCondLine; + line->dColor = dEdgeColor; + + APPLY_COORDS (line, 4) + + g_CurrentFile->addObject (line); + window->refresh (); + } + default: break; }
--- a/zz_addObjectDialog.h Tue Mar 19 21:52:38 2013 +0200 +++ b/zz_addObjectDialog.h Wed Mar 20 01:58:05 2013 +0200 @@ -24,6 +24,7 @@ #include <qlineedit.h> #include <qdialogbuttonbox.h> #include <qlabel.h> +#include <qspinbox.h> class AddObjectDialog : public QDialog { public: @@ -35,6 +36,9 @@ // -- COMMENT -- QLineEdit* qCommentLine; + // Coordinate edits for.. anything with coordinates, really. + QDoubleSpinBox* qaCoordinates[12]; + QDialogButtonBox* qButtons; };