Jeremy Bullock f15907
#include "stopmotion.h"
Jeremy Bullock f15907
Jeremy Bullock f15907
// TnzCore includes
Jeremy Bullock f15907
#include "menubarcommandids.h"
Jeremy Bullock f15907
#include "tapp.h"
Jeremy Bullock f15907
#include "tenv.h"
Jeremy Bullock f15907
#include "tsystem.h"
Jeremy Bullock f15907
#include "filebrowsermodel.h"
Jeremy Bullock f15907
#include "penciltestpopup.h"
Jeremy Bullock f15907
#include "tlevel_io.h"
Jeremy Bullock f15907
#include "toutputproperties.h"
shun-iwasawa 31accf
#include "filebrowserpopup.h"
shun-iwasawa 31accf
#include "tunit.h"
Jeremy Bullock f15907
Jeremy Bullock f15907
#include "toonz/namebuilder.h"
Jeremy Bullock f15907
#include "toonz/preferences.h"
Jeremy Bullock f15907
#include "toonz/tcamera.h"
Jeremy Bullock f15907
#include "toonz/tcolumnhandle.h"
Jeremy Bullock f15907
#include "toonz/tframehandle.h"
Jeremy Bullock f15907
#include "toonz/levelset.h"
Jeremy Bullock f15907
#include "toonz/sceneproperties.h"
Jeremy Bullock f15907
#include "toonz/toonzscene.h"
Jeremy Bullock f15907
#include "toonz/tscenehandle.h"
Jeremy Bullock f15907
#include "toonz/stage.h"
Jeremy Bullock f15907
#include "toonz/txsheethandle.h"
Jeremy Bullock f15907
#include "toonz/txshlevelhandle.h"
Jeremy Bullock f15907
#include "toonz/levelproperties.h"
Jeremy Bullock f15907
#include "toonz/tstageobjecttree.h"
Jeremy Bullock f15907
#include "toonzqt/menubarcommand.h"
Jeremy Bullock f15907
Jeremy Bullock f15907
#include <qapplication></qapplication>
Jeremy Bullock f15907
#include <qcamera></qcamera>
Jeremy Bullock f15907
#include <qcamerainfo></qcamerainfo>
Jeremy Bullock f15907
#include <qcoreapplication></qcoreapplication>
Jeremy Bullock f15907
#include <qdesktopwidget></qdesktopwidget>
Jeremy Bullock f15907
#include <qdialog></qdialog>
Jeremy Bullock f15907
#include <qfile></qfile>
Jeremy Bullock f15907
#include <qstring></qstring>
Jeremy Bullock f15907
#include <qtimer></qtimer>
shun-iwasawa 31accf
#include <qxmlstreamwriter></qxmlstreamwriter>
shun-iwasawa 31accf
#include <qxmlstreamreader></qxmlstreamreader>
Jeremy Bullock f15907
Jeremy Bullock f15907
// Connected camera
Jeremy Bullock f15907
TEnv::IntVar StopMotionOpacity("StopMotionOpacity", 100);
Jeremy Bullock f15907
TEnv::IntVar StopMotionAlwaysLiveView("StopMotionAlwaysLiveView", 0);
Jeremy Bullock f15907
TEnv::IntVar StopMotionPlaceOnXSheet("StopMotionPlaceOnXSheet", 1);
justburner d63640
TEnv::IntVar StopMotionReviewDSec("StopMotionReviewDSec", 10);
justburner d63640
TEnv::IntVar StopMotionIntervalDSec("StopMotionIntervalDSec", 100);
Jeremy Bullock f15907
TEnv::IntVar StopMotionUseNumpad("StopMotionUseNumpad", 0);
shun-iwasawa 31accf
TEnv::IntVar StopMotionDrawBeneathLevels("StopMotionDrawBeneathLevels", 1);
justburner d63640
TEnv::IntVar StopMotionPlayCaptureSound("StopMotionPlayCaptureSound", 0);
Jeremy Bullock f15907
Jeremy Bullock f15907
// Connected camera
Jeremy Bullock f15907
TEnv::StringVar StopMotionCameraName("CamCapCameraName", "");
Jeremy Bullock f15907
// Camera resolution
Jeremy Bullock f15907
TEnv::StringVar StopMotionCameraResolution("CamCapCameraResolution", "");
Jeremy Bullock f15907
Jeremy Bullock f15907
namespace {
Jeremy Bullock f15907
Jeremy Bullock f15907
TPointD getCurrentCameraDpi() {
Jeremy Bullock f15907
  TCamera *camera =
Jeremy Bullock f15907
      TApp::instance()->getCurrentScene()->getScene()->getCurrentCamera();
Jeremy Bullock f15907
  TDimensionD size = camera->getSize();
Jeremy Bullock f15907
  TDimension res   = camera->getRes();
Jeremy Bullock f15907
  return TPointD(res.lx / size.lx, res.ly / size.ly);
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
bool findCell(TXsheet *xsh, int col, const TXshCell &targetCell,
Jeremy Bullock f15907
              int &bottomRowWithTheSameLevel) {
Jeremy Bullock f15907
  bottomRowWithTheSameLevel = -1;
Jeremy Bullock f15907
  TXshColumnP column        = const_cast<txsheet *="">(xsh)->getColumn(col);</txsheet>
Jeremy Bullock f15907
  if (!column) return false;
Jeremy Bullock f15907
Jeremy Bullock f15907
  TXshCellColumn *cellColumn = column->getCellColumn();
Jeremy Bullock f15907
  if (!cellColumn) return false;
Jeremy Bullock f15907
Jeremy Bullock f15907
  int r0, r1;
Jeremy Bullock f15907
  if (!cellColumn->getRange(r0, r1)) return false;
Jeremy Bullock f15907
Jeremy Bullock f15907
  for (int r = r0; r <= r1; r++) {
Jeremy Bullock f15907
    TXshCell cell = cellColumn->getCell(r);
Jeremy Bullock f15907
    if (cell == targetCell) {
Jeremy Bullock f15907
      bottomRowWithTheSameLevel = r;
Jeremy Bullock f15907
      return true;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    if (cell.m_level == targetCell.m_level) bottomRowWithTheSameLevel = r;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  return false;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
QChar numToLetter(int letterNum) {
Jeremy Bullock f15907
  switch (letterNum) {
Jeremy Bullock f15907
  case 0:
Jeremy Bullock f15907
    return QChar();
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 1:
Jeremy Bullock f15907
    return 'A';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 2:
Jeremy Bullock f15907
    return 'B';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 3:
Jeremy Bullock f15907
    return 'C';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 4:
Jeremy Bullock f15907
    return 'D';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 5:
Jeremy Bullock f15907
    return 'E';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 6:
Jeremy Bullock f15907
    return 'F';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 7:
Jeremy Bullock f15907
    return 'G';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 8:
Jeremy Bullock f15907
    return 'H';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  case 9:
Jeremy Bullock f15907
    return 'I';
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  default:
Jeremy Bullock f15907
    return QChar();
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
QString convertToFrameWithLetter(int value, int length = -1) {
Jeremy Bullock f15907
  QString str;
Jeremy Bullock f15907
  str.setNum((int)(value / 10));
Jeremy Bullock f15907
  while (str.length() < length) str.push_front("0");
Jeremy Bullock f15907
  QChar letter = numToLetter(value % 10);
Jeremy Bullock f15907
  if (!letter.isNull()) str.append(letter);
Jeremy Bullock f15907
  return str;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
QString fidsToString(const std::vector<tframeid> &fids,</tframeid>
Jeremy Bullock f15907
                     bool letterOptionEnabled) {
Jeremy Bullock f15907
  if (fids.empty()) return StopMotion::tr("No", "frame id");
Jeremy Bullock f15907
  QString retStr("");
Jeremy Bullock f15907
  if (letterOptionEnabled) {
Jeremy Bullock f15907
    bool beginBlock = true;
Jeremy Bullock f15907
    for (int f = 0; f < fids.size() - 1; f++) {
Jeremy Bullock f15907
      int num      = fids[f].getNumber();
Jeremy Bullock f15907
      int next_num = fids[f + 1].getNumber();
Jeremy Bullock f15907
Jeremy Bullock f15907
      if (num % 10 == 0 && num + 10 == next_num) {
Jeremy Bullock f15907
        if (beginBlock) {
Jeremy Bullock f15907
          retStr += convertToFrameWithLetter(num) + " - ";
Jeremy Bullock f15907
          beginBlock = false;
Jeremy Bullock f15907
        }
Jeremy Bullock f15907
      } else {
Jeremy Bullock f15907
        retStr += convertToFrameWithLetter(num) + ", ";
Jeremy Bullock f15907
        beginBlock = true;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    retStr += convertToFrameWithLetter(fids.back().getNumber());
Jeremy Bullock f15907
  } else {
Jeremy Bullock f15907
    bool beginBlock = true;
Jeremy Bullock f15907
    for (int f = 0; f < fids.size() - 1; f++) {
Jeremy Bullock f15907
      int num      = fids[f].getNumber();
Jeremy Bullock f15907
      int next_num = fids[f + 1].getNumber();
Jeremy Bullock f15907
      if (num + 1 == next_num) {
Jeremy Bullock f15907
        if (beginBlock) {
Jeremy Bullock f15907
          retStr += QString::number(num) + " - ";
Jeremy Bullock f15907
          beginBlock = false;
Jeremy Bullock f15907
        }
Jeremy Bullock f15907
      } else {
Jeremy Bullock f15907
        retStr += QString::number(num) + ", ";
Jeremy Bullock f15907
        beginBlock = true;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    retStr += QString::number(fids.back().getNumber());
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  return retStr;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
bool getRasterLevelSize(TXshLevel *level, TDimension &dim) {
Jeremy Bullock f15907
  std::vector<tframeid> fids;</tframeid>
Jeremy Bullock f15907
  level->getFids(fids);
Jeremy Bullock f15907
  if (fids.empty()) return false;
Jeremy Bullock f15907
  TXshSimpleLevel *simpleLevel = level->getSimpleLevel();
Jeremy Bullock f15907
  if (!simpleLevel) return false;
Jeremy Bullock f15907
  TRasterImageP rimg = (TRasterImageP)simpleLevel->getFrame(fids[0], false);
Jeremy Bullock f15907
  if (!rimg || rimg->isEmpty()) return false;
Jeremy Bullock f15907
Jeremy Bullock f15907
  dim = rimg->getRaster()->getSize();
Jeremy Bullock f15907
  return true;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
};  // namespace
Jeremy Bullock f15907
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
StopMotion::StopMotion() {
shun-iwasawa 31accf
  m_opacity = StopMotionOpacity;
Jeremy Bullock f15907
shun-iwasawa 31accf
  m_webcam = new Webcam();
shun-iwasawa 31accf
  m_canon  = Canon::instance();
shun-iwasawa 31accf
  m_serial = new StopMotionSerial();
shun-iwasawa 31accf
  m_light  = new StopMotionLight();
Jeremy Bullock f15907
shun-iwasawa 31accf
  m_alwaysLiveView = StopMotionAlwaysLiveView;
Jeremy Bullock f15907
Jeremy Bullock f15907
  m_placeOnXSheet      = StopMotionPlaceOnXSheet;
justburner d63640
  m_reviewTimeDSec     = StopMotionReviewDSec;
justburner d63640
  m_intervalDSec       = StopMotionIntervalDSec;
Jeremy Bullock f15907
  m_useNumpadShortcuts = StopMotionUseNumpad;
shun-iwasawa 31accf
  m_drawBeneathLevels  = StopMotionDrawBeneathLevels;
justburner d63640
  m_playCaptureSound   = StopMotionPlayCaptureSound;
Jeremy Bullock f15907
  m_numpadForStyleSwitching =
Jeremy Bullock f15907
      Preferences::instance()->isUseNumpadForSwitchingStylesEnabled();
Jeremy Bullock f15907
  setUseNumpadShortcuts(m_useNumpadShortcuts);
Jeremy Bullock f15907
  m_turnOnRewind = Preferences::instance()->rewindAfterPlaybackEnabled();
Jeremy Bullock f15907
  m_timer        = new QTimer(this);
Jeremy Bullock f15907
  m_reviewTimer  = new QTimer(this);
Jeremy Bullock f15907
  m_reviewTimer->setSingleShot(true);
shun-iwasawa 31accf
  m_intervalTimer      = new QTimer(this);
shun-iwasawa 31accf
  m_countdownTimer     = new QTimer(this);
shun-iwasawa 31accf
  m_webcamOverlayTimer = new QTimer(this);
justburner d63640
  m_camSnapSound       = new QSound(":Resources/camera_snap.wav");
Jeremy Bullock f15907
shun-iwasawa 31accf
  // Make the interval timer single-shot. When the capture finished, restart
shun-iwasawa 31accf
  // timer for next frame.
shun-iwasawa 31accf
  // This is because capturing and saving the image needs some time.
shun-iwasawa 31accf
  m_intervalTimer->setSingleShot(true);
shun-iwasawa 31accf
  m_webcamOverlayTimer->setSingleShot(true);
Jeremy Bullock f15907
Jeremy Bullock f15907
  TXsheetHandle *xsheetHandle = TApp::instance()->getCurrentXsheet();
Jeremy Bullock f15907
  TSceneHandle *sceneHandle   = TApp::instance()->getCurrentScene();
Jeremy Bullock f15907
  TFrameHandle *frameHandle   = TApp::instance()->getCurrentFrame();
Jeremy Bullock f15907
  bool ret                    = true;
Jeremy Bullock f15907
Jeremy Bullock f15907
  ret = ret &&
Jeremy Bullock f15907
        connect(xsheetHandle, SIGNAL(xsheetSwitched()), this, SLOT(update()));
Jeremy Bullock f15907
  ret = ret && connect(m_reviewTimer, SIGNAL(timeout()), this,
Jeremy Bullock f15907
                       SLOT(onReviewTimeout()));
Jeremy Bullock f15907
  ret = ret && connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
shun-iwasawa 31accf
Jeremy Bullock f15907
  ret = ret && connect(sceneHandle, SIGNAL(sceneSwitched()), this,
Jeremy Bullock f15907
                       SLOT(onSceneSwitched()));
Jeremy Bullock f15907
  ret = ret && connect(frameHandle, SIGNAL(isPlayingStatusChanged()), this,
Jeremy Bullock f15907
                       SLOT(onPlaybackChanged()));
shun-iwasawa 31accf
  ret = ret && connect(m_intervalTimer, SIGNAL(timeout()), this,
shun-iwasawa 31accf
                       SLOT(onIntervalCaptureTimerTimeout()));
shun-iwasawa 31accf
  ret = ret && connect(m_webcamOverlayTimer, SIGNAL(timeout()), this,
shun-iwasawa 31accf
                       SLOT(captureWebcamOnTimeout()));
shun-iwasawa 31accf
  ret = ret && connect(m_canon, SIGNAL(newCanonImageReady()), this,
shun-iwasawa 31accf
                       SLOT(importImage()));
shun-iwasawa 31accf
  assert(ret);
shun-iwasawa 31accf
  ret = ret && connect(m_canon, SIGNAL(canonCameraChanged(QString)), this,
shun-iwasawa 31accf
                       SLOT(onCanonCameraChanged(QString)));
Jeremy Bullock f15907
  assert(ret);
Jeremy Bullock f15907
Jeremy Bullock f15907
  ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
Jeremy Bullock f15907
Jeremy Bullock f15907
  setToNextNewLevel();
Jeremy Bullock f15907
  m_filePath = scene->getDefaultLevelPath(OVL_TYPE, m_levelName.toStdWString())
Jeremy Bullock f15907
                   .getParentDir()
Jeremy Bullock f15907
                   .getQString();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
StopMotion::~StopMotion() {
shun-iwasawa 31accf
  disconnectAllCameras();
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  m_canon->closeAll();
shun-iwasawa 31accf
#endif
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::onSceneSwitched() {
shun-iwasawa 31accf
  disconnectAllCameras();
shun-iwasawa 31accf
Jeremy Bullock f15907
  TApp *app         = TApp::instance();
Jeremy Bullock f15907
  ToonzScene *scene = app->getCurrentScene()->getScene();
Jeremy Bullock f15907
  TXsheet *xsh      = TApp::instance()->getCurrentXsheet()->getXsheet();
Jeremy Bullock f15907
  setToNextNewLevel();
Jeremy Bullock f15907
  m_filePath = scene->getDefaultLevelPath(OVL_TYPE, m_levelName.toStdWString())
Jeremy Bullock f15907
                   .getParentDir()
Jeremy Bullock f15907
                   .getQString();
shun-iwasawa 31accf
  m_frameNumber = 1;
shun-iwasawa 31accf
  m_liveViewImageMap.clear();
Jeremy Bullock f15907
Jeremy Bullock f15907
  TLevelSet *levelSet = scene->getLevelSet();
Jeremy Bullock f15907
  std::vector<txshlevel *=""> levels;</txshlevel>
Jeremy Bullock f15907
  levelSet->listLevels(levels);
shun-iwasawa 31accf
  int size   = levels.size();
shun-iwasawa 31accf
  bool found = false;
Jeremy Bullock f15907
  for (int i = 0; i < size; i++) {
Jeremy Bullock f15907
    TXshLevel *level = levels[i];
Jeremy Bullock f15907
    if (level->getType() == OVL_XSHLEVEL) {
Jeremy Bullock f15907
      TXshSimpleLevel *sl    = 0;
Jeremy Bullock f15907
      sl                     = level->getSimpleLevel();
Jeremy Bullock f15907
      bool isStopMotionLevel = sl->getProperties()->isStopMotionLevel();
Jeremy Bullock f15907
      if (isStopMotionLevel) {
Jeremy Bullock f15907
        m_filePath    = sl->getPath().getParentDir().getQString();
Jeremy Bullock f15907
        m_levelName   = QString::fromStdWString(sl->getName());
Jeremy Bullock f15907
        m_frameNumber = sl->getFrameCount() + 1;
Jeremy Bullock f15907
        setXSheetFrameNumber(xsh->getFrameCount() + 1);
shun-iwasawa 31accf
        loadXmlFile();
shun-iwasawa 31accf
        buildLiveViewMap(sl);
shun-iwasawa 6bac0f
        m_sl  = sl;
shun-iwasawa 31accf
        found = true;
Jeremy Bullock f15907
        break;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (!found) {
shun-iwasawa 31accf
    setXSheetFrameNumber(1);
shun-iwasawa 31accf
  }
Jeremy Bullock f15907
  emit(levelNameChanged(m_levelName));
Jeremy Bullock f15907
  emit(filePathChanged(m_filePath));
Jeremy Bullock f15907
  emit(frameNumberChanged(m_frameNumber));
Jeremy Bullock f15907
  emit(xSheetFrameNumberChanged(m_xSheetFrameNumber));
Jeremy Bullock f15907
  refreshFrameInfo();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
bool StopMotion::buildLiveViewMap(TXshSimpleLevel *sl) {
shun-iwasawa 31accf
  m_liveViewImageMap.clear();
shun-iwasawa 31accf
  TApp *app         = TApp::instance();
shun-iwasawa 31accf
  ToonzScene *scene = app->getCurrentScene()->getScene();
shun-iwasawa 31accf
  TXsheet *xsh      = scene->getXsheet();
shun-iwasawa 31accf
shun-iwasawa 31accf
  std::wstring levelName = m_levelName.toStdWString();
shun-iwasawa 31accf
  if (levelName.empty()) {
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (m_usingWebcam) {
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath liveViewFolder = scene->decodeFilePath(
shun-iwasawa 31accf
      TFilePath(m_filePath) + TFilePath(levelName + L"_LiveView"));
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath levelFp = TFilePath(m_filePath) +
shun-iwasawa 31accf
                      TFilePath(levelName + L".." + m_fileType.toStdWString());
shun-iwasawa 31accf
  TFilePath actualLevelFp = scene->decodeFilePath(levelFp);
shun-iwasawa 31accf
  TFilePath liveViewFp =
shun-iwasawa 31accf
      scene->decodeFilePath(liveViewFolder + TFilePath(levelName + L"..jpg"));
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (!TSystem::doesExistFileOrLevel(liveViewFolder)) return false;
shun-iwasawa 31accf
shun-iwasawa 31accf
  int count = sl->getFrameCount();
shun-iwasawa 31accf
  std::vector<tframeid> fids;</tframeid>
shun-iwasawa 31accf
  sl->getFids(fids);
shun-iwasawa 31accf
  for (TFrameId id : fids) {
shun-iwasawa 31accf
    int frameNumber = id.getNumber();
shun-iwasawa 31accf
    if (TSystem::doesExistFileOrLevel(liveViewFp.withFrame(frameNumber))) {
shun-iwasawa 31accf
      TRaster32P image;
shun-iwasawa 31accf
      JpgConverter::loadJpg(liveViewFp.withFrame(frameNumber), image);
shun-iwasawa 31accf
      m_liveViewImageMap.insert(std::pair<int, traster32p="">(frameNumber, image));</int,>
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (m_liveViewImageMap.size() > 0) {
shun-iwasawa 31accf
    return true;
shun-iwasawa 31accf
  } else
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::disconnectAllCameras() {
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  if (m_liveViewStatus > LiveViewClosed) {
shun-iwasawa 31accf
    m_canon->resetCanon(true);
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    m_canon->resetCanon(false);
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (m_usingWebcam) {
shun-iwasawa 31accf
    m_webcam->releaseWebcam();
shun-iwasawa 31accf
    m_usingWebcam = false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  m_webcam->clearWebcam();
shun-iwasawa 31accf
shun-iwasawa 31accf
  m_liveViewStatus = LiveViewClosed;
shun-iwasawa 31accf
  setTEnvCameraName("");
shun-iwasawa 31accf
shun-iwasawa 31accf
  m_isTimeLapse     = false;
shun-iwasawa 31accf
  m_intervalStarted = false;
shun-iwasawa 31accf
  m_intervalTimer->stop();
shun-iwasawa 31accf
  m_countdownTimer->stop();
shun-iwasawa 31accf
  emit(intervalToggled(false));
shun-iwasawa 31accf
shun-iwasawa 31accf
  emit(liveViewChanged(false));
shun-iwasawa 31accf
  emit(liveViewStopped());
shun-iwasawa 31accf
  emit(newCameraSelected(0, false));
shun-iwasawa 31accf
  toggleNumpadShortcuts(false);
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
Jeremy Bullock f15907
void StopMotion::onPlaybackChanged() {
shun-iwasawa 31accf
  if (TApp::instance()->getCurrentFrame()->isPlaying() ||
shun-iwasawa 31accf
      m_liveViewStatus == LiveViewClosed)
Jeremy Bullock f15907
    return;
Jeremy Bullock f15907
Jeremy Bullock f15907
  int r0, r1, step;
Jeremy Bullock f15907
  ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
Jeremy Bullock f15907
  scene->getProperties()->getPreviewProperties()->getRange(r0, r1, step);
Jeremy Bullock f15907
  if (r1 > -1) return;
Jeremy Bullock f15907
Jeremy Bullock f15907
  int frame     = TApp::instance()->getCurrentFrame()->getFrame();
Jeremy Bullock f15907
  int lastFrame = TApp::instance()->getCurrentFrame()->getMaxFrameIndex();
flurick c8ee00
  if (m_xSheetFrameNumber - 1 == frame + 1) {
Jeremy Bullock f15907
    TApp::instance()->getCurrentFrame()->setFrame(m_xSheetFrameNumber - 1);
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setOpacity(int opacity) {
Jeremy Bullock f15907
  m_opacity         = opacity;
Jeremy Bullock f15907
  StopMotionOpacity = m_opacity;
Jeremy Bullock f15907
  emit(opacityChanged(m_opacity));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::lowerOpacity() {
Jeremy Bullock f15907
  int opacity = round((double)m_opacity / 255.0 * 10.0);
Jeremy Bullock f15907
  opacity *= 10;
Jeremy Bullock f15907
  opacity -= 10;
Jeremy Bullock f15907
  m_opacity         = double(opacity) / 100.0 * 255.0;
otakuto 158f9f
  m_opacity         = std::max(0, m_opacity);
Jeremy Bullock f15907
  StopMotionOpacity = m_opacity;
Jeremy Bullock f15907
  emit(opacityChanged(m_opacity));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::raiseOpacity() {
Jeremy Bullock f15907
  int opacity = round((double)m_opacity / 255.0 * 10.0);
Jeremy Bullock f15907
  opacity *= 10;
Jeremy Bullock f15907
  opacity += 10;
Jeremy Bullock f15907
  m_opacity         = double(opacity) / 100.0 * 255.0;
otakuto 158f9f
  m_opacity         = std::min(255, m_opacity);
Jeremy Bullock f15907
  StopMotionOpacity = m_opacity;
Jeremy Bullock f15907
  emit(opacityChanged(m_opacity));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setAlwaysLiveView(bool on) {
Jeremy Bullock f15907
  m_alwaysLiveView         = on;
Jeremy Bullock f15907
  StopMotionAlwaysLiveView = int(on);
Jeremy Bullock f15907
  emit(liveViewOnAllFramesSignal(on));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setPlaceOnXSheet(bool on) {
Jeremy Bullock f15907
  m_placeOnXSheet         = on;
Jeremy Bullock f15907
  StopMotionPlaceOnXSheet = int(on);
Jeremy Bullock f15907
  emit(placeOnXSheetSignal(on));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
justburner d63640
void StopMotion::setReviewTimeDSec(int timeDSec) {
justburner d63640
  m_reviewTimeDSec     = timeDSec;
justburner d63640
  StopMotionReviewDSec = timeDSec;
justburner d63640
  emit(reviewTimeChangedSignal(timeDSec));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
void StopMotion::jumpToCameraFrame() {
shun-iwasawa 31accf
  if (m_liveViewStatus == LiveViewPaused && !m_userCalledPause) {
shun-iwasawa 31accf
    m_liveViewStatus = LiveViewOpen;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (m_hasLineUpImage) m_showLineUpImage = true;
shun-iwasawa 31accf
  TApp::instance()->getCurrentFrame()->setFrame(m_xSheetFrameNumber - 1);
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
void StopMotion::removeStopMotionFrame() {
shun-iwasawa 31accf
  if (m_xSheetFrameNumber == 1) return;
shun-iwasawa 31accf
  TApp *app         = TApp::instance();
shun-iwasawa 31accf
  ToonzScene *scene = app->getCurrentScene()->getScene();
shun-iwasawa 31accf
  TXsheet *xsh      = scene->getXsheet();
shun-iwasawa 31accf
shun-iwasawa 31accf
  int row = m_xSheetFrameNumber - 2;
shun-iwasawa 31accf
shun-iwasawa 31accf
  // find which column the level is on.
shun-iwasawa 31accf
  // check with the current column first
shun-iwasawa 31accf
  int col       = app->getCurrentColumn()->getColumnIndex();
shun-iwasawa 31accf
  TXshCell cell = xsh->getCell(row, col);
shun-iwasawa 31accf
  TXshSimpleLevelP sl;
shun-iwasawa 31accf
  bool found = false;
shun-iwasawa 31accf
  if (!cell.isEmpty()) {
shun-iwasawa 31accf
    if (cell.getSimpleLevel() != 0) {
shun-iwasawa 31accf
      sl = cell.getSimpleLevel();
shun-iwasawa 31accf
      if (sl.getPointer()->getName() == m_levelName.toStdWString()) {
shun-iwasawa 31accf
        found = true;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (!found) {
shun-iwasawa 31accf
    int cols = xsh->getColumnCount();
shun-iwasawa 31accf
    for (int i = 0; i < cols; i++) {
shun-iwasawa 31accf
      cell = xsh->getCell(row, i);
shun-iwasawa 31accf
      if (!cell.isEmpty()) {
shun-iwasawa 31accf
        if (cell.getSimpleLevel() != 0) {
shun-iwasawa 31accf
          sl = cell.getSimpleLevel();
shun-iwasawa 31accf
          if (sl.getPointer()->getName() == m_levelName.toStdWString()) {
shun-iwasawa 31accf
            found = true;
shun-iwasawa 31accf
            col   = i;
shun-iwasawa 31accf
            break;
shun-iwasawa 31accf
          }
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (!found) {
shun-iwasawa 31accf
    // DVGui::error(tr("Could not find an xsheet level with  the current
shun-iwasawa 31accf
    // level"));
shun-iwasawa 31accf
    return;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  TXshCellColumn *xshCellColumn = xsh->getColumn(col)->getCellColumn();
shun-iwasawa 31accf
  if (!xshCellColumn) return;
shun-iwasawa 31accf
shun-iwasawa 31accf
  xshCellColumn->removeCells(row, 1);
shun-iwasawa 31accf
shun-iwasawa 31accf
  app->getCurrentScene()->getScene()->getXsheet()->updateFrameCount();
shun-iwasawa 31accf
  setXSheetFrameNumber(m_xSheetFrameNumber - 1);
shun-iwasawa 31accf
  app->getCurrentFrame()->prevFrame();
shun-iwasawa 31accf
  app->getCurrentScene()->notifySceneChanged();
shun-iwasawa 31accf
  app->getCurrentXsheet()->notifyXsheetChanged();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setUseNumpadShortcuts(bool on) {
Jeremy Bullock f15907
  m_useNumpadShortcuts = on;
Jeremy Bullock f15907
  StopMotionUseNumpad  = int(on);
Jeremy Bullock f15907
  emit(useNumpadSignal(on));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::setDrawBeneathLevels(bool on) {
shun-iwasawa 31accf
  m_drawBeneathLevels         = on;
shun-iwasawa 31accf
  StopMotionDrawBeneathLevels = int(on);
shun-iwasawa 31accf
  emit(drawBeneathLevelsSignal(on));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::toggleInterval(bool on) {
shun-iwasawa 31accf
  m_isTimeLapse = on;
shun-iwasawa 31accf
  emit(intervalToggled(on));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::startInterval() {
shun-iwasawa 31accf
  if (m_liveViewStatus > 1) {
justburner d63640
    m_intervalTimer->start(m_intervalDSec * 100);
justburner d63640
    if (m_intervalDSec != 0) m_countdownTimer->start(100);
shun-iwasawa 31accf
    m_intervalStarted = true;
shun-iwasawa 31accf
    emit(intervalStarted());
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    DVGui::warning(tr("Please start live view before using time lapse."));
shun-iwasawa 31accf
    m_intervalStarted = false;
shun-iwasawa 31accf
    emit(intervalStopped());
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::stopInterval() {
shun-iwasawa 31accf
  m_intervalTimer->stop();
shun-iwasawa 31accf
  m_countdownTimer->stop();
shun-iwasawa 31accf
  m_intervalStarted = false;
shun-iwasawa 31accf
  emit(intervalStopped());
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
justburner d63640
void StopMotion::setIntervalDSec(int value) {
justburner d63640
  m_intervalDSec         = value;
justburner d63640
  StopMotionIntervalDSec = value;
shun-iwasawa 31accf
  emit(intervalAmountChanged(value));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::onIntervalCaptureTimerTimeout() {
shun-iwasawa 31accf
  if (m_liveViewStatus > 0) {
shun-iwasawa 31accf
    captureImage();
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    DVGui::warning(tr("Please start live view before using time lapse."));
shun-iwasawa 31accf
    m_intervalStarted = false;
shun-iwasawa 31accf
    emit(intervalStopped());
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::restartInterval() {
shun-iwasawa 31accf
  // restart interval timer for capturing next frame (it is single shot)
shun-iwasawa 31accf
  if (m_isTimeLapse && m_intervalStarted) {
justburner d63640
    m_intervalTimer->start(m_intervalDSec * 100);
shun-iwasawa 31accf
    // restart the count down as well (for aligning the timing. It is not
shun-iwasawa 31accf
    // single shot)
justburner d63640
    if (m_intervalDSec != 0) m_countdownTimer->start(100);
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
Jeremy Bullock f15907
void StopMotion::toggleNumpadShortcuts(bool on) {
Jeremy Bullock f15907
  // can't just return if this feature is off
Jeremy Bullock f15907
  // it could have been toggled while the camera was active
Jeremy Bullock f15907
  if (!m_useNumpadShortcuts) on = false;
shun-iwasawa 6bac0f
  CommandManager *comm = CommandManager::instance();
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (on) {
shun-iwasawa 31accf
    m_oldActionMap.clear();
Jeremy Bullock f15907
    // if turning it on, get all old shortcuts
Jeremy Bullock f15907
    if (m_numpadForStyleSwitching) {
shun-iwasawa 2c27a4
      Preferences::instance()->setValue(useNumpadForSwitchingStyles, false);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    std::string shortcut;
Jeremy Bullock f15907
    QAction *action;
Jeremy Bullock f15907
    for (int i = 0; i <= 9; i++) {
Jeremy Bullock f15907
      shortcut = QString::number(i).toStdString();
Jeremy Bullock f15907
      action   = comm->getActionFromShortcut(shortcut);
Jeremy Bullock f15907
      if (action) {
Jeremy Bullock f15907
        m_oldActionMap.insert(
Jeremy Bullock f15907
            std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
Jeremy Bullock f15907
        action->setShortcut(QKeySequence(""));
Jeremy Bullock f15907
        action = NULL;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    shortcut = "+";
Jeremy Bullock f15907
    action   = comm->getActionFromShortcut(shortcut);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      m_oldActionMap.insert(
Jeremy Bullock f15907
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    shortcut = "-";
Jeremy Bullock f15907
    action   = comm->getActionFromShortcut(shortcut);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      m_oldActionMap.insert(
Jeremy Bullock f15907
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
      action = NULL;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    shortcut = "Enter";
shun-iwasawa 31accf
    action   = comm->getActionFromShortcut(shortcut);
shun-iwasawa 31accf
    if (action) {
shun-iwasawa 31accf
      m_oldActionMap.insert(
shun-iwasawa 31accf
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
      action = NULL;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    shortcut = "Backspace";
shun-iwasawa 31accf
    action   = comm->getActionFromShortcut(shortcut);
shun-iwasawa 31accf
    if (action) {
shun-iwasawa 31accf
      m_oldActionMap.insert(
shun-iwasawa 31accf
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    shortcut = "Return";
Jeremy Bullock f15907
    action   = comm->getActionFromShortcut(shortcut);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      m_oldActionMap.insert(
Jeremy Bullock f15907
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    shortcut = "*";
Jeremy Bullock f15907
    action   = comm->getActionFromShortcut(shortcut);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      m_oldActionMap.insert(
Jeremy Bullock f15907
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
      action = NULL;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    shortcut = ".";
shun-iwasawa 31accf
    action   = comm->getActionFromShortcut(shortcut);
shun-iwasawa 31accf
    if (action) {
shun-iwasawa 31accf
      m_oldActionMap.insert(
shun-iwasawa 31accf
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
      action = NULL;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    shortcut = "/";
shun-iwasawa 31accf
    action   = comm->getActionFromShortcut(shortcut);
shun-iwasawa 31accf
    if (action) {
shun-iwasawa 31accf
      m_oldActionMap.insert(
shun-iwasawa 31accf
          std::pair<std::string, *="" qaction="">(shortcut, action));</std::string,>
shun-iwasawa 31accf
      action->setShortcut(QKeySequence(""));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
Jeremy Bullock f15907
    // now set all new shortcuts
shun-iwasawa 31accf
    action = comm->getAction(MI_PrevFrame);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      action->setShortcut(QKeySequence("1"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    action = comm->getAction(MI_StopMotionNextFrame);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      action->setShortcut(QKeySequence("2"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    action = comm->getAction(MI_StopMotionJumpToCamera);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      action->setShortcut(QKeySequence("3"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    action = comm->getAction(MI_Loop);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      action->setShortcut(QKeySequence("8"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    action = comm->getAction(MI_Play);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      action->setShortcut(QKeySequence("0"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    action = comm->getAction(MI_StopMotionRaiseOpacity);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      action->setShortcut(QKeySequence("+"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    action = comm->getAction(MI_StopMotionLowerOpacity);
Jeremy Bullock f15907
    if (action) {
Jeremy Bullock f15907
      action->setShortcut(QKeySequence("-"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    action = comm->getAction(MI_StopMotionCapture);
Jeremy Bullock f15907
    if (action) {
shun-iwasawa 31accf
      action->setShortcut(QKeySequence("Return"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    action = comm->getAction(MI_StopMotionRemoveFrame);
Jeremy Bullock f15907
    if (action) {
shun-iwasawa 31accf
      action->setShortcut(QKeySequence("Backspace"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    action = comm->getAction(MI_StopMotionToggleLiveView);
Jeremy Bullock f15907
    if (action) {
shun-iwasawa 31accf
      action->setShortcut(QKeySequence("5"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    action = comm->getAction(MI_StopMotionToggleUseLiveViewImages);
Jeremy Bullock f15907
    if (action) {
shun-iwasawa 31accf
      action->setShortcut(QKeySequence("."));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    action = comm->getAction(MI_StopMotionToggleZoom);
Jeremy Bullock f15907
    if (action) {
shun-iwasawa 31accf
      action->setShortcut(QKeySequence("*"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    action = comm->getAction(MI_StopMotionPickFocusCheck);
Jeremy Bullock f15907
    if (action) {
shun-iwasawa 31accf
      action->setShortcut(QKeySequence("/"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    action = comm->getAction(MI_ShortPlay);
Jeremy Bullock f15907
    if (action) {
shun-iwasawa 31accf
      action->setShortcut(QKeySequence("6"));
Jeremy Bullock f15907
      action = NULL;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    // unset the new shortcuts first
shun-iwasawa 31accf
    if (m_oldActionMap.size() > 0) {
Jeremy Bullock f15907
      QAction *action;
shun-iwasawa 31accf
      action = comm->getAction(MI_PrevFrame);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
Jeremy Bullock f15907
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionNextFrame);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionJumpToCamera);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_Loop);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_Play);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionCapture);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionLowerOpacity);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionRaiseOpacity);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionToggleLiveView);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionToggleUseLiveViewImages);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionToggleZoom);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_ShortPlay);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionPickFocusCheck);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionRemoveFrame);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(
shun-iwasawa 31accf
            QKeySequence(comm->getShortcutFromAction(action).c_str()));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
shun-iwasawa 31accf
      // now put back the old shortcuts
shun-iwasawa 31accf
      auto it = m_oldActionMap.begin();
shun-iwasawa 31accf
      while (it != m_oldActionMap.end()) {
shun-iwasawa 31accf
        it->second->setShortcut(QKeySequence(it->first.c_str()));
shun-iwasawa 31accf
        it++;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (m_numpadForStyleSwitching) {
shun-iwasawa 31accf
        std::string shortcut;
shun-iwasawa 31accf
        QAction *action;
shun-iwasawa 31accf
        for (int i = 0; i <= 9; i++) {
shun-iwasawa 31accf
          shortcut = QString::number(i).toStdString();
shun-iwasawa 31accf
          action   = comm->getActionFromShortcut(shortcut);
shun-iwasawa 31accf
          if (action) {
shun-iwasawa 31accf
            action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
            action = NULL;
shun-iwasawa 31accf
          }
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
        Preferences::instance()->setValue(useNumpadForSwitchingStyles, true);
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::toggleNumpadForFocusCheck(bool on) {
shun-iwasawa 31accf
  CommandManager *comm = CommandManager::instance();
shun-iwasawa 31accf
  if (m_useNumpadShortcuts) {
shun-iwasawa 31accf
    if (on) {
shun-iwasawa 31accf
      QAction *action;
shun-iwasawa 31accf
      action = comm->getAction(MI_PrevFrame);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionNextFrame);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionJumpToCamera);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_Loop);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_Play);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionToggleLiveView);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_ShortPlay);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionCapture);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence(""));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
    } else {
shun-iwasawa 31accf
      QAction *action;
shun-iwasawa 31accf
      action = comm->getAction(MI_PrevFrame);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("1"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionNextFrame);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("2"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionJumpToCamera);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("3"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_Loop);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("8"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_Play);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("0"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionToggleLiveView);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("5"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_ShortPlay);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("6"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      action = comm->getAction(MI_StopMotionCapture);
shun-iwasawa 31accf
      if (action) {
shun-iwasawa 31accf
        action->setShortcut(QKeySequence("Return"));
shun-iwasawa 31accf
        action = NULL;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::setXSheetFrameNumber(int frameNumber) {
shun-iwasawa 31accf
  m_xSheetFrameNumber = frameNumber;
shun-iwasawa 31accf
  TApp::instance()->getCurrentFrame()->setFrame(frameNumber - 1);
shun-iwasawa 31accf
  loadLineUpImage();
shun-iwasawa 31accf
  emit(xSheetFrameNumberChanged(m_xSheetFrameNumber));
shun-iwasawa 31accf
  m_serial->sendSerialData();
shun-iwasawa 31accf
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
bool StopMotion::loadLineUpImage() {
shun-iwasawa 31accf
  if (m_liveViewStatus == LiveViewClosed || m_userCalledPause) return false;
shun-iwasawa 31accf
  int row;
shun-iwasawa 31accf
  if (m_xSheetFrameNumber == 1) {
shun-iwasawa 31accf
    row = 0;
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    row = m_xSheetFrameNumber - 2;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  m_hasLineUpImage = loadLiveViewImage(row, m_lineUpImage);
shun-iwasawa 31accf
  return m_hasLineUpImage;
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
bool StopMotion::loadLiveViewImage(int row, TRaster32P &image) {
shun-iwasawa 31accf
  // first see if the level exists in the current level set
shun-iwasawa 31accf
  ToonzScene *currentScene = TApp::instance()->getCurrentScene()->getScene();
shun-iwasawa 31accf
  TLevelSet *levelSet      = currentScene->getLevelSet();
shun-iwasawa 31accf
shun-iwasawa 31accf
  std::wstring levelName = m_levelName.toStdWString();
shun-iwasawa 31accf
shun-iwasawa 31accf
  // level with the same name
shun-iwasawa 31accf
  TXshLevel *level_sameName = levelSet->getLevel(levelName);
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath levelFp = TFilePath(m_filePath) +
shun-iwasawa 31accf
                      TFilePath(levelName + L".." + m_fileType.toStdWString());
shun-iwasawa 31accf
shun-iwasawa 31accf
  // level with the same path
shun-iwasawa 31accf
  TXshLevel *level_samePath = levelSet->getLevel(*(currentScene), levelFp);
shun-iwasawa 31accf
shun-iwasawa 31accf
  // TFilePath actualLevelFp = currentScene->decodeFilePath(levelFp);
shun-iwasawa 31accf
  TXshSimpleLevelP sl;
shun-iwasawa 31accf
  if (level_sameName && level_samePath && level_sameName == level_samePath) {
shun-iwasawa 31accf
    sl                 = dynamic_cast<txshsimplelevel *="">(level_sameName);</txshsimplelevel>
Jeremy Bullock f15907
    bool isRasterLevel = sl && (sl->getType() == OVL_XSHLEVEL);
Jeremy Bullock f15907
    if (!isRasterLevel) {
Jeremy Bullock f15907
      return false;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  } else
Jeremy Bullock f15907
    return false;
Jeremy Bullock f15907
Jeremy Bullock f15907
  // next we need to find the column the level is on
Jeremy Bullock f15907
  TApp *app    = TApp::instance();
Jeremy Bullock f15907
  TXsheet *xsh = currentScene->getXsheet();
shun-iwasawa 31accf
  int col      = app->getCurrentColumn()->getColumnIndex();
Jeremy Bullock f15907
Jeremy Bullock f15907
  int foundCol = -1;
Jeremy Bullock f15907
  // most possibly, it's in the current column
Jeremy Bullock f15907
  int rowCheck;
Jeremy Bullock f15907
  findCell(xsh, col, TXshCell(level_sameName, TFrameId(1)), rowCheck);
Jeremy Bullock f15907
  if (rowCheck >= 0) {
Jeremy Bullock f15907
    foundCol = col;
Jeremy Bullock f15907
  } else {
Jeremy Bullock f15907
    // search entire xsheet
Jeremy Bullock f15907
    for (int c = 0; c < xsh->getColumnCount(); c++) {
Jeremy Bullock f15907
      if (c == col) continue;
Jeremy Bullock f15907
      findCell(xsh, c, TXshCell(level_sameName, TFrameId(1)), rowCheck);
Jeremy Bullock f15907
      if (rowCheck >= 0) {
Jeremy Bullock f15907
        foundCol = c;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  if (rowCheck < 0) return false;
Jeremy Bullock f15907
Jeremy Bullock f15907
  // note found row represents the last row found that uses
Jeremy Bullock f15907
  // the active level
shun-iwasawa 31accf
  TXshCell cell = xsh->getCell(row, foundCol);
shun-iwasawa 31accf
  if (!(cell.getSimpleLevel() != 0 &&
shun-iwasawa 31accf
        cell.getSimpleLevel() == level_sameName->getSimpleLevel())) {
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
Jeremy Bullock f15907
  TFrameId frameId = xsh->getCell(row, foundCol).getFrameId();
Jeremy Bullock f15907
Jeremy Bullock f15907
  int frameNumber = frameId.getNumber();
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (m_usingWebcam) {
Jeremy Bullock f15907
    if (frameNumber > 0) {
shun-iwasawa 31accf
      image = sl->getFrame(frameId, false)->raster();
Jeremy Bullock f15907
      return true;
Jeremy Bullock f15907
    } else
Jeremy Bullock f15907
      return false;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
shun-iwasawa 31accf
  // first check if the image is in the live view map
shun-iwasawa 31accf
  std::map<int, traster32p="">::iterator it;</int,>
shun-iwasawa 31accf
  it = m_liveViewImageMap.find(frameNumber);
shun-iwasawa 31accf
  if (it != m_liveViewImageMap.end()) {
shun-iwasawa 31accf
    image = m_liveViewImageMap.find(frameNumber)->second;
shun-iwasawa 31accf
    return true;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  // it's not in the map
shun-iwasawa 31accf
  // now check to see if a file actually exists
shun-iwasawa 31accf
  // then put it in the map
Jeremy Bullock f15907
  TFilePath liveViewFolder = currentScene->decodeFilePath(
Jeremy Bullock f15907
      TFilePath(m_filePath) + TFilePath(levelName + L"_LiveView"));
Jeremy Bullock f15907
  TFilePath liveViewFp = currentScene->decodeFilePath(
Jeremy Bullock f15907
      liveViewFolder + TFilePath(levelName + L"..jpg"));
Jeremy Bullock f15907
  TFilePath liveViewFile(liveViewFp.withFrame(frameNumber));
Jeremy Bullock f15907
  if (TFileStatus(liveViewFile).doesExist()) {
shun-iwasawa 31accf
    if (JpgConverter::loadJpg(liveViewFile, image)) {
shun-iwasawa 31accf
      m_liveViewImageMap.insert(std::pair<int, traster32p="">(frameNumber, image));</int,>
Jeremy Bullock f15907
      return true;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  return false;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setFrameNumber(int frameNumber) {
Jeremy Bullock f15907
  m_frameNumber = frameNumber;
Jeremy Bullock f15907
  emit(frameNumberChanged(m_frameNumber));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::nextFrame() {
Jeremy Bullock f15907
  if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) {
Jeremy Bullock f15907
    int f = m_frameNumber;
Jeremy Bullock f15907
    if (f % 10 == 0)  // next number
Jeremy Bullock f15907
      m_frameNumber = ((int)(f / 10) + 1) * 10;
Jeremy Bullock f15907
    else  // next alphabet
Jeremy Bullock f15907
      m_frameNumber = f + 1;
Jeremy Bullock f15907
  } else
Jeremy Bullock f15907
    m_frameNumber = m_frameNumber + 1;
Jeremy Bullock f15907
  emit(frameNumberChanged(m_frameNumber));
Jeremy Bullock f15907
  refreshFrameInfo();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::lastFrame() {}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::previousFrame() {
Jeremy Bullock f15907
  int f = m_frameNumber;
Jeremy Bullock f15907
  if (f > 1) {
Jeremy Bullock f15907
    if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) {
Jeremy Bullock f15907
      if (f % 10 == 0)  // next number
Jeremy Bullock f15907
        m_frameNumber = ((int)(f / 10) - 1) * 10;
Jeremy Bullock f15907
      else  // next alphabet
Jeremy Bullock f15907
        m_frameNumber = f - 1;
Jeremy Bullock f15907
    } else
Jeremy Bullock f15907
      m_frameNumber = f - 1;
Jeremy Bullock f15907
    emit(frameNumberChanged(m_frameNumber));
Jeremy Bullock f15907
    refreshFrameInfo();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setLevelName(QString levelName) { m_levelName = levelName; }
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::nextName() {
Jeremy Bullock f15907
  std::unique_ptr<flexiblenamecreator> nameCreator(new FlexibleNameCreator());</flexiblenamecreator>
Jeremy Bullock f15907
  if (!nameCreator->setCurrent(m_levelName.toStdWString())) {
Jeremy Bullock f15907
    setToNextNewLevel();
Jeremy Bullock f15907
    return;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  std::wstring levelName = nameCreator->getNext();
Jeremy Bullock f15907
  updateLevelNameAndFrame(levelName);
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::previousName() {
Jeremy Bullock f15907
  std::unique_ptr<flexiblenamecreator> nameCreator(new FlexibleNameCreator());</flexiblenamecreator>
Jeremy Bullock f15907
Jeremy Bullock f15907
  std::wstring levelName;
Jeremy Bullock f15907
luz paz 6454c4
  // if the current level name is non-sequential, then try to switch the last
luz paz 6454c4
  // sequential level in the scene.
Jeremy Bullock f15907
  if (!nameCreator->setCurrent(m_levelName.toStdWString())) {
Jeremy Bullock f15907
    TLevelSet *levelSet =
Jeremy Bullock f15907
        TApp::instance()->getCurrentScene()->getScene()->getLevelSet();
Jeremy Bullock f15907
    nameCreator->setCurrent(L"ZZ");
Jeremy Bullock f15907
    for (;;) {
Jeremy Bullock f15907
      levelName = nameCreator->getPrevious();
Jeremy Bullock f15907
      if (levelSet->getLevel(levelName) != 0) break;
Jeremy Bullock f15907
      if (levelName == L"A") {
Jeremy Bullock f15907
        setToNextNewLevel();
Jeremy Bullock f15907
        return;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  } else
Jeremy Bullock f15907
    levelName = nameCreator->getPrevious();
Jeremy Bullock f15907
Jeremy Bullock f15907
  updateLevelNameAndFrame(levelName);
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setFileType(QString fileType) {
Jeremy Bullock f15907
  m_fileType = fileType;
Jeremy Bullock f15907
  emit(fileTypeChanged(m_fileType));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setFilePath(QString filePath) {
Jeremy Bullock f15907
  m_filePath = filePath;
Jeremy Bullock f15907
Jeremy Bullock f15907
  ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
Jeremy Bullock f15907
  TFilePath saveInPath(filePath.toStdWString());
Jeremy Bullock f15907
  scene->getProperties()->setCameraCaptureSaveInPath(saveInPath);
Jeremy Bullock f15907
  refreshFrameInfo();
Jeremy Bullock f15907
Jeremy Bullock f15907
  emit(filePathChanged(m_filePath));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setSubsamplingValue(int subsampling) {
Jeremy Bullock f15907
  m_subsampling = subsampling;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::getSubsampling() {
Jeremy Bullock f15907
  ToonzScene *currentScene = TApp::instance()->getCurrentScene()->getScene();
Jeremy Bullock f15907
  TLevelSet *levelSet      = currentScene->getLevelSet();
Jeremy Bullock f15907
Jeremy Bullock f15907
  std::wstring levelName = m_levelName.toStdWString();
Jeremy Bullock f15907
Jeremy Bullock f15907
  // level with the same name
Jeremy Bullock f15907
  TXshLevel *level_sameName = levelSet->getLevel(levelName);
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath levelFp = TFilePath(m_filePath) +
Jeremy Bullock f15907
                      TFilePath(levelName + L".." + m_fileType.toStdWString());
Jeremy Bullock f15907
Jeremy Bullock f15907
  // level with the same path
Jeremy Bullock f15907
  TXshLevel *level_samePath = levelSet->getLevel(*(currentScene), levelFp);
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath actualLevelFp = currentScene->decodeFilePath(levelFp);
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (level_sameName && level_samePath && level_sameName == level_samePath) {
Jeremy Bullock f15907
    TXshSimpleLevelP m_sl;
Jeremy Bullock f15907
    m_sl               = dynamic_cast<txshsimplelevel *="">(level_sameName);</txshsimplelevel>
Jeremy Bullock f15907
    bool isRasterLevel = m_sl && (m_sl->getType() == OVL_XSHLEVEL);
Jeremy Bullock f15907
    if (isRasterLevel) {
Jeremy Bullock f15907
      int currSubsampling = m_sl->getProperties()->getSubsampling();
Jeremy Bullock f15907
      m_subsampling       = currSubsampling;
Jeremy Bullock f15907
      emit(subsamplingChanged(m_subsampling));
Jeremy Bullock f15907
    } else
Jeremy Bullock f15907
      emit(subsamplingChanged(-1));
Jeremy Bullock f15907
  } else
Jeremy Bullock f15907
    emit(subsamplingChanged(-1));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
justburner d63640
void StopMotion::setPlayCaptureSound(bool on) {
justburner d63640
  m_playCaptureSound         = on;
justburner d63640
  StopMotionPlayCaptureSound = on;
justburner d63640
  emit(playCaptureSignal(on));
justburner d63640
}
justburner d63640
justburner d63640
//-----------------------------------------------------------------------------
justburner d63640
Jeremy Bullock f15907
void StopMotion::update() { getSubsampling(); }
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setSubsampling() {
Jeremy Bullock f15907
  ToonzScene *currentScene = TApp::instance()->getCurrentScene()->getScene();
Jeremy Bullock f15907
  TLevelSet *levelSet      = currentScene->getLevelSet();
Jeremy Bullock f15907
Jeremy Bullock f15907
  std::wstring levelName = m_levelName.toStdWString();
Jeremy Bullock f15907
Jeremy Bullock f15907
  // level with the same name
Jeremy Bullock f15907
  TXshLevel *level_sameName = levelSet->getLevel(levelName);
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath levelFp = TFilePath(m_filePath) +
Jeremy Bullock f15907
                      TFilePath(levelName + L".." + m_fileType.toStdWString());
Jeremy Bullock f15907
Jeremy Bullock f15907
  // level with the same path
Jeremy Bullock f15907
  TXshLevel *level_samePath = levelSet->getLevel(*(currentScene), levelFp);
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath actualLevelFp = currentScene->decodeFilePath(levelFp);
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (level_sameName && level_samePath && level_sameName == level_samePath) {
Jeremy Bullock f15907
    TXshSimpleLevelP m_sl;
Jeremy Bullock f15907
    m_sl               = dynamic_cast<txshsimplelevel *="">(level_sameName);</txshsimplelevel>
Jeremy Bullock f15907
    bool isRasterLevel = m_sl && (m_sl->getType() & RASTER_TYPE);
Jeremy Bullock f15907
    if (isRasterLevel) {
Jeremy Bullock f15907
      int currSubsampling = m_sl->getProperties()->getSubsampling();
Jeremy Bullock f15907
      int newSubsampling  = m_subsampling;
Jeremy Bullock f15907
      if (currSubsampling != newSubsampling) {
Jeremy Bullock f15907
        m_sl->getProperties()->setSubsampling(newSubsampling);
Jeremy Bullock f15907
        m_sl->invalidateFrames();
Jeremy Bullock f15907
        TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Jeremy Bullock f15907
        TApp::instance()
Jeremy Bullock f15907
            ->getCurrentXsheet()
Jeremy Bullock f15907
            ->getXsheet()
Jeremy Bullock f15907
            ->getStageObjectTree()
Jeremy Bullock f15907
            ->invalidateAll();
Jeremy Bullock f15907
        TApp::instance()->getCurrentLevel()->notifyLevelChange();
Jeremy Bullock f15907
        emit(subsamplingChanged(m_subsampling));
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::onTimeout() {
Jeremy Bullock f15907
  int currentFrame = TApp::instance()->getCurrentFrame()->getFrame();
shun-iwasawa 31accf
shun-iwasawa 31accf
  if ((m_liveViewStatus > LiveViewClosed && m_liveViewStatus < LiveViewPaused &&
shun-iwasawa 31accf
       !TApp::instance()->getCurrentFrame()->isPlaying()) ||
shun-iwasawa 31accf
      (m_liveViewStatus == LiveViewPaused && !m_userCalledPause)) {
shun-iwasawa 31accf
    if (getAlwaysLiveView() || (currentFrame >= m_xSheetFrameNumber - 2)) {
shun-iwasawa 31accf
      if (!m_usingWebcam) {
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
        bool success = m_canon->downloadEVFData();
shun-iwasawa 31accf
        if (success) {
shun-iwasawa 31accf
          setLiveViewImage();
shun-iwasawa 31accf
        } else {
shun-iwasawa 31accf
          m_hasLiveViewImage = false;
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
      } else {
shun-iwasawa 31accf
        bool success = m_webcam->getWebcamImage(m_liveViewImage);
shun-iwasawa 31accf
        if (success) {
shun-iwasawa 31accf
          setLiveViewImage();
shun-iwasawa 31accf
        } else {
shun-iwasawa 31accf
          m_hasLiveViewImage = false;
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if ((!getAlwaysLiveView() &&
shun-iwasawa 31accf
           !(currentFrame >= m_xSheetFrameNumber - 2)) ||
shun-iwasawa 31accf
          m_canon->m_pickLiveViewZoom) {
Jeremy Bullock f15907
        m_showLineUpImage = false;
Jeremy Bullock f15907
      } else {
Jeremy Bullock f15907
        m_showLineUpImage = true;
Jeremy Bullock f15907
      }
shun-iwasawa 31accf
    } else if (m_liveViewStatus == LiveViewOpen) {
shun-iwasawa 31accf
      m_liveViewStatus = LiveViewPaused;
Jeremy Bullock f15907
      TApp::instance()->getCurrentScene()->notifySceneChanged();
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
  //  else if (m_liveViewStatus == LiveViewPaused && !m_userCalledPause) {
shun-iwasawa 31accf
  //    if (getAlwaysLiveView() || (currentFrame == m_xSheetFrameNumber - 1)) {
shun-iwasawa 31accf
  //      if (!m_usingWebcam) {
shun-iwasawa 31accf
  //#ifdef WITH_CANON
shun-iwasawa 31accf
  //        bool success = m_canon->downloadEVFData();
shun-iwasawa 31accf
  //        if (success) {
shun-iwasawa 31accf
  //          setLiveViewImage();
shun-iwasawa 31accf
  //        } else {
shun-iwasawa 31accf
  //          m_hasLiveViewImage = false;
shun-iwasawa 31accf
  //        }
shun-iwasawa 31accf
  //#endif
shun-iwasawa 31accf
  //      } else {
shun-iwasawa 31accf
  //        bool success = m_webcam->getWebcamImage(m_liveViewImage);
shun-iwasawa 31accf
  //        if (success) {
shun-iwasawa 31accf
  //          setLiveViewImage();
shun-iwasawa 31accf
  //        } else {
shun-iwasawa 31accf
  //          m_hasLiveViewImage = false;
shun-iwasawa 31accf
  //        }
shun-iwasawa 31accf
  //      }
shun-iwasawa 31accf
  //    }
shun-iwasawa 31accf
  //  }
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
void StopMotion::setLiveViewImage() {
shun-iwasawa 31accf
  m_hasLiveViewImage = true;
shun-iwasawa 31accf
shun-iwasawa 31accf
  // make sure not to set to LiveViewOpen if it has been turned off
shun-iwasawa 31accf
  if (m_liveViewStatus > LiveViewClosed && !m_userCalledPause) {
shun-iwasawa 31accf
    m_liveViewStatus = LiveViewOpen;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (m_liveViewDpi.x == 0.0 || m_liveViewImageDimensions.lx == 0) {
shun-iwasawa 31accf
    TCamera *camera =
shun-iwasawa 31accf
        TApp::instance()->getCurrentScene()->getScene()->getCurrentCamera();
shun-iwasawa 31accf
    TDimensionD size = camera->getSize();
shun-iwasawa 31accf
    m_liveViewImageDimensions =
shun-iwasawa 31accf
        TDimension(m_liveViewImage->getLx(), m_liveViewImage->getLy());
shun-iwasawa 31accf
    double minimumDpi = std::min(m_liveViewImageDimensions.lx / size.lx,
shun-iwasawa 31accf
                                 m_liveViewImageDimensions.ly / size.ly);
shun-iwasawa 6bac0f
    m_liveViewDpi     = TPointD(minimumDpi, minimumDpi);
shun-iwasawa 31accf
shun-iwasawa 31accf
    if (!m_usingWebcam) {
shun-iwasawa 6bac0f
      minimumDpi     = std::min(m_fullImageDimensions.lx / size.lx,
shun-iwasawa 31accf
                            m_fullImageDimensions.ly / size.ly);
shun-iwasawa 31accf
      m_fullImageDpi = TPointD(minimumDpi, minimumDpi);
shun-iwasawa 31accf
    } else {
shun-iwasawa 31accf
      m_fullImageDimensions = m_liveViewImageDimensions;
shun-iwasawa 31accf
      m_fullImageDpi        = m_liveViewDpi;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
shun-iwasawa 31accf
    emit(newDimensions());
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  emit(newLiveViewImageReady());
shun-iwasawa 31accf
}
shun-iwasawa 31accf
//
shun-iwasawa 31accf
////-----------------------------------------------------------------------------
shun-iwasawa 31accf
//
shun-iwasawa 31accf
// void StopMotion::setLiveViewImage() {
shun-iwasawa 31accf
//    m_hasLiveViewImage = true;
shun-iwasawa 31accf
//    m_liveViewStatus = LiveViewOpen;
shun-iwasawa 31accf
//    if (m_hasLiveViewImage &&
shun-iwasawa 31accf
//        (m_liveViewDpi.x == 0.0 || m_liveViewImageDimensions.lx == 0)) {
shun-iwasawa 31accf
//        TCamera* camera =
shun-iwasawa 31accf
//            TApp::instance()->getCurrentScene()->getScene()->getCurrentCamera();
shun-iwasawa 31accf
//        TDimensionD size = camera->getSize();
shun-iwasawa 31accf
//        m_liveViewImageDimensions =
shun-iwasawa 31accf
//            TDimension(m_liveViewImage->getLx(), m_liveViewImage->getLy());
shun-iwasawa 31accf
//        double minimumDpi = std::min(m_liveViewImageDimensions.lx / size.lx,
shun-iwasawa 31accf
//            m_liveViewImageDimensions.ly / size.ly);
shun-iwasawa 31accf
//        m_liveViewDpi = TPointD(minimumDpi, minimumDpi);
shun-iwasawa 31accf
//
shun-iwasawa 31accf
//        m_fullImageDimensions = m_liveViewImageDimensions;
shun-iwasawa 31accf
//
shun-iwasawa 31accf
//        m_fullImageDpi = m_liveViewDpi;
shun-iwasawa 31accf
//
shun-iwasawa 31accf
//        emit(newDimensions());
shun-iwasawa 31accf
//    }
shun-iwasawa 31accf
//
shun-iwasawa 31accf
//    emit(newLiveViewImageReady());
shun-iwasawa 31accf
//}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
shun-iwasawa 31accf
Jeremy Bullock f15907
void StopMotion::onReviewTimeout() {
shun-iwasawa 31accf
  if (m_liveViewStatus > LiveViewClosed) {
shun-iwasawa 31accf
    m_liveViewStatus = LiveViewOpen;
Jeremy Bullock f15907
    m_timer->start(40);
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  TApp::instance()->getCurrentFrame()->setFrame(m_xSheetFrameNumber - 1);
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
bool StopMotion::importImage() {
Jeremy Bullock f15907
  TApp *app         = TApp::instance();
Jeremy Bullock f15907
  ToonzScene *scene = app->getCurrentScene()->getScene();
Jeremy Bullock f15907
  TXsheet *xsh      = scene->getXsheet();
Jeremy Bullock f15907
Jeremy Bullock f15907
  std::wstring levelName = m_levelName.toStdWString();
Jeremy Bullock f15907
  if (levelName.empty()) {
Jeremy Bullock f15907
    DVGui::error(
Jeremy Bullock f15907
        tr("No level name specified: please choose a valid level name"));
Jeremy Bullock f15907
    return false;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (m_usingWebcam) {
Jeremy Bullock f15907
    m_newImage = m_liveViewImage;
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  m_light->hideOverlays();
shun-iwasawa 31accf
Jeremy Bullock f15907
  int frameNumber = m_frameNumber;
Jeremy Bullock f15907
Jeremy Bullock f15907
  /* create parent directory if it does not exist */
Jeremy Bullock f15907
  TFilePath parentDir     = scene->decodeFilePath(TFilePath(m_filePath));
Jeremy Bullock f15907
  TFilePath fullResFolder = scene->decodeFilePath(
Jeremy Bullock f15907
      TFilePath(m_filePath) + TFilePath(levelName + L"_FullRes"));
Jeremy Bullock f15907
  TFilePath liveViewFolder = scene->decodeFilePath(
Jeremy Bullock f15907
      TFilePath(m_filePath) + TFilePath(levelName + L"_LiveView"));
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath levelFp = TFilePath(m_filePath) +
Jeremy Bullock f15907
                      TFilePath(levelName + L".." + m_fileType.toStdWString());
Jeremy Bullock f15907
  TFilePath actualLevelFp = scene->decodeFilePath(levelFp);
shun-iwasawa 31accf
  TFilePath actualFile(actualLevelFp.withFrame(frameNumber));
Jeremy Bullock f15907
  TFilePath fullResFp =
Jeremy Bullock f15907
      scene->decodeFilePath(fullResFolder + TFilePath(levelName + L"..jpg"));
Jeremy Bullock f15907
  TFilePath fullResFile(fullResFp.withFrame(frameNumber));
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath liveViewFp =
Jeremy Bullock f15907
      scene->decodeFilePath(liveViewFolder + TFilePath(levelName + L"..jpg"));
Jeremy Bullock f15907
  TFilePath liveViewFile(liveViewFp.withFrame(frameNumber));
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath tempFile = parentDir + "temp.jpg";
Jeremy Bullock f15907
Jeremy Bullock f15907
  TXshSimpleLevel *sl = 0;
Jeremy Bullock f15907
  TXshLevel *level    = scene->getLevelSet()->getLevel(levelName);
Jeremy Bullock f15907
  enum State { NEWLEVEL = 0, ADDFRAME, OVERWRITE } state;
Jeremy Bullock f15907
Jeremy Bullock f15907
  /* if the level already exists in the scene cast */
Jeremy Bullock f15907
  if (level) {
Jeremy Bullock f15907
    /* if the existing level is not a raster level, then return */
Jeremy Bullock f15907
    if (level->getType() != OVL_XSHLEVEL) {
Jeremy Bullock f15907
      DVGui::error(
Jeremy Bullock f15907
          tr("The level name specified is already used: please choose a "
Jeremy Bullock f15907
             "different level name."));
Jeremy Bullock f15907
      return false;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    /* if the existing level does not match file path and pixel size, then
Jeremy Bullock f15907
     * return */
Jeremy Bullock f15907
    sl = level->getSimpleLevel();
Jeremy Bullock f15907
    if (scene->decodeFilePath(sl->getPath()) != actualLevelFp) {
Jeremy Bullock f15907
      DVGui::error(
Jeremy Bullock f15907
          tr("The save in path specified does not match with the existing "
Jeremy Bullock f15907
             "level."));
Jeremy Bullock f15907
      return false;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    if (sl->getProperties()->getImageRes() !=
Jeremy Bullock f15907
        TDimension(m_newImage->getLx(), m_newImage->getLy())) {
Jeremy Bullock f15907
      DVGui::error(tr(
Jeremy Bullock f15907
          "The captured image size does not match with the existing level."));
Jeremy Bullock f15907
      return false;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    /* if the level already have the same frame, then ask if overwrite it */
Jeremy Bullock f15907
    TFilePath frameFp(actualLevelFp.withFrame(frameNumber));
Jeremy Bullock f15907
    if (TFileStatus(frameFp).doesExist()) {
Jeremy Bullock f15907
      QString question =
Jeremy Bullock f15907
          tr("File %1 already exists.\nDo you want to overwrite it?")
Jeremy Bullock f15907
              .arg(toQString(frameFp));
Jeremy Bullock f15907
      int ret = DVGui::MsgBox(question, QObject::tr("Overwrite"),
Jeremy Bullock f15907
                              QObject::tr("Cancel"));
Jeremy Bullock f15907
      if (ret == 0 || ret == 2) return false;
Jeremy Bullock f15907
      state = OVERWRITE;
Jeremy Bullock f15907
    } else
Jeremy Bullock f15907
      state = ADDFRAME;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  /* if the level does not exist in the scene cast */
Jeremy Bullock f15907
  else {
Jeremy Bullock f15907
    /* if the file does exist, load it first */
Jeremy Bullock f15907
    if (TSystem::doesExistFileOrLevel(actualLevelFp)) {
Jeremy Bullock f15907
      level = scene->loadLevel(actualLevelFp);
Jeremy Bullock f15907
      if (!level) {
Jeremy Bullock f15907
        DVGui::error(tr("Failed to load %1.").arg(toQString(actualLevelFp)));
Jeremy Bullock f15907
        return false;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
Jeremy Bullock f15907
      /* if the loaded level does not match in pixel size, then return */
Jeremy Bullock f15907
      sl = level->getSimpleLevel();
shun-iwasawa 6bac0f
      if (!sl || sl->getProperties()->getImageRes() !=
shun-iwasawa 6bac0f
                     TDimension(m_newImage->getLx(), m_newImage->getLy())) {
Jeremy Bullock f15907
        DVGui::error(
Jeremy Bullock f15907
            tr("The captured image size does not match with the existing "
Jeremy Bullock f15907
               "level."));
Jeremy Bullock f15907
        return false;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
Jeremy Bullock f15907
      /* confirm overwrite */
Jeremy Bullock f15907
      TFilePath frameFp(actualLevelFp.withFrame(frameNumber));
Jeremy Bullock f15907
      if (TFileStatus(frameFp).doesExist()) {
Jeremy Bullock f15907
        QString question =
Jeremy Bullock f15907
            tr("File %1 already exists.\nDo you want to overwrite it?")
Jeremy Bullock f15907
                .arg(toQString(frameFp));
Jeremy Bullock f15907
        int ret = DVGui::MsgBox(question, QObject::tr("Overwrite"),
Jeremy Bullock f15907
                                QObject::tr("Cancel"));
Jeremy Bullock f15907
        if (ret == 0 || ret == 2) return false;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    /* if the file does not exist, then create a new level */
Jeremy Bullock f15907
    else {
Jeremy Bullock f15907
      TXshLevel *level = scene->createNewLevel(OVL_XSHLEVEL, levelName,
Jeremy Bullock f15907
                                               TDimension(), 0, levelFp);
shun-iwasawa 6bac0f
      sl               = level->getSimpleLevel();
Jeremy Bullock f15907
      sl->setPath(levelFp, true);
Jeremy Bullock f15907
      sl->getProperties()->setDpiPolicy(LevelProperties::DP_CustomDpi);
Jeremy Bullock f15907
      TPointD dpi;
Jeremy Bullock f15907
      // Right now always set the dpi to scale to the camera width
Jeremy Bullock f15907
      if (Preferences::instance()->getPixelsOnly() && false)
Jeremy Bullock f15907
        dpi = getCurrentCameraDpi();
Jeremy Bullock f15907
      // Compute the dpi so that the image will fit
Jeremy Bullock f15907
      // to the camera frame
Jeremy Bullock f15907
      else {
Jeremy Bullock f15907
        TCamera *camera =
Jeremy Bullock f15907
            TApp::instance()->getCurrentScene()->getScene()->getCurrentCamera();
Jeremy Bullock f15907
        TDimensionD size  = camera->getSize();
Jeremy Bullock f15907
        double minimumDpi = std::min(m_newImage->getLx() / size.lx,
Jeremy Bullock f15907
                                     m_newImage->getLy() / size.ly);
shun-iwasawa 6bac0f
        dpi               = TPointD(minimumDpi, minimumDpi);
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      sl->getProperties()->setDpi(dpi.x);
Jeremy Bullock f15907
      sl->getProperties()->setImageDpi(dpi);
Jeremy Bullock f15907
      sl->getProperties()->setImageRes(
Jeremy Bullock f15907
          TDimension(m_newImage->getLx(), m_newImage->getLy()));
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
Jeremy Bullock f15907
    state = NEWLEVEL;
Jeremy Bullock f15907
    getSubsampling();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (!TFileStatus(parentDir).doesExist()) {
Jeremy Bullock f15907
    QString question;
Jeremy Bullock f15907
    question = tr("Folder %1 doesn't exist.\nDo you want to create it?")
Jeremy Bullock f15907
                   .arg(toQString(parentDir));
Jeremy Bullock f15907
    int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"));
Jeremy Bullock f15907
    if (ret == 0 || ret == 2) return false;
Jeremy Bullock f15907
    try {
Jeremy Bullock f15907
      TSystem::mkDir(parentDir);
Jeremy Bullock f15907
      DvDirModel::instance()->refreshFolder(parentDir.getParentDir());
Jeremy Bullock f15907
    } catch (...) {
Jeremy Bullock f15907
      DVGui::error(tr("Unable to create") + toQString(parentDir));
Jeremy Bullock f15907
      return false;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  if (!m_usingWebcam) {
Jeremy Bullock f15907
    if (!TFileStatus(fullResFolder).doesExist()) {
Jeremy Bullock f15907
      try {
Jeremy Bullock f15907
        TSystem::mkDir(fullResFolder);
Jeremy Bullock f15907
        DvDirModel::instance()->refreshFolder(fullResFolder.getParentDir());
Jeremy Bullock f15907
      } catch (...) {
Jeremy Bullock f15907
        DVGui::error(tr("Unable to create") + toQString(fullResFolder));
Jeremy Bullock f15907
        return false;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    if (!TFileStatus(liveViewFolder).doesExist()) {
Jeremy Bullock f15907
      try {
Jeremy Bullock f15907
        TSystem::mkDir(liveViewFolder);
Jeremy Bullock f15907
        DvDirModel::instance()->refreshFolder(liveViewFolder.getParentDir());
Jeremy Bullock f15907
      } catch (...) {
Jeremy Bullock f15907
        DVGui::error(tr("Unable to create") + toQString(liveViewFolder));
Jeremy Bullock f15907
        return false;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  // move the temp file
Jeremy Bullock f15907
  if (!m_usingWebcam) {
shun-iwasawa 31accf
    if (m_canon->m_useScaledImages) {
Jeremy Bullock f15907
      TSystem::copyFile(fullResFile, tempFile);
Jeremy Bullock f15907
      TSystem::deleteFile(tempFile);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    if (m_hasLineUpImage) {
shun-iwasawa 31accf
      JpgConverter::saveJpg(m_lineUpImage, liveViewFile);
shun-iwasawa 31accf
      // check the live view image map to see if there is already
shun-iwasawa 31accf
      // an image with this framenumber.  Overwrite if it exists
shun-iwasawa 31accf
      std::map<int, traster32p="">::iterator it;</int,>
shun-iwasawa 31accf
      it = m_liveViewImageMap.find(frameNumber);
shun-iwasawa 31accf
      if (it != m_liveViewImageMap.end()) {
shun-iwasawa 31accf
        m_liveViewImageMap.find(frameNumber)->second = m_lineUpImage;
shun-iwasawa 31accf
        return true;
shun-iwasawa 31accf
      } else {
shun-iwasawa 31accf
        m_liveViewImageMap.insert(
shun-iwasawa 31accf
            std::pair<int, traster32p="">(m_frameNumber, m_lineUpImage));</int,>
shun-iwasawa 31accf
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFrameId fid(frameNumber);
Jeremy Bullock f15907
  TPointD levelDpi = sl->getDpi();
Jeremy Bullock f15907
  /* create the raster */
Jeremy Bullock f15907
  TRaster32P raster = m_newImage;
Jeremy Bullock f15907
Jeremy Bullock f15907
  TRasterImageP ri(raster);
Jeremy Bullock f15907
  ri->setDpi(levelDpi.x, levelDpi.y);
Jeremy Bullock f15907
Jeremy Bullock f15907
  /* setting the frame */
Jeremy Bullock f15907
  sl->setFrame(fid, ri);
Jeremy Bullock f15907
Jeremy Bullock f15907
  /* set dirty flag */
Jeremy Bullock f15907
  sl->getProperties()->setDirtyFlag(true);
Jeremy Bullock f15907
  sl->getProperties()->setIsStopMotion(true);
Jeremy Bullock f15907
  sl->setIsReadOnly(true);
Jeremy Bullock f15907
Jeremy Bullock f15907
  // if (m_saveOnCaptureCB->isChecked()) sl->save();
Jeremy Bullock f15907
  // for now always save.  This can be tweaked later
Jeremy Bullock f15907
  sl->save();
shun-iwasawa 31accf
  m_sl = sl;
justburner d63640
  if (getReviewTimeDSec() > 0 && !m_isTimeLapse) {
shun-iwasawa 31accf
    m_liveViewStatus = LiveViewPaused;
justburner d63640
    m_reviewTimer->start(getReviewTimeDSec() * 100);
shun-iwasawa 31accf
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  /* placement in xsheet */
Jeremy Bullock f15907
  if (!getPlaceOnXSheet()) {
Jeremy Bullock f15907
    postImportProcess();
Jeremy Bullock f15907
    return true;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  int row = m_xSheetFrameNumber - 1;
Jeremy Bullock f15907
  int col = app->getCurrentColumn()->getColumnIndex();
Jeremy Bullock f15907
Jeremy Bullock f15907
  // if the level is newly created or imported, then insert a new column
Jeremy Bullock f15907
  if (state == NEWLEVEL) {
Jeremy Bullock f15907
    if (!xsh->isColumnEmpty(col)) {
Jeremy Bullock f15907
      col += 1;
Jeremy Bullock f15907
      xsh->insertColumn(col);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    xsh->insertCells(row, col);
Jeremy Bullock f15907
    xsh->setCell(row, col, TXshCell(sl, fid));
Jeremy Bullock f15907
    app->getCurrentColumn()->setColumnIndex(col);
justburner d63640
    if (getReviewTimeDSec() == 0 || m_isTimeLapse)
shun-iwasawa 31accf
      app->getCurrentFrame()->setFrame(row + 1);
Jeremy Bullock f15907
    m_xSheetFrameNumber = row + 2;
Jeremy Bullock f15907
    emit(xSheetFrameNumberChanged(m_xSheetFrameNumber));
Jeremy Bullock f15907
    postImportProcess();
Jeremy Bullock f15907
    // if (m_newImage->getLx() > 2000) {
Jeremy Bullock f15907
    //  m_subsampling = 4;
Jeremy Bullock f15907
    //  setSubsampling();
Jeremy Bullock f15907
    //}
Jeremy Bullock f15907
    return true;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  // state == OVERWRITE, ADDFRAME
Jeremy Bullock f15907
Jeremy Bullock f15907
  // if the same cell is already in the column, then just replace the content
Jeremy Bullock f15907
  // and do not set a new cell
Jeremy Bullock f15907
  int foundCol, foundRow = -1;
Jeremy Bullock f15907
  // most possibly, it's in the current column
Jeremy Bullock f15907
  int rowCheck;
Jeremy Bullock f15907
  if (findCell(xsh, col, TXshCell(sl, fid), rowCheck)) {
Jeremy Bullock f15907
    postImportProcess();
Jeremy Bullock f15907
    return true;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  if (rowCheck >= 0) {
Jeremy Bullock f15907
    foundRow = rowCheck;
Jeremy Bullock f15907
    foundCol = col;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  // search entire xsheet
Jeremy Bullock f15907
  for (int c = 0; c < xsh->getColumnCount(); c++) {
Jeremy Bullock f15907
    if (c == col) continue;
Jeremy Bullock f15907
    if (findCell(xsh, c, TXshCell(sl, fid), rowCheck)) {
Jeremy Bullock f15907
      postImportProcess();
Jeremy Bullock f15907
      return true;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    if (rowCheck >= 0) {
Jeremy Bullock f15907
      foundRow = rowCheck;
Jeremy Bullock f15907
      foundCol = c;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  // note found row represents the last row found that uses
Jeremy Bullock f15907
  // the active level
Jeremy Bullock f15907
Jeremy Bullock f15907
  // if there is a column containing the same level
Jeremy Bullock f15907
  if (foundRow >= 0) {
Jeremy Bullock f15907
    // put the cell at the bottom
Jeremy Bullock f15907
    xsh->insertCells(row, foundCol);
Jeremy Bullock f15907
    xsh->setCell(row, foundCol, TXshCell(sl, fid));
Jeremy Bullock f15907
    app->getCurrentColumn()->setColumnIndex(foundCol);
justburner d63640
    if (getReviewTimeDSec() == 0 || m_isTimeLapse)
shun-iwasawa 31accf
      app->getCurrentFrame()->setFrame(row + 1);
Jeremy Bullock f15907
    m_xSheetFrameNumber = row + 2;
Jeremy Bullock f15907
    emit(xSheetFrameNumberChanged(m_xSheetFrameNumber));
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  // if the level is registered in the scene, but is not placed in the xsheet,
Jeremy Bullock f15907
  // then insert a new column
Jeremy Bullock f15907
  else {
Jeremy Bullock f15907
    if (!xsh->isColumnEmpty(col)) {
Jeremy Bullock f15907
      col += 1;
Jeremy Bullock f15907
      xsh->insertColumn(col);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    xsh->setCell(row, col, TXshCell(sl, fid));
Jeremy Bullock f15907
    app->getCurrentColumn()->setColumnIndex(col);
justburner d63640
    if (getReviewTimeDSec() == 0 || m_isTimeLapse)
shun-iwasawa 31accf
      app->getCurrentFrame()->setFrame(row + 1);
Jeremy Bullock f15907
    m_xSheetFrameNumber = row + 2;
Jeremy Bullock f15907
    emit(xSheetFrameNumberChanged(m_xSheetFrameNumber));
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  postImportProcess();
Jeremy Bullock f15907
  return true;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::captureImage() {
justburner d63640
  if (m_playCaptureSound) {
justburner d63640
    m_camSnapSound->play();
justburner d63640
  }
shun-iwasawa 31accf
  if (m_isTimeLapse && !m_intervalStarted) {
shun-iwasawa 31accf
    startInterval();
shun-iwasawa 31accf
    return;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (m_isTimeLapse && m_intervalStarted && m_intervalTimer->isActive()) {
shun-iwasawa 31accf
    stopInterval();
shun-iwasawa 31accf
    return;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (!m_hasLiveViewImage || m_liveViewStatus != LiveViewOpen) {
shun-iwasawa 31accf
    DVGui::warning(tr("Cannot capture image unless live view is active."));
shun-iwasawa 31accf
    return;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  bool sessionOpen = false;
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  sessionOpen = m_canon->m_sessionOpen;
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
  if ((!m_usingWebcam && !sessionOpen) || m_userCalledPause) {
shun-iwasawa 2c27a4
    DVGui::warning(tr("Please start live view before capturing an image."));
Jeremy Bullock f15907
    return;
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
Jeremy Bullock f15907
  if (m_usingWebcam) {
shun-iwasawa 31accf
    captureWebcamImage();
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    captureDslrImage();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::captureWebcamImage() {
shun-iwasawa 31accf
  if (m_light->useOverlays()) {
shun-iwasawa 31accf
    m_light->showOverlays();
shun-iwasawa 31accf
    m_webcamOverlayTimer->start(500);
shun-iwasawa 31accf
  } else {
justburner d63640
    if (getReviewTimeDSec() > 0 && !m_isTimeLapse) {
Jeremy Bullock f15907
      m_timer->stop();
shun-iwasawa 31accf
      if (m_liveViewStatus > LiveViewClosed) {
shun-iwasawa 31accf
        // m_liveViewStatus = LiveViewPaused;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    m_lineUpImage    = m_liveViewImage;
Jeremy Bullock f15907
    m_hasLineUpImage = true;
Jeremy Bullock f15907
    emit(newLiveViewImageReady());
Jeremy Bullock f15907
    importImage();
Jeremy Bullock f15907
    return;
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
}
Jeremy Bullock f15907
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
shun-iwasawa 31accf
void StopMotion::captureWebcamOnTimeout() {
justburner d63640
  if (getReviewTimeDSec() > 0 && !m_isTimeLapse) {
shun-iwasawa 31accf
    m_timer->stop();
shun-iwasawa 31accf
    if (m_liveViewStatus > LiveViewClosed) {
shun-iwasawa 31accf
      // m_liveViewStatus = LiveViewPaused;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
  m_lineUpImage    = m_liveViewImage;
shun-iwasawa 31accf
  m_hasLineUpImage = true;
shun-iwasawa 31accf
  emit(newLiveViewImageReady());
shun-iwasawa 31accf
  importImage();
shun-iwasawa 31accf
  return;
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotion::captureDslrImage() {
shun-iwasawa 31accf
  m_light->showOverlays();
Jeremy Bullock f15907
justburner d63640
  if (getReviewTimeDSec() > 0 && !m_isTimeLapse) {
Jeremy Bullock f15907
    m_timer->stop();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
shun-iwasawa 31accf
  if (m_liveViewStatus > LiveViewClosed && !m_isTimeLapse) {
shun-iwasawa 31accf
    // m_liveViewStatus = LiveViewPaused;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (m_hasLiveViewImage) {
Jeremy Bullock f15907
    m_lineUpImage    = m_liveViewImage;
Jeremy Bullock f15907
    m_hasLineUpImage = true;
Jeremy Bullock f15907
    emit(newLiveViewImageReady());
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  TApp *app         = TApp::instance();
Jeremy Bullock f15907
  ToonzScene *scene = app->getCurrentScene()->getScene();
Jeremy Bullock f15907
Jeremy Bullock f15907
  int frameNumber        = m_frameNumber;
Jeremy Bullock f15907
  std::wstring levelName = m_levelName.toStdWString();
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath parentDir = scene->decodeFilePath(TFilePath(m_filePath));
Jeremy Bullock f15907
  TFilePath tempFile  = parentDir + "temp.jpg";
Jeremy Bullock f15907
Jeremy Bullock f15907
  if (!TFileStatus(parentDir).doesExist()) {
Jeremy Bullock f15907
    TSystem::mkDir(parentDir);
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  m_tempFile = tempFile.getQString();
Jeremy Bullock f15907
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  m_canon->takePicture();
Jeremy Bullock f15907
#endif
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::postImportProcess() {
shun-iwasawa 31accf
  saveXmlFile();
Jeremy Bullock f15907
  if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) {
Jeremy Bullock f15907
    int f = m_frameNumber;
Jeremy Bullock f15907
    if (f % 10 == 0)  // next number
Jeremy Bullock f15907
      m_frameNumber = ((int)(f / 10) + 1) * 10;
Jeremy Bullock f15907
    else  // next alphabet
Jeremy Bullock f15907
      m_frameNumber = f + 1;
Jeremy Bullock f15907
  } else
Jeremy Bullock f15907
    m_frameNumber += 1;
Jeremy Bullock f15907
  emit(frameNumberChanged(m_frameNumber));
Jeremy Bullock f15907
  /* notify */
Jeremy Bullock f15907
  refreshFrameInfo();
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (m_isTimeLapse && m_intervalStarted) restartInterval();
shun-iwasawa 31accf
Jeremy Bullock f15907
  TApp::instance()->getCurrentScene()->notifySceneChanged();
Jeremy Bullock f15907
  TApp::instance()->getCurrentScene()->notifyCastChange();
Jeremy Bullock f15907
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
void StopMotion::saveXmlFile() {
shun-iwasawa 31accf
  TApp *app         = TApp::instance();
shun-iwasawa 31accf
  ToonzScene *scene = app->getCurrentScene()->getScene();
shun-iwasawa 31accf
  TXsheet *xsh      = scene->getXsheet();
shun-iwasawa 31accf
shun-iwasawa 31accf
  std::wstring levelName = m_levelName.toStdWString();
shun-iwasawa 31accf
  TFilePath parentDir    = scene->decodeFilePath(TFilePath(m_filePath));
shun-iwasawa 31accf
  TFilePath tempFile     = parentDir + TFilePath(levelName + L".xml");
shun-iwasawa 31accf
  QString xmlFileName    = tempFile.getQString();
shun-iwasawa 31accf
  QFile xmlFile(xmlFileName);
shun-iwasawa 31accf
  xmlFile.open(QIODevice::WriteOnly);
shun-iwasawa 31accf
  QXmlStreamWriter xmlWriter(&xmlFile);
shun-iwasawa 31accf
  xmlWriter.setAutoFormatting(true);
shun-iwasawa 31accf
  xmlWriter.writeStartDocument();
shun-iwasawa 31accf
  xmlWriter.writeStartElement("body");
shun-iwasawa 31accf
  xmlWriter.writeStartElement("SceneInfo");
shun-iwasawa 31accf
  xmlWriter.writeTextElement("LevelName", QString::fromStdWString(levelName));
shun-iwasawa 31accf
  xmlWriter.writeTextElement("CurrentFrame",
shun-iwasawa 31accf
                             QString::number(m_xSheetFrameNumber));
shun-iwasawa 31accf
  xmlWriter.writeEndElement();
shun-iwasawa 31accf
shun-iwasawa 31accf
  xmlWriter.writeStartElement("CameraInfo");
shun-iwasawa 31accf
  if (m_usingWebcam) {
shun-iwasawa 31accf
    xmlWriter.writeTextElement("Webcam", "yes");
shun-iwasawa 31accf
    xmlWriter.writeTextElement("CameraName", m_webcam->getWebcamDescription());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("CameraResolutionX",
shun-iwasawa 31accf
                               QString::number(m_webcam->getWebcamWidth()));
shun-iwasawa 31accf
    xmlWriter.writeTextElement("CameraResolutionY",
shun-iwasawa 31accf
                               QString::number(m_webcam->getWebcamHeight()));
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    xmlWriter.writeTextElement("Webcam", "no");
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
    xmlWriter.writeTextElement("CameraName",
shun-iwasawa 31accf
                               QString::fromStdString(m_canon->m_cameraName));
shun-iwasawa 31accf
    xmlWriter.writeTextElement("Aperture", m_canon->getCurrentAperture());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("ShutterSpeed",
shun-iwasawa 31accf
                               m_canon->getCurrentShutterSpeed());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("ISO", m_canon->getCurrentIso());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("PictureStyle",
shun-iwasawa 31accf
                               m_canon->getCurrentPictureStyle());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("ImageQuality",
shun-iwasawa 31accf
                               m_canon->getCurrentImageQuality());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("WhiteBalance",
shun-iwasawa 31accf
                               m_canon->getCurrentWhiteBalance());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("ColorTemperature",
shun-iwasawa 31accf
                               m_canon->getCurrentColorTemperature());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("ExposureCompensation",
shun-iwasawa 31accf
                               m_canon->getCurrentExposureCompensation());
shun-iwasawa 31accf
    xmlWriter.writeTextElement("FocusCheckLocationX",
shun-iwasawa 31accf
                               QString::number(m_canon->m_finalZoomPoint.x));
shun-iwasawa 31accf
    xmlWriter.writeTextElement("FocusCheckLocationY",
shun-iwasawa 31accf
                               QString::number(m_canon->m_finalZoomPoint.y));
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  xmlWriter.writeEndElement();
shun-iwasawa 31accf
shun-iwasawa 31accf
  xmlWriter.writeStartElement("Images");
shun-iwasawa 31accf
  xmlWriter.writeTextElement("Frame", "Yes");
shun-iwasawa 31accf
  xmlWriter.writeEndElement();
shun-iwasawa 31accf
  xmlWriter.writeEndElement();
shun-iwasawa 31accf
  xmlWriter.writeEndDocument();
shun-iwasawa 31accf
  xmlFile.close();
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
bool StopMotion::loadXmlFile() {
shun-iwasawa 31accf
  TApp *app         = TApp::instance();
shun-iwasawa 31accf
  ToonzScene *scene = app->getCurrentScene()->getScene();
shun-iwasawa 31accf
  TXsheet *xsh      = scene->getXsheet();
shun-iwasawa 31accf
shun-iwasawa 31accf
  bool webcam      = false;
shun-iwasawa 31accf
  bool foundCamera = false;
shun-iwasawa 31accf
  QString text;
shun-iwasawa 31accf
  int x;
shun-iwasawa 31accf
  int y;
shun-iwasawa 31accf
shun-iwasawa 31accf
  std::wstring levelName = m_levelName.toStdWString();
shun-iwasawa 31accf
  TFilePath parentDir    = scene->decodeFilePath(TFilePath(m_filePath));
shun-iwasawa 31accf
  TFilePath tempFile     = parentDir + TFilePath(levelName + L".xml");
shun-iwasawa 31accf
  QString xmlFileName    = tempFile.getQString();
shun-iwasawa 31accf
  QFile xmlFile(xmlFileName);
shun-iwasawa 31accf
  if (!xmlFile.exists()) return false;
shun-iwasawa 31accf
  xmlFile.open(QIODevice::ReadOnly);
shun-iwasawa 31accf
shun-iwasawa 31accf
  QXmlStreamReader xmlReader;
shun-iwasawa 31accf
  xmlReader.setDevice(&xmlFile);
shun-iwasawa 31accf
  xmlReader.readNext();
shun-iwasawa 31accf
  while (!xmlReader.atEnd()) {
shun-iwasawa 31accf
    if (xmlReader.isStartElement()) {
shun-iwasawa 31accf
      if (xmlReader.name() == "Webcam") {
shun-iwasawa 6bac0f
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (text == "yes") webcam = true;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "CameraName") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (webcam) {
shun-iwasawa 31accf
          QList<qcamerainfo> cameras = QCameraInfo::availableCameras();</qcamerainfo>
shun-iwasawa 31accf
          if (cameras.size() > 0) {
shun-iwasawa 31accf
            for (int i = 0; i < cameras.size(); i++) {
shun-iwasawa 31accf
              if (cameras.at(i).description() == text) {
shun-iwasawa 31accf
                changeCameras(i + 1);
shun-iwasawa 31accf
                foundCamera = true;
shun-iwasawa 31accf
                break;
shun-iwasawa 31accf
              }
shun-iwasawa 31accf
            }
shun-iwasawa 31accf
          }
shun-iwasawa 31accf
        } else {
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
          QString camName = "";
shun-iwasawa 31accf
          if (m_canon->getCameraCount() > 0) {
shun-iwasawa 31accf
            m_canon->openCameraSession();
shun-iwasawa 31accf
            camName = QString::fromStdString(m_canon->getCameraName());
shun-iwasawa 31accf
            m_canon->closeCameraSession();
shun-iwasawa 31accf
          }
shun-iwasawa 31accf
          if (text == camName) {
shun-iwasawa 31accf
            changeCameras(-1);
shun-iwasawa 31accf
            foundCamera = true;
shun-iwasawa 31accf
          }
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "CameraResolutionX") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        x    = text.toInt();
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "CameraResolutionY") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        y    = text.toInt();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == true) {
shun-iwasawa 31accf
          setWebcamResolution(
shun-iwasawa 31accf
              QString(QString::number(x) + " x " + QString::number(y)));
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
      if (xmlReader.name() == "Aperture") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setAperture(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "ShutterSpeed") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setShutterSpeed(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "ISO") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setIso(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "PictureStyle") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setPictureStyle(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "ImageQuality") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setImageQuality(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "WhiteBalance") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setWhiteBalance(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "ColorTemperature") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setColorTemperature(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "ExposureCompensation") {
shun-iwasawa 31accf
        text = xmlReader.readElementText();
shun-iwasawa 31accf
        if (foundCamera == true && webcam == false) {
shun-iwasawa 31accf
          m_canon->setExposureCompensation(text);
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "FocusCheckLocationX") {
shun-iwasawa 31accf
        text                        = xmlReader.readElementText();
shun-iwasawa 31accf
        m_canon->m_finalZoomPoint.x = text.toInt();
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
      if (xmlReader.name() == "FocusCheckLocationY") {
shun-iwasawa 31accf
        text                        = xmlReader.readElementText();
shun-iwasawa 31accf
        m_canon->m_finalZoomPoint.y = text.toInt();
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    xmlReader.readNext();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  return true;
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
bool StopMotion::exportImageSequence() {
shun-iwasawa 31accf
  TApp *app         = TApp::instance();
shun-iwasawa 31accf
  ToonzScene *scene = app->getCurrentScene()->getScene();
shun-iwasawa 31accf
  TXsheet *xsh      = scene->getXsheet();
shun-iwasawa 31accf
shun-iwasawa 31accf
  std::wstring levelName = m_levelName.toStdWString();
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (levelName.empty()) {
shun-iwasawa 31accf
    DVGui::error(
shun-iwasawa 31accf
        tr("No level name specified: please choose a valid level name"));
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  int frameNumber = m_frameNumber;
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath parentDir     = scene->decodeFilePath(TFilePath(m_filePath));
shun-iwasawa 31accf
  TFilePath fullResFolder = scene->decodeFilePath(
shun-iwasawa 31accf
      TFilePath(m_filePath) + TFilePath(levelName + L"_FullRes"));
shun-iwasawa 31accf
  TFilePath liveViewFolder = scene->decodeFilePath(
shun-iwasawa 31accf
      TFilePath(m_filePath) + TFilePath(levelName + L"_LiveView"));
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath levelFp = TFilePath(m_filePath) +
shun-iwasawa 31accf
                      TFilePath(levelName + L".." + m_fileType.toStdWString());
shun-iwasawa 31accf
  TFilePath actualLevelFp = scene->decodeFilePath(levelFp);
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath fullResFp =
shun-iwasawa 31accf
      scene->decodeFilePath(fullResFolder + TFilePath(levelName + L"..jpg"));
shun-iwasawa 31accf
  TFilePath fullResFile(fullResFp.withFrame(frameNumber));
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath liveViewFp =
shun-iwasawa 31accf
      scene->decodeFilePath(liveViewFolder + TFilePath(levelName + L"..jpg"));
shun-iwasawa 31accf
  TFilePath liveViewFile(liveViewFp.withFrame(frameNumber));
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath tempFile = parentDir + "temp.jpg";
shun-iwasawa 31accf
shun-iwasawa 31accf
  TXshSimpleLevel *sl = 0;
shun-iwasawa 31accf
  TXshLevel *level    = scene->getLevelSet()->getLevel(levelName);
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (level == NULL) {
shun-iwasawa 31accf
    DVGui::error(tr("No level exists with the current name."));
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  /* if the existing level is not a raster level, then return */
shun-iwasawa 31accf
  if (level->getType() != OVL_XSHLEVEL) {
shun-iwasawa 31accf
    DVGui::error(tr("This is not an image level."));
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (!level->getSimpleLevel()->getProperties()->isStopMotionLevel()) {
shun-iwasawa 31accf
    DVGui::error(tr("This is not a stop motion level."));
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  sl = level->getSimpleLevel();
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (scene->decodeFilePath(sl->getPath()) != actualLevelFp) {
shun-iwasawa 31accf
    DVGui::error(
shun-iwasawa 31accf
        tr("The save in path specified does not match with the existing "
shun-iwasawa 31accf
           "level."));
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  // find which column the level is on.
shun-iwasawa 31accf
  // check with the first column
shun-iwasawa 31accf
  int col = TApp::instance()->getCurrentColumn()->getColumnIndex();
shun-iwasawa 31accf
  int r0, r1, row;
shun-iwasawa 31accf
  xsh->getColumn(col)->getRange(r0, r1);
shun-iwasawa 31accf
  TXshSimpleLevel *colLevel = xsh->getCell(r0, col).getSimpleLevel();
shun-iwasawa 31accf
  if (colLevel != sl) {
shun-iwasawa 31accf
    int cols = xsh->getColumnCount();
shun-iwasawa 31accf
    for (int i = 0; i < cols; i++) {
shun-iwasawa 31accf
      xsh->getColumn(col)->getRange(r0, r1);
shun-iwasawa 31accf
      colLevel = xsh->getCell(r0, col).getSimpleLevel();
shun-iwasawa 31accf
      if (colLevel == sl) {
shun-iwasawa 31accf
        col = i;
shun-iwasawa 31accf
        break;
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    DVGui::error(tr("Could not find an xsheet level with  the current level"));
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  row = r0;
shun-iwasawa 31accf
  xsh->getColumn(col)->getLevelRange(row, r0, r1);
shun-iwasawa 31accf
shun-iwasawa 31accf
  GenericSaveFilePopup *m_saveSequencePopup =
shun-iwasawa 31accf
      new GenericSaveFilePopup("Export Image Sequence");
shun-iwasawa 31accf
  m_saveSequencePopup->setFileMode(true);
shun-iwasawa 31accf
  TFilePath fp = m_saveSequencePopup->getPath();
shun-iwasawa 31accf
  if (fp == TFilePath()) {
shun-iwasawa 31accf
    DVGui::error(tr("No export path given."));
shun-iwasawa 31accf
    return false;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  TFilePath sourceFile;
shun-iwasawa 31accf
  TFilePath exportFilePath =
shun-iwasawa 31accf
      scene->decodeFilePath(fp + TFilePath(levelName + L"..jpg"));
shun-iwasawa 31accf
  TFilePath exportFile;
shun-iwasawa 31accf
  int exportFrameNumber = 1;
shun-iwasawa 31accf
  for (int i = r0; i <= r1; i++) {
shun-iwasawa 31accf
    int cellNumber = xsh->getCell(i, col).getFrameId().getNumber();
shun-iwasawa 31accf
    fullResFile    = fullResFp.withFrame(cellNumber);
shun-iwasawa 31accf
    if (TFileStatus(fullResFile).doesExist()) {
shun-iwasawa 31accf
      sourceFile = fullResFile;
shun-iwasawa 31accf
    } else {
shun-iwasawa 31accf
      sourceFile = actualLevelFp.withFrame(cellNumber);
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
shun-iwasawa 31accf
    if (!TFileStatus(sourceFile).doesExist()) {
shun-iwasawa 31accf
      DVGui::error(tr("Could not find the source file."));
shun-iwasawa 31accf
      return false;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    exportFile = exportFilePath.withFrame(exportFrameNumber);
shun-iwasawa 31accf
    if (TFileStatus(exportFile).doesExist()) {
shun-iwasawa 31accf
      QString question = tr("Overwrite existing files?");
shun-iwasawa 31accf
      int ret          = DVGui::MsgBox(question, QObject::tr("Overwrite"),
shun-iwasawa 31accf
                              QObject::tr("Cancel"));
shun-iwasawa 31accf
      if (ret == 0 || ret == 2) return false;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    TSystem::copyFile(exportFile, sourceFile);
shun-iwasawa 31accf
    exportFrameNumber++;
shun-iwasawa 31accf
    if (!TFileStatus(exportFile).doesExist()) {
shun-iwasawa 31accf
      DVGui::error(tr("An error occurred.  Aborting."));
shun-iwasawa 31accf
      return false;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa c7f5f4
  QString msg = tr("Successfully exported %1 images.")
shun-iwasawa c7f5f4
                    .arg(QString::number(exportFrameNumber - 1));
shun-iwasawa c7f5f4
  DVGui::MsgBoxInPopup(DVGui::MsgType(DVGui::INFORMATION), msg);
shun-iwasawa 31accf
  return true;
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
// Refresh information that how many & which frames are saved for the current
shun-iwasawa 31accf
// level
shun-iwasawa 31accf
void StopMotion::refreshFrameInfo() {
shun-iwasawa 31accf
  bool sessionOpen = false;
shun-iwasawa 31accf
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  sessionOpen = m_canon->m_sessionOpen;
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
shun-iwasawa 31accf
  if ((!sessionOpen && m_liveViewStatus < LiveViewOpen) && !m_usingWebcam) {
Jeremy Bullock f15907
    m_frameInfoText = "";
Jeremy Bullock f15907
    return;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  QString tooltipStr, labelStr;
Jeremy Bullock f15907
  enum InfoType { NEW = 0, ADD, OVERWRITE, WARNING } infoType(WARNING);
Jeremy Bullock f15907
Jeremy Bullock f15907
  static QColor infoColors[4] = {Qt::cyan, Qt::green, Qt::yellow, Qt::red};
Jeremy Bullock f15907
Jeremy Bullock f15907
  ToonzScene *currentScene = TApp::instance()->getCurrentScene()->getScene();
Jeremy Bullock f15907
  TLevelSet *levelSet      = currentScene->getLevelSet();
Jeremy Bullock f15907
Jeremy Bullock f15907
  std::wstring levelName = m_levelName.toStdWString();
Jeremy Bullock f15907
  int frameNumber        = m_frameNumber;
Jeremy Bullock f15907
Jeremy Bullock f15907
  TDimension stopMotionRes;
shun-iwasawa 6bac0f
  bool checkRes = true;
shun-iwasawa 31accf
  if (m_usingWebcam) stopMotionRes = m_liveViewImageDimensions;
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  else if (m_canon->m_useScaledImages ||
shun-iwasawa 31accf
           !m_canon->getCurrentImageQuality().contains("Large")) {
shun-iwasawa 31accf
    stopMotionRes = m_canon->m_proxyImageDimensions;
shun-iwasawa 31accf
    if (m_canon->m_proxyImageDimensions == TDimension(0, 0)) {
Jeremy Bullock f15907
      checkRes = false;
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
  else
Jeremy Bullock f15907
    stopMotionRes = m_fullImageDimensions;
Jeremy Bullock f15907
Jeremy Bullock f15907
  bool letterOptionEnabled =
Jeremy Bullock f15907
      Preferences::instance()->isShowFrameNumberWithLettersEnabled();
Jeremy Bullock f15907
Jeremy Bullock f15907
  // level with the same name
Jeremy Bullock f15907
  TXshLevel *level_sameName = levelSet->getLevel(levelName);
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath levelFp = TFilePath(m_filePath) +
Jeremy Bullock f15907
                      TFilePath(levelName + L".." + m_fileType.toStdWString());
Jeremy Bullock f15907
Jeremy Bullock f15907
  // level with the same path
Jeremy Bullock f15907
  TXshLevel *level_samePath = levelSet->getLevel(*(currentScene), levelFp);
Jeremy Bullock f15907
Jeremy Bullock f15907
  TFilePath actualLevelFp = currentScene->decodeFilePath(levelFp);
Jeremy Bullock f15907
Jeremy Bullock f15907
  // level existence
Jeremy Bullock f15907
  bool levelExist = TSystem::doesExistFileOrLevel(actualLevelFp);
Jeremy Bullock f15907
Jeremy Bullock f15907
  // frame existence
Jeremy Bullock f15907
  TFilePath frameFp(actualLevelFp.withFrame(frameNumber));
shun-iwasawa 6bac0f
  bool frameExist = false;
Jeremy Bullock f15907
  if (levelExist) frameExist = TFileStatus(frameFp).doesExist();
Jeremy Bullock f15907
Jeremy Bullock f15907
  // reset acceptable camera size
Jeremy Bullock f15907
  m_allowedCameraSize = QSize();
Jeremy Bullock f15907
Jeremy Bullock f15907
  // ### CASE 1 ###
Jeremy Bullock f15907
  // If there is no same level registered in the scene cast
Jeremy Bullock f15907
  if (!level_sameName && !level_samePath) {
Jeremy Bullock f15907
    // If there is a level in the file system
Jeremy Bullock f15907
    if (levelExist) {
Jeremy Bullock f15907
      TLevelReaderP lr;
Jeremy Bullock f15907
      TLevelP level_p;
Jeremy Bullock f15907
      try {
Jeremy Bullock f15907
        lr = TLevelReaderP(actualLevelFp);
Jeremy Bullock f15907
      } catch (...) {
Jeremy Bullock f15907
        // TODO: output something
Jeremy Bullock f15907
        m_frameInfoText = tr("UNDEFINED WARNING");
Jeremy Bullock f15907
        return;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      if (!lr) {
Jeremy Bullock f15907
        // TODO: output something
Jeremy Bullock f15907
        m_frameInfoText = tr("UNDEFINED WARNING");
Jeremy Bullock f15907
        return;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      try {
Jeremy Bullock f15907
        level_p = lr->loadInfo();
Jeremy Bullock f15907
      } catch (...) {
Jeremy Bullock f15907
        // TODO: output something
Jeremy Bullock f15907
        m_frameInfoText = tr("UNDEFINED WARNING");
Jeremy Bullock f15907
        return;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      if (!level_p) {
Jeremy Bullock f15907
        // TODO: output something
Jeremy Bullock f15907
        m_frameInfoText = tr("UNDEFINED WARNING");
Jeremy Bullock f15907
        return;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      int frameCount      = level_p->getFrameCount();
Jeremy Bullock f15907
      TLevel::Iterator it = level_p->begin();
Jeremy Bullock f15907
      std::vector<tframeid> fids;</tframeid>
Jeremy Bullock f15907
      for (int i = 0; it != level_p->end(); ++it, ++i)
Jeremy Bullock f15907
        fids.push_back(it->first);
Jeremy Bullock f15907
Jeremy Bullock f15907
      tooltipStr +=
Jeremy Bullock f15907
          tr("The level is not registered in the scene, but exists in the file "
Jeremy Bullock f15907
             "system.");
Jeremy Bullock f15907
Jeremy Bullock f15907
      // check resolution
Jeremy Bullock f15907
      const TImageInfo *ii;
Jeremy Bullock f15907
      try {
Jeremy Bullock f15907
        ii = lr->getImageInfo(fids[0]);
Jeremy Bullock f15907
      } catch (...) {
Jeremy Bullock f15907
        // TODO: output something
Jeremy Bullock f15907
        m_frameInfoText = tr("UNDEFINED WARNING");
Jeremy Bullock f15907
        return;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      TDimension dim(ii->m_lx, ii->m_ly);
Jeremy Bullock f15907
      // if the saved images has not the same resolution as the current camera
Jeremy Bullock f15907
      // resolution
Jeremy Bullock f15907
      if (checkRes && m_hasLiveViewImage && stopMotionRes != dim) {
Jeremy Bullock f15907
        tooltipStr += tr("\nWARNING : Image size mismatch. The saved image "
Jeremy Bullock f15907
                         "size is %1 x %2.")
Jeremy Bullock f15907
                          .arg(dim.lx)
Jeremy Bullock f15907
                          .arg(dim.ly);
Jeremy Bullock f15907
        labelStr += tr("WARNING ");
Jeremy Bullock f15907
        infoType = WARNING;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      // if the resolutions are matched
Jeremy Bullock f15907
      {
Jeremy Bullock f15907
        if (frameCount == 1)
Jeremy Bullock f15907
          tooltipStr += tr("\nFrame %1 exists.")
Jeremy Bullock f15907
                            .arg(fidsToString(fids, letterOptionEnabled));
Jeremy Bullock f15907
        else
Jeremy Bullock f15907
          tooltipStr += tr("\nFrames %1 exist.")
Jeremy Bullock f15907
                            .arg(fidsToString(fids, letterOptionEnabled));
Jeremy Bullock f15907
        // if the frame exists, then it will be overwritten
Jeremy Bullock f15907
        if (frameExist) {
Jeremy Bullock f15907
          labelStr += tr("OVERWRITE 1 of");
Jeremy Bullock f15907
          infoType = OVERWRITE;
Jeremy Bullock f15907
        } else {
Jeremy Bullock f15907
          labelStr += tr("ADD to");
Jeremy Bullock f15907
          infoType = ADD;
Jeremy Bullock f15907
        }
Jeremy Bullock f15907
        if (frameCount == 1)
Jeremy Bullock f15907
          labelStr += tr(" %1 frame").arg(frameCount);
Jeremy Bullock f15907
        else
Jeremy Bullock f15907
          labelStr += tr(" %1 frames").arg(frameCount);
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      m_allowedCameraSize = QSize(dim.lx, dim.ly);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    // If no level exists in the file system, then it will be a new level
Jeremy Bullock f15907
    else {
Jeremy Bullock f15907
      tooltipStr += tr("The level will be newly created.");
Jeremy Bullock f15907
      labelStr += tr("NEW");
Jeremy Bullock f15907
      infoType = NEW;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  // ### CASE 2 ###
Jeremy Bullock f15907
  // If there is already the level registered in the scene cast
Jeremy Bullock f15907
  else if (level_sameName && level_samePath &&
Jeremy Bullock f15907
           level_sameName == level_samePath) {
Jeremy Bullock f15907
    tooltipStr += tr("The level is already registered in the scene.");
Jeremy Bullock f15907
    if (!levelExist) tooltipStr += tr("\nNOTE : The level is not saved.");
Jeremy Bullock f15907
Jeremy Bullock f15907
    std::vector<tframeid> fids;</tframeid>
Jeremy Bullock f15907
    level_sameName->getFids(fids);
Jeremy Bullock f15907
Jeremy Bullock f15907
    // check resolution
Jeremy Bullock f15907
    TDimension dim;
Jeremy Bullock f15907
    bool ret = getRasterLevelSize(level_sameName, dim);
Jeremy Bullock f15907
    if (!ret) {
Jeremy Bullock f15907
      tooltipStr +=
Jeremy Bullock f15907
          tr("\nWARNING : Failed to get image size of the existing level %1.")
Jeremy Bullock f15907
              .arg(QString::fromStdWString(levelName));
Jeremy Bullock f15907
      labelStr += tr("WARNING ");
Jeremy Bullock f15907
      infoType = WARNING;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    // if the saved images has not the same resolution as the current camera
Jeremy Bullock f15907
    // resolution
Jeremy Bullock f15907
    else if (checkRes && m_hasLiveViewImage && stopMotionRes != dim) {
Jeremy Bullock f15907
      tooltipStr += tr("\nWARNING : Image size mismatch. The existing level "
Jeremy Bullock f15907
                       "size is %1 x %2.")
Jeremy Bullock f15907
                        .arg(dim.lx)
Jeremy Bullock f15907
                        .arg(dim.ly);
Jeremy Bullock f15907
      labelStr += tr("WARNING ");
Jeremy Bullock f15907
      infoType = WARNING;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    // if the resolutions are matched
Jeremy Bullock f15907
    {
Jeremy Bullock f15907
      int frameCount = fids.size();
Jeremy Bullock f15907
      if (fids.size() == 1)
Jeremy Bullock f15907
        tooltipStr += tr("\nFrame %1 exists.")
Jeremy Bullock f15907
                          .arg(fidsToString(fids, letterOptionEnabled));
Jeremy Bullock f15907
      else
Jeremy Bullock f15907
        tooltipStr += tr("\nFrames %1 exist.")
Jeremy Bullock f15907
                          .arg(fidsToString(fids, letterOptionEnabled));
Jeremy Bullock f15907
      // Check if the target frame already exist in the level
Jeremy Bullock f15907
      bool hasFrame = false;
Jeremy Bullock f15907
      for (int f = 0; f < frameCount; f++) {
Jeremy Bullock f15907
        if (fids.at(f).getNumber() == frameNumber) {
Jeremy Bullock f15907
          hasFrame = true;
Jeremy Bullock f15907
          break;
Jeremy Bullock f15907
        }
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      // If there is already the frame then it will be overwritten
Jeremy Bullock f15907
      if (hasFrame) {
Jeremy Bullock f15907
        labelStr += tr("OVERWRITE 1 of");
Jeremy Bullock f15907
        infoType = OVERWRITE;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      // Or, the frame will be added to the level
Jeremy Bullock f15907
      else {
Jeremy Bullock f15907
        labelStr += tr("ADD to");
Jeremy Bullock f15907
        infoType = ADD;
Jeremy Bullock f15907
      }
Jeremy Bullock f15907
      if (frameCount == 1)
Jeremy Bullock f15907
        labelStr += tr(" %1 frame").arg(frameCount);
Jeremy Bullock f15907
      else
Jeremy Bullock f15907
        labelStr += tr(" %1 frames").arg(frameCount);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    m_allowedCameraSize = QSize(dim.lx, dim.ly);
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  // ### CASE 3 ###
Jeremy Bullock f15907
  // If there are some conflicts with the existing level.
Jeremy Bullock f15907
  else {
Jeremy Bullock f15907
    if (level_sameName) {
Jeremy Bullock f15907
      TFilePath anotherPath = level_sameName->getPath();
Jeremy Bullock f15907
      tooltipStr +=
Jeremy Bullock f15907
          tr("WARNING : Level name conflicts. There already is a level %1 in the scene with the path\
Jeremy Bullock f15907
                        \n          %2.")
Jeremy Bullock f15907
              .arg(QString::fromStdWString(levelName))
Jeremy Bullock f15907
              .arg(toQString(anotherPath));
Jeremy Bullock f15907
      // check resolution
Jeremy Bullock f15907
      TDimension dim;
Jeremy Bullock f15907
      bool ret = getRasterLevelSize(level_sameName, dim);
Jeremy Bullock f15907
      if (ret && checkRes && m_hasLiveViewImage && stopMotionRes != dim)
Jeremy Bullock f15907
        tooltipStr += tr("\nWARNING : Image size mismatch. The size of level "
Jeremy Bullock f15907
                         "with the same name is is %1 x %2.")
Jeremy Bullock f15907
                          .arg(dim.lx)
Jeremy Bullock f15907
                          .arg(dim.ly);
Jeremy Bullock f15907
      m_allowedCameraSize = QSize(dim.lx, dim.ly);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    if (level_samePath) {
Jeremy Bullock f15907
      std::wstring anotherName = level_samePath->getName();
Jeremy Bullock f15907
      if (!tooltipStr.isEmpty()) tooltipStr += QString("\n");
Jeremy Bullock f15907
      tooltipStr +=
Jeremy Bullock f15907
          tr("WARNING : Level path conflicts. There already is a level with the path %1\
Jeremy Bullock f15907
                        \n          in the scene with the name %2.")
Jeremy Bullock f15907
              .arg(toQString(levelFp))
Jeremy Bullock f15907
              .arg(QString::fromStdWString(anotherName));
Jeremy Bullock f15907
      // check resolution
Jeremy Bullock f15907
      TDimension dim;
Jeremy Bullock f15907
      bool ret = getRasterLevelSize(level_samePath, dim);
Jeremy Bullock f15907
      if (ret && checkRes && m_hasLiveViewImage && stopMotionRes != dim)
Jeremy Bullock f15907
        tooltipStr += tr("\nWARNING : Image size mismatch. The size of level "
Jeremy Bullock f15907
                         "with the same path is %1 x %2.")
Jeremy Bullock f15907
                          .arg(dim.lx)
Jeremy Bullock f15907
                          .arg(dim.ly);
Jeremy Bullock f15907
      m_allowedCameraSize = QSize(dim.lx, dim.ly);
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
    labelStr += tr("WARNING");
Jeremy Bullock f15907
    infoType = WARNING;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  QColor infoColor   = infoColors[(int)infoType];
Jeremy Bullock f15907
  m_infoColorName    = infoColor.name();
Jeremy Bullock f15907
  m_frameInfoText    = labelStr;
Jeremy Bullock f15907
  m_frameInfoToolTip = tooltipStr;
Jeremy Bullock f15907
  emit(frameInfoTextChanged(m_frameInfoText));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::updateLevelNameAndFrame(std::wstring levelName) {
Jeremy Bullock f15907
  if (levelName != m_levelName.toStdWString()) {
Jeremy Bullock f15907
    m_levelName = QString::fromStdWString(levelName);
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
  m_liveViewImageMap.clear();
Jeremy Bullock f15907
  emit(levelNameChanged(m_levelName));
Jeremy Bullock f15907
  // m_previousLevelButton->setDisabled(levelName == L"A");
Jeremy Bullock f15907
Jeremy Bullock f15907
  // set the start frame 10 if the option in preferences
Jeremy Bullock f15907
  // "Show ABC Appendix to the Frame Number in Xsheet Cell" is active.
Jeremy Bullock f15907
  // (frame 10 is displayed as "1" with this option)
Jeremy Bullock f15907
  bool withLetter =
Jeremy Bullock f15907
      Preferences::instance()->isShowFrameNumberWithLettersEnabled();
Jeremy Bullock f15907
Jeremy Bullock f15907
  TLevelSet *levelSet =
Jeremy Bullock f15907
      TApp::instance()->getCurrentScene()->getScene()->getLevelSet();
Jeremy Bullock f15907
  TXshLevel *level_p = levelSet->getLevel(levelName);
Jeremy Bullock f15907
  int startFrame;
Jeremy Bullock f15907
  if (!level_p) {
Jeremy Bullock f15907
    startFrame = withLetter ? 10 : 1;
Jeremy Bullock f15907
  } else {
Jeremy Bullock f15907
    std::vector<tframeid> fids;</tframeid>
Jeremy Bullock f15907
    level_p->getFids(fids);
Jeremy Bullock f15907
    if (fids.empty()) {
Jeremy Bullock f15907
      startFrame = withLetter ? 10 : 1;
Jeremy Bullock f15907
    } else {
Jeremy Bullock f15907
      int lastNum = fids.back().getNumber();
Jeremy Bullock f15907
      startFrame  = withLetter ? ((int)(lastNum / 10) + 1) * 10 : lastNum + 1;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
  if (level_p) {
shun-iwasawa 31accf
    TXshSimpleLevel *sl = level_p->getSimpleLevel();
shun-iwasawa 31accf
    if (sl && sl->getType() == OVL_XSHLEVEL &&
shun-iwasawa 31accf
        sl->getProperties()->isStopMotionLevel()) {
shun-iwasawa 31accf
      buildLiveViewMap(sl);
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  loadLineUpImage();
Jeremy Bullock f15907
  m_frameNumber = startFrame;
Jeremy Bullock f15907
  emit(frameNumberChanged(startFrame));
Jeremy Bullock f15907
  refreshFrameInfo();
Jeremy Bullock f15907
  getSubsampling();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setToNextNewLevel() {
Jeremy Bullock f15907
  const std::unique_ptr<namebuilder> nameBuilder(NameBuilder::getBuilder(L""));</namebuilder>
Jeremy Bullock f15907
Jeremy Bullock f15907
  TLevelSet *levelSet =
Jeremy Bullock f15907
      TApp::instance()->getCurrentScene()->getScene()->getLevelSet();
Jeremy Bullock f15907
  ToonzScene *scene      = TApp::instance()->getCurrentScene()->getScene();
Jeremy Bullock f15907
  std::wstring levelName = L"";
Jeremy Bullock f15907
Jeremy Bullock f15907
  // Select a different unique level name in case it already exists (either in
Jeremy Bullock f15907
  // scene or on disk)
Jeremy Bullock f15907
  TFilePath fp;
Jeremy Bullock f15907
  TFilePath actualFp;
Jeremy Bullock f15907
  for (;;) {
Jeremy Bullock f15907
    levelName = nameBuilder->getNext();
Jeremy Bullock f15907
Jeremy Bullock f15907
    if (levelSet->getLevel(levelName) != 0) continue;
Jeremy Bullock f15907
Jeremy Bullock f15907
    fp = TFilePath(m_filePath) +
Jeremy Bullock f15907
         TFilePath(levelName + L".." + m_fileType.toStdWString());
Jeremy Bullock f15907
    actualFp = scene->decodeFilePath(fp);
Jeremy Bullock f15907
Jeremy Bullock f15907
    if (TSystem::doesExistFileOrLevel(actualFp)) {
Jeremy Bullock f15907
      continue;
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
Jeremy Bullock f15907
    break;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  updateLevelNameAndFrame(levelName);
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
void StopMotion::refreshCameraList() {
shun-iwasawa 31accf
  QString camera = "";
shun-iwasawa 31accf
  bool hasCamera = false;
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  if (m_canon->m_sessionOpen && m_canon->getCameraCount() > 0 &&
shun-iwasawa 31accf
      !m_usingWebcam && m_canon->m_cameraName == m_canon->getCameraName()) {
shun-iwasawa 31accf
    hasCamera = true;
shun-iwasawa 31accf
    camera    = QString::fromStdString(m_canon->m_cameraName);
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
  if (m_usingWebcam) {
shun-iwasawa 31accf
    QList<qcamerainfo> cameras = QCameraInfo::availableCameras();</qcamerainfo>
shun-iwasawa 31accf
    if (m_usingWebcam && cameras.size() > 0) {
shun-iwasawa 31accf
      for (int i = 0; i < cameras.size(); i++) {
shun-iwasawa 31accf
        if (cameras.at(i).description() == m_webcam->getWebcamDescription()) {
shun-iwasawa 31accf
          hasCamera = true;
shun-iwasawa 31accf
          camera    = m_webcam->getWebcamDescription();
shun-iwasawa 31accf
          break;
shun-iwasawa 31accf
        }
shun-iwasawa 31accf
      }
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (!hasCamera) disconnectAllCameras();
shun-iwasawa 31accf
  emit(updateCameraList(camera));
shun-iwasawa 31accf
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::changeCameras(int index) {
shun-iwasawa 31accf
  // note: index is negative if this is called to load DSLR from load settings
shun-iwasawa 31accf
Jeremy Bullock f15907
  QList<qcamerainfo> cameras = QCameraInfo::availableCameras();</qcamerainfo>
Jeremy Bullock f15907
Jeremy Bullock f15907
  // if selected the non-connected state, then disconnect the current camera
Jeremy Bullock f15907
  if (index == 0) {
shun-iwasawa 31accf
    disconnectAllCameras();
shun-iwasawa 31accf
    stopInterval();
Jeremy Bullock f15907
    return;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  // There is a "Select Camera" as the first index
Jeremy Bullock f15907
  index -= 1;
shun-iwasawa 31accf
shun-iwasawa 31accf
  // first see if the index didn't actually change
shun-iwasawa 31accf
  if (cameras.size() > 0 && index < cameras.size() && index >= 0) {
shun-iwasawa 31accf
    if (cameras.at(index).deviceName() == m_webcam->getWebcamDeviceName()) {
shun-iwasawa 31accf
      return;
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  if ((index > cameras.size() - 1) && m_canon->m_sessionOpen) return;
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
shun-iwasawa 31accf
  // close live view if open
shun-iwasawa 31accf
  if (m_liveViewStatus > LiveViewClosed) {
shun-iwasawa 31accf
    toggleLiveView();
shun-iwasawa 31accf
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  // Check if its a webcam or DSLR
Jeremy Bullock f15907
  // Webcams are listed first, so see if one of them is selected
shun-iwasawa 31accf
  if (index < 0 || index > cameras.size() - 1) {
Jeremy Bullock f15907
    m_usingWebcam = false;
Jeremy Bullock f15907
  } else {
Jeremy Bullock f15907
    m_usingWebcam = true;
shun-iwasawa 31accf
    m_webcam->setWebcamIndex(index);
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
Jeremy Bullock f15907
  // in case the camera is not changed
Jeremy Bullock f15907
  if (m_usingWebcam) {
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
    if (m_canon->m_sessionOpen && m_canon->getCameraCount() > 0) {
shun-iwasawa 31accf
      m_canon->closeCameraSession();
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
#endif
Jeremy Bullock f15907
shun-iwasawa 31accf
    m_webcam->setWebcam(new QCamera(cameras.at(index)));
shun-iwasawa 31accf
    m_webcam->setWebcamDeviceName(cameras.at(index).deviceName());
shun-iwasawa 31accf
    m_webcam->setWebcamDescription(cameras.at(index).description());
shun-iwasawa 31accf
Jeremy Bullock f15907
    // loading new camera
shun-iwasawa 31accf
    m_webcam->getWebcam()->load();
Jeremy Bullock f15907
shun-iwasawa 31accf
    m_webcam->refreshWebcamResolutions();
Jeremy Bullock f15907
shun-iwasawa 31accf
    QList<qsize> webcamResolutions = m_webcam->getWebcamResolutions();</qsize>
shun-iwasawa 31accf
    int sizeCount                  = webcamResolutions.count() - 1;
Jeremy Bullock f15907
Jeremy Bullock f15907
    int width;
Jeremy Bullock f15907
    int height;
shun-iwasawa 31accf
    for (int s = 0; s < webcamResolutions.size(); s++) {
shun-iwasawa 31accf
      width  = webcamResolutions.at(s).width();
shun-iwasawa 31accf
      height = webcamResolutions.at(s).height();
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    // see if we can set the webcam resolution to the current camera resolution
shun-iwasawa 31accf
    TDimension res = TApp::instance()
shun-iwasawa 31accf
                         ->getCurrentScene()
shun-iwasawa 31accf
                         ->getScene()
shun-iwasawa 31accf
                         ->getCurrentCamera()
shun-iwasawa 31accf
                         ->getRes();
shun-iwasawa 31accf
    if (webcamResolutions.contains(QSize(res.lx, res.ly))) {
shun-iwasawa 31accf
      width     = res.lx;
shun-iwasawa 31accf
      height    = res.ly;
shun-iwasawa 31accf
      sizeCount = webcamResolutions.indexOf(QSize(res.lx, res.ly));
Jeremy Bullock f15907
    }
Jeremy Bullock f15907
shun-iwasawa 31accf
    m_webcam->getWebcam()->unload();
Jeremy Bullock f15907
Jeremy Bullock f15907
    setWebcamResolution(
Jeremy Bullock f15907
        QString(QString::number(width) + " x " + QString::number(height)));
shun-iwasawa 31accf
    setTEnvCameraName(m_webcam->getWebcamDescription().toStdString());
Jeremy Bullock f15907
    emit(newCameraSelected(index + 1, true));
Jeremy Bullock f15907
    emit(webcamResolutionsChanged());
shun-iwasawa 31accf
    emit(newWebcamResolutionSelected(sizeCount));
Jeremy Bullock f15907
Jeremy Bullock f15907
  } else {
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
    m_canon->openCameraSession();
shun-iwasawa 31accf
    setTEnvCameraName(m_canon->getCameraName());
shun-iwasawa 31accf
    if (index == -2) {
shun-iwasawa 31accf
      index = cameras.size();
Jeremy Bullock f15907
    }
shun-iwasawa 31accf
    m_webcam->clearWebcam();
Jeremy Bullock f15907
shun-iwasawa 31accf
    emit(newCameraSelected(index + 1, false));
Jeremy Bullock f15907
#endif
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
  if (m_useNumpadShortcuts) toggleNumpadShortcuts(true);
shun-iwasawa 31accf
  m_liveViewDpi      = TPointD(0.0, 0.0);
shun-iwasawa 31accf
  m_hasLineUpImage   = false;
shun-iwasawa 31accf
  m_hasLiveViewImage = false;
shun-iwasawa 31accf
  if (m_isTimeLapse && m_intervalStarted) {
shun-iwasawa 31accf
    stopInterval();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
  emit(liveViewStopped());
shun-iwasawa 31accf
  emit(liveViewChanged(false));
shun-iwasawa 31accf
  refreshFrameInfo();
shun-iwasawa 31accf
  // after all live view data is cleared, start it again.
shun-iwasawa 31accf
  toggleLiveView();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::setWebcamResolution(QString resolution) {
shun-iwasawa 31accf
  m_webcam->releaseWebcam();
Jeremy Bullock f15907
Jeremy Bullock f15907
  // resolution is written in the itemText with the format "<width> x</width>
Jeremy Bullock f15907
  // <height>" (e.g. "800 x 600")</height>
Jeremy Bullock f15907
  QStringList texts = resolution.split(' ');
shun-iwasawa 31accf
  // the split text must be "<width>" "x" and "<height>"</height></width>
Jeremy Bullock f15907
  if (texts.size() != 3) return;
shun-iwasawa 31accf
Jeremy Bullock f15907
  int tempStatus   = m_liveViewStatus;
shun-iwasawa 31accf
  m_liveViewStatus = LiveViewClosed;
shun-iwasawa 31accf
shun-iwasawa 31accf
  bool startTimer = false;
Jeremy Bullock f15907
  if (m_timer->isActive()) {
Jeremy Bullock f15907
    m_timer->stop();
Jeremy Bullock f15907
    startTimer = true;
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
Jeremy Bullock f15907
  qApp->processEvents(QEventLoop::AllEvents, 1000);
Jeremy Bullock f15907
shun-iwasawa 31accf
  m_webcam->setWebcamWidth(texts[0].toInt());
shun-iwasawa 31accf
  m_webcam->setWebcamHeight(texts[2].toInt());
Jeremy Bullock f15907
Jeremy Bullock f15907
  m_liveViewDpi    = TPointD(0.0, 0.0);
Jeremy Bullock f15907
  m_liveViewStatus = tempStatus;
Jeremy Bullock f15907
  if (startTimer) m_timer->start(40);
Jeremy Bullock f15907
Jeremy Bullock f15907
  // update env
Jeremy Bullock f15907
  setTEnvCameraResolution(resolution.toStdString());
Jeremy Bullock f15907
Jeremy Bullock f15907
  refreshFrameInfo();
Jeremy Bullock f15907
shun-iwasawa 31accf
  int index = m_webcam->getIndexOfResolution();
Jeremy Bullock f15907
  emit(newWebcamResolutionSelected(index));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
bool StopMotion::toggleLiveView() {
shun-iwasawa 31accf
  bool sessionOpen = false;
Jeremy Bullock f15907
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
  sessionOpen = m_canon->m_sessionOpen;
shun-iwasawa 31accf
#endif
Jeremy Bullock f15907
shun-iwasawa 31accf
  if ((sessionOpen || m_usingWebcam) && m_liveViewStatus == LiveViewClosed) {
Jeremy Bullock f15907
    m_liveViewDpi             = TPointD(0.0, 0.0);
Jeremy Bullock f15907
    m_liveViewImageDimensions = TDimension(0, 0);
Jeremy Bullock f15907
    if (!m_usingWebcam) {
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
      m_canon->startCanonLiveView();
shun-iwasawa 31accf
#endif
Jeremy Bullock f15907
    } else
shun-iwasawa 31accf
      m_liveViewStatus = LiveViewStarting;
Jeremy Bullock f15907
    loadLineUpImage();
Jeremy Bullock f15907
    m_timer->start(40);
Jeremy Bullock f15907
    emit(liveViewChanged(true));
Jeremy Bullock f15907
    Preferences::instance()->setValue(rewindAfterPlayback, false);
shun-iwasawa 2c27a4
    TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
Jeremy Bullock f15907
    return true;
shun-iwasawa 31accf
  } else if ((sessionOpen || m_usingWebcam) &&
shun-iwasawa 31accf
             m_liveViewStatus > LiveViewClosed) {
shun-iwasawa 31accf
    if (!m_usingWebcam) {
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
      m_canon->endCanonLiveView();
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
    } else {
shun-iwasawa 31accf
      m_webcam->releaseWebcam();
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
Jeremy Bullock f15907
    m_timer->stop();
shun-iwasawa 31accf
    emit(liveViewStopped());
Jeremy Bullock f15907
    emit(liveViewChanged(false));
Jeremy Bullock f15907
    if (m_turnOnRewind) {
shun-iwasawa 2c27a4
      Preferences::instance()->setValue(rewindAfterPlayback, true);
Jeremy Bullock f15907
    }
shun-iwasawa 2c27a4
    TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
shun-iwasawa 31accf
    m_liveViewStatus = LiveViewClosed;
Jeremy Bullock f15907
    return false;
Jeremy Bullock f15907
  } else {
Jeremy Bullock f15907
    DVGui::warning(tr("No camera selected."));
Jeremy Bullock f15907
    return false;
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
Jeremy Bullock f15907
void StopMotion::pauseLiveView() {
shun-iwasawa 31accf
  if (m_liveViewStatus == LiveViewOpen) {
shun-iwasawa 31accf
    m_liveViewStatus  = LiveViewPaused;
Jeremy Bullock f15907
    m_userCalledPause = true;
Jeremy Bullock f15907
    emit(liveViewStopped());
shun-iwasawa 31accf
  } else if (m_liveViewStatus == LiveViewPaused) {
shun-iwasawa 31accf
    m_liveViewStatus  = LiveViewOpen;
Jeremy Bullock f15907
    m_userCalledPause = false;
shun-iwasawa 31accf
  } else if (m_liveViewStatus == LiveViewClosed) {
shun-iwasawa 31accf
    toggleLiveView();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
void StopMotion::toggleAlwaysUseLiveViewImages() {
shun-iwasawa 31accf
  m_alwaysUseLiveViewImages = !m_alwaysUseLiveViewImages;
shun-iwasawa 31accf
  emit(alwaysUseLiveViewImagesToggled(m_alwaysUseLiveViewImages));
shun-iwasawa 31accf
  TApp::instance()->getCurrentScene()->notifySceneChanged();
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
Jeremy Bullock f15907
shun-iwasawa 31accf
void StopMotion::onCanonCameraChanged(QString camera) {
shun-iwasawa 31accf
  emit(cameraChanged(camera));
Jeremy Bullock f15907
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//-----------------------------------------------------------------
shun-iwasawa 31accf
std::string StopMotion::getTEnvCameraName() { return StopMotionCameraName; }
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
void StopMotion::setTEnvCameraName(std::string name) {
shun-iwasawa 31accf
  StopMotionCameraName = name;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
//-----------------------------------------------------------------
shun-iwasawa 31accf
std::string StopMotion::getTEnvCameraResolution() {
shun-iwasawa 31accf
  return StopMotionCameraResolution;
Jeremy Bullock f15907
}
Jeremy Bullock f15907
//-----------------------------------------------------------------
shun-iwasawa 31accf
void StopMotion::setTEnvCameraResolution(std::string resolution) {
shun-iwasawa 31accf
  StopMotionCameraResolution = resolution;
shun-iwasawa 31accf
}
Jeremy Bullock f15907
Jeremy Bullock f15907
//=============================================================================
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotionCaptureCommand : public MenuItemHandler {
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  StopMotionCaptureCommand() : MenuItemHandler(MI_StopMotionCapture) {}
Jeremy Bullock f15907
  void execute() {
Jeremy Bullock f15907
    StopMotion *sm = StopMotion::instance();
Jeremy Bullock f15907
    if (sm->m_liveViewStatus > 0) sm->captureImage();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
} StopMotionCaptureCommand;
Jeremy Bullock f15907
Jeremy Bullock f15907
//=============================================================================
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotionRaiseOpacityCommand : public MenuItemHandler {
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  StopMotionRaiseOpacityCommand()
Jeremy Bullock f15907
      : MenuItemHandler(MI_StopMotionRaiseOpacity) {}
Jeremy Bullock f15907
  void execute() {
Jeremy Bullock f15907
    StopMotion *sm = StopMotion::instance();
Jeremy Bullock f15907
    if (sm->m_liveViewStatus > 0) sm->raiseOpacity();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
} StopMotionRaiseOpacityCommand;
Jeremy Bullock f15907
Jeremy Bullock f15907
//=============================================================================
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotionLowerOpacityCommand : public MenuItemHandler {
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  StopMotionLowerOpacityCommand()
Jeremy Bullock f15907
      : MenuItemHandler(MI_StopMotionLowerOpacity) {}
Jeremy Bullock f15907
  void execute() {
Jeremy Bullock f15907
    StopMotion *sm = StopMotion::instance();
Jeremy Bullock f15907
    if (sm->m_liveViewStatus > 0) sm->lowerOpacity();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
} StopMotionLowerOpacityCommand;
Jeremy Bullock f15907
Jeremy Bullock f15907
//=============================================================================
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotionToggleLiveViewCommand : public MenuItemHandler {
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  StopMotionToggleLiveViewCommand()
Jeremy Bullock f15907
      : MenuItemHandler(MI_StopMotionToggleLiveView) {}
Jeremy Bullock f15907
  void execute() {
Jeremy Bullock f15907
    StopMotion *sm = StopMotion::instance();
Jeremy Bullock f15907
    sm->pauseLiveView();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
} StopMotionToggleLiveViewCommand;
Jeremy Bullock f15907
Jeremy Bullock f15907
//=============================================================================
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotionLowerSubsamplingCommand : public MenuItemHandler {
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  StopMotionLowerSubsamplingCommand()
Jeremy Bullock f15907
      : MenuItemHandler(MI_StopMotionLowerSubsampling) {}
Jeremy Bullock f15907
  void execute() {
Jeremy Bullock f15907
    StopMotion *sm = StopMotion::instance();
Jeremy Bullock f15907
    sm->setSubsamplingValue(std::max(1, sm->getSubsamplingValue() - 1));
Jeremy Bullock f15907
    sm->setSubsampling();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
} StopMotionLowerSubsamplingCommand;
Jeremy Bullock f15907
Jeremy Bullock f15907
//=============================================================================
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotionRaiseSubsamplingCommand : public MenuItemHandler {
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  StopMotionRaiseSubsamplingCommand()
Jeremy Bullock f15907
      : MenuItemHandler(MI_StopMotionRaiseSubsampling) {}
Jeremy Bullock f15907
  void execute() {
Jeremy Bullock f15907
    StopMotion *sm = StopMotion::instance();
Jeremy Bullock f15907
    sm->setSubsamplingValue(std::min(30, sm->getSubsamplingValue() + 1));
Jeremy Bullock f15907
    sm->setSubsampling();
Jeremy Bullock f15907
  }
Jeremy Bullock f15907
} StopMotionRaiseSubsamplingCommand;
Jeremy Bullock f15907
Jeremy Bullock f15907
//=============================================================================
Jeremy Bullock f15907
Jeremy Bullock f15907
class StopMotionJumpToCameraCommand : public MenuItemHandler {
Jeremy Bullock f15907
public:
Jeremy Bullock f15907
  StopMotionJumpToCameraCommand()
Jeremy Bullock f15907
      : MenuItemHandler(MI_StopMotionJumpToCamera) {}
Jeremy Bullock f15907
  void execute() {
Jeremy Bullock f15907
    StopMotion *sm = StopMotion::instance();
Jeremy Bullock f15907
    sm->jumpToCameraFrame();
Jeremy Bullock f15907
  }
shun-iwasawa 31accf
} StopMotionJumpToCameraCommand;
shun-iwasawa 31accf
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
shun-iwasawa 31accf
class StopMotionExportImageSequence : public MenuItemHandler {
shun-iwasawa 31accf
public:
shun-iwasawa 31accf
  StopMotionExportImageSequence()
shun-iwasawa 31accf
      : MenuItemHandler(MI_StopMotionExportImageSequence) {}
shun-iwasawa 31accf
  void execute() {
shun-iwasawa 31accf
    StopMotion *sm = StopMotion::instance();
shun-iwasawa 31accf
    sm->exportImageSequence();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
} StopMotionExportImageSequence;
shun-iwasawa 31accf
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
shun-iwasawa 31accf
class StopMotionRemoveFrame : public MenuItemHandler {
shun-iwasawa 31accf
public:
shun-iwasawa 31accf
  StopMotionRemoveFrame() : MenuItemHandler(MI_StopMotionRemoveFrame) {}
shun-iwasawa 31accf
  void execute() {
shun-iwasawa 31accf
    StopMotion *sm = StopMotion::instance();
shun-iwasawa 31accf
    sm->removeStopMotionFrame();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
} StopMotionRemoveFrame;
shun-iwasawa 31accf
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
shun-iwasawa 31accf
class StopMotionNextFrame : public MenuItemHandler {
shun-iwasawa 31accf
public:
shun-iwasawa 31accf
  StopMotionNextFrame() : MenuItemHandler(MI_StopMotionNextFrame) {}
shun-iwasawa 31accf
  void execute() {
shun-iwasawa 31accf
    StopMotion *sm = StopMotion::instance();
shun-iwasawa 31accf
    int index      = TApp::instance()->getCurrentFrame()->getFrameIndex();
shun-iwasawa 31accf
    int maxInXSheet =
shun-iwasawa 31accf
        TApp::instance()->getCurrentXsheet()->getXsheet()->getFrameCount();
shun-iwasawa 31accf
    int max = std::max(maxInXSheet, sm->getXSheetFrameNumber() - 1);
shun-iwasawa 31accf
    if (index < max) {
shun-iwasawa 31accf
      TApp::instance()->getCurrentFrame()->setFrame(index + 1);
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
} StopMotionNextFrame;
shun-iwasawa 31accf
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
shun-iwasawa 31accf
class StopMotionToggleUseLiveViewImagesCommand : public MenuItemHandler {
shun-iwasawa 31accf
public:
shun-iwasawa 31accf
  StopMotionToggleUseLiveViewImagesCommand()
shun-iwasawa 31accf
      : MenuItemHandler(MI_StopMotionToggleUseLiveViewImages) {}
shun-iwasawa 31accf
  void execute() {
shun-iwasawa 31accf
    StopMotion *sm = StopMotion::instance();
shun-iwasawa 31accf
    sm->toggleAlwaysUseLiveViewImages();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
} StopMotionToggleUseLiveViewImagesCommand;
shun-iwasawa 31accf
shun-iwasawa 31accf
#ifdef WITH_CANON
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
shun-iwasawa 31accf
class StopMotionPickFocusCheck : public MenuItemHandler {
shun-iwasawa 31accf
public:
shun-iwasawa 31accf
  StopMotionPickFocusCheck() : MenuItemHandler(MI_StopMotionPickFocusCheck) {}
shun-iwasawa 31accf
  void execute() {
shun-iwasawa 31accf
    StopMotion *sm = StopMotion::instance();
shun-iwasawa 31accf
    sm->m_canon->toggleZoomPicking();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
} StopMotionPickFocusCheck;
shun-iwasawa 31accf
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
shun-iwasawa 31accf
class StopMotionToggleZoomCommand : public MenuItemHandler {
shun-iwasawa 31accf
public:
shun-iwasawa 31accf
  StopMotionToggleZoomCommand() : MenuItemHandler(MI_StopMotionToggleZoom) {}
shun-iwasawa 31accf
  void execute() {
shun-iwasawa 31accf
    StopMotion *sm = StopMotion::instance();
shun-iwasawa 31accf
    sm->m_canon->zoomLiveView();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
} StopMotionToggleZoomCommand;
flurick c8ee00
#endif