コード例 #1
0
void PressureCorrectedTemperature<EvalT,Traits, TempST, SurfHeightST,
                                  typename std::enable_if<
                                             std::is_convertible<SurfHeightST, TempST>::value &&
                                             std::is_convertible<typename EvalT::MeshScalarT,TempST>::value,
                                             typename EvalT::MeshScalarT
                                           >::type>::
evaluateFields(typename Traits::EvalData d)
{
  if (memoizer.have_stored_data(d)) return;

  for (std::size_t cell = 0; cell < d.numCells; ++cell)
    correctedTemp(cell) = std::min(temp(cell) +coeff * (sHeight(cell) - coord(cell,2)), 273.15);
}
コード例 #2
0
ファイル: patternPrinter.cpp プロジェクト: zjucsxxd/Cstitch
void patternPrinter::drawColorList(int startHeight) {

  painter_.save();
  int yused = startHeight;
  // have the list font match the symbol size, within reason
  // TODO: limit so that overflow isn't possible
  int symbolDim = qMax(pdfSymbolDim_, sHeight("B"));
  symbolDim = qMin(symbolDim, 35);
  ::setFontHeight(&painter_, symbolDim);
  const QFont listFont = painter_.font();

  const QFontMetrics listFontMetric(listFont);
  const int fontHeight = listFontMetric.height();

  //// list color count and box dimensions
  QRect textBoundingRect;
  painter_.drawText(QRect(0, yused + fontHeight, printerWidth_,
                          4 * fontHeight),
                    Qt::TextWordWrap,
                    QObject::tr("The pattern uses %1 colors and is %2 "
                                "squares wide by %3 squares high.")
                    .arg(::itoqs(colors_.size()))
                    .arg(::itoqs(xBoxes_))
                    .arg(::itoqs(yBoxes_)),
                    &textBoundingRect);
                    
  yused += textBoundingRect.height() + fontHeight;
  
  const bool useCodeAbbreviations = printListDescription(&yused, fontHeight);
  // save this height so it can be restored for a second column
  const int yusedSaved = yused;

  //// now draw the color list
  QFont boldFont = listFont;
  boldFont.setBold(true);
  painter_.setFont(boldFont);
  const QFontMetrics boldFontMetric(boldFont);

  //// tab stops
  const int padding = 10;
  const int swatchTab = symbolDim + 5;
  const int countTab = 2 * swatchTab + padding;
  const int codeTab = countTab + listFontMetric.width("99999999") + padding;
  const int nameTab = codeTab + listFontMetric.width("255 255 255") + padding;
  const int endTab = nameTab + boldFontMetric.width("~8888:Ultra V DK Turquoise");

  yused += fontHeight;
  drawListHeader(0, yused, countTab, codeTab, nameTab);
  painter_.drawLine(0, yused + 3, endTab, yused + 3);
  yused += 5;
  painter_.setFont(listFont);

  int xtab = 0;
  bool partial = true; // the first page list may be a partial page
  QVector<typedFloss> flossVector = ::rgbToFloss(colors_);
  std::sort(flossVector.begin(), flossVector.end(), flossIntensity());

  // build a color count map
  QHash<QRgb, int> countsHash;
  ::colorCounts(squareImage_, squareDim_, &countsHash);

  QPixmap thisSymbol;
  QPainter symbolPainter;
  QPixmap thisPixmap(symbolDim, symbolDim);
  QString thisCodeString;
  for (int i = 0, size = flossVector.size(); i < size; ++i) {
    const typedFloss thisFloss = flossVector[i];
    if (yused + fontHeight > printerHeight_) { // out of room in this column
      // if we're currently in a second column or there isn't room for a
      // second column, then start a new page
      if (xtab > 0 || endTab + 50 + endTab > printerWidth_) {
        xtab = 0;
        printer_.newPage();
        partial = false;
        yused = 0;
        painter_.setFont(boldFont);
        drawListHeader(xtab, fontHeight, countTab, codeTab, nameTab);
        painter_.setFont(listFont);
        yused += fontHeight;
        painter_.drawLine(xtab, yused + 3, endTab, yused + 3);
        yused += 5;
      }
      else { // start a second column
        xtab = endTab + 50;
        painter_.setFont(boldFont);
        if (partial) { // second column on first page of listing
          yused = yusedSaved;
          drawListHeader(xtab, fontHeight + yused, countTab,
                         codeTab, nameTab);
          yused += fontHeight;
        }
        else {
          yused = 0;
          drawListHeader(xtab, fontHeight, countTab, codeTab, nameTab);
          yused += fontHeight;
        }
        painter_.setFont(listFont);
        painter_.drawLine(xtab, yused + 3, endTab + xtab, yused + 3);
        yused += 5;
      }
    }
    //// symbol
    thisSymbol = imageContainer_->symbolNoBorder(thisFloss.color(),
                                                 symbolDim);
    symbolPainter.begin(&thisSymbol);
    symbolPainter.drawRect(0, 0, thisSymbol.width() - 1, 
                           thisSymbol.height() - 1);
    symbolPainter.end();
    painter_.drawPixmap(xtab, yused + 5, thisSymbol);
    //// color swatch ("sample")
    thisPixmap.fill(thisFloss.color().qc());
    painter_.drawPixmap(swatchTab + xtab + 2, yused + 5, thisPixmap);
    painter_.drawRect(swatchTab + xtab + 2, yused + 5,
                      symbolDim, symbolDim);
    //// color count
    painter_.drawText(countTab + xtab, yused + symbolDim,
                      ::itoqs(countsHash[thisFloss.color().qrgb()]));
    //// floss code (or rgb code)
    painter_.drawText(codeTab + xtab, yused + symbolDim,
                      flossToCode(thisFloss, useCodeAbbreviations));
    //// color name
    painter_.drawText(nameTab + xtab, yused + symbolDim, thisFloss.name());

    yused += symbolDim + 5;
  }
  printer_.newPage();
  painter_.restore();
}
コード例 #3
0
ファイル: patternPrinter.cpp プロジェクト: zjucsxxd/Cstitch
bool patternPrinter::drawPatternPages() {

  if (!portrait_) { // draw landscape
    int temp = printerWidth_;
    printerWidth_ = printerHeight_;
    printerHeight_ = temp;
    // you can't change the orientation under Windows, so we'll just
    // draw sideways instead
    painter_.rotate(-90);
    painter_.translate(-printerWidth_, 0);
  }

  painter_.setPen(QPen(Qt::black, 1));
  // image width to use on a particular page (last page may be smaller)
  int widthToUse = widthPerPage_;
  int heightToUse = heightPerPage_;
  const int f = 5; // fudge room for grid number separation from the grid
  const QHash<QRgb, QPixmap> symbolMap =
    imageContainer_->symbolsNoBorder(pdfSymbolDim_);
  QProgressDialog progressMeter(QObject::tr("Creating pdf..."),
                                QObject::tr("Cancel"), 0,
                                (xPages_ * yPages_)/5);
  progressMeter.setMinimumDuration(4000);
  progressMeter.setWindowModality(Qt::WindowModal);
  progressMeter.move(PROGRESS_X_COORDINATE, PROGRESS_Y_COORDINATE);
  progressMeter.show();
  for (int x = 1; x <= xPages_; ++x) {
    for (int y = 1; y <= yPages_; ++y) {
      if (progressMeter.wasCanceled()) {
        return true;
      }
      const int pageNum = yPages_ * (x-1) + y;
      // draw the page number
      painter_.drawText(printerWidth_ - sWidth(pageNum), sHeight(pageNum) - 5,
                        ::itoqs(pageNum));
      if (pageNum % 5 == 0) {
        progressMeter.setValue(pageNum / 5);
      }
      widthToUse = widthPerPage_;
      if (x * widthPerPage_ > patternImageWidth_) {
        widthToUse = patternImageWidth_ - (x-1) * widthPerPage_;
      }
      heightToUse = heightPerPage_;
      if (y * heightPerPage_ > patternImageHeight_) {
        heightToUse = patternImageHeight_ - (y-1) * heightPerPage_;
      }

      // draw this page's image
      const int patternXBoxStart = ((x-1) * widthPerPage_)/pdfSymbolDim_;
      const int patternXBoxEnd = patternXBoxStart + (widthToUse/pdfSymbolDim_);
      const int patternYBoxStart = ((y-1) * heightPerPage_)/pdfSymbolDim_;
      const int patternYBoxEnd = patternYBoxStart + (heightToUse/pdfSymbolDim_);
      for (int j = patternYBoxStart, jj = 0; j < patternYBoxEnd;
            ++j, ++jj) {
        for (int i = patternXBoxStart, ii = 0; i < patternXBoxEnd;
              ++i, ++ii) {
          const QPixmap& thisSymbol =
            symbolMap[squareImage_.pixel(i * squareDim_, j * squareDim_)];
          painter_.drawPixmap(margin_ + ii * pdfSymbolDim_,
                              margin_ + jj * pdfSymbolDim_, thisSymbol);
        }
      }

      //// draw grid lines and counts (thick every 5, thin every 1)
      const int thickCount = 5;
      //// x grid lines
      painter_.setPen(QPen(Qt::black, 1));
      int tx = 0;
      //// draw the thin x grid lines
      while (tx * pdfSymbolDim_ <= widthToUse) {
        painter_.drawLine(tx * pdfSymbolDim_ + margin_, margin_,
                          tx * pdfSymbolDim_ + margin_, heightToUse + margin_);
        ++tx;
      }
      bool lastXLine = false;
      if ((x-1) * widthPerPage_ + tx * pdfSymbolDim_ > patternImageWidth_) {
        lastXLine = true; // the last x line is drawn on this page
      }
      //// draw the thin y grid lines
      int ty = 0;
      while (ty * pdfSymbolDim_ <= heightToUse) {
        painter_.drawLine(margin_, ty * pdfSymbolDim_ + margin_,
                          widthToUse + margin_, ty * pdfSymbolDim_ + margin_);
        ++ty;
      }
      bool lastYLine = false;
      if ((y-1) * heightPerPage_ + ty * pdfSymbolDim_ >
          patternImageHeight_) {
        lastYLine = true; // the last y line is drawn on this page
      }

      //// thick lines
      tx = 0; // x grid count for this page
      if ((x-1) * xBoxesPerPage_ % thickCount != 0) {
        // to the next multiple of thickCount
        tx = thickCount - ((x-1) * xBoxesPerPage_ % thickCount);
      }

      const int savedTx = tx;
      // draw the x grid counts
      painter_.setPen(QPen(Qt::black, 1));
      while (tx * pdfSymbolDim_ <= widthToUse) {
        const int tgridx = (x-1) * xBoxesPerPage_ + tx;
        if (tx == 0) { // avoid collision
          painter_.drawText(margin_ + tx * pdfSymbolDim_, margin_ - f,
                            ::itoqs(tgridx));
        }
        else {
          painter_.drawText(margin_ + tx * pdfSymbolDim_ - sWidth(tgridx),
                            margin_ - f, ::itoqs(tgridx));
        }
        tx += thickCount;
      }

      // draw the thick x grid lines
      tx = savedTx;
      painter_.setPen(QPen(Qt::black, 3));
      while (tx * pdfSymbolDim_ <= widthToUse) {
        painter_.drawLine(tx * pdfSymbolDim_ + margin_, margin_,
                          tx * pdfSymbolDim_ + margin_, heightToUse + margin_);
        tx += thickCount;
      }
      tx -= thickCount;

      // draw the final line
      if (lastXLine) {
        painter_.setPen(QPen(Qt::black, 1));
        painter_.drawText(margin_ + widthToUse - sWidth(xBoxes_), margin_ - f,
                          ::itoqs(xBoxes_));
        painter_.setPen(QPen(Qt::black, 3));
        painter_.drawLine(widthToUse + margin_, margin_, widthToUse + margin_,
                          heightToUse + margin_);
      }

      ty = 0; // y grid count for this page
      if ((y-1) * yBoxesPerPage_ % thickCount != 0) {
        // to the next multiple of 5
        ty = thickCount - ((y-1) * yBoxesPerPage_ % thickCount);
      }

      const int savedTy = ty;
      // draw the y grid counts
      painter_.setPen(QPen(Qt::black, 1));
      while (ty * pdfSymbolDim_ <= heightToUse) {
        const int tgridy = (y-1) * yBoxesPerPage_ + ty;
        if (ty == 0) { // avoid confusion
          painter_.drawText(margin_ - sWidth(tgridy) - f,
                            ty * pdfSymbolDim_ + margin_ + sHeight(tgridy),
                            ::itoqs(tgridy));
        }
        else {
          painter_.drawText(margin_ - sWidth(tgridy) - f,
                            ty * pdfSymbolDim_ + margin_,
                            ::itoqs(tgridy));
        }
        ty += thickCount;
      }

      // draw the thick y grid lines
      ty = savedTy;
      painter_.setPen(QPen(Qt::black, 3));
      while (ty * pdfSymbolDim_ <= heightToUse) {
        painter_.drawLine(margin_, ty * pdfSymbolDim_ + margin_,
                          widthToUse + margin_, ty * pdfSymbolDim_ + margin_);
        ty += thickCount;
      }

      // draw the final line
      if (lastYLine) {
        painter_.setPen(QPen(Qt::black, 1));
        painter_.drawText(margin_ - sWidth(yBoxes_) - f, heightToUse + margin_,
                          ::itoqs(yBoxes_));
        painter_.setPen(QPen(Qt::black, 3));
        painter_.drawLine(margin_, heightToUse + margin_, widthToUse + margin_,
                          heightToUse + margin_);
      }

      painter_.setPen(QPen(Qt::black, 1)); // reset

      if (x < xPages_ || y < yPages_) {
        printer_.newPage();
      }
    }
  }
  return false;
}
コード例 #4
0
ファイル: patternPrinter.cpp プロジェクト: zjucsxxd/Cstitch
int patternPrinter::drawLegend() {

  // max page number width
  const int maxPageNumWidth =
    sWidth(QString(::itoqs(xPages_ * yPages_).size(), '5')) + 10;
  const int maxPageNumHeight = sHeight("5");

  const qreal minLegendWidth = xPages_ * maxPageNumWidth;
  const qreal minLegendHeight = yPages_ * maxPageNumHeight;
  qreal ratio; // legend to original
  qreal legendWidth, legendHeight;
  if (patternImageWidth_ > patternImageHeight_) {
    legendWidth = (printerWidth_/4 > minLegendWidth) ?
      printerWidth_/4 : minLegendWidth;
    ratio = legendWidth/patternImageWidth_;
    legendHeight = ratio * patternImageHeight_;
  }
  else {
    legendHeight = (printerHeight_/5 > minLegendHeight) ?
      printerHeight_/5 : minLegendHeight;
    ratio = legendHeight/patternImageHeight_;
    legendWidth = ratio * patternImageWidth_;
  }
  const int pageWidth = (widthPerPage_ > patternImageWidth_) ?
    patternImageWidth_ : widthPerPage_;
  const int pageHeight = (heightPerPage_ > patternImageHeight_) ?
    patternImageHeight_ : heightPerPage_;
  // width of each "page" on the legend
  qreal legendBoxWidth = pageWidth * ratio;
  if (legendBoxWidth < maxPageNumWidth) {
    legendWidth = (legendWidth/legendBoxWidth) * maxPageNumWidth;
    legendBoxWidth = maxPageNumWidth;
  }
  // floating point zero (not, but good enough)
  const qreal epsilon = .0000001;
  // xx is the last "page" box width
  qreal xx = legendWidth - floor(legendWidth/legendBoxWidth)*legendBoxWidth;
  if (xx < epsilon) { // computer zero
    xx = legendBoxWidth;
  }
  else if (xx > 0 && xx < maxPageNumWidth) {
    legendWidth -= xx;
    xx = (maxPageNumWidth > legendBoxWidth) ?
      legendBoxWidth : maxPageNumWidth;
    legendWidth += xx;
  }

  // height of each "page" box on the legend
  qreal legendBoxHeight = pageHeight * ratio;
  if (legendBoxHeight < maxPageNumHeight) {
    legendHeight = (legendHeight/legendBoxHeight)*maxPageNumHeight;
    legendBoxHeight = maxPageNumHeight;
  }
  // yy is the last "page" box height
  qreal yy = legendHeight -
    floor(legendHeight/legendBoxHeight)*legendBoxHeight;
  if (yy < epsilon) {
    yy = legendBoxHeight;
  }
  else if (yy > 0 && yy < maxPageNumHeight) {
    legendHeight -= yy;
    yy = (maxPageNumHeight > legendBoxHeight) ?
      legendBoxHeight : maxPageNumHeight;
    legendHeight += yy;
  }

  // the border
  const qreal xstart = printerWidth_/2 - legendWidth/2;
  const qreal ystart = pdfSymbolDim_;
  painter_.drawRect(QRectF(xstart, ystart, legendWidth, legendHeight));
  // the interior vertical lines
  for (int i = 1; i * legendBoxWidth < legendWidth; ++i) {
    painter_.drawLine(QPointF(xstart + i * legendBoxWidth, ystart),
                      QPointF(xstart + i * legendBoxWidth,
                              ystart + legendHeight));
  }
  // the interior horizontal lines
  for (int j = 1; j * legendBoxHeight < legendHeight; ++j) {
    painter_.drawLine(QPointF(xstart, ystart + j * legendBoxHeight),
                      QPointF(xstart + legendWidth,
                              ystart + j * legendBoxHeight));
  }
  // add the page numbers to the legend boxes
  for (int x = 1; x <= xPages_; ++x) {
    for (int y = 1; y <= yPages_; ++y) {
      const qreal thisBoxWidth = (x < xPages_ || xPages_ == 1) ?
        legendBoxWidth : xx;
      const qreal thisBoxHeight = (y < yPages_ || yPages_ == 1) ?
        legendBoxHeight : yy;
      const int pageNum = yPages_ * (x-1) + y;
      painter_.
        drawText(QPointF(xstart + (x-1) * legendBoxWidth +
                         static_cast<qreal>(thisBoxWidth - sWidth(pageNum))/2,
                         ystart + (y-1) * legendBoxHeight +
                         static_cast<qreal>(thisBoxHeight)/2 +
                         static_cast<qreal>(sHeight(pageNum))/4),
                 ::itoqs(pageNum));
    }
  }
  return ystart + legendHeight;
}