WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-28-2013, 08:59 AM
mshukun mshukun is offline
Member
 
Join Date: Jan 2013
Posts: 32
Event handling

I am having a problem regarding event handling, and I haven't yet been able to figure out the cause of the problem. Any assistance you could provide in this regard would be greatly appreciated.

I created a PlaceMarkerEvt class to handle mouse click events, which allows users to create three points in a given map environment (and a fourth click removes all created points). The application allows users to change the map environment by typing on the keyboard, and each map environment utilizes the PlaceMarkerEvt class. The problem is that the PlaceMarkerEvt class works without flawlessly in the initial map environment; however, when the map environment is changed, it no longer works the way it is supposed to work.

Output:
# Initial map environment
1: [-21.214298248291016, 13.693742752075195, 96.99993896484375, '2013-03-28 10:59:15.947000']
2: [27.049070358276367, -7.507974147796631, 95.81939697265625, '2013-03-28 10:59:16.397000']
3: [-22.711130142211914, -32.831119537353516, 91.01387786865234, '2013-03-28 10:59:16.847000']
4: Remove points
removeShapes() - POINTS REMOVED

# Map environment is changed -- duplicates coordinates recordings and does not remove points
1: [-31.70626449584961, 2.459872245788574, 94.83840942382812, '2013-03-28 10:59:20.997000']
1: [-31.70626449584961, 2.459872245788574, 94.83840942382812, '2013-03-28 10:59:20.998000']
2: [7.19222354888916, -4.607730865478516, 99.53379821777344, '2013-03-28 10:59:21.381000']
2: [7.19222354888916, -4.607730865478516, 99.53379821777344, '2013-03-28 10:59:21.382000']
3: [-2.733815908432007, -18.645051956176758, 97.84542846679688, '2013-03-28 10:59:21.814000']
3: [-2.733815908432007, -18.645051956176758, 97.84542846679688, '2013-03-28 10:59:21.815000']
4: Remove points
removeShapes() - POINTS REMOVED
4: Remove points
removeShapes() - POINTS REMOVED

Code:
import viz
import vizmat
import vizshape
import datetime


class PlaceMarkerEvt(viz.EventClass):
	
	def __init__(self,locMarker):
		
		viz.EventClass.__init__(self)
		
		self.count = 1  # Mouse click count
		
		self.callback(viz.MOUSEDOWN_EVENT, self.placeMarker)
		
		self.locMarker = locMarker
		
	def placeMarker(self, w):
		
		global shape1, shape2, shape3
		
		if self.count < 4:
			
			line = viz.MainWindow.screenToWorld(viz.mouse.getPosition())
			pos = vizmat.MoveAlongVector(line.begin,line.dir,100)
						
			coor = [] # Create list for xyz coordinate
			
			if self.count == 1:  # First mouse click
				shape1 = vizshape.addCircle()
				shape1.color(viz.RED)
				shape1.billboard()
				shape1.setPosition(pos)
				coor = shape1.getPosition()
				coor.append(str(datetime.datetime.now()))
								
			elif self.count == 2: #Second mouse click
				shape2 = vizshape.addCircle()
				shape2.color(viz.GREEN)
				shape2.billboard()
				shape2.setPosition(pos)
				coor = shape2.getPosition()
				coor.append(str(datetime.datetime.now()))
								
			elif self.count ==3: #Third mouse click
				shape3 = vizshape.addCircle()
				shape3.color(viz.BLUE)
				shape3.billboard()
				shape3.setPosition(pos)
				coor = shape3.getPosition()
				coor.append(str(datetime.datetime.now()))
								
			print str(self.count) + ": " + str (coor)
			
			self.count += 1 # Update count
			
		else: # Fourth mouse click
			print str(self.count) + ": Remove points"
			self.removeShapes()
	
	def removeShapes(self):
		shape1.remove()
		shape2.remove()
		shape3.remove()
		print "removeShapes() - POINTS REMOVED"
		# Reset count
		self.count = 1
		
if __name__ == '__main__':	
	
	viz.setMultiSample(4)
	viz.fov(60)
	viz.go()
	
	mapEnvList = []
	gDome = 0
	
	mapEnvList.append(viz.add(viz.ENVIRONMENT_MAP,'gpo_L.jpg'))
	mapEnvList.append(viz.add(viz.ENVIRONMENT_MAP,'th_L.jpg'))
	
	def selectEnvironment(index):
		
		if index in [1, 2]:
			gDome.texture(mapEnvList[index-1])
			env = mapEnvList[index-1]
		PlaceMarkerEvt(env)
	
	gDome = viz.add('skydome.dlc',0,'',0,0,0,0,viz.WORLD)
	
	vizact.onkeydown('1', selectEnvironment, 1)
	vizact.onkeydown('2', selectEnvironment, 2)
	
	selectEnvironment(1)
	
	viz.link( viz.Mouse , viz.addTexQuad(viz.SCREEN,texture=viz.add('crosshair.png')) )
	viz.mouse.setVisible(viz.OFF)

	import vizcam
	vizcam.PanoramaNavigate()
Reply With Quote
  #2  
Old 03-29-2013, 12:01 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
It's not exactly clear to me what the issue is. However, I noticed that you are creating a new instance of PlaceMarkerEvt when the environment is changed, but you are not removing the previous instance. This might be the cause of your problems.
Reply With Quote
  #3  
Old 04-01-2013, 09:22 AM
mshukun mshukun is offline
Member
 
Join Date: Jan 2013
Posts: 32
Thank you so much! I was able to fix the problem by deleting instance of PlaceMarkerEvt.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse event: how to detect no mouse move event, how to set mouse position? Zhi Vizard 3 04-11-2011 06:25 PM
how to cancel event? shahramy Vizard 1 12-20-2010 08:52 AM
Distance or position based event? vissimutah Vizard 1 08-25-2009 12:26 PM
event detection and handling Chandan Vizard 1 10-13-2006 04:01 PM
sending event markers to a monitoring computer mikestatic Vizard 3 01-26-2006 09:23 AM


All times are GMT -7. The time now is 12:52 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC