Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Add SelectionUtils namespace and refactor level selection in vectorizerpopup

Abel You91e028c72e40
diff --git a/toonz/sources/toonz/selectionutils.cpp b/toonz/sources/toonz/selectionutils.cpp
index 7be8f3059..3a44f7e45 100644
--- a/toonz/sources/toonz/selectionutils.cpp
+++ b/toonz/sources/toonz/selectionutils.cpp
@@ -27,6 +27,55 @@
#include <boost/range/counting_range.hpp>
#include <boost/range/adaptor/transformed.hpp>
+namespace SelectionUtils{
+ bool getSelectedLevels(std::set<TXshLevel*>& levels, int& r0, int& c0, int& r1,
+ int& c1) {
+ TXsheet* xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
+
+ CastSelection* castSelection =
+ dynamic_cast<CastSelection*>(TSelection::getCurrent());
+ TCellSelection* cellSelection =
+ dynamic_cast<TCellSelection*>(TSelection::getCurrent());
+ TColumnSelection* columnSelection =
+ dynamic_cast<TColumnSelection*>(TSelection::getCurrent());
+
+ if (castSelection) {
+ std::vector<TXshLevel*> selectedLevels;
+ castSelection->getSelectedLevels(selectedLevels);
+
+ for (int i = 0; i < (int)selectedLevels.size(); ++i)
+ levels.insert(selectedLevels[i]);
+
+ return false;
+ }
+ else if (columnSelection) {
+ TColumnSelection::getLevelSetFromColumnIndices(columnSelection->getIndices(), levels);
+ return false;
+ }
+ else if (cellSelection) {
+ cellSelection->getSelectedCells(r0, c0, r1, c1);
+
+ for (int c = c0; c <= c1; ++c) {
+ for (int r = r0; r <= r1; ++r) {
+ TXshCell cell = xsheet->getCell(r, c);
+
+ if (TXshLevel* level = cell.isEmpty() ? 0 : cell.getSimpleLevel())
+ levels.insert(level);
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+ bool getSelectedLevels(std::set<TXshLevel*>& levels) {
+ int r0, c0, r1, c1;
+ getSelectedLevels(levels, r0, c0, r1, c1);
+ }
+}
+
+
//*********************************************************************************
// Local namespace
//*********************************************************************************
diff --git a/toonz/sources/toonz/selectionutils.h b/toonz/sources/toonz/selectionutils.h
index 44f331dc3..ed49b9d22 100644
--- a/toonz/sources/toonz/selectionutils.h
+++ b/toonz/sources/toonz/selectionutils.h
@@ -10,6 +10,12 @@
#include <set>
#include <map>
+namespace SelectionUtils {
+ bool getSelectedLevels(std::set<TXshLevel*>& levels, int& r0, int& c0, int& r1,
+ int& c1);
+ bool getSelectedLevels(std::set<TXshLevel*>& levels);
+}
+
//==============================================================
// Forward declarations
diff --git a/toonz/sources/toonz/vectorizerpopup.cpp b/toonz/sources/toonz/vectorizerpopup.cpp
index d81130e52..0fda8fa58 100644
--- a/toonz/sources/toonz/vectorizerpopup.cpp
+++ b/toonz/sources/toonz/vectorizerpopup.cpp
@@ -12,6 +12,7 @@
#include "vectorizerswatch.h"
#include "filebrowserpopup.h"
#include "menubarcommandids.h"
+#include "selectionutils.h"
// TnzQt includes
#include "toonzqt/menubarcommand.h"
@@ -66,6 +67,7 @@
#include <QToolButton>
using namespace DVGui;
+using namespace SelectionUtils;
//********************************************************************************
// Local namespace classes
@@ -113,50 +115,6 @@ VectorizerParameters *getCurrentVectorizerParameters() {
//-----------------------------------------------------------------------------
-bool getSelectedLevels(std::set<TXshLevel *> &levels, int &r0, int &c0, int &r1,
- int &c1) {
- TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
-
- CastSelection *castSelection =
- dynamic_cast<CastSelection *>(TSelection::getCurrent());
- TCellSelection *cellSelection =
- dynamic_cast<TCellSelection *>(TSelection::getCurrent());
- TColumnSelection* columnSelection =
- dynamic_cast<TColumnSelection*>(TSelection::getCurrent());
-
- if (castSelection) {
- std::vector<TXshLevel *> selectedLevels;
- castSelection->getSelectedLevels(selectedLevels);
-
- for (int i = 0; i < (int)selectedLevels.size(); ++i)
- levels.insert(selectedLevels[i]);
-
- return false;
- }
- else if (columnSelection) {
- TColumnSelection::getLevelSetFromColumnIndices(columnSelection->getIndices(), levels);
- return false;
- }
- else if (cellSelection) {
- cellSelection->getSelectedCells(r0, c0, r1, c1);
-
- for (int c = c0; c <= c1; ++c) {
- for (int r = r0; r <= r1; ++r) {
- TXshCell cell = xsheet->getCell(r, c);
-
- if (TXshLevel *level = cell.isEmpty() ? 0 : cell.getSimpleLevel())
- levels.insert(level);
- }
- }
-
- return true;
- }
-
- return false;
-}
-
-//-----------------------------------------------------------------------------
-
TXshLevel *getSelectedLevel() {
std::set<TXshLevel *> levels;
int r0, c0, r1, c1;