def restoreAnnotations(self, settings):
		"""
		restore annotations from cache
		"""
		annotations = AnnotationSettings.getInstance().getAnnotations()
		keys = annotations.keys()

		for key in keys:
			annotation = annotations[key]
			name, pen, text = annotation.getName(), annotation.GetPen(), annotation.GetTextColour()
			annotation.SetEventHandler(annotation)
			self.addNewShape(annotation, noUpdate = 1)
			annotation.SetCanvas(self)
			annotation.setName(name)
			annotation.SetPen(pen)
			annotation.SetTextColour(text)
			AnnotationSettings.getInstance().updateAnnotation(annotation, annotation)

		self.setOffset(self.xoffset, self.yoffset)
		self.updateAnnotations()

		self.diagram.ShowAll(1)
		self.repaintHelpers()

		self.Refresh()
	def deleteAnnotation(self, ctrl = False):
		"""
		Delete annotations on the scene
		"""
		shapeList = self.diagram.GetShapeList()
		for shape in shapeList:
			if shape.Selected():
				if shape.parent != None:
					parent = shape.parent
					if not ctrl:
						annotations = parent.GetAnnotations()
						for annotation in annotations:
							self.RemoveShape(annotation)
					parent.RemoveAnnotation(shape)
					self.RemoveShape(shape)
					shape.Delete()
					if not ctrl:
						del parent
				else:
					self.RemoveShape(shape)
					shape.Delete()

				AnnotationSettings.getInstance().removeAnnotation(shape)
				self.saveAnnotations()
				self.paintPreview()
				self.Refresh()
	def saveAnnotations(self):
		"""
		Save the annotations to the settings
		"""
		annotations = self.diagram.GetShapeList()

		annotations = filter(lambda x:isinstance(x, GUI.OGLAnnotations.OGLAnnotation), annotations)
		annotations = filter(lambda x:not isinstance(x, GUI.OGLAnnotations.MyPolygonSketch), annotations)

		if self.dataUnit:
			for annotation in annotations:
				AnnotationSettings.getInstance().addAnnotation(annotation)
	def setAnnotationColor(self, evt):
		"""
		Changes the annotation color of the selected annotation(s)
		"""
		annotations = AnnotationSettings.getInstance().getAnnotations()
		keys = annotations.keys()
		for key in keys:
			if annotations[key].Selected():
				annotation = annotations[key]
				color = evt.GetValue()
				annotation.SetPen(wx.Pen(color, 1))
				annotation.SetTextColour(annotation.getName())
				AnnotationSettings.getInstance().updateAnnotation(annotation, annotation)
		lib.messenger.send(None, "update_helpers", 1)
コード例 #5
0
    def setAnnotationColor(self, evt):
        """
		Changes the annotation color of the selected annotation(s)
		"""
        annotations = AnnotationSettings.getInstance().getAnnotations()
        keys = annotations.keys()
        for key in keys:
            if annotations[key].Selected():
                annotation = annotations[key]
                color = evt.GetValue()
                annotation.SetPen(wx.Pen(color, 1))
                annotation.SetTextColour(annotation.getName())
                AnnotationSettings.getInstance().updateAnnotation(
                    annotation, annotation)
        lib.messenger.send(None, "update_helpers", 1)
	def addNewShape(self, shape, noUpdate = 0):
		"""
		Add a new shape to the canvas
		"""
		evthandler = GUI.OGLAnnotations.MyEvtHandler(self)
		evthandler.SetShape(shape)
		evthandler.SetPreviousHandler(shape.GetEventHandler())
		shape.SetEventHandler(evthandler)
		shape.SetDraggable(True, True)
		shape.SetCanvas(self)
		shape.SetBrush(wx.TRANSPARENT_BRUSH)
		shape.SetPen(wx.Pen(self.annotationColor, 1))

		# Change color for annotation name
		# Unfortunately needs to be done in this not so handy way
		AnnotationSettings.getInstance().addColor(shape.getName(), self.annotationColor)
		shape.SetTextColour(shape.getName())
		
		self.AddShape( shape )
		
		if not noUpdate:
			self.diagram.ShowAll(1)
			self.repaintHelpers()
			self.Refresh()		  
	def onMouseMotion(self, event):
		"""
		Update the mouse position and the rendering according to user action,
					 e.g. draw a rubber band when zooming to selected region
		"""
		if not event.Dragging():
			self.scrollPos = None
			self.zoomDragPos = None
		if (event.LeftIsDown() or event.MiddleIsDown()) and event.Dragging():
			# Here we check if we want to prevent scrolling, because
			# we might only want to move an annotation. The key
			# is to select an annotation, and then drag it.
			# The preventScrolling variable is updated in OGLAnnotations'
			# onDragLeft.
			annotations = AnnotationSettings.getInstance().getAnnotations()
			keys = annotations.keys()
			annotationSelected = False
			for key in keys:
				if annotations[key].Selected():
					annotationSelected = True
					break
			if not self.preventScrolling and not annotationSelected and self.scrollPos and self.action != ZOOM_TO_BAND and self.action != ADD_ANNOTATION and self.action != ADD_ROI:
				self.changeScrollByDifference(self.scrollPos, event.GetPosition())
			self.scrollPos = event.GetPosition()
		if event.RightIsDown():
			yPos = event.GetPosition()[1]
			if self.zoomDragPos:
				dy = yPos - self.zoomDragPos
				f = self.getZoomFactor()
				if dy > 0:
					f-=0.1
				elif dy < 0:
					f+=0.1
				scripting.visualizer.setZoomFactor(f)
				scripting.visualizer.Render()
			if event.Dragging():
				self.zoomDragPos = yPos
			
		if event.LeftIsDown():
			self.actionend = event.GetPosition()
			if self.action == ZOOM_TO_BAND or self.action == ADD_ANNOTATION or self.action == ADD_ROI:
				self.paintPreview()
				self.Refresh()
				
		pos = event.GetPosition()

		if self.currentSketch:
			self.actionend = pos
			x0, y0, w, h = self.GetClientRect()
			
			self.currentSketch.setTentativePoint((pos))
			dc = wx.ClientDC(self)
			self.PrepareDC(dc)
			
			self.paintPreview()
			self.Refresh()
			 
			self.currentSketch.Draw(dc)
			
			dc.EndDrawing()
		event.Skip()