Beispiel #1
0
  void ScalarFiniteElement<D> ::
  CalcDShape (const IntegrationPoint & ip, 
	      FlatMatrixFixWidth<D> dshape) const
  
  {
    static bool firsttime = true;
    if (firsttime)
      {
	cout << "WARNING: CalcDShape not overloaded for class, using numerical differentiation " << typeid(this).name() << ", ndof = " << ndof << endl;
        firsttime = false;
      }
    
    int nd = GetNDof();
    int sdim = D;

    double eps = 2e-5;
    ArrayMem<double, 100> hm1(nd), hm2(nd), hm3(nd), hm4(nd);
    FlatVector<> 
      shape1(nd, &hm1[0]), 
      shape2(nd, &hm2[0]), 
      shape3(nd, &hm3[0]), 
      shape4(nd, &hm4[0]);

    for (int i = 0; i < sdim; i++)
      {
	IntegrationPoint ip1 = ip;
	IntegrationPoint ip2 = ip;
        ip1(i) -= eps;
        ip2(i) += eps;
	CalcShape (ip1, shape1);
	CalcShape (ip2, shape2);

        ip1(i) -= eps;
        ip2(i) += eps;
	CalcShape (ip1, shape3);
	CalcShape (ip2, shape4);

	for (int j = 0; j < nd; j++)
	  dshape(j, i) = 
	    2/(3*eps) * (shape2(j) - shape1(j)) 
	    -1/(12*eps) * (shape4(j) - shape3(j));
      }
  }
Beispiel #2
0
void TestShapePainting::testPaintOrder()
{
    // the stacking order determines the painting order so things on top
    // get their paint called last.
    // Each shape has a zIndex and within the children a container has
    // it determines the stacking order. Its important to realize that
    // the zIndex is thus local to a container, if you have layer1 and layer2
    // with both various child shapes the stacking order of the layer shapes
    // is most important, then within this the child shape index is used.

    class OrderedMockShape : public MockShape {
    public:
        OrderedMockShape(QList<MockShape*> &list) : order(list) {}
        void paint(QPainter &painter, const KViewConverter &converter) {
            order.append(this);
            MockShape::paint(painter, converter);
        }
        QList<MockShape*> &order;
    };

    QList<MockShape*> order;

    MockContainer top;
    top.setZIndex(2);
    OrderedMockShape shape1(order);
    shape1.setZIndex(5);
    OrderedMockShape shape2(order);
    shape2.setZIndex(0);
    top.addShape(&shape1);
    top.addShape(&shape2);

    MockContainer bottom;
    bottom.setZIndex(1);
    OrderedMockShape shape3(order);
    shape3.setZIndex(-1);
    OrderedMockShape shape4(order);
    shape4.setZIndex(9);
    bottom.addShape(&shape3);
    bottom.addShape(&shape4);

    MockCanvas canvas;
    KShapeManager manager(&canvas);
    manager.addShape(&top);
    manager.addShape(&bottom);
    QCOMPARE(manager.shapes().count(), 6);

    QImage image(100, 100,  QImage::Format_Mono);
    QPainter painter(&image);
    KViewConverter vc;
    manager.paint(painter, vc, false);
    QCOMPARE(top.paintedCount, 1);
    QCOMPARE(bottom.paintedCount, 1);
    QCOMPARE(shape1.paintedCount, 1);
    QCOMPARE(shape2.paintedCount, 1);
    QCOMPARE(shape3.paintedCount, 1);
    QCOMPARE(shape4.paintedCount, 1);

    QCOMPARE(order.count(), 4);
    QVERIFY(order[0] == &shape3); // lowest first
    QVERIFY(order[1] == &shape4);
    QVERIFY(order[2] == &shape2);
    QVERIFY(order[3] == &shape1);

    // again, with clipping.
    order.clear();
    painter.setClipRect(0, 0, 100, 100);
    manager.paint(painter, vc, false);
    QCOMPARE(top.paintedCount, 2);
    QCOMPARE(bottom.paintedCount, 2);
    QCOMPARE(shape1.paintedCount, 2);
    QCOMPARE(shape2.paintedCount, 2);
    QCOMPARE(shape3.paintedCount, 2);
    QCOMPARE(shape4.paintedCount, 2);

    QCOMPARE(order.count(), 4);
    QVERIFY(order[0] == &shape3); // lowest first
    QVERIFY(order[1] == &shape4);
    QVERIFY(order[2] == &shape2);
    QVERIFY(order[3] == &shape1);

    order.clear();
    
    MockContainer root;
    root.setZIndex(0);
    
    MockContainer branch1;
    branch1.setZIndex(1);
    OrderedMockShape child1_1(order);
    child1_1.setZIndex(1);
    OrderedMockShape child1_2(order);
    child1_2.setZIndex(2);
    branch1.addShape(&child1_1);
    branch1.addShape(&child1_2);
    
    MockContainer branch2;
    branch2.setZIndex(2);
    OrderedMockShape child2_1(order);
    child2_1.setZIndex(1);
    OrderedMockShape child2_2(order);
    child2_2.setZIndex(2);
    branch2.addShape(&child2_1);
    branch2.addShape(&child2_2);
 
    root.addShape(&branch1);
    root.addShape(&branch2);
    
    QList<KShape*> sortedShapes;
    sortedShapes.append(&root);
    sortedShapes.append(&branch1);
    sortedShapes.append(&branch2);
    sortedShapes.append(branch1.shapes());
    sortedShapes.append(branch2.shapes());
    
    qSort(sortedShapes.begin(), sortedShapes.end(), KShape::compareShapeZIndex);
    QCOMPARE(sortedShapes.count(), 7);
    QVERIFY(sortedShapes[0] == &root);
    QVERIFY(sortedShapes[1] == &branch1);
    QVERIFY(sortedShapes[2] == &child1_1);
    QVERIFY(sortedShapes[3] == &child1_2);
    QVERIFY(sortedShapes[4] == &branch2);
    QVERIFY(sortedShapes[5] == &child2_1);
    QVERIFY(sortedShapes[6] == &child2_2);
}