예제 #1
0
 def draw_layout(
     self,
     layout_name: str,
     reset_view: bool = True,
 ):
     print(f"drawing {layout_name}")
     self._current_layout = layout_name
     self.view.begin_loading()
     new_scene = qw.QGraphicsScene()
     self._backend.set_scene(new_scene)
     layout = self.doc.layout(layout_name)
     self._update_render_context(layout)
     try:
         start = time.perf_counter()
         self.create_frontend().draw_layout(layout)
         duration = time.perf_counter() - start
         print(f"took {duration:.4f} seconds")
     except DXFStructureError as e:
         qw.QMessageBox.critical(
             self,
             "DXF Structure Error",
             f'Abort rendering of layout "{layout_name}": {str(e)}',
         )
     finally:
         self._backend.finalize()
     self.view.end_loading(new_scene)
     self.view.buffer_scene_rect()
     if reset_view:
         self.view.fit_to_scene()
예제 #2
0
    def __init__(self, config: Configuration = Configuration.defaults()):
        super().__init__()
        self._config = config
        self.doc = None
        self._render_context = None
        self._visible_layers = None
        self._current_layout = None
        self._reset_backend()

        self.view = CADGraphicsViewWithOverlay()
        self.view.setScene(qw.QGraphicsScene())
        self.view.scale(1, -1)  # so that +y is up
        self.view.element_selected.connect(self._on_element_selected)
        self.view.mouse_moved.connect(self._on_mouse_moved)

        menu = self.menuBar()
        select_doc_action = QAction("Select Document", self)
        select_doc_action.triggered.connect(self._select_doc)
        menu.addAction(select_doc_action)
        self.select_layout_menu = menu.addMenu("Select Layout")

        toggle_sidebar_action = QAction("Toggle Sidebar", self)
        toggle_sidebar_action.triggered.connect(self._toggle_sidebar)
        menu.addAction(toggle_sidebar_action)

        self.sidebar = qw.QSplitter(qc.Qt.Vertical)
        self.layers = qw.QListWidget()
        self.layers.setStyleSheet(
            "QListWidget {font-size: 12pt;} "
            "QCheckBox {font-size: 12pt; padding-left: 5px;}")
        self.sidebar.addWidget(self.layers)
        info_container = qw.QWidget()
        info_layout = qw.QVBoxLayout()
        info_layout.setContentsMargins(0, 0, 0, 0)
        self.selected_info = qw.QPlainTextEdit()
        self.selected_info.setReadOnly(True)
        info_layout.addWidget(self.selected_info)
        self.mouse_pos = qw.QLabel()
        info_layout.addWidget(self.mouse_pos)
        info_container.setLayout(info_layout)
        self.sidebar.addWidget(info_container)

        container = qw.QSplitter()
        self.setCentralWidget(container)
        container.addWidget(self.view)
        container.addWidget(self.sidebar)
        container.setCollapsible(0, False)
        container.setCollapsible(1, True)
        w = container.width()
        container.setSizes([int(3 * w / 4), int(w / 4)])

        self.setWindowTitle("CAD Viewer")
        self.resize(1600, 900)
        self.show()
예제 #3
0
    def __init__(
        self,
        scene: Optional[qw.QGraphicsScene] = None,
        *,
        use_text_cache: bool = True,
        debug_draw_rect: bool = False,
        extra_lineweight_scaling: float = 2.0,
    ):
        """
        Args:
            extra_lineweight_scaling: compared to other backends,
                PyQt draws lines which appear thinner
        """
        super().__init__()
        self._scene = scene or qw.QGraphicsScene()  # avoids many type errors
        self._color_cache: Dict[Color, qg.QColor] = {}
        self._pattern_cache: Dict[PatternKey, int] = {}
        self._no_line = qg.QPen(qc.Qt.NoPen)
        self._no_fill = qg.QBrush(qc.Qt.NoBrush)

        self._text_renderer = TextRenderer(qg.QFont(), use_text_cache)
        self._line_renderer: PyQtLineRenderer
        self._extra_lineweight_scaling = extra_lineweight_scaling
        self._debug_draw_rect = debug_draw_rect
예제 #4
0
def backend():
    global _app
    _app = qw.QApplication([])
    scene = qw.QGraphicsScene()
    return PyQtBackend(scene)