From: <sv...@ww...> - 2008-02-26 19:41:22
|
Author: nsmoooose Date: 2008-02-26 11:41:06 -0800 (Tue, 26 Feb 2008) New Revision: 2221 Added: trunk/csp/tools/layout2/scripts/document/SceneDocument.py Modified: trunk/csp/tools/layout2/cpp/OsgGraphicsWindow.cpp trunk/csp/tools/layout2/scripts/document/DocumentRegistry.py trunk/csp/tools/layout2/scripts/ui/ControlIdGenerator.pyc trunk/csp/tools/layout2/scripts/ui/MainFrame.py trunk/csp/tools/layout2/scripts/ui/commands/OpenCustomLayoutModelFileCommand.py trunk/csp/tools/layout2/scripts/ui/controls/SceneWindow.py Log: It is now possible to start the layout2 editor from linux without a crasch. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=2221 Modified: trunk/csp/tools/layout2/cpp/OsgGraphicsWindow.cpp =================================================================== --- trunk/csp/tools/layout2/cpp/OsgGraphicsWindow.cpp 2008-02-20 18:26:56 UTC (rev 2220) +++ trunk/csp/tools/layout2/cpp/OsgGraphicsWindow.cpp 2008-02-26 19:41:06 UTC (rev 2221) @@ -18,6 +18,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US +#include <iostream> #include <strstream> #include <osgViewer/ViewerEventHandlers> #include <osgGA/TrackballManipulator> @@ -32,6 +33,7 @@ Ref<Scene> m_Scene; void init(OsgGraphicsWindow* window, Scene* scene) { + m_Window = window; m_Scene = scene; @@ -43,7 +45,7 @@ setState( new osg::State ); getState()->setGraphicsContext(this); - + if (_traits.valid() && _traits->sharedContext) { getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); @@ -161,6 +163,7 @@ stream << " Distance: " << manipulator->getDistance(); stream << " Rotation: " << rotation._v[0] << ", " << rotation._v[1] << ", " << rotation._v[2] << ", " << rotation._v[3]; stream << std::ends; + return stream.str(); } @@ -172,4 +175,4 @@ csp::layout::FeatureGraph* csp::layout::OsgGraphicsWindow::graph() { return m_Implementation->m_Scene->graph(); -} \ No newline at end of file +} Modified: trunk/csp/tools/layout2/scripts/document/DocumentRegistry.py =================================================================== --- trunk/csp/tools/layout2/scripts/document/DocumentRegistry.py 2008-02-20 18:26:56 UTC (rev 2220) +++ trunk/csp/tools/layout2/scripts/document/DocumentRegistry.py 2008-02-26 19:41:06 UTC (rev 2221) @@ -1,3 +1,4 @@ +from csp.base.signals import Signal class DocumentRegistry: """This class represents all opened documents. It can be @@ -6,9 +7,14 @@ def __init__(self): self.documents = [] + self.documentAddedSignal = Signal() + def GetDocumentAddedSignal(self): + return self.documentAddedSignal + def Add(self, document): self.documents.append(document) + self.documentAddedSignal.Emit(document) def GetByName(self, name): for document in self.documents: Added: trunk/csp/tools/layout2/scripts/document/SceneDocument.py =================================================================== --- trunk/csp/tools/layout2/scripts/document/SceneDocument.py (rev 0) +++ trunk/csp/tools/layout2/scripts/document/SceneDocument.py 2008-02-26 19:41:06 UTC (rev 2221) @@ -0,0 +1,19 @@ +from Document import Document + +class SceneDocument(Document): + """This document represents a scene of 3D objects.""" + + def __init__(self, name): + Document.__init__(self, name) + self.node = None + + def SetRootNode(self, node): + self.node = node + self.GetChangedSignal().Emit(self) + + def GetRootNode(self): + return self.node + + def Clear(self): + self.node = None + self.GetChangedSignal().Emit(self) Modified: trunk/csp/tools/layout2/scripts/ui/ControlIdGenerator.pyc =================================================================== (Binary files differ) Modified: trunk/csp/tools/layout2/scripts/ui/MainFrame.py =================================================================== --- trunk/csp/tools/layout2/scripts/ui/MainFrame.py 2008-02-20 18:26:56 UTC (rev 2220) +++ trunk/csp/tools/layout2/scripts/ui/MainFrame.py 2008-02-26 19:41:06 UTC (rev 2221) @@ -2,6 +2,8 @@ import wx import wx.richtext +from csp.tools.layout2.scripts.document.SceneDocument import SceneDocument + from ControlIdGenerator import ControlIdGenerator from CommandControlFactory import CommandControlFactory from controls.OutputWindow import OutputWindow @@ -28,7 +30,9 @@ # configuration object. application = wx.GetApp() - + documentRegistry = application.GetDocumentRegistry() + documentRegistry.GetDocumentAddedSignal().Connect(self.documentAdded_Signal) + # Create a control id generator. This is used by all helper classes # to actualy define an unique id for each control (menu, toolbar button) # etc. @@ -65,11 +69,11 @@ # To the left we have a project, properties and that type # of controls. To the right we have all opened documents. # And at the bottom we have the output panel. - splitter1 = wx.SplitterWindow(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_NOBORDER) - propertyNotebook = wx.Notebook(splitter1, wx.ID_ANY, style=wx.NB_LEFT) - splitter2 = wx.SplitterWindow(splitter1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_NOBORDER) - outputNotebook = wx.Notebook(splitter2, wx.ID_ANY) - documentNotebook = wx.Notebook(splitter2, wx.ID_ANY) + splitter1 = wx.SplitterWindow(self, wx.ID_ANY) + propertyNotebook = wx.Notebook(splitter1, wx.ID_ANY, style=wx.NB_TOP) + splitter2 = wx.SplitterWindow(splitter1, wx.ID_ANY) + outputNotebook = wx.Notebook(splitter2, wx.ID_ANY, style=wx.NB_TOP) + documentNotebook = wx.Notebook(splitter2, wx.ID_ANY, style=wx.NB_TOP) splitter1.SplitVertically(propertyNotebook, splitter2, 200) splitter2.SetSashGravity(1.0) splitter2.SplitHorizontally(documentNotebook, outputNotebook, -100) @@ -86,12 +90,6 @@ startPage.SetEditable(False) documentNotebook.AddPage(startPage, "Start") - # Add the scene control that is responsible for the 3D - # scene. - scenePage = SceneWindow(documentNotebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.BORDER_NONE, "GLCanvas", 0, wx.NullPalette) - documentNotebook.AddPage(scenePage, "Scene") - self.scene = scenePage - # Display the tree control with all files in this project. Also # register this instance so all command object can use it to # access the selected file or directory. @@ -101,15 +99,28 @@ ProjectTree.Instance = projectTreePage propertyNotebook.AddPage(projectTreePage, "Project") + + # Store some variables for later use + self.documentNotebook = documentNotebook + self.scene = None # Connect idle event. wx.EVT_IDLE(self, self.on_Idle) def on_Idle(self, event): # Only render when the scene is visible on screen. - if self.scene.IsShownOnScreen(): + if self.scene is not None and self.scene.IsShownOnScreen(): self.scene.Frame() event.RequestMore() + + def documentAdded_Signal(self, document): + # Add the scene control that is responsible for the 3D + # scene. + if isinstance(document, SceneDocument): + scenePage = SceneWindow(self.documentNotebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.BORDER_NONE, "GLCanvas", 0, wx.NullPalette) + scenePage.SetDocument(document) + self.documentNotebook.AddPage(scenePage, "Scene") + self.scene = scenePage def GetSceneWindow(self): return self.scene \ No newline at end of file Modified: trunk/csp/tools/layout2/scripts/ui/commands/OpenCustomLayoutModelFileCommand.py =================================================================== --- trunk/csp/tools/layout2/scripts/ui/commands/OpenCustomLayoutModelFileCommand.py 2008-02-20 18:26:56 UTC (rev 2220) +++ trunk/csp/tools/layout2/scripts/ui/commands/OpenCustomLayoutModelFileCommand.py 2008-02-26 19:41:06 UTC (rev 2221) @@ -2,6 +2,7 @@ import os.path import wx from csp.tools.layout2.scripts.data import DataTree +from csp.tools.layout2.scripts.document.SceneDocument import SceneDocument from FileCommand import FileCommand class OpenCustomLayoutModelFileCommand(FileCommand): @@ -63,11 +64,14 @@ self._node_map = node_map node = node_map.getRoot() assert(node is not None and node.isGroup()) + + # Create a document and add the root node to it. This will in + # turn signal the document added signal that is caught in the gui. + # This will create a 3D view. + document = SceneDocument('Scene') + document.SetRootNode(node) + application.GetDocumentRegistry().Add(document) - sceneWindow = topWindow.GetSceneWindow() - sceneWindow.graphicsWindow.graph().setRoot(node) - node.thisown = 0 - self.UpdateTree(node) return 1 Modified: trunk/csp/tools/layout2/scripts/ui/controls/SceneWindow.py =================================================================== --- trunk/csp/tools/layout2/scripts/ui/controls/SceneWindow.py 2008-02-20 18:26:56 UTC (rev 2220) +++ trunk/csp/tools/layout2/scripts/ui/controls/SceneWindow.py 2008-02-26 19:41:06 UTC (rev 2221) @@ -24,7 +24,10 @@ self.graphicsWindow.connectToSetCurrent(self.on_SetCurrent) self.graphicsWindow.connectToSwapBuffers(self.on_SwapBuffers) - + + def SetDocument(self, document): + self.graphicsWindow.graph().setRoot(document.GetRootNode()) + def MoveCameraToHome(self): self.graphicsWindow.moveCameraToHome() |