示例#1
0
//---------------------------------------------------------------------------
void TGenotype::FitnessEvaluation(TNet myNet, TEnviroment enviroment, TMyAgent platform, TTool tool, Tifo ifo){
    fitnes = 0; fitnes_temp = 0;
    int steps_per_time = 1;
    vector<double> inputVals;
    vector<double> resultVals;
    vector<double> Weights;
    vector<double> Gains;
    vector<double> T_consts;
    bool turn_left, turn_right;
    PhenotypeConvertion();
    for(unsigned i = 0; i < num_Weights; ++i)
        Weights.push_back(phenotypes[ i]);
    for(unsigned i = 0; i < num_Neurons; ++i){
        Gains.push_back(phenotypes_gain[ i]);
        T_consts.push_back(phenotypes_time_const[ i]);
    }
    myNet.setWeights(Weights);
    myNet.setGains(Gains);
    myNet.setTime_const(T_consts);
    for(int run = 0; run < (13+14*(Form1->steps-1)); ++run){
        tool.setInputValues(inputVals, platform, ifo);
        myNet.feedForward(inputVals);
        myNet.getResults(resultVals);
        tool.output(resultVals, turn_left, turn_right, steps_per_time);
        platform.Move(enviroment, turn_left, turn_right, steps_per_time);
        ifo.Move(enviroment);
        if(ifo.GetPosition_y() == 13)
            platform.FitnessUpdate(ifo);
    }  fitnes = platform.GetFitness();   fitnes_temp = platform.GetFitness();
    platform.setInitialConditions();
}
void StrokeSelection::changeColorStyle(int styleIndex)
{
	TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
	if (!tool)
		return;
	TVectorImageP img(tool->getImage(true));
	if (!img)
		return;
	TPalette *palette = img->getPalette();
	TColorStyle *cs = palette->getStyle(styleIndex);
	if (!cs->isStrokeStyle())
		return;
	if (m_indexes.empty())
		return;

	UndoSetStrokeStyle *undo = new UndoSetStrokeStyle(img, styleIndex);
	std::set<int>::iterator it;
	for (it = m_indexes.begin(); it != m_indexes.end(); ++it) {
		int index = *it;
		assert(0 <= index && index < (int)img->getStrokeCount());
		TStroke *stroke = img->getStroke(index);
		undo->addStroke(stroke);
		stroke->setStyle(styleIndex);
	}

	tool->notifyImageChanged();
	TUndoManager::manager()->add(undo);
}
void StrokeSelection::removeEndpoints()
{
	if (!m_vi)
		return;
	if (m_indexes.empty())
		return;

	vector<pair<int, TStroke *>> undoData;

	m_vi->findRegions();
	set<int>::iterator it = m_indexes.begin();
	for (; it != m_indexes.end(); ++it) {
		TStroke *s = m_vi->removeEndpoints(*it);
		if (s)
			undoData.push_back(pair<int, TStroke *>(*it, s));
	}
	TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
	TXshSimpleLevel *level = TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
	if (!undoData.empty())
		TUndoManager::manager()->add(new RemoveEndpointsUndo(level, tool->getCurrentFid(), undoData));

	m_updateSelectionBBox = true;
	tool->notifyImageChanged();
	m_updateSelectionBBox = false;
}
示例#4
0
// ---------------------------------------------------------------------------
void __fastcall TfSbornyZakaz::UpdateToolsPrices() {
	// найдем номеклатуры для оборудования
	for (int i = 0; i < listOfTools->Count; i++) {
		TTool *tool = dynamic_cast<TTool*>(listOfTools->Items[i]);
		tool->ToolFindPrice(agent->typeprice);
	}
}
示例#5
0
void StrokeSelection::deleteStrokes() {
  if (!m_vi) return;
  if (m_indexes.empty()) return;
  TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
  if (!tool) return;

  bool isSpline = tool->getApplication()->getCurrentObject()->isSpline();
  TUndo *undo;
  if (isSpline)
    undo = new ToolUtils::UndoPath(
        tool->getXsheet()->getStageObject(tool->getObjectId())->getSpline());

  StrokesData *data = new StrokesData();
  data->setImage(m_vi, m_indexes);
  std::set<int> oldIndexes = m_indexes;
  deleteStrokesWithoutUndo(m_vi, m_indexes);

  if (!isSpline) {
    TXshSimpleLevel *level =
        TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
    TUndoManager::manager()->add(new DeleteStrokesUndo(
        level, tool->getCurrentFid(), oldIndexes, data, m_sceneHandle));
  } else {
    assert(undo);
    if (undo) TUndoManager::manager()->add(undo);
  }
}
void SceneViewer::inputMethodEvent(QInputMethodEvent *e) {
  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  if (tool && tool->isEnabled()) {
    tool->onInputText(e->preeditString().toStdWString(),
                      e->commitString().toStdWString(), e->replacementStart(),
                      e->replacementLength());
  }
}
void SceneViewer::leaveEvent(QEvent *) {
  if (!m_isMouseEntered) return;

  m_isMouseEntered = false;

  if (m_freezedStatus != NO_FREEZED) return;
  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  if (tool && tool->isEnabled()) tool->onLeave();
  update();
}
示例#8
0
void ControlPointSelection::setUnlinear() {
  TTool *tool            = TTool::getApplication()->getCurrentTool()->getTool();
  int currentStrokeIndex = m_controlPointEditorStroke->getStrokeIndex();
  TVectorImageP vi(tool->getImage(false));
  if (!vi || isEmpty() || currentStrokeIndex == -1) return;

  TUndo *undo;
  if (tool->getApplication()->getCurrentObject()->isSpline())
    undo = new UndoPath(
        tool->getXsheet()->getStageObject(tool->getObjectId())->getSpline());
  else {
    TXshSimpleLevel *level =
        tool->getApplication()->getCurrentLevel()->getSimpleLevel();
    UndoControlPointEditor *cpEditorUndo =
        new UndoControlPointEditor(level, tool->getCurrentFid());
    cpEditorUndo->addOldStroke(currentStrokeIndex,
                               vi->getVIStroke(currentStrokeIndex));
    undo = cpEditorUndo;
  }
  if (m_controlPointEditorStroke->getControlPointCount() == 0) return;

  bool isChanged = m_controlPointEditorStroke->setControlPointsLinear(
      m_selectedPoints, false);

  if (!isChanged) return;
  TUndoManager::manager()->add(undo);
  tool->notifyImageChanged();
}
示例#9
0
double TfSbornyZakaz::Sum() {
	LockWindowUpdate(Handle);
	double sum = 0;

	// здесь сбрасываем использование принтеров
	for (int i = 0; i < listOfTools->Count; i++) {
		TTool *tool = (TTool*)listOfTools->Items[i];
		tool->SetUse(false);
	}

	// чистим
	slgoods->Clear();
	Memo1->Clear();
	sldescription->Clear();

	if (sbForSelFrame->ControlCount == 0) {
		sum = 0;
	}
	else {
		// поищем что есть посчитать, все фреймы, виртуальная функция Sum
		for (int i = 0; i < listOfIzdelies->Count; i++) {
			TfrSelectable *izdelie =
				dynamic_cast<TfrSelectable*>(listOfIzdelies->Items[i]);
			sum += izdelie->Sum();
		}

		double zakazCount = spCount->Value;
		// подсчитаем использование оборудования
		for (int i = 0; i < listOfTools->Count; i++) {
			TToolPrepareTool *tool =
				dynamic_cast<TToolPrepareTool*>(listOfTools->Items[i]);
			if (tool && tool->GetUse() == true) {
				Memo1->Lines->Add(tool->prepareTool->myToString(zakazCount));
				sum += Ceil(tool->prepareTool->price * zakazCount);
			}
		}

	}

	lbAllPrice->Caption = "Сумма: " + FloatToStrF(sum, ffFixed, 10, 2) +
		" руб.";

	allsum = sum;

	LockWindowUpdate(NULL);
	return sum;
}
示例#10
0
void ControlPointSelection::deleteControlPoints() {
  TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
  TVectorImageP vi(tool->getImage(false));
  int currentStrokeIndex = m_controlPointEditorStroke->getStrokeIndex();
  if (!vi || isEmpty() || currentStrokeIndex == -1) return;

  // Inizializzo l'UNDO
  TUndo *undo;
  bool isCurrentObjectSpline =
      tool->getApplication()->getCurrentObject()->isSpline();
  if (isCurrentObjectSpline)
    undo = new UndoPath(
        tool->getXsheet()->getStageObject(tool->getObjectId())->getSpline());
  else {
    TXshSimpleLevel *level =
        tool->getApplication()->getCurrentLevel()->getSimpleLevel();
    UndoControlPointEditor *cpEditorUndo =
        new UndoControlPointEditor(level, tool->getCurrentFid());
    cpEditorUndo->addOldStroke(currentStrokeIndex,
                               vi->getVIStroke(currentStrokeIndex));
    undo = cpEditorUndo;
  }

  int i;
  for (i = m_controlPointEditorStroke->getControlPointCount() - 1; i >= 0; i--)
    if (isSelected(i)) m_controlPointEditorStroke->deleteControlPoint(i);

  if (m_controlPointEditorStroke->getControlPointCount() == 0) {
    m_controlPointEditorStroke->setStroke((TVectorImage *)0, -1);
    if (!isCurrentObjectSpline) {
      UndoControlPointEditor *cpEditorUndo =
          dynamic_cast<UndoControlPointEditor *>(undo);
      if (cpEditorUndo) cpEditorUndo->isStrokeDelete(true);
    }
  }

  // La spline non puo' essere cancellata completamente!!!
  if (vi->getStrokeCount() == 0) {
    if (TTool::getApplication()->getCurrentObject()->isSpline()) {
      std::vector<TPointD> points;
      double d = 10;
      points.push_back(TPointD(-d, 0));
      points.push_back(TPointD(0, 0));
      points.push_back(TPointD(d, 0));
      TStroke *stroke = new TStroke(points);
      vi->addStroke(stroke, false);
      m_controlPointEditorStroke->setStrokeIndex(0);
    }
  }
  tool->notifyImageChanged();
  selectNone();
  // Registro l'UNDO
  TUndoManager::manager()->add(undo);
}
示例#11
0
void SceneViewer::mouseDoubleClickEvent(QMouseEvent *event) {
  if (m_freezedStatus != NO_FREEZED) return;

  int frame = TApp::instance()->getCurrentFrame()->getFrame();
  if (frame == -1) return;

  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  if (!tool || !tool->isEnabled()) return;
  TMouseEvent toonzEvent;
  initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, true);
  TPointD pos              = tool->getMatrix().inv() * winToWorld(event->pos());
  TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
  if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
    pos.x /= m_dpiScale.x;
    pos.y /= m_dpiScale.y;
  }

  if (event->button() == Qt::LeftButton)
    tool->leftButtonDoubleClick(pos, toonzEvent);
}
示例#12
0
void SceneViewer::contextMenuEvent(QContextMenuEvent *e) {
#ifndef _WIN32
  /* On windows the widget receive the release event before the menu
     is shown, on linux and osx the release event is lost, never
     received by the widget */
  QMouseEvent fakeRelease(QEvent::MouseButtonRelease, e->pos(), Qt::RightButton,
                          Qt::NoButton, Qt::NoModifier);

  QApplication::instance()->sendEvent(this, &fakeRelease);
#endif

  if (m_freezedStatus != NO_FREEZED) return;
  if (m_isLocator) return;

  TPoint winPos(e->pos().x(), height() - e->pos().y());
  std::vector<int> columnIndices;
  // enable to select all the columns regardless of the click position
  for (int i = 0;
       i < TApp::instance()->getCurrentXsheet()->getXsheet()->getColumnCount();
       i++)
    columnIndices.push_back(i);

  SceneViewerContextMenu *menu = new SceneViewerContextMenu(this);

  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  TPointD pos =
      ((tool) ? tool->getMatrix().inv() : TAffine()) * winToWorld(e->pos());
  menu->addEnterGroupCommands(pos);

  menu->addLevelCommands(columnIndices);

  ComboViewerPanel *cvp = qobject_cast<ComboViewerPanel *>(
      parentWidget()->parentWidget()->parentWidget());
  if (cvp) {
    menu->addSeparator();
    cvp->addShowHideContextMenu(menu);
  }

  menu->exec(e->globalPos());
  delete menu;
}
示例#13
0
void SceneViewer::enterEvent(QEvent *) {
  if (m_isMouseEntered) return;

  m_isMouseEntered = true;

  TApp *app        = TApp::instance();
  modifiers        = 0;
  TTool *tool      = app->getCurrentTool()->getTool();
  TXshLevel *level = app->getCurrentLevel()->getLevel();
  if (level && level->getSimpleLevel())
    m_dpiScale =
        getCurrentDpiScale(level->getSimpleLevel(), tool->getCurrentFid());
  else
    m_dpiScale = TPointD(1, 1);

  if (m_freezedStatus != NO_FREEZED) return;

  invalidateToolStatus();
  if (tool && tool->isEnabled()) {
    tool->setViewer(this);
    tool->updateMatrix();
    tool->onEnter();
  }

  setFocus();
  updateGL();
}
示例#14
0
void SceneViewer::keyReleaseEvent(QKeyEvent *event) {
  if (m_freezedStatus != NO_FREEZED) return;

  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  if (!tool || !tool->isEnabled()) return;
  tool->setViewer(this);

  int key = event->key();

  if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt ||
      key == Qt::Key_AltGr) {
    if (key == Qt::Key_Shift)
      modifiers &= ~Qt::ShiftModifier;
    else if (key == Qt::Key_Control)
      modifiers &= ~Qt::ControlModifier;
    else if (key == Qt::Key_Alt || key == Qt::Key_AltGr)
      modifiers &= ~Qt::AltModifier;

    // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono
    // cambiare subito la forma del cursore, senza aspettare il prossimo move
    TMouseEvent toonzEvent;
    initToonzEvent(toonzEvent, event);
    toonzEvent.m_pos =
        TPoint(m_lastMousePos.x(), height() - 1 - m_lastMousePos.y());

    TPointD pos = tool->getMatrix().inv() * winToWorld(m_lastMousePos);

    TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
    if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
      pos.x /= m_dpiScale.x;
      pos.y /= m_dpiScale.y;
    }

    tool->mouseMove(pos, toonzEvent);
    setToolCursor(this, tool->getCursorId());
  }

  if (tool->getName() == T_Type)
    event->accept();
  else
    event->ignore();
}
示例#15
0
  void execute() override {
    TColumnSelection *selection = dynamic_cast<TColumnSelection *>(
        TApp::instance()->getCurrentSelection()->getSelection());
    TXsheet *xsh       = TApp::instance()->getCurrentXsheet()->getXsheet();
    int cc             = TApp::instance()->getCurrentColumn()->getColumnIndex();
    bool sound_changed = false;
    TTool *tool        = TApp::instance()->getCurrentTool()->getTool();
    TTool::Viewer *viewer = tool ? tool->getViewer() : nullptr;
    bool viewer_changed   = false;

    for (int i = 0; i < xsh->getColumnCount(); i++) {
      /*- 空のカラムの場合は飛ばす -*/
      if (xsh->isColumnEmpty(i)) continue;
      /*- カラムが取得できなかったら飛ばす -*/
      TXshColumn *column = xsh->getColumn(i);
      if (!column) continue;
      /*- ターゲットが選択カラムのモードで、選択されていなかった場合は飛ばす -*/
      bool isSelected = selection && selection->isColumnSelected(i);
      if (m_target == TARGET_SELECTED && !isSelected) continue;

      /*-
       * ターゲットが「カレントカラムより右側」のモードで、iがカレントカラムより左の場合は飛ばす
       * -*/
      if (m_target == TARGET_UPPER && i < cc) continue;

      bool negate = m_target == TARGET_CURRENT && cc != i ||
                    m_target == TARGET_OTHER && cc == i ||
                    m_target == TARGET_UPPER && cc == i;

      int cmd = m_cmd;

      if (cmd & (CMD_LOCK | CMD_UNLOCK | CMD_TOGGLE_LOCK)) {
        if (cmd & CMD_LOCK)
          column->lock(!negate);
        else if (cmd & CMD_UNLOCK)
          column->lock(negate);
        else
          column->lock(!column->isLocked());
        viewer_changed = true;
      }
      if (cmd &
          (CMD_ENABLE_PREVIEW | CMD_DISABLE_PREVIEW | CMD_TOGGLE_PREVIEW)) {
        if (cmd & CMD_ENABLE_PREVIEW)
          column->setPreviewVisible(!negate);
        else if (cmd & CMD_DISABLE_PREVIEW)
          column->setPreviewVisible(negate);
        else
          column->setPreviewVisible(!column->isPreviewVisible());
      }
      if (cmd &
          (CMD_ENABLE_CAMSTAND | CMD_DISABLE_CAMSTAND | CMD_TOGGLE_CAMSTAND)) {
        if (cmd & CMD_ENABLE_CAMSTAND)
          column->setCamstandVisible(!negate);
        else if (cmd & CMD_DISABLE_CAMSTAND)
          column->setCamstandVisible(negate);
        else
          column->setCamstandVisible(!column->isCamstandVisible());
        if (column->getSoundColumn()) sound_changed = true;
        viewer_changed                              = true;
      }
      /*TAB
if(cmd & (CMD_ENABLE_PREVIEW|CMD_DISABLE_PREVIEW|CMD_TOGGLE_PREVIEW))
{ //In Tab preview e cameraStand vanno settati entrambi
if(cmd&CMD_ENABLE_PREVIEW)
{
column->setPreviewVisible(!negate);
column->setCamstandVisible(!negate);
}
else if(cmd&CMD_DISABLE_PREVIEW)
{
column->setPreviewVisible(negate);
column->setCamstandVisible(negate);
}
else
{
column->setPreviewVisible(!column->isPreviewVisible());
column->setCamstandVisible(!column->isCamstandVisible());
}
}
      */
    }
    if (sound_changed)
      TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged();
    TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
    TApp::instance()->getCurrentScene()->setDirtyFlag(true);
    if (viewer && viewer_changed) viewer->invalidateToolStatus();
  }
示例#16
0
void SceneViewer::mouseMoveEvent(QMouseEvent *event) {
  if (m_freezedStatus != NO_FREEZED) return;

  QPoint curPos  = event->pos();
  bool cursorSet = false;
  m_lastMousePos = curPos;

  if (m_editPreviewSubCamera) {
    if (!PreviewSubCameraManager::instance()->mouseMoveEvent(this, event))
      return;
  }

  // if the "compare with snapshot" mode is activated, change the mouse cursor
  // on the border handle
  if (m_visualSettings.m_doCompare) {
    if (abs(curPos.x() - width() * m_compareSettings.m_compareX) < 20) {
      cursorSet = true;
      setToolCursor(this, ToolCursor::ScaleHCursor);
    } else if (abs((height() - curPos.y()) -
                   height() * m_compareSettings.m_compareY) < 20) {
      cursorSet = true;
      setToolCursor(this, ToolCursor::ScaleVCursor);
    }
  }

  // control of the border handle when the "compare with snapshot" mode is
  // activated
  if (m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) {
    if (m_compareSettings.m_dragCompareX)
      m_compareSettings.m_compareX +=
          ((double)(curPos.x() - m_pos.x())) / width();
    else if (m_compareSettings.m_dragCompareY)
      m_compareSettings.m_compareY -=
          ((double)(curPos.y() - m_pos.y())) / height();
    m_compareSettings.m_compareX =
        tcrop(m_compareSettings.m_compareX, 0.0, 1.0);
    m_compareSettings.m_compareY =
        tcrop(m_compareSettings.m_compareY, 0.0, 1.0);

    update();

    m_pos = curPos;
  } else if (m_mouseButton == Qt::NoButton || m_mouseButton == Qt::LeftButton) {
    if (is3DView() && m_current3DDevice != NONE &&
        m_mouseButton == Qt::LeftButton)
      return;
    else if (is3DView() && m_mouseButton == Qt::NoButton) {
      TRectD rect = TRectD(TPointD(m_topRasterPos.x, m_topRasterPos.y),
                           TDimensionD(20, 20));
      if (rect.contains(TPointD(curPos.x(), curPos.y())))
        m_current3DDevice = TOP_3D;
      else {
        rect = TRectD(TPointD(m_sideRasterPos.x, m_sideRasterPos.y),
                      TDimensionD(20, 20));
        if (rect.contains(TPointD(curPos.x(), curPos.y()))) {
          if (m_phi3D > 0)
            m_current3DDevice = SIDE_RIGHT_3D;
          else
            m_current3DDevice = SIDE_LEFT_3D;
        } else
          m_current3DDevice = NONE;
      }
      if (m_current3DDevice != NONE) {
        cursorSet = true;
        setToolCursor(this, ToolCursor::CURSOR_ARROW);
      }
    }

    // if the middle mouse button is pressed while dragging, then do panning
    Qt::MouseButtons mousebuttons;
    mousebuttons = event->buttons();
    if (mousebuttons & Qt::MidButton) {
      // panning
      QPoint p = curPos - m_pos;
      if (m_pos == QPoint(0, 0) && p.manhattanLength() > 300) return;
      panQt(curPos - m_pos);
      m_pos = curPos;
      return;
    }

    TTool *tool = TApp::instance()->getCurrentTool()->getTool();
    if (!tool || !tool->isEnabled()) {
      m_tabletEvent = false;
      return;
    }
    tool->setViewer(this);
    TMouseEvent toonzEvent;
    initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent,
                   false);
    TPointD worldPos = winToWorld(curPos);
    TPointD pos      = tool->getMatrix().inv() * worldPos;

    if (m_locator) {
      m_locator->onChangeViewAff(worldPos);
    }

    TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
    if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
      pos.x /= m_dpiScale.x;
      pos.y /= m_dpiScale.y;
    }

    // qDebug() << "mouseMoveEvent. "  << (m_tabletEvent?"tablet":"mouse")
    //         << " pressure=" << m_pressure << " mouseButton=" << m_mouseButton
    //         << " buttonClicked=" << m_buttonClicked;
    if ((m_tabletEvent && m_pressure > 0) || m_mouseButton == Qt::LeftButton) {
      // sometimes the mousePressedEvent is postponed to a wrong  mouse move
      // event!
      if (m_buttonClicked) tool->leftButtonDrag(pos, toonzEvent);
    } else if (m_pressure == 0) {
      tool->mouseMove(pos, toonzEvent);
      // m_tabletEvent=false;
    }
    if (!cursorSet) setToolCursor(this, tool->getCursorId());
    m_pos = curPos;
  } else if (m_mouseButton == Qt::MidButton) {
    if ((event->buttons() & Qt::MidButton) == 0)
      m_mouseButton = Qt::NoButton;
    else
      // panning
      panQt(curPos - m_pos);
    m_pos = curPos;

    return;
  }
}
示例#17
0
void StrokeSelection::paste() {
  TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
  if (!tool) return;
  if (TTool::getApplication()->getCurrentObject()->isSpline()) {
    const StrokesData *stData = dynamic_cast<const StrokesData *>(
        QApplication::clipboard()->mimeData());
    if (!stData) return;
    TVectorImageP splineImg = tool->getImage(true);
    TVectorImageP img       = stData->m_image;
    if (!splineImg || !img) return;

    QMutexLocker lock(splineImg->getMutex());
    TUndo *undo = new ToolUtils::UndoPath(
        tool->getXsheet()->getStageObject(tool->getObjectId())->getSpline());
    while (splineImg->getStrokeCount() > 0) splineImg->deleteStroke(0);

    TStroke *stroke = img->getStroke(0);
    splineImg->addStroke(new TStroke(*stroke), false);
    TUndoManager::manager()->add(undo);
    tool->notifyImageChanged();
    tool->invalidate();
    return;
  }

  TVectorImageP tarImg = tool->touchImage();
  if (!tarImg) return;
  TPaletteP palette       = tarImg->getPalette();
  TPaletteP oldPalette    = new TPalette();
  if (palette) oldPalette = palette->clone();
  bool isPaste = pasteStrokesWithoutUndo(tarImg, m_indexes, m_sceneHandle);
  if (isPaste) {
    TXshSimpleLevel *level =
        TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
    TUndoManager::manager()->add(new PasteStrokesUndo(
        level, tool->getCurrentFid(), m_indexes, oldPalette, m_sceneHandle));
    m_updateSelectionBBox = isPaste;
  }
  tool->notifyImageChanged();
  tool->getApplication()
      ->getPaletteController()
      ->getCurrentLevelPalette()
      ->notifyPaletteChanged();
  m_updateSelectionBBox = false;
  tool->invalidate();
}
示例#18
0
void SceneViewer::mousePressEvent(QMouseEvent *event) {
  // evita i press ripetuti
  if (m_buttonClicked) return;
  m_buttonClicked = true;

  if (m_freezedStatus != NO_FREEZED) return;

  if (m_mouseButton != Qt::NoButton) return;

  m_pos         = event->pos();
  m_mouseButton = event->button();

  // when using tablet, avoid unexpected drawing behavior occurs when
  // middle-click
  Qt::MouseButtons mousebuttons;
  mousebuttons = event->buttons();
  if (m_tabletEvent && m_mouseButton == Qt::MidButton &&
      (mousebuttons | Qt::LeftButton))
    return;

  if (is3DView() && m_current3DDevice != NONE &&
      m_mouseButton == Qt::LeftButton)
    return;
  else if (m_mouseButton == Qt::LeftButton && m_editPreviewSubCamera) {
    if (!PreviewSubCameraManager::instance()->mousePressEvent(this, event))
      return;
  } else if (m_mouseButton == Qt::LeftButton && m_visualSettings.m_doCompare) {
    if (abs(m_pos.x() - width() * m_compareSettings.m_compareX) < 20) {
      m_compareSettings.m_dragCompareX = true;
      m_compareSettings.m_dragCompareY = false;
      m_compareSettings.m_compareY     = ImagePainter::DefaultCompareValue;
      update();
      m_tabletEvent = false;
      return;
    } else if (abs((height() - m_pos.y()) -
                   height() * m_compareSettings.m_compareY) < 20) {
      m_compareSettings.m_dragCompareY = true;
      m_compareSettings.m_dragCompareX = false;
      m_compareSettings.m_compareX     = ImagePainter::DefaultCompareValue;
      update();
      m_tabletEvent = false;
      return;
    } else
      m_compareSettings.m_dragCompareX = m_compareSettings.m_dragCompareY =
          false;
  }

  if (m_freezedStatus != NO_FREEZED) return;

  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  if (!tool || !tool->isEnabled()) {
    m_tabletEvent = false;
    return;
  }
  tool->setViewer(this);
  if (m_mouseButton == Qt::LeftButton && tool->preLeftButtonDown()) {
    tool = TApp::instance()->getCurrentTool()->getTool();
    if (!tool || !tool->isEnabled()) {
      m_tabletEvent = false;
      return;
    }
    tool->setViewer(this);
  }

  TMouseEvent toonzEvent;
  if (m_pressure > 0 && !m_tabletEvent) m_tabletEvent = true;

  if (TApp::instance()->isPenCloseToTablet()) m_tabletEvent = true;
  initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, true);
  // if(!m_tabletEvent) qDebug() << "-----------------MOUSE PRESS 'PURO'.
  // POSSIBILE EMBOLO";
  TPointD pos = tool->getMatrix().inv() * winToWorld(m_pos);

  TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
  if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
    pos.x /= m_dpiScale.x;
    pos.y /= m_dpiScale.y;
  }
  if (m_mouseButton == Qt::LeftButton) {
    TApp::instance()->getCurrentTool()->setToolBusy(true);
    tool->leftButtonDown(pos, toonzEvent);
  }
  if (m_mouseButton == Qt::RightButton) tool->rightButtonDown(pos, toonzEvent);
}
示例#19
0
bool TMainTool::ExecuteCommand(const std::string& InTarget, std::string& InCommand, std::vector<Environment::VoidPointer>& InOutArguments)
{
	TTool* target = nullptr;
	std::string functionName;
	if (InTarget != "")
	{
		functionName = "cmd_" + InCommand;
		std::string targetName = InTarget;
		target = Container->GetElement<TTool>(targetName);
		if (target)
		{
			auto p_attribute = target->GetAttribute(functionName);
			if (p_attribute && p_attribute->Object().CastTo<RFunction*>())
			{
				//targetArgs = std::vector<VoidPointer>(args.begin() + 2, args.end());
			}
			else
			{
				target = nullptr;
			}
		}
		else
		{
			target = nullptr;
		}
	}
	else
	{
		functionName = "cmd_" + InCommand;
		std::vector<TTool*> targets = Container->GetElementsWithAttribute<TTool, RFunction*>(functionName);
		if (targets.size() == 0)
			Dialogue->WriteLine("Could not find tool with function :" + functionName);
		else if (targets.size() > 1)
		{
			Dialogue->WriteLine("Function name is ambigious. Try to specify your target via: @target " + functionName + '\n'
				+ "Following target are available: ");
			for (auto target : targets)
			{
				Dialogue->WriteLine(target->GetName());
			}
		}
		else
		{
			target = targets[0];
			//targetArgs = std::vector<VoidPointer>(args.begin() + 1, args.end());
		}
	}

	if (target == nullptr)
	{
		Dialogue->WriteLine("Could not find tool");
		return false;
	}
	else
	{
		bool success = target->GetAttribute(functionName)->Object().CastAndDereference<RFunction*>()->CorrectArgsAndExecute(InOutArguments);
		if (!success)
		{
			LOG("Command '" + functionName + "' returned false.", Logger::Severity::Warning);
		}
		return success;
	}
}
示例#20
0
void SceneViewer::mouseReleaseEvent(QMouseEvent *event) {
  // evita i release ripetuti
  if (!m_buttonClicked) return;
  m_buttonClicked = false;

  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  if (!tool || !tool->isEnabled()) {
    if (!m_toolDisableReason.isEmpty() && m_mouseButton == Qt::LeftButton &&
        !m_editPreviewSubCamera)
      DVGui::warning(m_toolDisableReason);
  }

  if (m_freezedStatus != NO_FREEZED) return;

  if (m_mouseButton != event->button()) return;

  if (m_current3DDevice != NONE) {
    m_mouseButton = Qt::NoButton;
    m_tabletEvent = false;
    m_pressure    = 0;
    if (m_current3DDevice == SIDE_LEFT_3D)
      set3DLeftSideView();
    else if (m_current3DDevice == SIDE_RIGHT_3D)
      set3DRightSideView();
    else if (m_current3DDevice == TOP_3D)
      set3DTopView();
    return;
  }

  if (m_mouseButton == Qt::LeftButton && m_editPreviewSubCamera) {
    if (!PreviewSubCameraManager::instance()->mouseReleaseEvent(this, event))
      goto quit;
  }

  if (m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) {
    m_compareSettings.m_dragCompareX = m_compareSettings.m_dragCompareY = false;
    goto quit;
  }

  m_pos = QPoint(0, 0);
  if (!tool || !tool->isEnabled()) goto quit;

  tool->setViewer(this);

  {
    TMouseEvent toonzEvent;
    initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent,
                   false);
    TPointD pos = tool->getMatrix().inv() * winToWorld(event->pos());

    TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
    if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
      pos.x /= m_dpiScale.x;
      pos.y /= m_dpiScale.y;
    }

    if (m_mouseButton == Qt::LeftButton) {
      tool->leftButtonUp(pos, toonzEvent);
      TApp::instance()->getCurrentTool()->setToolBusy(false);
    }
  }

quit:

  m_mouseButton = Qt::NoButton;
  m_tabletEvent = false;
  m_pressure    = 0;
}
示例#21
0
bool SceneViewer::event(QEvent *e) {
  if (e->type() == QEvent::ShortcutOverride || e->type() == QEvent::KeyPress) {
    if (!((QKeyEvent *)e)->isAutoRepeat()) {
      TApp::instance()->getCurrentTool()->storeTool();
    }
  }
  if (e->type() == QEvent::ShortcutOverride) {
    TTool *tool = TApp::instance()->getCurrentTool()->getTool();
    if (tool && tool->isEnabled() && tool->getName() == T_Type &&
        tool->isActive())
      e->accept();
    return true;
  }
  if (e->type() == QEvent::KeyRelease) {
    if (!((QKeyEvent *)e)->isAutoRepeat()) {
      QWidget *focusWidget = QApplication::focusWidget();
      if (focusWidget == 0 ||
          QString(focusWidget->metaObject()->className()) == "SceneViewer")
        TApp::instance()->getCurrentTool()->restoreTool();
    }
  }

  // discard too frequent move events
  static QTime clock;
  if (e->type() == QEvent::MouseButtonPress)
    clock.start();
  else if (e->type() == QEvent::MouseMove) {
    if (clock.elapsed() < 10) {
      e->accept();
      return true;
    }
    clock.start();
  }

  /*
switch(e->type())
{
case QEvent::Enter:
qDebug() << "************************** Enter";
break;
case QEvent::Leave:
qDebug() << "************************** Leave";
break;

case QEvent::TabletPress:
qDebug() << "************************** TabletPress"  << m_pressure;
break;
case QEvent::TabletMove:
qDebug() << "************************** TabletMove";
break;
case QEvent::TabletRelease:
qDebug() << "************************** TabletRelease";
break;


case QEvent::MouseButtonPress:
qDebug() << "**************************MouseButtonPress"  << m_pressure << " "
<< m_tabletEvent;
break;
case QEvent::MouseMove:
qDebug() << "**************************MouseMove" <<  m_pressure;
break;
case QEvent::MouseButtonRelease:
qDebug() << "**************************MouseButtonRelease";
break;

case QEvent::MouseButtonDblClick:
qDebug() << "============================== MouseButtonDblClick";
break;
}
*/

  return QGLWidget::event(e);
}
SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
    : QMenu(parent), m_viewer(parent), m_groupIndexToBeEntered(-1) {
  TApp *app                      = TApp::instance();
  bool isEditingLevel            = app->getCurrentFrame()->isEditingLevel();
  bool ret                       = true;
  QAction *action                = 0;
  CommandManager *commandManager = CommandManager::instance();

  /*- サブカメラの消去 -*/
  if (parent->isEditPreviewSubcamera()) {
    action = addAction(tr("Reset Subcamera"));
    ret =
        ret &&
        parent->connect(action, SIGNAL(triggered()), SLOT(doDeleteSubCamera()));
    addSeparator();
  }

  // tool
  TTool *tool = app->getCurrentTool()->getTool();
  if (tool && tool->isEnabled()) tool->addContextMenuItems(this);

  // fullscreen
  if (ImageUtils::FullScreenWidget *fsWidget =
          dynamic_cast<ImageUtils::FullScreenWidget *>(
              m_viewer->parentWidget())) {
    bool isFullScreen = (fsWidget->windowState() & Qt::WindowFullScreen) != 0;

    action =
        commandManager->createAction(V_ShowHideFullScreen, this, !isFullScreen);
    addAction(action);
    ret = ret &&
          parent->connect(action, SIGNAL(triggered()), fsWidget,
                          SLOT(toggleFullScreen()));
  }

  // swap compared
  if (parent->canSwapCompared()) {
    action = addAction(tr("Swap Compared Images"));
    ret    = ret &&
          parent->connect(action, SIGNAL(triggered()), SLOT(swapCompared()));
  }

  // reset
  action = commandManager->createAction(V_ZoomReset, this);
  addAction(action);
  ret = ret &&
        parent->connect(action, SIGNAL(triggered()), SLOT(resetSceneViewer()));

  if (!isEditingLevel) {
    // fit camera
    action = commandManager->createAction(V_ZoomFit, this);
    addAction(action);
    ret = ret &&
          parent->connect(action, SIGNAL(triggered()), SLOT(fitToCamera()));
  }

  // actual pixel size
  action = commandManager->createAction(V_ActualPixelSize, this);
  addAction(action);
  ret =
      ret &&
      parent->connect(action, SIGNAL(triggered()), SLOT(setActualPixelSize()));

  // onion skin
  if (Preferences::instance()->isOnionSkinEnabled() &&
      !parent->isPreviewEnabled())
    OnioniSkinMaskGUI::addOnionSkinCommand(this);

  // preview
  if (parent->isPreviewEnabled()) {
    addSeparator();

    // save previewed frames
    action = addAction(tr("Save Previewed Frames"));
    action->setShortcut(QKeySequence(
        CommandManager::instance()->getKeyFromId(MI_SavePreviewedFrames)));
    ret = ret &&
          parent->connect(action, SIGNAL(triggered()), this,
                          SLOT(savePreviewedFrames()));

    // regenerate preview
    action = addAction(tr("Regenerate Preview"));
    action->setShortcut(QKeySequence(
        CommandManager::instance()->getKeyFromId(MI_RegeneratePreview)));
    ret =
        ret &&
        parent->connect(action, SIGNAL(triggered()), SLOT(regeneratePreview()));

    // regenerate frame preview
    action = addAction(tr("Regenerate Frame Preview"));
    action->setShortcut(QKeySequence(
        CommandManager::instance()->getKeyFromId(MI_RegenerateFramePr)));
    ret = ret &&
          parent->connect(action, SIGNAL(triggered()),
                          SLOT(regeneratePreviewFrame()));
  }

  assert(ret);
}
示例#23
0
void SceneViewer::keyPressEvent(QKeyEvent *event) {
  if (m_freezedStatus != NO_FREEZED) return;

  int key = event->key();

  if (changeFrameSkippingHolds(event)) {
    return;
  }
  if ((event->modifiers() & Qt::ShiftModifier) &&
      (key == Qt::Key_Down || key == Qt::Key_Up)) {
  }

  TTool *tool = TApp::instance()->getCurrentTool()->getTool();
  if (!tool) return;

  bool isTextToolActive = tool->getName() == T_Type && tool->isActive();

  if (!isTextToolActive && ViewerZoomer(this).exec(event)) return;

  if (!isTextToolActive && SceneViewerShortcutReceiver(this).exec(event))
    return;

  if (!tool->isEnabled()) return;

  tool->setViewer(this);

  // If this object is child of Viewer or ComboViewer
  // (m_isStyleShortcutSelective = true),
  // then consider about shortcut for the current style selection.
  if (m_isStyleShortcutSwitchable &&
      Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&
      (!isTextToolActive) && (event->modifiers() == Qt::NoModifier ||
                              event->modifiers() == Qt::KeypadModifier) &&
      ((Qt::Key_0 <= key && key <= Qt::Key_9) || key == Qt::Key_Tab ||
       key == Qt::Key_Backtab)) {
    event->ignore();
    return;
  }

  if (key == Qt::Key_Shift)
    modifiers |= Qt::SHIFT;
  else if (key == Qt::Key_Control)
    modifiers |= Qt::CTRL;
  else if (key == Qt::Key_Alt || key == Qt::Key_AltGr)
    modifiers |= Qt::ALT;

  if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt ||
      key == Qt::Key_AltGr) {
    // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono
    // cambiare subito la forma del cursore, senza aspettare il prossimo move
    TMouseEvent toonzEvent;
    initToonzEvent(toonzEvent, event);
    toonzEvent.m_pos =
        TPoint(m_lastMousePos.x(), height() - 1 - m_lastMousePos.y());

    TPointD pos = tool->getMatrix().inv() * winToWorld(m_lastMousePos);

    TObjectHandle *objHandle = TApp::instance()->getCurrentObject();
    if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) {
      pos.x /= m_dpiScale.x;
      pos.y /= m_dpiScale.y;
    }

    tool->mouseMove(pos, toonzEvent);
    setToolCursor(this, tool->getCursorId());
  }

  bool shiftButton = QApplication::keyboardModifiers() == Qt::ShiftModifier;

  TUINT32 flags = 0;
  TPoint pos;
  if (key == Qt::Key_Shift)
    flags = TwConsts::TK_ShiftPressed;
  else if (key == Qt::Key_Control)
    flags = TwConsts::TK_CtrlPressed;
  else if (key == Qt::Key_Alt)
    flags = TwConsts::TK_AltPressed;
  else if (key == Qt::Key_CapsLock)
    flags = TwConsts::TK_CapsLock;
  else if (key == Qt::Key_Backspace)
    key = TwConsts::TK_Backspace;
  else if (key == Qt::Key_Return)
    key = TwConsts::TK_Return;
  else if (key == Qt::Key_Left && !shiftButton)
    key = TwConsts::TK_LeftArrow;
  else if (key == Qt::Key_Right && !shiftButton)
    key = TwConsts::TK_RightArrow;
  else if (key == Qt::Key_Up && !shiftButton)
    key = TwConsts::TK_UpArrow;
  else if (key == Qt::Key_Down && !shiftButton)
    key = TwConsts::TK_DownArrow;
  else if (key == Qt::Key_Left && shiftButton)
    key = TwConsts::TK_ShiftLeftArrow;
  else if (key == Qt::Key_Right && shiftButton)
    key = TwConsts::TK_ShiftRightArrow;
  else if (key == Qt::Key_Up && shiftButton)
    key = TwConsts::TK_ShiftUpArrow;
  else if (key == Qt::Key_Down && shiftButton)
    key = TwConsts::TK_ShiftDownArrow;
  else if (key == Qt::Key_Home)
    key = TwConsts::TK_Home;
  else if (key == Qt::Key_End)
    key = TwConsts::TK_End;
  else if (key == Qt::Key_PageUp)
    key = TwConsts::TK_PageUp;
  else if (key == Qt::Key_PageDown)
    key = TwConsts::TK_PageDown;
  else if (key == Qt::Key_Insert)
    key = TwConsts::TK_Insert;
  else if (key == Qt::Key_Delete)
    key = TwConsts::TK_Delete;
  else if (key == Qt::Key_Escape)
    key = TwConsts::TK_Esc;
  else if (key == Qt::Key_F1)
    key = TwConsts::TK_F1;
  else if (key == Qt::Key_F2)
    key = TwConsts::TK_F2;
  else if (key == Qt::Key_F3)
    key = TwConsts::TK_F3;
  else if (key == Qt::Key_F4)
    key = TwConsts::TK_F4;
  else if (key == Qt::Key_F5)
    key = TwConsts::TK_F5;
  else if (key == Qt::Key_F6)
    key = TwConsts::TK_F6;
  else if (key == Qt::Key_F7)
    key = TwConsts::TK_F7;
  else if (key == Qt::Key_F8)
    key = TwConsts::TK_F8;
  else if (key == Qt::Key_F9)
    key = TwConsts::TK_F9;
  else if (key == Qt::Key_F10)
    key = TwConsts::TK_F10;
  else if (key == Qt::Key_F11)
    key = TwConsts::TK_F11;
  else if (key == Qt::Key_F12)
    key = TwConsts::TK_F12;
  else if (key == Qt::Key_Menu || key == Qt::Key_Meta)
    return;

  bool ret = false;
  if (tool)  // && m_toolEnabled)
  {
    QString text = event->text();
    if ((event->modifiers() & Qt::ShiftModifier)) text.toUpper();
    std::wstring unicodeChar = text.toStdWString();
    ret = tool->keyDown(key, unicodeChar, flags, pos);  // per il textTool
    if (ret) {
      update();
      return;
    }
    ret = tool->keyDown(key, flags, pos);  // per gli altri tool
  }
  if (!ret) {
    TFrameHandle *fh = TApp::instance()->getCurrentFrame();

    if (key == TwConsts::TK_UpArrow)
      fh->prevFrame();
    else if (key == TwConsts::TK_DownArrow)
      fh->nextFrame();
    else if (key == TwConsts::TK_Home)
      fh->firstFrame();
    else if (key == TwConsts::TK_End)
      fh->lastFrame();
  }
  update();
  // TODO: devo accettare l'evento?
}