Пример #1
0
void UnGroupCommand::execute(){
    if(!isInitialized){
        for(Graphics* selectNode : *shapes){
            if(selectNode->isSelected()){
                if(CompositeGraphics* com = dynamic_cast<CompositeGraphics*>(selectNode)) {
                    shapeHasBeenSelected = *(com->getChildVector());
                    for(Graphics* child : shapeHasBeenSelected){
                       shapes->push_back(child);
                    }
                    removeSpecifiedElementInShapes(com);
                    com->clearChildVector();
                    group = com;
                    isInitialized = true;
                    break;
                }
            }
        }
    }else{
         for(Graphics* child : shapeHasBeenSelected){
            shapes->push_back(child);
         }
        CompositeGraphics* com = dynamic_cast<CompositeGraphics*>(this->group);
        removeSpecifiedElementInShapes(com);
        com->clearChildVector();
    }
}
Пример #2
0
TEST (CompositeGraphics, defaultBoundingBox) {
    CompositeGraphics g;
    // CompositeGraphics object has a default bounding box of
    // rectangle (0,0,0,0)
    LONGS_EQUAL(0,g.getBoundingBox().llx());
    LONGS_EQUAL(0,g.getBoundingBox().lly());
    LONGS_EQUAL(0,g.getBoundingBox().urx());
    LONGS_EQUAL(0,g.getBoundingBox().ury());
    LONGS_EQUAL(0,g.getBoundingBox().area());
}
Пример #3
0
void UnGroupCommand::unexecute(){
     for(Graphics* sha : shapeHasBeenSelected){
            removeSpecifiedElementInShapes(sha);
        }
        CompositeGraphics *com = dynamic_cast<CompositeGraphics*>(this->group);
        for(Graphics* selectedSha : shapeHasBeenSelected){
            com->add(selectedSha);
        }
        shapes->push_back(com);
}
Пример #4
0
TEST(CompositeGraphics, addingTwoChildrenAndGetBoundingBox) {
    CompositeGraphics g;

    g.add(new SimpleGraphics(new Circle(0,0,1)));
    g.add(new SimpleGraphics(new Square(-2,-2,2)));

    LONGS_EQUAL(-2,g.getBoundingBox().llx());
    LONGS_EQUAL(-2,g.getBoundingBox().lly());
    LONGS_EQUAL(1,g.getBoundingBox().urx());
    LONGS_EQUAL(1,g.getBoundingBox().ury());
}
Пример #5
0
TEST(CompositeGraphics, addingOneChild) {
    CompositeGraphics g;

    try {
        g.add(new SimpleGraphics(new Circle(0,0,2)));
    } catch (std::string s) {
        FAIL("Should not throw exception");
    }

    LONGS_EQUAL(16,g.getBoundingBox().area());
}
Пример #6
0
TEST (DescVisitor, CompositeGraphics) {
    CompositeGraphics g;
    g.add(new SimpleGraphics(new Circle(0,0,1)));
    g.add(new SimpleGraphics(new Square(-2,-2,2)));

    DescriptionVisitor dv;
    g.accept(dv);

    std::string ans("Comp R(-2,-2,3,3)\n");
    ans += std::string("  C(0,0,1)\n");
    ans += std::string("  S(-2,-2,2)\n");
    CHECK(ans==dv.getDescription());
    // std::cout << dv.getDescription() << std::endl;
}
Пример #7
0
TEST(CompositeGraphics, SimpleAndCompositeChildrenAndGetBoundingBox) {
    CompositeGraphics g;
    SimpleGraphics r(new Rectangle (-1,-1,1,3));

    g.add(new SimpleGraphics(new Circle(0,0,1)));
    g.add(new SimpleGraphics(new Square(-2,-2,2)));
    CompositeGraphics h;
    h.add(&g);
    h.add(&r);

    LONGS_EQUAL(-2,h.getBoundingBox().llx());
    LONGS_EQUAL(-2,h.getBoundingBox().lly());
    LONGS_EQUAL(1,h.getBoundingBox().urx());
    LONGS_EQUAL(2,h.getBoundingBox().ury());

}
Пример #8
0
TEST(AreaVisitor, derivedFromGraphicsVisitor) {
    CompositeGraphics g;
    g.add(new SimpleGraphics(new Circle(0,0,1)));
    g.add(new SimpleGraphics(new Square(-2,-2,2)));
    SimpleGraphics r(new Rectangle (-1,-1,1,3));
    CompositeGraphics h;

    h.add(&g);
    h.add(&r);

    GraphicsVisitor * av = new AreaVisitor;
    h.accept(*av);

    LONGS_EQUAL(10, static_cast<AreaVisitor *>(av)->area());
}
Пример #9
0
TEST (AreaVisitor, Composite) {
    CompositeGraphics g;
    g.add(new SimpleGraphics(new Circle(0,0,1)));
    g.add(new SimpleGraphics(new Square(-2,-2,2)));

    AreaVisitor av;
    g.accept(av);

    LONGS_EQUAL(7,av.area());

    SimpleGraphics r(new Rectangle (-1,-1,1,3));

    CompositeGraphics h;
    h.add(&g);
    h.add(&r);

    AreaVisitor av2;
    h.accept(av2);

    LONGS_EQUAL(10,av2.area());
}
Пример #10
0
TEST (DescVisitor, CompositeGraphicsWithComposite) {
    CompositeGraphics g;
    g.add(new SimpleGraphics(new Circle(0,0,1)));
    g.add(new SimpleGraphics(new Square(-2,-2,2)));

    SimpleGraphics r(new Rectangle (-1,-1,1,3));

    CompositeGraphics h;
    h.add(&g);
    h.add(&r);

    DescriptionVisitor dv;
    h.accept(dv);

    std::string ans("Comp R(-2,-2,3,4)\n");
    ans += std::string("  Comp R(-2,-2,3,3)\n");
    ans += std::string("    C(0,0,1)\n");
    ans += std::string("    S(-2,-2,2)\n");
    ans += std::string("  R(-1,-1,1,3)\n");
    CHECK(ans==dv.getDescription());
    // std::cout << dv.getDescription() << std::endl;
}