Exemple #1
0
static void render(int type, SKMATRIX *mat, mapView_t *mapView, CSkPainter *pPainter, bool eqOnly, int x, int y, int spcx, int spcy)
{
  if (x < 0)
  {
    x += 129600000;
  }
  else
  if (x >= 129600000)
  {
    x -= 129600000;
  }

  if (y < 0 || y > 64800000)
  {
    return;
  }

  radec_t rd[4];

  if (mSet.contains(MAKE_INT64(x, y)))
  { // already rendered
    return;
  }

  QColor col = g_skSet.map.grid[type].color;
  QPen pen1 = QPen(col, 1);
  QPen pen3 = QPen(col, 3);

  rd[0].Ra = TORA(x);
  rd[0].Dec = TODEC(y);

  rd[1].Ra = TORA(x + spcx);
  rd[1].Dec = TODEC(y);

  rd[2].Ra = rd[1].Ra;
  rd[2].Dec = TODEC(y + spcy);

  rd[3].Ra = TORA(x);
  rd[3].Dec = rd[2].Dec;

  double dec = rd[0].Dec;
  double ra = rd[0].Ra;

  if (type == SMCT_ALT_AZM)
  {
    for (int i = 0; i < 4; i++)
    {
      rd[i].Dec -= cAstro.getInvAtmRef(rd[i].Dec);
    }
  }

  if (y + spcy > 64800000 && depth > 0)
  {
    return;
  }

  if (y + spcy < 00 && depth > 0)
  {
    return;
  }

  SKPOINT pt[4];
  SKPOINT opt[4];

  for (int i = 0; i < 4; i++)
  {
    trfRaDecToPointNoCorrect(&rd[i], &pt[i], mat);
    opt[i] = pt[i];
  }

  if (!SKPLANECheckFrustumToPolygon(trfGetFrustum(), pt, 4))
  { // out of screen
    return;
  }

  pPainter->setPen(pen1);
  ren++;

  if (!eqOnly && trfProjectLine(&pt[0], &pt[3]))
  {
    if ((y + spcy < 64800000 && y > 0) || (x == 0 || x == FROMRA(90) || x == FROMRA(180) || x == FROMRA(270)))
    {
      pPainter->setClipRect(clipSize, clipSize, scrWidth - clipSize * 2, scrHeight - clipSize * 2);
      pPainter->drawLine(pt[0].sx, pt[0].sy, pt[3].sx, pt[3].sy);
      pPainter->setClipping(false);

      int cx, cy;

      if (getClipPoint(cx, cy, pt[0].sx, pt[0].sy, pt[3].sx, pt[3].sy))
      {
        QString text;

        if (g_skSet.map.showGridLabels && g_showLabels)
        {
          if (type == SMCT_RA_DEC)
          {
            text = getStrRA(ra, true);
          }
          else
          if (type == SMCT_ECL)
          {
            text = getStrDeg(ra, true);
          }
          else
          {
            double value = R360 - ra;
            rangeDbl(&value, R360);
            text = getStrDeg(value, true);
          }
          drawEdgeAlignTextY(pPainter, cx, cy, text);
        }
      }
    }
  }
  else
  {
    QPointF fpt[2];
    if (eqOnly && y == 32400000 && trfProjectLine(&pt[0], &pt[3], fpt))
    {
      QString text;

      if (g_skSet.map.showGridLabels && g_showLabels)
      {
        if (type == SMCT_RA_DEC)
        {
          text = getStrRA(ra, true);
        }
        else
        if (type == SMCT_ECL)
        {
          text = getStrDeg(ra, true);
        }
        else
        {
          double value = R360 - ra;
          rangeDbl(&value, R360);
          text = getStrDeg(value, true);
        }

        SKVECTOR v;
        double l = 10;

        QPointF fpt2[2];
        trfProjectLine(&pt[0], &pt[1], fpt2);

        v.x = fpt2[0].x() - fpt2[1].x();
        v.y = fpt2[0].y() - fpt2[1].y();
        v.z = 0;

        SKVecNormalize(&v, &v);

        pPainter->setClipRect(clipSize, clipSize, scrWidth - clipSize * 2, scrHeight - clipSize * 2);

        pPainter->setPen(pen1);
        pPainter->drawLine(fpt[0].x(), fpt[0].y(), fpt[0].x() - v.y * l, fpt[0].y() + v.x * l);
        pPainter->drawLine(fpt[0].x(), fpt[0].y(), fpt[0].x() + v.y * l, fpt[0].y() - v.x * l);

        setSetFontColor(FONT_GRID, pPainter);
        pPainter->renderText(fpt[0].x(), fpt[0].y(), 10, text, RT_BOTTOM);

        pPainter->setClipping(false);
      }
    }
  }

  if ((eqOnly && y == 32400000) || !eqOnly)
  {
    int cx, cy;

    if (y == 32400000)
    {
      pPainter->setPen(pen3);
    }
    else
    {
      pPainter->setPen(pen1);
    }

    pPainter->setClipRect(clipSize, clipSize, scrWidth - clipSize * 2, scrHeight - clipSize * 2);
    if (drawInterpolatedLineRD(mat, 5, &rd[0], &rd[1], pPainter, cx, cy))
    {
      pPainter->setClipping(false);
      if (g_skSet.map.showGridLabels && g_showLabels)
      {
        drawEdgeAlignTextX(pPainter, cx, cy, QString("%1").arg(getStrDeg(dec, true)));
      }
    }
    pPainter->setClipping(false);
  }

  mSet.insert(MAKE_INT64(x, y));

  depth++;

  render(type, mat, mapView, pPainter, eqOnly, x - spcx, y, spcx, spcy);
  render(type, mat, mapView, pPainter, eqOnly, x + spcx, y, spcx, spcy);
  render(type, mat, mapView, pPainter, eqOnly, x, y + spcy, spcx, spcy);
  render(type, mat, mapView, pPainter, eqOnly, x, y - spcy, spcx, spcy);
}
Exemple #2
0
static int dateCommand(int argc, char **argv)
{
  if (argc <= 0) {
    printf("show/set the system clock.\n");
    if (argc < 0) {
      printf("%sThe argument used to set the time, if given,\n", *argv);
      printf("%sis in the form [MMDDhhmm[[CC]YY][.ss]].\n", *argv);
    }
    return COMMAND_OK;
  }

  if (argc > 1) {
    // Set the time.
    struct tm tm;
    time_t t = time(NULL);
    localtime_r(&t, &tm);

    char *p = argv[1];          // Point to the date string.

    // Find seconds.
    char *s = strchr(p, '.');
    if (s) {
      // Seconds here. Terminate p and point to them.
      *s++ = '\0';
    }

    int left = strlen(p);       // Number of characters in non-second string.

#define TODEC(v) if (*(p)) { v = 0; v += *p - '0'; ++p; --left; } \
             if (*(p)) { v *= 10; v += *p - '0'; ++p; --left; }

    TODEC(tm.tm_mon)
    if (tm.tm_mon < 1 || tm.tm_mon > 12) {
      printf("invalid month: %d\n", tm.tm_mon);
      return COMMAND_ERROR;
    }
    --tm.tm_mon;    // In the range of 0 .. 11.

    TODEC(tm.tm_mday)
    if (tm.tm_mday < 1 || tm.tm_mday > 31) {
      printf("invalid day of month: %d\n", tm.tm_mday);
      return COMMAND_ERROR;
    }

    TODEC(tm.tm_hour)
    if (tm.tm_hour < 0 || tm.tm_hour > 23) {
      printf("invalid hour: %d\n", tm.tm_hour);
      return COMMAND_ERROR;
    }

    TODEC(tm.tm_min)
    if (tm.tm_min < 0 || tm.tm_min > 59) {
      printf("invalid minute: %d\n", tm.tm_min);
      return COMMAND_ERROR;
    }

    if (left >= 2) {
      int year = 0;
      if (left >= 4) {
        // Have a four digit year.
        TODEC(year)
        year = year * 100;
      } else {
        year = 1900;
      }

      int tens = 0;
      TODEC(tens)
      year += tens;
      if (year < 1900) {
        printf("invalid year: %d\n", year);
        return COMMAND_ERROR;
      }

      tm.tm_year = year - 1900;
    }

    if (s) {
      // Have seconds.
      p = s;
      TODEC(tm.tm_sec);
      if (tm.tm_sec < 0 || tm.tm_sec > 59) {
        printf("invalid seconds: %d\n", tm.tm_sec);
        return COMMAND_ERROR;
      }
    }

    time_t sec = mktime(&tm);
    if (sec == (time_t)-1) {
      printf("mktime failed %s\n", asctime(&tm));
      return COMMAND_ERROR;
    }
    struct timeval tv = { sec, 0 };
    return settimeofday(&tv, NULL) == 0 ? COMMAND_OK : COMMAND_ERROR;
  }

  time_t t = time(NULL);
  char date[26];
  fputs(ctime_r(&t, date), stdout);
  return COMMAND_OK;
}