11 from qt_gui_py_common.worker_thread
import WorkerThread
13 from python_qt_binding
import loadUi, QtCore, QtWidgets
14 from python_qt_binding.QtWidgets
import QWidget
15 from python_qt_binding.QtCore
import Slot
21 from project_plugin
import ProjectPlugin
31 signal_update = QtCore.Signal(int)
34 super(FrameEditorGUI, self).
__init__(context)
36 self.setObjectName(
'FrameEditorGUI')
40 self.editor.parse_args(context.argv())
43 self.update_current_filename()
48 self._update_thread.start()
55 editor.observers.append(self)
71 ui_file = os.path.join(rospkg.RosPack().get_path(
'frame_editor'),
'src/frame_editor',
'FrameEditorGUI.ui')
72 loadUi(ui_file, widget)
73 widget.setObjectName(
'FrameEditorGUIUi')
77 widget.setWindowTitle(
"frame editor")
85 self.editor.init_views()
88 widget.style_frame.layout().addWidget(self.interface_style.get_widget())
134 print(
"> Shutting down")
137 def update(self, editor, level, elements):
138 self.signal_update.emit(level)
147 self.update_current_filename()
160 self.widget.list_tf.clear()
161 self.widget.list_tf.addItems(
162 sorted(self.editor.all_frame_ids(include_temp=
False)))
165 new_list = self.editor.frames.keys()
169 for item
in new_list:
172 self.widget.list_frames.addItems(items)
176 if item
not in new_list:
177 if self.widget.list_frames.currentItem()
and item == self.widget.list_frames.currentItem().text():
178 self.widget.list_frames.setCurrentItem(
None)
179 found = self.widget.list_frames.findItems(item, QtCore.Qt.MatchExactly)
180 self.widget.list_frames.takeItem(self.widget.list_frames.row(found[0]))
182 self.widget.list_frames.sortItems()
188 if not self.editor.active_frame:
190 self.widget.list_frames.setCurrentItem(
None)
191 self.widget.box_edit.setEnabled(
False)
194 self.widget.box_edit.setEnabled(
True)
196 name = self.editor.active_frame.name
201 items = self.widget.list_frames.findItems(name, QtCore.Qt.MatchExactly)
202 self.widget.list_frames.setCurrentItem(items[0])
212 f = self.editor.active_frame
218 w.txt_name.setText(f.name)
219 w.txt_parent.setText(f.parent)
222 w.txt_x.setValue(f.position[0])
223 w.txt_y.setValue(f.position[1])
224 w.txt_z.setValue(f.position[2])
226 rot = tf.transformations.euler_from_quaternion(f.orientation)
227 if self.widget.btn_deg.isChecked():
228 rot = (180.0*rot[0]/math.pi, 180.0*rot[1]/math.pi, 180.0*rot[2]/math.pi)
230 w.txt_a.setValue(rot[0])
231 w.txt_b.setValue(rot[1])
232 w.txt_c.setValue(rot[2])
234 txt_abs_pos = (w.txt_abs_x, w.txt_abs_y, w.txt_abs_z)
235 txt_abs_rot = (w.txt_abs_a, w.txt_abs_b, w.txt_abs_c)
240 f.tf_buffer.lookup_transform(
'world', f.name, rospy.Time(0)))
241 for txt, p
in zip(txt_abs_pos, position):
244 rot = tf.transformations.euler_from_quaternion(orientation)
245 if self.widget.btn_deg.isChecked():
246 rot = map(math.degrees, rot)
247 for txt, r
in zip(txt_abs_rot, rot):
251 for txt
in txt_abs_rot + txt_abs_pos:
252 txt.setEnabled(
False)
255 self.widget.combo_style.setCurrentIndex(self.widget.combo_style.findText(f.style))
263 if not self.editor.active_frame
or (self.editor.active_frame.name != name):
270 return self.editor.save_file(file_name)
280 existing_frames = set(self.editor.all_frame_ids())
282 name, ok = QtWidgets.QInputDialog.getText(self.widget,
"Add New Frame",
"Name:", QtWidgets.QLineEdit.Normal,
"my_frame");
284 while ok
and name
in existing_frames:
285 name, ok = QtWidgets.QInputDialog.getText(self.widget,
"Add New Frame",
"Name (must be unique):", QtWidgets.QLineEdit.Normal,
"my_frame")
289 if not existing_frames:
290 available_parents = [
"world"]
292 available_parents = self.editor.all_frame_ids(include_temp=
False)
293 parent, ok = QtWidgets.QInputDialog.getItem(self.widget,
"Add New Frame",
"Parent Name:", sorted(available_parents))
296 if not ok
or parent ==
"":
305 item = self.widget.list_frames.currentItem()
308 source_name = item.text()
309 parent_name = self.editor.frames[source_name].parent
312 existing_frames = set(self.editor.all_frame_ids())
314 name, ok = QtWidgets.QInputDialog.getText(self.widget,
"Duplicate Frame",
"Name:", QtWidgets.QLineEdit.Normal, source_name);
316 while ok
and name
in existing_frames:
317 name, ok = QtWidgets.QInputDialog.getText(self.widget,
"Duplicate Frame",
"Name (must be unique):", QtWidgets.QLineEdit.Normal, source_name)
327 item = self.widget.list_frames.currentItem()
344 parent = self.widget.list_tf.currentItem()
348 if parent.text() == self.editor.active_frame.name:
351 self.editor.command(
Command_SetParent(self.editor, self.editor.active_frame, parent.text(), keep_absolute))
358 self.
set_pose([
"x",
"y",
"z",
"a",
"b",
"c"])
388 source = self.widget.list_tf.currentItem()
392 frame = self.editor.active_frame
405 self.editor.active_frame.tf_buffer.lookup_transform(
406 self.editor.active_frame.parent,
"world", rospy.Time(0)))
416 self.editor.active_frame.listener.lookupTransform(
417 self.editor.active_frame.parent,
"world", rospy.Time(0)))
424 frame = self.editor.active_frame
425 value = widget.value()
428 if self.widget.btn_deg.isChecked()
and symbol
in [
'a',
'b',
'c']:
429 value = value * math.pi / 180.0
431 if frame.value(symbol) != value:
432 self.editor.command(
Command_SetValue(self.editor, self.editor.active_frame, symbol, value))
458 style = self.widget.combo_style.currentText().lower()
459 if self.editor.active_frame.style != style:
460 self.editor.command(
Command_SetStyle(self.editor, self.editor.active_frame, style))
467 self._update_thread.kill()
def btn_set_parent_abs_clicked(self, checked)
def update_active_frame(self)
def update_all(self, level)
def btn_delete_clicked(self, checked)
def btn_reset_orientation_rel_clicked(self, checked)
def btn_set_pose_clicked(self, checked)
SET BUTTONS ##.
def _update_finished(self)
def _update_thread_run(self)
def btn_set_position_clicked(self, checked)
def btn_set_x_clicked(self, checked)
def update_frame_list(self)
def btn_set_y_clicked(self, checked)
def create_main_widget(self)
def btn_set_parent_rel_clicked(self, checked)
PARENTING ##.
def btn_set_c_clicked(self, checked)
old_frame_list
Add missing.
def btn_reset_position_abs_clicked(self, checked)
def btn_set_z_clicked(self, checked)
def btn_reset_position_rel_clicked(self, checked)
RESET BUTTONS ##.
def shutdown_plugin(self)
PLUGIN ##.
def btn_duplicate_clicked(self, checked)
def __init__(self, context)
def btn_set_orientation_clicked(self, checked)
def set_value(self, widget, symbol)
Spin Boxes ##.
def update(self, editor, level, elements)
interface_style
Main widget.
old_selected
Select item in list.
def selected_frame_changed(self, name)
def btn_set_a_clicked(self, checked)
def write_file(self, file_name)
BUTTONS ##.
def FromTransformStamped(msg)
TransformStamped ##.
def set_parent(self, keep_absolute)
def frame_style_changed(self, id)
FRAME STYLE ##.
def btn_reset_orientation_abs_clicked(self, checked)
def btn_set_b_clicked(self, checked)
def btn_add_clicked(self, checked)