Ejemplo n.º 1
0
class PlugIn(SimplePlugIn):

    def load(self):
        import GraphicsWindow, Items
        self.GraphicsWindow = GraphicsWindow
        self.Items = Items
        xpm = QPixmap()
        xpm.loadFromData(self.getFile('graphicswin.xpm').read())
        winIcon = QIcon(xpm)
        self.winManager = SubWinManager(SimuVis4.Globals.mainWin.workSpace, self.GraphicsWindow.GraphicsWindow,
            QCoreApplication.translate('Graphics', "GraphicsView"), winIcon)
        testAction = QAction(winIcon,
            QCoreApplication.translate('Graphics', '&Graphics Test'), SimuVis4.Globals.mainWin)
        testAction.setStatusTip(QCoreApplication.translate('Graphics', 'Show a new graphics window'))
        QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
        SimuVis4.Globals.mainWin.plugInMenu.addAction(testAction)
        return True


    def unload(self, fast):
        if self.winManager:
            self.winManager.shutdown()
            del self.winManager


    def test(self):
        if not self.winManager:
            return
        from PyQt4.QtGui import QGraphicsScene, QGraphicsItem, QGraphicsLineItem
        from PyQt4.QtCore import QRectF, QLineF
        w = self.winManager.newWindow()
        scene = QGraphicsScene(w.graphicsView)
        scene.addItem(Items.Grid())
        scene.addItem(Items.Axes())

        line = scene.addLine(QLineF(0, 0, 0, 0))

        cross = Items.NodeCross(movable=True)
        cross.addEdge(line, 1)
        scene.addItem(cross)

        help = scene.addText(QCoreApplication.translate('Graphics', 'Press "h" for help!'))
        help.moveBy(-50, 80)

        text = Items.NodeText(QCoreApplication.translate('Graphics', 'Drag Me!'))
        text.setFlag(QGraphicsItem.ItemIsMovable, True)
        text.setFlag(QGraphicsItem.ItemIsSelectable, True)
        text.addEdge(line, 2)
        scene.addItem(text)
        w.graphicsView.setScene(scene)


    def listWindows(self):
        if self.winManager:
            return self.winManager.windows
Ejemplo n.º 2
0
    def load(self):
        self.initTranslations()
        import vtk, VtkWidget, VtkWindow, Objects, Helpers
        self.vtk = vtk
        self.VtkWidget = VtkWidget
        self.VtkWindow = VtkWindow
        self.Objects = Objects
        self.Helpers = Helpers
        xpm = QPixmap()
        xpm.loadFromData(self.getFile('3dwin.xpm').read())
        winIcon = QIcon(xpm)
        self.winManager = SubWinManager(glb.mainWin.workSpace, self.VtkWindow.VtkWindow,
                QCoreApplication.translate('VtkWindow', "Vtk Window"), winIcon)
        testAction = QAction(winIcon,
            QCoreApplication.translate('VtkWindow', '&VtkWindow Test'), glb.mainWin)
        testAction.setStatusTip(QCoreApplication.translate('VtkWindow', 'Show a new Vtk test window'))
        QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
        glb.mainWin.plugInMenu.addAction(testAction)

        ftActions = glb.fileTypeActions
        ftActions.addType('application/x-3ds', '.3ds')
        ftActions.addAction(self.show3DS, ('application/x-3ds',),
            QCoreApplication.translate('VtkWindow', 'Open in VtkWindow'), 5)
        ftActions.addType('application/x-vrml', '.wrl')
        ftActions.addAction(self.showVRML, ('application/x-vrml',),
            QCoreApplication.translate('VtkWindow', 'Open in VtkWindow'), 5)

        return True
Ejemplo n.º 3
0
 def load(self):
     import GraphicsWindow, Items
     self.GraphicsWindow = GraphicsWindow
     self.Items = Items
     xpm = QPixmap()
     xpm.loadFromData(self.getFile('graphicswin.xpm').read())
     winIcon = QIcon(xpm)
     self.winManager = SubWinManager(SimuVis4.Globals.mainWin.workSpace, self.GraphicsWindow.GraphicsWindow,
         QCoreApplication.translate('Graphics', "GraphicsView"), winIcon)
     testAction = QAction(winIcon,
         QCoreApplication.translate('Graphics', '&Graphics Test'), SimuVis4.Globals.mainWin)
     testAction.setStatusTip(QCoreApplication.translate('Graphics', 'Show a new graphics window'))
     QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
     SimuVis4.Globals.mainWin.plugInMenu.addAction(testAction)
     return True
Ejemplo n.º 4
0
 def load(self):
     self.initTranslations()
     import vtk, VtkWidget, VtkWindow, Objects, Helpers
     self.vtk = vtk
     self.VtkWidget = VtkWidget
     self.VtkWindow = VtkWindow
     self.Objects = Objects
     self.Helpers = Helpers
     xpm = QPixmap()
     xpm.loadFromData(self.getFile('3dwin.xpm').read())
     winIcon = QIcon(xpm)
     self.winManager = SubWinManager(SimuVis4.Globals.mainWin.workSpace, self.VtkWindow.VtkWindow,
             QCoreApplication.translate('VtkWindow', "Vtk Window"), winIcon)
     testAction = QAction(winIcon,
         QCoreApplication.translate('VtkWindow', '&VtkWindow Test'), SimuVis4.Globals.mainWin)
     testAction.setStatusTip(QCoreApplication.translate('VtkWindow', 'Show a new Vtk test window'))
     QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
     SimuVis4.Globals.mainWin.plugInMenu.addAction(testAction)
     return True
Ejemplo n.º 5
0
 def load(self):
     self.initTranslations()
     cfg = SimuVis4.Globals.config
     cfgsec = self.name.lower()
     if not cfg.has_section(cfgsec):
         cfg.add_section(cfgsec)
     glb = SimuVis4.Globals
     import QwtPlotWindow, QPlot, MaskedArray
     self.QwtPlotWindow = QwtPlotWindow
     self.MaskedArray = MaskedArray
     xpm = QPixmap()
     xpm.loadFromData(self.getFile('plotwin.xpm').read())
     winIcon = QIcon(xpm)
     self.winManager = SubWinManager(SimuVis4.Globals.mainWin.workSpace, QwtPlotWindow.QwtPlotWindow,
             QCoreApplication.translate('QwtPlot', 'Qwt Plotwindow'), winIcon)
     testAction = QAction(winIcon,
         QCoreApplication.translate('QwtPlot', '&QwtPlotWindow Test'), SimuVis4.Globals.mainWin)
     testAction.setStatusTip(QCoreApplication.translate('QwtPlot', 'Show a new Qwt test window'))
     QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
     SimuVis4.Globals.mainWin.plugInMenu.addAction(testAction)
     return True
Ejemplo n.º 6
0
class PlugIn(SimplePlugIn):

    def load(self):
        self.initTranslations()
        cfg = SimuVis4.Globals.config
        cfgsec = self.name.lower()
        if not cfg.has_section(cfgsec):
            cfg.add_section(cfgsec)
        glb = SimuVis4.Globals
        import QwtPlotWindow, QPlot, MaskedArray
        self.QwtPlotWindow = QwtPlotWindow
        self.MaskedArray = MaskedArray
        xpm = QPixmap()
        xpm.loadFromData(self.getFile('plotwin.xpm').read())
        winIcon = QIcon(xpm)
        self.winManager = SubWinManager(SimuVis4.Globals.mainWin.workSpace, QwtPlotWindow.QwtPlotWindow,
                QCoreApplication.translate('QwtPlot', 'Qwt Plotwindow'), winIcon)
        testAction = QAction(winIcon,
            QCoreApplication.translate('QwtPlot', '&QwtPlotWindow Test'), SimuVis4.Globals.mainWin)
        testAction.setStatusTip(QCoreApplication.translate('QwtPlot', 'Show a new Qwt test window'))
        QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
        SimuVis4.Globals.mainWin.plugInMenu.addAction(testAction)
        return True


    def test(self):
        from math import sin, cos
        from PyQt4.Qwt5 import QwtPlotCurve
        w = self.winManager.newWindow()
        plt = w.plot
        xx = [0.05*x for x in range(100)]
        y1 = [sin(x) for x in xx]
        y2 = [cos(x) for x in xx]
        curve1 = QwtPlotCurve('sin(x)')
        curve1.attach(plt)
        curve1.setData(xx, y1)
        curve2 = QwtPlotCurve('cos(x)')
        curve2.attach(plt)
        curve2.setData(xx, y2)
Ejemplo n.º 7
0
class PlugIn(SimplePlugIn):

    def load(self):
        self.initTranslations()
        import vtk, VtkWidget, VtkWindow, Objects, Helpers
        self.vtk = vtk
        self.VtkWidget = VtkWidget
        self.VtkWindow = VtkWindow
        self.Objects = Objects
        self.Helpers = Helpers
        xpm = QPixmap()
        xpm.loadFromData(self.getFile('3dwin.xpm').read())
        winIcon = QIcon(xpm)
        self.winManager = SubWinManager(glb.mainWin.workSpace, self.VtkWindow.VtkWindow,
                QCoreApplication.translate('VtkWindow', "Vtk Window"), winIcon)
        testAction = QAction(winIcon,
            QCoreApplication.translate('VtkWindow', '&VtkWindow Test'), glb.mainWin)
        testAction.setStatusTip(QCoreApplication.translate('VtkWindow', 'Show a new Vtk test window'))
        QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
        glb.mainWin.plugInMenu.addAction(testAction)

        ftActions = glb.fileTypeActions
        ftActions.addType('application/x-3ds', '.3ds')
        ftActions.addAction(self.show3DS, ('application/x-3ds',),
            QCoreApplication.translate('VtkWindow', 'Open in VtkWindow'), 5)
        ftActions.addType('application/x-vrml', '.wrl')
        ftActions.addAction(self.showVRML, ('application/x-vrml',),
            QCoreApplication.translate('VtkWindow', 'Open in VtkWindow'), 5)

        return True


    def unload(self, fast):
        if self.winManager:
            self.winManager.shutdown()
            del self.winManager


    def test(self, name=None):
        if not self.winManager:
            return

        w = self.winManager.newWindow(name)
        vtk = self.vtk

        ren = vtk.vtkRenderer()
        w.vtkWidget.GetRenderWindow().AddRenderer(ren)

        sphere = vtk.vtkSphereSource()
        sphereMapper = vtk.vtkPolyDataMapper()
        sphereMapper.SetInput(sphere.GetOutput())
        sphereActor = vtk.vtkActor()
        sphereActor.SetMapper(sphereMapper)
        sphereActor.GetProperty().SetColor(1.0, 0.3, 0.3)
        ren.AddActor(sphereActor)

        cone = vtk.vtkConeSource()
        cone.SetResolution(16)
        coneMapper = vtk.vtkPolyDataMapper()
        coneMapper.SetInput(cone.GetOutput())
        coneActor = vtk.vtkActor()
        coneActor.SetMapper(coneMapper)
        coneActor.AddPosition(0.0, 1.0, 0.0)
        coneActor.GetProperty().SetColor(1.0, 1.0, 0.0)
        ren.AddActor(coneActor)

        cube = vtk.vtkCubeSource()
        cubeMapper = vtk.vtkPolyDataMapper()
        cubeMapper.SetInput(cube.GetOutput())
        cubeActor = vtk.vtkActor()
        cubeActor.SetMapper(cubeMapper)
        cubeActor.AddPosition(0.0, 2.0, 0.0)
        cubeActor.GetProperty().SetColor(0.3, 1.0, 0.3)
        ren.AddActor(cubeActor)
        w.show()
        w.vtkWidget.Initialize()
        w.vtkWidget.Start()

        return w

    def show3DS(self, fileName):
        vtk = self.vtk
        importer = vtk.vtk3DSImporter()
        importer.ComputeNormalsOn()
        importer.SetFileName(fileName)
        importer.Read()
        ren = importer.GetRenderer()
        ren.SetBackground(0.1, 0.2, 0.4)
        ren.ResetCamera()
        w = self.winManager.newWindow(fileName)
        importer.SetRenderWindow(w.vtkWidget.GetRenderWindow())
        w.vtkWidget.GetRenderWindow().AddRenderer(ren)
        w.show()
        w.vtkWidget.Initialize()
        w.vtkWidget.Start()
        return w

    def showVRML(self, fileName):
        vtk = self.vtk
        importer = vtk.vtkVRMLImporter()
        importer.SetFileName(fileName)
        importer.Read()
        ren = importer.GetRenderer()
        ren.SetBackground(0.1, 0.2, 0.4)
        ren.ResetCamera()
        w = self.winManager.newWindow(fileName)
        importer.SetRenderWindow(w.vtkWidget.GetRenderWindow())
        w.vtkWidget.GetRenderWindow().AddRenderer(ren)
        w.show()
        w.vtkWidget.Initialize()
        w.vtkWidget.Start()
        return w
Ejemplo n.º 8
0
class PlugIn(SimplePlugIn):

    def load(self):
        self.initTranslations()
        import vtk, VtkWidget, VtkWindow, Objects, Helpers
        self.vtk = vtk
        self.VtkWidget = VtkWidget
        self.VtkWindow = VtkWindow
        self.Objects = Objects
        self.Helpers = Helpers
        xpm = QPixmap()
        xpm.loadFromData(self.getFile('3dwin.xpm').read())
        winIcon = QIcon(xpm)
        self.winManager = SubWinManager(SimuVis4.Globals.mainWin.workSpace, self.VtkWindow.VtkWindow,
                QCoreApplication.translate('VtkWindow', "Vtk Window"), winIcon)
        testAction = QAction(winIcon,
            QCoreApplication.translate('VtkWindow', '&VtkWindow Test'), SimuVis4.Globals.mainWin)
        testAction.setStatusTip(QCoreApplication.translate('VtkWindow', 'Show a new Vtk test window'))
        QWidget.connect(testAction, SIGNAL("triggered()"), self.test)
        SimuVis4.Globals.mainWin.plugInMenu.addAction(testAction)
        return True


    def unload(self, fast):
        if self.winManager:
            self.winManager.shutdown()
            del self.winManager


    def test(self, name=None):
        if not self.winManager:
            return

        w = self.winManager.newWindow(name)
        vtk = self.vtk

        ren = vtk.vtkRenderer()
        w.vtkWidget.GetRenderWindow().AddRenderer(ren)

        sphere = vtk.vtkSphereSource()
        sphereMapper = vtk.vtkPolyDataMapper()
        sphereMapper.SetInput(sphere.GetOutput())
        sphereActor = vtk.vtkActor()
        sphereActor.SetMapper(sphereMapper)
        sphereActor.GetProperty().SetColor(1.0, 0.3, 0.3)
        ren.AddActor(sphereActor)

        cone = vtk.vtkConeSource()
        cone.SetResolution(16)
        coneMapper = vtk.vtkPolyDataMapper()
        coneMapper.SetInput(cone.GetOutput())
        coneActor = vtk.vtkActor()
        coneActor.SetMapper(coneMapper)
        coneActor.AddPosition(0.0, 1.0, 0.0)
        coneActor.GetProperty().SetColor(1.0, 1.0, 0.0)
        ren.AddActor(coneActor)

        cube = vtk.vtkCubeSource()
        cubeMapper = vtk.vtkPolyDataMapper()
        cubeMapper.SetInput(cube.GetOutput())
        cubeActor = vtk.vtkActor()
        cubeActor.SetMapper(cubeMapper)
        cubeActor.AddPosition(0.0, 2.0, 0.0)
        cubeActor.GetProperty().SetColor(0.3, 1.0, 0.3)
        ren.AddActor(cubeActor)
        w.show()
        w.vtkWidget.Initialize()
        w.vtkWidget.Start()

        return w