German Larrain avatar German Larrain committed c27fa08

app: no code changes, analogous to 640685d90cb2 and 842f6e6c5fc0.

Comments (0)

Files changed (1)

ars/app/__init__.py

+"""Main package of the software.
+It contains the Program class which is the core application controller.
 
-# Created on 2011.10.14
-#
-# @author: german
-
-"""
-Main package of the software.
-It contains the Program class which is the core application controller.
 """
 
 from abc import abstractmethod
 
 
 class Program():
-
 	"""
 	Main class of ARS.
 	To run a custom simulation a subclass has to be created.
 	To run this, only two statements are necessary:
 	-create an object of this class (i.e. sim_program = ProgramSubclass() )
 	-call its 'start' method (i.e. sim_program.start() )
+
 	"""
-
 	WRITE_DATA_FILES = False
 	DEBUG = False
 	PRINT_KEY_INFO = True
 
 	WINDOW_TITLE = "Autonomous Robot Simulator"
-	WINDOW_POSITION = (0,0)
-	WINDOW_SIZE = (1024,768) # (width,height)
+	WINDOW_POSITION = (0, 0)
+	WINDOW_SIZE = (1024, 768)  # (width,height)
 	WINDOW_ZOOM = 1.0
-	CAMERA_POSITION = (10,8,10)
+	CAMERA_POSITION = (10, 8, 10)
 
-	BACKGROUND_COLOR = (1,1,1)
+	BACKGROUND_COLOR = (1, 1, 1)
 
 	FPS = 50
 	STEPS_PER_FRAME = 50
 
-	FLOOR_BOX_SIZE = (10,0.01,10)
+	FLOOR_BOX_SIZE = (10, 0.01, 10)
 
 	def __init__(self):
 		"""
 		-create the visualization window according to the related Program's
 		class constants
 		-create the simulation
+
 		"""
 		self.do_create_window = True
-		self.data_files_names = None # TODO
-		self.data_files = None # TODO
+		self.data_files_names = None 	# TODO
+		self.data_files = None 			# TODO
 
 		self.key_press_functions = None
 		self.sim = None
 		self.set_key_2_action_mapping()
 
 		self.gAdapter = gp.VtkAdapter()
-		self.gAdapter.create_window(self.WINDOW_TITLE, self.WINDOW_POSITION, self.WINDOW_SIZE,
-							 zoom=self.WINDOW_ZOOM, background_color=self.BACKGROUND_COLOR,
-							 cam_position=self.CAMERA_POSITION)
+		self.gAdapter.create_window(self.WINDOW_TITLE,
+			self.WINDOW_POSITION,
+			self.WINDOW_SIZE,
+			zoom=self.WINDOW_ZOOM,
+			background_color=self.BACKGROUND_COLOR,
+			cam_position=self.CAMERA_POSITION)
 
 		self.create_simulation()
 
 		Starts (indirectly) the simulation handled by this class by starting
 		the visualization window. If it is closed, the simulation ends. It will
 		restart if the 'do_create_window' has been previously set to True.
+
 		"""
 
-		if self.WRITE_DATA_FILES: self.sim.data_files = self.open_files()
+		if self.WRITE_DATA_FILES:
+			self.sim.data_files = self.open_files()
 
 		while self.do_create_window:
 			self.do_create_window = False
-			self.gAdapter.start_window(self.sim.on_idle, self.reset_simulation, self.on_action_selection)
+			self.gAdapter.start_window(self.sim.on_idle, self.reset_simulation,
+				self.on_action_selection)
 
 		# after the window is closed
-		if self.WRITE_DATA_FILES: self.close_files(self.sim.data_files)
+		if self.WRITE_DATA_FILES:
+			self.close_files(self.sim.data_files)
 
 	def reset_simulation(self):
 		"""Resets the simulation by resetting the graphics adapter and creating
-		a new simulation"""
+		a new simulation
+
+		"""
 		if self.PRINT_KEY_INFO:
 			print("reset simulation")
 		self.do_create_window = True
 		subclasses
 		-gets the actors representing the simulation objects and adds them to
 		the graphics adapter
+
 		"""
 		# set up the simulation parameters
 		self.sim = Simulation(self.FPS, self.STEPS_PER_FRAME)
 		if add_axes:
 			self.sim.add_axes()
 		if add_floor:
-			self.sim.add_floor(normal=(0,1,0), box_size=self.FLOOR_BOX_SIZE,
-				color=(0.7,0.7,0.7))
+			self.sim.add_floor(normal=(0, 1, 0), box_size=self.FLOOR_BOX_SIZE,
+				color=(0.7, 0.7, 0.7))
 
 		self.create_sim_objects()
 
 		It shall contain statements calling its 'sim' attribute's methods for
 		adding objects (e.g. add_sphere). For example:
 		self.sim.add_sphere(0.5, (1,10,1), density=1)
+
 		"""
 		raise NotImplementedError()
 
 		"""
 		Creates an Action map, assigns it to the 'key_press_functions'
 		attribute and then adds some pairs of 'key' and 'function'.
+
 		"""
-		self.key_press_functions = ActionMap() # TODO: add to constructor = None?
+		# TODO: add to constructor ``self.key_press_functions = None``?
+		self.key_press_functions = ActionMap()
 		self.key_press_functions.add('plus', self.select_next_joint)
 		self.key_press_functions.add('minus', self.select_previous_joint)
 		self.key_press_functions.add('r', self.reset_simulation)
 		except Exception as ex:
 			print(ex)
 
-#===============================================================================
-# KEYPRESS action functions
-#===============================================================================
+	#==========================================================================
+	# KEYPRESS action functions
+	#==========================================================================
 
 	def select_next_joint(self):
 		"""select next joint for future user actions"""
 		"""decrement the position of an already selected joint"""
 		print('dec_joint_pos has not been implemented yet')
 
-
-#===============================================================================
-# FILES methods
-#===============================================================================
+	#==========================================================================
+	# FILES methods
+	#==========================================================================
 
 	def read_filenames(self):
 		print('read_filenames has not been implemented')
 		for _key in files:
 			files[_key].close()
 
-#===============================================================================
-# other
-#===============================================================================
+	#==========================================================================
+	# other
+	#==========================================================================
 
 	def on_pre_step(self):
 		"""
 		This method will be called before each integration step of the simulation.
 		It is meant to be, optionally, implemented by subclasses.
+
 		"""
 		raise NotImplementedError()
 
 		"""
 		This method will be called before each visualization frame is created.
 		It is meant to be, optionally, implemented by subclasses.
+
 		"""
 		raise NotImplementedError()
 
 		By default it will create an image each time 'record_frame' is called.
 		If 'periodically' is True then screenshots will be saved in sequence.
 		The time period between each frame is determined according to the FPS attribute
+
 		"""
-		self._screenshot_recorder = gp.ScreenshotRecorder(base_filename, self.gAdapter)
+		self._screenshot_recorder = gp.ScreenshotRecorder(base_filename,
+			self.gAdapter)
 		if periodically:
 			period = 1.0 / self.FPS
 			self._screenshot_recorder.period = period
 		time / period.
 		If frames are not meant to be written periodically, then index =
 		simulator's frame number.
+
 		"""
 		if self._screenshot_recorder is None:
 			raise exc.ArsError('Screenshot recorder is not initialized')
 		except Exception:
 			raise exc.ArsError('Could not record frame')
 
+
 class ActionMap:
 	def __init__(self):
 		self._map = {}
 
 	def add(self, key, value, repeat=False):
-		self._map[key] = (value,repeat)
+		self._map[key] = (value, repeat)
 
 	def has_key(self, key):
 		return self._map.has_key(key)
 	"""
 	customize the behavior, knowing which strings mean existing keys or not,
 	plus combinations (e.g. Ctrl+F1)
+
 	"""
-	pass
+	pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.