11#!/usr/bin/env python
22
3+ import os
4+ import sys
5+
36import time
47import threading
58import yaml
1619from python_qt_binding import QtCore
1720from python_qt_binding .QtWidgets import QUndoStack
1821
22+ ## Views
23+ from frame_editor .interface_interactive_marker import FrameEditor_InteractiveMarker
24+ from frame_editor .interface_services import FrameEditor_Services
25+ from frame_editor .interface_markers import FrameEditor_Markers
26+ from frame_editor .interface_tf import FrameEditor_TF
27+
1928
2029class FrameEditor (QtCore .QObject ):
2130
@@ -24,7 +33,7 @@ def __init__(self):
2433
2534 self .frames = {}
2635 self .active_frame = None
27-
36+
2837 ## Undo/Redo
2938 self .observers = []
3039 self .undo_level = 0
@@ -164,7 +173,7 @@ def load_data(self, data):
164173 f .set_color (color )
165174 else :
166175 f = Frame (name , position , orientation , frame ["parent" ])
167-
176+
168177 self .command (Command_AddElement (self , f ))
169178
170179 self .undo_stack .endMacro ()
@@ -198,13 +207,13 @@ def save_file(self, filename):
198207
199208 if frame .style == "plane" :
200209 f ["data" ] = { "length" : frame .length , "width" :frame .width , "color" : frame .color }
201-
210+
202211 elif frame .style == "cube" :
203212 f ["data" ] = { "length" : frame .length , "width" : frame .width , "height" : frame .height , "color" : frame .color }
204-
213+
205214 elif frame .style == "sphere" :
206215 f ["data" ] = { "diameter" : frame .diameter , "color" : frame .color }
207-
216+
208217 elif frame .style == "axis" :
209218 f ["data" ] = { "length" : frame .length , "width" : frame .width , "color" : frame .color }
210219
@@ -258,17 +267,77 @@ def update_file_format(self, frame):
258267 # Do nothing if conversion not needed
259268 pass
260269
270+ def run (self ):
271+ print "> Going for some spins"
272+ rate = rospy .Rate (200 ) # hz
273+ while not rospy .is_shutdown ():
274+ self .broadcast ()
275+ rate .sleep ()
276+
277+ def parse_args (self , argv ):
278+ ## Args ##
279+ ##
280+ # Process standalone plugin command-line arguments
281+ from argparse import ArgumentParser
282+ parser = ArgumentParser ()
283+ # Add argument(s) to the parser.
284+ parser .add_argument ("-q" , "--quiet" , action = "store_true" ,
285+ dest = "quiet" ,
286+ help = "Put plugin in silent mode" )
287+ parser .add_argument ("-l" , "--load" , action = "append" ,
288+ dest = "file" ,
289+ help = "Load a file at startup. [rospack filepath/file]" )
290+
291+ args , unknowns = parser .parse_known_args (argv )
292+ if not args .quiet :
293+ print 'arguments: ' , args
294+ print 'unknowns: ' , unknowns
295+
296+ ## Load file ##
297+ ##
298+ if args .file :
299+ arg_path = args .file [0 ].split ()
300+ if len (arg_path ) == 1 :
301+ #load file
302+ filename = arg_path [0 ]
303+ print "Loading" , filename
304+ success = self .load_file (str (filename ))
305+ elif len (arg_path ) == 2 :
306+ #load rospack
307+ rospack = rospkg .RosPack ()
308+ filename = os .path .join (rospack .get_path (arg_path [0 ]), arg_path [1 ])
309+ print "Loading" , filename
310+ success = self .load_file (str (filename ))
311+ else :
312+ print "Load argument not understood! --load" , arg_path
313+ print "Please use --load 'myRosPackage pathInMyPackage/myYaml.yaml'"
314+ print "or use --load 'fullPathToMyYaml.yaml'"
315+ success = None
316+
317+ if success :
318+ return filename
319+ elif success == False :
320+ print "ERROR LOADING FILE"
321+ return ''
322+
323+ def init_views (self ):
324+ ## Views
325+ self .interface_tf = FrameEditor_TF (self )
326+ self .interactive = FrameEditor_InteractiveMarker (self )
327+ self .services = FrameEditor_Services (self )
328+ self .interface_markers = FrameEditor_Markers (self )
329+
261330if __name__ == "__main__" :
262331
263332 rospy .init_node ('frame_editor' )
264333
265334 editor = FrameEditor ()
266- editor .load_params (rospy .get_name ())
335+ # editor.load_params(rospy.get_name())
336+
337+ editor .parse_args (sys .argv [1 :])
338+ editor .init_views ()
267339
268340 print "Frame editor ready!"
269- rate = rospy .Rate (100 ) # hz
270- while not rospy .is_shutdown ():
271- editor .broadcast ()
272- rate .sleep ()
341+ editor .run ()
273342
274343# eof
0 commit comments