Commits

German Larrain  committed bf75c4a

graphics.adapters.VtkBody set_color and get_color were modified to deal with assemblies (collection of objects)

  • Participants
  • Parent commits ffa7173

Comments (0)

Files changed (1)

File ars/graphics/adapters.py

 	adapter = VtkAdapter
 	
 	def get_color(self):
-		self._color = self._actor.GetProperty().GetColor() 
+		"""
+		Returns the color of the body. If it is an assembly, 
+		it is not checked whether all the objects' colors are equal.
+		"""
+		
+		# dealing with vtkAssembly properties is more complex
+		if isinstance(self._actor, vtk.vtkAssembly):
+			props_3D = self._actor.GetParts()
+			props_3D.InitTraversal()
+			actor_ = props_3D.GetNextProp3D()
+			while not actor_ == None:
+				self._color = actor_.GetProperty().GetColor()
+				actor_ = props_3D.GetNextProp3D()
+		else: 
+			self._color = self._actor.GetProperty().GetColor() 
 		return self._color
 	
 	def set_color(self, color):
-		self._actor.GetProperty().SetColor(color)
+		"""
+		Sets the color of the body. If it is an assembly, 
+		all the objects' color is set.
+		"""
+		
+		# dealing with vtkAssembly properties is more complex
+		if isinstance(self._actor, vtk.vtkAssembly):
+			props_3D = self._actor.GetParts()
+			props_3D.InitTraversal()
+			actor_ = props_3D.GetNextProp3D()
+			while not actor_ == None:
+				actor_.GetProperty().SetColor(color)
+				actor_ = props_3D.GetNextProp3D()
+		else: 
+			self._actor.GetProperty().SetColor(color)
 		self._color = color
 
 class Axes(VtkBody, gp.Axes):