forked from graspit-simulator/graspit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqmDlg.cpp
197 lines (171 loc) · 5.86 KB
/
qmDlg.cpp
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//######################################################################
//
// GraspIt!
// Copyright (C) 2002-2009 Columbia University in the City of New York.
// All rights reserved.
//
// GraspIt! is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GraspIt! is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GraspIt!. If not, see <http://www.gnu.org/licenses/>.
//
// Author(s): Andrew T. Miller
//
// $Id:
//
//######################################################################
#include <QHBoxLayout>
#include "qmDlg.h"
#include "graspit/graspitCore.h"
#include "graspit/ivmgr.h"
#include "graspit/grasp.h"
#include "list"
#include "graspit/world.h"
#include "graspit/robot.h"
//#define GRASPITDBG
#include "graspit/debug.h"
/*!
This populates the quality measure list with the currently defined quality
measures for this grasp. Then it populates the QM comboBox with the
all the possible quality measure types. Next, it creates an empty
settings area widget to hold the settings for the individual types of
quality measures, and adds it to the layout.
*/
void QMDlg::init()
{
std::list<QualityMeasure *>::iterator qp;
Grasp *g = graspitCore->getWorld()->getCurrentHand()->getGrasp();
int i;
qmListBox->insertItem("New quality measure");
for (qp = g->qmList.begin(), i = 1; qp != g->qmList.end(); qp++, i++) {
qmListBox->insertItem((*qp)->getName());
}
for (i = 0; QualityMeasure::TYPE_LIST[i]; i++) {
qmTypeComboBox->insertItem(QString(QualityMeasure::TYPE_LIST[i]));
}
qmSettingsBox->setColumnLayout(0, Qt::Vertical);
QHBoxLayout *settingsBoxLayout = new QHBoxLayout(qmSettingsBox->layout());
settingsBoxLayout->setAlignment(Qt::AlignTop);
qmDlgData.settingsArea = new QWidget(qmSettingsBox);
settingsBoxLayout->addWidget(qmDlgData.settingsArea);
qmDlgData.grasp = g;
qmDlgData.qmTypeComboBox = qmTypeComboBox;
qmDlgData.qmName = qmName;
gravityBox->setChecked(g->isGravitySet());
qmListBox->setCurrentItem(0);
}
/*!
Reads the selected QM type and calls updateSettingsBox .
*/
void QMDlg::selectQMType(const QString &typeStr)
{
qmDlgData.qmType = typeStr.latin1();
updateSettingsBox();
}
/*!
Deletes the current settings area widget, creates a new one, and
calls the static quality meausre method to build the correct set of
settings widgets for the currently selected QM type.
*/
void QMDlg::updateSettingsBox()
{
delete qmDlgData.settingsArea;
qmDlgData.settingsArea = new QWidget(qmSettingsBox);
qmSettingsBox->layout()->setAlignment(Qt::AlignTop);
qmSettingsBox->layout()->add(qmDlgData.settingsArea);
QualityMeasure::buildParamArea(&qmDlgData);
qmDlgData.settingsArea->show();
}
/*!
Creates a new quality measure of the selected type with the given name from
the name text area. If "New Quality Measure" is selected in the list, it
adds this QM to the grasp and to the quality measure list. Otherwise it
replaces the currently selected QM with the new one.
*/
void QMDlg::addEditQM()
{
Grasp *g = graspitCore->getWorld()->getCurrentHand()->getGrasp();
QualityMeasure *newQM;
int selectedQM;
newQM = QualityMeasure::createInstance(&qmDlgData);
selectedQM = qmListBox->currentItem();
if (selectedQM == 0) { // create a new quality measure
g->addQM(newQM);
qmListBox->insertItem(qmName->text());
}
else { // replace an old quality measure with a new one
g->replaceQM(selectedQM - 1, newQM);
qmListBox->changeItem(qmName->text(), selectedQM);
}
qmListBox->setCurrentItem(0);
qmListBox->update();
qmListBox->show();
}
/*!
Removes the selected QM from the grasp and the quality measure list. Then
it selects the next item in the list.
*/
void QMDlg::deleteQM()
{
int selectedQM;
int numItems;
selectedQM = qmListBox->currentItem();
graspitCore->getWorld()->getCurrentHand()->getGrasp()->
removeQM(selectedQM - 1);
qmListBox->removeItem(selectedQM);
// select the next item in the list
numItems = qmListBox->count();
qmListBox->setCurrentItem(selectedQM < numItems ? selectedQM : 0);
qmListBox->update();
}
/*!
If "New Quality Measure" is selected, the first item is the QM type box
is selected, and the delete button is disabled. Otherwise, it updates
the name in the text area, and sets the QM type in the comboBox to the
type of thecurrently selected QM, and finally calls the updateSettingsBox
to update the settings area.
*/
void QMDlg::selectQM(int which)
{
if (which == 0) { // "New quality measure" selected
qmDlgData.currQM = NULL;
qmDlgData.qmType = QualityMeasure::TYPE_LIST[0];
qmTypeComboBox->setCurrentItem(0);
DeleteButton->setEnabled(false);
qmName->setText(QString("New Quality Measure"));
}
else {
DeleteButton->setEnabled(true);
Grasp *g = graspitCore->getWorld()->getCurrentHand()->getGrasp();
qmDlgData.currQM = g->getQM(which - 1);
for (int i = 0; QualityMeasure::TYPE_LIST[i]; i++) {
if (!strcmp(QualityMeasure::TYPE_LIST[i], qmDlgData.currQM->getType())) {
qmTypeComboBox->setCurrentItem(i);
qmDlgData.qmType = QualityMeasure::TYPE_LIST[i];
break;
}
}
qmName->setText(qmListBox->text(which));
}
updateSettingsBox();
}
void QMDlg::gravityBox_clicked()
{
Grasp *g = graspitCore->getWorld()->getCurrentHand()->getGrasp();
g->setGravity(gravityBox->isChecked());
if (gravityBox->isChecked()) {
fprintf(stderr, "Gravity on\n");
} else {
fprintf(stderr, "Gravity off\n");
}
// g->updateWrenchSpaces();
g->update();
}