Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/viewer-context-detection #1237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Added

* Added `viewerinstance` in `compas.scene.Scene` to support viewers context detection.
* Added `compas_rhino8` as starting point for Rhino8 support.
* Added `compas.scene.SceneObjectNode`.
* Added `compas.scene.SceneTree`.
Expand Down
22 changes: 9 additions & 13 deletions src/compas/scene/context.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from compas.plugins import pluggable
import inspect
from collections import defaultdict

import compas
from compas.plugins import PluginValidator
from compas.plugins import pluggable

from .exceptions import NoSceneObjectContextError
from .exceptions import SceneObjectNotRegisteredError
import inspect
import compas
from collections import defaultdict

ITEM_SCENEOBJECT = defaultdict(dict)

Expand Down Expand Up @@ -62,15 +64,9 @@ def is_viewer_open():
bool

"""
# TODO: implement [without introducing compas_view2 as a dependency..?]
# make the viewer app a singleton
# check for the exitence of an instance of the singleton
# if the instance exists, return True
# in this case, the viewer is the current context
# to do this without introducing compas_view2 as a dependency,
# creating the singleton instance should modify a class attribute of the SceneObject
# (or potentially a module level attribute of compas itself)
return False
from compas.scene import Scene

return Scene.viewerinstance is not None


def _detect_current_context():
Expand Down
7 changes: 5 additions & 2 deletions src/compas/scene/scene.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from compas.data import Data
from compas.datastructures import Tree
from compas.datastructures import TreeNode
from .sceneobject import SceneObject
from .context import redraw

from .context import clear
from .context import redraw
from .sceneobject import SceneObject


class SceneObjectNode(TreeNode):
Expand Down Expand Up @@ -178,6 +179,8 @@ class Scene(Data):

"""

viewerinstance = None

def __init__(self, name=None, context=None):
super(Scene, self).__init__(name)
self._tree = SceneTree("Scene")
Expand Down
Loading