Esempio n. 1
0
bool PointImp::hit(LocationType point) const
{
   PlotViewImp* pPlot = getPlot();
   if (pPlot == NULL)
   {
      return false;
   }

   double dScreenX = 0.0;
   double dScreenY = 0.0;
   pPlot->translateWorldToScreen(point.mX, point.mY, dScreenX, dScreenY);

   double dCurrentScreenX = 0.0;
   double dCurrentScreenY = 0.0;

   pPlot->translateDataToScreen(mLocation.mX, mLocation.mY, dCurrentScreenX, dCurrentScreenY);

   double dXDist = fabs(dCurrentScreenX - dScreenX);
   double dYDist = fabs(dCurrentScreenY - dScreenY);

   double dDist = mSymbolSize;
   if (isSelected() == true)
   {
      dDist *= 2.0;
   }

   if ((dXDist < dDist) && (dYDist < dDist))
   {
      return true;
   }

   return false;
}
Esempio n. 2
0
bool CurveImp::hit(LocationType point) const
{
   PlotViewImp* pPlot = getPlot();
   if (pPlot == NULL)
   {
      return false;
   }

   unsigned int numPoints = mPoints.size();
   for (unsigned int i = 0; i < numPoints; i++)
   {
      double dScreenX = 0;
      double dScreenY = 0;
      pPlot->translateWorldToScreen(point.mX, point.mY, dScreenX, dScreenY);

      LocationType currentPoint = mPoints.at(i);

      double dCurrentScreenX = 0;
      double dCurrentScreenY = 0;
      pPlot->translateDataToScreen(currentPoint.mX, currentPoint.mY, 
         dCurrentScreenX, dCurrentScreenY);

      double dXDist = fabs(dCurrentScreenX - dScreenX);
      double dYDist = fabs(dCurrentScreenY - dScreenY);

      if ((dXDist < 3.0) && (dYDist < 3.0))
      {
         return true;
      }
   }

   return false;
}
Esempio n. 3
0
PlotWidget* PlotSetImp::createPlot(const QString& strPlotName, const PlotType& plotType)
{
   if (strPlotName.isEmpty() == true)
   {
      return NULL;
   }

   // Do not create the plot if a plot with the given name already exists
   PlotWidget* pPlot = getPlot(strPlotName);
   if (pPlot != NULL)
   {
      return NULL;
   }

   // Create the plot widget
   pPlot = new PlotWidgetAdapter(SessionItemImp::generateUniqueId(), strPlotName.toStdString(), plotType,
      dynamic_cast<PlotSet*>(this), this);
   if (pPlot != NULL)
   {
      // Block undo actions from being added to the plot view
      PlotViewImp* pPlotView = dynamic_cast<PlotViewImp*>(pPlot->getPlot());
      if (pPlotView != NULL)
      {
         pPlotView->blockUndo();
      }

      // Add the plot widget to the plot set
      addPlot(pPlot);
   }

   return pPlot;
}
Esempio n. 4
0
void PointImp::draw()
{
   LocationType pixelSize(1.0, 1.0);

   PlotViewImp* pPlot = dynamic_cast<PlotViewImp*> (getPlot());
   if (pPlot != NULL)
   {
      pixelSize = pPlot->getPixelSize();
   }

   draw(pixelSize);
}
Esempio n. 5
0
bool PointImp::getExtents(double& dMinX, double& dMinY, double& dMaxX, double& dMaxY)
{
   PlotViewImp* pPlot = getPlot();
   VERIFY(pPlot != NULL);

   double dWorldX = 0.0;
   double dWorldY = 0.0;

   pPlot->translateDataToWorld(mLocation.mX, mLocation.mY, dWorldX, dWorldY);

   dMinX = dMaxX = dWorldX;
   dMinY = dMaxY = dWorldY;
   return true;
}
Esempio n. 6
0
bool CurveImp::getExtents(double& dMinX, double& dMinY, double& dMaxX, double& dMaxY)
{
   unsigned int numPoints = mPoints.size();
   if (numPoints == 0)
   {
      return false;
   }

   PlotViewImp* pPlot = getPlot();
   VERIFY(pPlot != NULL);

   dMinX = 1e38;
   dMinY = 1e38;
   dMaxX = -1e38;
   dMaxY = -1e38;

   for (unsigned int i = 0; i < numPoints; i++)
   {
      LocationType point = mPoints.at(i);

      double dWorldX = 0.0;
      double dWorldY = 0.0;

      pPlot->translateDataToWorld(point.mX, point.mY, dWorldX, dWorldY);

      if (dWorldX < dMinX)
      {
         dMinX = dWorldX;
      }

      if (dWorldY < dMinY)
      {
         dMinY = dWorldY;
      }

      if (dWorldX > dMaxX)
      {
         dMaxX = dWorldX;
      }

      if (dWorldY > dMaxY)
      {
         dMaxY = dWorldY;
      }
   }

   return true;
}
Esempio n. 7
0
void PlotSetImp::addPlot(PlotWidget* pPlot)
{
   if (pPlot == NULL)
   {
      return;
   }

   if (containsPlot(pPlot) == true)
   {
      return;
   }

   // Get the plot view
   PlotViewImp* pView = dynamic_cast<PlotViewImp*>(pPlot->getPlot());
   if (pView == NULL)
   {
      return;
   }

   // Get the plot name
   const string& plotName = pView->getDisplayName(true);
   if (plotName.empty() == true)
   {
      return;
   }

   // Add the new tab
   PlotWidgetImp* pPlotImp = dynamic_cast<PlotWidgetImp*>(pPlot);
   if (pPlotImp != NULL)
   {
      VERIFYNR(connect(pView, SIGNAL(renamed(const QString&)), this, SLOT(updatePlotName())));
      addTab(pPlotImp, QString::fromStdString(plotName));

      QString text = QString::fromStdString(plotName);
      QAction* pAction = mpSelector->addAction(text);
      QVariant variant(indexOf(pPlotImp));
      pAction->setData(variant);

      emit plotAdded(pPlot);
      notify(SIGNAL_NAME(PlotSet, PlotAdded), boost::any(pPlot));
      setCurrentPlot(pPlot);
   }
Esempio n. 8
0
void TextImp::draw()
{
   if (isVisible() == false)
   {
      return;
   }

   PlotViewImp* pPlot = dynamic_cast<PlotViewImp*>(getPlot());
   if (pPlot != NULL)
   {
      glColor3ub(mColor.red(), mColor.green(), mColor.blue());

      double dScreenX = 0.0;
      double dScreenY = 0.0;
      pPlot->translateDataToScreen(mLocation.mX, mLocation.mY, dScreenX, dScreenY);

      int screenX = static_cast<int>(dScreenX);
      int screenY = pPlot->height() - static_cast<int>(dScreenY);
      pPlot->renderText(screenX, screenY, mText, mFont);
   }
}
Esempio n. 9
0
bool TextImp::getExtents(double& dMinX, double& dMinY, double& dMaxX, double& dMaxY)
{
   PlotViewImp* pPlot = getPlot();
   if (pPlot == NULL)
   {
      return false;
   }

   double dScreenX = 0;
   double dScreenY = 0;
   pPlot->translateDataToScreen(mLocation.mX, mLocation.mY, dScreenX, dScreenY);

   QFontMetrics ftMetrics(mFont);
   int iHeight = ftMetrics.height();
   int iWidth = ftMetrics.width(mText);

   double dScreenExtentX = dScreenX + iWidth;
   double dScreenExtentY = dScreenY + iHeight;

   pPlot->translateDataToWorld(mLocation.mX, mLocation.mY, dMinX, dMinY);
   pPlot->translateScreenToWorld(dScreenExtentX, dScreenExtentY, dMaxX, dMaxY);

   return true;
}
Esempio n. 10
0
void CurveImp::draw()
{
   if (isVisible() == false)
   {
      return;
   }

   unsigned int numPoints = mPoints.size();
   if (numPoints == 0)
   {
      return;
   }

   glColor3ub(mColor.red(), mColor.green(), mColor.blue());
   glLineWidth(mLineWidth);

   if (mLineStyle != SOLID_LINE)
   {
      glEnable(GL_LINE_STIPPLE);

      if (mLineStyle == DASHED)
      {
         glLineStipple(3, 0x3f3f);
      }
      else if (mLineStyle == DOT)
      {
         glLineStipple(2, 0x1111);
      }
      else if (mLineStyle == DASH_DOT)
      {
         glLineStipple(2, 0x11ff);
      }
      else if (mLineStyle == DASH_DOT_DOT)
      {
         glLineStipple(2, 0x24ff);
      }
   }

   glBegin(GL_LINE_STRIP);

   PlotViewImp* pPlot = getPlot();
   VERIFYNRV(pPlot != NULL);

   double dWorldX = 0.0;
   double dWorldY = 0.0;

   unsigned int i = 0;
   for (i = 0; i < numPoints; i++)
   {
      LocationType point = mPoints.at(i);
      pPlot->translateDataToWorld(point.mX, point.mY, dWorldX, dWorldY);
      glVertex2d(dWorldX, dWorldY);
   }

   glEnd();

   if (mLineStyle != SOLID_LINE)
   {
      glDisable(GL_LINE_STIPPLE);
   }

   glLineWidth(1);

   if (isSelected() == true)
   {
      for (i = 0; i < numPoints; i++)
      {
         LocationType point = mPoints.at(i);

         double dScreenX = 0;
         double dScreenY = 0;
         pPlot->translateDataToScreen(point.mX, point.mY, dScreenX, dScreenY);

         double dX1 = dScreenX - 4;
         double dY1 = dScreenY - 4;
         double dX2 = dScreenX + 4;
         double dY2 = dScreenY + 4;

         double dPixelX1 = 0.0;
         double dPixelY1 = 0.0;
         double dPixelX2 = 0.0;
         double dPixelY2 = 0.0;

         pPlot->translateScreenToWorld(dX1, dY1, dPixelX1, dPixelY1);
         pPlot->translateScreenToWorld(dX2, dY2, dPixelX2, dPixelY2);

         glBegin(GL_POLYGON);
         glVertex2d(dPixelX1, (dPixelY1 + dPixelY2) / 2);
         glVertex2d((dPixelX1 + dPixelX2) / 2, dPixelY1);
         glVertex2d(dPixelX2, (dPixelY1 + dPixelY2) / 2);
         glVertex2d((dPixelX1 + dPixelX2) / 2, dPixelY2);
         glEnd();
      }
   }
}
Esempio n. 11
0
void PointImp::draw(LocationType pixelSize)
{
   if (isVisible() == false)
   {
      return;
   }

   PlotViewImp* pPlot = dynamic_cast<PlotViewImp*>(getPlot());
   VERIFYNRV(pPlot != NULL);

   if (pixelSize.mX == 0.0)
   {
      pixelSize.mX = 1.0;
   }

   if (pixelSize.mY == 0.0)
   {
      pixelSize.mY = 1.0;
   }

   double dSymbolSizeX = mSymbolSize / pixelSize.mX;
   double dSymbolSizeY = mSymbolSize / pixelSize.mY;
   double dWorldX = 0.0;
   double dWorldY = 0.0;

   pPlot->translateDataToWorld(mLocation.mX, mLocation.mY, dWorldX, dWorldY);

   // Increase point size when selected
   if (isSelected() == true)
   {
      switch (pPlot->getSelectionDisplayMode())
      {
      case SYMBOL_SELECTION: default:
         dSymbolSizeX = (mSymbolSize + 3) / pixelSize.mX;
         dSymbolSizeY = (mSymbolSize + 3) / pixelSize.mY;
         break;

      case INVERT_SELECTION:
         // Invert symbol color and draw slightly enlarged symbol behind it when selected
         glPushMatrix();
         glLineWidth(2);

         // Invert the color
         glColor3ub(255 - mColor.red(), 255 - mColor.green(), 255 - mColor.blue());

         // Draw the inverted symbol
         glTranslatef(dWorldX, dWorldY, 0);
         glScalef( (mSymbolSize + 1) / pixelSize.mX, (mSymbolSize + 1) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + mSymbol);
         glLineWidth(1);
         glPopMatrix();
         break;
      case BOX_SELECTION:
         // Draw a gray box around the symbol if it is selected
         glPushMatrix();
         glLineWidth(2);
         glColor3ub(212, 208, 200);

         glTranslatef(dWorldX, dWorldY, 0);
         glScalef((mSymbolSize+2) / pixelSize.mX, (mSymbolSize+2) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + BOX);
         glLineWidth(1);
         glPopMatrix();
         break;
      }
   }

   // Set the color
   glColor3ub(mColor.red(), mColor.green(), mColor.blue());

   glPushMatrix();
   glTranslatef(dWorldX, dWorldY, 0);
   glScalef(dSymbolSizeX, dSymbolSizeY, 0);
   glCallList(pPlot->getDisplayListIndex() + mSymbol);
   glPopMatrix();
}
Esempio n. 12
0
void PointSetImp::draw()
{
   if (isVisible() == false)
   {
      return;
   }

   if (mPoints.size() == 0)
   {
      return;
   }

   // Line
   if (mLine == true)
   {
      PlotViewImp* pPlot = getPlot();
      VERIFYNRV(pPlot != NULL);

      if (pPlot->isShadingEnabled() == false)
      {
         glColor3ub(mLineColor.red(), mLineColor.green(), mLineColor.blue());
         glShadeModel(GL_FLAT);
      }
      else
      {
         glShadeModel(GL_SMOOTH);
      }
      glLineWidth(mLineWidth);

      if (mLineStyle != SOLID_LINE)
      {
         glEnable(GL_LINE_STIPPLE);

         if (mLineStyle == DASHED)
         {
            glLineStipple(3, 0x3f3f);
         }
         else if (mLineStyle == DOT)
         {
            glLineStipple(2, 0x1111);
         }
         else if (mLineStyle == DASH_DOT)
         {
            glLineStipple(2, 0x11ff);
         }
         else if (mLineStyle == DASH_DOT_DOT)
         {
            glLineStipple(2, 0x24ff);
         }
      }

      glBegin(GL_LINE_STRIP);

      double dWorldX = 0.0;
      double dWorldY = 0.0;

      vector<Point*>::iterator iter = mPoints.begin();
      while (iter != mPoints.end())
      {
         Point* pPoint = NULL;
         pPoint = *iter;
         if (pPoint != NULL)
         {
            const LocationType& point = pPoint->getLocation();
            pPlot->translateDataToWorld(point.mX, point.mY, dWorldX, dWorldY);
            if (pPlot->isShadingEnabled() == true)
            {
               ColorType color = pPoint->getColor();
               glColor3ub(color.mRed, color.mGreen, color.mBlue);
            }
            glVertex2d(dWorldX, dWorldY);
         }

         ++iter;
      }

      glEnd();

      if (mLineStyle != SOLID_LINE)
      {
         glDisable(GL_LINE_STIPPLE);
      }

      glLineWidth(1);

      // Turn the shade model back to flat to not impact other types of plot objects
      glShadeModel(GL_FLAT);
   }
   
   // Points
   LocationType pixelSize(1.0, 1.0);

   PlotViewImp* pPlot = dynamic_cast<PlotViewImp*> (getPlot());
   if (pPlot != NULL)
   {
      pixelSize = pPlot->getPixelSize();
   }

   vector<Point*>::iterator iter = mPoints.begin();
   while (iter != mPoints.end())
   {
      PointAdapter* pPoint = NULL;
      pPoint = static_cast<PointAdapter*> (*iter);
      if (pPoint != NULL)
      {
         if ((mSymbols == true) || (mLine == false) || (pPoint->isSelected() == true))
         {
            pPoint->draw(pixelSize);
         }
      }

      ++iter;
   }
}
Esempio n. 13
0
bool PointSetImp::hit(LocationType point) const
{
   if (mLine == true)
   {
      if (mPoints.size() > 0)
      {
         PlotViewImp* pPlot = getPlot();
         if (pPlot != NULL)
         {
            double dPointX = 0.0;
            double dPointY = 0.0;
            pPlot->translateWorldToScreen(point.mX, point.mY, dPointX, dPointY);

            point.mX = dPointX;
            point.mY = dPointY;

            LocationType oldLocation;
            LocationType currentLocation;

            Point* pPoint = NULL;
            pPoint = mPoints.front();
            if (pPoint != NULL)
            {
               const LocationType& location = pPoint->getLocation();

               double dLocationX = 0.0;
               double dLocationY = 0.0;
               pPlot->translateDataToScreen(location.mX, location.mY, dLocationX, dLocationY);

               oldLocation.mX = dLocationX;
               oldLocation.mY = dLocationY;
            }

            for (unsigned int i = 1; i < mPoints.size(); i++)
            {
               pPoint = mPoints.at(i);
               if (pPoint != NULL)
               {
                  const LocationType& location = pPoint->getLocation();

                  double dLocationX = 0.0;
                  double dLocationY = 0.0;
                  pPlot->translateDataToScreen(location.mX, location.mY, dLocationX, dLocationY);

                  currentLocation.mX = dLocationX;
                  currentLocation.mY = dLocationY;

                  bool bHit = false;
                  bHit = DrawUtil::lineHit(oldLocation, currentLocation, point, 3.0);
                  if (bHit == true)
                  {
                     return true;
                  }

                  oldLocation = currentLocation;
               }
            }
         }
      }
   }

   Point* pPoint = hitPoint(point);
   return (pPoint != NULL);
}
Esempio n. 14
0
void ArrowImp::updateArrowHead()
{
   // Reset the arrow head
   mArrowHead.clear(true);
   mArrowHead.setFillStyle(EMPTY_FILL);

   // Convert the line points to screen coordinates
   PlotViewImp* pPlot = getPlot();
   if (pPlot == NULL)
   {
      return;
   }

   LocationType baseLocation = getBaseLocation();
   LocationType tipLocation = getTipLocation();

   double dBaseX = 0;
   double dBaseY = 0;
   double dTipX = 0;
   double dTipY = 0;

   pPlot->translateDataToScreen(baseLocation.mX, baseLocation.mY, dBaseX, dBaseY);
   pPlot->translateDataToScreen(tipLocation.mX, tipLocation.mY, dTipX , dTipY);

   // Calculate the end points using screen pixels
   double arrowHeadSize = 10;
   if ((mStyle == ARROW_LARGE) || (mStyle == ARROW_TRIANGLE_LARGE) || (mStyle == ARROW_TRIANGLE_LARGE_FILL))
   {
      arrowHeadSize *= 2;
   }

   double h = arrowHeadSize * sqrt(static_cast<double>(mArrowHead.getLineWidth()));
   double theta = atan2(dTipY - dBaseY, dTipX - dBaseX);
   double hcTheta = h * cos(theta);
   double hsTheta = h * sin(theta);

   double dScreenEnd1X = dTipX - hcTheta - hsTheta;
   double dScreenEnd1Y = dTipY + hcTheta - hsTheta;
   double dScreenEnd2X = dTipX - hcTheta + hsTheta;
   double dScreenEnd2Y = dTipY - hcTheta - hsTheta;
   double dScreenEnd3X = dTipX - (2 * hcTheta);
   double dScreenEnd3Y = dTipY - (2 * hsTheta);

   double dEnd1X = 0.0;
   double dEnd1Y = 0.0;
   double dEnd2X = 0.0;
   double dEnd2Y = 0.0;
   double dEnd3X = 0.0;
   double dEnd3Y = 0.0;

   pPlot->translateScreenToData(dScreenEnd1X, dScreenEnd1Y, dEnd1X, dEnd1Y);
   pPlot->translateScreenToData(dScreenEnd2X, dScreenEnd2Y, dEnd2X, dEnd2Y);
   pPlot->translateScreenToData(dScreenEnd3X, dScreenEnd3Y, dEnd3X, dEnd3Y);

   // Add the points to the arrow head object
   if (mStyle != ARROW_NONE)
   {
      mArrowHead.addPoint(dEnd1X, dEnd1Y);
      mArrowHead.addPoint(tipLocation.mX, tipLocation.mY);
      mArrowHead.addPoint(dEnd2X, dEnd2Y);
   }

   if ((mStyle == ARROW_DIAMOND) || (mStyle == ARROW_DIAMOND_FILL))
   {
      mArrowHead.addPoint(dEnd3X, dEnd3Y);
   }

   if ((mStyle == ARROW_TRIANGLE_SMALL) || (mStyle == ARROW_TRIANGLE_LARGE) ||
      (mStyle == ARROW_TRIANGLE_SMALL_FILL) || (mStyle == ARROW_TRIANGLE_LARGE_FILL) ||
      (mStyle == ARROW_DIAMOND) || (mStyle == ARROW_DIAMOND_FILL))
   {
      mArrowHead.addPoint(dEnd1X, dEnd1Y);
   }

   // Set the fill
   if ((mStyle == ARROW_TRIANGLE_SMALL_FILL) || (mStyle == ARROW_TRIANGLE_LARGE_FILL) ||
      (mStyle == ARROW_DIAMOND_FILL))
   {
      mArrowHead.setFillStyle(SOLID_FILL);
   }
}
Esempio n. 15
0
void PointImp::draw(LocationType pixelSize)
{
   if (isVisible() == false)
   {
      return;
   }

   PlotViewImp* pPlot = dynamic_cast<PlotViewImp*>(getPlot());
   VERIFYNRV(pPlot != NULL);

   if (pixelSize.mX == 0.0)
   {
      pixelSize.mX = 1.0;
   }

   if (pixelSize.mY == 0.0)
   {
      pixelSize.mY = 1.0;
   }

   double dSymbolSizeX = mSymbolSize / pixelSize.mX;
   double dSymbolSizeY = mSymbolSize / pixelSize.mY;
   double dWorldX = 0.0;
   double dWorldY = 0.0;

   pPlot->translateDataToWorld(mLocation.mX, mLocation.mY, dWorldX, dWorldY);

   // Increase point size when selected
   if (isSelected() == true)
   {
      switch (pPlot->getSelectionDisplayMode())
      {
      case SYMBOL_SELECTION: default:
         dSymbolSizeX = (mSymbolSize + 3) / pixelSize.mX;
         dSymbolSizeY = (mSymbolSize + 3) / pixelSize.mY;
         break;

      case INVERT_SELECTION:
      {
         // Invert the background color and draw slightly enlarged symbol behind it when selected
         glPushMatrix();
         glLineWidth(2);

         // Invert the color
         QColor backgroundColor = pPlot->getBackgroundColor();

         int selectionHue = -1;
         int selectionSaturation = 255;
         int selectionValue = 255;

         int pointHue = mColor.hue();
         int backgroundHue = backgroundColor.hue();
         if ((pointHue > -1) && (backgroundHue > -1))
         {
            selectionHue = (pointHue + backgroundHue) / 2;
            if (abs(pointHue - backgroundHue) < 180)
            {
               selectionHue += 180;
            }
         }
         else if (pointHue > -1)
         {
            selectionHue = pointHue + 180;
         }
         else if (backgroundHue > -1)
         {
            selectionHue = backgroundHue + 180;
         }
         else
         {
            int pointValue = mColor.value();
            int backgroundValue = backgroundColor.value();

            selectionValue = (pointValue + backgroundValue) / 2;
            if (abs(pointValue - backgroundValue) < 128)
            {
               selectionValue += 128;
            }
         }

         while (selectionHue >= 360)
         {
            selectionHue -= 360;
         }

         while (selectionValue >= 256)
         {
            selectionValue -= 256;
         }

         QColor selectionColor = QColor::fromHsv(selectionHue, selectionSaturation, selectionValue);
         glColor3ub(selectionColor.red(), selectionColor.green(), selectionColor.blue());

         // Draw the inverted symbol
         glTranslatef(dWorldX, dWorldY, 0);
         glScalef((mSymbolSize + 2) / pixelSize.mX, (mSymbolSize + 2) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + mSymbol);
         glLineWidth(1);
         glPopMatrix();
         break;
      }

      case BOX_SELECTION:
         // Draw a gray box around the symbol if it is selected
         glPushMatrix();
         glLineWidth(2);
         glColor3ub(212, 208, 200);

         glTranslatef(dWorldX, dWorldY, 0);
         glScalef((mSymbolSize+2) / pixelSize.mX, (mSymbolSize+2) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + BOX);
         glLineWidth(1);
         glPopMatrix();
         break;
      }
   }

   // Set the color
   glColor3ub(mColor.red(), mColor.green(), mColor.blue());

   glPushMatrix();
   glTranslatef(dWorldX, dWorldY, 0);
   glScalef(dSymbolSizeX, dSymbolSizeY, 0);
   glCallList(pPlot->getDisplayListIndex() + mSymbol);
   glPopMatrix();
}