]> Shamusworld >> Repos - architektonas/blob - src/forms/dlgellipse.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / dlgellipse.cpp
1 // dlgellipse.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/11/2010  Created this file. :-)
15 //
16
17 #include "dlgellipse.h"
18
19 #include "ellipse.h"
20 #include "drawing.h"
21 #include "math.h"
22
23 DlgEllipse::DlgEllipse(QWidget * parent/*= NULL*/, Qt::WindowFlags flags/*= 0*/):
24         QDialog(parent, flags)
25 {
26         ui.setupUi(this);
27 }
28
29 DlgEllipse::~DlgEllipse()
30 {
31 }
32
33 void DlgEllipse::setEllipse(Ellipse & e)
34 {
35         ellipse = &e;
36         //pen = ellipse->getPen();
37         ui.wPen->setPen(ellipse->getPen(false), true, false, "Pen");
38         Drawing * graphic = ellipse->getGraphic();
39
40         if (graphic != NULL)
41                 ui.cbLayer->init(*(graphic->getLayerList()), false, false);
42
43         Layer * lay = ellipse->getLayer(false);
44
45         if (lay != NULL)
46                 ui.cbLayer->setLayer(*lay);
47
48         QString s;
49         s.setNum(ellipse->getCenter().x);
50         ui.leCenterX->setText(s);
51         s.setNum(ellipse->getCenter().y);
52         ui.leCenterY->setText(s);
53         s.setNum(ellipse->getMajorP().magnitude());
54         ui.leMajor->setText(s);
55         s.setNum(ellipse->getMajorP().magnitude() * ellipse->getRatio());
56         ui.leMinor->setText(s);
57         s.setNum(Math::rad2deg(ellipse->getMajorP().angle()));
58         ui.leRotation->setText(s);
59         s.setNum(Math::rad2deg(ellipse->getAngle1()));
60         ui.leAngle1->setText(s);
61         s.setNum(Math::rad2deg(ellipse->getAngle2()));
62         ui.leAngle2->setText(s);
63         ui.cbReversed->setChecked(ellipse->isReversed());
64 }
65
66 void DlgEllipse::updateEllipse()
67 {
68         ellipse->setCenter(Vector(Math::eval(ui.leCenterX->text()),
69                 Math::eval(ui.leCenterY->text())));
70         Vector v;
71         v.setPolar(Math::eval(ui.leMajor->text()),
72                 Math::deg2rad(Math::eval(ui.leRotation->text())));
73         ellipse->setMajorP(v);
74
75         if (Math::eval(ui.leMajor->text()) > 1.0e-6)
76                 ellipse->setRatio(Math::eval(ui.leMinor->text()) / Math::eval(ui.leMajor->text()));
77         else
78                 ellipse->setRatio(1.0);
79
80         ellipse->setAngle1(Math::deg2rad(Math::eval(ui.leAngle1->text())));
81         ellipse->setAngle2(Math::deg2rad(Math::eval(ui.leAngle2->text())));
82         ellipse->setReversed(ui.cbReversed->isChecked());
83         ellipse->setPen(ui.wPen->getPen());
84         ellipse->setLayer(ui.cbLayer->currentText());
85 }