mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-16 11:15:56 +08:00
Change the dynamic class definition to be more elegant
CURA-12404
This commit is contained in:
parent
b338a370c0
commit
9a92451f44
@ -9,10 +9,18 @@ from UM.Logger import Logger
|
||||
|
||||
try:
|
||||
import pynavlib.pynavlib_interface as pynav
|
||||
parent_class = pynav.NavlibNavigationModel
|
||||
except BaseException as exception:
|
||||
Logger.warning(f"Unable to load 3DConnexion library: {exception}")
|
||||
pynav = None
|
||||
parent_class = object
|
||||
|
||||
class NavlibClient(pynav.NavlibNavigationModel):
|
||||
class NavlibClient(parent_class):
|
||||
|
||||
def __init__(self, scene, renderer) -> None:
|
||||
if not pynav:
|
||||
return
|
||||
|
||||
super().__init__(False, pynav.NavlibOptions.RowMajorOrder)
|
||||
self._scene = scene
|
||||
self._renderer = renderer
|
||||
@ -22,6 +30,14 @@ try:
|
||||
self._picking_pass = None
|
||||
self._pivot_node = OverlayNode(node=SceneNode(), image_path=Resources.getPath(Resources.Images, "3dx_pivot.png"), size=3.)
|
||||
|
||||
def put_profile_hint(self, hint) -> None:
|
||||
if pynav:
|
||||
super().put_profile_hint(hint)
|
||||
|
||||
def enable_navigation(self, enabled) -> None:
|
||||
if pynav:
|
||||
super().enable_navigation(enabled)
|
||||
|
||||
def pick(self, x, y, check_selection = False, radius = 0.):
|
||||
|
||||
if self._picking_pass is None or radius < 0.:
|
||||
@ -68,7 +84,7 @@ try:
|
||||
|
||||
return result_position
|
||||
|
||||
def get_pointer_position(self)->pynav.NavlibVector:
|
||||
def get_pointer_position(self) -> "pynav.NavlibVector":
|
||||
|
||||
from UM.Qt.QtApplication import QtApplication
|
||||
main_window = QtApplication.getInstance().getMainWindow()
|
||||
@ -90,7 +106,7 @@ try:
|
||||
|
||||
return pynav.NavlibVector(pointer_position.x, pointer_position.y, pointer_position.z)
|
||||
|
||||
def get_view_extents(self)->pynav.NavlibBox:
|
||||
def get_view_extents(self) -> "pynav.NavlibBox":
|
||||
|
||||
view_width = self._scene.getActiveCamera().getViewportWidth()
|
||||
view_height = self._scene.getActiveCamera().getViewportHeight()
|
||||
@ -102,7 +118,7 @@ try:
|
||||
|
||||
return pynav.NavlibBox(pt_min, pt_max)
|
||||
|
||||
def get_view_frustum(self)->pynav.NavlibFrustum:
|
||||
def get_view_frustum(self) -> "pynav.NavlibFrustum":
|
||||
|
||||
projection_matrix = self._scene.getActiveCamera().getProjectionMatrix()
|
||||
half_height = 2. / projection_matrix.getData()[1,1]
|
||||
@ -110,10 +126,10 @@ try:
|
||||
|
||||
return pynav.NavlibFrustum(-half_width, half_width, -half_height, half_height, 1., 5000.)
|
||||
|
||||
def get_is_view_perspective(self)->bool:
|
||||
def get_is_view_perspective(self) -> bool:
|
||||
return self._scene.getActiveCamera().isPerspective()
|
||||
|
||||
def get_selection_extents(self)->pynav.NavlibBox:
|
||||
def get_selection_extents(self) -> "pynav.NavlibBox":
|
||||
|
||||
from UM.Scene.Selection import Selection
|
||||
bounding_box = Selection.getBoundingBox()
|
||||
@ -123,17 +139,17 @@ try:
|
||||
pt_max = pynav.NavlibVector(bounding_box.maximum.x, bounding_box.maximum.y, bounding_box.maximum.z)
|
||||
return pynav.NavlibBox(pt_min, pt_max)
|
||||
|
||||
def get_selection_transform(self)->pynav.NavlibMatrix:
|
||||
def get_selection_transform(self) -> "pynav.NavlibMatrix":
|
||||
return pynav.NavlibMatrix()
|
||||
|
||||
def get_is_selection_empty(self)->bool:
|
||||
def get_is_selection_empty(self) -> bool:
|
||||
from UM.Scene.Selection import Selection
|
||||
return not Selection.hasSelection()
|
||||
|
||||
def get_pivot_visible(self)->bool:
|
||||
def get_pivot_visible(self) -> bool:
|
||||
return False
|
||||
|
||||
def get_camera_matrix(self)->pynav.NavlibMatrix:
|
||||
def get_camera_matrix(self) -> "pynav.NavlibMatrix":
|
||||
|
||||
transformation = self._scene.getActiveCamera().getLocalTransformation()
|
||||
|
||||
@ -142,13 +158,13 @@ try:
|
||||
[transformation.at(2, 0), transformation.at(2, 1), transformation.at(2, 2), transformation.at(2, 3)],
|
||||
[transformation.at(3, 0), transformation.at(3, 1), transformation.at(3, 2), transformation.at(3, 3)]])
|
||||
|
||||
def get_coordinate_system(self)->pynav.NavlibMatrix:
|
||||
def get_coordinate_system(self) -> "pynav.NavlibMatrix":
|
||||
return pynav.NavlibMatrix()
|
||||
|
||||
def get_front_view(self)->pynav.NavlibMatrix:
|
||||
def get_front_view(self) -> "pynav.NavlibMatrix":
|
||||
return pynav.NavlibMatrix()
|
||||
|
||||
def get_model_extents(self)->pynav.NavlibBox:
|
||||
def get_model_extents(self) -> "pynav.NavlibBox":
|
||||
|
||||
result_bbox = AxisAlignedBox()
|
||||
build_volume_bbox = None
|
||||
@ -170,10 +186,10 @@ try:
|
||||
self._scene_radius = (result_bbox.maximum - self._scene_center).length()
|
||||
return pynav.NavlibBox(pt_min, pt_max)
|
||||
|
||||
def get_pivot_position(self)->pynav.NavlibVector:
|
||||
def get_pivot_position(self) -> "pynav.NavlibVector":
|
||||
return pynav.NavlibVector()
|
||||
|
||||
def get_hit_look_at(self)->pynav.NavlibVector:
|
||||
def get_hit_look_at(self) -> "pynav.NavlibVector":
|
||||
|
||||
if self._was_pick and self._pointer_pick is not None:
|
||||
return pynav.NavlibVector(self._pointer_pick.x, self._pointer_pick.y, self._pointer_pick.z)
|
||||
@ -187,13 +203,13 @@ try:
|
||||
if picked_position is not None:
|
||||
return pynav.NavlibVector(picked_position.x, picked_position.y, picked_position.z)
|
||||
|
||||
def get_units_to_meters(self)->float:
|
||||
def get_units_to_meters(self) -> float:
|
||||
return 0.05
|
||||
|
||||
def is_user_pivot(self)->bool:
|
||||
def is_user_pivot(self) -> bool:
|
||||
return False
|
||||
|
||||
def set_camera_matrix(self, matrix : pynav.NavlibMatrix):
|
||||
def set_camera_matrix(self, matrix : "pynav.NavlibMatrix"):
|
||||
|
||||
# !!!!!!
|
||||
# Hit testing in Orthographic view is not reliable
|
||||
@ -238,7 +254,7 @@ try:
|
||||
|
||||
self._pivot_node.scale(scale)
|
||||
|
||||
def set_view_extents(self, extents: pynav.NavlibBox):
|
||||
def set_view_extents(self, extents: "pynav.NavlibBox"):
|
||||
view_width = self._scene.getActiveCamera().getViewportWidth()
|
||||
new_zoom = (extents._min._x + view_width / 2.) / - view_width
|
||||
self._scene.getActiveCamera().setZoomFactor(new_zoom)
|
||||
@ -264,17 +280,3 @@ try:
|
||||
self._scene.getRoot().addChild(self._pivot_node)
|
||||
else:
|
||||
self._scene.getRoot().removeChild(self._pivot_node)
|
||||
|
||||
except BaseException as exception:
|
||||
Logger.warning(f"Unable to load 3DConnexion library: {exception}")
|
||||
|
||||
# Define dummy class instead so that integration is transparent from outside
|
||||
class NavlibClient:
|
||||
def __init__(self, scene, renderer) -> None:
|
||||
pass
|
||||
|
||||
def put_profile_hint(self, hint) -> None:
|
||||
pass
|
||||
|
||||
def enable_navigation(self, enabled) -> None:
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user