Mon, 15 Apr 2013 18:07:29 +0300
Added select by type. Selection is now preserved over operations.
bbox.cpp | file | annotate | diff | comparison | revisions | |
gldraw.cpp | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
gui_actions.cpp | file | annotate | diff | comparison | revisions | |
gui_editactions.cpp | file | annotate | diff | comparison | revisions |
--- a/bbox.cpp Mon Apr 15 04:58:33 2013 +0300 +++ b/bbox.cpp Mon Apr 15 18:07:29 2013 +0300 @@ -130,8 +130,8 @@ } else if (fYScale > fZScale) fSize = fYScale; - printf ("fsize: %f\n", fSize); if (abs (fSize) >= 2.0f) return abs (fSize / 2); + return 1.0f; }
--- a/gldraw.cpp Mon Apr 15 04:58:33 2013 +0300 +++ b/gldraw.cpp Mon Apr 15 18:07:29 2013 +0300 @@ -526,7 +526,6 @@ } g_ForgeWindow->buildObjList (); - g_ForgeWindow->updateSelection (); bPicking = false; glEnable (GL_DITHER);
--- a/gui.cpp Mon Apr 15 04:58:33 2013 +0300 +++ b/gui.cpp Mon Apr 15 18:07:29 2013 +0300 @@ -302,6 +302,8 @@ ADD_TOOLBAR_ITEM (moveZPos) ADD_TOOLBAR_ITEM (moveZNeg) + addToolBarBreak (Qt::TopToolBarArea); + initSingleToolBar ("Select"); ADD_TOOLBAR_ITEM (selectByColor) ADD_TOOLBAR_ITEM (selectByType) @@ -430,10 +432,13 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // ========================================================================= // void ForgeWindow::deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects) { - bool const bSelectionEmpty = (paSelection.size() == 0); + if (selection ().size () == 0) + return; + + std::vector<LDObject*> sel = selection (); // Delete the objects that were being selected - for (LDObject* obj : paSelection) { + for (LDObject* obj : sel) { if (papObjects && ulapIndices) { papObjects->push_back (obj->clone ()); ulapIndices->push_back (obj->getIndex (g_CurrentFile)); @@ -443,8 +448,7 @@ delete obj; } - if (bSelectionEmpty == false) - refresh (); + refresh (); } // ========================================================================= // @@ -454,6 +458,11 @@ if (!g_CurrentFile) return; + // Lock the selection while we do this so that refreshing the object list + // doesn't trigger selection updating so that the selection doesn't get lost + // while this is done + g_bSelectionLocked = true; + QList<QTreeWidgetItem*> qaItems; qObjList->clear (); @@ -576,6 +585,9 @@ } qObjList->insertTopLevelItems (0, qaItems); + + g_bSelectionLocked = false; + updateSelection (); } // ========================================================================= // @@ -678,6 +690,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // ========================================================================= // void ForgeWindow::refresh () { + printf ("refreshing.. (%lu)\n", paSelection.size ()); buildObjList (); R->hardRefresh (); } @@ -713,6 +726,8 @@ for (LDObject* obj : paSelection) obj->qObjListEntry->setSelected (true); + printf ("updateSelection: %lu objects selected\n", paSelection.size ()); + g_bSelectionLocked = false; slot_selectionChanged (); } @@ -739,12 +754,8 @@ if (obj->dColor == -1) continue; // doesn't use color - if (dResult != -1 && obj->dColor != dResult) { - // No consensus in object color, therefore we don't have a - // proper default value to use. - dResult = -1; - break; - } + if (dResult != -1 && obj->dColor != dResult) + return -1; // No consensus in object color if (dResult == -1) dResult = obj->dColor; @@ -756,6 +767,23 @@ // ========================================================================= // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // ========================================================================= // +LDObjectType_e ForgeWindow::getSelectedType () { + LDObjectType_e eResult = OBJ_Unidentified; + + for (LDObject* obj : paSelection) { + if (eResult != OBJ_Unidentified && obj->dColor != eResult) + return OBJ_Unidentified; + + if (eResult == OBJ_Unidentified) + eResult = obj->getType (); + } + + return eResult; +} + +// ========================================================================= // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// ========================================================================= // std::vector<LDObject*>& ForgeWindow::selection () { return paSelection; }
--- a/gui.h Mon Apr 15 04:58:33 2013 +0300 +++ b/gui.h Mon Apr 15 18:07:29 2013 +0300 @@ -140,7 +140,8 @@ void updateRecentFilesMenu (); void updateSelection (); bool isSelected (LDObject* obj); - short int getSelectedColor(); + short getSelectedColor(); + LDObjectType_e getSelectedType (); private: void createMenuActions ();
--- a/gui_actions.cpp Mon Apr 15 04:58:33 2013 +0300 +++ b/gui_actions.cpp Mon Apr 15 18:07:29 2013 +0300 @@ -144,12 +144,10 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ACTION (selectByColor, "Select by Color", "select-color", - "Select all objects by the given color.", (0)) + "Select all objects by the given color.", CTRL_SHIFT (A)) { short dColor = g_ForgeWindow->getSelectedColor (); - printf ("color: %d\n", dColor); - if (dColor == -1) return; // no consensus on color @@ -164,7 +162,38 @@ ACTION (selectByType, "Select by Type", "select-type", "Select all objects by the given type.", (0)) { + if (g_ForgeWindow->selection ().size () == 0) + return; + LDObjectType_e eType = g_ForgeWindow->getSelectedType (); + + if (eType == OBJ_Unidentified) + return; + + // If we're selecting subfile references, the reference filename must also + // be uniform. + str zRefName; + + if (eType == OBJ_Subfile) { + zRefName = static_cast<LDSubfile*> (g_ForgeWindow->selection ()[0])->zFileName; + + for (LDObject* pObj : g_ForgeWindow->selection ()) + if (static_cast<LDSubfile*> (pObj)->zFileName != zRefName) + return; + } + + g_ForgeWindow->paSelection.clear (); + for (LDObject* obj : g_CurrentFile->objects) { + if (obj->getType() != eType) + continue; + + if (eType == OBJ_Subfile && static_cast<LDSubfile*> (obj)->zFileName != zRefName) + continue; + + g_ForgeWindow->paSelection.push_back (obj); + } + + g_ForgeWindow->updateSelection (); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
--- a/gui_editactions.cpp Mon Apr 15 04:58:33 2013 +0300 +++ b/gui_editactions.cpp Mon Apr 15 18:07:29 2013 +0300 @@ -79,11 +79,13 @@ vector<ulong> ulaIndices; vector<LDObject*> paCopies; + ulong idx = g_ForgeWindow->getInsertionPoint (); + for (LDObject* obj : g_Clipboard) { - ulong idx = g_CurrentFile->addObject (obj->clone ()); - ulaIndices.push_back (idx); paCopies.push_back (obj->clone ()); + + g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx++, obj->clone ()); } History::addEntry (new AddHistory (ulaIndices, paCopies, AddHistory::Paste));