Ejemplo n.º 1
0
/*!\reimp
 */
void QGridView::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
{
    int colfirst = columnAt( cx );
    int collast = columnAt( cx + cw );
    int rowfirst = rowAt( cy );
    int rowlast = rowAt( cy + ch );

    if ( rowfirst == -1 || colfirst == -1 ) {
	paintEmptyArea( p, cx, cy, cw, ch );
	return;
    }

    if ( collast < 0 || collast >= ncols )
	collast = ncols-1;
    if ( rowlast < 0 || rowlast >= nrows )
	rowlast = nrows-1;

    // Go through the rows
    for ( int r = rowfirst; r <= rowlast; ++r ) {
	// get row position and height
	int rowp = r * cellh;

	// Go through the columns in the row r
	// if we know from where to where, go through [colfirst, collast],
	// else go through all of them
	for ( int c = colfirst; c <= collast; ++c ) {
	    // get position and width of column c
	    int colp = c * cellw;
	    // Translate painter and draw the cell
	    p->translate( colp, rowp );
	    paintCell( p, r, c );
	    p->translate( -colp, -rowp );
	}
    }

    // Paint empty rects
    paintEmptyArea( p, cx, cy, cw, ch );
}
Ejemplo n.º 2
0
void indicator(Grid* cGrid, shared_ptr<Var> T) {
  updateOtherVertex(cGrid); 

  T->set(0); 
  auto dx = listCell[0]->edge(0).abs();
  auto dy = listCell[0]->edge(1).abs(); 
 
  auto pi = 4.0*atan(1.0); 
  for (auto i = listCell[0]->level[0]; i < levelMax[0]+1; ++i) dx /= 2; 
  for (auto i = listCell[1]->level[1]; i < levelMax[1]+1; ++i) dy /= 2; 

  cout << " ------ " << dx << ", "<< dy << " : " << " " << levelMax[0] << endl; 

  // 00. Now color a new function at the cell centers; 
  double dist[listCell.size()];
  for (auto i = 0; i<listCell.size(); ++i) dist[i] = -1; 

  for (auto ci1 = 0; ci1 < cGrid->listCell.size(); ++ci1) {
    auto c1 = cGrid->listCell[ci1]; 
    auto x1 = c1->getCoord(); 
    auto norm = c1->vol(); norm = norm/norm.abs(); 
    auto i1 = c1->node[0]; 
    if (i1 < 0 && i1 >= cGrid->listVertex.size()) {
      cout << " Cell does not have a vertex ??? " << i1 << endl; 
      exit(1); 
    }
    auto v1 = cGrid->listVertex[i1];     
    auto i0 = cGrid->otherVertex[i1]; 
    if (i0 < 0 && i0 >= listVertex.size()) {
      cout << "WARNING - no associated vertex found! now what? " << endl; 
      exit(1); 
    }
    auto v0 = listVertex[i0];

    int_8 j; 
    for (j = 0; j < v0->cell.size(); ++j) if (v0->cell[j] >= 0) break; 
    
    vector<int_8> ngbrCells(1, v0->cell[j]); 
    ngbrCellbyLayer(5, ngbrCells); 

    for (auto j = 0; j < ngbrCells.size(); ++j) {
      auto ci0 = ngbrCells[j]; 
      auto c0 = listCell[ci0];       
      auto r = (c0->getCoord() - x1).abs(); 
      if (dist[ci0] < 0) dist[ci0] = r; 
      if (dist[ci0] < r) continue; 
      dist[ci0] = r; 
      if (r > 0.04) continue; 
      r = (c0->getCoord() - x1)*norm;
      T->set(ci0, 1.0/(1+exp(-160*r))); //0.25*r/dx*pi)));      
    }    
  }


  int icnt = 0; 
  for (auto i = 0; i < listCell.size(); ++i) {
    int_8 sum = 0; 
    paintCell(T, 0.0, 0.5, 1.0, i, sum);
    // if (sum > 1) {
    //   cout << endl << " Paint cells: " << sum << " icnt: " << icnt << endl; 
    //   if (icnt > 1) {
    // 	cout << " Found more than one bodies " << listCell[i]->getCoord() << endl; 
    // 	exit(1); 
    //   }
    //   ++icnt; 
    // }
  }
       
}
Ejemplo n.º 3
0
void TableSectionPainter::paintObject(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
    LayoutRect localPaintInvalidationRect = LayoutRect(paintInfo.rect);
    localPaintInvalidationRect.moveBy(-paintOffset);

    LayoutRect tableAlignedRect = m_layoutTableSection.logicalRectForWritingModeAndDirection(localPaintInvalidationRect);

    CellSpan dirtiedRows = m_layoutTableSection.dirtiedRows(tableAlignedRect);
    CellSpan dirtiedColumns = m_layoutTableSection.dirtiedColumns(tableAlignedRect);

    HashSet<LayoutTableCell*> overflowingCells = m_layoutTableSection.overflowingCells();
    if (dirtiedColumns.start() < dirtiedColumns.end()) {
        if (!m_layoutTableSection.hasMultipleCellLevels() && !overflowingCells.size()) {
            if (paintInfo.phase == PaintPhaseCollapsedTableBorders) {
                // Collapsed borders are painted from the bottom right to the top left so that precedence
                // due to cell position is respected.
                for (unsigned r = dirtiedRows.end(); r > dirtiedRows.start(); r--) {
                    unsigned row = r - 1;
                    for (unsigned c = dirtiedColumns.end(); c > dirtiedColumns.start(); c--) {
                        unsigned col = c - 1;
                        LayoutTableSection::CellStruct& current = m_layoutTableSection.cellAt(row, col);
                        LayoutTableCell* cell = current.primaryCell();
                        if (!cell || (row > dirtiedRows.start() && m_layoutTableSection.primaryCellAt(row - 1, col) == cell) || (col > dirtiedColumns.start() && m_layoutTableSection.primaryCellAt(row, col - 1) == cell))
                            continue;
                        LayoutPoint cellPoint = m_layoutTableSection.flipForWritingModeForChild(cell, paintOffset);
                        TableCellPainter(*cell).paintCollapsedBorders(paintInfo, cellPoint);
                    }
                }
            } else {
                // Draw the dirty cells in the order that they appear.
                for (unsigned r = dirtiedRows.start(); r < dirtiedRows.end(); r++) {
                    LayoutTableRow* row = m_layoutTableSection.rowLayoutObjectAt(r);
                    if (row && !row->hasSelfPaintingLayer())
                        TableRowPainter(*row).paintOutlineForRowIfNeeded(paintInfo, paintOffset);
                    for (unsigned c = dirtiedColumns.start(); c < dirtiedColumns.end(); c++) {
                        LayoutTableSection::CellStruct& current = m_layoutTableSection.cellAt(r, c);
                        LayoutTableCell* cell = current.primaryCell();
                        if (!cell || (r > dirtiedRows.start() && m_layoutTableSection.primaryCellAt(r - 1, c) == cell) || (c > dirtiedColumns.start() && m_layoutTableSection.primaryCellAt(r, c - 1) == cell))
                            continue;
                        paintCell(cell, paintInfo, paintOffset);
                    }
                }
            }
        } else {
            // The overflowing cells should be scarce to avoid adding a lot of cells to the HashSet.
#if ENABLE(ASSERT)
            unsigned totalRows = m_layoutTableSection.numRows();
            unsigned totalCols = m_layoutTableSection.table()->columns().size();
            ASSERT(overflowingCells.size() < totalRows * totalCols * gMaxAllowedOverflowingCellRatioForFastPaintPath);
#endif

            // To make sure we properly paint invalidate the section, we paint invalidated all the overflowing cells that we collected.
            Vector<LayoutTableCell*> cells;
            copyToVector(overflowingCells, cells);

            HashSet<LayoutTableCell*> spanningCells;

            for (unsigned r = dirtiedRows.start(); r < dirtiedRows.end(); r++) {
                LayoutTableRow* row = m_layoutTableSection.rowLayoutObjectAt(r);
                if (row && !row->hasSelfPaintingLayer())
                    TableRowPainter(*row).paintOutlineForRowIfNeeded(paintInfo, paintOffset);
                for (unsigned c = dirtiedColumns.start(); c < dirtiedColumns.end(); c++) {
                    LayoutTableSection::CellStruct& current = m_layoutTableSection.cellAt(r, c);
                    if (!current.hasCells())
                        continue;
                    for (unsigned i = 0; i < current.cells.size(); ++i) {
                        if (overflowingCells.contains(current.cells[i]))
                            continue;

                        if (current.cells[i]->rowSpan() > 1 || current.cells[i]->colSpan() > 1) {
                            if (!spanningCells.add(current.cells[i]).isNewEntry)
                                continue;
                        }

                        cells.append(current.cells[i]);
                    }
                }
            }

            // Sort the dirty cells by paint order.
            if (!overflowingCells.size())
                std::stable_sort(cells.begin(), cells.end(), compareCellPositions);
            else
                std::sort(cells.begin(), cells.end(), compareCellPositionsWithOverflowingCells);

            if (paintInfo.phase == PaintPhaseCollapsedTableBorders) {
                for (unsigned i = cells.size(); i > 0; --i) {
                    LayoutPoint cellPoint = m_layoutTableSection.flipForWritingModeForChild(cells[i - 1], paintOffset);
                    TableCellPainter(*cells[i - 1]).paintCollapsedBorders(paintInfo, cellPoint);
                }
            } else {
                for (unsigned i = 0; i < cells.size(); ++i)
                    paintCell(cells[i], paintInfo, paintOffset);
            }
        }
    }
}