void ControlPointEditorStroke::adjustChunkParity() {
  TStroke *stroke = getStroke();
  if (!stroke) return;
  int firstChunk;
  int secondChunk = stroke->getChunkCount();
  int i;
  for (i = stroke->getChunkCount() - 1; i > 0; i--) {
    if (tdistance(stroke->getChunk(i - 1)->getP0(),
                  stroke->getChunk(i)->getP2()) < 0.5)
      continue;
    TPointD p0 = stroke->getChunk(i - 1)->getP1();
    TPointD p1 = stroke->getChunk(i - 1)->getP2();
    TPointD p2 = stroke->getChunk(i)->getP1();
    if (isCuspPoint(p0, p1, p2) || isLinearPoint(p0, p1, p2)) {
      firstChunk = i;
      insertPoint(stroke, firstChunk, secondChunk);
      secondChunk = firstChunk;
    }
  }
  insertPoint(stroke, 0, secondChunk);
}
Example #2
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);
	};
Example #3
0
void tglDraw(const TVectorRenderData &rd, TRegion *r, bool pushAttribs) {
  checkErrorsByGL;
  assert(r);
  checkErrorsByGL;
  if (!r) return;
  bool alphaChannel = rd.m_alphaChannel;
  checkErrorsByGL;

  int j          = 0;
  bool visible   = false;
  int colorCount = 0;

  TColorStyleP style;
  if (rd.m_paintCheckEnabled && r->getStyle() == rd.m_colorCheckIndex) {
    static TSolidColorStyle *redColor = new TSolidColorStyle();
    redColor->addRef();
    redColor->setMainColor(TPixel::Red);
    style = redColor;
  } else if (rd.m_tcheckEnabled) {
    static TSolidColorStyle *color = new TSolidColorStyle();
    color->addRef();
    color->setMainColor(rd.m_tCheckPaint);
    style = color;
  } else
    style = rd.m_palette->getStyle(r->getStyle());

  colorCount = style->getColorParamCount();
  if (colorCount == 0) {  // for example texture
    visible = true;
  } else {
    visible = false;
    for (j = 0; j < colorCount && !visible; j++) {
      TPixel32 color            = style->getColorParamValue(j);
      if (rd.m_cf) color        = (*(rd.m_cf))(color);
      if (color.m != 0) visible = true;
    }
  }
  if (visible) {
    TRegionProp *prop = r->getProp(/*rd.m_palette*/);
    /// questo codice satva dentro tregion::getprop/////
    int styleId = r->getStyle();
    if (styleId) {
      // TColorStyle * style = rd.m_palette->getStyle(styleId);
      if (!style->isRegionStyle() || style->isEnabled() == false) {
        prop = 0;
      } else {
        // Warning: The same remark of stroke props holds here.
        if (!prop || style.getPointer() != prop->getColorStyle()) {
          r->setProp(style->makeRegionProp(r));
          prop = r->getProp();
        }
      }
    }

    ////// draw
    if (prop) {
      if (pushAttribs) glPushAttrib(GL_ALL_ATTRIB_BITS);

      tglEnableLineSmooth(true);
//#define DRAW_EDGE_NUMBERS
#ifdef DRAW_EDGE_NUMBERS
      glPushMatrix();
      tglMultMatrix(rd.m_aff);
      switch (Index % 7) {
      case 0:
        tglColor(TPixel::Red);
        break;
      case 1:
        tglColor(TPixel::Green);
        break;
      case 2:
        tglColor(TPixel::Blue);
        break;
      case 3:
        tglColor(TPixel::Cyan);
        break;
      case 4:
        tglColor(TPixel::Magenta);
        break;
      case 5:
        tglColor(TPixel::Yellow);
        break;
      case 6:
        tglColor(TPixel::Black);
        break;
      default:
        tglColor(TPixel::Red);
        break;
      }

      Index++;
      if (rIndex == 2) {
        double y = r->getEdge(0)
                       ->m_s
                       ->getThickPoint(
                           (r->getEdge(0)->m_w0 + r->getEdge(0)->m_w1) / 2.0)
                       .y;
        tglDrawSegment(TPointD(-1000, y), TPointD(1000, y));
      }

      for (int i = 0; i < (int)r->getEdgeCount(); i++) {
        TEdge *e  = r->getEdge(i);
        TPointD p = e->m_s->getPoint(0.8 * e->m_w0 + 0.2 * e->m_w1);
        if (i == 0)
          tglDrawText(p,
                      (QString::number(rIndex) + QString("-0")).toStdString());
        else
          tglDrawText(p, QString::number(i).toStdString());
        if (e->m_index == 3) {
          tglColor(TPixel::Black);
          TStroke *s = e->m_s;
          drawPoint(s->getChunk(0)->getP0(), .3);
          tglColor(TPixel::Red);
          tglDrawText(s->getChunk(0)->getP0(),
                      QString::number(0).toStdString());
          for (int ii = 0; ii < s->getChunkCount(); ii++) {
            drawPoint(s->getChunk(ii)->getP2(), .3);
            if (ii < s->getChunkCount() - 1) {
              tglColor(TPixel::Red);
              tglDrawText(s->getChunk(ii)->getP2(),
                          QString::number(ii + 1).toStdString());
            }
          }
        }
      }
      glPopMatrix();
#endif

      if (alphaChannel) {
        GLboolean red, green, blue, alpha;
        tglGetColorMask(red, green, blue, alpha);

        // Draw RGB channels
        tglEnableBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glColorMask(red, green, blue, GL_FALSE);
        prop->draw(rd);

        // Draw Matte channel
        tglEnableBlending(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, alpha);
        prop->draw(rd);

        glColorMask(red, green, blue, alpha);
      } else {
        // pezza: in render, le aree fillate dei custom styles sparivano.
        if (!rd.m_isOfflineRender || !rd.m_isImagePattern)
          tglRgbOnlyColorMask();  // RGB components only

        prop->draw(rd);
      }

      if (pushAttribs) glPopAttrib();
    }
  }

  for (UINT i = 0; i < r->getSubregionCount(); i++)
    tglDraw(rd, r->getSubregion(i), pushAttribs);
  checkErrorsByGL;
}