Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "toutputproperties.h"
Toshihiro Shimizu 890ddd
#include "tfx.h"
Toshihiro Shimizu 890ddd
#include "tparamcontainer.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "tfxattributes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/fxdag.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshchildlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/observer.h"
Toshihiro Shimizu 890ddd
#include "toonz/controlpointobserver.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfxset.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshpalettecolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshzeraryfxcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsoundcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/columnfan.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshnoteset.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage.h"
Toshihiro Shimizu 890ddd
#include "toonz/textureutils.h"
Toshihiro Shimizu 890ddd
#include "xshhandlemanager.h"
Jaroslav 203cc8
#include "orientation.h"
shun-iwasawa 4a3868
#include "toonz/expressionreferencemonitor.h"
manongjohn 8404a6
#include "toonz/navigationtags.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Jeremy Bullock 57507e
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
shun-iwasawa 4a3868
// STD includes
shun-iwasawa 4a3868
#include <set></set>
shun-iwasawa 4a3868
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DEFINE_CLASS_CODE(TXsheet, 18)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
string getColumnDefaultName(TXsheet *xsh, int col, QString oldName) {
Shinya Kitaoka 120a6e
  TXshColumn *column = xsh->getColumn(col);
Shinya Kitaoka 120a6e
  if (column) {
Shinya Kitaoka 120a6e
    TXshLevelColumn *lc = column->getLevelColumn();
Shinya Kitaoka 120a6e
    if (lc) {
Shinya Kitaoka 120a6e
      int r0, r1;
Shinya Kitaoka 120a6e
      if (lc->getRange(r0, r1)) {
Shinya Kitaoka 120a6e
        TXshCell cell = lc->getCell(r0);
Shinya Kitaoka 120a6e
        assert(!cell.isEmpty());
Shinya Kitaoka 120a6e
        TXshLevel *level = cell.m_level.getPointer();
Shinya Kitaoka 120a6e
        if (level) {
Shinya Kitaoka 120a6e
          bool isNumber = true;
Shinya Kitaoka 120a6e
          oldName.right(oldName.size() - 3).toInt(&isNumber);
Shinya Kitaoka 120a6e
          if (oldName.left(3) == "Col" && isNumber)
Shinya Kitaoka 120a6e
            return ::to_string(level->getName());
Shinya Kitaoka 120a6e
          else
Shinya Kitaoka 120a6e
            return "";
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return "Col" + std::to_string(col + 1);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void setColumnName(TXsheet *xsh, int col) {
Shinya Kitaoka 120a6e
  TStageObject *obj = xsh->getStageObject(TStageObjectId::ColumnId(col));
Shinya Kitaoka 120a6e
  QString oldName   = QString::fromStdString(obj->getName());
Shinya Kitaoka 120a6e
  string name       = getColumnDefaultName(xsh, col, oldName);
Shinya Kitaoka 120a6e
  if (!name.empty()) obj->setName(name);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TXsheetImp
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct TXsheet::TXsheetImp {
Shinya Kitaoka 120a6e
  unsigned long m_id;  //!< The xsheet instance's unique identifier
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TColumnSetT<txshcolumn> m_columnSet;</txshcolumn>
Shinya Kitaoka 120a6e
  TStageObjectTree *m_pegTree;
Shinya Kitaoka 120a6e
  FxDag *m_fxDag;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_frameCount;
Shinya Kitaoka 120a6e
  int m_soloColumn;
Shinya Kitaoka 120a6e
  int m_viewColumn;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TSoundTrackP m_mixedSound;
Jaroslav 203cc8
  ColumnFan m_columnFans[Orientations::COUNT];
Shinya Kitaoka 120a6e
  XshHandleManager *m_handleManager;
Shinya Kitaoka 120a6e
  ToonzScene *m_scene;
Toshihiro Shimizu 890ddd
shun-iwasawa 4a3868
  ExpressionReferenceMonitor *m_expRefMonitor;
shun-iwasawa 4a3868
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TXsheetImp();
Shinya Kitaoka 120a6e
  ~TXsheetImp();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static inline unsigned long newIdentifier() {
Shinya Kitaoka 120a6e
    static unsigned long currentId = 0;
Shinya Kitaoka 120a6e
    return ++currentId;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Jaroslav 203cc8
  void copyFoldedState();
Jaroslav 203cc8
Toshihiro Shimizu 890ddd
private:
Jaroslav 203cc8
  void initColumnFans();
Jaroslav 203cc8
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TXsheetImp(const TXsheetImp &);
Shinya Kitaoka 120a6e
  TXsheetImp &operator=(const TXsheetImp &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXsheet::SoundProperties::SoundProperties()
Shinya Kitaoka 120a6e
    : m_fromFrame(-1), m_toFrame(-1), m_frameRate(-1), m_isPreview(false) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXsheet::SoundProperties::~SoundProperties() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool TXsheet::SoundProperties::operator==(
Shinya Kitaoka 120a6e
    const SoundProperties &c) const {
Shinya Kitaoka 120a6e
  return m_fromFrame == c.m_fromFrame && m_toFrame == c.m_toFrame &&
Shinya Kitaoka 120a6e
         m_frameRate == c.m_frameRate && m_isPreview == c.m_isPreview;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool TXsheet::SoundProperties::operator!=(
Shinya Kitaoka 120a6e
    const SoundProperties &c) const {
Shinya Kitaoka 120a6e
  return !(*this == c);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXsheet::TXsheetImp::TXsheetImp()
Shinya Kitaoka 120a6e
    : m_id(newIdentifier())
Shinya Kitaoka 120a6e
    , m_pegTree(new TStageObjectTree)
Shinya Kitaoka 120a6e
    , m_handleManager(0)
Shinya Kitaoka 120a6e
    , m_fxDag(new FxDag())
Shinya Kitaoka 120a6e
    , m_frameCount(0)
Shinya Kitaoka 120a6e
    , m_soloColumn(-1)
Shinya Kitaoka 120a6e
    , m_viewColumn(-1)
Shinya Kitaoka 120a6e
    , m_mixedSound(0)
shun-iwasawa 4a3868
    , m_scene(0)
shun-iwasawa 4a3868
    , m_expRefMonitor(new ExpressionReferenceMonitor()) {
Jaroslav 203cc8
  initColumnFans();
Jaroslav 203cc8
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXsheet::TXsheetImp::~TXsheetImp() {
Shinya Kitaoka 120a6e
  assert(m_pegTree);
Shinya Kitaoka 120a6e
  assert(m_fxDag);
Shinya Kitaoka 120a6e
  assert(m_handleManager);
Shinya Kitaoka 120a6e
  delete m_pegTree;
Shinya Kitaoka 120a6e
  delete m_fxDag;
Shinya Kitaoka 120a6e
  delete m_handleManager;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Jaroslav 203cc8
//-----------------------------------------------------------------------------
Jaroslav 203cc8
Jaroslav 203cc8
void TXsheet::TXsheetImp::initColumnFans() {
Jaroslav 203cc8
  for (auto o : Orientations::all()) {
Jaroslav 203cc8
    int index = o->dimension(PredefinedDimension::INDEX);
shun-iwasawa 52004d
    m_columnFans[index].setDimensions(
shun-iwasawa 52004d
        o->dimension(PredefinedDimension::LAYER),
shun-iwasawa 52004d
        o->dimension(PredefinedDimension::CAMERA_LAYER));
Jaroslav 203cc8
  }
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
void TXsheet::TXsheetImp::copyFoldedState() {
Jaroslav 203cc8
  for (int i = 1; i < Orientations::COUNT; i++)
Jaroslav 203cc8
    m_columnFans[i].copyFoldedStateFrom(m_columnFans[0]);
Jaroslav 203cc8
}
Jaroslav 203cc8
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TXsheet
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXsheet::TXsheet()
Shinya Kitaoka 120a6e
    : TSmartObject(m_classCode)
Shinya Kitaoka 120a6e
    , m_player(0)
Shinya Kitaoka 120a6e
    , m_imp(new TXsheet::TXsheetImp)
John Dancel c323ac
    , m_notes(new TXshNoteSet())
shun-iwasawa 4a3868
    , m_cameraColumnIndex(0)
manongjohn 8404a6
    , m_observer(nullptr)
manongjohn 8404a6
    , m_navigationTags(new NavigationTags()) {
Shinya Kitaoka 120a6e
  // extern TSyntax::Grammar *createXsheetGrammar(TXsheet*);
Shinya Kitaoka 120a6e
  m_soundProperties      = new TXsheet::SoundProperties();
Shinya Kitaoka 120a6e
  m_imp->m_handleManager = new XshHandleManager(this);
Shinya Kitaoka 120a6e
  m_imp->m_pegTree->setHandleManager(m_imp->m_handleManager);
Shinya Kitaoka 120a6e
  m_imp->m_pegTree->createGrammar(this);
manongjohn 4334db
manongjohn 4334db
  // Dummy camera column
manongjohn 4334db
  m_cameraColumn          = TXshColumn::createEmpty(0);
manongjohn 4334db
  m_cameraColumn->m_index = -1;
manongjohn 4334db
  m_cameraColumn->setXsheet(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXsheet::~TXsheet() {
Shinya Kitaoka 120a6e
  texture_utils::invalidateTextures(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(m_imp);
Shinya Kitaoka 120a6e
  if (m_notes) delete m_notes;
Shinya Kitaoka 120a6e
  if (m_soundProperties) delete m_soundProperties;
manongjohn 8404a6
  if (m_navigationTags) delete m_navigationTags;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
unsigned long TXsheet::id() const { return m_imp->m_id; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TXsheet::getFrameCount() const { return m_imp->m_frameCount; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TXshCell &TXsheet::getCell(int row, int col) const {
Jaroslav 203cc8
  return getCell(CellPosition(row, col));
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
const TXshCell &TXsheet::getCell(const CellPosition &pos) const {
Shinya Kitaoka 120a6e
  static const TXshCell emptyCell;
Jaroslav 203cc8
Jaroslav 203cc8
  TXshColumnP column = m_imp->m_columnSet.getColumn(pos.layer());
Shinya Kitaoka 120a6e
  if (!column) return emptyCell;
Shinya Kitaoka 120a6e
  TXshCellColumn *xshColumn = column->getCellColumn();
Shinya Kitaoka 120a6e
  if (!xshColumn) return emptyCell;
Jaroslav 203cc8
  return xshColumn->getCell(pos.frame());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::setCell(int row, int col, const TXshCell &cell) {
Shinya Kitaoka 120a6e
  if (row < 0 || col < 0) return false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool wasColumnEmpty = isColumnEmpty(col);
Shinya Kitaoka 120a6e
  TXshCellColumn *cellColumn;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!cell.isEmpty()) {
Shinya Kitaoka 120a6e
    TXshLevel *level = cell.m_level.getPointer();
Shinya Kitaoka 120a6e
    assert(level);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    int levelType               = level->getType();
Shinya Kitaoka 120a6e
    TXshColumn::ColumnType type = TXshColumn::eLevelType;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (levelType == SND_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eSoundType;
Shinya Kitaoka 120a6e
    else if (levelType == SND_TXT_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eSoundTextType;
Shinya Kitaoka 120a6e
    else if (levelType == PLT_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::ePaletteType;
Shinya Kitaoka 120a6e
    else if (levelType == ZERARYFX_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eZeraryFxType;
Shinya Kitaoka 120a6e
    else if (levelType == MESH_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eMeshType;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    cellColumn = touchColumn(col, type)->getCellColumn();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    TXshColumn *column = getColumn(col);
Shinya Kitaoka 120a6e
    cellColumn         = column ? column->getCellColumn() : 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!cellColumn || cellColumn->isLocked()) return false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  cellColumn->setXsheet(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!cellColumn->setCell(row, cell)) {
Shinya Kitaoka 120a6e
    if (wasColumnEmpty) {
Shinya Kitaoka 120a6e
      removeColumn(col);
Shinya Kitaoka 120a6e
      insertColumn(col);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFx *fx = cellColumn->getFx();
Shinya Kitaoka 120a6e
  if (wasColumnEmpty && fx && fx->getOutputConnectionCount() == 0 &&
Shinya Kitaoka 120a6e
      cellColumn->getPaletteColumn() == 0)
Shinya Kitaoka 120a6e
    getFxDag()->addToXsheet(fx);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (cell.isEmpty())
Shinya Kitaoka 120a6e
    updateFrameCount();
Shinya Kitaoka 120a6e
  else if (row >= m_imp->m_frameCount)
Shinya Kitaoka 120a6e
    m_imp->m_frameCount = row + 1;
Toshihiro Shimizu 890ddd
shun-iwasawa 23b326
  // set the level name to the column
shun-iwasawa 23b326
  if (wasColumnEmpty && cellColumn && !cell.isEmpty() &&
shun-iwasawa 23b326
      Preferences::instance()->isLinkColumnNameWithLevelEnabled()) {
shun-iwasawa 23b326
    getStageObject(TStageObjectId::ColumnId(col))
shun-iwasawa 23b326
        ->setName(to_string(cell.m_level->getName()));
shun-iwasawa 23b326
  }
shun-iwasawa 23b326
Shinya Kitaoka 120a6e
  TNotifier::instance()->notify(TXsheetChange());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::getCells(int row, int col, int rowCount, TXshCell cells[]) const {
Shinya Kitaoka 120a6e
  static const TXshCell emptyCell;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  TXshColumnP column = m_imp->m_columnSet.getColumn(col);
Shinya Kitaoka 120a6e
  if (!column) {
Shinya Kitaoka 120a6e
    for (i = 0; i < rowCount; i++) cells[i] = emptyCell;
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TXshCellColumn *xshColumn = column->getCellColumn();
Shinya Kitaoka 120a6e
  if (!xshColumn) {
Shinya Kitaoka 120a6e
    for (i = 0; i < rowCount; i++) cells[i] = emptyCell;
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  xshColumn->getCells(row, rowCount, cells);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::setCells(int row, int col, int rowCount, const TXshCell cells[]) {
Shinya Kitaoka 120a6e
  static const TXshCell emptyCell;
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  while (i < rowCount && cells[i].isEmpty()) i++;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // inserito da Elisa verso novembre 2009.
Shinya Kitaoka 120a6e
  // cosi' ha il difetto che se assegno celle vuote non fa nulla
Shinya Kitaoka 120a6e
  // per ora lo commento. bisogna indagare se questo rompe qualcosa
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // ho modificato il seguito per gestire il caso in cui i>=rowCount
Shinya Kitaoka 120a6e
  // => niente livelli dentro cells
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // if(i>=rowCount)
Shinya Kitaoka 120a6e
  //  return false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TXshColumn::ColumnType type = TXshColumn::eLevelType;
Shinya Kitaoka 120a6e
  if (i < rowCount) {
Shinya Kitaoka 120a6e
    TXshLevel *level = cells[i].m_level.getPointer();
Shinya Kitaoka 120a6e
    int levelType    = level->getType();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (levelType == SND_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eSoundType;
Shinya Kitaoka 120a6e
    else if (levelType == SND_TXT_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eSoundTextType;
Shinya Kitaoka 120a6e
    else if (levelType == PLT_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::ePaletteType;
Shinya Kitaoka 120a6e
    else if (levelType == ZERARYFX_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eZeraryFxType;
Shinya Kitaoka 120a6e
    else if (levelType == MESH_XSHLEVEL)
Shinya Kitaoka 120a6e
      type = TXshColumn::eMeshType;
Shinya Kitaoka 120a6e
  }
John Dancel 421acd
  bool wasColumnEmpty = isColumnEmpty(col);
John Dancel 421acd
  if (col < 0) return false;
Shinya Kitaoka 120a6e
  TXshCellColumn *column = touchColumn(col, type)->getCellColumn();
Shinya Kitaoka 120a6e
  if (!column) return false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int oldColRowCount = column->getMaxFrame() + 1;
Shinya Kitaoka 120a6e
  bool ret           = column->setCells(row, rowCount, cells);
Shinya Kitaoka 120a6e
  if (!ret || column->isLocked()) {
Shinya Kitaoka 120a6e
    if (wasColumnEmpty) {
Shinya Kitaoka 120a6e
      removeColumn(col);
Shinya Kitaoka 120a6e
      insertColumn(col);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int newColRowCount = column->getMaxFrame() + 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFx *fx = column->getFx();
Shinya Kitaoka 120a6e
  if (wasColumnEmpty && fx && fx->getOutputConnectionCount() == 0)
Shinya Kitaoka 120a6e
    getFxDag()->addToXsheet(fx);
Shinya Kitaoka 120a6e
  column->setXsheet(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (newColRowCount > m_imp->m_frameCount)
Shinya Kitaoka 120a6e
    m_imp->m_frameCount = newColRowCount;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    if (oldColRowCount == m_imp->m_frameCount &&
Shinya Kitaoka 120a6e
        newColRowCount < m_imp->m_frameCount)
Shinya Kitaoka 120a6e
      updateFrameCount();
Shinya Kitaoka 120a6e
  }
shun-iwasawa 23b326
  row + 1;
shun-iwasawa 23b326
shun-iwasawa 23b326
  // set the level name to the column
shun-iwasawa 23b326
  if (wasColumnEmpty && i < rowCount &&
shun-iwasawa 23b326
      Preferences::instance()->isLinkColumnNameWithLevelEnabled()) {
shun-iwasawa 23b326
    getStageObject(TStageObjectId::ColumnId(col))
shun-iwasawa 23b326
        ->setName(to_string(cells[i].m_level->getName()));
shun-iwasawa 23b326
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::insertCells(int row, int col, int rowCount) {
Shinya Kitaoka 120a6e
  TXshColumnP column = m_imp->m_columnSet.getColumn(col);
Shinya Kitaoka 120a6e
  if (!column || column->isLocked()) return;
Shinya Kitaoka 120a6e
  TXshCellColumn *xshColumn = column->getCellColumn();
Shinya Kitaoka 120a6e
  if (!xshColumn) return;
Shinya Kitaoka 120a6e
  xshColumn->insertEmptyCells(row, rowCount);
Shinya Kitaoka 120a6e
  // aggiorno il frame count
Shinya Kitaoka 120a6e
  int fc = xshColumn->getMaxFrame() + 1;
Shinya Kitaoka 120a6e
  if (fc > m_imp->m_frameCount) m_imp->m_frameCount = fc;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::removeCells(int row, int col, int rowCount) {
Shinya Kitaoka 120a6e
  TXshColumnP column = m_imp->m_columnSet.getColumn(col);
Shinya Kitaoka 120a6e
  if (!column || column->isLocked()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TXshCellColumn *xshCellColumn = column->getCellColumn();
Shinya Kitaoka 120a6e
  if (!xshCellColumn) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int oldColRowCount = xshCellColumn->getMaxFrame() + 1;
Shinya Kitaoka 120a6e
  xshCellColumn->removeCells(row, rowCount);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // aggiornamento framecount
Shinya Kitaoka 120a6e
  if (oldColRowCount == m_imp->m_frameCount) updateFrameCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TNotifier::instance()->notify(TXsheetChange());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::clearCells(int row, int col, int rowCount) {
Shinya Kitaoka 120a6e
  const TXshColumnP &column = m_imp->m_columnSet.getColumn(col);
Shinya Kitaoka 120a6e
  if (!column || column->isLocked()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TXshCellColumn *xshCellColumn = column->getCellColumn();
Shinya Kitaoka 120a6e
  if (!xshCellColumn) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int oldColRowCount = xshCellColumn->getMaxFrame() + 1;
Shinya Kitaoka 120a6e
  xshCellColumn->clearCells(row, rowCount);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // aggiornamento framecount
Shinya Kitaoka 120a6e
  if (oldColRowCount == m_imp->m_frameCount) updateFrameCount();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::clearAll() {
Shinya Kitaoka 120a6e
  int c0 = 0, c1 = m_imp->m_columnSet.getColumnCount() - 1;
Shinya Kitaoka 120a6e
  int r0 = 0, r1 = getFrameCount() - 1;
Shinya Kitaoka 120a6e
  m_imp->m_columnSet.clear();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_imp->m_pegTree) {
Shinya Kitaoka 120a6e
    delete m_imp->m_pegTree;
Shinya Kitaoka 120a6e
    m_imp->m_pegTree = new TStageObjectTree();
Shinya Kitaoka 120a6e
    m_imp->m_pegTree->setHandleManager(m_imp->m_handleManager);
Shinya Kitaoka 120a6e
    m_imp->m_pegTree->createGrammar(this);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_imp->m_fxDag) {
Shinya Kitaoka 120a6e
    delete m_imp->m_fxDag;
Shinya Kitaoka 120a6e
    m_imp->m_fxDag = new FxDag();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_imp->m_frameCount = 0;
Shinya Kitaoka 120a6e
  m_imp->m_mixedSound = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TXsheet::getCellRange(int col, int &r0, int &r1) const {
Shinya Kitaoka 120a6e
  r0                 = 0;
Shinya Kitaoka 120a6e
  r1                 = -1;
Shinya Kitaoka 120a6e
  TXshColumnP column = m_imp->m_columnSet.getColumn(col);
Shinya Kitaoka 120a6e
  if (!column) return 0;
Shinya Kitaoka 120a6e
  TXshCellColumn *cellColumn = column->getCellColumn();
Shinya Kitaoka 120a6e
  if (!cellColumn) return 0;
Shinya Kitaoka 120a6e
  return cellColumn->getRange(r0, r1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TXsheet::getMaxFrame(int col) const {
Shinya Kitaoka 120a6e
  TXshColumnP column = m_imp->m_columnSet.getColumn(col);
Shinya Kitaoka 120a6e
  if (!column) return 0;
Shinya Kitaoka 120a6e
  return column->getMaxFrame();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::isColumnEmpty(int col) const {
Shinya Kitaoka 120a6e
  TXshColumnP column = m_imp->m_columnSet.getColumn(col);
Shinya Kitaoka 120a6e
  return column ? column->isEmpty() : true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::getUsedLevels(set<txshlevel *=""> &levels) const {</txshlevel>
Shinya Kitaoka 120a6e
  set<const *="" txsheet=""> visitedXshs;</const>
Shinya Kitaoka 120a6e
  vector<const *="" txsheet=""> todoXshs;</const>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  visitedXshs.insert(this);
Shinya Kitaoka 120a6e
  todoXshs.push_back(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (!todoXshs.empty()) {
Shinya Kitaoka 120a6e
    const TXsheet *xsh = todoXshs.back();
Shinya Kitaoka 120a6e
    todoXshs.pop_back();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    int c0 = 0, c1 = xsh->getColumnCount() - 1;
Shinya Kitaoka 120a6e
    for (int c = c0; c <= c1; ++c) {
Shinya Kitaoka 120a6e
      TXshColumnP column = const_cast<txsheet *="">(xsh)->getColumn(c);</txsheet>
Shinya Kitaoka 120a6e
      if (!column) continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TXshCellColumn *cellColumn = column->getCellColumn();
Shinya Kitaoka 120a6e
      if (!cellColumn) continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      int r0, r1;
Shinya Kitaoka 120a6e
      if (!cellColumn->getRange(r0, r1)) continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TXshLevel *level = 0;
Shinya Kitaoka 120a6e
      for (int r = r0; r <= r1; r++) {
Shinya Kitaoka 120a6e
        TXshCell cell = cellColumn->getCell(r);
Shinya Kitaoka 120a6e
        if (cell.isEmpty() || !cell.m_level) continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        if (level != cell.m_level.getPointer()) {
Shinya Kitaoka 120a6e
          level = cell.m_level.getPointer();
Shinya Kitaoka 120a6e
          levels.insert(level);
Shinya Kitaoka 120a6e
          if (level->getChildLevel()) {
Shinya Kitaoka 120a6e
            TXsheet *childXsh = level->getChildLevel()->getXsheet();
Shinya Kitaoka 120a6e
            if (visitedXshs.count(childXsh) == 0) {
Shinya Kitaoka 120a6e
              visitedXshs.insert(childXsh);
Shinya Kitaoka 120a6e
              todoXshs.push_back(childXsh);
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::isLevelUsed(TXshLevel *level) const {
Shinya Kitaoka 120a6e
  set<txshlevel *=""> levels;</txshlevel>
Shinya Kitaoka 120a6e
  getUsedLevels(levels);
Shinya Kitaoka 120a6e
  return levels.count(level) > 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TStageObject *TXsheet::getStageObject(const TStageObjectId &id) const {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TStageObjectTree *TXsheet::getStageObjectTree() const {
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TAffine TXsheet::getPlacement(const TStageObjectId &id, int frame) const {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id)->getPlacement(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TXsheet::getZ(const TStageObjectId &id, int frame) const {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id)->getZ(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TXsheet::getNoScaleZ(const TStageObjectId &id) const {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id)->getNoScaleZ();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TAffine TXsheet::getParentPlacement(const TStageObjectId &id, int frame) const {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id)->getParentPlacement(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPointD TXsheet::getCenter(const TStageObjectId &id, int frame) const {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id)->getCenter(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::setCenter(const TStageObjectId &id, int frame,
Shinya Kitaoka 120a6e
                        const TPointD ¢er) {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  m_imp->m_pegTree->getStageObject(id)->setCenter(frame, center);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TStageObjectId TXsheet::getStageObjectParent(const TStageObjectId &id) {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id)->getParent();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::setStageObjectParent(const TStageObjectId &id,
Shinya Kitaoka 120a6e
                                   const TStageObjectId &parentId) {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  m_imp->m_pegTree->getStageObject(id)->setParent(parentId);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::hasChildren(const TStageObjectId &id) const {
Shinya Kitaoka 120a6e
  assert(id != TStageObjectId::NoneId);
Shinya Kitaoka 120a6e
  return m_imp->m_pegTree->getStageObject(id)->hasChildren();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TAffine TXsheet::getCameraAff(int frame) const {
Shinya Kitaoka 120a6e
  TStageObjectId cameraId = getStageObjectTree()->getCurrentCameraId();
Shinya Kitaoka 120a6e
  TAffine cameraAff       = getPlacement(cameraId, frame);
Shinya Kitaoka 120a6e
  double cameraZ          = getZ(cameraId, frame);
Shinya Kitaoka 120a6e
  TAffine aff             = cameraAff * TScale((1000 + cameraZ) / 1000);
Shinya Kitaoka 120a6e
  return aff;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::reverseCells(int r0, int c0, int r1, int c1) {
Shinya Kitaoka 120a6e
  int rowCount = r1 - r0;
Shinya Kitaoka 120a6e
  if (rowCount < 0 || c1 - c0 < 0) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int j = c0; j <= c1; j++) {
Shinya Kitaoka 120a6e
    int i1, i2;
Shinya Kitaoka 120a6e
    for (i1 = r0, i2 = r1; i1 < i2; i1++, i2--) {
Jaroslav 203cc8
      TXshCell app1 = getCell(CellPosition(i1, j));
Jaroslav 203cc8
      TXshCell app2 = getCell(CellPosition(i2, j));
Shinya Kitaoka 120a6e
      setCell(i1, j, app2);
Shinya Kitaoka 120a6e
      setCell(i2, j, app1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::swingCells(int r0, int c0, int r1, int c1) {
Shinya Kitaoka 120a6e
  int rowCount = r1 - r0;
Shinya Kitaoka 120a6e
  if (rowCount < 0 || c1 - c0 < 0) return;
Shinya Kitaoka 120a6e
  int r0Mod = r1 + 1;
Shinya Kitaoka 120a6e
  for (int c = c0; c <= c1; ++c) insertCells(r0Mod, c, rowCount);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int j = c0; j <= c1; j++) {
Shinya Kitaoka 120a6e
    for (int i1 = r0Mod, i2 = r1 - 1; i2 >= r0; i1++, i2--) {
Jaroslav 203cc8
      TXshCell cell = getCell(CellPosition(i2, j));
Shinya Kitaoka 120a6e
      setCell(i1, j, cell);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::incrementCells(int r0, int c0, int r1, int c1,
Shinya Kitaoka 120a6e
                             vector<std::pair<trect, txshcell="">> &forUndo) {</std::pair<trect,>
Shinya Kitaoka 120a6e
  for (int j = c0; j <= c1; j++) {
Shinya Kitaoka 120a6e
    int i = r0;
Jaroslav 203cc8
    while (getCell(CellPosition(i, j)).isEmpty() && i <= r1 - 1) i++;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (; i <= r1 - 1; i++) {
Jaroslav 203cc8
      if (getCell(CellPosition(i + 1, j)).isEmpty()) break;
Jaroslav 203cc8
      const TXshCell &ce1 = getCell(CellPosition(i, j)),
Jaroslav 203cc8
                     &ce2 = getCell(CellPosition(i + 1, j));
Shinya Kitaoka 120a6e
      if (ce2.getSimpleLevel() != ce1.getSimpleLevel() ||
Shinya Kitaoka 120a6e
          ce2.getFrameId().getNumber() < ce1.getFrameId().getNumber())
Shinya Kitaoka 120a6e
        return false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    i = r0;
Jaroslav 203cc8
    while (getCell(CellPosition(i, j)).isEmpty() && i <= r1 - 1) i++;
Shinya Kitaoka 120a6e
    int count;
Shinya Kitaoka 120a6e
    for (; i <= r1 - 1; i++) {
Shinya Kitaoka 120a6e
      count = 1;
Jaroslav 203cc8
      if (getCell(CellPosition(i + 1, j)).isEmpty()) continue;
Toshihiro Shimizu 890ddd
Jaroslav 203cc8
      int frame1 = getCell(CellPosition(i, j)).getFrameId().getNumber();
Shinya Kitaoka 120a6e
      if (frame1 == -1) break;
Jaroslav 203cc8
      while (!getCell(CellPosition(i + 1, j)).isEmpty() &&
Jaroslav 203cc8
             getCell(CellPosition(i + 1, j)).getFrameId().getNumber() ==
Jaroslav 203cc8
                 getCell(CellPosition(i, j)).getFrameId().getNumber())
Shinya Kitaoka 120a6e
        i++, count++;
Toshihiro Shimizu 890ddd
Jaroslav 203cc8
      int frame2 = getCell(CellPosition(i + 1, j)).getFrameId().getNumber();
Shinya Kitaoka 120a6e
      if (frame2 == -1) break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (frame1 + count == frame2)
Shinya Kitaoka 120a6e
        continue;
Jaroslav 203cc8
      else if (frame1 + count < frame2)  // add
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        int numCells = frame2 - frame1 - count;
Shinya Kitaoka 120a6e
        insertCells(i + 1, j, numCells);
Shinya Kitaoka 120a6e
        forUndo.push_back(std::pair<trect, txshcell="">(</trect,>
Shinya Kitaoka 120a6e
            TRect(i + 1, j, i + 1 + numCells - 1, j), TXshCell()));
Jaroslav 203cc8
        for (int k = 1; k <= numCells; k++)
Jaroslav 203cc8
          setCell(i + k, j, getCell(CellPosition(i, j)));
Shinya Kitaoka 120a6e
        i += numCells;
Shinya Kitaoka 120a6e
        r1 += numCells;
Jaroslav 203cc8
      } else  // remove
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        int numCells = count - frame2 + frame1;
Shinya Kitaoka 120a6e
        i            = i - numCells;
Jaroslav 203cc8
        forUndo.push_back(
Jaroslav 203cc8
            std::pair<trect, txshcell="">(TRect(i + 1, j, i + 1 + numCells - 1, j),</trect,>
Jaroslav 203cc8
                                       getCell(CellPosition(i + 1, j))));
Shinya Kitaoka 120a6e
        removeCells(i + 1, j, numCells);
Shinya Kitaoka 120a6e
        r1 -= numCells;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return true;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::duplicateCells(int r0, int c0, int r1, int c1, int upTo) {
Shinya Kitaoka 120a6e
  assert(upTo >= r1 + 1);
Shinya Kitaoka 120a6e
  int chunk = r1 - r0 + 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int j = c0; j <= c1; j++) {
Shinya Kitaoka 120a6e
    insertCells(r1 + 1, j, upTo - (r1 + 1) + 1);
Shinya Kitaoka 120a6e
    for (int i = r1 + 1; i <= upTo; i++)
Jaroslav 203cc8
      setCell(i, j, getCell(CellPosition(r0 + ((i - (r1 + 1)) % chunk), j)));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::stepCells(int r0, int c0, int r1, int c1, int type) {
Shinya Kitaoka 120a6e
  int nr = r1 - r0 + 1;
Shinya Kitaoka 120a6e
  int nc = c1 - c0 + 1;
Shinya Kitaoka 120a6e
  if (nr < 1 || nc <= 0) return;
Shinya Kitaoka 120a6e
  int size = nr * nc;
Shinya Kitaoka 120a6e
  std::unique_ptr<txshcell[]> cells(new TXshCell[size]);</txshcell[]>
Shinya Kitaoka 120a6e
  if (!cells) return;
Shinya Kitaoka 120a6e
  // salvo il contenuto delle celle in cells
Shinya Kitaoka 120a6e
  int k = 0;
Shinya Kitaoka 120a6e
  for (int r = r0; r <= r1; r++)
Shinya Kitaoka 120a6e
    for (int c = c0; c <= c1; c++) {
Jaroslav 203cc8
      cells[k++] = getCell(CellPosition(r, c));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int nrows = nr * (type - 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int c = c0; c <= c1; ++c) insertCells(r1 + 1, c, nrows);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int j = c0; j <= c1; j++) {
Shinya Kitaoka 120a6e
    int i, k;
Shinya Kitaoka 120a6e
    for (i = r0, k = j - c0; k < size; k += nc) {
Shinya Kitaoka 120a6e
      for (int i1 = 0; i1 < type; i1++) {
Shinya Kitaoka 120a6e
        if (cells[k].isEmpty())
Shinya Kitaoka 120a6e
          clearCells(i + i1, j);
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          setCell(i + i1, j, cells[k]);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      i += type;  // dipende dal tipo di step (2 o 3 per ora)
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::increaseStepCells(int r0, int c0, int &r1, int c1) {
Shinya Kitaoka 120a6e
  int c, size = r1 - r0 + 1;
Shinya Kitaoka 120a6e
  QList<int> ends;</int>
Shinya Kitaoka 120a6e
  for (c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
    int r = r0, i = 0, rEnd = r1;
Shinya Kitaoka 120a6e
    while (r <= rEnd) {
Jaroslav 203cc8
      TXshCell cell = getCell(CellPosition(r, c));
Shinya Kitaoka 120a6e
      if (!cell.isEmpty()) {
Shinya Kitaoka 120a6e
        insertCells(r, c);
Shinya Kitaoka 120a6e
        setCell(r, c, cell);
Shinya Kitaoka 120a6e
        rEnd++;
Shinya Kitaoka 120a6e
        r++;
Jaroslav 203cc8
        while (cell == getCell(CellPosition(r, c)) && r <= rEnd) r++;
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        r++;
Shinya Kitaoka 120a6e
      i++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    ends.append(rEnd);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (ends.isEmpty()) return;
Shinya Kitaoka 120a6e
  // controllo se devo cambiare la selezione
Shinya Kitaoka 120a6e
  bool allIncreaseIsEqual = true;
Shinya Kitaoka 120a6e
  for (c = 0; c < ends.size() - 1 && allIncreaseIsEqual; c++)
shun-iwasawa 52004d
    allIncreaseIsEqual = allIncreaseIsEqual && ends[c] == ends[c + 1];
Shinya Kitaoka 120a6e
  if (allIncreaseIsEqual) r1 = ends[0];
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::decreaseStepCells(int r0, int c0, int &r1, int c1) {
Shinya Kitaoka 120a6e
  int c, size = r1 - r0 + 1;
Shinya Kitaoka 120a6e
  QList<int> ends;</int>
Shinya Kitaoka 120a6e
  for (c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
    int r = r0, i = 0, rEnd = r1;
Shinya Kitaoka 120a6e
    while (r <= rEnd) {
Jaroslav 203cc8
      TXshCell cell = getCell(CellPosition(r, c));
Shinya Kitaoka 120a6e
      if (!cell.isEmpty()) {
Shinya Kitaoka 120a6e
        r++;
Shinya Kitaoka 120a6e
        bool removed = false;
Jaroslav 203cc8
        while (cell == getCell(CellPosition(r, c)) && r <= rEnd) {
Shinya Kitaoka 120a6e
          if (!removed) {
Shinya Kitaoka 120a6e
            removed = true;
Shinya Kitaoka 120a6e
            removeCells(r, c);
Shinya Kitaoka 120a6e
            rEnd--;
Shinya Kitaoka 120a6e
          } else
Shinya Kitaoka 120a6e
            r++;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        r++;
Shinya Kitaoka 120a6e
      i++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    ends.append(rEnd);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (ends.isEmpty()) return;
Shinya Kitaoka 120a6e
  // controllo se devo cambiare la selezione
Shinya Kitaoka 120a6e
  bool allDecreaseIsEqual = true;
Shinya Kitaoka 120a6e
  for (c = 0; c < ends.size() - 1 && allDecreaseIsEqual; c++)
shun-iwasawa 52004d
    allDecreaseIsEqual = allDecreaseIsEqual && ends[c] == ends[c + 1];
Shinya Kitaoka 120a6e
  if (allDecreaseIsEqual) r1 = ends[0];
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::eachCells(int r0, int c0, int r1, int c1, int type) {
Shinya Kitaoka 120a6e
  int nr = r1 - r0 + 1;
Shinya Kitaoka 120a6e
  int nc = c1 - c0 + 1;
Shinya Kitaoka 120a6e
  if (nr < type || nc <= 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int newRows = nr % type ? nr / type + 1 : nr / type;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int size = newRows * nc;
Shinya Kitaoka 120a6e
  assert(size > 0);
Shinya Kitaoka 120a6e
  std::unique_ptr<txshcell[]> cells(new TXshCell[size]);</txshcell[]>
Shinya Kitaoka 120a6e
  assert(cells);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i, j, k;
Shinya Kitaoka 120a6e
  for (j = r0, i = 0; i < size;
Shinya Kitaoka 120a6e
       j += type)  // in cells copio il contenuto delle celle che mi interessano
Shinya Kitaoka 120a6e
  {
Jaroslav 203cc8
    for (k = c0; k <= c1; k++, i++) cells[i] = getCell(CellPosition(j, k));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int c;
Shinya Kitaoka 120a6e
  for (c = c0; c <= c1; ++c) removeCells(r0 + newRows, c, nr - newRows);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = r0, k = 0; i < r0 + newRows && k < size; i++)
Shinya Kitaoka 120a6e
    for (j = c0; j <= c1; j++) {
Shinya Kitaoka 120a6e
      //----110523 iwasawa
Shinya Kitaoka 38fd86
      // Eachでできた空きセルに、操作前のセルの中身が残ってしまう不具合を修正
Shinya Kitaoka 120a6e
      if (cells[k].isEmpty())
Shinya Kitaoka 120a6e
        clearCells(i, j);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        setCell(i, j, cells[k]);
Shinya Kitaoka 120a6e
      k++;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! force cells order in n-steps. returns the row amount after process
Toshihiro Shimizu 890ddd
 */
shun-iwasawa 68b038
int TXsheet::reframeCells(int r0, int r1, int col, int step, int withBlank) {
Shinya Kitaoka 120a6e
  // Row amount in the selection
Shinya Kitaoka 120a6e
  int nr = r1 - r0 + 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (nr < 1) return 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QVector<txshcell> cells;</txshcell>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  cells.clear();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int r = r0; r <= r1; r++) {
Jaroslav 203cc8
    if (cells.size() == 0 || cells.last() != getCell(CellPosition(r, col)))
Jaroslav 203cc8
      cells.push_back(getCell(CellPosition(r, col)));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa aa65b8
  // if withBlank is greater than -1, remove empty cells from cell order
shun-iwasawa aa65b8
  if (withBlank >= 0) {
shun-iwasawa aa65b8
    auto itr = cells.begin();
shun-iwasawa aa65b8
    while (itr != cells.end()) {
shun-iwasawa aa65b8
      if ((*itr).isEmpty())
shun-iwasawa aa65b8
        itr = cells.erase(itr);
shun-iwasawa aa65b8
      else
shun-iwasawa aa65b8
        itr++;
shun-iwasawa aa65b8
    }
shun-iwasawa aa65b8
  }
shun-iwasawa aa65b8
Shinya Kitaoka 120a6e
  if (cells.empty()) return 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // row amount after n-step
shun-iwasawa 68b038
  int nrows = cells.size() * step;
Shinya Kitaoka 120a6e
shun-iwasawa aa65b8
  if (withBlank > 0) {
shun-iwasawa 68b038
    nrows += cells.size() * withBlank * step;
shun-iwasawa aa65b8
  }
shun-iwasawa aa65b8
Shinya Kitaoka 120a6e
  // if needed, insert cells
Shinya Kitaoka 120a6e
  if (nr < nrows) {
Shinya Kitaoka 120a6e
    insertCells(r1 + 1, col, nrows - nr);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // if needed, remove cells
Shinya Kitaoka 120a6e
  else if (nr > nrows) {
Shinya Kitaoka 120a6e
    removeCells(r0 + nrows, col, nr - nrows);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = r0, k = 0; i < r0 + nrows; k++) {
shun-iwasawa 68b038
    for (int i1 = 0; i1 < step; i1++) {
Shinya Kitaoka 120a6e
      if (cells[k].isEmpty())
Shinya Kitaoka 120a6e
        clearCells(i + i1, col);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        setCell(i + i1, col, cells[k]);
Shinya Kitaoka 120a6e
    }
shun-iwasawa 68b038
    i += step;  // dipende dal tipo di step (2 o 3 per ora)
shun-iwasawa aa65b8
shun-iwasawa aa65b8
    if (withBlank > 0) {
shun-iwasawa 68b038
      for (int i1 = 0; i1 < withBlank * step; i1++) {
shun-iwasawa aa65b8
        clearCells(i + i1, col);
shun-iwasawa aa65b8
      }
shun-iwasawa 68b038
      i += withBlank * step;
shun-iwasawa aa65b8
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return nrows;  // return row amount after process
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::resetStepCells(int r0, int c0, int r1, int c1) {
Shinya Kitaoka 120a6e
  int c, size = r1 - r0 + 1;
Shinya Kitaoka 120a6e
  for (c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
    int r = r0, i = 0;
Shinya Kitaoka 120a6e
    TXshCell *cells = new TXshCell[size];
Shinya Kitaoka 120a6e
    while (r <= r1) {
Shinya Kitaoka 120a6e
      // mi prendo le celle che mi servono
Jaroslav 203cc8
      cells[i] = getCell(CellPosition(r, c));
Shinya Kitaoka 120a6e
      r++;
Jaroslav 203cc8
      while (cells[i] == getCell(CellPosition(r, c)) && r <= r1) r++;
Shinya Kitaoka 120a6e
      i++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    size = i;
Shinya Kitaoka 120a6e
    removeCells(r0, c, r1 - r0 + 1);
Shinya Kitaoka 120a6e
    insertCells(r0, c, i);
Shinya Kitaoka 120a6e
    i = 0;
Shinya Kitaoka 120a6e
    r = r0;
Shinya Kitaoka 120a6e
    for (i = 0; i < size; i++, r++) setCell(r, c, cells[i]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Roll first cells of rect r0,c0,r1,c1. Move cells contained in first row to
Shinya Kitaoka 120a6e
 * last row.
shun-iwasawa 339c73
 */
Shinya Kitaoka 120a6e
void TXsheet::rollupCells(int r0, int c0, int r1, int c1) {
Shinya Kitaoka 120a6e
  int nc   = c1 - c0 + 1;
Shinya Kitaoka 120a6e
  int size = 1 * nc;
Shinya Kitaoka 120a6e
  assert(size > 0);
Shinya Kitaoka 120a6e
  std::unique_ptr<txshcell[]> cells(new TXshCell[size]);</txshcell[]>
Shinya Kitaoka 120a6e
  assert(cells);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // in cells copio il contenuto delle celle che mi interessano
Shinya Kitaoka 120a6e
  int k;
Jaroslav 203cc8
  for (k = c0; k <= c1; k++) cells[k - c0] = getCell(CellPosition(r0, k));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (k = c0; k <= c1; k++) removeCells(r0, k, 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (k = c0; k <= c1; k++) {
Shinya Kitaoka 120a6e
    insertCells(r1, k, 1);
Shinya Kitaoka 120a6e
    setCell(r1, k, cells[k - c0]);  // setto le celle
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Roll last cells of rect r0,c0,r1,c1. Move cells contained in last row to
Shinya Kitaoka 120a6e
 * first row.
shun-iwasawa 339c73
 */
Shinya Kitaoka 120a6e
void TXsheet::rolldownCells(int r0, int c0, int r1, int c1) {
Shinya Kitaoka 120a6e
  int nc   = c1 - c0 + 1;
Shinya Kitaoka 120a6e
  int size = 1 * nc;
Shinya Kitaoka 120a6e
  assert(size > 0);
Shinya Kitaoka 120a6e
  std::unique_ptr<txshcell[]> cells(new TXshCell[size]);</txshcell[]>
Shinya Kitaoka 120a6e
  assert(cells);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // in cells copio il contenuto delle celle che mi interessano
Shinya Kitaoka 120a6e
  int k;
Jaroslav 203cc8
  for (k = c0; k <= c1; k++) cells[k - c0] = getCell(CellPosition(r1, k));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (k = c0; k <= c1; k++) removeCells(r1, k, 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (k = c0; k <= c1; k++) {
Shinya Kitaoka 120a6e
    insertCells(r0, k, 1);
Shinya Kitaoka 120a6e
    setCell(r0, k, cells[k - c0]);  // setto le celle
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Stretch cells contained in rect r0,c0,r1,c1, from r1-r0+1 to nr.
luzpaz 27707d
                If nr>r1-r0+1 add cells, otherwise remove cells. */
Shinya Kitaoka 120a6e
void TXsheet::timeStretch(int r0, int c0, int r1, int c1, int nr) {
Shinya Kitaoka 120a6e
  int oldNr = r1 - r0 + 1;
Shinya Kitaoka 120a6e
  if (nr > oldNr) /* ingrandisce */
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    int c;
Shinya Kitaoka 120a6e
    for (c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
      int dn = nr - oldNr;
Shinya Kitaoka 120a6e
      assert(oldNr > 0);
Shinya Kitaoka 120a6e
      std::unique_ptr<txshcell[]> cells(new TXshCell[oldNr]);</txshcell[]>
Shinya Kitaoka 120a6e
      assert(cells);
Shinya Kitaoka 120a6e
      getCells(r0, c, oldNr, cells.get());
Shinya Kitaoka 120a6e
      insertCells(r0 + 1, c, dn);
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      for (i = nr - 1; i >= 0; i--) {
Shinya Kitaoka 120a6e
        int j = i * double(oldNr) / double(nr);
Shinya Kitaoka 120a6e
        if (j < i) setCell(i + r0, c, cells[j]);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else /* rimpicciolisce */
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    int c;
Shinya Kitaoka 120a6e
    for (c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
      int dn = oldNr - nr;
Shinya Kitaoka 120a6e
      std::unique_ptr<txshcell[]> cells(new TXshCell[oldNr]);</txshcell[]>
Shinya Kitaoka 120a6e
      assert(cells);
Shinya Kitaoka 120a6e
      getCells(r0, c, oldNr, cells.get());
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      for (i = 0; i < nr; i++) {
Shinya Kitaoka 120a6e
        int j = i * double(oldNr) / double(nr);
Shinya Kitaoka 120a6e
        if (j > i) setCell(i + r0, c, cells[j]);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      removeCells(r1 - dn + 1, c, dn);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
int TXsheet::exposeLevel(int row, int col, TXshLevel *xl, bool overwrite) {
Shinya Kitaoka 120a6e
  if (!xl) return 0;
Shinya Kitaoka 120a6e
  std::vector<tframeid> fids;</tframeid>
Shinya Kitaoka 120a6e
  xl->getFids(fids);
Shinya Kitaoka 120a6e
  int frameCount = 1;
Shinya Kitaoka 120a6e
  if (fids.empty()) {
Shinya Kitaoka 120a6e
    setCell(row, col, TXshCell(xl, TFrameId(1)));
Shinya Kitaoka 120a6e
    updateFrameCount();
Shinya Kitaoka 120a6e
    return frameCount;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  exposeLevel(row, col, xl, fids, overwrite);
Shinya Kitaoka 120a6e
  return (int)fids.size();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// customized version for load level popup
Shinya Kitaoka 120a6e
int TXsheet::exposeLevel(int row, int col, TXshLevel *xl,
shun-iwasawa ef0f8b
                         std::vector<tframeid> &fIds_, TFrameId xFrom,</tframeid>
shun-iwasawa ef0f8b
                         TFrameId xTo, int step, int inc, int frameCount,
Shinya Kitaoka 120a6e
                         bool doesFileActuallyExist) {
Shinya Kitaoka 120a6e
  if (!xl) return 0;
Shinya Kitaoka 120a6e
  std::vector<tframeid> fids;</tframeid>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (doesFileActuallyExist)
Shinya Kitaoka 120a6e
    xl->getFids(fids);
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)fIds_.size(); i++) {
Shinya Kitaoka 120a6e
      fids.push_back(fIds_[i]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // multiple exposing
Shinya Kitaoka 120a6e
  if (frameCount < 0 || xFrom < 0 || xTo < 0 || step < 0 || inc < 0) {
Shinya Kitaoka 120a6e
    insertCells(row, col, xl->getFrameCount());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    frameCount = 1;
Shinya Kitaoka 120a6e
    if (fids.empty())
Shinya Kitaoka 120a6e
      setCell(row, col, TXshCell(xl, TFrameId(1)));
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      frameCount = (int)fids.size();
Shinya Kitaoka 120a6e
      insertCells(row, col, frameCount);
Shinya Kitaoka 120a6e
      std::vector<tframeid>::iterator it;</tframeid>
Shinya Kitaoka 120a6e
      for (it = fids.begin(); it != fids.end(); ++it)
Shinya Kitaoka 120a6e
        setCell(row++, col, TXshCell(xl, *it));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    updateFrameCount();
Shinya Kitaoka 120a6e
    return frameCount;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // single exposing
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  insertCells(row, col, frameCount);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (fids.empty()) {
Shinya Kitaoka 120a6e
    setCell(row, col, TXshCell(xl, TFrameId(1)));
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (inc == 0)  // inc = Auto
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      std::vector<tframeid>::iterator it;</tframeid>
Shinya Kitaoka 120a6e
      it = fids.begin();
shun-iwasawa ef0f8b
      while (*it < xFrom) it++;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (step == 0)  // Step = Auto
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        std::vector<tframeid>::iterator next_it;</tframeid>
Shinya Kitaoka 120a6e
        next_it = it;
Shinya Kitaoka 120a6e
        next_it++;
shun-iwasawa ef0f8b
        for (int f = 0; f < frameCount; f++) {
shun-iwasawa ef0f8b
          setCell(row++, col, TXshCell(xl, *it));
shun-iwasawa ef0f8b
          if (next_it != fids.end()) {
Shinya Kitaoka 120a6e
            it++;
Shinya Kitaoka 120a6e
            next_it++;
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      else  // Step != Auto
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        int loopCount = frameCount / step;
Shinya Kitaoka 120a6e
        for (int loop = 0; loop < loopCount; loop++) {
Shinya Kitaoka 120a6e
          for (int s = 0; s < step; s++) {
Shinya Kitaoka 120a6e
            setCell(row++, col, TXshCell(xl, *it));
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
          it++;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    } else  // inc != Auto
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      int loopCount;
Shinya Kitaoka 120a6e
      if (step == 0)  // Step = Auto
Shinya Kitaoka 120a6e
        step = inc;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      loopCount = frameCount / step;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      for (int loop = 0; loop < loopCount; loop++) {
shun-iwasawa ef0f8b
        TFrameId id(xFrom.getNumber() + loop * inc, xFrom.getLetter());
Shinya Kitaoka 120a6e
        for (int s = 0; s < step; s++) {
Shinya Kitaoka 120a6e
          setCell(row++, col, TXshCell(xl, id));
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateFrameCount();
Shinya Kitaoka 120a6e
  return frameCount;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::exposeLevel(int row, int col, TXshLevel *xl,
Shinya Kitaoka 120a6e
                          std::vector<tframeid> fids, bool overwrite) {</tframeid>
Shinya Kitaoka 120a6e
  int frameCount = (int)fids.size();
Shinya Kitaoka 120a6e
  if (!overwrite) insertCells(row, col, frameCount);
Shinya Kitaoka 120a6e
  std::vector<tframeid>::iterator it;</tframeid>
Shinya Kitaoka 120a6e
  for (it = fids.begin(); it != fids.end(); ++it)
Shinya Kitaoka 120a6e
    setCell(row++, col, TXshCell(xl, *it));
Shinya Kitaoka 120a6e
  updateFrameCount();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::updateFrameCount() {
Shinya Kitaoka 120a6e
  m_imp->m_frameCount = 0;
Shinya Kitaoka 120a6e
  for (int i = 0; i < m_imp->m_columnSet.getColumnCount(); ++i) {
Shinya Kitaoka 120a6e
    TXshColumnP cc = m_imp->m_columnSet.getColumn(i);
Shinya Kitaoka 120a6e
    if (cc && !cc->isEmpty())
Shinya Kitaoka 120a6e
      m_imp->m_frameCount =
Shinya Kitaoka 120a6e
          std::max(m_imp->m_frameCount, cc->getMaxFrame() + 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  clearAll();
Shinya Kitaoka 120a6e
  TStageObjectId cameraId   = TStageObjectId::CameraId(0);
Shinya Kitaoka 120a6e
  TStageObject *firstCamera = getStageObject(cameraId);
Shinya Kitaoka 120a6e
  m_imp->m_pegTree->removeStageObject(cameraId);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int col = 0;
Shinya Kitaoka 120a6e
  string tagName;
Shinya Kitaoka 120a6e
  while (is.openChild(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "columns") {
Shinya Kitaoka 120a6e
      while (!is.eos()) {
Shinya Kitaoka 120a6e
        TPersist *p = 0;
Shinya Kitaoka 120a6e
        is >> p;
Shinya Kitaoka 120a6e
        TXshColumn *column = dynamic_cast<txshcolumn *="">(p);</txshcolumn>
Shinya Kitaoka 120a6e
        if (!column) throw TException("expected xsheet column");
Shinya Kitaoka 120a6e
        m_imp->m_columnSet.insertColumn(col++, column);
Shinya Kitaoka 120a6e
        column->setXsheet(this);
Shinya Kitaoka 120a6e
        if (TXshZeraryFxColumn *zc =
Shinya Kitaoka 120a6e
                dynamic_cast<txshzeraryfxcolumn *="">(column)) {</txshzeraryfxcolumn>
Shinya Kitaoka 120a6e
          TFx *fx         = zc->getZeraryColumnFx()->getZeraryFx();
Shinya Kitaoka 120a6e
          int fxTypeCount = m_imp->m_fxDag->getFxTypeCount(fx);
Shinya Kitaoka 120a6e
          int maxFxTypeId = std::max(fxTypeCount, fx->getAttributes()->getId());
Shinya Kitaoka 120a6e
          m_imp->m_fxDag->updateFxTypeTable(fx, maxFxTypeId);
Shinya Kitaoka 120a6e
          m_imp->m_fxDag->updateFxIdTable(fx);
Shinya Kitaoka 120a6e
          for (int j = 0; j < fx->getParams()->getParamCount(); j++) {
Shinya Kitaoka 120a6e
            TParam *param = fx->getParams()->getParam(j);
Shinya Kitaoka 120a6e
            if (TDoubleParam *dp = dynamic_cast<tdoubleparam *="">(param))</tdoubleparam>
Shinya Kitaoka 120a6e
              getStageObjectTree()->setGrammar(dp);
Shinya Kitaoka 120a6e
            else if (dynamic_cast<tpointparam *="">(param) ||</tpointparam>
Shinya Kitaoka 120a6e
                     dynamic_cast<trangeparam *="">(param) ||</trangeparam>
Shinya Kitaoka 120a6e
                     dynamic_cast<tpixelparam *="">(param)) {</tpixelparam>
Shinya Kitaoka 120a6e
              TParamSet *paramSet = dynamic_cast<tparamset *="">(param);</tparamset>
Shinya Kitaoka 120a6e
              assert(paramSet);
Shinya Kitaoka 120a6e
              int f;
Shinya Kitaoka 120a6e
              for (f = 0; f < paramSet->getParamCount(); f++) {
Shinya Kitaoka 120a6e
                TDoubleParam *dp = dynamic_cast<tdoubleparam *="">(</tdoubleparam>
Shinya Kitaoka 120a6e
                    paramSet->getParam(f).getPointer());
Shinya Kitaoka 120a6e
                if (!dp) continue;
Shinya Kitaoka 120a6e
                getStageObjectTree()->setGrammar(dp);
Shinya Kitaoka 120a6e
              }
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
shun-iwasawa f84c65
    } else if (tagName == "cameraColumn") {
shun-iwasawa f84c65
      while (is.openChild(tagName)) {
shun-iwasawa f84c65
        if (!m_cameraColumn->getCellColumn()->loadCellMarks(tagName, is))
shun-iwasawa f84c65
          throw TException("Camera Column, unknown tag: " + tagName);
shun-iwasawa f84c65
        is.closeChild();
shun-iwasawa f84c65
      }
Shinya Kitaoka 120a6e
    } else if (tagName == "pegbars") {
Shinya Kitaoka 120a6e
      TPersist *p = m_imp->m_pegTree;
manongjohn 4334db
      m_imp->m_pegTree->loadData(is, this);
Shinya Kitaoka 120a6e
    } else if (tagName == "fxnodes") {
Shinya Kitaoka 120a6e
      m_imp->m_fxDag->loadData(is);
Shinya Kitaoka 120a6e
      std::vector<tfx *=""> fxs;</tfx>
Shinya Kitaoka 120a6e
      m_imp->m_fxDag->getFxs(fxs);
Shinya Kitaoka 120a6e
      for (int i = 0; i < (int)fxs.size(); i++) {
Shinya Kitaoka 120a6e
        TFx *fx = fxs[i];
Shinya Kitaoka 120a6e
        for (int j = 0; j < fx->getParams()->getParamCount(); j++) {
Shinya Kitaoka 120a6e
          TParam *param = fx->getParams()->getParam(j);
Shinya Kitaoka 120a6e
          if (TDoubleParam *dp = dynamic_cast<tdoubleparam *="">(param))</tdoubleparam>
Shinya Kitaoka 120a6e
            getStageObjectTree()->setGrammar(dp);
Shinya Kitaoka 120a6e
          else if (dynamic_cast<tpointparam *="">(param) ||</tpointparam>
Shinya Kitaoka 120a6e
                   dynamic_cast<trangeparam *="">(param) ||</trangeparam>
Shinya Kitaoka 120a6e
                   dynamic_cast<tpixelparam *="">(param)) {</tpixelparam>
Shinya Kitaoka 120a6e
            TParamSet *paramSet = dynamic_cast<tparamset *="">(param);</tparamset>
Shinya Kitaoka 120a6e
            assert(paramSet);
Shinya Kitaoka 120a6e
            int f;
Shinya Kitaoka 120a6e
            for (f = 0; f < paramSet->getParamCount(); f++) {
Shinya Kitaoka 120a6e
              TDoubleParam *dp = dynamic_cast<tdoubleparam *="">(</tdoubleparam>
Shinya Kitaoka 120a6e
                  paramSet->getParam(f).getPointer());
Shinya Kitaoka 120a6e
              if (!dp) continue;
Shinya Kitaoka 120a6e
              getStageObjectTree()->setGrammar(dp);
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (is.matchEndTag()) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // was ist dass?
Shinya Kitaoka 120a6e
      TFxSet fxSet;
Shinya Kitaoka 120a6e
      fxSet.loadData(is);
Shinya Kitaoka 120a6e
    } else if (tagName == "columnFan") {
Jaroslav 203cc8
      m_imp->m_columnFans[0].loadData(is);
Jaroslav 203cc8
      m_imp->copyFoldedState();
Shinya Kitaoka 120a6e
    } else if (tagName == "noteSet") {
Shinya Kitaoka 120a6e
      m_notes->loadData(is);
manongjohn 8404a6
    } else if (tagName == "navigationTags") {
manongjohn 8404a6
      m_navigationTags->loadData(is);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      throw TException("xsheet, unknown tag: " + tagName);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    is.closeChild();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateFrameCount();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TXsheet::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.openChild("columns");
Shinya Kitaoka 120a6e
  for (int c = 0; c < m_imp->m_columnSet.getColumnCount(); ++c) {
Shinya Kitaoka 120a6e
    TXshColumnP column = m_imp->m_columnSet.getColumn(c);
Shinya Kitaoka 120a6e
    if (column && c < getFirstFreeColumnIndex()) os << column.getPointer();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  os.closeChild();
shun-iwasawa f84c65
shun-iwasawa f84c65
  // save cell marks in the camera column
shun-iwasawa f84c65
  if (!m_cameraColumn->getCellColumn()->getCellMarks().isEmpty()) {
shun-iwasawa f84c65
    os.openChild("cameraColumn");
shun-iwasawa f84c65
    m_cameraColumn->getCellColumn()->saveCellMarks(os);
shun-iwasawa f84c65
    os.closeChild();
shun-iwasawa f84c65
  }
shun-iwasawa f84c65
Shinya Kitaoka 120a6e
  os.openChild("pegbars");
manongjohn 4334db
  m_imp->m_pegTree->saveData(os, getFirstFreeColumnIndex(), this);
Shinya Kitaoka 120a6e
  // os << *(m_imp->m_pegTree);
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FxDag *fxDag = getFxDag();
Shinya Kitaoka 120a6e
  os.openChild("fxnodes");
Shinya Kitaoka 120a6e
  fxDag->saveData(os, getFirstFreeColumnIndex());
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
Jaroslav 203cc8
  // does not matter which Orientation to take, as all fans share folded data
Jaroslav 203cc8
  ColumnFan *columnFan = getColumnFan(Orientations::topToBottom());
Shinya Kitaoka 120a6e
  if (!columnFan->isEmpty()) {
Shinya Kitaoka 120a6e
    os.openChild("columnFan");
Shinya Kitaoka 120a6e
    columnFan->saveData(os);
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TXshNoteSet *notes = getNotes();
Shinya Kitaoka 120a6e
  if (notes->getCount() > 0) {
Shinya Kitaoka 120a6e
    os.openChild("noteSet");
Shinya Kitaoka 120a6e
    notes->saveData(os);
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
manongjohn 8404a6
manongjohn 8404a6
  NavigationTags *navigationTags = getNavigationTags();
manongjohn 8404a6
  if (navigationTags->getCount() > 0) {
manongjohn 8404a6
    os.openChild("navigationTags");
manongjohn 8404a6
    navigationTags->saveData(os);
manongjohn 8404a6
    os.closeChild();
manongjohn 8404a6
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TXsheet, "xsheet")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::insertColumn(int col, TXshColumn::ColumnType type) {
Shinya Kitaoka 120a6e
  insertColumn(col, TXshColumn::createEmpty(type));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::insertColumn(int col, TXshColumn *column) {
John Dancel 421acd
  if (col < 0) col = 0;
Shinya Kitaoka 120a6e
  column->setXsheet(this);
Shinya Kitaoka 120a6e
  m_imp->m_columnSet.insertColumn(col, column);
Shinya Kitaoka 120a6e
  m_imp->m_pegTree->insertColumn(col);
Shinya Kitaoka 120a6e
  if (column->getPaletteColumn() ==
Shinya Kitaoka 120a6e
      0)  // palette column are not connected to the xsheet fx node
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    TFx *fx = column->getFx();
Shinya Kitaoka 120a6e
    if (fx) getFxDag()->addToXsheet(fx);
Shinya Kitaoka 120a6e
  }
shun-iwasawa 98258e
shun-iwasawa 98258e
  for (ColumnFan &columnFan : m_imp->m_columnFans) {
shun-iwasawa 98258e
    columnFan.rollRightFoldedState(col,
shun-iwasawa 98258e
                                   m_imp->m_columnSet.getColumnCount() - col);
shun-iwasawa 98258e
  }
shun-iwasawa 4a3868
shun-iwasawa 4a3868
  notify(TXsheetColumnChange(TXsheetColumnChange::Insert, col));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::removeColumn(int col) {
Shinya Kitaoka 120a6e
  TXshColumn *column = getColumn(col);
Shinya Kitaoka 120a6e
  if (column) {
Shinya Kitaoka 120a6e
    TFx *fx = column->getFx();
Shinya Kitaoka 120a6e
    if (fx) {
Shinya Kitaoka 120a6e
      getFxDag()->removeFromXsheet(fx);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      // disconnetto dal columnFx tutti gli effetti connessi in uscita
Shinya Kitaoka 120a6e
      TFxPort *outPort = 0;
Shinya Kitaoka 120a6e
      while ((outPort = fx->getOutputConnection(0))) outPort->setFx(0);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_imp->m_columnSet.removeColumn(col);
Shinya Kitaoka 120a6e
  m_imp->m_pegTree->removeColumn(col);
shun-iwasawa 98258e
shun-iwasawa 98258e
  for (ColumnFan &columnFan : m_imp->m_columnFans) {
shun-iwasawa 98258e
    columnFan.rollLeftFoldedState(col,
shun-iwasawa 98258e
                                  m_imp->m_columnSet.getColumnCount() - col);
shun-iwasawa 98258e
  }
shun-iwasawa 4a3868
shun-iwasawa 4a3868
  notify(TXsheetColumnChange(TXsheetColumnChange::Remove, col));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::moveColumn(int srcIndex, int dstIndex) {
Shinya Kitaoka 120a6e
  if (srcIndex == dstIndex) return;
Shinya Kitaoka 120a6e
  assert(srcIndex >= 0);
Shinya Kitaoka 120a6e
  assert(dstIndex >= 0);
Shinya Kitaoka 120a6e
  int col = std::max(srcIndex, dstIndex);
Shinya Kitaoka 120a6e
  if (col >= m_imp->m_columnSet.getColumnCount()) {
Shinya Kitaoka 120a6e
    int n = m_imp->m_columnSet.getColumnCount();
Shinya Kitaoka 120a6e
    touchColumn(col, TXshColumn::eLevelType);
Shinya Kitaoka 120a6e
    while (n <= col) {
Shinya Kitaoka 120a6e
      TXshColumn *column = getColumn(n);
Shinya Kitaoka 120a6e
      assert(column);
Shinya Kitaoka 120a6e
      column->setXsheet(this);
Shinya Kitaoka 120a6e
      n++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  assert(m_imp->m_columnSet.getColumnCount() > srcIndex);
Shinya Kitaoka 120a6e
  assert(m_imp->m_columnSet.getColumnCount() > dstIndex);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (srcIndex < dstIndex) {
Shinya Kitaoka 120a6e
    int c0 = srcIndex;
Shinya Kitaoka 120a6e
    int c1 = dstIndex;
Shinya Kitaoka 120a6e
    assert(c0 < c1);
Shinya Kitaoka 120a6e
    m_imp->m_columnSet.rollLeft(c0, c1 - c0 + 1);
shun-iwasawa 98258e
    for (ColumnFan &columnFan : m_imp->m_columnFans)
shun-iwasawa 98258e
      columnFan.rollLeftFoldedState(c0, c1 - c0 + 1);
Shinya Kitaoka 120a6e
    for (int c = c0; c < c1; ++c) m_imp->m_pegTree->swapColumns(c, c + 1);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    int c0 = dstIndex;
Shinya Kitaoka 120a6e
    int c1 = srcIndex;
Shinya Kitaoka 120a6e
    assert(c0 < c1);
Shinya Kitaoka 120a6e
    m_imp->m_columnSet.rollRight(c0, c1 - c0 + 1);
shun-iwasawa 98258e
    for (ColumnFan &columnFan : m_imp->m_columnFans)
shun-iwasawa 98258e
      columnFan.rollRightFoldedState(c0, c1 - c0 + 1);
Shinya Kitaoka 120a6e
    for (int c = c1 - 1; c >= c0; --c) m_imp->m_pegTree->swapColumns(c, c + 1);
Shinya Kitaoka 120a6e
  }
shun-iwasawa 4a3868
shun-iwasawa 4a3868
  notify(TXsheetColumnChange(TXsheetColumnChange::Move, srcIndex, dstIndex));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn *TXsheet::getColumn(int col) const {
manongjohn 4334db
  if (col < 0) return m_cameraColumn;
Shinya Kitaoka 120a6e
  return m_imp->m_columnSet.getColumn(col).getPointer();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TXsheet::getColumnCount() const {
Shinya Kitaoka 120a6e
  return m_imp->m_columnSet.getColumnCount();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TXsheet::getFirstFreeColumnIndex() const {
Shinya Kitaoka 120a6e
  int i = getColumnCount();
Shinya Kitaoka 120a6e
  while (i > 0 && isColumnEmpty(i - 1)) --i;
Shinya Kitaoka 120a6e
  return i;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn *TXsheet::touchColumn(int index, TXshColumn::ColumnType type) {
Shinya Kitaoka 120a6e
  TXshColumn *column = m_imp->m_columnSet.touchColumn(index, type).getPointer();
John Dancel 421acd
  if (index < 0 || !column) return 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // NOTE (Daniele): The following && should be a bug... but I fear I'd break
Shinya Kitaoka 120a6e
  // something changing it.
Shinya Kitaoka 120a6e
  // Observe that the implied behavior is that of REPLACING AN EXISTING
Shinya Kitaoka 120a6e
  // LEGITIMATE COLUMN!
Shinya Kitaoka 120a6e
  // Please, Inquire further if you're not upon release!
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (column->isEmpty() && column->getColumnType() != type) {
Shinya Kitaoka 120a6e
    removeColumn(index);
Shinya Kitaoka 120a6e
    insertColumn(index, type);
Shinya Kitaoka 120a6e
    column = getColumn(index);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return column;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
namespace {  // Utility function
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void searchAudioColumn(TXsheet *xsh, std::vector<txshsoundcolumn *=""> &sounds,</txshsoundcolumn>
Shinya Kitaoka 120a6e
                       bool isPreview = true) {
Shinya Kitaoka 120a6e
  int i       = 0;
Shinya Kitaoka 120a6e
  int columns = xsh->getColumnCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (; i < columns; ++i) {
Shinya Kitaoka 120a6e
    TXshColumn *column = xsh->getColumn(i);
Shinya Kitaoka 120a6e
    if (column) {
Shinya Kitaoka 120a6e
      TXshSoundColumn *soundCol = column->getSoundColumn();
shun-iwasawa 339c73
      if (soundCol && !soundCol->isEmpty() &&
shun-iwasawa 339c73
          ((isPreview && soundCol->isCamstandVisible()) ||
shun-iwasawa 339c73
           (!isPreview && soundCol->isPreviewVisible()))) {
Shinya Kitaoka 120a6e
        sounds.push_back(soundCol);
Shinya Kitaoka 120a6e
        continue;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundTrack *TXsheet::makeSound(SoundProperties *properties) {
Shinya Kitaoka 120a6e
  std::vector<txshsoundcolumn *=""> sounds;</txshsoundcolumn>
Shinya Kitaoka 120a6e
  searchAudioColumn(this, sounds, properties->m_isPreview);
Shinya Kitaoka 120a6e
  if (!m_imp->m_mixedSound || *properties != *m_soundProperties) {
Shinya Kitaoka 120a6e
    if (!sounds.empty() && properties->m_fromFrame <= properties->m_toFrame)
Shinya Kitaoka 120a6e
      m_imp->m_mixedSound = sounds[0]->mixingTogether(
Shinya Kitaoka 120a6e
          sounds, properties->m_fromFrame, properties->m_toFrame,
Shinya Kitaoka 120a6e
          properties->m_frameRate);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_imp->m_mixedSound = 0;
Shinya Kitaoka 120a6e
    delete m_soundProperties;
Shinya Kitaoka 120a6e
    m_soundProperties = properties;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    delete properties;
Shinya Kitaoka 120a6e
  return m_imp->m_mixedSound.getPointer();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::scrub(int frame, bool isPreview) {
Toondad 9c4638
  try {
Toondad 9c4638
    double fps =
shun-iwasawa 4a3868
        getScene()->getProperties()->getOutputProperties()->getFrameRate();
Toshihiro Shimizu 890ddd
Toondad 9c4638
    TXsheet::SoundProperties *prop = new TXsheet::SoundProperties();
Toondad 9c4638
    prop->m_isPreview              = isPreview;
Toshihiro Shimizu 890ddd
Toondad 9c4638
    TSoundTrack *st = makeSound(prop);  // Absorbs prop's ownership
Toondad 9c4638
    if (!st) return;
Toshihiro Shimizu 890ddd
Toondad 9c4638
    double samplePerFrame = st->getSampleRate() / fps;
Toshihiro Shimizu 890ddd
Toondad 9c4638
    double s0 = frame * samplePerFrame, s1 = s0 + samplePerFrame;
Jeremy Bullock 57507e
    // if (m_player && m_player->isPlaying()) {
Jeremy Bullock 57507e
    //    try {
Jeremy Bullock 57507e
    //        m_player->stop();
Jeremy Bullock 57507e
    //    }
Jeremy Bullock 57507e
    //    catch (const std::runtime_error& e) {
Jeremy Bullock 57507e
    //        int i = 0;
Jeremy Bullock 57507e
    //    }
Jeremy Bullock 57507e
    //    catch (const std::exception& e) {
Jeremy Bullock 57507e
    //        int i = 0;
Jeremy Bullock 57507e
    //    }
Jeremy Bullock 57507e
    //    catch (...) {
Jeremy Bullock 57507e
    //        int i = 0;
Jeremy Bullock 57507e
    //    }
Jeremy Bullock 57507e
    //}
Toondad 9c4638
    play(st, s0, s1, false);
Toondad 9c4638
  } catch (TSoundDeviceException &e) {
Toondad 9c4638
    if (e.getType() == TSoundDeviceException::NoDevice) {
Toondad 9c4638
      std::cout << ::to_string(e.getMessage()) << std::endl;
Toondad 9c4638
    } else {
Toondad 9c4638
      throw TSoundDeviceException(e.getType(), e.getMessage());
Toondad 9c4638
    }
Toondad 9c4638
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::stopScrub() {
Shinya Kitaoka 120a6e
  if (m_player) m_player->stop();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::play(TSoundTrackP soundtrack, int s0, int s1, bool loop) {
Shinya Kitaoka 120a6e
  if (!TSoundOutputDevice::installed()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!m_player) m_player = new TSoundOutputDevice();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_player) {
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      m_player->play(soundtrack, s0, s1, loop);
Shinya Kitaoka 120a6e
    } catch (TSoundDeviceException &) {
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FxDag *TXsheet::getFxDag() const { return m_imp->m_fxDag; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jaroslav 203cc8
ColumnFan *TXsheet::getColumnFan(const Orientation *o) const {
Jaroslav 203cc8
  int index = o->dimension(PredefinedDimension::INDEX);
Jaroslav 203cc8
  return &m_imp->m_columnFans[index];
Jaroslav 203cc8
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ToonzScene *TXsheet::getScene() const { return m_imp->m_scene; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::setScene(ToonzScene *scene) { m_imp->m_scene = scene; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::checkCircularReferences(const TXshCell &cellCandidate) {
Shinya Kitaoka 120a6e
  if (cellCandidate.isEmpty() || !cellCandidate.m_level->getChildLevel())
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  TXsheet *childCandidate = cellCandidate.m_level->getChildLevel()->getXsheet();
Shinya Kitaoka 120a6e
  return checkCircularReferences(childCandidate);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::checkCircularReferences(TXshColumn *columnCandidate) {
Shinya Kitaoka 120a6e
  if (!columnCandidate || !columnCandidate->getLevelColumn()) return false;
Shinya Kitaoka 120a6e
  TXshLevelColumn *lc = columnCandidate->getLevelColumn();
Shinya Kitaoka 120a6e
  int r0 = 0, r1 = -1;
Shinya Kitaoka 120a6e
  if (lc->getRange(r0, r1) <= 0) return false;
Shinya Kitaoka 120a6e
  int r;
Shinya Kitaoka 120a6e
  TXshCell oldCell;
Shinya Kitaoka 120a6e
  for (r = r0; r <= r1; r++) {
Shinya Kitaoka 120a6e
    TXshCell cell = lc->getCell(r);
Shinya Kitaoka 120a6e
    // to speed up:
Shinya Kitaoka 120a6e
    if (cell.m_level.getPointer() == oldCell.m_level.getPointer()) continue;
Shinya Kitaoka 120a6e
    if (checkCircularReferences(cell)) return true;
Shinya Kitaoka 120a6e
    oldCell = cell;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXsheet::invalidateSound() { m_imp->m_mixedSound = TSoundTrackP(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXsheet::checkCircularReferences(TXsheet *childCandidate) {
Shinya Kitaoka 120a6e
  if (this == childCandidate) return true;
Shinya Kitaoka 120a6e
  if (childCandidate == 0) return false;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < childCandidate->getColumnCount(); i++)
Shinya Kitaoka 120a6e
    if (checkCircularReferences(childCandidate->getColumn(i))) return true;
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Builds the camstand bbox associated to the specified xsheet
Shinya Kitaoka 120a6e
TRectD TXsheet::getBBox(int r) const {
Shinya Kitaoka 120a6e
  static const double maxDouble = (std::numeric_limits<double>::max)();</double>
Shinya Kitaoka 120a6e
  static const TRectD voidRect(maxDouble, maxDouble, -maxDouble, -maxDouble);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  struct locals {
Shinya Kitaoka 120a6e
    static TRectD getBBox(const TXsheet *xsh, int r, int c) {
Shinya Kitaoka 120a6e
      // Discriminate cell content
Jaroslav 203cc8
      const TXshCell &cell = xsh->getCell(CellPosition(r, c));
Shinya Kitaoka 120a6e
      if (cell.isEmpty()) return voidRect;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (TXshChildLevel *cl = cell.getChildLevel())
Shinya Kitaoka 120a6e
        return cl->getXsheet()->getBBox(cell.getFrameId().getNumber() - 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TXshSimpleLevel *sl = cell.getSimpleLevel();
Shinya Kitaoka 120a6e
      if (!sl ||
Shinya Kitaoka 120a6e
          !(sl->getType() &
Shinya Kitaoka 120a6e
            LEVELCOLUMN_XSHLEVEL))  // Avoid other mesh levels - which could
Shinya Kitaoka 120a6e
        return voidRect;            // be deformed too...
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // Retrieve column affine
Shinya Kitaoka 120a6e
      TAffine columnZaff;
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        TStageObject *colObj = xsh->getStageObject(TStageObjectId::ColumnId(c));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        const TAffine &columnAff = colObj->getPlacement(r);  // ...
Shinya Kitaoka 120a6e
        double columnZ           = colObj->getZ(r);          // ...
Shinya Kitaoka 120a6e
        double columnNoScaleZ    = colObj->getGlobalNoScaleZ();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        TStageObjectId cameraId =
Shinya Kitaoka 120a6e
            xsh->getStageObjectTree()->getCurrentCameraId();
Shinya Kitaoka 120a6e
        TStageObject *camera = xsh->getStageObject(cameraId);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        const TAffine &cameraAff = camera->getPlacement(r);  // ...
Shinya Kitaoka 120a6e
        double cameraZ           = camera->getZ(r);          // ...
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        if (!TStageObject::perspective(columnZaff, cameraAff, cameraZ,
Shinya Kitaoka 120a6e
                                       columnAff, columnZ, columnNoScaleZ))
Shinya Kitaoka 120a6e
          return voidRect;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      const TRectD &bbox = sl->getBBox(cell.getFrameId());
Shinya Kitaoka 120a6e
      if (bbox.getLx() <= 0.0 || bbox.getLy() <= 0.0) return voidRect;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      return columnZaff * TScale(Stage::inch, Stage::inch) * bbox;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //-----------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Initialize a union-neutral rect
Shinya Kitaoka 120a6e
  TRectD bbox(voidRect);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Traverse the xsheet's columns, adding the bbox of each
Shinya Kitaoka 120a6e
  int c, cCount = getColumnCount();
Shinya Kitaoka 120a6e
  for (c = 0; c != cCount; ++c) {
Shinya Kitaoka 120a6e
    // Skip empty or invisible columns
Shinya Kitaoka 120a6e
    TXshColumn *column = getColumn(c);
Shinya Kitaoka 120a6e
    if (column->isEmpty() || !column->isCamstandVisible()) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    const TRectD &colBBox = locals::getBBox(this, r, c);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Make the union
Shinya Kitaoka 120a6e
    bbox.x0 = std::min(bbox.x0, colBBox.x0);
Shinya Kitaoka 120a6e
    bbox.y0 = std::min(bbox.y0, colBBox.y0);
Shinya Kitaoka 120a6e
    bbox.x1 = std::max(bbox.x1, colBBox.x1);
Shinya Kitaoka 120a6e
    bbox.y1 = std::max(bbox.y1, colBBox.y1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return bbox;
Toshihiro Shimizu 890ddd
}
shun-iwasawa 5e2a8f
shun-iwasawa 5e2a8f
//-----------------------------------------------------------------------
shun-iwasawa 5e2a8f
Jaroslav 203cc8
bool TXsheet::isRectEmpty(const CellPosition &pos0,
Jaroslav 203cc8
                          const CellPosition &pos1) const {
Jaroslav 203cc8
  for (int frame = pos0.frame(); frame <= pos1.frame(); frame++)
Jaroslav 203cc8
    for (int layer = pos0.layer(); layer <= pos1.layer(); layer++)
Jaroslav 203cc8
      if (!getCell(CellPosition(frame, layer)).isEmpty()) return false;
shun-iwasawa 5e2a8f
  return true;
shun-iwasawa 947ad3
}
shun-iwasawa 947ad3
shun-iwasawa 947ad3
//-----------------------------------------------------------------------
shun-iwasawa 947ad3
// Function triggered by AutoInputCellNumberPopup.
shun-iwasawa 947ad3
// executing this on column selection, set r1 = -1.
shun-iwasawa 947ad3
// Here are the expected behaviors
shun-iwasawa 947ad3
// 1. Cell Selection + Overwrite
shun-iwasawa 947ad3
//    Cells will be input from the top of the selected range.
shun-iwasawa 947ad3
//    New arrangement CANNOT run over the selected range.
shun-iwasawa 947ad3
//    If the new arrangement is shorter than the selected range,
shun-iwasawa 947ad3
//    excess cells will not be cleared but keep their contents.
shun-iwasawa 947ad3
//    (It is the same behavior as Celsys' QuickChecker)
shun-iwasawa 947ad3
// 2. Cell Selection + Insert
shun-iwasawa 947ad3
//    New arrangement will be inserted before the selected range.
shun-iwasawa 947ad3
//    If the selected range has multiple columns, then the inserted
shun-iwasawa 947ad3
//    cells will be expanded to the longest arrangement with empty cells.
shun-iwasawa 947ad3
// 3. Column Selection + Overwrite
shun-iwasawa 947ad3
//    Cells will be input from the top of the columns.
shun-iwasawa 947ad3
//    New arrangement CAN run over the existing column range.
shun-iwasawa 947ad3
//    If the new arrangement is shorter than the selected range,
shun-iwasawa 947ad3
//    excess cells will not be cleared but keep their contents.
shun-iwasawa 947ad3
// 4. Column Selection + Insert
shun-iwasawa 947ad3
//    New arrangement will be inserted at the top of the columns.
shun-iwasawa 947ad3
//    If multiple columns are selected, then the inserted cells
shun-iwasawa 947ad3
//    will be expanded to the longest arrangement with empty cells.
shun-iwasawa 947ad3
//
shun-iwasawa 947ad3
void TXsheet::autoInputCellNumbers(int increment, int interval, int step,
shun-iwasawa 947ad3
                                   int repeat, int from, int to, int r0, int r1,
shun-iwasawa 947ad3
                                   bool isOverwrite,
shun-iwasawa 947ad3
                                   std::vector<int> columnIndices,</int>
shun-iwasawa 947ad3
                                   std::vector<txshlevelp> levels,</txshlevelp>
shun-iwasawa 947ad3
                                   int rowsCount) {
shun-iwasawa 947ad3
  int rowUpTo = (r1 == -1) ? rowsCount - 1
shun-iwasawa 947ad3
                           : ((isOverwrite) ? std::min(r1, r0 + rowsCount - 1)
shun-iwasawa 947ad3
                                            : r0 + rowsCount - 1);
shun-iwasawa 947ad3
  // for each column
shun-iwasawa 947ad3
  for (int c = 0; c < columnIndices.size(); c++) {
shun-iwasawa 947ad3
    int columnIndex  = columnIndices.at(c);
shun-iwasawa 947ad3
    TXshLevelP level = levels.at(c);
shun-iwasawa 947ad3
shun-iwasawa 947ad3
    // on insertion, insert empty cells first
shun-iwasawa 947ad3
    if (!isOverwrite) insertCells(r0, columnIndex, rowsCount);
shun-iwasawa 947ad3
shun-iwasawa 947ad3
    // obtain fids to be input
shun-iwasawa 947ad3
    std::vector<tframeid> fids;</tframeid>
shun-iwasawa 947ad3
    if (increment == 0) {
shun-iwasawa 947ad3
      std::vector<tframeid> wholeFids;</tframeid>
shun-iwasawa 947ad3
      level->getFids(wholeFids);
shun-iwasawa 947ad3
      if (from <= to) {
shun-iwasawa 947ad3
        for (auto itr = wholeFids.begin(); itr != wholeFids.end(); ++itr) {
shun-iwasawa 947ad3
          if ((*itr).getNumber() >= from && (*itr).getNumber() <= to)
shun-iwasawa 947ad3
            fids.push_back(*itr);
shun-iwasawa 947ad3
          else if ((*itr).getNumber() > to)
shun-iwasawa 947ad3
            break;
shun-iwasawa 947ad3
        }
shun-iwasawa 947ad3
      } else {  // from > to
shun-iwasawa 947ad3
        for (auto itr = wholeFids.rbegin(); itr != wholeFids.rend(); ++itr) {
shun-iwasawa 947ad3
          if ((*itr).getNumber() <= from && (*itr).getNumber() >= to)
shun-iwasawa 947ad3
            fids.push_back(*itr);
shun-iwasawa 947ad3
          else if ((*itr).getNumber() < to)
shun-iwasawa 947ad3
            break;
shun-iwasawa 947ad3
        }
shun-iwasawa 947ad3
      }
shun-iwasawa 947ad3
    } else {  // increment != 0
shun-iwasawa 947ad3
      int f = from;
shun-iwasawa 947ad3
      if (from <= to) {
shun-iwasawa 947ad3
        while (f <= to) {
shun-iwasawa 947ad3
          fids.push_back(TFrameId(f));
shun-iwasawa 947ad3
          f += increment;
shun-iwasawa 947ad3
        }
shun-iwasawa 947ad3
      } else {  // from > to
shun-iwasawa 947ad3
        while (f >= to) {
shun-iwasawa 947ad3
          fids.push_back(TFrameId(f));
shun-iwasawa 947ad3
          f -= increment;
shun-iwasawa 947ad3
        }
shun-iwasawa 947ad3
      }
shun-iwasawa 947ad3
    }
shun-iwasawa 947ad3
shun-iwasawa 947ad3
    // input cells
shun-iwasawa 947ad3
    int row             = r0;
shun-iwasawa 947ad3
    int repeat_itr      = 0;
shun-iwasawa 947ad3
    int fid_itr         = 0;
shun-iwasawa 947ad3
    int step_interv_itr = 0;
shun-iwasawa 947ad3
    while (row <= rowUpTo) {
shun-iwasawa 947ad3
      // input cell
shun-iwasawa 947ad3
      if (step_interv_itr < step)
shun-iwasawa 947ad3
        setCell(row, columnIndex, TXshCell(level, fids.at(fid_itr)));
shun-iwasawa 947ad3
      // .. or set empty cell as interval
shun-iwasawa 947ad3
      else
shun-iwasawa 947ad3
        setCell(row, columnIndex, TXshCell());
shun-iwasawa 947ad3
shun-iwasawa 947ad3
      // increment
shun-iwasawa 947ad3
      step_interv_itr++;
shun-iwasawa 947ad3
      // next frame
shun-iwasawa 947ad3
      if (step_interv_itr == step + interval) {
shun-iwasawa 947ad3
        fid_itr++;
shun-iwasawa 947ad3
        step_interv_itr = 0;
shun-iwasawa 947ad3
      }
shun-iwasawa 947ad3
      // next repeat cycle
shun-iwasawa 947ad3
      if (fid_itr == fids.size()) {
shun-iwasawa 947ad3
        repeat_itr++;
shun-iwasawa 947ad3
        fid_itr = 0;
shun-iwasawa 947ad3
      }
shun-iwasawa 947ad3
      if (repeat_itr == repeat) break;
shun-iwasawa 947ad3
shun-iwasawa 947ad3
      row++;
shun-iwasawa 947ad3
    }
shun-iwasawa 947ad3
  }
Toondad 9c4638
}
shun-iwasawa 4a3868
shun-iwasawa 4a3868
//---------------------------------------------------------
shun-iwasawa 4a3868
shun-iwasawa 4a3868
void TXsheet::setObserver(TXsheetColumnChangeObserver *observer) {
shun-iwasawa 4a3868
  m_observer = observer;
shun-iwasawa 4a3868
}
shun-iwasawa 4a3868
shun-iwasawa 4a3868
//---------------------------------------------------------
shun-iwasawa 4a3868
shun-iwasawa 4a3868
void TXsheet::notify(const TXsheetColumnChange &change) {
shun-iwasawa 4a3868
  if (m_observer) m_observer->onChange(change);
shun-iwasawa 4a3868
}
shun-iwasawa 4a3868
void TXsheet::notifyFxAdded(const std::vector<tfx *=""> &fxs) {</tfx>
shun-iwasawa 4a3868
  if (m_observer) m_observer->onFxAdded(fxs);
shun-iwasawa 4a3868
}
shun-iwasawa 4a3868
void TXsheet::notifyStageObjectAdded(const TStageObjectId id) {
shun-iwasawa 4a3868
  if (m_observer) m_observer->onStageObjectAdded(id);
shun-iwasawa 4a3868
}
shun-iwasawa 4a3868
bool TXsheet::isReferenceManagementIgnored(TDoubleParam *param) {
shun-iwasawa 4a3868
  if (m_observer) return m_observer->isIgnored(param);
shun-iwasawa 4a3868
  return false;
shun-iwasawa 4a3868
}
shun-iwasawa 4a3868
ExpressionReferenceMonitor *TXsheet::getExpRefMonitor() const {
shun-iwasawa 4a3868
  return m_imp->m_expRefMonitor;
shun-iwasawa 4a3868
}
shun-iwasawa 4a3868
//---------------------------------------------------------
manongjohn 8404a6
manongjohn 8404a6
bool TXsheet::isFrameTagged(int frame) const {
manongjohn 8404a6
  if (frame < 0) return false;
manongjohn 8404a6
manongjohn 8404a6
  return m_navigationTags->isTagged(frame);
manongjohn 8404a6
}
manongjohn 8404a6
manongjohn 8404a6
//---------------------------------------------------------
manongjohn 8404a6
manongjohn 8404a6
void TXsheet::toggleTaggedFrame(int frame) {
manongjohn 8404a6
  if (frame < 0) return;
manongjohn 8404a6
manongjohn 8404a6
  if (isFrameTagged(frame))
manongjohn 8404a6
    m_navigationTags->removeTag(frame);
manongjohn 8404a6
  else
manongjohn 8404a6
    m_navigationTags->addTag(frame);
manongjohn 8404a6
}