OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

osgswig and wxPython


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
R Fritz
Guest





PostPosted: Mon Dec 01, 2008 4:40 am    Post subject:
osgswig and wxPython
Reply with quote

I've the beginnings of a simple light-fixture modeling component in
wxPython and I am trying to use osgswig (2.2.0.1 version) as a base.
I've started out by copying the file loading example which uses
osgUtil.SceneView(). The code successfully loads the geometry of a
lighting fixture (considering that this is done with readNodeFile
that's not terribly surprising). Unfortunately, thereafter I can't
maneuver the view with the mouse. Sometimes, I can't even find the
fixture model. I suspect I'm doing something dumb. My code--almost
the sample code--is attached--any ideas? (Getting a newer version of
osgswig would be nice, but as I've written here, I've run into build
problems, and I would rather not spend the time chasing them down.)

Randolph

#!/usr/bin/env python

# import wxWidgets stuff
import wx
import wx.glcanvas

# import OpenSceneGraph wrapper
import osg
import osgUtil
import osgDB

class OSGLumView(wx.glcanvas.GLCanvas):
def __init__(self,parent,id):
wx.glcanvas.GLCanvas.__init__(self,parent,id)
sv = self.sceneview = osgUtil.SceneView()
self.rootnode = osg.MatrixTransformRef(osg.MatrixTransform())
sv.setSceneData(self.rootnode.get())

x,y = self.GetClientSize()

self.oldX = 0
self.oldY = 0

sv.setDefaults()

self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)

sv.init()


def AddGeom(self, geom):
print "AddGeom"
self.rootnode.addChild(geom)
# self.Refresh(False)


def OnMouse(self, evt):
if ((evt.Dragging() == True) and (evt.LeftIsDown() == True)):
x = evt.GetX() - self.oldY
y = evt.GetY() - self.oldY

self.sceneview.setViewMatrixAsLookAt(
osg.Vec3f(0,y,x), osg.Vec3f(0,0,0), osg.Vec3f(0,1,0))

# self.Refresh(False)

self.oldX = evt.GetX()
self.oldY = evt.GetY()


if ((evt.Dragging() == True) and (evt.RightIsDown() == True)) :
m = self.rootnode.getMatrix()

x,y = self.GetClientSize()

rot = osg.Matrixd()

rot.makeRotate(self.oldX - evt.GetX(), osg.Vec3f(1,0,0))

m.postMult(rot)

# self.Refresh(False)

self.oldX = evt.GetX()
self.oldY = evt.GetY()

def Clear(self):
self.rootnode.removeChild(0,self.rootnode.getNumChildren())
# self.Refresh(False)


def OnEnterWindow(self, evt):
self.SetFocus()

def OnEraseBackground(self, evt):
pass

def OnSize(self, evt):
x,y = self.GetClientSize()
self.SetCurrent()
self.sceneview.setViewport(0,0,x,y)
evt.Skip()


def OnPaint(self, evt):

if (0 == self.GetContext()) :
return

dc = wx.PaintDC(self)
self.SetCurrent()
self.sceneview.update()
self.sceneview.cull()
self.sceneview.draw()
self.SwapBuffers()


------------------
Post generated by Mail2Forum
Back to top
Hartmut Seichter
Guest





PostPosted: Mon Dec 01, 2008 8:25 am    Post subject:
osgswig and wxPython
Reply with quote

Its hard to guess as you don't provide the whole example - all
self.Refresh are commented out and its not clear if you use the wxApp
OnIdle message pump for updates. The other example (osgviewerWX.py) in
the repository might give you some pointers.

H


R Fritz wrote:
Quote:
I've the beginnings of a simple light-fixture modeling component in
wxPython and I am trying to use osgswig (2.2.0.1 version) as a base.
I've started out by copying the file loading example which uses
osgUtil.SceneView(). The code successfully loads the geometry of a
lighting fixture (considering that this is done with readNodeFile
that's not terribly surprising). Unfortunately, thereafter I can't
maneuver the view with the mouse. Sometimes, I can't even find the
fixture model. I suspect I'm doing something dumb. My code--almost
the sample code--is attached--any ideas? (Getting a newer version of
osgswig would be nice, but as I've written here, I've run into build
problems, and I would rather not spend the time chasing them down.)

Randolph

#!/usr/bin/env python

# import wxWidgets stuff
import wx
import wx.glcanvas

# import OpenSceneGraph wrapper
import osg
import osgUtil
import osgDB

class OSGLumView(wx.glcanvas.GLCanvas):
def __init__(self,parent,id):
wx.glcanvas.GLCanvas.__init__(self,parent,id)
sv = self.sceneview = osgUtil.SceneView()
self.rootnode = osg.MatrixTransformRef(osg.MatrixTransform())
sv.setSceneData(self.rootnode.get())

x,y = self.GetClientSize()

self.oldX = 0
self.oldY = 0

sv.setDefaults()

self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)

sv.init()


def AddGeom(self, geom):
print "AddGeom"
self.rootnode.addChild(geom)
# self.Refresh(False)


def OnMouse(self, evt):
if ((evt.Dragging() == True) and (evt.LeftIsDown() == True)):
x = evt.GetX() - self.oldY
y = evt.GetY() - self.oldY

self.sceneview.setViewMatrixAsLookAt(
osg.Vec3f(0,y,x), osg.Vec3f(0,0,0), osg.Vec3f(0,1,0))

# self.Refresh(False)

self.oldX = evt.GetX()
self.oldY = evt.GetY()


if ((evt.Dragging() == True) and (evt.RightIsDown() == True)) :
m = self.rootnode.getMatrix()

x,y = self.GetClientSize()

rot = osg.Matrixd()

rot.makeRotate(self.oldX - evt.GetX(), osg.Vec3f(1,0,0))

m.postMult(rot)

# self.Refresh(False)

self.oldX = evt.GetX()
self.oldY = evt.GetY()

def Clear(self):
self.rootnode.removeChild(0,self.rootnode.getNumChildren())
# self.Refresh(False)


def OnEnterWindow(self, evt):
self.SetFocus()

def OnEraseBackground(self, evt):
pass

def OnSize(self, evt):
x,y = self.GetClientSize()
self.SetCurrent()
self.sceneview.setViewport(0,0,x,y)
evt.Skip()


def OnPaint(self, evt):

if (0 == self.GetContext()) :
return

dc = wx.PaintDC(self)
self.SetCurrent()
self.sceneview.update()
self.sceneview.cull()
self.sceneview.draw()
self.SwapBuffers()



--
Hartmut Seichter, PhD (HKU), Dipl-Ing.(BUW), Postdoctoral Fellow, HITLabNZ



------------------
Post generated by Mail2Forum
Back to top
Randolph Fritz
Guest





PostPosted: Tue Dec 02, 2008 2:19 am    Post subject:
osgswig and wxPython
Reply with quote

Thank you. After some experimentation, I discovered I was looking at a
combination of minor coding errors and an IDLE interaction--if I start
the script outside of IDLE, it now works. If you are at all interested,
I've attached my experimental scripts. Beginner question: what are you
using as a debugging enviroment?

Randolph

Hartmut Seichter wrote:
Quote:
Its hard to guess as you don't provide the whole example - all
self.Refresh are commented out and its not clear if you use the wxApp
OnIdle message pump for updates. The other example (osgviewerWX.py) in
the repository might give you some pointers.


# -*- coding: us-ascii -*-
# generated by wxGlade 0.6.3 on Sun Nov 16 18:44:07 2008

import wx
import OSGLumView

# begin wxGlade: dependencies
# end wxGlade

# begin wxGlade: extracode

# end wxGlade

class LumViewer(wx.Panel):
def __init__(self, *args, **kwds):
# begin wxGlade: LumViewer.__init__
kwds["style"] = wx.TAB_TRAVERSAL
wx.Panel.__init__(self, *args, **kwds)
self.viewer = OSGLumView.OSGLumView(self, -1)

self.__set_properties()
self.__do_layout()
# end wxGlade
self.Parent.storeCanvas(self.viewer)

def __set_properties(self):
# begin wxGlade: LumViewer.__set_properties
pass
# end wxGlade

def __do_layout(self):
# begin wxGlade: LumViewer.__do_layout
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_2.Add(self.viewer, 1, wx.EXPAND, 0)
self.SetSizer(sizer_2)
sizer_2.Fit(self)
# end wxGlade

def AddGeom(self,geom):
self.viewer.AddGeom(geom)

# end of class LumViewer

import osgDB
class testFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title = "OSG Test Frame")

self.canvas = None
self.Bind(wx.EVT_IDLE, self.onIdle)

self.lum_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_OPEN, "Open...", "Ctrl+O", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_EXIT, "Exit", "", wx.ITEM_NORMAL)
self.lum_menubar.Append(wxglade_tmp_menu, "File")
self.SetMenuBar(self.lum_menubar)

self.Bind(wx.EVT_MENU, self.onFileOpen, id=wx.ID_OPEN)
self.Bind(wx.EVT_MENU, self.onFileExit, id=wx.ID_EXIT)

self.lumviewer = LumViewer(self)

def onFileExit(self, event): # wxGlade: LumEdit.<event_handler>
self.Close()

def onFileOpen(self, event): # wxGlade: LumEdit.<event_handler>
dlg = wx.FileDialog(
self, style = wx.FD_OPEN,
message = "Model File")
if dlg.ShowModal() == wx.ID_OK:
try:
fn = dlg.GetPath().encode('ascii', 'replace')
geom = osgDB.readNodeFile(fn)
self.lumviewer.AddGeom(geom)
except ValueError:
pass # Handle the can't read error here
dlg.Destroy()

def onIdle(self,event):
if self.canvas:
self.canvas.Refresh(eraseBackground = False)

def storeCanvas(self,c):
self.canvas = c

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = testFrame(None)
frame.Show(True)
app.MainLoop()

#!/usr/bin/env python

# import wxWidgets stuff
import wx
import wx.glcanvas

# import OpenSceneGraph wrapper
import osg
import osgUtil
import osgDB

class OSGLumView(wx.glcanvas.GLCanvas):
def __init__(self,parent,id):
wx.glcanvas.GLCanvas.__init__(self,parent,id)
sv = self.sceneview = osgUtil.SceneView()
self.rootnode = osg.MatrixTransformRef(osg.MatrixTransform())
sv.setSceneData(self.rootnode.get())

x,y = self.GetClientSize()

self.oldX = 0
self.oldY = 0

sv.setDefaults()

self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)

sv.init()


def AddGeom(self, geom):
self.rootnode.addChild(geom)
# Calculate bounds & set the view matrix
self.Refresh(eraseBackground = False)


def OnMouse(self, evt):
if ((evt.Dragging() == True) and (evt.LeftIsDown() == True)):
x = evt.GetX() - self.oldY
y = evt.GetY() - self.oldY

self.sceneview.setViewMatrixAsLookAt(
osg.Vec3f(0,y,x), osg.Vec3f(0,0,0), osg.Vec3f(0,1,0))

self.Refresh(eraseBackground = False)

self.oldX = evt.GetX()
self.oldY = evt.GetY()


if ((evt.Dragging() == True) and (evt.RightIsDown() == True)) :
m = self.rootnode.getMatrix()

x,y = self.GetClientSize()

rot = osg.Matrixd()

rot.makeRotate(self.oldX - evt.GetX(), osg.Vec3f(1,0,0))

m.postMult(rot)

self.Refresh(False)

self.oldX = evt.GetX()
self.oldY = evt.GetY()

def Clear(self):
self.rootnode.removeChild(0,self.rootnode.getNumChildren())
self.Refresh(eraseBackground = False)


def OnEnterWindow(self, evt):
self.SetFocus()

def OnEraseBackground(self, evt):
pass

def OnSize(self, evt):
x,y = self.GetClientSize()
self.SetCurrent()
self.sceneview.setViewport(0,0,x,y)
evt.Skip()


def OnPaint(self, evt):

if (0 == self.GetContext()) :
return

dc = wx.PaintDC(self)
self.SetCurrent()
self.sceneview.update()
self.sceneview.cull()
self.sceneview.draw()
self.SwapBuffers()





------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Happy New Year to all OSG Users Chris Hanson General 0 Mon Jan 07, 2019 10:17 am View latest post
No new posts osg-users Digest, Vol 138, Issue 27 Zachary1234 General 0 Tue Jan 01, 2019 1:16 am View latest post
No new posts osg-users Digest, Vol 137, Issue 14 poweruserm@live.com.au General 0 Fri Nov 16, 2018 11:16 pm View latest post
No new posts General Users starting questions in O... A Z General 1 Mon Oct 15, 2018 3:59 am View latest post
No new posts osg-users Digest, Vol 136, Issue 8 jonasydy General 0 Wed Oct 10, 2018 12:40 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP