WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Event handling (https://forum.worldviz.com/showthread.php?t=4535)

mshukun 03-28-2013 08:59 AM

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()


farshizzo 03-29-2013 12:01 PM

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.

mshukun 04-01-2013 09:22 AM

Thank you so much! I was able to fix the problem by deleting instance of PlaceMarkerEvt.


All times are GMT -7. The time now is 07:54 PM.

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