Exemplo n.º 1
0
// -------------------------------------------------------------
void Graph::drawArrowSymbols(int x0i, int y0i, QPainter *p) const
{
  int x0, y0, x1, x2, y1, y2;
  float DX_, DY_;
  auto Scale = 1; /// \todo p->Scale;
  auto Painter = p;
  auto pp = begin();
  if(!pp->isPt())
    pp++;

  /// \todo DX DY
  DX_ = /*p->DX*/ + float(x0i)*Scale;
  DY_ = /*p->DY*/ + float(y0i)*Scale;
  y2 = DY_;

  while(!pp->isGraphEnd()) {
    if(pp->isPt()) {
      x0 = DX_ + pp->getScrX()*Scale;
      x1 = x0-4.0*Scale;
      x2 = x0+4.0*Scale;
      y0 = DY_ - (pp++)->getScrY()*Scale;
      y1 = y0+7.0*Scale;
      Painter->drawLine(QLineF(x0, y0, x0, y2));
      Painter->drawLine(QLineF(x1, y1, x0, y0));
      Painter->drawLine(QLineF(x2, y1, x0, y0));
    }
    else  pp++;
  }
}
Exemplo n.º 2
0
// -------------------------------------------------------------
void Graph::drawStarSymbols(int x0i, int y0i, QPainter *p) const
{
  float x3, x0, y0, x1, x2, y1, y2;
  float z, DX_, DY_;
  auto Scale = 1; /// \todo p->Scale;
  auto Painter = p;
  auto pp = begin();
  if(!pp->isPt())
    pp++;

  /// \todo DX DY
  DX_ = /*p->DX*/ + float(x0i)*Scale;
  DY_ = /*p->DY*/ + float(y0i)*Scale;

  while(!pp->isGraphEnd()) {
    if(pp->isPt()) {
      z = DX_ + pp->getScrX()*Scale;
      x0 = z-5.0*Scale;
      x3 = z+5.0*Scale;
      x1 = z-4.0*Scale;
      x2 = z+4.0*Scale;
      z = DY_ - (pp++)->getScrY()*Scale;
      y0 = z;
      y1 = z-4.0*Scale;
      y2 = z+4.0*Scale;
      Painter->drawLine(QLineF(x0, y0, x3, y0)); // horizontal line
      Painter->drawLine(QLineF(x1, y2, x2, y1)); // upper left to lower right
      Painter->drawLine(QLineF(x2, y2, x1, y1)); // upper right to lower left
    }
    else  pp++;
  }
}
Exemplo n.º 3
0
int isPt(struct a_NODE *node)
{
	if(!node)
		return FALSE;
	if(node->token == '&')
		return TRUE;
	if(node->token == TK_IDENTIFIER && node->node->type == ID_POINTER)
		return TRUE;

	if(node->token == '+' && isPt(node->sons[0]) && isInt(node->sons[1]))
		return TRUE;
	if(node->token == '+' && isPt(node->sons[1]) && isInt(node->sons[0]))
		return TRUE;
	if(isPt(node->sons[0]))
		return TRUE;
	return FALSE;
}
Exemplo n.º 4
0
// -------------------------------------------------------------
//draws the vectors of phasor diagram
void Graph::drawvect(int x0, int y0, QPainter *p) const
{
  float DX_, DY_;
  double beta, phi;
  QPolygon Points;
  auto Painter = p;
  QPen pen = Painter->pen();
  auto Scale = 1; /// \todo p->Scale;

  Painter->setPen(pen);
  QPainterPath path;
  auto pp = begin();
  if(!pp->isPt())
    pp++;

  /// \todo DX DY
  DX_ = /*p->DX*/ + float(x0)*Scale;
  DY_ = /*p->DY*/ + float(y0)*Scale;

  float x1, y1,x2,y2,x3,y3,x4,y4;

  while(!pp->isGraphEnd())
  {
    if(!pp->isBranchEnd())//draws the main line
    {
      x1=DX_ + pp->getScrX()*Scale;
      y1=DY_ - (pp++)->getScrY()*Scale;
      x2=DX_ + pp->getScrX()*Scale;
      y2=DY_ - (pp++)->getScrY()*Scale;
      Painter->drawLine(QLineF(x1, y1, x2, y2));
    }
    else
    {
      pp++;
      continue;
    }

      phi = atan2(double(y2-y1), double(x2-x1));
      beta = atan2(double(4), double(10));
      double alfa = beta+phi;
      double Length = sqrt(4*4+10*10);
      x3 = x2-int(Length*cos(alfa));
      y3 = y2-int(Length*sin(alfa));
      Painter->drawLine(QLineF(x3, y3, x2, y2));
      pp++;

      alfa = phi-beta;
      x4 = x2-int(Length*cos(alfa));
      y4 = y2-int(Length*sin(alfa));

      Painter->drawLine(QLineF(x4, y4, x2, y2));

  }

}
Exemplo n.º 5
0
// -------------------------------------------------------------
void Graph::drawCircleSymbols(int x0i, int y0i, ViewPainter *p) const
{
  float x0, y0;
  float z, DX_, DY_;
  auto Scale = p->Scale;
  auto Painter = p->Painter;
  auto pp = begin();
  if(!pp->isPt())
    pp++;

  z = 8.0*Scale;
  DX_ = p->DX + float(x0i)*Scale;
  DY_ = p->DY + float(y0i)*Scale;

  while(!pp->isGraphEnd()) {
    if(pp->isPt()) {
      x0 = DX_ + (pp->getScrX()-4.0)*Scale;
      y0 = DY_ - ((pp++)->getScrY()+4.0)*Scale;
      Painter->drawEllipse(QRectF(x0, y0, z, z));
    }
    else  pp++;
  }
}
Exemplo n.º 6
0
void verify(struct a_NODE * node_p)
{
	struct a_NODE * aux;
	if(node_p)
	{
	struct a_NODE node_ = *node_p;

	switch(node_.token)
	{
		// TOKENS
		case LIT_TRUE:

			break;
		case LIT_FALSE:

			break;
		case LIT_INTEGER:

			break;
		case TK_IDENTIFIER:
			break;
		case LIT_CHAR:

			break;
		case LIT_STRING:

			break;
		// LIST
		case LIST:
			verify((node_.sons[0]));
			verify((node_.sons[1]));
			break;
		// TYPE
		case KW_BOOL:
			break;
		case KW_WORD:
			break;
		case KW_BYTE:
			break;
		// FUNC_DECLARATION
		case ARGUMENTS:
			verify((node_.sons[0]));
			verify((node_.sons[1]));
			if((node_.sons[2])!=NULL)
			{
				verify((node_.sons[2]));
			}
			break;
		case D_NODE: // GAMBIARRATION
			verify((node_.sons[0]));
			verify((node_.sons[1]));
			break;
		case FUNC_DECLARATION:
			/*node_.sons[1]->node->type = ID_FUNC;
			if(node_.sons[0]->token == KW_BOOL)
				node_.sons[1]->node->dataType = ID_BOOL;
			else if(node_.sons[0]->token == KW_WORD)
				node_.sons[1]->node->dataType = ID_WORD;
			else if(node_.sons[0]->token == KW_BYTE)
				node_.sons[1]->node->dataType = ID_BYTE;

			currentFunction = node_.sons[1]->node;

			aux = node_.sons[2];
			for(aux = node_.sons[2] ; aux != NULL ; aux = aux->sons[2])
			{
				aux->sons[1]->node->type = ID_SCALAR;
				if(aux->sons[0]->token == KW_BOOL)
				{
					aux->sons[1]->node->dataType = ID_BOOL;
				}
				else if(aux->sons[0]->token == KW_WORD)
				{
					aux->sons[1]->node->dataType = ID_WORD;
				}
				else if(aux->sons[0]->token == KW_BYTE)
				{
					aux->sons[1]->node->dataType = ID_BYTE;
				}

				node_.sons[1]->node->args = insertInIntList(aux->sons[0]->token,node_.sons[1]->node->args);
			}
			*/
			currentFunction = node_.sons[1]->node;
			verify((node_.sons[3])); // SEMPRE D_NODE , GAMBIARRATIONN

			break;
		// DECLARATIONS
		case PROG:
			verify((node_.sons[0]));
			verify((node_.sons[1]));
			break;
		case DECLARATION:
			if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER)
				{hasError++;printf("Semantic error on line %d: variable %s already declared \n",node_.lineNumber,node_.sons[1]->node->value);}
			else
			{
				if(node_.sons[0]->token == KW_BOOL)
					node_.sons[1]->node->dataType = ID_BOOL;
				else if(node_.sons[0]->token == KW_WORD)
					node_.sons[1]->node->dataType = ID_WORD;
				else if(node_.sons[0]->token == KW_BYTE)
					node_.sons[1]->node->dataType = ID_BYTE;
				node_.sons[1]->node->type = ID_SCALAR;
				if(!(
					(node_.sons[0]->token == KW_BOOL && (node_.sons[2]->token == LIT_TRUE || node_.sons[2]->token == LIT_FALSE)) ||
					(((node_.sons[0]->token == KW_WORD) || (node_.sons[0]->token == KW_BYTE)) && ((node_.sons[2]->token == LIT_INTEGER)||(node_.sons[2]->token == LIT_CHAR)))))
					{hasError++;printf("Semantic error on line %d: Scalar initialized wrong.\n",node_.lineNumber);}
			}

			break;
		case DECLARATION_POINTER:
			if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER)
				{hasError++;printf("Semantic error on line %d: variable already declared\n",node_.lineNumber);}
			else
			{
				if(node_.sons[0]->token == KW_BOOL)
					node_.sons[1]->node->dataType = ID_BOOL;
				else if(node_.sons[0]->token == KW_WORD)
					node_.sons[1]->node->dataType = ID_WORD;
				else if(node_.sons[0]->token == KW_BYTE)
					node_.sons[1]->node->dataType = ID_BYTE;
				node_.sons[1]->node->type = ID_POINTER;
			}
			break;
		case DECLARATION_VEC:
			if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER)
				{hasError++;printf("Semantic error on line %d: variable already declared\n",node_.lineNumber);}
			else
			{
				if(node_.sons[0]->token == KW_BOOL)
					node_.sons[1]->node->dataType = ID_BOOL;
				else if(node_.sons[0]->token == KW_WORD)
					node_.sons[1]->node->dataType = ID_WORD;
				else if(node_.sons[0]->token == KW_BYTE)
					node_.sons[1]->node->dataType = ID_BYTE;
				node_.sons[1]->node->type = ID_VECTOR;

				if(!isInt(node_.sons[2]))
					{hasError++;printf("Semantic error on line %d: Vector with not-integer size\n",node_.lineNumber);}
			}
			break;
		case DECLARATION_VEC_INIT:
			if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER)
				{hasError++;printf("Semantic error on line %d: variable already declared\n",node_.lineNumber);}
			else
			{
				if(node_.sons[0]->token == KW_BOOL)
					node_.sons[1]->node->dataType = ID_BOOL;
				else if(node_.sons[0]->token == KW_WORD)
					node_.sons[1]->node->dataType = ID_WORD;
				else if(node_.sons[0]->token == KW_BYTE)
					node_.sons[1]->node->dataType = ID_BYTE;
				node_.sons[1]->node->type = ID_VECTOR;

				if(!isInt(node_.sons[2]))
					{hasError++;printf("Semantic error on line %d: Vector with not-integer size\n",node_.lineNumber);}
				if(!(node_.sons[3]->token == LIST))
					{hasError++;printf("Semantic error on line %d: Vector initialized wrong.\n",node_.lineNumber);}
			}
			break;

		// EXPRESSION
		case '&':
			if(!(node_.sons[0]->node->type==ID_SCALAR))
				{hasError++;printf("Semantic error: getting reference for not-scalar on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			break;
		case POINTER:
			if(!(node_.sons[0]->node->type==ID_POINTER))
				{hasError++;printf("Semantic error: using not-pointer as pointer on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			break;
		case '*':
			if(!(isInt(node_.sons[0]) && isInt(node_.sons[1])))
				{hasError++;printf("Semantic error: multiplying not integer on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case '(':
			verify((node_.sons[0]));
			break;
		case '+':
			if(!(isInt(node_.sons[0]) && isInt(node_.sons[1])))
				{hasError++;printf("Semantic error: adding not integer on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case '-':
			if(!(isInt(node_.sons[0]) && isInt(node_.sons[1])))
				{hasError++;printf("Semantic error: subtracting not integer on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case '/':
			if(!(isInt(node_.sons[0]) && isInt(node_.sons[1])))
				{hasError++;printf("Semantic error: dividing not integer on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case OR:
			if(!(isBoolean(node_.sons[0]) && isBoolean(node_.sons[1])))
				{hasError++;printf("Semantic error: '||' with not boolean on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case AND:
			if(!(isBoolean(node_.sons[0]) && isBoolean(node_.sons[1])))
				{hasError++;printf("Semantic error: '&&' with not boolean on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case LE:
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case EQ:
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case GE:
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case NE:
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case '>':
			if(!(isInt(node_.sons[0]) && isInt(node_.sons[1])))
				{hasError++;printf("Semantic error: '>' with not integer on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case '<':
			if(!(isInt(node_.sons[0]) && isInt(node_.sons[1])))
				{hasError++;printf("Semantic error: '<' with not integer on line %d\n",node_.lineNumber);}
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		case VECCALL:
			if(node_.sons[0]->node->type == SYMBOL_IDENTIFIER)
				{hasError++;printf("Semantic error: Vector %s not declared used on line %d\n",node_.sons[0]->node->value,node_.lineNumber);}
			if(!isInt(node_.sons[1]))
				{hasError++;printf("Semantic error: Vector index not integer on line %d\n",node_.lineNumber);}
			if(!(node_.sons[0]->node->type==ID_VECTOR))
				{hasError++;printf("Semantic error: Something not-vector used as vector on line %d\n",node_.lineNumber);}
			break;
		case NORMAL:
			if(node_.sons[0]->node->type == SYMBOL_IDENTIFIER)
				{hasError++;printf("Semantic error: Variable %s not declared used on line %d\n",node_.sons[0]->node->value,node_.lineNumber);}
			if(node_.sons[0]->node->type != ID_SCALAR && node_.sons[0]->node->type != ID_POINTER)
				{hasError++;printf("Semantic error: Something not-scalar used as scalar on line %d\n",node_.lineNumber);}
			break;
		// FUNCALL ARGCALL CMD_SEQ
		case FUNCALL:
			if(node_.sons[0]->node->type == SYMBOL_IDENTIFIER)
				{hasError++;printf("Semantic error: Function %s not yet declared used on line %d\n",node_.sons[0]->node->value,node_.lineNumber);}
			if(!(node_.sons[0]->node->type==ID_FUNC))
				{hasError++;printf("Semantic error: Something not-function used as function on line %d\n",node_.lineNumber);}
			testArguments(node_.sons[0]->node,node_.sons[1]);
			break;
		case ARGCALL:
			break;
		case CMD_SEQ:
			verify((node_.sons[0]));
			verify((node_.sons[1]));
			break;
		// OUTPUT
		case OUTPUT_L:
			verify(node_.sons[0]);
			verify(node_.sons[1]);
			break;
		// CMD
		case INPUT:
			verify(node_.sons[0]);
			break;
		case OUTPUT:
			verify(node_.sons[0]);
			break;
		case RETURN:
			if(!currentFunction)
				{hasError++;printf("Semantic error: 'return' in wrong place on line %d\n",node_.lineNumber);}
			else if(currentFunction->dataType == ID_WORD)
			{
				if(!isInt(node_.sons[0]))
					{hasError++;printf("Semantic error: wrong return type for function %s, on line %d\n",currentFunction->value,node_.lineNumber);}
			}
			else if(currentFunction->dataType == ID_BYTE)
			{
				if(!isInt(node_.sons[0]))
					{hasError++;printf("Semantic error: wrong return type for function %s, on line %d\n",currentFunction->value,node_.lineNumber);}
			}
			else if(currentFunction->dataType == ID_BOOL)
			{
				if(!isBoolean(node_.sons[0]))
					{hasError++;printf("Semantic error: wrong return type for function %s, should be boolean, on line %d\n",currentFunction->value,node_.lineNumber);}
			}
			break;
		case BLOCK:
			verify((node_.sons[0]));
			break;
		case '=':
			verify(node_.sons[1]); ////////////////////////////////////////////////////////////////////// REMEMBER
			if(node_.sons[0]->token == VECCALL)
			{
				if(!(node_.sons[0]->sons[0]->node->type == ID_VECTOR))
					{hasError++;printf("Semantic error: not-vector used as vector on line %d\n",node_.lineNumber);}

				if(!isInt(node_.sons[0]->sons[1]))
					{hasError++;printf("Semantic error: vector index is not integer on line %d\n",node_.lineNumber);}

				if(node_.sons[0]->sons[0]->node->dataType == ID_WORD)
				{
					if(!isInt(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to integer vector from not-integer on line %d\n",node_.lineNumber);}
				}
				else if(node_.sons[0]->sons[0]->node->dataType == ID_BYTE)
				{
					if(!isInt(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to integer vector from not-integer on line %d\n",node_.lineNumber);}
				}
				else if(node_.sons[0]->sons[0]->node->dataType == ID_BOOL)
				{
					if(!isBoolean(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to boolean vector from not-boolean on line %d\n",node_.lineNumber);}
				}
				else
					{hasError++;printf("Semantic error: identifier %s not declared on line %d\n",node_.sons[0]->node->value,node_.lineNumber);}
			}
			else if(node_.sons[0]->token == POINTER)
			{
				if(node_.sons[0]->sons[0]->node->type != ID_POINTER)
					{hasError++;printf("Semantic error: dereferencing non-pointer on line %d\n",node_.lineNumber);}
				if(node_.sons[0]->sons[0]->node->dataType == ID_WORD)
				{

					if(!isInt(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);}
				}
				else if(node_.sons[0]->sons[0]->node->dataType == ID_BYTE)
				{
					if(!isInt(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);}
				}
				else if(node_.sons[0]->sons[0]->node->dataType == ID_BOOL)
				{
					if(!isBoolean(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to boolean scalar from not-boolean on line %d\n",node_.lineNumber);}
				}
				else
					{hasError++;printf("Semantic error: identifier %s not declared on line %d\n",node_.sons[0]->node->value,node_.lineNumber);}
			}
			else if(node_.sons[0]->node->type == ID_POINTER)
			{
				if(!isPt(node_.sons[1]))
				{
					{hasError++;printf("Semantic error: atributin a non-pointer to a pointer on line %d\n",node_.lineNumber);}
				}

			}
			else if(node_.sons[0]->node->type == ID_SCALAR)
			{
				if(node_.sons[0]->node->type == ID_VECTOR)
					{hasError++;printf("Semantic error: vector used as not-vector on line %d\n",node_.lineNumber);}
				if(node_.sons[0]->node->dataType == ID_WORD)
				{
					if(!isInt(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);}
				}
				else if(node_.sons[0]->node->dataType == ID_BYTE)
				{
					if(!isInt(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);}
				}
				else if(node_.sons[0]->node->dataType == ID_BOOL)
				{
					if(!isBoolean(node_.sons[1]))
						{hasError++;printf("Semantic error: atributing to boolean scalar from not-boolean on line %d\n",node_.lineNumber);}
				}
				else
					{hasError++;printf("Semantic error: identifier %s not declared on line %d\n",node_.sons[0]->node->value,node_.lineNumber);}
			}
			else
			{
				{hasError++;printf("Semantic error: atributing to non-variable on line %d\n",node_.lineNumber);}
			}
			break;
		case IF_THEN:
			if(!isBoolean(node_.sons[0]))
				{hasError++;printf("Semantic error: if called with not-boolean on line %d\n",node_.lineNumber);}
			verify(node_.sons[1]);
			break;
		case IF_THEN_ELSE:
			if(!isBoolean(node_.sons[0]))
				{hasError++;printf("Semantic error: if called with not-boolean on line %d\n",node_.lineNumber);}
			verify(node_.sons[1]);
			verify(node_.sons[2]);
			break;
		case LOOP :
			if(!isBoolean(node_.sons[0]))
				{hasError++;printf("Semantic error: loop called with not-boolean on line %d\n",node_.lineNumber);}
			verify(node_.sons[1]);
			break;
		// DEFAULT
		default:
			break;

	} // switch
	} // if node
}
Exemplo n.º 7
0
/*!
 * Checks if the coordinates x/y point to the graph. returns the number of the
 * branch of the graph, -1 upon a miss.
 *
 * x/y are relative to diagram cx/cy. 5 is the precision the user must point
 * onto the graph.
 *
 * FIXME: should return reference to hit sample point or some context.
 */
int Graph::getSelected(int x, int y)
{
  auto pp = ScrPoints.begin();
  if(pp == ScrPoints.end()) return -1;

  int A, z=0;
  int dx, dx2, x1;
  int dy, dy2, y1;

  int countX = cPointsX.at(0)->count;
  if(pp->isStrokeEnd()) {
    if(pp->isBranchEnd()) z++;
    pp++;
    if(pp->isBranchEnd()) {
      if(pp->isGraphEnd())  return -1;   // not even one point ?
      z++;
      pp++;
      if(pp->isGraphEnd())  return -1;   // not even one point ?
    }
  }

  if(Style >= GRAPHSTYLE_STAR || gy!=NULL) {
    // for graph symbols
    while(!pp->isGraphEnd()) {
      if(!pp->isStrokeEnd()) {
        dx  = x - int((pp)->getScrX());
        dy  = y - int((pp++)->getScrY());

        if(dx < -5) continue;
        if(dx >  5) continue;
        if(dy < -5) continue;
        if(dy >  5) continue;
        return z*countX;   // points on graph symbol
      }
      else {
        z++;   // next branch
        pp++;
      }
    }
    return -1;
  }

  // for graph lines
  while(!pp->isGraphEnd()) {
    while(!pp->isBranchEnd()) {
      x1 = int(pp->getScrX());
      y1 = int((pp++)->getScrY());
      dx  = x - x1;
      dy  = y - y1;

      if(pp->isPt()){
        dx2 = int(pp->getScrX());
      }else if(pp->isBranchEnd()) {
        break;
      }else if(pp->isStrokeEnd()) {
        pp++;
        dx2 = int(pp->getScrX());  // go on as graph can also be selected between strokes
        if(pp->isBranchEnd()) break;
      }
      if(dx < -5) { if(x < dx2-5) continue; } // point between x coordinates ?
      else { if(x > 5) if(x > dx2+5) continue; }

      dy2 = int(pp->getScrY());
      if(dy < -5) { if(y < dy2-5) continue; } // point between y coordinates ?
      else { if(y > 5) if(y > dy2+5) continue; }

      dx2 -= x1;
      dy2 -= y1;

      A  = dx2*dy - dx*dy2;    // calculate the rectangle area spanned
      A *= A;                  // avoid the need for square root
      A -= 25*(dx2*dx2 + dy2*dy2);  // substract selectable area

      if(A <= 0)  return z*countX;  // lies x/y onto the graph line ?
    }
    pp++;
    z++;
  }

  return -1;
}
Exemplo n.º 8
0
/*!
 * draw a (line) graph from screen coord pairs
 */
void Graph::drawLines(int x0, int y0, QPainter *p) const
{
  float DX_, DY_;
  float x1, y1;
  auto Scale = 1; /// \todo p->Scale;
  auto Painter = p;
  QVector<qreal> dashes;

  double Stroke=10., Space=0.;
  switch(Style) {
    case GRAPHSTYLE_DASH:
      Stroke = 10.; Space =  6.;
      break;
    case GRAPHSTYLE_DOT:
      Stroke =  2.; Space =  4.;
      break;
    case GRAPHSTYLE_LONGDASH:
      Stroke = 24.; Space =  8.;
      break;
    default:
      break;
  }

  QPen pen = Painter->pen();
  switch(Style) {
    case GRAPHSTYLE_DASH:
    case GRAPHSTYLE_DOT:
    case GRAPHSTYLE_LONGDASH:
      dashes << Stroke << Space;
      pen.setDashPattern(dashes);
      Painter->setPen(pen);
      break;
    default:
      pen.setStyle(Qt::SolidLine);
      break;
  }
  Painter->setPen(pen);

  auto pp = begin();
  if(!pp->isPt())
    pp++;

  /// \todo DX DY
  DX_ = /*p->DX*/ + float(x0)*Scale;
  DY_ = /*p->DY*/ + float(y0)*Scale;

  while(!pp->isGraphEnd()) {
    if(pp->isStrokeEnd()) ++pp; // ??
    QPainterPath path;
    if(pp->isPt()) {
      x1 = DX_ + pp->getScrX()*Scale;
      y1 = DY_ - pp->getScrY()*Scale;
      path.moveTo(x1,y1);
      ++pp;
    }else{
      break;
    }

    while(!pp->isStrokeEnd()) {
      x1 = DX_ + pp->getScrX()*Scale;
      y1 = DY_ - pp->getScrY()*Scale;
      path.lineTo(x1,y1);
      ++pp;
    }

    Painter->drawPath(path);
  }
}