示例#1
0
void ModuleView::generateImage()
{
  if(image)
  {
    delete image;
    image = 0;
  }
  
  const QString& dotName(QDir::temp().filePath("ModuleView.dot"));
  if(generateDotFile(dotName.toAscii().constData()))
  {
    const QString& pngName(QDir::temp().filePath("ModuleView.png"));
#ifdef _WIN32
    const QString& cmd(QString("\"%1\\Util\\dot-1.9.0\\dot.exe\" -Tpng -o \"%2\" \"%3\"").arg(File::getGTDir(), pngName, dotName));
#else
    const QString& cmd(QString("dot -Tpng -o \"%1\" \"%2\"").arg(pngName, dotName));
#endif
    if(QProcess::execute(cmd) == 0)
    {
      image = new QPixmap(pngName);
      if(image->isNull())
      {
        delete image;
        image = 0;
      }
      QFile::remove(pngName);
    }
    SYNC_WITH(console);
    lastModulInfoTimeStamp = console.moduleInfo.timeStamp;
  }

  QFile::remove(dotName);
}
示例#2
0
QString ModuleGraphViewObject::generateDotFileContent()
{
  SYNC_WITH(console);
  lastModulInfoTimeStamp = console.moduleInfo.timeStamp;
  const ModuleInfo& m = console.moduleInfo;
  bool success = false;
  std::stringstream stream;
  stream << "digraph G {" << std::endl;
  stream << "node [style=filled,fillcolor=lightyellow,fontname=Arial,fontsize=9,height=0.2];" << std::endl;
  stream << "concentrate = true;" << std::endl;

  for(std::list<ModuleInfo::Module>::const_iterator i = m.modules.begin(); i != m.modules.end(); ++i)
    if(i->processIdentifier == processIdentifier && (category == "" || i->category == category))
    {
      bool used = false;
      for(std::vector<std::string>::const_iterator j = i->representations.begin(); j != i->representations.end(); ++j)
      {
        std::list<ModuleInfo::Provider>::const_iterator k = std::find(m.providers.begin(), m.providers.end(), *j);
        while(k != m.providers.end() && k->selected != i->name)
          k = std::find(++k, m.providers.end(), *j);
        if(k != m.providers.end())
        {
          used = true;
          stream << j->c_str() << " [style=filled,fillcolor=\"lightblue\"];" << std::endl;
          stream << i->name << "->" << j->c_str() << " [len=2];" << std::endl;
        }
      }
      if(used)
      {
        for(std::vector<std::string>::const_iterator j = i->requirements.begin(); j != i->requirements.end(); ++j)
        {
          std::list<ModuleInfo::Provider>::const_iterator k = std::find(m.providers.begin(), m.providers.end(), *j);
          while(k != m.providers.end() && (k->selected == "" || k->processIdentifier != processIdentifier))
            k = std::find(++k, m.providers.end(), *j);
          if(k == m.providers.end())
          {
            // no provider in same process
            k = std::find(m.providers.begin(), m.providers.end(), *j);
            while(k != m.providers.end() && k->selected == "")
              k = std::find(++k, m.providers.end(), *j);
            if(k == m.providers.end())
              stream << j->c_str() << " [style=\"filled,dashed\",color=red,fontcolor=red];" << std::endl;
            else
              stream << j->c_str() << " [style=\"filled,dashed\",fillcolor=\"#ffdec4\"];" << std::endl;
          }
          stream << j->c_str() << "->" << i->name << " [len=2];" << std::endl;
        }
        if(i->name == "default")
          stream << i->name.c_str() << "[shape=box,fontcolor=red];" << std::endl;
        else
          stream << i->name.c_str() << "[shape=box];" << std::endl;
        success = true;
      }
    }

  stream << "}" << std::endl;
  return success ? QString(stream.str().c_str()) : QString();

}
示例#3
0
void TimeWidget::update()
{
  SYNC_WITH(timeView.console);
  {
    if(timeView.info.timeStamp == lastTimeInfoTimeStamp)
    {
      return;
    }
    lastTimeInfoTimeStamp = timeView.info.timeStamp;

    if(SystemCall::getTimeSince(lastUpdate) < 200) //only update 5 times per second
    {
      return;
    }
    lastUpdate = SystemCall::getCurrentSystemTime();

    float avgFrequency = -1.0;
    timeView.info.getProcessStatistics(avgFrequency);
    frequency->setText(" Frequency: " + QString::number(avgFrequency));

    table->setUpdatesEnabled(false);
    table->setSortingEnabled(false);//disable sorting while updating to avoid race conditions
    for(TimeInfo::Infos::const_iterator i = timeView.info.infos.begin(), end = timeView.info.infos.end(); i != end; ++i)
    {
      std::string name = timeView.info.getName(i->first);
      Row* currentRow = NULL;
      if(items.find(i->first) != items.end())
      {//already know this one
        currentRow = items[i->first];
      }
      else
      {//new item
        currentRow = new Row;
        currentRow->avg = new NumberTableWidgetItem();
        currentRow->max = new NumberTableWidgetItem();
        currentRow->min = new NumberTableWidgetItem();
        currentRow->name = new QTableWidgetItem();
        const int rowCount = table->rowCount();
        table->setRowCount(rowCount + 1);
        table->setItem(rowCount, 0, currentRow->name);
        table->setItem(rowCount, 1, currentRow->min);
        table->setItem(rowCount, 2, currentRow->max);
        table->setItem(rowCount, 3, currentRow->avg);
        items[i->first] = currentRow;
      }
      float minTime = -1, maxTime = -1, avgTime = -1;
      timeView.info.getStatistics(i->second, minTime, maxTime, avgTime);
      currentRow->avg->setText(QString::number(avgTime));
      currentRow->min->setText(QString::number(minTime));
      currentRow->max->setText(QString::number(maxTime));
      currentRow->name->setText(QString(name.c_str())); //refresh name every time to eliminate unknown
    }
  }
  applyFilter();
  table->setSortingEnabled(true);
  table->setUpdatesEnabled(true);
  table->update();
}
void ColorCalibrationWidget::update()
{
  SYNC_WITH(colorCalibrationView.console);
  if(colorCalibrationView.console.colorCalibrationTimeStamp != timeStamp)
  {
    updateWidgets(currentColor);
    timeStamp = colorCalibrationView.console.colorCalibrationTimeStamp;
  }
}
示例#5
0
void DebugDrawing3D::draw()
{
  if(robotConsole)
  {
    SYNC_WITH(*robotConsole);
    draw2();
  }
  else
    draw2();
}
 void update()
 {
   {
     SYNC_WITH(cabslBehaviorView.console);
     if(cabslBehaviorView.timeStamp == lastCABSLBehaviorDebugInfoTimeStamp)
       return;
     lastCABSLBehaviorDebugInfoTimeStamp = cabslBehaviorView.timeStamp;
   }
   QWidget::update();
 }
示例#7
0
void TimeView::updateWidget(QWidget& widget)
{
  {
    SYNC_WITH(console);
    if(info.timeStamp == lastTimeInfoTimeStamp)
      return;
    lastTimeInfoTimeStamp = info.timeStamp;
  }

  timeWidget->update();
}
示例#8
0
  void update()
  {
    {
      SYNC_WITH(sensorView.console);
      if(sensorView.sensorData.timeStamp == lastUpdateTimeStamp)
        return;
      lastUpdateTimeStamp = sensorView.sensorData.timeStamp;
    }

    QWidget::update();
  }
示例#9
0
bool ColorSpaceView::needsUpdate() const
{
  SYNC_WITH(console);
  Image* image = 0;
  RobotConsole::Images& currentImages = upperCam ? console.upperCamImages : console.lowerCamImages;
  RobotConsole::Images::const_iterator i = currentImages.find(name);
  if(i != currentImages.end())
    image = i->second.image;
  return ((image && image->timeStamp != lastTimeStamp) ||
          (!image && lastTimeStamp));
}
示例#10
0
void ModuleView::updateWidget(QWidget& widget)
{
  {
    SYNC_WITH(console);
    if(lastModulInfoTimeStamp == console.moduleInfo.timeStamp)
      return;
  }
  generateImage();
  ((ModuleWidget*)(&widget))->image = image;
  widget.update();
}
示例#11
0
void SensorView::updateWidget(QWidget& widget)
{
  {
    SYNC_WITH(console);
    if(sensorData.timeStamp == lastUpdateTimeStamp)
      return;
    lastUpdateTimeStamp = sensorData.timeStamp;
  }

  sensorWidget->update();
}
示例#12
0
void ColorSpaceView::updateDisplayLists()
{
  SYNC_WITH(console);
  Image* image = 0,
       * raw = 0;

  RobotConsole::Images& currentImages = upperCam ? console.upperCamImages : console.lowerCamImages;
  RobotConsole::Images::const_iterator i = currentImages.find(name);

  if(i != currentImages.end())
    image = i->second.image;
  i = currentImages.find("raw image");
  if(i != currentImages.end())
    raw = i->second.image;
  if(image && (channel < 3 || raw))
  {
    if(!channel)
      OpenGLMethods::paintCubeToOpenGLList(256, 256, 256,
                                           cubeId, true,
                                           127, //scale
                                           -127, -127, -127, // offsets
                                           int(background.x * 255) ^ 0xc0,
                                           int(background.y * 255) ^ 0xc0,
                                           int(background.z * 255) ^ 0xc0);
    else
      OpenGLMethods::paintCubeToOpenGLList(
        image->width, image->height, 128,
        cubeId, true,
        127, //scale
        -image->width / 2, -image->height / 2, -65, // offsets
        int(background.x * 255) ^ 0xc0,
        int(background.y * 255) ^ 0xc0,
        int(background.z * 255) ^ 0xc0);

    OpenGLMethods::paintImagePixelsToOpenGLList(*image, colorModel, channel - 1, false, colorsId);
    lastTimeStamp = image->timeStamp;
  }
  else
  {
    glNewList(cubeId, GL_COMPILE_AND_EXECUTE);
    glEndList();
    glNewList(colorsId, GL_COMPILE_AND_EXECUTE);
    glEndList();
    lastTimeStamp = 0;
  }
}
  void paintEvent(QPaintEvent* event)
  {
    painter.begin(this);
    painter.setFont(font);
    painter.setBrush(altBrush);
    painter.setPen(fontPen);
    fillBackground = false;

    char formattedTime[65];

    paintRect = painter.window();
    int defaultLeft = textOffset;
    paintRectField0 = QRect(defaultLeft, 0, paintRect.right() - textOffset * 2, lineSpacing);
    {
      SYNC_WITH(cabslBehaviorView.console);
      const ActivationGraph& info(cabslBehaviorView.activationGraph);

      for(const ActivationGraph::Node activeOption : info.graph)
      {
        paintRectField0.setLeft(defaultLeft + 10 * activeOption.depth);

        sprintf(formattedTime, "%.02f", float(activeOption.optionTime) / 1000.f);
        print(activeOption.option.c_str(), formattedTime, true, true);

        if(!activeOption.parameters.empty())
        {
          paintRectField0.setLeft(defaultLeft + 10 * activeOption.depth + 5);
          for(const std::string& parameter : activeOption.parameters)
            print(parameter.c_str(), "", false, false);
        }

        paintRectField0.setLeft(defaultLeft + 10 * activeOption.depth + 5);
        sprintf(formattedTime, "%.02f", float(activeOption.stateTime) / 1000.f);
        print(("state = " + activeOption.state).c_str(), formattedTime, false, true);
        newBlock();
      }
    }
    painter.end();
    int minHeight = paintRectField0.top();
    if(minHeight > 0)
      setMinimumHeight(minHeight);
  }
示例#14
0
int SoundPlayer::play(const std::string& name)
{
  int queuelen;

  {
    SYNC_WITH(soundPlayer);
    soundPlayer.queue.push_back(name.c_str()); // avoid copy-on-write
    queuelen = static_cast<int>(soundPlayer.queue.size());
    if(!soundPlayer.started)
    {
      soundPlayer.started = true;
      soundPlayer.filePrefix = File::getBHDir();
      soundPlayer.filePrefix += "/Config/Sounds/";
      soundPlayer.start();
    }
    else
      soundPlayer.sem.post();
  }
  return queuelen;
}
示例#15
0
  void paintEvent(QPaintEvent *event)
  {  
    painter.begin(this);
    painter.setFont(font);
    painter.setBrush(altBrush);
    painter.setPen(fontPen);
    fillBackground = false;

    paintRect = painter.window();
    paintRectField0 = QRect(headerView->sectionViewportPosition(0) + textOffset, 0, headerView->sectionSize(0) - textOffset * 2, lineSpacing);
    paintRectField1 = QRect(headerView->sectionViewportPosition(1) + textOffset, 0, headerView->sectionSize(1) - textOffset * 2, lineSpacing);
    paintRectField2 = QRect(headerView->sectionViewportPosition(2) + textOffset, 0, headerView->sectionSize(2) - textOffset * 2, lineSpacing);
    paintRectField3 = QRect(headerView->sectionViewportPosition(3) + textOffset, 0, headerView->sectionSize(3) - textOffset * 2, lineSpacing);
    paintRectField4 = QRect(headerView->sectionViewportPosition(4) + textOffset, 0, headerView->sectionSize(4) - textOffset * 2, lineSpacing);
    paintRectField5 = QRect(headerView->sectionViewportPosition(5) + textOffset, 0, headerView->sectionSize(5) - textOffset * 2, lineSpacing);
    paintRectField6 = QRect(headerView->sectionViewportPosition(6) + textOffset, 0, headerView->sectionSize(6) - textOffset * 2, lineSpacing);
    {
      SYNC_WITH(console);
      
      for(TimeInfo::Infos::const_iterator i = info.infos.begin(), end = info.infos.end(); i != end; ++i)
      {
        double minTime = -1, maxTime = -1, avgTime = -1, minDelta = -1, maxDelta = -1, avgFreq = -1;
        char fminTime[100], fmaxTime[100], favgTime[100], fminDelta[100], fmaxDelta[100], favgFreq[100];
        if(info.getStatistics(i->second, minTime, maxTime, avgTime, minDelta, maxDelta, avgFreq))
        {
          sprintf(fminTime, "%.02f", minTime);
          sprintf(fmaxTime, "%.02f", maxTime);
          sprintf(favgTime, "%.02f", avgTime);
          sprintf(fminDelta, "%.02f", minDelta);
          sprintf(fmaxDelta, "%.02f", maxDelta);
          sprintf(favgFreq, "%.02f", avgFreq);
          print(i->first.c_str(), fminTime, fmaxTime, favgTime, fminDelta, fmaxDelta, favgFreq);
          newBlock();
        }
      }
    }
    painter.end();
    setMinimumHeight(paintRectField1.top());
  }
示例#16
0
void ImageWidget::paint(QPainter& painter)
{
  SYNC_WITH(imageView.console);

  const DebugImage* image = nullptr;
  RobotConsole::Images& currentImages = imageView.upperCam ? imageView.console.upperCamImages : imageView.console.lowerCamImages;
  RobotConsole::Images::const_iterator i = currentImages.find(imageView.background);

  if(i != currentImages.end())
  {
    image = i->second.image;
    imageWidth = image->getImageWidth();
    imageHeight = image->height;
  }
  else if(!currentImages.empty())
  {
    imageWidth = currentImages.begin()->second.image->getImageWidth();
    imageHeight = currentImages.begin()->second.image->height;
  }

  const QSize& size = painter.window().size();
  float xScale = float(size.width()) / float(imageWidth);
  float yScale = float(size.height()) / float(imageHeight);
  scale = xScale < yScale ? xScale : yScale;
  scale *= zoom;
  float imageXOffset = (float(size.width()) - float(imageWidth) * scale) * 0.5f + float(offset.x()) * scale;
  float imageYOffset = (float(size.height()) - float(imageHeight) * scale) * 0.5f + float(offset.y()) * scale;

  painter.setTransform(QTransform(scale, 0, 0, scale, imageXOffset, imageYOffset));

  if(image)
    paintImage(painter, *image);
  else
    lastImageTimeStamp = 0;

  paintDrawings(painter);
}
示例#17
0
void SensorWidget::paintEvent(QPaintEvent* event)
{
  painter.begin(this);
  painter.setFont(font);
  painter.setBrush(altBrush);
  painter.setPen(fontPen);
  fillBackground = false;

  paintRect = painter.window();
  paintRectField0 = QRect(headerView->sectionViewportPosition(0) + textOffset, 0, headerView->sectionSize(0) - textOffset * 2, lineSpacing);
  paintRectField1 = QRect(headerView->sectionViewportPosition(1) + textOffset, 0, headerView->sectionSize(1) - textOffset * 2, lineSpacing);
  {
    SYNC_WITH(sensorView.console);
    paintInertialSensorData();
    newSection();
    paintSystemSensorData();
    newSection();
    paintFsrSensorData();
    newSection();
    paintKeyStates();
  }
  painter.end();
  setMinimumHeight(paintRectField1.top());
}
示例#18
0
void DebugDrawing3D::draw()
{
  SYNC_WITH(*robotConsole);

  // Convert mm to m.
  glScaled(0.001, 0.001, 0.001);

  // Custom scaling.
  glScaled(scaleX, scaleY, scaleZ);

  // Custom rotation.
  if (rotateX != 0) glRotated(toDegrees(rotateX), 1, 0, 0);
  if (rotateY != 0) glRotated(toDegrees(rotateY), 0, 1, 0);
  if (rotateZ != 0) glRotated(toDegrees(rotateZ), 0, 0, 1);

  // Custom translation.
  glTranslated(transX, transY, transZ);

  GLboolean lighting;
  glGetBooleanv(GL_LIGHTING, &lighting);
  glDisable(GL_LIGHTING);

  // Draw all quads.
  std::vector<Quad>::iterator q;
  for(q = quads.begin(); q != quads.end(); ++q)
  {
    glColor4ub(q->color.r, q->color.g, q->color.b, q->color.a);
    glBegin(GL_QUADS);
    glVertex3d(q->points[0].x, q->points[0].y, q->points[0].z);
    glVertex3d(q->points[1].x, q->points[1].y, q->points[1].z);
    glVertex3d(q->points[2].x, q->points[2].y, q->points[2].z);      
    glVertex3d(q->points[3].x, q->points[3].y, q->points[3].z);      
    glEnd();
  }

  // Draw all polygons/triangles.
  std::vector<Polygon>::iterator p;
  for(p = polygons.begin(); p != polygons.end(); ++p)
  {
    glColor4ub(p->color.r, p->color.g, p->color.b, p->color.a);
    glBegin(GL_TRIANGLES);
    glVertex3d(p->points[0].x, p->points[0].y, p->points[0].z);
    glVertex3d(p->points[1].x, p->points[1].y, p->points[1].z);
    glVertex3d(p->points[2].x, p->points[2].y, p->points[2].z);      
    glEnd();
  }

  // Draw all lines.
  // Get line width so we can restore it later on
  float lw[1];
  glGetFloatv(GL_LINE_WIDTH, lw);

  std::vector<Line>::iterator l;
  for(l = lines.begin(); l != lines.end(); ++l)
  {
    glLineWidth(l->width);
    glColor4ub(l->color.r, l->color.g, l->color.b, l->color.a);
    glBegin(GL_LINES);
    glVertex3d(l->points[0].x, l->points[0].y, l->points[0].z);
    glVertex3d(l->points[1].x, l->points[1].y, l->points[1].z);
    glEnd();    
  }
  // Restore line width
  glLineWidth(lw[0]);

  // Draw all points.
  // Get point size so we can restore it later on
  float ps[1];
  glGetFloatv(GL_POINT_SIZE, ps);

  std::vector<Dot>::iterator d;
  for(d = dots.begin(); d != dots.end(); ++d)
  {
    // Since each point may have a different size we can't handle all
    // points in a single glBegin(GL_POINTS). 
    // ( glPointSize is not allowed in a glBegin(...). )
    glPointSize(d->width);
    glColor4ub(d->color.r, d->color.g, d->color.b, d->color.a);
    glBegin(GL_POINTS);
    glVertex3d(d->point.x,d->point.y,d->point.z);
    glEnd();
  }

  std::vector<Sphere>::iterator s;
  for(s = spheres.begin(); s != spheres.end(); ++s)
  {
    glColor4ub(s->color.r, s->color.g, s->color.b, s->color.a);
    glPushMatrix();
    glTranslated(s->point.x, s->point.y, s->point.z);
    GLUquadric* q = gluNewQuadric();
    gluSphere(q, s->radius, 16, 16);
    gluDeleteQuadric(q);
    glPopMatrix();
  }

  std::vector<Cylinder>::iterator c;
  for(c = cylinders.begin(); c != cylinders.end(); ++c)
  {
    glColor4ub(c->color.r, c->color.g, c->color.b, c->color.a);
    glPushMatrix();
    glTranslated(c->point.x, c->point.y, c->point.z);
    if(c->rotation.x != 0)
      glRotated(toDegrees(c->rotation.x), 1, 0, 0);
    if(c->rotation.y != 0)
      glRotated(toDegrees(c->rotation.y), 0, 1, 0);
    if(c->rotation.z != 0)
      glRotated(toDegrees(c->rotation.z), 0, 0, 1);
    glTranslated(0,0,-c->height / 2);
    GLUquadric* q = gluNewQuadric();
    gluCylinder(q, c->radius, c->radius, c->height, 16, 1);
    glRotated(180, 0, 1, 0);
    gluDisk(q, 0, c->radius, 16, 1);
    glRotated(180, 0, 1, 0);
    glTranslated(0, 0, c->height);
    gluDisk(q, 0, c->radius, 16, 1);
    gluDeleteQuadric(q);
    glPopMatrix();
  }

  GLboolean culling;
  glGetBooleanv(GL_CULL_FACE, &culling);
  glDisable(GL_CULL_FACE);
  glEnable(GL_TEXTURE_2D);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  std::vector<Image3D>::iterator i;
  for(i = images.begin(); i != images.end(); ++i)
  {
    GLuint t;
    glGenTextures(1, &t);
    glBindTexture(GL_TEXTURE_2D, t);

    int width, height;
    char* imageData = copyImage(*i->image, width, height);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 
      width, height,
      0, GL_RGB, GL_UNSIGNED_BYTE, imageData);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    delete [] imageData;

    glPushMatrix();
    glTranslated(i->point.x, i->point.y, i->point.z);
    if(i->rotation.x != 0)
      glRotated(toDegrees(i->rotation.x), 1, 0, 0);
    if(i->rotation.y != 0)
      glRotated(toDegrees(i->rotation.y), 0, 1, 0);
    if(i->rotation.z != 0)
      glRotated(toDegrees(i->rotation.z), 0, 0, 1);
    glBegin(GL_QUADS);
    double right = (double) i->image->cameraInfo.resolutionWidth / width;
    double top = (double) i->image->cameraInfo.resolutionHeight / height;
    glTexCoord2d(right, top); glVertex3d(0, -i->width / 2, i->height / 2);
    glTexCoord2d(0, top); glVertex3d(0, i->width / 2, i->height / 2);
    glTexCoord2d(0, 0); glVertex3d(0, i->width / 2, -i->height / 2);
    glTexCoord2d(right, 0); glVertex3d(0, -i->width / 2, -i->height / 2);
    glEnd();
    glPopMatrix();
    glDeleteTextures(1, &t);
  }
  glDisable(GL_TEXTURE_2D);

  // Restore point size
  glPointSize(ps[0]);  
  if(lighting)
    glEnable(GL_LIGHTING);
  if(culling)
    glEnable(GL_CULL_FACE);
}
示例#19
0
bool ModuleGraphViewObject::hasChanged()
{
  SYNC_WITH(console);
  return lastModulInfoTimeStamp != console.moduleInfo.timeStamp;
}
示例#20
0
void TimeWidget::update()
{
  SYNC_WITH(timeView.console);
  {
    if(Time::getTimeSince(lastUpdate) < 200) //only update 5 times per second
      return;
    lastUpdate = Time::getCurrentSystemTime();

    // if timing info is lost for more than 1s, clear timing table
    if(timeView.console.logFile == "" && lastUpdate > lastTimeInfoTimeStamp + 1000 && table->rowCount() > 0)
    {
      table->setRowCount(0);
      items.clear();
      table->update();
      return;
    }

    if(timeView.info.timeStamp == lastTimeInfoTimeStamp)
      return;
    lastTimeInfoTimeStamp = timeView.info.timeStamp;

    float avgFrequency = -1.0;
    float minDuration = -1.0;
    float maxDuration = -1.0;
    timeView.info.getProcessStatistics(avgFrequency, minDuration, maxDuration);
    frequency->setText(" Freq: " + QString::number(avgFrequency, 'f', 1)
                       + ", Min: " + QString::number(minDuration, 'f', 1) +
                       "ms, Max: " + QString::number(maxDuration, 'f', 1) + "ms");

    table->setUpdatesEnabled(false);
    table->setSortingEnabled(false);//disable sorting while updating to avoid race conditions
    for(const auto& infoPair : timeView.info.infos)
    {
      std::string name = timeView.info.getName(infoPair.first);
      Row* currentRow = nullptr;
      if(items.find(infoPair.first) != items.end())
      {
        //already know this one
        currentRow = items[infoPair.first];
      }
      else
      {
        //new item
        currentRow = new Row;
        currentRow->avg = new NumberTableWidgetItem();
        currentRow->max = new NumberTableWidgetItem();
        currentRow->min = new NumberTableWidgetItem();
        currentRow->name = new QTableWidgetItem();
        const int rowCount = table->rowCount();
        table->setRowCount(rowCount + 1);
        table->setItem(rowCount, 0, currentRow->name);
        table->setItem(rowCount, 1, currentRow->min);
        table->setItem(rowCount, 2, currentRow->max);
        table->setItem(rowCount, 3, currentRow->avg);
        items[infoPair.first] = currentRow;
      }
      float minTime = -1, maxTime = -1, avgTime = -1;
      timeView.info.getStatistics(infoPair.second, minTime, maxTime, avgTime);
      // this row timed out, remove it from the list
      if(infoPair.second.timeStamp + 1000 < lastUpdate)
        maxTime = 0;
      currentRow->avg->setText(QString::number(avgTime));
      currentRow->min->setText(QString::number(minTime));
      currentRow->max->setText(QString::number(maxTime));
      currentRow->name->setText(QString(name.c_str())); //refresh name every time to eliminate unknown
    }
  }
  applyFilter();
  table->setSortingEnabled(true);
  table->setUpdatesEnabled(true);
  table->update();
}
示例#21
0
  void paintEvent(QPaintEvent *event)
  {  
    static const ViewInfo viewInfoNao[] =  {
      {SensorData::gyroX,    angularSpeed, false},
      {SensorData::gyroY,    angularSpeed, true},

      {SensorData::accX,    acceleration, false},
      {SensorData::accY,    acceleration, false},
      {SensorData::accZ,    acceleration, true},

      {SensorData::batteryLevel, ratio, true},

      {SensorData::fsrLFL,  pressure, false},
      {SensorData::fsrLFR,  pressure, false},
      {SensorData::fsrLBL,  pressure, false},
      {SensorData::fsrLBR,  pressure, false},
      {SensorData::fsrRFL,  pressure, false},
      {SensorData::fsrRFR,  pressure, false},
      {SensorData::fsrRBL,  pressure, false},
      {SensorData::fsrRBR,  pressure, true},

      {SensorData::us,  usLDistance,   false},
      {SensorData::us,  usLtRDistance, false},
      {SensorData::us,  usRtLDistance, false},
      {SensorData::us,  usRDistance,   true},

      {SensorData::angleX,  angle2, false},
      {SensorData::angleY,  angle2, false},
      {SensorData::numOfSensors, end, true}
    };

    painter.begin(this);
    painter.setFont(font);
    painter.setBrush(altBrush);
    painter.setPen(fontPen);
    fillBackground = false;

    paintRect = painter.window();
    paintRectField0 = QRect(headerView->sectionViewportPosition(0) + textOffset, 0, headerView->sectionSize(0) - textOffset * 2, lineSpacing);
    paintRectField1 = QRect(headerView->sectionViewportPosition(1) + textOffset, 0, headerView->sectionSize(1) - textOffset * 2, lineSpacing);
    paintRectField2 = QRect(headerView->sectionViewportPosition(2) + textOffset, 0, headerView->sectionSize(2) - textOffset * 2, lineSpacing);
    {
      char value[32];
      char filtered[32];
      SYNC_WITH(console);
      const SensorData& sensorData(sensorView.sensorData);
      const SensorData& filteredSensorData(sensorView.filteredSensorData);

      if(sensorData.data[SensorData::us] != SensorData::off)
        usDistances[0][sensorData.usSensorType] = sensorData.data[SensorData::us];
      if(filteredSensorData.data[SensorData::us] != SensorData::off)
        usDistances[1][sensorData.usSensorType] = filteredSensorData.data[SensorData::us];

      for(int i = 0;; ++i)
      {
        const ViewInfo &vi = viewInfoNao[i];
        if(vi.type == SensorWidget::end)
          break;
        
        formatSensor(vi.type, sensorData.data[vi.sensor], false, value);
        formatSensor(vi.type, filteredSensorData.data[vi.sensor], true, filtered);

        print(getSensorName(vi), value, filtered);
        newBlock();
        if(vi.endOfSection)
          newSection();
      }
    }
    painter.end();
    setMinimumHeight(paintRectField1.top());
  }