Skip to content

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

C

Refactor conversion process and support Raster->ToonzRaster

Abel You4e90dc99c1a3
diff --git a/toonz/sources/toonz/cellselection.cpp b/toonz/sources/toonz/cellselection.cpp
index 1e480a1f5..c88515cc5 100644
--- a/toonz/sources/toonz/cellselection.cpp
+++ b/toonz/sources/toonz/cellselection.cpp
@@ -1638,7 +1638,6 @@ bool TCellSelection::isEnabledCommand(
MI_Redo,
MI_PasteNumbers,
MI_PasteCellContent,
- MI_ConvertToToonzRaster,
MI_ConvertVectorToVector,
MI_CreateBlankDrawing,
MI_FillEmptyCell};
diff --git a/toonz/sources/toonz/convertpopup.cpp b/toonz/sources/toonz/convertpopup.cpp
index 4b4ba73a8..bd436b283 100644
--- a/toonz/sources/toonz/convertpopup.cpp
+++ b/toonz/sources/toonz/convertpopup.cpp
@@ -233,6 +233,7 @@ void ConvertPopup::Converter::convertLevel(
}
popup->m_notifier->notifyLevelCompleted(dstFileFullPath);
+ popup->m_convertedFileMap[sourceFileFullPath] = dstFileFullPath;
}
// to use legacy code
@@ -833,7 +834,8 @@ void ConvertPopup::setFiles(const std::vector<TFilePath> &fps) {
m_imageDpi = 0.0;
if (m_srcFilePaths.size() == 1) {
- setWindowTitle(tr("Convert 1 Level"));
+ setWindowTitle(tr("Convert 1 Level : %1")
+ .arg(QString::fromStdString(fps[0].getName())));
m_fileNameFld->setEnabled(true);
m_fromFld->setEnabled(false);
@@ -886,6 +888,7 @@ void ConvertPopup::setFiles(const std::vector<TFilePath> &fps) {
}
void ConvertPopup::setFormat(QString format){
+ m_fileFormat->setDisabled(true);
m_fileFormat->setCurrentIndex(m_fileFormat->findText(format));
}
@@ -1263,6 +1266,7 @@ QString::number(m_srcFilePaths.size()-skipped)).arg(QString::number(m_srcFilePat
void ConvertPopup::onLevelConverted(const TFilePath &fullPath) {
IconGenerator::instance()->invalidate(fullPath);
+
}
//-------------------------------------------------------------------
diff --git a/toonz/sources/toonz/convertpopup.h b/toonz/sources/toonz/convertpopup.h
index c94ebf83b..8f244734d 100644
--- a/toonz/sources/toonz/convertpopup.h
+++ b/toonz/sources/toonz/convertpopup.h
@@ -54,7 +54,7 @@ class FrameTaskNotifier;
*/
class ConvertPopup : public DVGui::Dialog {
- Q_OBJECT
+ Q_OBJECT
public:
ConvertPopup(bool specifyInput = false);
@@ -65,7 +65,8 @@ public:
bool isConverting() const { return m_isConverting; }
void convertToTlv(bool toPainted);
-
+ TFilePath getConvetedPath(TFilePath path)
+ {return m_convertedFileMap[path];};
QString getDestinationType() const;
QString getTlvMode() const;
QString TlvMode_Unpainted;
@@ -128,6 +129,7 @@ private:
DVGui::ProgressDialog *m_progressDialog;
std::vector<TFilePath> m_srcFilePaths;
+ std::map<TFilePath, TFilePath> m_convertedFileMap;
static QMap<std::string, TPropertyGroup *> m_formatProperties;
bool m_isConverting;
diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp
index 4b1f94fdf..599d564eb 100644
--- a/toonz/sources/toonz/mainwindow.cpp
+++ b/toonz/sources/toonz/mainwindow.cpp
@@ -1946,7 +1946,7 @@ void MainWindow::defineActions() {
createMenuLevelAction(MI_ConvertToVectors,
QT_TR_NOOP("Convert to Vectors..."), "", "convert");
createMenuLevelAction(MI_ConvertToToonzRaster,
- QT_TR_NOOP("Vectors to Toonz Raster"), "");
+ QT_TR_NOOP("Convert to Toonz Raster..."), "");
createMenuLevelAction(
MI_ConvertVectorToVector,
QT_TRANSLATE_NOOP("MainWindow",
diff --git a/toonz/sources/toonz/rasterizecommand.cpp b/toonz/sources/toonz/rasterizecommand.cpp
index 64008d0c7..21b93ce2d 100644
--- a/toonz/sources/toonz/rasterizecommand.cpp
+++ b/toonz/sources/toonz/rasterizecommand.cpp
@@ -41,6 +41,8 @@
// TnzCore includes
#include "filebrowsermodel.h"
+#include <QCoreApplication>
+
using namespace DVGui;
using namespace SelectionUtils;
@@ -201,14 +203,25 @@ namespace {
bool convertRaster(TXshSimpleLevel* in, TXshSimpleLevel* out,
std::set<TFrameId>& frameIdsSet)
{
- return false;
ConvertPopup popup(false);
- TFilePath path = TApp::instance()->getCurrentScene()->getScene()->decodeFilePath(in->getPath());
+ TFilePath path =
+ TApp::instance()->getCurrentScene()->getScene()->decodeFilePath(in->getPath());
if (!TSystem::doesExistFileOrLevel(path))return false;
in->save();
popup.setFiles({path});
popup.setFormat("tlv");
popup.show();
+ popup.adjustSize();
+ while (popup.isVisible() || popup.isConverting())
+ QCoreApplication::processEvents(QEventLoop::AllEvents |
+ QEventLoop::WaitForMoreEvents);
+ path = popup.getConvetedPath(path);
+ if (path.isEmpty()) return false;
+ out->setPath(path);
+ out->load();
+ std::vector<TFrameId> fids = out->getFids();
+ frameIdsSet = std::set<TFrameId>(fids.begin(), fids.end());
+ return true;
}