Пример #1
0
void Checker::prepareForDisplay (const QPolygonF &polygon,
                                 int pointRadius,
                                 const DocumentModelAxesChecker &modelAxesChecker,
                                 const DocumentModelCoords &modelCoords)
{
  LOG4CPP_INFO_S ((*mainCat)) << "Checker::prepareForDisplay";

  ENGAUGE_ASSERT (polygon.count () == NUM_AXES_POINTS);

  // Convert pixel coordinates in QPointF to screen and graph coordinates in Point using
  // identity transformation, so this routine can reuse computations provided by Transformation
  QList<Point> points;
  QPolygonF::const_iterator itr;
  for (itr = polygon.begin (); itr != polygon.end (); itr++) {

    const QPointF &pF = *itr;

    Point p (DUMMY_CURVENAME,
             pF,
             pF);
    points.push_back (p);
  }

  // Screen and graph coordinates are treated as the same, so identity transform is used
  Transformation transformIdentity;
  transformIdentity.identity();
  prepareForDisplay (points,
                     pointRadius,
                     modelAxesChecker,
                     modelCoords,
                     transformIdentity);
}
Пример #2
0
/**
* Renders the spreadsheet to stdout
* @param spreadsheet Represents the spreadsheet
*/
void renderSpreadSheet(Cell spreadsheet[], FILE* file, int socket) {
   size_t i;
   char cell1[DISPLAY], cell2[DISPLAY], cell3[DISPLAY], cell4[DISPLAY], cell5[DISPLAY], cell6[DISPLAY], cell7[DISPLAY], cell8[DISPLAY], cell9[DISPLAY];
   char trun1[TRUNCATE], trun2[TRUNCATE], trun3[TRUNCATE], trun4[TRUNCATE], trun5[TRUNCATE], trun6[TRUNCATE], trun7[TRUNCATE], trun8[TRUNCATE], trun9[TRUNCATE];
   char buffer[BUFFER_SIZE];
   bool writeToSocket;
   FILE* fd = NULL;
   FILE* out = NULL;

   writeToSocket = socket != -1? true : false;
   if (writeToSocket)
   {
      fd = fdopen(socket, "w");
      // printf("fd\n");

      // change to full buffering instead of line buffering
      // to hold entire spreadsheet.
      if (setvbuf(fd, buffer, _IOFBF, BUFFER_SIZE) != 0)
         die("Couldn't create buffer for spreadsheet");
   }
   printf("Created buffer\n");

   for (i = 0; i < GRID;) {
      strcpy(cell1, prepareForDisplay(spreadsheet[i].value));
      strcpy(cell2, prepareForDisplay(spreadsheet[i + 1].value));
      strcpy(cell3, prepareForDisplay(spreadsheet[i + 2].value));
      strcpy(cell4, prepareForDisplay(spreadsheet[i + 3].value));
      strcpy(cell5, prepareForDisplay(spreadsheet[i + 4].value));
      strcpy(cell6, prepareForDisplay(spreadsheet[i + 5].value));
      strcpy(cell7, prepareForDisplay(spreadsheet[i + 6].value));
      strcpy(cell8, prepareForDisplay(spreadsheet[i + 7].value));
      strcpy(cell9, prepareForDisplay(spreadsheet[i + 8].value));
      strcpy(trun1, truncateOrNah(spreadsheet[i].value));
      strcpy(trun2, truncateOrNah(spreadsheet[i + 1].value));
      strcpy(trun3, truncateOrNah(spreadsheet[i + 2].value));
      strcpy(trun4, truncateOrNah(spreadsheet[i + 3].value));
      strcpy(trun5, truncateOrNah(spreadsheet[i + 4].value));
      strcpy(trun6, truncateOrNah(spreadsheet[i + 5].value));
      strcpy(trun7, truncateOrNah(spreadsheet[i + 6].value));
      strcpy(trun8, truncateOrNah(spreadsheet[i + 7].value));
      strcpy(trun9, truncateOrNah(spreadsheet[i + 8].value));
      // Renders the spreadsheet row by row
      out = writeToSocket? fd : file;
      fprintf(out, "+--------------+ +--------------+ +--------------+ +--------------+ +--------------+ +--------------+ +--------------+ +--------------+ +--------------+"
                      "\n|              | |              | |              | |              | |              | |              | |              | |              | |              |"
                      "\n|              | |              | |              | |              | |              | |              | |              | |              | |              |"
                      "\n|      %.*s    | |      %s    | |      %s    | |      %s    | |      %s    | |      %s    | |      %s    | |      %s    | |      %s    |"
                      "\n|  %s | |  %s | |  %s | |  %s | |  %s | |  %s | |  %s | |  %s | |  %s |"
                      "\n|              | |              | |              | |              | |              | |              | |              | |              | |              |"
                      "\n+------%s------+ +------%s------+ +------%s------+ +------%s------+ +------%s------+ +------%s------+ +------%s------+ +------%s------+ +------%s------+",
              4, cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, trun1, trun2, trun3,
              trun4, trun5, trun6, trun7, trun8, trun9, spreadsheet[i].address, spreadsheet[i + 1].address,
              spreadsheet[i + 2].address, spreadsheet[i + 3].address, spreadsheet[i + 4].address,
              spreadsheet[i + 5].address, spreadsheet[i + 6].address,
              spreadsheet[i + 7].address, spreadsheet[i + 8].address);
      fprintf(out, "\n");
      i += 9;
   }
   // Send buffer contents(spreadsheet) to client.
   if (fd) {
      fflush(fd);
      if (setvbuf(fd, buffer, _IOLBF, IN_BUF_LIMIT) != 0)
         die("Couldn't change buffer to line buffering");
   }
}