toonz/sources/toonz/cellselection.cpp
//-----------------------------------------------------------------------------
// Convert selected vector cells to ToonzRaster
Convert selected vector cells to ToonzRaster
Convert selected vector cells to ToonzRaster
void TCellSelection::convertToToonzRaster() {
  int r0, c0, r1, c1;
  getSelectedCells(r0, c0, r1, c1);
  TApp *app = TApp::instance();
  int row   = app->getCurrentFrame()->getFrame();
  int col   = app->getCurrentColumn()->getColumnIndex();
  int i, j;
  ToonzScene *scene = app->getCurrentScene()->getScene();
  TXsheet *xsh      = scene->getXsheet();
  TXshCell firstCell        = xsh->getCell(r0, c0);
  TXshSimpleLevel *sourceSl = firstCell.getSimpleLevel();
  if (!areOnlyVectorCellsSelected()) return;
  TXshSimpleLevel *sl = getNewToonzRasterLevel(sourceSl);
  TCamera *camera = app->getCurrentScene()->getScene()->getCurrentCamera();
  double dpi      = camera->getDpi().x;
  int xres        = camera->getRes().lx;
  int yres        = camera->getRes().ly;
  assert(sl);
  sl->getProperties()->setDpiPolicy(LevelProperties::DP_ImageDpi);
  sl->getProperties()->setDpi(dpi);
  sl->getProperties()->setImageDpi(TPointD(dpi, dpi));
  sl->getProperties()->setImageRes(TDimension(xres, yres));
  TFrameId frameId = firstCell.getFrameId();
  std::set<TFrameId> frameIdsSet;
  std::vector<TFrameId> frameIds;
  frameIds.push_back(frameId);
  for (i = r0 + 1; i <= r1; i++) {
    TXshCell newCell    = xsh->getCell(i, c0);
    TFrameId newFrameId = xsh->getCell(i, c0).getFrameId();
    if (newCell.getSimpleLevel() == sourceSl) {
      if (std::find(frameIds.begin(), frameIds.end(), newCell.getFrameId()) ==
          frameIds.end()) {
        frameIds.push_back(newFrameId);
      }
    }
  }
  int totalImages = frameIds.size();
  for (i = 0; i < totalImages; i++) {
    frameIdsSet.insert(frameIds[i]);
  }
  DrawingData *data = new DrawingData();
  data->setLevelFrames(sourceSl, frameIdsSet);
  std::set<TFrameId> newFrameIds;
  for (i = 0; i < totalImages; i++) {
    TRasterCM32P raster(xres, yres);
    raster->fill(TPixelCM32());
    TToonzImageP firstImage(raster, TRect());
    firstImage->setDpi(dpi, dpi);
    TFrameId newFrameId = TFrameId(i + 1);
    sl->setFrame(newFrameId, firstImage);
    newFrameIds.insert(newFrameId);
    firstImage->setSavebox(TRect(0, 0, xres - 1, yres - 1));
  }
  bool keepOriginalPalette;
  bool success = data->getLevelFrames(
      sl, newFrameIds, DrawingData::OVER_SELECTION, true, keepOriginalPalette,
      true);  
  std::vector<TFrameId> newFids;
  sl->getFids(newFids);
  col += 1;
  TApp::instance()->getCurrentColumn()->setColumnIndex(col);
  xsh->insertColumn(col);
  CreateLevelUndo *undo = new CreateLevelUndo(row, col, totalImages, 1, true);
  TUndoManager::manager()->add(undo);
  for (i = 0; i < totalImages; i++) {
    for (int k = r0; k <= r1; k++) {
      TXshCell oldCell = xsh->getCell(k, c0);
      TXshCell newCell(sl, newFids[i]);
      if (oldCell.getFrameId() == frameIds[i]) {
        xsh->setCell(k, col, newCell);
      }
    }
  }
  invalidateIcons(sl, newFrameIds);
  sl->save(sl->getPath(), TFilePath(), true);
  DvDirModel::instance()->refreshFolder(sl->getPath().getParentDir());
  undo->onAdd(sl);
  app->getCurrentScene()->notifySceneChanged();
  app->getCurrentScene()->notifyCastChange();
  app->getCurrentXsheet()->notifyXsheetChanged();
  app->getCurrentTool()->onImageChanged(
      (TImage::Type)app->getCurrentImageType());
}
void TCellSelection :: convertToToonzRaster ( ) { int r0 , c0 , r1 , c1 ; getSelectedCells ( r0 , c0 , r1 , c1 ) ; TApp * app = TApp :: instance ( ) ; int row = app -> getCurrentFrame ( ) -> getFrame ( ) ; int col = app -> getCurrentColumn ( ) -> getColumnIndex ( ) ; int i , j ; ToonzScene * scene = app -> getCurrentScene ( ) -> getScene ( ) ; TXsheet * xsh = scene -> getXsheet ( ) ; TXshCell firstCell = xsh -> getCell ( r0 , c0 ) ; TXshSimpleLevel * sourceSl = firstCell . getSimpleLevel ( ) ; if ( ! areOnlyVectorCellsSelected ( ) ) return ; TXshSimpleLevel * sl = getNewToonzRasterLevel ( sourceSl ) ; TCamera * camera = app -> getCurrentScene ( ) -> getScene ( ) -> getCurrentCamera ( ) ; double dpi = camera -> getDpi ( ) . x ; int xres = camera -> getRes ( ) . lx ; int yres = camera -> getRes ( ) . ly ; assert ( sl ) ; sl -> getProperties ( ) -> setDpiPolicy ( LevelProperties :: DP_ImageDpi ) ; sl -> getProperties ( ) -> setDpi ( dpi ) ; sl -> getProperties ( ) -> setImageDpi ( TPointD ( dpi , dpi ) ) ; sl -> getProperties ( ) -> setImageRes ( TDimension ( xres , yres ) ) ; TFrameId frameId = firstCell . getFrameId ( ) ; std :: set < TFrameId > frameIdsSet ; std :: vector < TFrameId > frameIds ; frameIds . push_back ( frameId ) ; for ( i = r0 + 1 ; i <= r1 ; i ++ ) { TXshCell newCell = xsh -> getCell ( i , c0 ) ; TFrameId newFrameId = xsh -> getCell ( i , c0 ) . getFrameId ( ) ; if ( newCell . getSimpleLevel ( ) == sourceSl ) { if ( std :: find ( frameIds . begin ( ) , frameIds . end ( ) , newCell . getFrameId ( ) ) == frameIds . end ( ) ) { frameIds . push_back ( newFrameId ) ; } } } int totalImages = frameIds . size ( ) ; for ( i = 0 ; i < totalImages ; i ++ ) { frameIdsSet . insert ( frameIds [ i ] ) ; } DrawingData * data = new DrawingData ( ) ; data -> setLevelFrames ( sourceSl , frameIdsSet ) ; std :: set < TFrameId > newFrameIds ; for ( i = 0 ; i < totalImages ; i ++ ) { TRasterCM32P raster ( xres , yres ) ; raster -> fill ( TPixelCM32 ( ) ) ; TToonzImageP firstImage ( raster , TRect ( ) ) ; firstImage -> setDpi ( dpi , dpi ) ; TFrameId newFrameId = TFrameId ( i + 1 ) ; sl -> setFrame ( newFrameId , firstImage ) ; newFrameIds . insert ( newFrameId ) ; firstImage -> setSavebox ( TRect ( 0 , 0 , xres - 1 , yres - 1 ) ) ; } bool keepOriginalPalette ; bool success = data -> getLevelFrames ( sl , newFrameIds , DrawingData :: OVER_SELECTION , true , keepOriginalPalette , true ) ; std :: vector < TFrameId > newFids ; sl -> getFids ( newFids ) ; col += 1 ; TApp :: instance ( ) -> getCurrentColumn ( ) -> setColumnIndex ( col ) ; xsh -> insertColumn ( col ) ; CreateLevelUndo * undo = new CreateLevelUndo ( row , col , totalImages , 1 , true ) ; TUndoManager :: manager ( ) -> add ( undo ) ; for ( i = 0 ; i < totalImages ; i ++ ) { for ( int k = r0 ; k <= r1 ; k ++ ) { TXshCell oldCell = xsh -> getCell ( k , c0 ) ; TXshCell newCell ( sl , newFids [ i ] ) ; if ( oldCell . getFrameId ( ) == frameIds [ i ] ) { xsh -> setCell ( k , col , newCell ) ; } } } invalidateIcons ( sl , newFrameIds ) ; sl -> save ( sl -> getPath ( ) , TFilePath ( ) , true ) ; DvDirModel :: instance ( ) -> refreshFolder ( sl -> getPath ( ) . getParentDir ( ) ) ; undo -> onAdd ( sl ) ; app -> getCurrentScene ( ) -> notifySceneChanged ( ) ; app -> getCurrentScene ( ) -> notifyCastChange ( ) ; app -> getCurrentXsheet ( ) -> notifyXsheetChanged ( ) ; app -> getCurrentTool ( ) -> onImageChanged ( ( TImage :: Type ) app -> getCurrentImageType ( ) ) ; }
Convert selected vector cells to ToonzRaster
Convert selected vector cells to ToonzRaster
// set up basics // set up new level // get camera settings // This is where the copying actually happens // setting is redo = true skips the // question about the palette // make a new column // expose the new frames in the column