~jil26/fabinterpreter/Qt_version

« back to all changes in this revision

Viewing changes to software/FabInterpreter/mainwindow.cpp

  • Committer: Jeremy Cohen
  • Date: 2010-07-16 20:20:34 UTC
  • Revision ID: jeremyrcohen@gmail.com-20100716202034-nsdz43xg4r9hyhqh
Added signal/slot implementation. Still need to implement threads

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
bool enablePosDisplay;
10
10
string pathDisplayText;
11
11
int maxProgress = 0;
 
12
QThread fabricationThread;
 
13
 
12
14
 
13
15
//timer variables
14
16
int numTicks = 0;
18
20
 
19
21
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
20
22
{
21
 
    ui.setupUi(this);
 
23
    setupUi(this);
 
24
    this->initialize();
22
25
}
23
26
 
24
27
MainWindow::~MainWindow()
25
28
{
26
 
 
 
29
    destroy(true, true);
27
30
}
28
31
 
29
 
void MainWindow::on_LoadModelButton_clicked()
 
32
void MainWindow::initialize()
30
33
{
31
 
    QString fileName = QFileDialog::getOpenFileName(this, "Model File Loader", "./", "*.fab");
32
 
    string result = printer.loadFabFile(fileName.toStdString());
33
 
    if(result.compare("") == 0)
34
 
    {
35
 
        //Update display.
36
 
        string info = Util::toString<int>(printer.numLoadedPaths())+" paths loaded from file "+fileName.toStdString();
37
 
 
38
 
        maxProgress = printer.numLoadedPaths(); //sets the max progress to the number of paths
39
 
        ExecutePathLabel->setText(info.c_str());
40
 
 
41
 
        //Show the loaded material calibrations.
42
 
        vector<string> result;
43
 
        printer.loadedMaterialCalibrations(result);
44
 
        bayMaterialCalibration0->clear();
45
 
        bayMaterialCalibration1->clear();
46
 
        for(vector<string>::iterator i = result.begin(); i != result.end(); ++i)
47
 
        {
48
 
            int numLoadedBays = printer.numLoadedBays();
49
 
            if(numLoadedBays >= 1)
50
 
            {
51
 
                bayMaterialCalibration0->addItem(i->c_str());
52
 
            }
53
 
            if(numLoadedBays >= 2)
54
 
            {
55
 
                bayMaterialCalibration1->addItem(i->c_str());
56
 
            }
57
 
            if(numLoadedBays >= 3)
58
 
            {
59
 
                bayMaterialCalibration2->addItem(i->c_str());
60
 
            }
61
 
        }
62
 
        ExecuteButton->setEnabled(true);
63
 
        ExecuteButton->setFocus();
64
 
    }
65
 
    else
66
 
    {
67
 
        Util::messageBox(result);
68
 
    }
 
34
    /*
 
35
    if ()
 
36
    {
 
37
        disconnect(PauseFabButton, SIGNAL(clicked()), printer, SLOT(pausePrint()));
 
38
        disconnect(CancelFabButton, SIGNAL(clicked()), printer, SLOT(cancelPrint()));
 
39
        disconnect(RedoPathButton, SIGNAL(clicked()), printer, SLOT(redoPath()));
 
40
        disconnect(ForceStopButton, SIGNAL(clicked()), printer, SLOT(stopMotors()));
 
41
        disconnect(ResetPosButton, SIGNAL(clicked()), printer, SLOT(resetPos()));
 
42
        delete printer;
 
43
    }
 
44
    */
 
45
    printer = new FabAtHomePrinter();
 
46
    connect(LoadConfigButton, SIGNAL(clicked()), this, SLOT(loadConfig()));
 
47
    connect(PauseFabButton, SIGNAL(clicked()), printer, SLOT(pausePrint()));
 
48
    connect(CancelFabButton, SIGNAL(clicked()), printer, SLOT(cancelPrint()));
 
49
    connect(RedoPathButton, SIGNAL(clicked()), printer, SLOT(redoPath()));
 
50
    connect(ForceStopButton, SIGNAL(clicked()), printer, SLOT(stopMotors()));
 
51
    connect(ResetPosButton, SIGNAL(clicked()), printer, SLOT(resetPos()));
 
52
    connect(MoveButton, SIGNAL(clicked()), printer, SLOT(move()));
 
53
    connect(ResetPosButton, SIGNAL(clicked()), this, SLOT(resetValues()));
 
54
    connect(LoadModelButton, SIGNAL(clicked()), this, SLOT(loadModel()));
 
55
    //connect(XCommandedField, SIGNAL(valueChanged(double), printer, SLOT()
 
56
    //TO_DO: add signal/slots for position boxes
69
57
}
70
58
 
71
 
void MainWindow::on_LoadConfigButton_clicked()
 
59
void MainWindow::loadConfig()
72
60
{
73
61
    //Open file dialog
74
62
    QString str = QFileDialog::getOpenFileName(this,"Config File Loader", "../../media/Printer Configs", "*.config");
75
 
    string result = printer.initialize(str.toStdString());
76
 
 
 
63
    string result = printer->initialize(str.toStdString());
77
64
    if(result.compare("") == 0)
78
65
    {
79
66
        //correctModule = true;
82
69
        XLabel->setText("X");
83
70
        YLabel->setText("Y");
84
71
        ZLabel->setText("Z");
85
 
        int numLoadedBays = printer.numLoadedBays();
 
72
 
 
73
        //TO_DO: add increment variables
 
74
 
 
75
        //sets minimum and maximum position so user cannot scroll past certain point
 
76
        XCommandedField->setMinimum(printer->axes["X"].motor->getMinPosition());
 
77
        XCommandedField->setMaximum(printer->axes["X"].motor->getMaxPosition());
 
78
        YCommandedField->setMinimum(printer->axes["Y"].motor->getMinPosition());
 
79
        YCommandedField->setMaximum(printer->axes["Y"].motor->getMaxPosition());
 
80
        ZCommandedField->setMinimum(printer->axes["Z"].motor->getMinPosition());
 
81
        ZCommandedField->setMaximum(printer->axes["Z"].motor->getMaxPosition());
 
82
        int numLoadedBays = printer->numLoadedBays();
86
83
        if(numLoadedBays >= 1)
87
84
        {
88
85
            bayLabel0->setText("Bay 0");
 
86
            bayCommandedPosition0->setMinimum(printer->tool.bays["Bay 0"].motor->getMinPosition());
 
87
            bayCommandedPosition0->setMaximum(printer->tool.bays["Bay 0"].motor->getMaxPosition());
89
88
        }
90
89
        if(numLoadedBays >= 2)
91
90
        {
112
111
        Util::messageBox(result);
113
112
    }
114
113
 
115
 
}
116
 
 
117
 
void MainWindow::on_MoveButton_clicked()
118
 
{
119
 
    printer.axes["X"].motor->moveAbsolute(XCommandedField->text().toDouble(), XVelocityField->text().toDouble(), XAccelerationField->text().toDouble());
120
 
    printer.axes["Y"].motor->moveAbsolute(YCommandedField->text().toDouble(), YVelocityField->text().toDouble(), YAccelerationField->text().toDouble());
121
 
    printer.axes["Z"].motor->moveAbsolute(ZCommandedField->text().toDouble(), ZVelocityField->text().toDouble(), ZAccelerationField->text().toDouble());
122
 
    int numLoadedBays = printer.numLoadedBays();
123
 
    if(numLoadedBays >= 1)
124
 
    {
125
 
        printer.tool.bays["Bay 0"].motor->moveAbsolute(bayCommandedPosition0->text().toDouble(), bayVelocity0->text().toDouble(), bayAcceleration0->text().toDouble());
126
 
    }
127
 
    if(numLoadedBays >= 2)
128
 
    {
129
 
        printer.tool.bays["Bay 1"].motor->moveAbsolute(bayCommandedPosition1->text().toDouble(), bayVelocity1->text().toDouble(), bayAcceleration1->text().toDouble());
130
 
    }
131
 
    if(numLoadedBays >= 3)
132
 
    {
133
 
        printer.tool.bays["Bay 2"].motor->moveAbsolute(bayCommandedPosition2->text().toDouble(), bayVelocity2->text().toDouble(), bayAcceleration2->text().toDouble());
134
 
    }
135
 
 }
136
 
 
137
 
void MainWindow::on_ExecuteButton_clicked()
138
 
{
139
 
 
140
 
}
141
 
 
142
 
void MainWindow::on_PauseFabButton_clicked()
143
 
{
144
 
    printer.pausePrint();
145
 
}
146
 
 
147
 
void MainWindow::on_CancelFabButton_clicked()
148
 
{
149
 
    printer.cancelPrint();
150
 
}
151
 
 
152
 
void MainWindow::on_ExitButton_clicked()
153
 
{
154
 
    disablePositionDisplay();
155
 
    this->close();
156
 
}
157
 
 
 
114
 
 
115
}
 
116
 
 
117
 
 
118
void MainWindow::resetValues()
 
119
{
 
120
    XCommandedField->setValue(0.000000);
 
121
    YCommandedField->setValue(0.000000);
 
122
    ZCommandedField->setValue(0.000000);
 
123
    int numLoadedBays = printer->numLoadedBays();
 
124
    if(numLoadedBays >= 1)
 
125
    {
 
126
        bayCommandedPosition0->setValue(0.00000);
 
127
    }
 
128
    if(numLoadedBays >= 2)
 
129
    {
 
130
        bayCommandedPosition1->setValue(0.000000);
 
131
    }
 
132
    if(numLoadedBays >= 3)
 
133
    {
 
134
        bayCommandedPosition2->setValue(0.000000);
 
135
    }
 
136
}
 
137
 
 
138
void MainWindow::loadModel()
 
139
{
 
140
    QString fileName = QFileDialog::getOpenFileName(this, "Model File Loader", "./", "*.fab");
 
141
    string result = printer->loadFabFile(fileName.toStdString());
 
142
    if(result.compare("") == 0)
 
143
    {
 
144
        //Update display.
 
145
        string info = Util::toString<int>(printer->numLoadedPaths())+" paths loaded from file "+fileName.toStdString();
 
146
 
 
147
        maxProgress = printer->numLoadedPaths(); //sets the max progress to the number of paths
 
148
        ExecutePathLabel->setText(info.c_str());
 
149
 
 
150
        //Show the loaded material calibrations.
 
151
        vector<string> result;
 
152
        printer->loadedMaterialCalibrations(result);
 
153
        bayMaterialCalibration0->clear();
 
154
        bayMaterialCalibration1->clear();
 
155
        for(vector<string>::iterator i = result.begin(); i != result.end(); ++i)
 
156
        {
 
157
            int numLoadedBays = printer->numLoadedBays();
 
158
            if(numLoadedBays >= 1)
 
159
            {
 
160
                bayMaterialCalibration0->addItem(i->c_str());
 
161
            }
 
162
            if(numLoadedBays >= 2)
 
163
            {
 
164
                bayMaterialCalibration1->addItem(i->c_str());
 
165
            }
 
166
            if(numLoadedBays >= 3)
 
167
            {
 
168
                bayMaterialCalibration2->addItem(i->c_str());
 
169
            }
 
170
        }
 
171
        ExecuteButton->setEnabled(true);
 
172
        ExecuteButton->setFocus();
 
173
    }
 
174
    else
 
175
    {
 
176
        Util::messageBox(result);
 
177
    }
 
178
}
 
179
void MainWindow::move()
 
180
{
 
181
    printer->axes["X"].motor->moveAbsolute(XCommandedField->text().toDouble(), XVelocityField->text().toDouble(), XAccelerationField->text().toDouble());
 
182
    printer->axes["Y"].motor->moveAbsolute(YCommandedField->text().toDouble(), YVelocityField->text().toDouble(), YAccelerationField->text().toDouble());
 
183
    printer->axes["Z"].motor->moveAbsolute(ZCommandedField->text().toDouble(), ZVelocityField->text().toDouble(), ZAccelerationField->text().toDouble());
 
184
    int numLoadedBays = printer->numLoadedBays();
 
185
    if(numLoadedBays >= 1)
 
186
    {
 
187
        printer->tool.bays["Bay 0"].motor->moveAbsolute(bayCommandedPosition0->text().toDouble(), bayVelocity0->text().toDouble(), bayAcceleration0->text().toDouble());
 
188
    }
 
189
    if(numLoadedBays >= 2)
 
190
    {
 
191
        printer->tool.bays["Bay 1"].motor->moveAbsolute(bayCommandedPosition1->text().toDouble(), bayVelocity1->text().toDouble(), bayAcceleration1->text().toDouble());
 
192
    }
 
193
    if(numLoadedBays >= 3)
 
194
    {
 
195
        printer->tool.bays["Bay 2"].motor->moveAbsolute(bayCommandedPosition2->text().toDouble(), bayVelocity2->text().toDouble(), bayAcceleration2->text().toDouble());
 
196
    }
 
197
}
158
198
 
159
199
void MainWindow::disablePositionDisplay()
160
200
{
161
 
     enablePosDisplay = false;
 
201
    enablePosDisplay = false;
162
202
}
163
203
 
164
204
void MainWindow::toggleAxes(bool enabled)
182
222
////////////////////////////////////////////////////////////////////////////////////
183
223
void MainWindow::toggleBays(bool enabled)
184
224
{
185
 
    int numLoadedBays = printer.numLoadedBays();
 
225
    int numLoadedBays = printer->numLoadedBays();
186
226
 
187
227
    //enable first bay
188
228
    if(numLoadedBays >= 1)
222
262
{
223
263
    string temp;
224
264
    //Display the position data in text fields
225
 
    temp = Util::toString<double>(printer.axes["X"].motor->getPosition());
 
265
    temp = Util::toString<double>(printer->axes["X"].motor->getPosition());
226
266
    XDisplay->setText(temp.c_str());
227
 
    temp = Util::toString<double>(printer.axes["Y"].motor->getPosition());
 
267
    temp = Util::toString<double>(printer->axes["Y"].motor->getPosition());
228
268
    YDisplay->setText(temp.c_str());
229
 
    temp = Util::toString<double>(printer.axes["Z"].motor->getPosition());
 
269
    temp = Util::toString<double>(printer->axes["Z"].motor->getPosition());
230
270
    ZDisplay->setText(temp.c_str());
231
 
    int numLoadedBays = printer.numLoadedBays();
 
271
    int numLoadedBays = printer->numLoadedBays();
232
272
    if(numLoadedBays >= 1)
233
273
    {
234
 
        temp = Util::toString<double>(printer.tool.bays["Bay 0"].motor->getPosition());
 
274
        temp = Util::toString<double>(printer->tool.bays["Bay 0"].motor->getPosition());
235
275
    }
236
276
    if(numLoadedBays >= 2)
237
277
    {
238
 
        temp = Util::toString<double>(printer.tool.bays["Bay 1"].motor->getPosition());
 
278
        temp = Util::toString<double>(printer->tool.bays["Bay 1"].motor->getPosition());
239
279
        bayMotorPosition1->setText(temp.c_str());
240
280
    }
241
281
    if(numLoadedBays >= 3)
242
282
    {
243
 
        temp = Util::toString<double>(printer.tool.bays["Bay 2"].motor->getPosition());
 
283
        temp = Util::toString<double>(printer->tool.bays["Bay 2"].motor->getPosition());
244
284
        bayMotorPosition2->setText(temp.c_str());
245
285
    }
246
 
 
247
286
}