void Tools::edgeLaplacian()
{
    ImageViewer* iv = getViewer();

    if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
                                                          << QImage::Format_Indexed8
                                                          << QImage::Format_RGB32))
        return;

    MaskDialog dialog;
    dialog.setWindowTitle("Laplacian");

    if (dialog.exec() == QDialog::Rejected)
        return;

    EdgeLaplacian* el = new EdgeLaplacian(iv->getImage(), iv);
    el->setParameter("size", dialog.getSize());

    el->start();
}
void Tools::morphClose()
{
    ImageViewer* iv = getViewer();

    if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Mono
                                                          << QImage::Format_Indexed8
                                                          << QImage::Format_RGB32))
        return;

    MorphDialog dialog;
    dialog.setWindowTitle("Close");

    if (dialog.exec() == QDialog::Rejected)
        return;

    MorphOpenClose* mc = new MorphOpenClose(iv->getImage(), iv);
    mc->setParameter("size",  dialog.getSize());
    mc->setParameter("shape", (int)dialog.getShape());
    mc->setParameter("type", (int)MorphOpenClose::Close);
    mc->start();
}
void Tools::binManual()
{
    ImageViewer* iv = getViewer();

    if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
                                                          << QImage::Format_RGB32))
        return;

    SliderDialog dialog(new BinarizationManual(new PNM(iv->getImage()->copy())), "threshold");
    dialog.setRange(PIXEL_VAL_MIN, PIXEL_VAL_MAX);
    dialog.initSliderValue(PIXEL_VAL_MAX/2);
    dialog.setImage(iv->getImage()->copy());
    dialog.update();

    if (dialog.exec() == QDialog::Rejected)
        return;

    BinarizationManual* bm = new BinarizationManual(iv->getImage(), iv);
    bm->setParameter("threshold", dialog.value());
    bm->start();
}
void Tools::correctBrightnessContrastGamma()
{
    ImageViewer* iv = getViewer();

    if (!SupportedImageFormat(iv, QList<QImage::Format>() << QImage::Format_Indexed8
                                                          << QImage::Format_RGB32))
        return;


    CorrectionDialog dialog;
    dialog.setImage(iv->getImage()->copy());
    dialog.update();

    if (dialog.exec() == QDialog::Rejected)
        return;

    Correction* bc = new Correction(iv->getImage(), iv);
    bc->setParameter("shift",  dialog.getShift());
    bc->setParameter("factor", dialog.getMultiplier());
    bc->setParameter("gamma",  dialog.getGamma());

    bc->start();
}
//================================================================
// Function : TexturesExt_Presentation::sampleKitchen
// Purpose  : kitchen with texturized items in it.
//================================================================
void TexturesExt_Presentation::sampleKitchen()
{
  TopoDS_Shape aShape;

  if (!loadShape(aShape, "Kitchen\\Room.brep"))
    return;

  gp_Trsf aTrsf;
  gp_Ax3 NewCoordSystem (gp_Pnt(-1,-1, -1),gp_Dir(0,0,1));
  gp_Ax3 CurrentCoordSystem(gp_Pnt(0,0,0),gp_Dir(0,0,1));
  aTrsf.SetDisplacement(CurrentCoordSystem, NewCoordSystem);
  aShape.Location(TopLoc_Location(aTrsf));

  moveScale(aShape);

  // draw kitchen room whithout one wall (to better see the insides)
  TopTools_IndexedMapOfShape aFaces;
  TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
  Standard_Integer nbFaces = aFaces.Extent();

  // create a wooden kitchen floor
  // the floor's face will be textured with texture from chataignier.gif
  DISP(Texturize(aFaces(5),"plancher.gif",1,1,2,1));

  // texturize other faces of the room with texture from wallpaper.gif (walls)
  DISP(Texturize(aFaces(1),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(3),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(4),"wallpaper.gif",1,1,8,6));

//  DISP(drawShape(aFaces(1), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(3), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(4), Quantity_NOC_LIGHTPINK, Standard_False));

  // texturize furniture items with "wooden" texture
  if (loadShape(aShape, "Kitchen\\MODERN_Table_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Chair_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i >= 59)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_STEEL, Standard_False));
      else if (i >= 29)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 28)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Exhaust_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_STONE, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i < 145)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 145)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }

  getViewer()->Update();
}
//================================================================
// Function : lightsOnOff
// Purpose  : 6 lights are used for a brighter demonstration of textured shapes
//            call lightsOnOff(false) before showing normal shape
//            call lightsOnOff(true)  before showing textured shape
//================================================================
void TexturesExt_Presentation::lightsOnOff(Standard_Boolean isOn)
{
  static Handle_V3d_Light aLight1 = new V3d_DirectionalLight(getViewer(), V3d_XnegYposZneg);
  static Handle_V3d_Light aLight2 = new V3d_DirectionalLight(getViewer(), V3d_XnegYnegZpos);
  static Handle_V3d_Light aLight3 = new V3d_DirectionalLight(getViewer(), V3d_XposYnegZpos);
  static Handle_V3d_Light aLight4 = new V3d_DirectionalLight(getViewer(), V3d_XnegYnegZneg);
  static Handle_V3d_Light aLight5 = new V3d_DirectionalLight(getViewer(), V3d_XnegYposZpos);
  static Handle_V3d_Light aLight6 = new V3d_DirectionalLight(getViewer(), V3d_XposYposZpos);

  if (isOn)
  {
    getViewer()->SetLightOn(aLight1);
    getViewer()->SetLightOn(aLight2);
    getViewer()->SetLightOn(aLight3);
    getViewer()->SetLightOn(aLight4);
    getViewer()->SetLightOn(aLight5);
    getViewer()->SetLightOn(aLight6);
  }
  else 
  {
    getViewer()->SetLightOff(aLight1);
    getViewer()->SetLightOff(aLight2);
    getViewer()->SetLightOff(aLight3);
    getViewer()->SetLightOff(aLight4);
    getViewer()->SetLightOff(aLight5);
    getViewer()->SetLightOff(aLight6);
  }
}
Beispiel #7
0
void LevelMoverTool::onDrag(const QMouseEvent *e) {
  QPoint pos = e->pos();
  onCellChange(getViewer()->yToRow(pos.y()), getViewer()->xToColumn(pos.x()));
  refreshCellsArea();
  refreshColumnsArea();
}
Beispiel #8
0
void LevelMoverTool::onCellChange(int row, int col) {
  TXsheet *xsh = getViewer()->getXsheet();

  TPoint pos           = TPoint(col, row) + m_grabOffset;
  if (pos.y < 0) pos.y = 0;
  if (pos.x < 0) return;
  if (pos == m_aimedPos) return;

  m_aimedPos   = pos;
  TPoint delta = m_aimedPos - m_lastPos;

  m_validPos = canMoveColumns(pos);
  if (!m_validPos) return;

  CellsMover *cellsMover = m_undo->getCellsMover();
  if (m_moved) cellsMover->undoMoveCells();
  m_validPos = canMove(pos);

  if (m_validPos) {
    //----------------------
    if (delta.x != 0 && (m_qualifiers & CellsMover::eMoveColumns)) {
      // spostamento di colonne
      int colCount = m_range.lx;

      bool emptySrc = true;
      for (int i = 0; i < colCount; i++) {
        TXshColumn *column = xsh->getColumn(m_lastPos.x + i);
        if (column && !column->isEmpty()) {
          emptySrc = false;
          break;
        }
      }

      bool lockedDst = false;
      bool emptyDst  = true;
      for (int i = 0; i < colCount; i++) {
        if (!isTotallyEmptyColumn(pos.x + i)) emptyDst = false;
        TXshColumn *column                          = xsh->getColumn(pos.x + i);
        if (column && column->isLocked()) lockedDst = true;
      }

      if (emptySrc) {
        if (m_lastPos.x == m_startPos.x)
          m_undo->getCellsMover()->m_uffa |=
              1;  // first column(s) has/have been cleared
        cellsMover->emptyColumns(m_lastPos.x);
      }

      if (emptyDst && !lockedDst) {
        if (pos.x == m_startPos.x)
          m_undo->getCellsMover()->m_uffa &=
              ~1;  // first column(s) has/have been restored
        else
          m_undo->getCellsMover()->m_uffa |=
              2;  // columns data have been copied on the current position
        cellsMover->restoreColumns(pos.x);
      } else {
        m_undo->getCellsMover()->m_uffa &=
            ~2;  // no columns data have been copied on the current position
      }
    }

    //----------------------

    m_lastPos = pos;
    cellsMover->setPos(pos.y, pos.x);
    cellsMover->saveCells();
    cellsMover->moveCells();
    m_moved = true;
  } else {
    cellsMover->moveCells();
  }

  xsh->updateFrameCount();
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
  if (cellsMover->getColumnTypeFromCell(0) == TXshColumn::eSoundType)
    TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged();
  TRect selection(m_aimedPos, m_range);
  getViewer()->getCellSelection()->selectCells(selection.y0, selection.x0,
                                               selection.y1, selection.x1);
}
Beispiel #9
0
void 
ViewerAppliInternal::postAnEvent(QEvent *e)
{ startSession(); getViewer()->post(e); }
void StylePickerTool::pick(const TPointD &pos, const TMouseEvent &e) {
  // Area = 0, Line = 1, All = 2
  int modeValue = m_colorType.getIndex();

  //------------------------------------
  // MultiLayerStylePicker
  /*---
                  PickしたStyleId = 0、かつ
                  Preference で MultiLayerStylePickerが有効、かつ
                  Scene編集モード、かつ
                  下のカラムから拾った色がTransparentでない場合、
                  → カレントLevelを移動する。
  ---*/
  if (Preferences::instance()->isMultiLayerStylePickerEnabled() &&
      getApplication()->getCurrentFrame()->isEditingScene()) {
    int superPickedColumnId = getViewer()->posToColumnIndex(
        e.m_pos, getPixelSize() * getPixelSize(), false);

    if (superPickedColumnId >= 0 /*-- 何かColumnに当たった場合 --*/
        &&
        getApplication()->getCurrentColumn()->getColumnIndex() !=
            superPickedColumnId) /*-- かつ、Current Columnでない場合 --*/
    {
      /*-- そのColumnからPickを試みる --*/
      int currentFrame = getApplication()->getCurrentFrame()->getFrame();
      TXshCell pickedCell =
          getApplication()->getCurrentXsheet()->getXsheet()->getCell(
              currentFrame, superPickedColumnId);
      TImageP pickedImage           = pickedCell.getImage(false).getPointer();
      TToonzImageP picked_ti        = pickedImage;
      TVectorImageP picked_vi       = pickedImage;
      TXshSimpleLevel *picked_level = pickedCell.getSimpleLevel();
      if ((picked_ti || picked_vi) && picked_level) {
        TPointD tmpMousePosition = getColumnMatrix(superPickedColumnId).inv() *
                                   getViewer()->winToWorld(e.m_pos);

        TPointD tmpDpiScale = getCurrentDpiScale(picked_level, getCurrentFid());

        tmpMousePosition.x /= tmpDpiScale.x;
        tmpMousePosition.y /= tmpDpiScale.y;

        StylePicker superPicker(pickedImage);
        int picked_subsampling =
            picked_level->getImageSubsampling(pickedCell.getFrameId());
        int superPicked_StyleId = superPicker.pickStyleId(
            TScale(1.0 / picked_subsampling) * tmpMousePosition +
                TPointD(-0.5, -0.5),
            getPixelSize() * getPixelSize(), modeValue);
        /*-- 何かStyleが拾えて、Transparentでない場合 --*/
        if (superPicked_StyleId > 0) {
          /*-- Levelの移動 --*/
          getApplication()->getCurrentLevel()->setLevel(picked_level);
          /*-- Columnの移動 --*/
          getApplication()->getCurrentColumn()->setColumnIndex(
              superPickedColumnId);
          /*-- 選択の解除 --*/
          if (getApplication()->getCurrentSelection()->getSelection())
            getApplication()
                ->getCurrentSelection()
                ->getSelection()
                ->selectNone();
          /*-- StyleIdの移動 --*/
          getApplication()->setCurrentLevelStyleIndex(superPicked_StyleId);
          return;
        }
      }
    }
  }
  /*-- MultiLayerStylePicker ここまで --*/
  //------------------------------------
  TImageP image    = getImage(false);
  TToonzImageP ti  = image;
  TVectorImageP vi = image;
  TXshSimpleLevel *level =
      getApplication()->getCurrentLevel()->getSimpleLevel();
  if ((!ti && !vi) || !level) return;

  /*-- 画面外をpickしても拾えないようにする --*/
  if (!m_viewer->getGeometry().contains(pos)) return;

  int subsampling = level->getImageSubsampling(getCurrentFid());
  StylePicker picker(image);
  int styleId =
      picker.pickStyleId(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5),
                         getPixelSize() * getPixelSize(), modeValue);

  if (styleId < 0) return;

  if (modeValue == 1)  // LINES
  {
    /*-- pickLineモードのとき、取得Styleが0の場合はカレントStyleを変えない。
      * --*/
    if (styleId == 0) return;
    /*--
      * pickLineモードのとき、PurePaintの部分をクリックしてもカレントStyleを変えない
      * --*/
    if (ti &&
        picker.pickTone(TScale(1.0 / subsampling) * pos +
                        TPointD(-0.5, -0.5)) == 255)
      return;
  }

  /*--- Styleを選択している場合は選択を解除する ---*/
  TSelection *selection =
      TTool::getApplication()->getCurrentSelection()->getSelection();
  if (selection) {
    TStyleSelection *styleSelection =
        dynamic_cast<TStyleSelection *>(selection);
    if (styleSelection) styleSelection->selectNone();
  }

  getApplication()->setCurrentLevelStyleIndex(styleId);
}
Beispiel #11
0
void CellPanel::paintEvent(QPaintEvent *e)
{
	QPainter painter(this);

	QRect toBeUpdated = e->rect();
	painter.setClipRect(toBeUpdated);

	int x0 = toBeUpdated.left() - 1;
	int y0 = toBeUpdated.top();
	int x1 = toBeUpdated.right(), y1 = toBeUpdated.bottom();

	// visible rows range
	int r0 = getViewer()->yToRow(y0);
	int r1 = getViewer()->yToRow(y1);

	// visible columns range
	int c0 = getViewer()->xToColumn(x0);
	int c1 = getViewer()->xToColumn(x1);

	// cambia colore alle celle prima di rowCount()
	int rowCount = getViewer()->getRowCount();

	//fill with bg color
	painter.fillRect(toBeUpdated, getViewer()->getLightLightBGColor());

	//scene range bg
	int yLast = getViewer()->rowToY(rowCount);
	if (yLast < y1)
		painter.fillRect(x0, y0, x1 - x0, yLast - y0, getViewer()->getBGColor());
	else
		painter.fillRect(toBeUpdated, getViewer()->getBGColor());

	//draw cells
	drawCells(painter, r0, c0, r1, c1);

	// draw columns
	painter.setPen(getViewer()->getVerticalLineColor());
	for (int col = c0; col <= c1; col++) {
		int x = getViewer()->columnToX(col);
		painter.drawLine(x, y0, x, y1);
	}

	// draw rows
	int currentRow = getViewer()->getCurrentRow();
	for (int r = r0; r <= r1; r++) {
		int y = getViewer()->rowToY(r);
		QColor color = getViewer()->isMarkRow(r) ? getViewer()->getMarkerLineColor() : getViewer()->getLightLineColor();
		painter.setPen(color);
		painter.drawLine(x0, y, x1, y);
	}
	// erase the marker interval at upper-end
	painter.setPen(getViewer()->getLightLineColor());
	painter.drawLine(x0, 0, x1, 0);
}
Beispiel #12
0
DragTool *CellPanel::createDragTool(QMouseEvent *)
{
	// FunctionSheetCellViewer::createDragTool is called instead
	// when clicking on the CellPanel in NumericalColumns
	return new SelectionDragTool(getViewer());
}
Beispiel #13
0
void ViewerConfiguration::buildViewerConfigurationControls(void)
	{
	/* Build the graphical user interface: */
	const GLMotif::StyleSheet& ss=*getUiStyleSheet();
	
	dialogWindow=new GLMotif::PopupWindow("ViewerConfigurationDialog",getWidgetManager(),"Viewer Configuration");
	dialogWindow->setHideButton(true);
	dialogWindow->setResizableFlags(true,false);
	
	GLMotif::RowColumn* viewerConfiguration=new GLMotif::RowColumn("ViewerConfiguration",dialogWindow,false);
	viewerConfiguration->setOrientation(GLMotif::RowColumn::VERTICAL);
	viewerConfiguration->setPacking(GLMotif::RowColumn::PACK_TIGHT);
	viewerConfiguration->setNumMinorWidgets(2);
	
	/* Create a drop-down menu to select a viewer: */
	new GLMotif::Label("ViewerLabel",viewerConfiguration,"Viewer");
	viewerMenu=new GLMotif::DropdownBox("ViewerMenu",viewerConfiguration);
	int mainViewerIndex=0;
	for(int viewerIndex=0;viewerIndex<getNumViewers();++viewerIndex)
		{
		Viewer* viewer=getViewer(viewerIndex);
		viewerMenu->addItem(viewer->getName());
		if(viewer==getMainViewer())
			mainViewerIndex=viewerIndex;
		}
	viewerMenu->setSelectedItem(mainViewerIndex);
	viewerMenu->getValueChangedCallbacks().add(this,&ViewerConfiguration::viewerMenuCallback);
	
	/* Calculate an appropriate slider range and granularity: */
	Scalar sliderRange=Scalar(18)*factory->configUnit.getInchFactor(); // Slider range is at least 18"
	Scalar sliderRangeFactor=Math::pow(Scalar(10),Math::floor(Math::log10(sliderRange)));
	sliderRange=Math::ceil(sliderRange/sliderRangeFactor)*sliderRangeFactor;
	Scalar sliderStep=Scalar(0.01)*factory->configUnit.getInchFactor(); // Slider granularity is at most 0.01"
	int sliderStepDigits=int(Math::floor(Math::log10(sliderStep)));
	Scalar sliderStepFactor=Math::pow(Scalar(10),Scalar(sliderStepDigits));
	sliderStep=Math::floor(sliderStep/sliderStepFactor)*sliderStepFactor;
	sliderStepDigits=sliderStepDigits<0?-sliderStepDigits:0;
	
	/* Create three sliders to set the mono eye position: */
	new GLMotif::Label("MonoEyePosLabel",viewerConfiguration,"Mono Eye");
	
	GLMotif::RowColumn* monoEyePosBox=new GLMotif::RowColumn("MonoEyePosBox",viewerConfiguration,false);
	monoEyePosBox->setPacking(GLMotif::RowColumn::PACK_GRID);
	for(int i=0;i<3;++i)
		{
		char epsName[14]="EyePosSlider ";
		epsName[12]=char(i+'0');
		eyePosSliders[0][i]=new GLMotif::TextFieldSlider(epsName,monoEyePosBox,7,ss.fontHeight*10.0f);
		eyePosSliders[0][i]->getTextField()->setFieldWidth(6);
		eyePosSliders[0][i]->getTextField()->setPrecision(sliderStepDigits);
		eyePosSliders[0][i]->getTextField()->setFloatFormat(GLMotif::TextField::FIXED);
		eyePosSliders[0][i]->setSliderMapping(GLMotif::TextFieldSlider::LINEAR);
		eyePosSliders[0][i]->setValueType(GLMotif::TextFieldSlider::FLOAT);
		eyePosSliders[0][i]->setValueRange(-sliderRange,sliderRange,sliderStep);
		eyePosSliders[0][i]->getValueChangedCallbacks().add(this,&ViewerConfiguration::eyePosSliderCallback,i);
		}
	monoEyePosBox->manageChild();
	
	/* Create a slider to set the eye separation distance: */
	new GLMotif::Label("EyeDistLabel",viewerConfiguration,"Eye Distance");
	
	eyeDistanceSlider=new GLMotif::TextFieldSlider("EyeDistanceSlider",viewerConfiguration,7,ss.fontHeight*10.0f);
	eyeDistanceSlider->getTextField()->setFieldWidth(6);
	eyeDistanceSlider->getTextField()->setPrecision(sliderStepDigits);
	eyeDistanceSlider->getTextField()->setFloatFormat(GLMotif::TextField::FIXED);
	eyeDistanceSlider->setSliderMapping(GLMotif::TextFieldSlider::LINEAR);
	eyeDistanceSlider->setValueType(GLMotif::TextFieldSlider::FLOAT);
	eyeDistanceSlider->setValueRange(sliderStep*Scalar(10),sliderRange,sliderStep);
	eyeDistanceSlider->getValueChangedCallbacks().add(this,&ViewerConfiguration::eyeDistanceSliderCallback);
	
	/* Create two triples of sliders to set the left and right eye positions: */
	for(int eyeIndex=1;eyeIndex<3;++eyeIndex)
		{
		/* Create a separator: */
		new GLMotif::Blind(eyeIndex==1?"Blind1":"Blind2",viewerConfiguration);
		new GLMotif::Separator(eyeIndex==1?"Separator1":"Separator2",viewerConfiguration,GLMotif::Separator::HORIZONTAL,ss.fontHeight,GLMotif::Separator::LOWERED);
		
		/* Create three sliders to set the left or right eye position: */
		new GLMotif::Label(eyeIndex==1?"LeftEyePosLabel":"RightEyePosLabel",viewerConfiguration,eyeIndex==1?"Left Eye":"Right Eye");
		
		GLMotif::RowColumn* eyePosBox=new GLMotif::RowColumn(eyeIndex==1?"LeftEyePosBox":"RightEyePosBox",viewerConfiguration,false);
		eyePosBox->setPacking(GLMotif::RowColumn::PACK_GRID);
		for(int i=0;i<3;++i)
			{
			char epsName[14]="EyePosSlider ";
			epsName[12]=char(eyeIndex*3+i+'0');
			eyePosSliders[eyeIndex][i]=new GLMotif::TextFieldSlider(epsName,eyePosBox,7,ss.fontHeight*10.0f);
			eyePosSliders[eyeIndex][i]->getTextField()->setFieldWidth(6);
			eyePosSliders[eyeIndex][i]->getTextField()->setPrecision(sliderStepDigits);
			eyePosSliders[eyeIndex][i]->getTextField()->setFloatFormat(GLMotif::TextField::FIXED);
			eyePosSliders[eyeIndex][i]->setSliderMapping(GLMotif::TextFieldSlider::LINEAR);
			eyePosSliders[eyeIndex][i]->setValueType(GLMotif::TextFieldSlider::FLOAT);
			eyePosSliders[eyeIndex][i]->setValueRange(-sliderRange,sliderRange,sliderStep);
			eyePosSliders[eyeIndex][i]->getValueChangedCallbacks().add(this,&ViewerConfiguration::eyePosSliderCallback,eyeIndex*3+i);
			}
		eyePosBox->manageChild();
		}
	
	viewerConfiguration->manageChild();
	
	/* Initialize vislet state and GUI: */
	setViewer(getViewer(mainViewerIndex));
	}
Beispiel #14
0
NATRON_NAMESPACE_ENTER


ViewerTab::ViewerTab(const std::string& scriptName,
                     const std::list<NodeGuiPtr> & existingNodesContext,
                     const std::list<NodeGuiPtr>& activePluginsContext,
                     Gui* gui,
                     const NodeGuiPtr& node_ui,
                     QWidget* parent)
    : QWidget(parent)
    , PanelWidget(scriptName, this, gui)
    , _imp( new ViewerTabPrivate(this, node_ui) )
{
    ViewerNodePtr node = node_ui->getNode()->isEffectViewerNode();
    installEventFilter(this);
    setMouseTracking(true);
    NodePtr internalNode = node->getNode();
    QObject::connect( internalNode.get(), SIGNAL(scriptNameChanged(QString)), this, SLOT(onInternalNodeScriptNameChanged(QString)) );
    QObject::connect( internalNode.get(), SIGNAL(labelChanged(QString,QString)), this, SLOT(onInternalNodeLabelChanged(QString,QString)) );
    QObject::connect( node.get(), SIGNAL(internalViewerCreated()), this, SLOT(onInternalViewerCreated()));

    _imp->mainLayout = new QVBoxLayout(this);
    setLayout(_imp->mainLayout);
    _imp->mainLayout->setSpacing(0);
    _imp->mainLayout->setContentsMargins(0, 0, 0, 0);

    QFontMetrics fm(font(), 0);


    _imp->viewerContainer = new QWidget(this);
    _imp->viewerLayout = new QHBoxLayout(_imp->viewerContainer);
    _imp->viewerLayout->setContentsMargins(0, 0, 0, 0);
    _imp->viewerLayout->setSpacing(0);

    _imp->viewerSubContainer = new QWidget(_imp->viewerContainer);
    _imp->viewerSubContainerLayout = new QVBoxLayout(_imp->viewerSubContainer);
    _imp->viewerSubContainerLayout->setContentsMargins(0, 0, 0, 0);
    _imp->viewerSubContainerLayout->setSpacing(1);


    // Info bars
    QString inputNames[2] = {
        QString::fromUtf8("A:"), QString::fromUtf8("B:")
    };

    bool infobarvisible = node->isInfoBarVisible();
    for (int i = 0; i < 2; ++i) {
        _imp->infoWidget[i] = new InfoViewerWidget(inputNames[i], this);

    }

    // Viewer
    _imp->viewer = new ViewerGL(this);

    GuiAppInstancePtr app = gui->getApp();

    // Init viewer to project format
    {
        Format projectFormat;
        app->getProject()->getProjectDefaultFormat(&projectFormat);

        RectD canonicalFormat = projectFormat.toCanonicalFormat();
        for (int i = 0; i < 2; ++i) {
            _imp->viewer->setInfoViewer(_imp->infoWidget[i], i);
            _imp->viewer->setRegionOfDefinition(canonicalFormat, projectFormat.getPixelAspectRatio(), i);
            setInfoBarAndViewerResolution(projectFormat, canonicalFormat, projectFormat.getPixelAspectRatio(), i);
        }
        _imp->viewer->resetWipeControls();
    }

    _imp->viewerSubContainerLayout->addWidget(_imp->viewer);
    for (int i = 0; i < 2; ++i) {
        _imp->viewerSubContainerLayout->addWidget(_imp->infoWidget[i]);
        _imp->viewer->setInfoViewer(_imp->infoWidget[i], i);
        if (i == 1 || !infobarvisible) {
            _imp->infoWidget[i]->hide();
        }
    }

    manageSlotsForInfoWidget(0, true);


    _imp->viewerLayout->addWidget(_imp->viewerSubContainer);
    _imp->mainLayout->addWidget(_imp->viewerContainer);

    TimeLinePtr timeline = app->getTimeLine();
    _imp->timeLineGui = new TimeLineGui(node, timeline, getGui(), this);
    QObject::connect( _imp->timeLineGui, SIGNAL(boundariesChanged(SequenceTime,SequenceTime)),
                      this, SLOT(onTimelineBoundariesChanged(SequenceTime,SequenceTime)) );
    QObject::connect( app->getProject().get(), SIGNAL(frameRangeChanged(int,int)), _imp->timeLineGui, SLOT(onProjectFrameRangeChanged(int,int)) );
    _imp->timeLineGui->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);

    if (!node->isTimelineVisible()) {
        _imp->timeLineGui->hide();
    }

    //Add some spacing because the timeline might be black as the info
    _imp->mainLayout->addSpacing( TO_DPIY(5) );
    _imp->mainLayout->addWidget(_imp->timeLineGui);

    double leftBound, rightBound;
    leftBound = node->getPlaybackInPointKnob()->getValue();
    rightBound = node->getPlaybackOutPointKnob()->getValue();

    TimeValue projectLeft, projectRight;
    app->getProject()->getFrameRange(&projectLeft, &projectRight);

    _imp->timeLineGui->setBoundaries(leftBound, rightBound);
    onTimelineBoundariesChanged(leftBound, rightBound);
    _imp->timeLineGui->setFrameRangeEdited(projectLeft != leftBound || projectRight != rightBound);;


    manageTimelineSlot(false, timeline);

    QObject::connect( node.get(), SIGNAL(renderStatsAvailable(int,double,RenderStatsMap)),
                      this, SLOT(onRenderStatsAvailable(int,double,RenderStatsMap)) );
    QObject::connect( _imp->viewer, SIGNAL(zoomChanged(int)), this, SLOT(updateZoomComboBox(int)) );
    QObject::connect( node.get(), SIGNAL(viewerDisconnected()), this, SLOT(disconnectViewer()) );


    createNodeViewerInterface(node_ui);
    setPluginViewerInterface(node_ui);
    
    for (std::list<NodeGuiPtr>::const_iterator it = existingNodesContext.begin(); it != existingNodesContext.end(); ++it) {
        ViewerNodePtr isViewerNode = (*it)->getNode()->isEffectViewerNode();
        // For viewers, create the viewer interface separately
        if (!isViewerNode) {
            createNodeViewerInterface(*it);
        }
    }
    for (std::list<NodeGuiPtr>::const_iterator it = activePluginsContext.begin(); it != activePluginsContext.end(); ++it) {
        ViewerNodePtr isViewerNode = (*it)->getNode()->isEffectViewerNode();
        // For viewers, create the viewer interface separately
        if (!isViewerNode) {
            setPluginViewerInterface(*it);
        }
    }


    setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);

    _imp->viewerNode.lock()->setUiContext( getViewer() );

    QTimer::singleShot( 25, _imp->timeLineGui, SLOT(recenterOnBounds()) );


    //Refresh the viewport lock state
    const std::list<ViewerTab*>& viewers = getGui()->getViewersList();
    if ( !viewers.empty() ) {
        ViewerTab* other = viewers.front();
        if ( other->getInternalNode()->isViewersSynchroEnabled() ) {
            double left, bottom, factor, par;
            other->getViewer()->getProjection(&left, &bottom, &factor, &par);
            _imp->viewer->setProjection(left, bottom, factor, par);
            node->setViewersSynchroEnabled(true);
        }
    }

    _imp->cachedFramesThread.reset(new CachedFramesThread(this));
    _imp->cachedFramesThread->start();
}