File: plotdialog.cpp

package info (click to toggle)
librecad 2.2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 105,584 kB
  • sloc: cpp: 187,958; sh: 336; xml: 47; makefile: 21
file content (159 lines) | stat: -rw-r--r-- 4,547 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "plotdialog.h"

#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QComboBox>
#include <QDebug>

Q_DECLARE_METATYPE(plotDialog::EntityType)

plotDialog::plotDialog(QWidget *parent) :
    QDialog(parent)
{
    setWindowTitle(tr("Plot equation"));
    mainLayout = new QGridLayout;
    buttonLayout = new QHBoxLayout;
    description = new QLabel(tr("This plugin allows you to plot mathematical equations.\n"
                                "If you don't want to use the parametric form, just leave out \"Equation2\".\n"
                                "You can use pi when you need the value of pi (i.e. (3*pi)).\n"
                                "Use t or x in your equation as a variable/parameter.\n"));
    lblEquasion1 = new QLabel(tr("Equation 1:"));
    lblEquasion2 = new QLabel(tr("Equation 2:"));
    lnedEquasion1 = new QLineEdit(this);
    lnedEquasion2 = new QLineEdit(this);
    lblStartValue = new QLabel(tr("start value:"));
    lblEndValue = new QLabel(tr("end value:"));
    lblStepSize = new QLabel(tr("step size:"));
    lnedStartValue = new QLineEdit(this);
    lnedEndValue = new QLineEdit(this);
    lnedStepSize = new QLineEdit(this);
    btnAccept = new QPushButton(tr("Draw"));
    btnCancel = new QPushButton(tr("Cancel"));
    space = new QSpacerItem(0, 20);


    lnedStartValue->setMaximumWidth(50);
    lnedEndValue->setMaximumWidth(50);
    lnedStepSize->setMaximumWidth(50);

    mainLayout->addWidget(description, 0, 0, 1, -1);

    mainLayout->addItem(space, 1, 0);

    mainLayout->addWidget(lblEquasion1, 2, 0);
    mainLayout->addWidget(lnedEquasion1, 2, 1);

    mainLayout->addWidget(lblEquasion2, 3, 0);
    mainLayout->addWidget(lnedEquasion2, 3, 1);

    mainLayout->addWidget(lblStartValue, 4, 0);
    mainLayout->addWidget(lblEndValue, 5, 0);
    mainLayout->addWidget(lblStepSize, 6, 0);

    mainLayout->addWidget(lnedStartValue, 4, 1);
    mainLayout->addWidget(lnedEndValue, 5, 1);
    mainLayout->addWidget(lnedStepSize, 6, 1);
    m_pTypeSelection = new QComboBox(this);
    m_pTypeSelection->addItem(tr("Line Segments", "Plot Equation to generate RS_Line segments"), QVariant::fromValue(LineSegments));
    m_pTypeSelection->addItem(tr("Polyline", "Plot Equation to generate RS_Polyline"), QVariant::fromValue(Polyline));
    m_pTypeSelection->addItem(tr("SplinePoints", "Plot Equation to generate 2nd spline by LC_SplinePoints"), QVariant::fromValue(SplinePoints));
    m_pTypeSelection->setCurrentIndex(1);

    mainLayout->addWidget(m_pTypeSelection, 7, 0);

    buttonLayout->addWidget(btnAccept);
    buttonLayout->addWidget(btnCancel);

    mainLayout->addLayout(buttonLayout, 8, 1);

    setLayout(mainLayout);

    connect(btnAccept, SIGNAL(clicked()), this, SLOT(slotDrawButtonClicked()));
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));


}

plotDialog::EntityType plotDialog::getEntityType() const
{
    return m_pTypeSelection->itemData(m_pTypeSelection->currentIndex()).value<plotDialog::EntityType>();
}

//get the valuew that the user entered
void plotDialog::getValues(QString& eq1, QString& eq2, QString& start, QString& end, double& step) const
{
    eq1 = equation1;
    eq2 = equation2;
    start = startValue;
    end = endValue;
    step = stepSize;
}

//accept the dialog when input is ok otherwise reject
void plotDialog::slotDrawButtonClicked()
{
    if(readInput())
    {
        accept();
    }
    else
    {
        done(QDialog::Rejected);
    }
}

//read the input from the user (equation1, equation2, starvalue, endvalue, stepsize)
bool plotDialog::readInput()
{
    bool conv;

    //get equations
    equation1 = lnedEquasion1->text();
    equation2 = lnedEquasion2->text();

    if(equation1.isEmpty())
    {
        qDebug("no equation1 given");
        return false;
    }
    else
    {
        equation1 = equation1.replace(" ", "");
    }

    if(equation2.isEmpty())
    {
        qDebug( "no equation2 given");
    }
    else
    {
        equation2 = equation2.replace(" ", "");
    }

    //get start/end value
    startValue = lnedStartValue->text();
    if(startValue.isEmpty())
    {
        qDebug("no start point given");
        return false;
    }

    endValue = lnedEndValue->text();
    if(endValue.isEmpty())
    {
        qDebug("no end point given");
        return false;
    }

    //get step size
    stepSize = lnedStepSize->text().toDouble(&conv);
    if(!conv)
    {
        qDebug("could not convert step size");
        return false;
    }

    return true;
}