예제 #1
0
파일: AtomLayer.C 프로젝트: nutjunkie/IQmol
void Atom::drawArrow(float length)
{
   static GLUquadric* quadric = gluNewQuadric();
   static const GLfloat radius(0.04f);
   GLfloat coneRadius(3.20f*radius);
   GLfloat headLength(1.80f*coneRadius);
   GLfloat tubeLength(length-headLength);
   glColor4fv(s_vibrationVectorColor);

   if (2.0*length < headLength) {
      // Zero out very small vectors to tydy things up.
      return;

   }else if (length < headLength) {
      coneRadius *= length/headLength;
      headLength  = length;
      tubeLength  = 0.0f;
   }else {
      // Only Vectors longer than headLength have a tube.
      gluQuadricOrientation(quadric, GLU_OUTSIDE);
      gluCylinder(quadric, radius, radius, tubeLength, Primitive::s_resolution, 1);
      gluQuadricOrientation(quadric, GLU_INSIDE);
      gluDisk(quadric, 0.0, radius, Primitive::s_resolution, 1);
   }

   glTranslatef(0.0, 0.0, tubeLength);
   gluQuadricOrientation(quadric, GLU_OUTSIDE);
   gluCylinder(quadric, coneRadius, 0.0, headLength, Primitive::s_resolution, 1);
   gluQuadricOrientation(quadric, GLU_INSIDE);
   gluDisk(quadric, 0.0, coneRadius, Primitive::s_resolution, 1);
}
예제 #2
0
bool ArrowMarker::eventFilter(QObject *, QEvent *e)
{
	switch(e->type()) {
		case QEvent::MouseButtonPress:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				if (me->button() != Qt::LeftButton)
					return false;
				QRect handler = QRect (QPoint(0,0), QSize(10, 10));
				handler.moveCenter (startPoint());
				if (handler.contains(me->pos()))
				{
					QApplication::setOverrideCursor(QCursor(Qt::SizeAllCursor), true);
					d_op = MoveStart;
					return true;
				}
				handler.moveCenter (endPoint());
				if (handler.contains(me->pos()))
				{
					QApplication::setOverrideCursor(QCursor(Qt::SizeAllCursor), true);
					d_op = MoveEnd;
					return true;
				}
				int d = qRound(width() + (int)floor(headLength()*tan(M_PI*headAngle()/180.0) + 0.5));
				if (dist(me->pos().x(),me->pos().y()) <= d)
				{
					QApplication::setOverrideCursor(QCursor(Qt::SizeAllCursor), true);
					d_op = MoveBoth;
					d_op_startat = me->pos()-startPoint();
					return true;
				}
				return false;
			}
		case QEvent::MouseMove:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				switch(d_op) {
					case MoveStart:
						setStartPoint(me->pos());
						plot()->replot();
						return true;
					case MoveEnd:
						setEndPoint(me->pos());
						plot()->replot();
						return true;
					case MoveBoth:
						setEndPoint(endPoint()+me->pos()-d_op_startat-startPoint());
						setStartPoint(me->pos()-d_op_startat);
						plot()->replot();
						return true;
					default:
						return false;
				}
			}
		case QEvent::MouseButtonRelease:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				switch(d_op) {
					case MoveStart:
						setStartPoint(me->pos());
						plot()->replot();
						d_op = None;
						QApplication::restoreOverrideCursor();
						return true;
					case MoveEnd:
						setEndPoint(me->pos());
						plot()->replot();
						d_op = None;
						QApplication::restoreOverrideCursor();
						return true;
					case MoveBoth:
						setXValue(plot()->invTransform(xAxis(), me->pos().x()-d_op_startat.x()));
						setYValue(plot()->invTransform(yAxis(), me->pos().y()-d_op_startat.y()));
						plot()->replot();
						d_op = None;
						QApplication::restoreOverrideCursor();
						return true;
					default:
						d_op = None;
						QApplication::restoreOverrideCursor();
						return false;
				}
			}
		case QEvent::MouseButtonDblClick:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				if (me->button() != Qt::LeftButton)
					return false;
				LineDialog *ld = new LineDialog(this, plot()->window());
				ld->exec();
				return true;
			}
		default:
			return false;
	}
}