Re: GSoC 2014: Introduction

Posted by dxli on
URL: https://forum.librecad.org/GSoC-2014-Introduction-tp5709705p5709749.html

petal calculation needs to be updated as well:

void RS_ActionDrawCircle::trigger() {
    RS_PreviewActionInterface::trigger();
    deletePreview();

    //    RS_Circle* circle = new RS_Circle(container, data);
    QList<RS_AtomicEntity*> lists;
    RS_Circle* flower= new RS_Circle(container, data); // circle in center
    lists<<flower;
    //        flower->setLayerToActive();
    //        flower->setPenToActive();
    //        container->addEntity(flower);
    static int petal=3; //remember previous # petals
    int i = petal; // ASK THE USER (integer)
    double offset=2.*data.radius*sin(M_PI/petal);
    while (i--)
    {
        flower = new RS_Circle(*flower);
        // x + 2 2 pi/t = pi/2 + pi/t , // first offset direction is Pi/2 + Pi/petal
        // x= pi/t( -4 + t/2 + 1), (2 + 2i)
        // (t/2 -3 + (t -i)*2) p/t
        if(i==petal-1)
            flower->move(RS_Vector(data.radius, 0.));
        else
            flower->move(RS_Vector(((petal -i)*2 + 0.5*petal - 3.)*M_PI/petal)*offset);
        lists<<flower;
    }
    for(RS_AtomicEntity* c: lists){
        c->setLayerToActive();
        c->setPenToActive();
        container->addEntity(c);
    }

    if (document!=NULL) {
        document->startUndoCycle();
        for(RS_AtomicEntity* c: lists){
            document->addUndoable(c);
        }
        document->endUndoCycle();
    }

    // upd. undo list:

    graphicView->redraw(RS2::RedrawDrawing);
    graphicView->moveRelativeZero(data.center);

    setStatus(SetCenter);
    reset();

    //increase # of petals for the subsequent session
    petal++;
    if(petal>=20) petal=3;

//    RS_DEBUG->print("RS_ActionDrawCircle::trigger(): circle added: %d",
//                    circle->getId());
}