Exemplo n.º 1
0
    def setupWidgets(self):
        self._text = QtWidgets.QLineEdit("Text")
        self._layout.addWidget(self._text)

        self._font_props = FontPropertiesWidget(self)
        self._layout.addWidget(self._font_props)

        self._color_picker = ColorPicker(self)

        layout = QtWidgets.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        lbl = QtWidgets.QLabel("Text color")
        layout.addWidget(lbl)

        self._color_btn = ColorButton()
        self._color_btn.setFixedWidth(64)
        layout.addWidget(self._color_btn)

        self._layout.addLayout(layout)

        self._layout.addStretch()

        self._text.textChanged.connect(self.onTextChanged)
        self._color_btn.clicked.connect(self.onColorClicked)
        self._color_picker.colorChanged.connect(self.onColorPicked)
Exemplo n.º 2
0
    def setupWidgets(self):
        self._gradient_bkgnd = QtWidgets.QCheckBox("Gradient background")
        self._gradient_bkgnd.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed
        )
        self._vtk_renderer.SetGradientBackground(False)
        self._layout.addWidget(self._gradient_bkgnd)

        layout = QtWidgets.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        lbl = QtWidgets.QLabel("Color")
        layout.addWidget(lbl)

        self._color_picker = ColorPicker(self)

        self._color_btn = ColorButton()
        qcolor = [0.321, 0.3411, 0.4313]
        self._color_btn.setColor(
            QtGui.QColor.fromRgbF(qcolor[0], qcolor[1], qcolor[2]))
        self._vtk_renderer.SetBackground(qcolor)
        layout.addWidget(self._color_btn)

        self._layout.addLayout(layout)

        layout = QtWidgets.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        lbl = QtWidgets.QLabel("Color 2")
        layout.addWidget(lbl)

        self._color_2_picker = ColorPicker(self)

        self._color_2_btn = ColorButton()
        qcolor = [0.321, 0.3411, 0.4313]
        self._color_2_btn.setColor(
            QtGui.QColor.fromRgbF(qcolor[0], qcolor[1], qcolor[2]))
        self._vtk_renderer.SetBackground2(qcolor)
        layout.addWidget(self._color_2_btn)

        self._layout.addLayout(layout)

        self._gradient_bkgnd.stateChanged.connect(self.onGradientBkgndChanged)
        self._color_btn.clicked.connect(self.onColorClicked)
        self._color_picker.colorChanged.connect(self.onColorChanged)
        self._color_2_btn.clicked.connect(self.onColor2Clicked)
        self._color_2_picker.colorChanged.connect(self.onColor2Changed)

        self._layout.addStretch()

        self.onGradientBkgndChanged(self._gradient_bkgnd.checkState())
Exemplo n.º 3
0
    def setupWidgets(self):
        self._layout = QtWidgets.QVBoxLayout()
        self._layout.setContentsMargins(20, 10, 20, 10)
        self._layout.setSpacing(8)

        self._color_picker = ColorPicker(self)
        self._color_picker.colorChanged.connect(self.onBlockColorPicked)

        self._setupBlocksWidgets()
        self._layout.addWidget(HLine())
        self._setupSidesetsWidgets()
        self._layout.addWidget(HLine())
        self._setupNodesetsWidgets()
        self._layout.addWidget(HLine())
        self._setupSummaryWidgets()
        self._layout.addWidget(HLine())
        self._setupRangeWidgets()
        self._layout.addWidget(HLine())

        self._layout.addStretch()
Exemplo n.º 4
0
class RootProps(PropsBase):
    """
    Properties page to display when root is selected
    """

    def __init__(self, renderer, parent=None):
        super().__init__(parent)
        self._vtk_renderer = renderer
        self.setupWidgets()

    def setupWidgets(self):
        self._gradient_bkgnd = QtWidgets.QCheckBox("Gradient background")
        self._gradient_bkgnd.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Fixed
        )
        self._vtk_renderer.SetGradientBackground(False)
        self._layout.addWidget(self._gradient_bkgnd)

        layout = QtWidgets.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        lbl = QtWidgets.QLabel("Color")
        layout.addWidget(lbl)

        self._color_picker = ColorPicker(self)

        self._color_btn = ColorButton()
        qcolor = [0.321, 0.3411, 0.4313]
        self._color_btn.setColor(
            QtGui.QColor.fromRgbF(qcolor[0], qcolor[1], qcolor[2]))
        self._vtk_renderer.SetBackground(qcolor)
        layout.addWidget(self._color_btn)

        self._layout.addLayout(layout)

        layout = QtWidgets.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        lbl = QtWidgets.QLabel("Color 2")
        layout.addWidget(lbl)

        self._color_2_picker = ColorPicker(self)

        self._color_2_btn = ColorButton()
        qcolor = [0.321, 0.3411, 0.4313]
        self._color_2_btn.setColor(
            QtGui.QColor.fromRgbF(qcolor[0], qcolor[1], qcolor[2]))
        self._vtk_renderer.SetBackground2(qcolor)
        layout.addWidget(self._color_2_btn)

        self._layout.addLayout(layout)

        self._gradient_bkgnd.stateChanged.connect(self.onGradientBkgndChanged)
        self._color_btn.clicked.connect(self.onColorClicked)
        self._color_picker.colorChanged.connect(self.onColorChanged)
        self._color_2_btn.clicked.connect(self.onColor2Clicked)
        self._color_2_picker.colorChanged.connect(self.onColor2Changed)

        self._layout.addStretch()

        self.onGradientBkgndChanged(self._gradient_bkgnd.checkState())

    def onColorClicked(self):
        qcolor = self._color_btn.color()
        self._color_picker.setColor(qcolor)
        self._color_picker.show()

    def onColorChanged(self, qcolor):
        self._color_btn.setColor(qcolor)
        clr = [
            qcolor.redF(),
            qcolor.greenF(),
            qcolor.blueF()
        ]
        self._vtk_renderer.SetBackground(clr)

    def onColor2Clicked(self):
        qcolor = self._color_2_btn.color()
        self._color_2_picker.setColor(qcolor)
        self._color_2_picker.show()

    def onColor2Changed(self, qcolor):
        self._color_2_btn.setColor(qcolor)
        clr = [
            qcolor.redF(),
            qcolor.greenF(),
            qcolor.blueF()
        ]
        self._vtk_renderer.SetBackground2(clr)

    def onGradientBkgndChanged(self, state):
        if state == QtCore.Qt.Checked:
            self._vtk_renderer.SetGradientBackground(True)
            self._color_2_btn.setEnabled(True)
        else:
            self._vtk_renderer.SetGradientBackground(False)
            self._color_2_btn.setEnabled(False)
Exemplo n.º 5
0
class InfoWindow(QtWidgets.QScrollArea):
    """
    Window for showing mesh info
    """

    IDX_NAME = 0
    IDX_COLOR = 1
    IDX_ID = 2

    blockVisibilityChanged = QtCore.pyqtSignal(int, object)
    sidesetVisibilityChanged = QtCore.pyqtSignal(int, object)
    sidesetSelectionChanged = QtCore.pyqtSignal(int)
    nodesetVisibilityChanged = QtCore.pyqtSignal(int, object)
    nodesetSelectionChanged = QtCore.pyqtSignal(int)
    blockColorChanged = QtCore.pyqtSignal(int, object)
    blockSelectionChanged = QtCore.pyqtSignal(int)
    dimensionsStateChanged = QtCore.pyqtSignal(bool)

    def __init__(self, plugin, parent=None):
        super().__init__(parent)
        self.plugin = plugin

        self._colors = [[156, 207, 237], [165, 165, 165], [60, 97, 180],
                        [234, 234, 234], [197, 226, 243], [127, 127, 127],
                        [250, 182, 0]]

        self.setupWidgets()

        w = QtWidgets.QWidget()
        w.setLayout(self._layout)
        self.setWidget(w)
        self.setWindowTitle("Info")
        self.setFixedWidth(300)
        self.setWidgetResizable(True)
        self.setWindowFlag(QtCore.Qt.Tool)

        geom = self.plugin.settings.value("info/geometry")
        default_size = QtCore.QSize(300, 700)
        if geom is None:
            self.resize(default_size)
        else:
            if not self.restoreGeometry(geom):
                self.resize(default_size)

        self.show()

    def _setupBlocksWidgets(self):
        self._lbl_info = QtWidgets.QLabel("Blocks")
        self._lbl_info.setStyleSheet("""
            color: #444;
            font-weight: bold;
            """)
        self._layout.addWidget(self._lbl_info)

        self._block_model = QtGui.QStandardItemModel()
        self._block_model.setHorizontalHeaderLabels(["Name", "", "ID"])
        self._block_model.itemChanged.connect(self.onBlockChanged)
        self._blocks = OTreeView()
        self._blocks.setFixedHeight(250)
        self._blocks.setRootIsDecorated(False)
        self._blocks.setModel(self._block_model)
        self._blocks.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        self._blocks.setColumnWidth(0, 170)
        self._blocks.setColumnWidth(1, 20)
        self._blocks.setColumnWidth(2, 40)
        self._blocks.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self._blocks.customContextMenuRequested.connect(
            self.onBlockCustomContextMenu)
        sel_model = self._blocks.selectionModel()
        sel_model.selectionChanged.connect(self.onBlockSelectionChanged)
        self._layout.addWidget(self._blocks)

    def _setupSidesetsWidgets(self):
        self._sideset_model = QtGui.QStandardItemModel()
        self._sideset_model.setHorizontalHeaderLabels(["Name", "", "ID"])
        self._sideset_model.itemChanged.connect(self.onSidesetChanged)
        self._sidesets = OTreeView()
        self._sidesets.setFixedHeight(150)
        self._sidesets.setRootIsDecorated(False)
        self._sidesets.setModel(self._sideset_model)
        self._sidesets.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        self._sidesets.setColumnWidth(0, 190)
        self._sidesets.setColumnWidth(2, 40)
        self._sidesets.hideColumn(self.IDX_COLOR)
        sel_model = self._sidesets.selectionModel()
        sel_model.selectionChanged.connect(self.onSidesetSelectionChanged)

        self._sidesets_expd = ExpandableWidget("Side sets")
        self._sidesets_expd.setWidget(self._sidesets)
        self._layout.addWidget(self._sidesets_expd)

    def _setupNodesetsWidgets(self):
        self._nodesets = OTreeView()
        self._nodeset_model = QtGui.QStandardItemModel()
        self._nodeset_model.setHorizontalHeaderLabels(["Name", "", "ID"])
        self._nodeset_model.itemChanged.connect(self.onNodesetChanged)
        self._nodesets.setFixedHeight(150)
        self._nodesets.setRootIsDecorated(False)
        self._nodesets.setModel(self._nodeset_model)
        self._nodesets.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        self._nodesets.setColumnWidth(0, 190)
        self._nodesets.setColumnWidth(2, 40)
        self._nodesets.hideColumn(self.IDX_COLOR)
        sel_model = self._nodesets.selectionModel()
        sel_model.selectionChanged.connect(self.onNodesetSelectionChanged)

        self._nodesets_expd = ExpandableWidget("Node sets")
        self._nodesets_expd.setWidget(self._nodesets)
        self._layout.addWidget(self._nodesets_expd)

    def _setupSummaryWidgets(self):
        self._totals = QtWidgets.QTreeWidget()
        self._totals.setFixedHeight(60)
        self._totals.setIndentation(0)
        self._totals.setHeaderLabels(["Total", "Count"])
        self._total_elements = QtWidgets.QTreeWidgetItem(["Elements", ""])
        self._totals.addTopLevelItem(self._total_elements)
        self._total_nodes = QtWidgets.QTreeWidgetItem(["Nodes", ""])
        self._totals.addTopLevelItem(self._total_nodes)

        self._totals_expd = ExpandableWidget("Summary")
        self._totals_expd.setWidget(self._totals)
        self._layout.addWidget(self._totals_expd)

    def _setupRangeWidgets(self):
        layout = QtWidgets.QVBoxLayout()
        layout.setSpacing(8)
        layout.setContentsMargins(0, 0, 0, 0)
        self._range = QtWidgets.QTreeWidget()
        self._range.setFixedHeight(80)
        self._range.setIndentation(0)
        self._range.setHeaderLabels(["Dimension", "Range"])
        self._x_range = QtWidgets.QTreeWidgetItem(["X", ""])
        self._range.addTopLevelItem(self._x_range)
        self._y_range = QtWidgets.QTreeWidgetItem(["Y", ""])
        self._range.addTopLevelItem(self._y_range)
        self._z_range = QtWidgets.QTreeWidgetItem(["Z", ""])
        self._range.addTopLevelItem(self._z_range)
        layout.addWidget(self._range)

        self._dimensions = QtWidgets.QCheckBox("Show dimensions")
        self._dimensions.stateChanged.connect(self.onDimensionsStateChanged)
        layout.addWidget(self._dimensions)

        w = QtWidgets.QWidget()
        w.setLayout(layout)

        self._range_expd = ExpandableWidget("Dimensions")
        self._range_expd.setWidget(w)
        self._layout.addWidget(self._range_expd)

    def setupWidgets(self):
        self._layout = QtWidgets.QVBoxLayout()
        self._layout.setContentsMargins(20, 10, 20, 10)
        self._layout.setSpacing(8)

        self._color_picker = ColorPicker(self)
        self._color_picker.colorChanged.connect(self.onBlockColorPicked)

        self._setupBlocksWidgets()
        self._layout.addWidget(HLine())
        self._setupSidesetsWidgets()
        self._layout.addWidget(HLine())
        self._setupNodesetsWidgets()
        self._layout.addWidget(HLine())
        self._setupSummaryWidgets()
        self._layout.addWidget(HLine())
        self._setupRangeWidgets()
        self._layout.addWidget(HLine())

        self._layout.addStretch()

    def event(self, event):
        if event.type() == QtCore.QEvent.WindowActivate:
            self.plugin.updateMenuBar()
        return super().event(event)

    def closeEvent(self, event):
        self.plugin.settings.setValue("info/geometry", self.saveGeometry())
        event.accept()

    def _loadBlocks(self, blocks):
        self._block_model.removeRows(0, self._block_model.rowCount())
        for index, blk in enumerate(blocks):
            row = self._block_model.rowCount()

            si_name = QtGui.QStandardItem()
            si_name.setText(blk.name)
            si_name.setCheckable(True)
            si_name.setCheckState(QtCore.Qt.Checked)
            si_name.setData(blk)
            self._block_model.setItem(row, self.IDX_NAME, si_name)

            si_clr = QtGui.QStandardItem()
            si_clr.setText('\u25a0')
            clr_idx = index % len(self._colors)
            rgb = self._colors[clr_idx]
            color = QtGui.QColor(rgb[0], rgb[1], rgb[2])
            si_clr.setForeground(QtGui.QBrush(color))
            si_clr.setData(color)
            self._block_model.setItem(row, self.IDX_COLOR, si_clr)

            si_id = QtGui.QStandardItem()
            si_id.setText(str(blk.number))
            self._block_model.setItem(row, self.IDX_ID, si_id)

    def _loadSideSets(self, sidesets):
        self._sideset_model.removeRows(0, self._sideset_model.rowCount())
        for index, ss in enumerate(sidesets):
            row = self._sideset_model.rowCount()

            si_name = QtGui.QStandardItem()
            si_name.setText(ss.name)
            si_name.setCheckable(True)
            si_name.setData(ss)
            self._sideset_model.setItem(row, self.IDX_NAME, si_name)

            si_id = QtGui.QStandardItem()
            si_id.setText(str(ss.number))
            self._sideset_model.setItem(row, self.IDX_ID, si_id)

    def _loadNodeSets(self, nodesets):
        self._nodeset_model.removeRows(0, self._nodeset_model.rowCount())
        for index, ns in enumerate(nodesets):
            row = self._nodeset_model.rowCount()

            si_name = QtGui.QStandardItem()
            si_name.setText(ns.name)
            si_name.setCheckable(True)
            si_name.setData(ns)
            self._nodeset_model.setItem(row, self.IDX_NAME, si_name)

            si_id = QtGui.QStandardItem()
            si_id.setText(str(ns.number))
            self._nodeset_model.setItem(row, self.IDX_ID, si_id)

    def _fillSummary(self, params):
        total_elems = params['total_elems']
        self._total_elements.setText(1, "{:,}".format(total_elems))
        total_nodes = params['total_nodes']
        self._total_nodes.setText(1, "{:,}".format(total_nodes))

    def onFileLoaded(self, params):
        if params is None:
            self.clear()
        else:
            self._loadBlocks(params['blocks'])
            self._loadSideSets(params['sidesets'])
            self._loadNodeSets(params['nodesets'])
            self._fillSummary(params)

    def onBlockChanged(self, item):
        if item.column() == self.IDX_NAME:
            visible = item.checkState() == QtCore.Qt.Checked
            block_info = item.data()
            self.blockVisibilityChanged.emit(block_info.number, visible)
        elif item.column() == self.IDX_COLOR:
            color = item.foreground().color()
            index = self._block_model.indexFromItem(item)
            name_index = index.siblingAtColumn(self.IDX_NAME)
            block_info = self._block_model.itemFromIndex(name_index).data()
            self.blockColorChanged.emit(block_info.number, color)

    def _onNameContextMenu(self, item, point):
        menu = QtWidgets.QMenu()
        if item.checkState() == QtCore.Qt.Checked:
            menu.addAction("Hide", self.onHideBlock)
            menu.addAction("Hide others", self.onHideOtherBlocks)
            menu.addAction("Hide all", self.onHideAllBlocks)
        else:
            menu.addAction("Show", self.onShowBlock)
            menu.addAction("Show all", self.onShowAllBlocks)
        menu.addSeparator()
        menu.addAction("Appearance...", self.onAppearance)
        menu.exec(point)

    def onBlockCustomContextMenu(self, point):
        index = self._blocks.indexAt(point)
        if index.isValid():
            item = self._block_model.itemFromIndex(index)
            self._onNameContextMenu(item,
                                    self._blocks.viewport().mapToGlobal(point))

    def onAppearance(self):
        selection_model = self._blocks.selectionModel()
        indexes = selection_model.selectedIndexes()
        if len(indexes) == 0:
            return
        index = indexes[0]
        clr_index = index.siblingAtColumn(self.IDX_COLOR)
        qcolor = self._block_model.itemFromIndex(clr_index).data()
        self._color_picker.setData(clr_index)
        self._color_picker.setColor(qcolor)
        self._color_picker.show()

    def onBlockColorPicked(self, qcolor):
        index = self._color_picker.data()
        item = self._block_model.itemFromIndex(index)
        item.setForeground(QtGui.QBrush(qcolor))
        item.setData(qcolor)

    def onSidesetChanged(self, item):
        if item.column() == self.IDX_NAME:
            visible = item.checkState() == QtCore.Qt.Checked
            sideset_info = item.data()
            self.sidesetVisibilityChanged.emit(sideset_info.number, visible)

    def onNodesetChanged(self, item):
        if item.column() == self.IDX_NAME:
            visible = item.checkState() == QtCore.Qt.Checked
            nodeset_info = item.data()
            self.nodesetVisibilityChanged.emit(nodeset_info.number, visible)

    def onDimensionsStateChanged(self, state):
        self.dimensionsStateChanged.emit(state == QtCore.Qt.Checked)

    def onBoundsChanged(self, bnds):
        if len(bnds) == 6:
            x_range = "{:.5f} to {:.5f}".format(bnds[0], bnds[1])
            self._x_range.setText(1, x_range)
            y_range = "{:.5f} to {:.5f}".format(bnds[2], bnds[3])
            self._y_range.setText(1, y_range)
            z_range = "{:.5f} to {:.5f}".format(bnds[4], bnds[5])
            self._z_range.setText(1, z_range)
        else:
            self._x_range.setText(1, "")
            self._y_range.setText(1, "")
            self._z_range.setText(1, "")

    def clear(self):
        self._block_model.removeRows(0, self._block_model.rowCount())
        self._sideset_model.removeRows(0, self._sideset_model.rowCount())
        self._nodeset_model.removeRows(0, self._nodeset_model.rowCount())

        self._total_elements.setText(1, "")
        self._total_nodes.setText(1, "")

    def onHideBlock(self):
        selection_model = self._blocks.selectionModel()
        indexes = selection_model.selectedIndexes()
        if len(indexes) > 0:
            index = indexes[0]
            item = self._block_model.itemFromIndex(index)
            item.setCheckState(QtCore.Qt.Unchecked)

    def onHideOtherBlocks(self):
        selection_model = self._blocks.selectionModel()
        indexes = selection_model.selectedIndexes()
        if len(indexes) > 0:
            index = indexes[0]
            for row in range(self._block_model.rowCount()):
                if row != index.row():
                    item = self._block_model.item(row, 0)
                    item.setCheckState(QtCore.Qt.Unchecked)

    def onHideAllBlocks(self):
        for row in range(self._block_model.rowCount()):
            item = self._block_model.item(row, 0)
            item.setCheckState(QtCore.Qt.Unchecked)

    def onShowBlock(self):
        selection_model = self._blocks.selectionModel()
        indexes = selection_model.selectedIndexes()
        if len(indexes) > 0:
            index = indexes[0]
            item = self._block_model.itemFromIndex(index)
            item.setCheckState(QtCore.Qt.Checked)

    def onShowAllBlocks(self):
        for row in range(self._block_model.rowCount()):
            item = self._block_model.item(row, 0)
            item.setCheckState(QtCore.Qt.Checked)

    def onBlockSelectionChanged(self, selected, deselected):
        if len(selected.indexes()) > 0:
            self._sidesets.clearSelection()
            self._nodesets.clearSelection()
            index = selected.indexes()[0]
            info = self._block_model.itemFromIndex(index).data()
            self.blockSelectionChanged.emit(info.number)
        else:
            self.blockSelectionChanged.emit(None)

    def onSidesetSelectionChanged(self, selected, deselected):
        if len(selected.indexes()) > 0:
            self._blocks.clearSelection()
            self._nodesets.clearSelection()
            index = selected.indexes()[0]
            info = self._sideset_model.itemFromIndex(index).data()
            self.sidesetSelectionChanged.emit(info.number)
        else:
            self.sidesetSelectionChanged.emit(None)

    def onNodesetSelectionChanged(self, selected, deselected):
        if len(selected.indexes()) > 0:
            self._blocks.clearSelection()
            self._sidesets.clearSelection()
            index = selected.indexes()[0]
            info = self._nodeset_model.itemFromIndex(index).data()
            self.nodesetSelectionChanged.emit(info.number)
        else:
            self.nodesetSelectionChanged.emit(None)
Exemplo n.º 6
0
class TextProps(PropsBase):
    """
    Properties page to display when nothing is selected
    """
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupWidgets()
        self.buildVtkActor()

    def getVtkActor(self):
        return self._actor

    def setupWidgets(self):
        self._text = QtWidgets.QLineEdit("Text")
        self._layout.addWidget(self._text)

        self._font_props = FontPropertiesWidget(self)
        self._layout.addWidget(self._font_props)

        self._color_picker = ColorPicker(self)

        layout = QtWidgets.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        lbl = QtWidgets.QLabel("Text color")
        layout.addWidget(lbl)

        self._color_btn = ColorButton()
        self._color_btn.setFixedWidth(64)
        layout.addWidget(self._color_btn)

        self._layout.addLayout(layout)

        self._layout.addStretch()

        self._text.textChanged.connect(self.onTextChanged)
        self._color_btn.clicked.connect(self.onColorClicked)
        self._color_picker.colorChanged.connect(self.onColorPicked)

    def buildVtkActor(self):
        self._actor = vtk.vtkTextActor()
        self._actor.SetInput(self._text.text())
        self._actor.SetPickable(True)
        self._actor.SetDragable(True)
        self._text_property = self._actor.GetTextProperty()
        qcolor = self._color_picker.color()
        clr = [qcolor.redF(), qcolor.greenF(), qcolor.blueF()]
        self._text_property.SetColor(clr)
        self._text_property.SetBold(False)
        self._text_property.SetItalic(False)
        self._color_btn.setColor(qcolor)
        self._font_props.setVtkTextProperty(self._text_property)

    def onTextChanged(self, txt):
        self._actor.SetInput(txt)

    def onColorClicked(self):
        qcolor = self._color_btn.color()
        self._color_picker.setColor(qcolor)
        self._color_picker.show()

    def onColorPicked(self, qcolor):
        clr = [qcolor.redF(), qcolor.greenF(), qcolor.blueF()]
        self._text_property.SetColor(clr)
        self._color_btn.setColor(qcolor)
Exemplo n.º 7
0
    def setupWidgets(self):
        self._layout = QtWidgets.QVBoxLayout(self)
        self._layout.setContentsMargins(20, 10, 20, 10)

        self._lbl_blocks = QtWidgets.QLabel("Components")
        self._layout.addWidget(self._lbl_blocks)
        self._component_model = QtGui.QStandardItemModel()
        self._component_model.setHorizontalHeaderLabels(["Name", "", "Type"])
        self._component_model.itemChanged.connect(self.onComponentChanged)
        self._components = QtWidgets.QTreeView()
        self._components.setFixedHeight(300)
        self._components.setRootIsDecorated(False)
        self._components.setModel(self._component_model)
        self._components.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        self._components.setColumnWidth(0, 180)
        self._components.setColumnWidth(1, 20)
        self._components.setColumnWidth(2, 70)
        self._components.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self._components.customContextMenuRequested.connect(
            self.onComponentCustomContextMenu)
        sel_model = self._components.selectionModel()
        sel_model.currentChanged.connect(self.onComponentCurrentChanged)
        self._layout.addWidget(self._components)

        self._color_picker = ColorPicker(self)
        self._color_picker.colorChanged.connect(self.onComponentColorPicked)

        self._lbl_dimensions = QtWidgets.QLabel("Dimensions")
        self._layout.addWidget(self._lbl_dimensions)

        self._range = QtWidgets.QTreeWidget()
        self._range.setFixedHeight(80)
        self._range.setIndentation(0)
        self._range.setHeaderLabels(["Direction", "Range"])
        self._x_range = QtWidgets.QTreeWidgetItem(["X", "0"])
        self._range.addTopLevelItem(self._x_range)
        self._y_range = QtWidgets.QTreeWidgetItem(["Y", "0"])
        self._range.addTopLevelItem(self._y_range)
        self._z_range = QtWidgets.QTreeWidgetItem(["Z", "0"])
        self._range.addTopLevelItem(self._z_range)
        self._layout.addWidget(self._range)

        self._show_pps = QtWidgets.QCheckBox("Show postprocessors")
        self._show_pps.stateChanged.connect(self.onPPSLocationsStateChanged)
        self._layout.addWidget(self._show_pps)

        self._dimensions = QtWidgets.QCheckBox("Show dimensions")
        self._dimensions.stateChanged.connect(self.onDimensionsStateChanged)
        self._layout.addWidget(self._dimensions)

        self._show_labels = QtWidgets.QCheckBox("Show labels")
        self._show_labels.stateChanged.connect(self.onShowLabelsStateChanged)
        self._layout.addWidget(self._show_labels)

        self._ori_marker = QtWidgets.QCheckBox("Orientation marker")
        self._ori_marker.stateChanged.connect(self.onOriMarkerStateChanged)
        self._ori_marker.setCheckState(QtCore.Qt.Checked)
        self._layout.addWidget(self._ori_marker)

        self._layout.addStretch()
Exemplo n.º 8
0
class InfoWindow(QtWidgets.QScrollArea):
    """
    Window for showing model info
    """

    IDX_NAME = 0
    IDX_COLOR = 1
    IDX_TYPE = 2

    componentVisibilityChanged = QtCore.pyqtSignal(str, object)
    componentColorChanged = QtCore.pyqtSignal(str, object)
    componentSelected = QtCore.pyqtSignal(object)
    dimensionsStateChanged = QtCore.pyqtSignal(bool)
    orientationMarkerStateChanged = QtCore.pyqtSignal(bool)
    showLabels = QtCore.pyqtSignal(bool)
    showPPS = QtCore.pyqtSignal(bool)

    def __init__(self, plugin):
        super().__init__()
        self.plugin = plugin

        self._colors = [[156, 207, 237], [165, 165, 165], [60, 97, 180],
                        [234, 234, 234], [197, 226, 243], [127, 127, 127],
                        [250, 182, 0]]

        self.setupWidgets()

        w = QtWidgets.QWidget()
        w.setLayout(self._layout)
        self.setWidget(w)
        self.setWindowTitle("Info")
        self.setMinimumWidth(350)
        self.setWidgetResizable(True)
        self.setWindowFlags(QtCore.Qt.Tool)

        geom = self.plugin.settings.value("info/geometry")
        default_size = QtCore.QSize(350, 700)
        if geom is None:
            self.resize(default_size)
        else:
            if not self.restoreGeometry(geom):
                self.resize(default_size)

        self.show()

    def setupWidgets(self):
        self._layout = QtWidgets.QVBoxLayout(self)
        self._layout.setContentsMargins(20, 10, 20, 10)

        self._lbl_blocks = QtWidgets.QLabel("Components")
        self._layout.addWidget(self._lbl_blocks)
        self._component_model = QtGui.QStandardItemModel()
        self._component_model.setHorizontalHeaderLabels(["Name", "", "Type"])
        self._component_model.itemChanged.connect(self.onComponentChanged)
        self._components = QtWidgets.QTreeView()
        self._components.setFixedHeight(300)
        self._components.setRootIsDecorated(False)
        self._components.setModel(self._component_model)
        self._components.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        self._components.setColumnWidth(0, 180)
        self._components.setColumnWidth(1, 20)
        self._components.setColumnWidth(2, 70)
        self._components.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self._components.customContextMenuRequested.connect(
            self.onComponentCustomContextMenu)
        sel_model = self._components.selectionModel()
        sel_model.currentChanged.connect(self.onComponentCurrentChanged)
        self._layout.addWidget(self._components)

        self._color_picker = ColorPicker(self)
        self._color_picker.colorChanged.connect(self.onComponentColorPicked)

        self._lbl_dimensions = QtWidgets.QLabel("Dimensions")
        self._layout.addWidget(self._lbl_dimensions)

        self._range = QtWidgets.QTreeWidget()
        self._range.setFixedHeight(80)
        self._range.setIndentation(0)
        self._range.setHeaderLabels(["Direction", "Range"])
        self._x_range = QtWidgets.QTreeWidgetItem(["X", "0"])
        self._range.addTopLevelItem(self._x_range)
        self._y_range = QtWidgets.QTreeWidgetItem(["Y", "0"])
        self._range.addTopLevelItem(self._y_range)
        self._z_range = QtWidgets.QTreeWidgetItem(["Z", "0"])
        self._range.addTopLevelItem(self._z_range)
        self._layout.addWidget(self._range)

        self._show_pps = QtWidgets.QCheckBox("Show postprocessors")
        self._show_pps.stateChanged.connect(self.onPPSLocationsStateChanged)
        self._layout.addWidget(self._show_pps)

        self._dimensions = QtWidgets.QCheckBox("Show dimensions")
        self._dimensions.stateChanged.connect(self.onDimensionsStateChanged)
        self._layout.addWidget(self._dimensions)

        self._show_labels = QtWidgets.QCheckBox("Show labels")
        self._show_labels.stateChanged.connect(self.onShowLabelsStateChanged)
        self._layout.addWidget(self._show_labels)

        self._ori_marker = QtWidgets.QCheckBox("Orientation marker")
        self._ori_marker.stateChanged.connect(self.onOriMarkerStateChanged)
        self._ori_marker.setCheckState(QtCore.Qt.Checked)
        self._layout.addWidget(self._ori_marker)

        self._layout.addStretch()

    def event(self, event):
        if event.type() == QtCore.QEvent.WindowActivate:
            self.plugin.updateMenuBar()
        return super().event(event)

    def closeEvent(self, event):
        self.plugin.settings.setValue("info/geometry", self.saveGeometry())
        event.accept()

    def _loadComponents(self, comps):
        self._component_model.removeRows(0, self._component_model.rowCount())
        for index, comp in enumerate(comps):
            if isinstance(comp, components.InvisibleComponent):
                continue

            row = self._component_model.rowCount()

            si_name = QtGui.QStandardItem()
            si_name.setText(comp.name)
            si_name.setCheckable(True)
            si_name.setCheckState(QtCore.Qt.Checked)
            si_name.setData(comp)
            self._component_model.setItem(row, self.IDX_NAME, si_name)

            si_clr = QtGui.QStandardItem()
            si_clr.setText('\u25a0')
            clr_idx = index % len(self._colors)
            rgb = self._colors[clr_idx]
            color = QtGui.QColor(rgb[0], rgb[1], rgb[2])
            si_clr.setForeground(QtGui.QBrush(color))
            si_clr.setData(color)
            self._component_model.setItem(row, self.IDX_COLOR, si_clr)

            si_type = QtGui.QStandardItem()
            si_type.setText(comp.type)
            self._component_model.setItem(row, self.IDX_TYPE, si_type)

    def onFileLoaded(self, components):
        if components is None:
            self.clear()
        else:
            self._loadComponents(components)

    def onComponentChanged(self, item):
        if item.column() == self.IDX_NAME:
            visible = item.checkState() == QtCore.Qt.Checked
            comp = item.data()
            self.componentVisibilityChanged.emit(comp.name, visible)
        elif item.column() == self.IDX_COLOR:
            color = item.foreground().color()
            index = self._component_model.indexFromItem(item)
            name_index = index.siblingAtColumn(self.IDX_NAME)
            comp = self._component_model.itemFromIndex(name_index).data()
            self.componentColorChanged.emit(comp.name, color)

    def onComponentColorPicked(self, qcolor):
        index = self._color_picker.data()
        item = self._component_model.itemFromIndex(index)
        item.setForeground(QtGui.QBrush(qcolor))
        item.setData(qcolor)

    def onDimensionsStateChanged(self, state):
        self.dimensionsStateChanged.emit(state == QtCore.Qt.Checked)

    def onBoundsChanged(self, bnds):
        if len(bnds) == 6:
            x_range = "{:.5f} to {:.5f}".format(bnds[0], bnds[1])
            self._x_range.setText(1, x_range)
            y_range = "{:.5f} to {:.5f}".format(bnds[2], bnds[3])
            self._y_range.setText(1, y_range)
            z_range = "{:.5f} to {:.5f}".format(bnds[4], bnds[5])
            self._z_range.setText(1, z_range)
        else:
            self._x_range.setText(1, "")
            self._y_range.setText(1, "")
            self._z_range.setText(1, "")

    def onOriMarkerStateChanged(self, state):
        self.orientationMarkerStateChanged.emit(state == QtCore.Qt.Checked)

    def clear(self):
        self._component_model.removeRows(0, self._component_model.rowCount())

    def onComponentSelected(self, comp_name):
        self._components.blockSignals(True)
        if comp_name is None:
            self._components.clearSelection()
        else:
            items = self._component_model.findItems(comp_name)
            if len(items) == 1:
                index = self._component_model.indexFromItem(items[0])
                self._components.setCurrentIndex(index)
        self._components.blockSignals(False)

    def onComponentCurrentChanged(self, current, previous):
        item = self._component_model.itemFromIndex(current)
        if item is not None:
            comp_name = item.text()
            self.componentSelected.emit(comp_name)

    def _onNameContextMenu(self, item, point):
        menu = QtWidgets.QMenu()
        menu.addAction("Appearance...", self.onAppearance)
        menu.exec(point)

    def onComponentCustomContextMenu(self, point):
        index = self._components.indexAt(point)
        if index.isValid():
            item = self._component_model.itemFromIndex(index)
            self._onNameContextMenu(
                item,
                self._components.viewport().mapToGlobal(point))

    def onAppearance(self):
        selection_model = self._components.selectionModel()
        indexes = selection_model.selectedIndexes()
        if len(indexes) == 0:
            return
        index = indexes[0]
        clr_index = index.siblingAtColumn(self.IDX_COLOR)
        qcolor = self._component_model.itemFromIndex(clr_index).data()
        self._color_picker.setData(clr_index)
        self._color_picker.setColor(qcolor)
        self._color_picker.show()

    def onShowLabelsStateChanged(self, state):
        self.showLabels.emit(state == QtCore.Qt.Checked)

    def onPPSLocationsStateChanged(self, state):
        self.showPPS.emit(state == QtCore.Qt.Checked)