예제 #1
0
 def setupSoQt(self):
     self.root = self.getRoot()
     self.examiner = SoQtExaminerViewer(self)
     self.examiner.setSceneGraph(self.root)
     for attr in [
             "viewAll", "setDecoration", "setHeadlight",
             "setTransparencyType"
     ]:
         setattr(self, attr, getattr(self.examiner, attr))
예제 #2
0
    def setupSoQt(self):
        root = SoSeparator()
        self.rotxyz = SoRotationXYZ()
        self.gate = SoGate(SoMFFloat.getClassTypeId())
        self.elapsedTime = SoElapsedTime()
        self.gate.enable = False
        self.gate.input.connectFrom(self.elapsedTime.timeOut)
        self.rotxyz.angle.connectFrom(self.gate.output)        
        self.material = SoMaterial()
        self.material.diffuseColor = (0.0, 1.0, 1.0)
        self.cone = SoCone()
        root.addChild(self.rotxyz)
        root.addChild(self.material)
        root.addChild(self.cone)

        self.exam = SoQtExaminerViewer(self.examiner)
        self.exam.setSceneGraph(root)
예제 #3
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.setupSoQt()
        self.buttonGroup = QButtonGroup(self.groupBox)
        self.buttonGroup.addButton(self.button_x, 0)
        self.buttonGroup.addButton(self.button_y, 1)
        self.buttonGroup.addButton(self.button_z, 2)
        self.connect(self.buttonGroup, SIGNAL("buttonClicked(int)"), self.change_axis)
        self.connect(self.button, SIGNAL("clicked()"), self.change_color)
        self.connect(self.checkbox, SIGNAL("clicked()"), self.rotate)

    def change_axis(self, axis):
        self.rotxyz.axis = axis

    def change_color(self):
        self.material.diffuseColor = (random(), random(), random())

    def rotate(self):
        self.gate.enable = not self.gate.enable.getValue()

    def setupSoQt(self):
        root = SoSeparator()
        self.rotxyz = SoRotationXYZ()
        self.gate = SoGate(SoMFFloat.getClassTypeId())
        self.elapsedTime = SoElapsedTime()
        self.gate.enable = False
        self.gate.input.connectFrom(self.elapsedTime.timeOut)
        self.rotxyz.angle.connectFrom(self.gate.output)        
        self.material = SoMaterial()
        self.material.diffuseColor = (0.0, 1.0, 1.0)
        self.cone = SoCone()
        root.addChild(self.rotxyz)
        root.addChild(self.material)
        root.addChild(self.cone)

        self.exam = SoQtExaminerViewer(self.examiner)
        self.exam.setSceneGraph(root)
예제 #4
0
class MinimalViewer(QWidget):
    """
    A QWidget which contains a child QuarterWidget
    """
    def __init__(self, colorLights=True):
        QWidget.__init__(self)
        self.setupSoQt()
        # camera defaults
        self.camera_point_at = [coin.SbVec3f(0, 0, 0), coin.SbVec3f(0, 0, 1)]
        self.camera_position = (7, 7, 7)
        # call viewAll when switching to a new page
        self.camera_viewAll = True
        # the scene root

        self.initializeViewer()
        self.setInitialCameraPosition()
        self.mouseEventCB = coin.SoEventCallback()
        self.getSRoot().addChild(self.mouseEventCB)
        if colorLights:
            self.addLights()
            self.setColorLightOn(True)
            # no need the default headlight in this case
            self.examiner.setHeadlight(False)

    def setupSoQt(self):
        self.root = self.getRoot()
        self.examiner = SoQtExaminerViewer(self)
        self.examiner.setSceneGraph(self.root)
        for attr in [
                "viewAll", "setDecoration", "setHeadlight",
                "setTransparencyType"
        ]:
            setattr(self, attr, getattr(self.examiner, attr))

    def getRoot(self):
        return coin.SoSeparator()

    @fluid
    def addChild(self, node):
        self.root.addChild(getattr(node, "root", node))

    @property
    def camera(self):
        return self.examiner.getCamera()

    def setCameraPosition(self, position):
        self.__camera_position = self.camera.position
        self.camera.position = position
        logger.debug('setCameraPosition: %s, %s, %s', position,
                     self.getCameraPosition(), self.camera)

    def getCameraPosition(self):
        return self.camera.position.getValue()

    cameraPosition = property(getCameraPosition, setCameraPosition)

    def setInitialCameraPosition(self):
        """Chose an adequate initial pov"""
        logger.debug('setInitialCameraPosition')
        self.setCameraPosition(self.camera_position)
        self.camera.pointAt(*self.camera_point_at)
        self.camera.farDistance = 25
        self.camera.nearDistance = .01

    def trackCameraPosition(self, val):
        if val:
            if not hasattr(self, "cameraSensor"):

                def print_pos(camera, sensor):
                    print "position:", camera.position.getValue()

                def print_or(camera, sensor):
                    print "orientation:", camera.orientation.getValue(
                    ).getAxisAngle()

                self.cameraSensor = callback(self.camera.position, print_pos,
                                             self.camera)
                self.cameraSensor2 = callback(self.camera.orientation,
                                              print_or, self.camera)
            else:
                self.cameraSensor.attach(self.camera.position)
                self.cameraSensor2.attach(self.camera.orientation)
        elif hasattr(self, "cameraSensor"):
            self.cameraSensor.detach()
            self.cameraSensor2.detach()

    def addLights(self):
        self.colorLights = readFile(filePath("viewer",
                                             "lights.iv")).getChild(0)
        self.insertLight(self.colorLights)
        self.colorLights.whichChild = coin.SO_SWITCH_ALL

    def setColorLightOn(self, val):
        if self.colorLights:
            self.colorLights.whichChild = coin.SO_SWITCH_ALL if val else coin.SO_SWITCH_NONE

    def insertLight(self, luz):
        self.getSRoot().insertChild(luz, 0)

    def buildRotor(self):
        rotor = coin.SoRotor()
        rotor.on = False
        rotor.setName("rotor")
        rotor.speed = 0.005
        rotor.rotation = (0, 0, 1, 0)
        return rotor

    def initializeViewer(self):
        fmt = QtOpenGL.QGLFormat()
        fmt.setAlpha(True)
        QtOpenGL.QGLFormat.setDefaultFormat(fmt)
        self.rotor = self.buildRotor()
        hints = coin.SoShapeHints()
        hints.vertexOrdering = coin.SoShapeHints.COUNTERCLOCKWISE
        hints.shapeType = coin.SoShapeHints.SOLID
        hints.faceType = coin.SoShapeHints.CONVEX
        self.root.addChild(self.rotor)
        self.root.addChild(hints)

    def getSRoot(self):
        return self.examiner.getSceneManager().getSceneGraph()

    def toText(self, root):
        wa = coin.SoWriteAction()
        return wa.apply(root)

    def setStereoAdjustment(self, val):
        self.camera.setStereoAdjustment(val)