Skip to content

Commit

Permalink
update for the review
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacZhangzhuo committed Jan 11, 2024
1 parent 188abe8 commit 96b0d40
Show file tree
Hide file tree
Showing 17 changed files with 307 additions and 282 deletions.
25 changes: 24 additions & 1 deletion data/default_config/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@
},
"guid": "52a481b2-0a86-46df-92b2-dbd59e9cb7a6"
},
"guid": "52a481b2-0a86-45df-92b2-dbd59e9cb7a6"
"viewport": {
"dtype": "compas_viewer.configurations/ViewportConfig",
"data": {
"render_1": {
"category": "render",
"config_path": "render.json"
}
},

"guid": "52a481b2-0b86-45df-92b2-dbd59e9cb7a6"
},
"toolbar": {
"dtype": "compas_viewer.configurations/ToolBarConfig",
"data": {
"basic": {
"view_top": { "action": "view_top", "kwargs": {} }
},
"view": {
"view_top": { "action": "view_top", "kwargs": {} }
}
},

"guid": "42a481b2-0b86-45df-92b2-dbd59e9cb7a6"
}
},
"guid": "52a481b3-0a86-45df-92b0-dbd59e9cb7a6"
}
4 changes: 3 additions & 1 deletion src/compas_viewer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"-f",
"--files",
required=False,
help="The compas.geometry's JSON file, or the compressed JSON file (ZIP), or a the path to a folder containing the JSON files for the viewer to load.",
help="""
The compas.geometry's JSON file, or the compressed JSON file (ZIP),
or a the path to a folder containing the JSON files for the viewer to load.""",
)

args = vars(ap.parse_args())
Expand Down
2 changes: 1 addition & 1 deletion src/compas_viewer/actions/select_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class SelectAll(Action):
"""Look at action."""
"""Select all objects."""

def pressed_action(self):
for obj in self.viewer.objects:
Expand Down
11 changes: 8 additions & 3 deletions src/compas_viewer/components/renderer/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def viewmode(self, viewmode):
self.config.viewmode = viewmode
self.shader_model.bind()
self.shader_model.uniform4x4(
"projection", self.camera.projection(self.viewer.layout.config.window.width, self.viewer.layout.config.window.height)
"projection",
self.camera.projection(self.viewer.layout.config.window.width, self.viewer.layout.config.window.height),
)
self.shader_model.release()
self.camera.reset_position()
Expand Down Expand Up @@ -362,7 +363,9 @@ def init(self):
for obj in self.viewer.objects:
obj.init()

projection = self.camera.projection(self.viewer.layout.config.window.width, self.viewer.layout.config.window.height)
projection = self.camera.projection(
self.viewer.layout.config.window.width, self.viewer.layout.config.window.height
)
viewworld = self.camera.viewworld()
transform = list(identity(4, dtype=float32))
# create the program
Expand Down Expand Up @@ -391,7 +394,9 @@ def init(self):
self.shader_arrow.uniform4x4("viewworld", viewworld)
self.shader_arrow.uniform4x4("transform", transform)
self.shader_arrow.uniform1f("opacity", self.opacity)
self.shader_arrow.uniform1f("aspect", self.viewer.layout.config.window.width / self.viewer.layout.config.window.height)
self.shader_arrow.uniform1f(
"aspect", self.viewer.layout.config.window.width / self.viewer.layout.config.window.height
)
self.shader_arrow.release()

self.shader_instance = Shader(name="instance")
Expand Down
2 changes: 2 additions & 0 deletions src/compas_viewer/configurations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
from .layout_config import StatusBarConfig, StatusBarConfigType # noqa: F401
from .layout_config import WindowConfig, WindowConfigType # noqa: F401
from .layout_config import MenuBarConfig, MenuBarConfigType # noqa: F401
from .layout_config import ViewportConfig, ViewportConfigType # noqa: F401
from .layout_config import ToolBarConfig, ToolBarConfigType # noqa: F401
54 changes: 54 additions & 0 deletions src/compas_viewer/configurations/layout_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,56 @@ class MenuBarConfigType(TypedDict):
kwargs: List[str]


class ViewportConfigType(TypedDict):
"""
The type template for each single item of the viewport.
"""

category: Literal["render"]
config_path: str


class ToolBarConfigType(TypedDict):
"""
The type template for the each toolbar element.
"""

action: str
kwargs: dict


class ToolBarConfig(Config):
"""
The class representation for the toolbar configuration of the class :class:`compas_viewer.layout.ToolBarLayout`.
The toolbar configuration contains all the settings about the toolbar itself.
"""

def __init__(self, config: Dict[str, Dict[str, ToolBarConfigType]]):
super().__init__(config)

@classmethod
def from_json(cls, filepath) -> "ToolBarConfig":
toolbar_config = super().from_json(filepath)
assert isinstance(toolbar_config, ToolBarConfig)
return toolbar_config


class ViewportConfig(Config):
"""
The class representation for the menu bar configuration of the class :class:`compas_viewer.layout.ViewportLayout`.
The viewport configuration contains all the settings about the viewport itself: render, ...
"""

def __init__(self, config: Dict[str, Dict[str, ViewportConfigType]]):
super().__init__(config)

@classmethod
def from_json(cls, filepath) -> "ViewportConfig":
viewport_config = super().from_json(filepath)
assert isinstance(viewport_config, ViewportConfig)
return viewport_config


class MenuBarConfig(Config):
"""
The class representation for the menu bar configuration of the class :class:`compas_viewer.layout.Layout`.
Expand Down Expand Up @@ -111,6 +161,8 @@ class LayoutConfigType(TypedDict):
window: WindowConfig
statusbar: StatusBarConfig
menubar: MenuBarConfig
viewport: ViewportConfig
toolbar: ToolBarConfig


class LayoutConfig(Config):
Expand All @@ -129,6 +181,8 @@ def __init__(self, config: LayoutConfigType):
self.window = config["window"]
self.statusbar = config["statusbar"]
self.menubar = config["menubar"]
self.viewport = config["viewport"]
self.toolbar = config["toolbar"]

@classmethod
def from_default(cls) -> "LayoutConfig":
Expand Down
83 changes: 32 additions & 51 deletions src/compas_viewer/layout/layout.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,53 @@
from typing import TYPE_CHECKING

from PySide6.QtCore import QDate
from PySide6.QtCore import QDateTime
from PySide6.QtCore import QLocale
from PySide6.QtCore import QMetaObject
from PySide6.QtCore import QObject
from PySide6.QtCore import QPoint
from PySide6.QtCore import QRect
from PySide6.QtCore import QSize
from PySide6.QtCore import Qt
from PySide6.QtCore import QTime
from PySide6.QtCore import QUrl
from PySide6.QtGui import QAction
from PySide6.QtGui import QBrush
from PySide6.QtGui import QColor
from PySide6.QtGui import QConicalGradient
from PySide6.QtGui import QCursor
from PySide6.QtGui import QFont
from PySide6.QtGui import QFontDatabase
from PySide6.QtGui import QGradient
from PySide6.QtGui import QIcon
from PySide6.QtGui import QImage
from PySide6.QtGui import QKeySequence
from PySide6.QtGui import QLinearGradient
from PySide6.QtGui import QPainter
from PySide6.QtGui import QPalette
from PySide6.QtGui import QPixmap
from PySide6.QtGui import QRadialGradient
from PySide6.QtGui import QSurfaceFormat
from PySide6.QtGui import QTransform
from PySide6.QtOpenGLWidgets import QOpenGLWidget
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QDockWidget
from PySide6.QtWidgets import QGridLayout
from PySide6.QtWidgets import QLabel
from PySide6.QtWidgets import QLayout
from PySide6.QtWidgets import QMenu
from PySide6.QtWidgets import QMenuBar
from PySide6.QtWidgets import QSizePolicy
from PySide6.QtWidgets import QStatusBar
from PySide6.QtWidgets import QTabWidget
from PySide6.QtWidgets import QVBoxLayout
from PySide6.QtWidgets import QWidget

from compas_viewer import DATA
from compas_viewer.configurations.layout_config import LayoutConfig

from .window import WindowLayout
from .statusbar import StatusBarLayout
from .menubar import MenuBarLayout
from . viewport import ViewportLayout
from .sidedock import SideDockLayout
from .statusbar import StatusBarLayout
from .toolbar import ToolBarLayout
from .viewport import ViewportLayout
from .window import WindowLayout

if TYPE_CHECKING:
from compas_viewer import Viewer

from PySide6.QtWidgets import QMainWindow


class Layout:
"""
The Layout class manages all the layout and other UI-related information of the viewer.
It is the master class that invokes the:`compas_viewer.layouts.layout.WindowLayout`, `compas_viewer.layouts.layout.BodyLayout` and others.
# TODO
Parameters
----------
config : :class:`compas_viewer.configurations.layout_config.LayoutConfig`
The configuration object for the layout.
Attributes
----------
config : :class:`compas_viewer.configurations.layout_config.LayoutConfig`
The configuration object for the layout.
viewer : :class:`compas_viewer.Viewer`
The parent viewer.
window : :class:`compas_viewer.layout.layout.WindowLayout`
The window layout.
statusbar : :class:`compas_viewer.layout.layout.StatusBarLayout`
The status bar layout.
menubar : :class:`compas_viewer.layout.layout.MenuBarLayout`
The menu bar layout.
viewport : :class:`compas_viewer.layout.layout.ViewportLayout`
The viewport layout.
toolbar : :class:`compas_viewer.layout.layout.ToolBarLayout`
The tool bar layout.
sidedock : :class:`compas_viewer.layout.layout.SideDockLayout`
The side dock layout.
See Also
--------
:class:`compas_viewer.configurations.layout_config.LayoutConfig`
:PySide6:`PySide6/QtWidgets/QLayout`
"""

def __init__(self, viewer: "Viewer", config: LayoutConfig):
Expand All @@ -79,12 +56,13 @@ def __init__(self, viewer: "Viewer", config: LayoutConfig):
self.config = config

# Widgets
self.central_widget = QWidget(self.viewer.window)
self.window = WindowLayout(self)
self.statusbar = StatusBarLayout(self)
self.menubar = MenuBarLayout(self)
self.viewport = ViewportLayout(self)


self.toolbar = ToolBarLayout(self)
self.sidedock = SideDockLayout(self)

def init(self):
"""
Expand All @@ -103,9 +81,13 @@ def init(self):
self.window.init()
self.statusbar.init()
self.menubar.init()
self.toolbar.init()
self.sidedock.init()
self.viewport.init()

self.viewer.window.setCentralWidget(self.central_widget)

# TODO
# def _resize(self, width: int, height: int):
# """Resize the main window programmatically.

Expand All @@ -125,4 +107,3 @@ def init(self):
# self._window.setGeometry(x, y, width, height)
# self.config.width = width
# self.config.height = height

Loading

0 comments on commit 96b0d40

Please sign in to comment.