Mon, 08 Apr 2013 18:47:31 +0300
Added a New Part dialog
gui.cpp | file | annotate | diff | comparison | revisions | |
icons/bfc.png | file | annotate | diff | comparison | revisions | |
icons/brick-new.png | file | annotate | diff | comparison | revisions | |
icons/brick.png | file | annotate | diff | comparison | revisions | |
ldforge.pro | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.h | file | annotate | diff | comparison | revisions | |
zz_configDialog.h | file | annotate | diff | comparison | revisions | |
zz_newPartDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_newPartDialog.h | file | annotate | diff | comparison | revisions |
--- a/gui.cpp Mon Apr 08 14:57:25 2013 +0300 +++ b/gui.cpp Mon Apr 08 18:47:31 2013 +0300 @@ -23,12 +23,13 @@ #include "gui.h" #include "file.h" #include "config.h" -#include "zz_setContentsDialog.h" -#include "zz_configDialog.h" +#include "misc.h" +#include "colors.h" #include "zz_addObjectDialog.h" -#include "misc.h" #include "zz_colorSelectDialog.h" -#include "colors.h" +#include "zz_configDialog.h" +#include "zz_newPartDialog.h" +#include "zz_setContentsDialog.h" #define MAKE_ACTION(OBJECT, DISPLAYNAME, IMAGENAME, DESCR) \ qAct_##OBJECT = new QAction (QIcon ("./icons/" IMAGENAME ".png"), tr (DISPLAYNAME), this); \ @@ -86,7 +87,7 @@ *sNewQuadText = "New Quadrilateral", *sAboutText = "About " APPNAME_DISPLAY; - MAKE_ACTION (new, "&New", "file-new", "Create a new part model.") + MAKE_ACTION (new, "&New", "brick", "Create a new part model.") MAKE_ACTION (open, "&Open", "file-open", "Load a part model from a file.") MAKE_ACTION (save, "&Save", "file-save", "Save the part model.") MAKE_ACTION (saveAs, "Save &As", "file-save-as", "Save the part to a specific file.") @@ -247,7 +248,8 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::slot_new () { - newFile (); + // newFile (); + NewPartDialog::StaticDialog (); } void ForgeWindow::slot_open () { @@ -333,16 +335,18 @@ if (objs.size() == 0) return false; - // Clear the clipboard. However, its contents are dynamically allocated - // clones of LDObjects (cannot use pointers to real objects because the - // cut operation deletes them!), so we have to delete said objects first. + // Clear the clipboard first. for (LDObject* obj : g_Clipboard) delete obj; g_Clipboard.clear (); - for (std::size_t i = 0; i < objs.size(); ++i) - g_Clipboard.push_back (objs[i]->makeClone ()); + // Now, copy the contents into the clipboard. The objects should be + // separate objects so that modifying the existing ones does not affect + // the clipboard. Thus, we add clones of the objects to the clipboard, not + // the objects themselves. + for (ulong i = 0; i < objs.size(); ++i) + g_Clipboard.push_back (objs[i]->clone ()); return true; } @@ -373,7 +377,7 @@ // ============================================================================= void ForgeWindow::slot_paste () { for (LDObject* obj : g_Clipboard) - g_CurrentFile->addObject (obj->makeClone ()); + g_CurrentFile->addObject (obj->clone ()); refresh (); }
--- a/ldforge.pro Mon Apr 08 14:57:25 2013 +0300 +++ b/ldforge.pro Mon Apr 08 18:47:31 2013 +0300 @@ -21,10 +21,11 @@ config.h \ colors.h \ types.h \ - zz_setContentsDialog.h \ - zz_configDialog.h \ zz_addObjectDialog.h \ zz_colorSelectDialog.h \ + zz_configDialog.h \ + zz_newPartDialog.h \ + zz_setContentsDialog.h SOURCES += bbox.cpp \ config.cpp \ @@ -37,10 +38,11 @@ misc.cpp \ str.cpp \ types.cpp \ - zz_setContentsDialog.cpp \ + zz_addObjectDialog.cpp \ + zz_colorSelectDialog.cpp \ zz_configDialog.cpp \ - zz_addObjectDialog.cpp \ - zz_colorSelectDialog.cpp + zz_newPartDialog.cpp \ + zz_setContentsDialog.cpp QMAKE_CXXFLAGS += -std=c++0x QT += opengl
--- a/ldtypes.cpp Mon Apr 08 14:57:25 2013 +0300 +++ b/ldtypes.cpp Mon Apr 08 18:47:31 2013 +0300 @@ -276,15 +276,19 @@ case OBJ_Line: transformSubObject<LDLine> (obj, mMatrix, vPos, dColor); break; + case OBJ_CondLine: transformSubObject<LDCondLine> (obj, mMatrix, vPos, dColor); break; + case OBJ_Triangle: transformSubObject<LDTriangle> (obj, mMatrix, vPos, dColor); break; + case OBJ_Quad: transformSubObject<LDQuad> (obj, mMatrix, vPos, dColor); break; + case OBJ_Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); @@ -295,6 +299,7 @@ } break; + default: break; } @@ -309,7 +314,7 @@ // If we have this cached, just clone that if (bDeepInline && pFile->objCache.size ()) { for (LDObject* obj : pFile->objCache) - objs.push_back (obj->makeClone ()); + objs.push_back (obj->clone ()); } else { if (!bDeepInline) bCache = false; @@ -343,18 +348,17 @@ vector<LDObject*> otherobjs = ref->inlineContents (true, false); for (LDObject* otherobj : otherobjs) { - // Cache this object if desired + // Cache this object, if desired if (bCache) - cache.push_back (otherobj->makeClone ()); + cache.push_back (otherobj->clone ()); objs.push_back (otherobj); } } else { - // Cache it, if desired if (bCache) - cache.push_back (obj->makeClone ()); + cache.push_back (obj->clone ()); - objs.push_back (obj->makeClone ()); + objs.push_back (obj->clone ()); } }
--- a/ldtypes.h Mon Apr 08 14:57:25 2013 +0300 +++ b/ldtypes.h Mon Apr 08 18:47:31 2013 +0300 @@ -29,7 +29,7 @@ return OBJ_##N; \ } \ virtual str getContents (); \ - virtual LD##N* makeClone () { \ + virtual LD##N* clone () { \ return new LD##N (*this); \ } @@ -84,7 +84,8 @@ return ""; } - virtual LDObject* makeClone () { + // Creates a new LDObject identical to this one and returns a pointer to it. + virtual LDObject* clone () { return new LDObject (*this); } @@ -137,6 +138,7 @@ class LDComment : public LDObject { public: IMPLEMENT_LDTYPE (Comment) + LDComment (str zText) : zText (zText) {} str zText; // The text of this comment };
--- a/zz_configDialog.h Mon Apr 08 14:57:25 2013 +0300 +++ b/zz_configDialog.h Mon Apr 08 18:47:31 2013 +0300 @@ -24,8 +24,6 @@ #include <qpushbutton.h> #include <qcheckbox.h> -class intconfig; - class ConfigDialog : public QDialog { Q_OBJECT
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zz_newPartDialog.cpp Mon Apr 08 18:47:31 2013 +0300 @@ -0,0 +1,124 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <qgridlayout.h> +#include "zz_newPartDialog.h" +#include "file.h" + +// ------------------------------------- +enum { + LICENSE_CCAL, + LICENSE_NonCA, + LICENSE_None +}; + +// ------------------------------------- +enum { + BFCBOX_CCW, + BFCBOX_CW, + BFCBOX_None, +}; + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +NewPartDialog::NewPartDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { + qLB_Icon = new QLabel; + qLB_Icon->setPixmap (QPixmap ("icons/brick.png")); + + qLB_NameLabel = new QLabel ("Name:"); + qLE_Name = new QLineEdit; + qLE_Name->setMinimumWidth (320); + + qLB_AuthorLabel = new QLabel ("Author:"); + qLE_Author = new QLineEdit; + + qLB_LicenseLabel = new QLabel ("License:"); + qCB_LicenseBox = new QComboBox; + qCB_LicenseBox->addItems ({ + "CCAL Redistributable", + "Non-redistributable", + "[none]", + }); + + qLB_BFCLabel = new QLabel ("BFC:"); + qCB_BFCBox = new QComboBox; + qCB_BFCBox->addItems ({ + "CCW", + "CW", + "No winding" + }); + + IMPLEMENT_DIALOG_BUTTONS + + QGridLayout* layout = new QGridLayout; + layout->addWidget (qLB_Icon, 0, 0); + layout->addWidget (qLB_NameLabel, 0, 1); + layout->addWidget (qLE_Name, 0, 2); + layout->addWidget (qLB_AuthorLabel, 1, 1); + layout->addWidget (qLE_Author, 1, 2); + layout->addWidget (qLB_LicenseLabel, 2, 1); + layout->addWidget (qCB_LicenseBox, 2, 2); + layout->addWidget (qLB_BFCLabel, 3, 1); + layout->addWidget (qCB_BFCBox, 3, 2); + layout->addWidget (qButtons, 4, 2); + + setLayout (layout); + setWindowIcon (QIcon ("icons/brick.png")); + setWindowTitle (APPNAME_DISPLAY " - new part"); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void NewPartDialog::StaticDialog () { + NewPartDialog dlg (g_qWindow); + if (dlg.exec ()) { + newFile (); + + short idx; + str zAuthor = dlg.qLE_Author->text (); + vector<LDObject*>& objs = g_CurrentFile->objects; + + idx = dlg.qCB_BFCBox->currentIndex (); + const LDBFCType_e eBFCType = + (idx == BFCBOX_CCW) ? BFC_CertifyCCW : + (idx == BFCBOX_CW) ? BFC_CertifyCW : + BFC_NoCertify; + + idx = dlg.qCB_LicenseBox->currentIndex (); + const char* sLicense = + (idx == LICENSE_CCAL) ? "Redistributable under CCAL version 2.0 : see CAreadme.txt" : + (idx == LICENSE_NonCA) ? "Not redistributable : see NonCAreadme.txt" : + nullptr; + + objs.push_back (new LDComment (dlg.qLE_Name->text ())); + objs.push_back (new LDComment ("Name: <untitled>.dat")); + objs.push_back (new LDComment (str::mkfmt ("Author: %s", zAuthor.chars()))); + objs.push_back (new LDComment (str::mkfmt ("!LDRAW_ORG Unofficial_Part"))); + + if (sLicense != nullptr) + objs.push_back (new LDComment (str::mkfmt ("!LICENSE %s", sLicense))); + + objs.push_back (new LDEmpty); + objs.push_back (new LDBFC (eBFCType)); + objs.push_back (new LDEmpty); + + g_qWindow->refresh (); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zz_newPartDialog.h Mon Apr 08 18:47:31 2013 +0300 @@ -0,0 +1,35 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri `arezey` Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui.h" +#include <qdialog.h> +#include <qlabel.h> +#include <qlineedit.h> +#include <qcombobox.h> +#include <qdialogbuttonbox.h> + +class NewPartDialog : public QDialog { +public: + explicit NewPartDialog (QWidget* parent = nullptr, Qt::WindowFlags f = 0); + static void StaticDialog (); + + QLabel* qLB_Icon, *qLB_NameLabel, *qLB_AuthorLabel, *qLB_LicenseLabel, *qLB_BFCLabel; + QLineEdit* qLE_Name, *qLE_Author; + QComboBox* qCB_LicenseBox, *qCB_BFCBox; + QDialogButtonBox* qButtons; +}; \ No newline at end of file