toonz/sources/toonz/cellselection.cpp
//-----------------------------------------------------------------------------
// Convert selected vector cells to ToonzRaster and back to vecor
Convert selected vector cells to ToonzRaster and back to vecor
Convert selected vector cells to ToonzRaster and back to vecor
void TCellSelection::convertVectortoVector() {
  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);
  assert(sl);
  TCamera *camera = app->getCurrentScene()->getScene()->getCurrentCamera();
  double dpi      = camera->getDpi().x;
  int xres        = camera->getRes().lx;
  int yres        = camera->getRes().ly;
  if (Preferences::instance()->getUseHigherDpiOnVectorSimplify()) {
    dpi *= 2;
    xres *= 2;
    yres *= 2;
  }
  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;
  std::vector<TImageP> oldImages;
  frameIds.push_back(frameId);
  oldImages.push_back(firstCell.getImage(false).getPointer()->cloneImage());
  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);
        oldImages.push_back(newCell.getImage(false)->cloneImage());
      }
    }
  }
  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);
  data->clear();
  data->setLevelFrames(sl, newFrameIds);
  if (Preferences::instance()->getKeepFillOnVectorSimplify())
    data->setKeepVectorFills(true);
  success = data->getLevelFrames(
      sourceSl, frameIdsSet, DrawingData::OVER_SELECTION, true,
      keepOriginalPalette, true);  
  std::vector<TImageP> newImages;
  for (i = 0; i < totalImages; i++) {
    newImages.push_back(sourceSl->getFrame(frameIds[i], false)->cloneImage());
  }
  HookSet *oldLevelHooks = new HookSet();
  *oldLevelHooks         = *sourceSl->getHookSet();
  TUndoManager::manager()->add(new VectorToVectorUndo(
      sourceSl, frameIds, oldImages, newImages, oldLevelHooks));
  invalidateIcons(sourceSl, frameIdsSet);
  sl->clearFrames();
  app->getCurrentScene()->getScene()->getLevelSet()->removeLevel(sl, true);
  app->getCurrentScene()->notifySceneChanged();
  app->getCurrentScene()->notifyCastChange();
  app->getCurrentXsheet()->notifyXsheetChanged();
  app->getCurrentTool()->onImageChanged(
      (TImage::Type)app->getCurrentImageType());
}
void TCellSelection :: convertVectortoVector ( ) { 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 ) ; assert ( sl ) ; TCamera * camera = app -> getCurrentScene ( ) -> getScene ( ) -> getCurrentCamera ( ) ; double dpi = camera -> getDpi ( ) . x ; int xres = camera -> getRes ( ) . lx ; int yres = camera -> getRes ( ) . ly ; if ( Preferences :: instance ( ) -> getUseHigherDpiOnVectorSimplify ( ) ) { dpi *= 2 ; xres *= 2 ; yres *= 2 ; } 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 ; std :: vector < TImageP > oldImages ; frameIds . push_back ( frameId ) ; oldImages . push_back ( firstCell . getImage ( false ) . getPointer ( ) -> cloneImage ( ) ) ; 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 ) ; oldImages . push_back ( newCell . getImage ( false ) -> cloneImage ( ) ) ; } } } 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 ) ; data -> clear ( ) ; data -> setLevelFrames ( sl , newFrameIds ) ; if ( Preferences :: instance ( ) -> getKeepFillOnVectorSimplify ( ) ) data -> setKeepVectorFills ( true ) ; success = data -> getLevelFrames ( sourceSl , frameIdsSet , DrawingData :: OVER_SELECTION , true , keepOriginalPalette , true ) ; std :: vector < TImageP > newImages ; for ( i = 0 ; i < totalImages ; i ++ ) { newImages . push_back ( sourceSl -> getFrame ( frameIds [ i ] , false ) -> cloneImage ( ) ) ; } HookSet * oldLevelHooks = new HookSet ( ) ; * oldLevelHooks = * sourceSl -> getHookSet ( ) ; TUndoManager :: manager ( ) -> add ( new VectorToVectorUndo ( sourceSl , frameIds , oldImages , newImages , oldLevelHooks ) ) ; invalidateIcons ( sourceSl , frameIdsSet ) ; sl -> clearFrames ( ) ; app -> getCurrentScene ( ) -> getScene ( ) -> getLevelSet ( ) -> removeLevel ( sl , true ) ; app -> getCurrentScene ( ) -> notifySceneChanged ( ) ; app -> getCurrentScene ( ) -> notifyCastChange ( ) ; app -> getCurrentXsheet ( ) -> notifyXsheetChanged ( ) ; app -> getCurrentTool ( ) -> onImageChanged ( ( TImage :: Type ) app -> getCurrentImageType ( ) ) ; }
Convert selected vector cells to ToonzRaster and back to vecor
Convert selected vector cells to ToonzRaster and back to vecor
// set up basics // set up new level name // get camera settings // Get the used FrameIds and images // The cloned images are used in the undo. // Make empty frames for the new data // This is where the copying actually happens // copy old frames to Toonz Raster // setting is redo = true skips the // question about the palette // get the new FrameIds // copy the Toonz Raster frames onto the old level // setting is redo = true skips the // question about the palette // get clones of the new images for undo // remove the toonz raster level