Exemple #1
0
class RectangleManager(QtCore.QObject):
    """
        general gui class to handle the rectangle in VRPStreamlineBase
        used by different VisItem panels
    """

    def __init__(self, parent, doApply, doApplyRadioBttn, doParamChange, typeRec=TRACER, startStyle = PLANE):
        QtCore.QObject.__init__(self)

        assert parent
        assert doApply

        #slots to be registered by parent
        self.__parent = parent
        self.__apply = doApply
        self.__applyRadioBttn = doApplyRadioBttn
        self.__paramChange = doParamChange
        self.__type = typeRec

        middleFloatInRangeCtrls = [ self.__parent.floatInRangeX, self.__parent.floatInRangeY, self.__parent.floatInRangeZ  ]
        sideFloatInRangeCtrls = []
        rotFloatInRangeCtrls = []
        endPointFloatInRangeCtrls = []

        # a streamlines panel will have these widgets so they will get connected
        if typeRec == TRACER:
            endPointFloatInRangeCtrls = [ self.__parent.floatInRangeEndPointX, self.__parent.floatInRangeEndPointY, self.__parent.floatInRangeEndPointZ  ]

        self.__boundingBox = ((-1, 1), (-1, 1), (-1, 1))
        for w, r in zip(middleFloatInRangeCtrls, self.__boundingBox):
            w.setRange(r)
        #if not typeRec == POINTPROBING:
        if startStyle == PLANE:
            sideRange = 0, self.__heuristicProbeMaxSideLengthFromBox(self.__boundingBox)
            if self.__type == TRACER:
                sideFloatInRangeCtrls = [self.__parent.floatInRangeWidth, self.__parent.floatInRangeHeight]
                for w in sideFloatInRangeCtrls:
                    w.setRange(sideRange)
            rotFloatInRangeCtrls = [ self.__parent.floatInRangeRotX, self.__parent.floatInRangeRotY, self.__parent.floatInRangeRotZ  ]
            for w in rotFloatInRangeCtrls:
                w.setRange((-180.,180.))
        elif startStyle == LINE:
            endPointFloatInRangeCtrls = [ self.__parent.floatInRangeEndPointX, self.__parent.floatInRangeEndPointY, self.__parent.floatInRangeEndPointZ  ]
            for w, r in zip(endPointFloatInRangeCtrls, self.__boundingBox):
                w.setRange(r)
            sideFloatInRangeCtrls = []
            rotFloatInRangeCtrls = []
        #else:
        #    sideFloatInRangeCtrls = []
        #    rotFloatInRangeCtrls = []

        for w in middleFloatInRangeCtrls + sideFloatInRangeCtrls + rotFloatInRangeCtrls + endPointFloatInRangeCtrls:
            w.sigSliderReleased.connect(self.__apply)
            if self.__paramChange:
                w.sigValueChanged.connect(self.__paramChange)

        #if not typeRec == POINTPROBING:
        for w in [self.__parent.xAxisRadioButton,
                self.__parent.yAxisRadioButton,
                self.__parent.zAxisRadioButton]:
            w.clicked.connect(self.__radioButtonClick)

        self.__boundingBox = Box((-1, 1), (-1, 1), (-1, 1))


    def getParams(self, startStyle = PLANE):
        if startStyle == PLANE:
            aar = AxisAlignedRectangleIn3d()
            aar.middle = self.__getMiddle()
            if self.__parent.zAxisRadioButton.isChecked():
                aar.orthogonalAxis = 'z'
            elif self.__parent.yAxisRadioButton.isChecked():
                aar.orthogonalAxis = 'y'
            elif self.__parent.xAxisRadioButton.isChecked():
                aar.orthogonalAxis = 'x'
            else:
                text = (
                    'Invalid orthogonalAxis.  Invalid value is "%s".  '
                    'Expected one out of {"x", "y", "z"}'
                    % str(aar.orthogonalAxis))
                assert False, text
            if self.__type == TRACER:
                aar.lengthA = self.__parent.floatInRangeWidth.getValue()
                aar.lengthB = self.__parent.floatInRangeHeight.getValue()
            elif self.__type == CUTTINGSURFACE:
                aar.lengthA = 1.0
                aar.lengthB = 1.0
            aar.rotX = self.__parent.floatInRangeRotX.getValue()
            aar.rotY = self.__parent.floatInRangeRotY.getValue()
            aar.rotZ = self.__parent.floatInRangeRotZ.getValue()
            
            return aar
        elif startStyle == LINE:
            line = Line3D()

            line.setStartEndPoint(self.__parent.floatInRangeX.getValue(),
                                  self.__parent.floatInRangeY.getValue(),
                                  self.__parent.floatInRangeZ.getValue(),
                                  self.__parent.floatInRangeEndPointX.getValue(),
                                  self.__parent.floatInRangeEndPointY.getValue(),
                                  self.__parent.floatInRangeEndPointZ.getValue())

            return line

    def getBoundingBox(self):
        return self.__boundingBox

    def setBoundingBox( self, box, startStyle = PLANE):
        if self.__boundingBox == box:
            return
        self.__boundingBox = box
        #self.__parent.floatInRangeY.setRange(self.__boundingBox.getYMinMax())
        #self.__parent.floatInRangeZ.setRange(self.__boundingBox.getZMinMax())
        if self.__type==TRACER:
            maxSideLength = self.__boundingBox.getMaxEdgeLength()
            self.__parent.floatInRangeHeight.setRange((0.0, maxSideLength))
            self.__parent.floatInRangeWidth.setRange((0.0, maxSideLength))
        center = self.__boundingBox.getCenter()

        self.__parent.floatInRangeX.setValue(center[0])
        #print "setXRange: "+str(self.__boundingBox.getXMinMax())
        self.__parent.floatInRangeX.setRange(self.__boundingBox.getXMinMax())
        self.__parent.floatInRangeY.setValue(center[1])
        #print "setYRange: "+str(self.__boundingBox.getYMinMax())
        self.__parent.floatInRangeY.setRange(self.__boundingBox.getYMinMax())
        self.__parent.floatInRangeZ.setValue(center[2])
        #print "setZRange: "+str(self.__boundingBox.getZMinMax())
        self.__parent.floatInRangeZ.setRange(self.__boundingBox.getZMinMax())

        if startStyle == LINE:
            self.__parent.floatInRangeEndPointX.setValue(self.__boundingBox.getXMinMax()[0])#center[0])
            #print "setXRange: "+str(self.__boundingBox.getXMinMax())
            self.__parent.floatInRangeEndPointX.setRange(self.__boundingBox.getXMinMax())
            self.__parent.floatInRangeEndPointY.setValue(self.__boundingBox.getYMinMax()[0])#center[1])
            #print "setYRange: "+str(self.__boundingBox.getYMinMax())
            self.__parent.floatInRangeEndPointY.setRange(self.__boundingBox.getYMinMax())
            self.__parent.floatInRangeEndPointZ.setValue(self.__boundingBox.getZMinMax()[0])#center[2])
            #print "setZRange: "+str(self.__boundingBox.getZMinMax())
            self.__parent.floatInRangeEndPointZ.setRange(self.__boundingBox.getZMinMax())


    def setRectangle(self, aar):
        controls = [
            self.__parent.floatInRangeX,
            self.__parent.floatInRangeY,
            self.__parent.floatInRangeZ,
            self.__parent.floatInRangeRotX,
            self.__parent.floatInRangeRotY,
            self.__parent.floatInRangeRotZ,
            self.__parent.xAxisRadioButton,
            self.__parent.yAxisRadioButton,
            self.__parent.zAxisRadioButton]
        for c in controls: c.blockSignals(True)
        self.__parent.floatInRangeX.setValue(aar.middle[0])
        self.__parent.floatInRangeY.setValue(aar.middle[1])
        self.__parent.floatInRangeZ.setValue(aar.middle[2])
        self.__parent.floatInRangeRotX.setValue(aar.rotX)
        self.__parent.floatInRangeRotY.setValue(aar.rotY)
        self.__parent.floatInRangeRotZ.setValue(aar.rotZ)
        if aar.orthogonalAxis == 'z':
            self.__parent.zAxisRadioButton.setChecked(True)
            self.__parent.xAxisRadioButton.setChecked(False)
            self.__parent.yAxisRadioButton.setChecked(False)
        elif aar.orthogonalAxis == 'y':
            self.__parent.yAxisRadioButton.setChecked(True)
            self.__parent.xAxisRadioButton.setChecked(False)
            self.__parent.zAxisRadioButton.setChecked(False)
        elif aar.orthogonalAxis == 'x':
            self.__parent.xAxisRadioButton.setChecked(True)
            self.__parent.zAxisRadioButton.setChecked(False)
            self.__parent.yAxisRadioButton.setChecked(False)
        elif aar.orthogonalAxis == 'line':
            pass
        else:
            text = ('Invalid orthogonalAxis.  Invalid value is "%s"'
                    % str(aar.orthogonalAxis))
            assert False, text
        self.__setElementsEnabled()
        for c in controls: c.blockSignals(False)

        if self.__type==TRACER:
            controls = [self.__parent.floatInRangeHeight,
                        self.__parent.floatInRangeWidth]
            for c in controls: c.blockSignals(True)
            self.__parent.floatInRangeWidth.setValue(aar.lengthA)
            self.__parent.floatInRangeHeight.setValue(aar.lengthB)
            for c in controls: c.blockSignals(False)


    def setLine(self, line):
        controls = [
            #self.__parent.floatInRangeHeight,
            #self.__parent.floatInRangeWidth,
            #self.__parent.floatInRangeRotX,
            #self.__parent.floatInRangeRotY,
            #self.__parent.floatInRangeRotZ,
            #self.__parent.xAxisRadioButton,
            #self.__parent.yAxisRadioButton,
            #self.__parent.zAxisRadioButton,
            self.__parent.floatInRangeX,
            self.__parent.floatInRangeY,
            self.__parent.floatInRangeZ,
            self.__parent.floatInRangeEndPointX,
            self.__parent.floatInRangeEndPointY,
            self.__parent.floatInRangeEndPointZ]
        for c in controls: c.blockSignals(True)

        self.__parent.floatInRangeX.setValue(line.getStartPoint()[0])
        self.__parent.floatInRangeY.setValue(line.getStartPoint()[1])
        self.__parent.floatInRangeZ.setValue(line.getStartPoint()[2])

        self.__parent.floatInRangeEndPointX.setValue(line.getEndPoint()[0])
        self.__parent.floatInRangeEndPointY.setValue(line.getEndPoint()[1])
        self.__parent.floatInRangeEndPointZ.setValue(line.getEndPoint()[2])

        for c in controls: c.blockSignals(False)


    def __heuristicProbeMaxSideLengthFromBox(self, bb):
        return math.sqrt(
            (bb[0][1] - bb[0][0]) * (bb[0][1] - bb[0][0])
            + (bb[1][1] - bb[1][0]) * (bb[1][1] - bb[1][0])
            + (bb[2][1] - bb[2][0]) * (bb[2][1] - bb[2][0]))

    def __getMiddle(self):
        return (self.__parent.floatInRangeX.getValue(),
                self.__parent.floatInRangeY.getValue(),
                self.__parent.floatInRangeZ.getValue())

    def __radioButtonClick(self):
        self.__parent.floatInRangeRotX.setValue(0.0)
        self.__parent.floatInRangeRotY.setValue(0.0)
        self.__parent.floatInRangeRotZ.setValue(0.0)
        self.__setElementsEnabled()
        if self.__applyRadioBttn != None:
            self.__applyRadioBttn()

    def __setElementsEnabled(self):
        if (self.__type == CUTTINGSURFACE):
            if self.__parent.xAxisRadioButton.isChecked():
                self.__parent.floatInRangeRotX.setEnabled(False)
                self.__parent.floatInRangeX.setEnabled(True)
                self.__parent.floatInRangeRotY.setEnabled(True)
                self.__parent.floatInRangeY.setEnabled(True)
                self.__parent.floatInRangeRotZ.setEnabled(True)            
                self.__parent.floatInRangeZ.setEnabled(True)
            elif self.__parent.yAxisRadioButton.isChecked():
                self.__parent.floatInRangeRotX.setEnabled(True)
                self.__parent.floatInRangeX.setEnabled(True)
                self.__parent.floatInRangeRotY.setEnabled(False)
                self.__parent.floatInRangeY.setEnabled(True)
                self.__parent.floatInRangeRotZ.setEnabled(True)
                self.__parent.floatInRangeZ.setEnabled(True)
            else:
                self.__parent.floatInRangeRotX.setEnabled(True)
                self.__parent.floatInRangeX.setEnabled(True)
                self.__parent.floatInRangeRotY.setEnabled(True)
                self.__parent.floatInRangeY.setEnabled(True)
                self.__parent.floatInRangeRotZ.setEnabled(False)
                self.__parent.floatInRangeZ.setEnabled(True)
Exemple #2
0
class RectangleManager(QtCore.QObject):
    """
        general gui class to handle the rectangle in VRPStreamlineBase
        used by different VisItem panels
    """
    def __init__(self,
                 parent,
                 doApply,
                 doApplyRadioBttn,
                 doParamChange,
                 typeRec=TRACER,
                 startStyle=PLANE):
        QtCore.QObject.__init__(self)

        assert parent
        assert doApply

        #slots to be registered by parent
        self.__parent = parent
        self.__apply = doApply
        self.__applyRadioBttn = doApplyRadioBttn
        self.__paramChange = doParamChange
        self.__type = typeRec

        middleFloatInRangeCtrls = [
            self.__parent.floatInRangeX, self.__parent.floatInRangeY,
            self.__parent.floatInRangeZ
        ]
        sideFloatInRangeCtrls = []
        rotFloatInRangeCtrls = []
        endPointFloatInRangeCtrls = []

        # a streamlines panel will have these widgets so they will get connected
        if typeRec == TRACER:
            endPointFloatInRangeCtrls = [
                self.__parent.floatInRangeEndPointX,
                self.__parent.floatInRangeEndPointY,
                self.__parent.floatInRangeEndPointZ
            ]

        self.__boundingBox = ((-1, 1), (-1, 1), (-1, 1))
        for w, r in zip(middleFloatInRangeCtrls, self.__boundingBox):
            w.setRange(r)
        #if not typeRec == POINTPROBING:
        if startStyle == PLANE:
            sideRange = 0, self.__heuristicProbeMaxSideLengthFromBox(
                self.__boundingBox)
            if self.__type == TRACER:
                sideFloatInRangeCtrls = [
                    self.__parent.floatInRangeWidth,
                    self.__parent.floatInRangeHeight
                ]
                for w in sideFloatInRangeCtrls:
                    w.setRange(sideRange)
            rotFloatInRangeCtrls = [
                self.__parent.floatInRangeRotX, self.__parent.floatInRangeRotY,
                self.__parent.floatInRangeRotZ
            ]
            for w in rotFloatInRangeCtrls:
                w.setRange((-180., 180.))
        elif startStyle == LINE:
            endPointFloatInRangeCtrls = [
                self.__parent.floatInRangeEndPointX,
                self.__parent.floatInRangeEndPointY,
                self.__parent.floatInRangeEndPointZ
            ]
            for w, r in zip(endPointFloatInRangeCtrls, self.__boundingBox):
                w.setRange(r)
            sideFloatInRangeCtrls = []
            rotFloatInRangeCtrls = []
        #else:
        #    sideFloatInRangeCtrls = []
        #    rotFloatInRangeCtrls = []

        for w in middleFloatInRangeCtrls + sideFloatInRangeCtrls + rotFloatInRangeCtrls + endPointFloatInRangeCtrls:
            w.sigSliderReleased.connect(self.__apply)
            if self.__paramChange:
                w.sigValueChanged.connect(self.__paramChange)

        #if not typeRec == POINTPROBING:
        for w in [
                self.__parent.xAxisRadioButton, self.__parent.yAxisRadioButton,
                self.__parent.zAxisRadioButton
        ]:
            w.clicked.connect(self.__radioButtonClick)

        self.__boundingBox = Box((-1, 1), (-1, 1), (-1, 1))

    def getParams(self, startStyle=PLANE):
        if startStyle == PLANE:
            aar = AxisAlignedRectangleIn3d()
            aar.middle = self.__getMiddle()
            if self.__parent.zAxisRadioButton.isChecked():
                aar.orthogonalAxis = 'z'
            elif self.__parent.yAxisRadioButton.isChecked():
                aar.orthogonalAxis = 'y'
            elif self.__parent.xAxisRadioButton.isChecked():
                aar.orthogonalAxis = 'x'
            else:
                text = ('Invalid orthogonalAxis.  Invalid value is "%s".  '
                        'Expected one out of {"x", "y", "z"}' %
                        str(aar.orthogonalAxis))
                assert False, text
            if self.__type == TRACER:
                aar.lengthA = self.__parent.floatInRangeWidth.getValue()
                aar.lengthB = self.__parent.floatInRangeHeight.getValue()
            elif self.__type == CUTTINGSURFACE:
                aar.lengthA = 1.0
                aar.lengthB = 1.0
            aar.rotX = self.__parent.floatInRangeRotX.getValue()
            aar.rotY = self.__parent.floatInRangeRotY.getValue()
            aar.rotZ = self.__parent.floatInRangeRotZ.getValue()

            return aar
        elif startStyle == LINE:
            line = Line3D()

            line.setStartEndPoint(
                self.__parent.floatInRangeX.getValue(),
                self.__parent.floatInRangeY.getValue(),
                self.__parent.floatInRangeZ.getValue(),
                self.__parent.floatInRangeEndPointX.getValue(),
                self.__parent.floatInRangeEndPointY.getValue(),
                self.__parent.floatInRangeEndPointZ.getValue())

            return line

    def getBoundingBox(self):
        return self.__boundingBox

    def setBoundingBox(self, box, startStyle=PLANE):
        if self.__boundingBox == box:
            return
        self.__boundingBox = box
        #self.__parent.floatInRangeY.setRange(self.__boundingBox.getYMinMax())
        #self.__parent.floatInRangeZ.setRange(self.__boundingBox.getZMinMax())
        if self.__type == TRACER:
            maxSideLength = self.__boundingBox.getMaxEdgeLength()
            self.__parent.floatInRangeHeight.setRange((0.0, maxSideLength))
            self.__parent.floatInRangeWidth.setRange((0.0, maxSideLength))
        center = self.__boundingBox.getCenter()

        self.__parent.floatInRangeX.setValue(center[0])
        #print "setXRange: "+str(self.__boundingBox.getXMinMax())
        self.__parent.floatInRangeX.setRange(self.__boundingBox.getXMinMax())
        self.__parent.floatInRangeY.setValue(center[1])
        #print "setYRange: "+str(self.__boundingBox.getYMinMax())
        self.__parent.floatInRangeY.setRange(self.__boundingBox.getYMinMax())
        self.__parent.floatInRangeZ.setValue(center[2])
        #print "setZRange: "+str(self.__boundingBox.getZMinMax())
        self.__parent.floatInRangeZ.setRange(self.__boundingBox.getZMinMax())

        if startStyle == LINE:
            self.__parent.floatInRangeEndPointX.setValue(
                self.__boundingBox.getXMinMax()[0])  #center[0])
            #print "setXRange: "+str(self.__boundingBox.getXMinMax())
            self.__parent.floatInRangeEndPointX.setRange(
                self.__boundingBox.getXMinMax())
            self.__parent.floatInRangeEndPointY.setValue(
                self.__boundingBox.getYMinMax()[0])  #center[1])
            #print "setYRange: "+str(self.__boundingBox.getYMinMax())
            self.__parent.floatInRangeEndPointY.setRange(
                self.__boundingBox.getYMinMax())
            self.__parent.floatInRangeEndPointZ.setValue(
                self.__boundingBox.getZMinMax()[0])  #center[2])
            #print "setZRange: "+str(self.__boundingBox.getZMinMax())
            self.__parent.floatInRangeEndPointZ.setRange(
                self.__boundingBox.getZMinMax())

    def setRectangle(self, aar):
        controls = [
            self.__parent.floatInRangeX, self.__parent.floatInRangeY,
            self.__parent.floatInRangeZ, self.__parent.floatInRangeRotX,
            self.__parent.floatInRangeRotY, self.__parent.floatInRangeRotZ,
            self.__parent.xAxisRadioButton, self.__parent.yAxisRadioButton,
            self.__parent.zAxisRadioButton
        ]
        for c in controls:
            c.blockSignals(True)
        self.__parent.floatInRangeX.setValue(aar.middle[0])
        self.__parent.floatInRangeY.setValue(aar.middle[1])
        self.__parent.floatInRangeZ.setValue(aar.middle[2])
        self.__parent.floatInRangeRotX.setValue(aar.rotX)
        self.__parent.floatInRangeRotY.setValue(aar.rotY)
        self.__parent.floatInRangeRotZ.setValue(aar.rotZ)
        if aar.orthogonalAxis == 'z':
            self.__parent.zAxisRadioButton.setChecked(True)
            self.__parent.xAxisRadioButton.setChecked(False)
            self.__parent.yAxisRadioButton.setChecked(False)
        elif aar.orthogonalAxis == 'y':
            self.__parent.yAxisRadioButton.setChecked(True)
            self.__parent.xAxisRadioButton.setChecked(False)
            self.__parent.zAxisRadioButton.setChecked(False)
        elif aar.orthogonalAxis == 'x':
            self.__parent.xAxisRadioButton.setChecked(True)
            self.__parent.zAxisRadioButton.setChecked(False)
            self.__parent.yAxisRadioButton.setChecked(False)
        elif aar.orthogonalAxis == 'line':
            pass
        else:
            text = ('Invalid orthogonalAxis.  Invalid value is "%s"' %
                    str(aar.orthogonalAxis))
            assert False, text
        self.__setElementsEnabled()
        for c in controls:
            c.blockSignals(False)

        if self.__type == TRACER:
            controls = [
                self.__parent.floatInRangeHeight,
                self.__parent.floatInRangeWidth
            ]
            for c in controls:
                c.blockSignals(True)
            self.__parent.floatInRangeWidth.setValue(aar.lengthA)
            self.__parent.floatInRangeHeight.setValue(aar.lengthB)
            for c in controls:
                c.blockSignals(False)

    def setLine(self, line):
        controls = [
            #self.__parent.floatInRangeHeight,
            #self.__parent.floatInRangeWidth,
            #self.__parent.floatInRangeRotX,
            #self.__parent.floatInRangeRotY,
            #self.__parent.floatInRangeRotZ,
            #self.__parent.xAxisRadioButton,
            #self.__parent.yAxisRadioButton,
            #self.__parent.zAxisRadioButton,
            self.__parent.floatInRangeX,
            self.__parent.floatInRangeY,
            self.__parent.floatInRangeZ,
            self.__parent.floatInRangeEndPointX,
            self.__parent.floatInRangeEndPointY,
            self.__parent.floatInRangeEndPointZ
        ]
        for c in controls:
            c.blockSignals(True)

        self.__parent.floatInRangeX.setValue(line.getStartPoint()[0])
        self.__parent.floatInRangeY.setValue(line.getStartPoint()[1])
        self.__parent.floatInRangeZ.setValue(line.getStartPoint()[2])

        self.__parent.floatInRangeEndPointX.setValue(line.getEndPoint()[0])
        self.__parent.floatInRangeEndPointY.setValue(line.getEndPoint()[1])
        self.__parent.floatInRangeEndPointZ.setValue(line.getEndPoint()[2])

        for c in controls:
            c.blockSignals(False)

    def __heuristicProbeMaxSideLengthFromBox(self, bb):
        return math.sqrt((bb[0][1] - bb[0][0]) * (bb[0][1] - bb[0][0]) +
                         (bb[1][1] - bb[1][0]) * (bb[1][1] - bb[1][0]) +
                         (bb[2][1] - bb[2][0]) * (bb[2][1] - bb[2][0]))

    def __getMiddle(self):
        return (self.__parent.floatInRangeX.getValue(),
                self.__parent.floatInRangeY.getValue(),
                self.__parent.floatInRangeZ.getValue())

    def __radioButtonClick(self):
        self.__parent.floatInRangeRotX.setValue(0.0)
        self.__parent.floatInRangeRotY.setValue(0.0)
        self.__parent.floatInRangeRotZ.setValue(0.0)
        self.__setElementsEnabled()
        if self.__applyRadioBttn != None:
            self.__applyRadioBttn()

    def __setElementsEnabled(self):
        if (self.__type == CUTTINGSURFACE):
            if self.__parent.xAxisRadioButton.isChecked():
                self.__parent.floatInRangeRotX.setEnabled(False)
                self.__parent.floatInRangeX.setEnabled(True)
                self.__parent.floatInRangeRotY.setEnabled(True)
                self.__parent.floatInRangeY.setEnabled(True)
                self.__parent.floatInRangeRotZ.setEnabled(True)
                self.__parent.floatInRangeZ.setEnabled(True)
            elif self.__parent.yAxisRadioButton.isChecked():
                self.__parent.floatInRangeRotX.setEnabled(True)
                self.__parent.floatInRangeX.setEnabled(True)
                self.__parent.floatInRangeRotY.setEnabled(False)
                self.__parent.floatInRangeY.setEnabled(True)
                self.__parent.floatInRangeRotZ.setEnabled(True)
                self.__parent.floatInRangeZ.setEnabled(True)
            else:
                self.__parent.floatInRangeRotX.setEnabled(True)
                self.__parent.floatInRangeX.setEnabled(True)
                self.__parent.floatInRangeRotY.setEnabled(True)
                self.__parent.floatInRangeY.setEnabled(True)
                self.__parent.floatInRangeRotZ.setEnabled(False)
                self.__parent.floatInRangeZ.setEnabled(True)
Exemple #3
0
class IsoCutterPanel(QtWidgets.QWidget, Ui_IsoCutterPanelBase):
    """For controling parameters of a iso surface """

    sigVisibiliyToggled = pyqtSignal()
    sigEditColorMap = pyqtSignal()

    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        Ui_IsoCutterPanelBase.__init__(self)
        self.setupUi(self)
        #current object key
        self.__key = -1

        #default setting of the panel
        self.vrpCheckBoxMapVariable.setEnabled(False)
        self.vrpComboBoxVariable.setEnabled(False)
        self.visibilityCheckBox.setVisible(
            covise.coConfigIsOn("vr-prepare.AdditionalVisibilityCheckbox",
                                False))

        self.__baseVariable = None

        #temporary storage of this parameter part
        self.colorCreator = {}

        middleFloatInRangeCtrls = [self.floatInRangeIsoValue]
        self.__boundingBox = Box()
        for w, r in zip(middleFloatInRangeCtrls,
                        self.__boundingBox.getTuple()):
            w.setRange(r)
        sideRange = 0, self.__heuristicProbeMaxSideLengthFromBox(
            self.__boundingBox.getTuple())

        IsoCutterPanelConnector(self)

    def setSelectedColormap(self, callerKey, key, name):
        # new colormap was selected in color manager
        if (self.__key == callerKey):
            if MainWindow.globalColorManager.setSelectedColormapKey(
                    self.colorMapCombobox, key):
                self.emitValueChange()

    def paramChanged(self, key):
        ''' params of the object with key changed '''
        if self.__key == key:
            self.update()

    def update(self):
        if self.__key != -1:
            self.updateForObject(self.__key)

    def updateForObject(self, key):
        """ called from MainWindow to update the content to the choosen object key """
        self.__key = key
        params = ObjectMgr().getParamsOfObject(key)
        self.__set2ndVariable(
            ObjectMgr().getPossibleScalarVariablesForVisItem(key))
        self.__setParams(params)

    def __getParams(self):
        ''' convert information in the panel into the right negotiator param classes '''
        data = PartIsoCutterVisParams()

        #data.vector = self.__vector
        data.name = str(self.nameWidget.text())
        data.isVisible = self.visibilityCheckBox.isChecked()
        data.variable = str(self.vrpLineEditVariable.text())
        data.colorTableKey = self.colorCreator
        if self.vrpCheckBoxMapVariable.isChecked():
            data.secondVariable = str(self.vrpComboBoxVariable.currentText())
            if data.secondVariable != "" and data.colorTableKey != None and data.secondVariable in data.colorTableKey and self.__baseVariable and self.__baseVariable == data.secondVariable:
                data.colorTableKey[
                    data.
                    secondVariable] = MainWindow.globalColorManager.getSelectedColormapKey(
                        self.colorMapCombobox)
        else:
            if self.__baseVariable and self.__baseVariable == data.variable and data.colorTableKey:
                data.colorTableKey[
                    data.
                    variable] = MainWindow.globalColorManager.getSelectedColormapKey(
                        self.colorMapCombobox)
        data.isovalue = self.floatInRangeIsoValue.getValue()
        data.cutoff_side = self.checkBoxCutoffSide.isChecked()
        data.isomin = self.floatInRangeIsoValue.getRange()[0]
        data.isomax = self.floatInRangeIsoValue.getRange()[1]
        data.boundingBox = self.__boundingBox
        return data

    def __panelAccordingTaskType(self):
        pass

    def __set2ndVariable(self, varlist):
        """ fill the combobox to choose a variable to be mapped on the trace """
        self.vrpComboBoxVariable.clear()
        self.vrpComboBoxVariable.setEnabled(len(varlist) != 0)
        self.vrpCheckBoxMapVariable.setEnabled(len(varlist) != 0)
        for v in varlist:
            self.vrpComboBoxVariable.addItem(v)

    def __setParams(self, params):
        ''' updates the panel with the params of the negotiatior'''
        IsoCutterPanelBlockSignals(self, True)

        if isinstance(params, int):
            self.__key = params
            return

        #self.__vector = params.vector
        self.__panelAccordingTaskType()
        self.nameWidget.setText(params.name)

        if hasattr(params, 'isVisible'):
            self.visibilityCheckBox.setChecked(params.isVisible)
        if hasattr(params, 'variable'):
            self.vrpLineEditVariable.setText(params.variable)
        if hasattr(params, 'secondVariable') and params.secondVariable != None:
            self.vrpCheckBoxMapVariable.setChecked(True)
            self.vrpComboBoxVariable.setCurrentIndex(
                self.vrpComboBoxVariable.findText(params.secondVariable))
            currentVariable = params.secondVariable
        else:
            self.vrpCheckBoxMapVariable.setChecked(False)
            currentVariable = params.variable

        currentVariable = params.variable  # no second variable in this visualizer right now

        self.__baseVariable = currentVariable
        currentColorTableKey = None
        if currentVariable != None and params.colorTableKey != None and currentVariable in params.colorTableKey:
            currentColorTableKey = params.colorTableKey[currentVariable]
        MainWindow.globalColorManager.update(self.colorMapCombobox,
                                             currentVariable,
                                             currentColorTableKey)

        if hasattr(params.boundingBox, 'getXMin'):
            self.__boundingBox = params.boundingBox
            maxSideLength = self.__boundingBox.getMaxEdgeLength()

        self.colorCreator = params.colorTableKey

        self.floatInRangeIsoValue.setRange([params.isomin, params.isomax])
        self.floatInRangeIsoValue.setValue(params.isovalue)
        self.checkBoxCutoffSide.setChecked(params.cutoff_side)

        IsoCutterPanelBlockSignals(self, False)

    def emitNameChange(self, aQString=None):
        if self.__key != -1:
            MainWindow.globalAccessToTreeView.setItemData(
                self.__key, str(self.nameWidget.text()))
            self.emitValueChange()

    def emitVisibilityToggled(self, b):
        self.sigVisibiliyToggled.emit((b, ))
        self.emitValueChange(b)

    def emitCustomizeColorMap(self):
        self.sigEditColorMap.emit(
            self.__key,
            MainWindow.globalColorManager.getSelectedColormapKey(
                self.colorMapCombobox))

    def emitValueChange(self, val=False):
        if not self.__key == -1:
            Application.vrpApp.key2params[self.__key] = self.__getParams()
            ObjectMgr().setParams(self.__key, self.__getParams())
            theGuiMsgHandler().runObject(self.__key)

    def __heuristicProbeMaxSideLengthFromBox(self, bb):
        return math.sqrt((bb[0][1] - bb[0][0]) * (bb[0][1] - bb[0][0]) +
                         (bb[1][1] - bb[1][0]) * (bb[1][1] - bb[1][0]) +
                         (bb[2][1] - bb[2][0]) * (bb[2][1] - bb[2][0]))

    def __tr(self, s, c=None):
        return coTranslate(s)