Exemplo n.º 1
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();
}
Exemplo n.º 2
0
	void leftButtonDrag(const TPointD &p, const TMouseEvent &)
	{

		if (!m_active)
			return;

		//      double dx = p.x - m_pointAtMouseDown.x;
		double pixelSize = getPixelSize();
		if (tdistance2(p, m_oldPos) < 9.0 * pixelSize * pixelSize)
			return;

		m_oldPos = p;
		m_pointAtMouseDown = p;

		//double sc = exp(0.001 * (double)dx);
		TVectorImageP vi = TImageP(getImage(true));
		if (!vi)
			return;
		QMutexLocker lock(vi->getMutex());
		TPointD
			offset = p - m_pointAtMove;

		/*
      if( tdistance2(m_pointAtMouseDown, p ) > sq(m_pointSize * 0.5) ) // reincremento
      {
      leftButtonUp(p);
      lefrightButtonDown(p);
      }
    */
		UINT i, j;

		for (i = 0; i < m_strokeHit.size(); ++i)
			modifyControlPoints(*m_strokeHit[i],
								TStrokePointDeformation(offset, m_pointAtMouseDown, m_pointSize * 0.7));

		for (i = 0; i < m_strokeToModify.size(); ++i)
			for (j = 0; j < m_strokeToModify[i].m_splittedToMove.size(); ++j) {
				TStroke *temp = m_strokeToModify[i].m_splittedToMove[j];
				modifyControlPoints(*temp, TStrokePointDeformation(offset, m_pointAtMouseDown, m_pointSize * 0.7));
			}

		m_pointAtMove = p;

		invalidate();
	};
Exemplo n.º 3
0
	void leftButtonUp(const TPointD &, const TMouseEvent &)
	{
		if (!m_active)
			return;

		m_active = false;
		m_pointAtMouseDown = m_pointAtMove = TConsts::napd;

		TStroke *ref;

		TVectorImageP vi = TImageP(getImage(true));
		if (!vi)
			return;
		QMutexLocker lock(vi->getMutex());
		UINT i, j;

		for (i = 0; i < m_strokeHit.size(); ++i) {
			ref = m_strokeHit[i];
			ref->enableComputeOfCaches();
			ref->reduceControlPoints(getPixelSize() * ReduceControlPointCorrection, *(m_hitStrokeCorners[i]));
			// vi->validateRegionEdges(ref, false);
		}
		clearPointerContainer(m_hitStrokeCorners);
		m_hitStrokeCorners.clear();

		UINT count = 0;
		for (i = 0; i < m_strokeToModify.size(); ++i) {
			// recupero la stroke collection
			MagnetTool::strokeCollection &sc = m_strokeToModify[i];

			for (j = 0; j < sc.m_splittedToMove.size(); ++j) {
				ref = sc.m_splittedToMove[j];
				ref->enableComputeOfCaches();
				ref->reduceControlPoints(getPixelSize() * ReduceControlPointCorrection, *(m_strokeToModifyCorners[count++]));
			}

			// ricostruisco una stroke con quella data
			ref = merge(sc.m_splitted);

			if (sc.m_parent->isSelfLoop()) {
				int cpCount = ref->getControlPointCount();
				TThickPoint p1 = ref->getControlPoint(0);
				TThickPoint p2 = ref->getControlPoint(cpCount - 1);
				TThickPoint midP = (p1 + p2) * 0.5;
				ref->setControlPoint(0, midP);
				ref->setControlPoint(cpCount - 1, midP);
				ref->setSelfLoop(true);
			}

			sc.m_parent->swapGeometry(*ref);

			delete ref;							  // elimino la curva temporanea
			clearPointerContainer(sc.m_splitted); // pulisco le stroke trovate con lo split
			sc.m_splittedToMove.clear();		  // pulisco il contenitore ( le stroke
												  // che erano contenute qua sono state
												  // eliminate nella clearPointer....
		}
		clearPointerContainer(m_strokeToModifyCorners);
		m_strokeToModifyCorners.clear();

		for (i = 0; i < vi->getStrokeCount(); ++i) {
			ref = vi->getStroke(i);
			ref->invalidate();
		}

		vi->notifyChangedStrokes(m_changedStrokes, m_oldStrokesArray);
		notifyImageChanged();
		if (m_undo)
			TUndoManager::manager()->add(m_undo);
		m_undo = 0;
		clearPointerContainer(m_oldStrokesArray);
		m_oldStrokesArray.clear();
		invalidate();
	};
Exemplo n.º 4
0
	void leftButtonDown(const TPointD &pos, const TMouseEvent &e)
	{
		TPointD p(pos);

		m_oldPos = pos;

		m_pointAtMouseDown = p;
		m_startingPos = p;
		m_active = false;
		TVectorImageP vi = TImageP(getImage(true));
		if (!vi)
			return;
		QMutexLocker lock(vi->getMutex());
		m_active = true;

		m_pointAtMove = m_pointAtMouseDown = p;
		m_strokeHit.clear();
		m_changedStrokes.clear();
		m_strokeToModify.clear();

		std::vector<TStroke *> strokeUndo;

		TStroke *ref;

		m_hitStrokeCorners.clear();
		m_strokeToModifyCorners.clear();

		UINT i = 0;
		for (; i < vi->getStrokeCount(); ++i) {
			if (!vi->inCurrentGroup(i))
				continue;

			TStroke *stroke = vi->getStroke(i);
			ref = stroke;
			//  calcola le intersezioni
			std::vector<double> intersections;
			intersect(*ref, p, m_pointSize, intersections);

			if (intersections.empty()) {
				if (increaseControlPoints(*ref,
										  TStrokePointDeformation(p, m_pointSize))) {
					m_changedStrokes.push_back(i);
					m_strokeHit.push_back(ref);

					std::vector<int> *corners = new std::vector<int>;
					corners->push_back(0);
					detectCorners(ref, 20, *corners);
					corners->push_back(ref->getChunkCount());
					m_hitStrokeCorners.push_back(corners);

					ref->disableComputeOfCaches();

					strokeUndo.push_back(ref);
				}
			} else {
				strokeUndo.push_back(ref);

				MagnetTool::strokeCollection sc;

				sc.m_parent = ref;

				splitStroke(*sc.m_parent, intersections, sc.m_splitted);

				selectStrokeToMove(sc.m_splitted,
								   p,
								   m_pointSize,
								   sc.m_splittedToMove);
				for (UINT ii = 0; ii < sc.m_splittedToMove.size(); ++ii) {
					TStroke *temp = sc.m_splittedToMove[ii];
					bool test = increaseControlPoints(*temp, TStrokePointDeformation(p, m_pointSize));
					assert(test);

					std::vector<int> *corners = new std::vector<int>;
					corners->push_back(0);
					detectCorners(temp, 20, *corners);
					corners->push_back(temp->getChunkCount());
					m_strokeToModifyCorners.push_back(corners);
				}

				m_strokeToModify.push_back(sc);
				m_changedStrokes.push_back(i);
			}
		}

		m_oldStrokesArray.resize(m_changedStrokes.size());
		for (i = 0; i < m_changedStrokes.size(); i++)
			m_oldStrokesArray[i] = new TStroke(*(vi->getStroke(m_changedStrokes[i])));

		if (!strokeUndo.empty()) {
			if (TTool::getApplication()->getCurrentObject()->isSpline())
				m_undo = new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());
			else {
				TXshSimpleLevel *sl = TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
				assert(sl);
				TFrameId id = getCurrentFid();
				m_undo = new UndoModifyListStroke(sl, id, strokeUndo);
			}
		}

		invalidate();
		// vi->validateRegionEdges(ref, true);
	};