diff --git a/.github/workflows/prepare_pr.yml b/.github/workflows/prepare_pr.yml new file mode 100644 index 0000000..77f8181 --- /dev/null +++ b/.github/workflows/prepare_pr.yml @@ -0,0 +1,11 @@ +name: Prepare PR + +on: + pull_request: + branches: + - next + +jobs: + prepare: + uses: Geode-solutions/actions/.github/workflows/py-prepare-pr.yml@master + secrets: inherit diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..bc7a268 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,536 @@ +[tool.pylint.main] +# Analyse import fallback blocks. This can be used to support both Python 2 and 3 +# compatible code, which means that the block might have code that exists only in +# one or another interpreter, leading to false positives when analysed. +# analyse-fallback-blocks = + +# Clear in-memory caches upon conclusion of linting. Useful if running pylint in +# a server-like mode. +# clear-cache-post-run = + +# Always return a 0 (non-error) status code, even if lint errors are found. This +# is primarily useful in continuous integration scripts. +# exit-zero = + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +# extension-pkg-allow-list = + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. (This is an alternative name to extension-pkg-allow-list +# for backward compatibility.) +# extension-pkg-whitelist = + +# Return non-zero exit code if any of these messages/categories are detected, +# even if score is above --fail-under value. Syntax same as enable. Messages +# specified are enabled, while categories only check already-enabled messages. +# fail-on = + +# Specify a score threshold under which the program will exit with error. +fail-under = 10 + +# Interpret the stdin as a python script, whose filename needs to be passed as +# the module_or_package argument. +# from-stdin = + +# Files or directories to be skipped. They should be base names, not paths. +ignore = ["CVS"] + +# Add files or directories matching the regular expressions patterns to the +# ignore-list. The regex matches against paths and can be in Posix or Windows +# format. Because '\\' represents the directory delimiter on Windows systems, it +# can't be used as an escape character. +# ignore-paths = + +# Files or directories matching the regular expression patterns are skipped. The +# regex matches against base names, not paths. The default value ignores Emacs +# file locks +ignore-patterns = ["^\\.#"] + +# List of module names for which member attributes should not be checked (useful +# for modules/projects where namespaces are manipulated during runtime and thus +# existing member attributes cannot be deduced by static analysis). It supports +# qualified module names, as well as Unix pattern matching. +# ignored-modules = + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +# init-hook = + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use, and will cap the count on Windows to +# avoid hangs. +jobs = 1 + +# Control the amount of potential inferred values when inferring a single object. +# This can help the performance when dealing with large functions or complex, +# nested conditions. +limit-inference-results = 100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +# load-plugins = + +# Pickle collected data for later comparisons. +persistent = true + +# Minimum Python version to use for version dependent checks. Will default to the +# version used to run pylint. +py-version = "3.9" + +# Discover python modules and packages in the file system subtree. +# recursive = + +# Add paths to the list of the source roots. Supports globbing patterns. The +# source root is an absolute path or a path relative to the current working +# directory used to determine a package namespace for modules located under the +# source root. +# source-roots = + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode = true + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +# unsafe-load-any-extension = + +[tool.pylint.basic] +# Naming style matching correct argument names. +argument-naming-style = "snake_case" + +# Regular expression matching correct argument names. Overrides argument-naming- +# style. If left empty, argument names will be checked with the set naming style. +# argument-rgx = + +# Naming style matching correct attribute names. +attr-naming-style = "snake_case" + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. If left empty, attribute names will be checked with the set naming +# style. +# attr-rgx = + +# Bad variable names which should always be refused, separated by a comma. +bad-names = ["foo", "bar", "baz", "toto", "tutu", "tata"] + +# Bad variable names regexes, separated by a comma. If names match any regex, +# they will always be refused +# bad-names-rgxs = + +# Naming style matching correct class attribute names. +class-attribute-naming-style = "any" + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. If left empty, class attribute names will be checked +# with the set naming style. +# class-attribute-rgx = + +# Naming style matching correct class constant names. +class-const-naming-style = "UPPER_CASE" + +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. If left empty, class constant names will be checked with +# the set naming style. +# class-const-rgx = + +# Naming style matching correct class names. +class-naming-style = "PascalCase" + +# Regular expression matching correct class names. Overrides class-naming-style. +# If left empty, class names will be checked with the set naming style. +# class-rgx = + +# Naming style matching correct constant names. +const-naming-style = "UPPER_CASE" + +# Regular expression matching correct constant names. Overrides const-naming- +# style. If left empty, constant names will be checked with the set naming style. +# const-rgx = + +# Minimum line length for functions/classes that require docstrings, shorter ones +# are exempt. +docstring-min-length = -1 + +# Naming style matching correct function names. +function-naming-style = "snake_case" + +# Regular expression matching correct function names. Overrides function-naming- +# style. If left empty, function names will be checked with the set naming style. +# function-rgx = + +# Good variable names which should always be accepted, separated by a comma. +good-names = ["i", "j", "k", "ex", "Run", "_"] + +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +# good-names-rgxs = + +# Include a hint for the correct naming format with invalid-name. +# include-naming-hint = + +# Naming style matching correct inline iteration names. +inlinevar-naming-style = "any" + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. If left empty, inline iteration names will be checked +# with the set naming style. +# inlinevar-rgx = + +# Naming style matching correct method names. +method-naming-style = "snake_case" + +# Regular expression matching correct method names. Overrides method-naming- +# style. If left empty, method names will be checked with the set naming style. +# method-rgx = + +# Naming style matching correct module names. +module-naming-style = "snake_case" + +# Regular expression matching correct module names. Overrides module-naming- +# style. If left empty, module names will be checked with the set naming style. +# module-rgx = + +# Colon-delimited sets of names that determine each other's naming style when the +# name regexes allow several styles. +# name-group = + +# Regular expression which should only match function or class names that do not +# require a docstring. +no-docstring-rgx = "^_" + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. These +# decorators are taken in consideration only for invalid-name. +property-classes = ["abc.abstractproperty"] + +# Regular expression matching correct type alias names. If left empty, type alias +# names will be checked with the set naming style. +# typealias-rgx = + +# Regular expression matching correct type variable names. If left empty, type +# variable names will be checked with the set naming style. +# typevar-rgx = + +# Naming style matching correct variable names. +variable-naming-style = "snake_case" + +# Regular expression matching correct variable names. Overrides variable-naming- +# style. If left empty, variable names will be checked with the set naming style. +# variable-rgx = + +[tool.pylint.classes] +# Warn about protected attribute access inside special methods +# check-protected-access-in-special-methods = + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods = ["__init__", "__new__", "setUp", "asyncSetUp", "__post_init__"] + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected = ["_asdict", "_fields", "_replace", "_source", "_make", "os._exit"] + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg = ["cls"] + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg = ["mcs"] + +[tool.pylint.design] +# List of regular expressions of class ancestor names to ignore when counting +# public methods (see R0903) +# exclude-too-few-public-methods = + +# List of qualified class names to ignore when counting class parents (see R0901) +# ignored-parents = + +# Maximum number of arguments for function / method. +max-args = 5 + +# Maximum number of attributes for a class (see R0902). +max-attributes = 7 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr = 5 + +# Maximum number of branch for function / method body. +max-branches = 12 + +# Maximum number of locals for function / method body. +max-locals = 15 + +# Maximum number of parents for a class (see R0901). +max-parents = 7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods = 20 + +# Maximum number of return / yield for function / method body. +max-returns = 6 + +# Maximum number of statements in function / method body. +max-statements = 50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods = 2 + +[tool.pylint.exceptions] +# Exceptions that will emit a warning when caught. +overgeneral-exceptions = ["builtins.BaseException", "builtins.Exception"] + +[tool.pylint.format] +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +# expected-line-ending-format = + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines = "^\\s*(# )??$" + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren = 4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string = " " + +# Maximum number of characters on a single line. +max-line-length = 100 + +# Maximum number of lines in a module. +max-module-lines = 1000 + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +# single-line-class-stmt = + +# Allow the body of an if to be on the same line as the test if there is no else. +# single-line-if-stmt = + +[tool.pylint.imports] +# List of modules that can be imported at any level, not just the top level one. +# allow-any-import-level = + +# Allow explicit reexports by alias from a package __init__. +# allow-reexport-from-package = + +# Allow wildcard imports from modules that define __all__. +# allow-wildcard-with-all = + +# Deprecated modules which should not be used, separated by a comma. +# deprecated-modules = + +# Output a graph (.gv or any supported image format) of external dependencies to +# the given file (report RP0402 must not be disabled). +# ext-import-graph = + +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be disabled). +# import-graph = + +# Output a graph (.gv or any supported image format) of internal dependencies to +# the given file (report RP0402 must not be disabled). +# int-import-graph = + +# Force import order to recognize a module as part of the standard compatibility +# libraries. +# known-standard-library = + +# Force import order to recognize a module as part of a third party library. +known-third-party = ["enchant"] + +# Couples of modules and preferred modules, separated by a comma. +# preferred-modules = + +[tool.pylint.logging] +# The type of string formatting that logging methods do. `old` means using % +# formatting, `new` is for `{}` formatting. +logging-format-style = "old" + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules = ["logging"] + +[tool.pylint."messages control"] +# Only show warnings with the listed confidence levels. Leave empty to show all. +# Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, UNDEFINED. +confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFINED"] + +# Disable the message, report, category or checker with the given id(s). You can +# either give multiple identifiers separated by comma (,) or put this option +# multiple times (only on the command line, not in the configuration file where +# it should appear only once). You can also use "--disable=all" to disable +# everything first and then re-enable specific checks. For example, if you want +# to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-symbolic-message-instead", "use-implicit-booleaness-not-comparison-to-string", "use-implicit-booleaness-not-comparison-to-zero"] + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where it +# should appear only once). See also the "--disable" option for examples. +# enable = + +[tool.pylint.method_args] +# List of qualified names (i.e., library.method) which require a timeout +# parameter e.g. 'requests.api.get,requests.api.post' +timeout-methods = ["requests.api.delete", "requests.api.get", "requests.api.head", "requests.api.options", "requests.api.patch", "requests.api.post", "requests.api.put", "requests.api.request"] + +[tool.pylint.miscellaneous] +# List of note tags to take in consideration, separated by a comma. +notes = ["FIXME", "XXX", "TODO"] + +# Regular expression of note tags to take in consideration. +# notes-rgx = + +[tool.pylint.refactoring] +# Maximum number of nested blocks for function / method body +max-nested-blocks = 5 + +# Complete name of functions that never returns. When checking for inconsistent- +# return-statements if a never returning function is called then it will be +# considered as an explicit return statement and no message will be printed. +never-returning-functions = ["sys.exit", "argparse.parse_error"] + +[tool.pylint.reports] +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'fatal', 'error', 'warning', 'refactor', +# 'convention', and 'info' which contain the number of messages in each category, +# as well as 'statement' which is the total number of statements analyzed. This +# score is used by the global evaluation report (RP0004). +evaluation = "max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))" + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +# msg-template = + +# Set the output format. Available formats are: text, parseable, colorized, json2 +# (improved json format), json (old json format) and msvs (visual studio). You +# can also give a reporter class, e.g. mypackage.mymodule.MyReporterClass. +# output-format = + +# Tells whether to display a full report or only the messages. +# reports = + +# Activate the evaluation score. +score = true + +[tool.pylint.similarities] +# Comments are removed from the similarity computation +ignore-comments = true + +# Docstrings are removed from the similarity computation +ignore-docstrings = true + +# Imports are removed from the similarity computation +ignore-imports = true + +# Signatures are removed from the similarity computation +ignore-signatures = true + +# Minimum lines number of a similarity. +min-similarity-lines = 4 + +[tool.pylint.spelling] +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions = 4 + +# Spelling dictionary name. No available dictionaries : You need to install both +# the python package and the system dependency for enchant to work. +# spelling-dict = + +# List of comma separated words that should be considered directives if they +# appear at the beginning of a comment and should not be checked. +spelling-ignore-comment-directives = "fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:" + +# List of comma separated words that should not be checked. +# spelling-ignore-words = + +# A path to a file that contains the private dictionary; one word per line. +# spelling-private-dict-file = + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +# spelling-store-unknown-words = + +[tool.pylint.typecheck] +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators = ["contextlib.contextmanager"] + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +# generated-members = + +# Tells whether missing members accessed in mixin class should be ignored. A +# class is considered mixin if its name matches the mixin-class-rgx option. +# Tells whether to warn about missing members when the owner of the attribute is +# inferred to be None. +ignore-none = true + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference can +# return multiple potential results while evaluating a Python object, but some +# branches might not be evaluated, which results in partial inference. In that +# case, it might be useful to still emit no-member and other checks for the rest +# of the inferred objects. +ignore-on-opaque-inference = true + +# List of symbolic message names to ignore for Mixin members. +ignored-checks-for-mixins = ["no-member", "not-async-context-manager", "not-context-manager", "attribute-defined-outside-init"] + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes = ["optparse.Values", "thread._local", "_thread._local", "argparse.Namespace"] + +# Show a hint with possible names when a member name was not found. The aspect of +# finding the hint is based on edit distance. +missing-member-hint = true + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance = 1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices = 1 + +# Regex pattern to define which classes are considered mixins. +mixin-class-rgx = ".*[Mm]ixin" + +# List of decorators that change the signature of a decorated function. +# signature-mutators = + +[tool.pylint.variables] +# List of additional names supposed to be defined in builtins. Remember that you +# should avoid defining new builtins when possible. +# additional-builtins = + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables = true + +# List of names allowed to shadow builtins +# allowed-redefined-builtins = + +# List of strings which can identify a callback function by name. A callback name +# must start or end with one of those strings. +callbacks = ["cb_", "_cb"] + +# A regular expression matching the name of dummy variables (i.e. expected to not +# be used). +dummy-variables-rgx = "_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_" + +# Argument names that match this expression will be ignored. +ignored-argument-names = "_.*|^ignored_|^unused_" + +# Tells whether we should check for unused import in __init__ files. +# init-import = + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules = ["six.moves", "past.builtins", "future.builtins", "builtins", "io"] \ No newline at end of file diff --git a/src/opengeodeweb_viewer/config.py b/src/opengeodeweb_viewer/config.py index 7779e9e..76fc3ef 100644 --- a/src/opengeodeweb_viewer/config.py +++ b/src/opengeodeweb_viewer/config.py @@ -27,8 +27,6 @@ def dev_config(): def test_config(path): default_config() print(f"{os.path.dirname(__file__)=}", flush=True) - os.environ["DATA_FOLDER_PATH"] = os.path.join(path, - "data" - ) + os.environ["DATA_FOLDER_PATH"] = os.path.join(path, "data") print(f"{os.environ.get('DATA_FOLDER_PATH')=}", flush=True) diff --git a/src/opengeodeweb_viewer/object/object_methods.py b/src/opengeodeweb_viewer/object/object_methods.py index bbd3b0e..1c9b7ed 100644 --- a/src/opengeodeweb_viewer/object/object_methods.py +++ b/src/opengeodeweb_viewer/object/object_methods.py @@ -8,6 +8,7 @@ from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema from opengeodeweb_viewer.vtk_protocol import VtkView + class VtkObjectView(VtkView): def __init__(self): super().__init__() @@ -98,19 +99,19 @@ def SetOpacity(self, id, opacity): actor = self.get_object(id)["actor"] actor.GetProperty().SetOpacity(opacity) self.render() - + def SetColor(self, id, red, green, blue): mapper = self.get_object(id)["mapper"] mapper.ScalarVisibilityOff() actor = self.get_object(id)["actor"] - actor.GetProperty().SetColor([red/255, green/255, blue/255]) + actor.GetProperty().SetColor([red / 255, green / 255, blue / 255]) self.render() def SetEdgesVisibility(self, id, visibility): actor = self.get_object(id)["actor"] actor.GetProperty().SetEdgeVisibility(visibility) self.render() - + def SetEdgesSize(self, id, size): actor = self.get_object(id)["actor"] actor.GetProperty().SetEdgeWidth(size) @@ -118,7 +119,7 @@ def SetEdgesSize(self, id, size): def SetEdgesColor(self, id, red, green, blue): actor = self.get_object(id)["actor"] - actor.GetProperty().SetEdgeColor([red/255, green/255, blue/255]) + actor.GetProperty().SetEdgeColor([red / 255, green / 255, blue / 255]) self.render() def SetPointsVisibility(self, id, visibility): @@ -134,7 +135,7 @@ def SetPointsSize(self, id, size): def SetPointsColor(self, id, red, green, blue): actor = self.get_object(id)["actor"] - actor.GetProperty().SetVertexColor([red/255, green/255, blue/255]) + actor.GetProperty().SetVertexColor([red / 255, green / 255, blue / 255]) self.render() def clearColors(self, id): @@ -143,4 +144,4 @@ def clearColors(self, id): reader = db["reader"] reader.GetOutput().GetPointData().SetActiveScalars("") reader.GetOutput().GetCellData().SetActiveScalars("") - mapper.ScalarVisibilityOff() \ No newline at end of file + mapper.ScalarVisibilityOff() diff --git a/src/opengeodeweb_viewer/rpc/generic/generic_protocols.py b/src/opengeodeweb_viewer/rpc/generic/generic_protocols.py index 983aed6..11298e5 100644 --- a/src/opengeodeweb_viewer/rpc/generic/generic_protocols.py +++ b/src/opengeodeweb_viewer/rpc/generic/generic_protocols.py @@ -11,21 +11,28 @@ from opengeodeweb_viewer.vtk_protocol import VtkView from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema + class VtkGenericView(VtkView): generic_prefix = "opengeodeweb_viewer.generic." - generic_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) + generic_schemas_dict = get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") + ) def __init__(self, mesh_protocols, model_protocols): super().__init__() self.mesh_protocols = mesh_protocols self.model_protocols = model_protocols - + @exportRpc(generic_prefix + generic_schemas_dict["register"]["rpc"]) def register(self, params): - print(self.generic_prefix + self.generic_schemas_dict["register"]["rpc"], f"{params=}", flush=True) + print( + self.generic_prefix + self.generic_schemas_dict["register"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.generic_schemas_dict["register"]) viewer_object = params["viewer_object"] - params.pop('viewer_object', None) + params.pop("viewer_object", None) print(f"{params=}", flush=True) if viewer_object == "mesh": self.mesh_protocols.registerMesh(params) @@ -34,13 +41,15 @@ def register(self, params): @exportRpc(generic_prefix + generic_schemas_dict["deregister"]["rpc"]) def deregister(self, params): - print(self.generic_prefix + self.generic_schemas_dict["deregister"]["rpc"], f"{params=}", flush=True) + print( + self.generic_prefix + self.generic_schemas_dict["deregister"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.generic_schemas_dict["deregister"]) viewer_object = params["viewer_object"] - params.pop('viewer_object', None) + params.pop("viewer_object", None) if viewer_object == "mesh": self.mesh_protocols.deregisterMesh(params) elif viewer_object == "model": self.model_protocols.deregisterModel(params) - - diff --git a/src/opengeodeweb_viewer/rpc/mesh/edges/edges_protocols.py b/src/opengeodeweb_viewer/rpc/mesh/edges/edges_protocols.py index 73683ed..1d1de4a 100644 --- a/src/opengeodeweb_viewer/rpc/mesh/edges/edges_protocols.py +++ b/src/opengeodeweb_viewer/rpc/mesh/edges/edges_protocols.py @@ -8,16 +8,23 @@ from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView + class VtkMeshEdgesView(VtkMeshView): mesh_edges_prefix = "opengeodeweb_viewer.mesh.edges." - mesh_edges_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) + mesh_edges_schemas_dict = get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") + ) def __init__(self): super().__init__() @exportRpc(mesh_edges_prefix + mesh_edges_schemas_dict["visibility"]["rpc"]) def setMeshEdgesVisibility(self, params): - print(self.mesh_edges_prefix + self.mesh_edges_schemas_dict["visibility"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_edges_prefix + self.mesh_edges_schemas_dict["visibility"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_edges_schemas_dict["visibility"]) id = params["id"] visibility = bool(params["visibility"]) @@ -25,19 +32,28 @@ def setMeshEdgesVisibility(self, params): @exportRpc(mesh_edges_prefix + mesh_edges_schemas_dict["color"]["rpc"]) def setMeshEdgesColor(self, params): - print(self.mesh_edges_prefix + self.mesh_edges_schemas_dict["color"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_edges_prefix + self.mesh_edges_schemas_dict["color"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_edges_schemas_dict["color"]) id = params["id"] - red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"] + red, green, blue = ( + params["color"]["r"], + params["color"]["g"], + params["color"]["b"], + ) self.SetEdgesColor(id, red, green, blue) @exportRpc(mesh_edges_prefix + mesh_edges_schemas_dict["size"]["rpc"]) def setMeshEdgesSize(self, params): - print(self.mesh_edges_prefix + self.mesh_edges_schemas_dict["size"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_edges_prefix + self.mesh_edges_schemas_dict["size"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_edges_schemas_dict["size"]) id = params["id"] size = bool(params["size"]) self.SetEdgesSize(id, size) - - - diff --git a/src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py b/src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py index 585d779..3118fac 100644 --- a/src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py +++ b/src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py @@ -9,16 +9,23 @@ from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema from opengeodeweb_viewer.object.object_methods import VtkObjectView + class VtkMeshView(VtkObjectView): mesh_prefix = "opengeodeweb_viewer.mesh." - mesh_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) + mesh_schemas_dict = get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") + ) def __init__(self): super().__init__() @exportRpc(mesh_prefix + mesh_schemas_dict["register"]["rpc"]) def registerMesh(self, params): - print(self.mesh_prefix + self.mesh_schemas_dict["register"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_prefix + self.mesh_schemas_dict["register"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_schemas_dict["register"]) id = params["id"] file_name = params["file_name"] @@ -33,14 +40,22 @@ def registerMesh(self, params): @exportRpc(mesh_prefix + mesh_schemas_dict["deregister"]["rpc"]) def deregisterMesh(self, params): - print(self.mesh_prefix + self.mesh_schemas_dict["deregister"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_prefix + self.mesh_schemas_dict["deregister"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_schemas_dict["deregister"]) id = params["id"] self.deregisterObject(id) @exportRpc(mesh_prefix + mesh_schemas_dict["visibility"]["rpc"]) def SetMeshVisibility(self, params): - print(self.mesh_prefix + self.mesh_schemas_dict["visibility"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_prefix + self.mesh_schemas_dict["visibility"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_schemas_dict["visibility"]) id = params["id"] visibility = bool(params["visibility"]) @@ -48,7 +63,11 @@ def SetMeshVisibility(self, params): @exportRpc(mesh_prefix + mesh_schemas_dict["opacity"]["rpc"]) def setMeshOpacity(self, params): - print(self.mesh_prefix + self.mesh_schemas_dict["opacity"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_prefix + self.mesh_schemas_dict["opacity"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_schemas_dict["opacity"]) id = params["id"] opacity = float(params["opacity"]) @@ -56,22 +75,32 @@ def setMeshOpacity(self, params): @exportRpc(mesh_prefix + mesh_schemas_dict["color"]["rpc"]) def setMeshColor(self, params): - print(self.mesh_prefix + self.mesh_schemas_dict["color"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_prefix + self.mesh_schemas_dict["color"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_schemas_dict["color"]) id = params["id"] - red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"] + red, green, blue = ( + params["color"]["r"], + params["color"]["g"], + params["color"]["b"], + ) self.SetColor(id, red, green, blue) - @exportRpc(mesh_prefix + mesh_schemas_dict["apply_textures"]["rpc"]) def meshApplyTextures(self, params): - print(self.mesh_prefix + self.mesh_schemas_dict["apply_textures"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_prefix + self.mesh_schemas_dict["apply_textures"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_schemas_dict["apply_textures"]) id = params["id"] textures = params["textures"] self.applyTextures(id, textures) - def displayAttributeOnVertices(self, id, name): reader = self.get_object(id)["reader"] points = reader.GetOutput().GetPointData() @@ -82,7 +111,6 @@ def displayAttributeOnVertices(self, id, name): mapper.SetScalarRange(points.GetScalars().GetRange()) self.render() - def displayAttributeOnCells(self, id, name): reader = self.get_object(id)["reader"] cells = reader.GetOutput().GetCellData() @@ -91,4 +119,4 @@ def displayAttributeOnCells(self, id, name): mapper.ScalarVisibilityOn() mapper.SetScalarModeToUseCellData() mapper.SetScalarRange(cells.GetScalars().GetRange()) - self.render() \ No newline at end of file + self.render() diff --git a/src/opengeodeweb_viewer/rpc/mesh/points/points_protocols.py b/src/opengeodeweb_viewer/rpc/mesh/points/points_protocols.py index cd3fc2f..e927df7 100644 --- a/src/opengeodeweb_viewer/rpc/mesh/points/points_protocols.py +++ b/src/opengeodeweb_viewer/rpc/mesh/points/points_protocols.py @@ -8,16 +8,24 @@ from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView + class VtkMeshPointsView(VtkMeshView): mesh_points_prefix = "opengeodeweb_viewer.mesh.points." - mesh_points_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) + mesh_points_schemas_dict = get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") + ) def __init__(self): super().__init__() @exportRpc(mesh_points_prefix + mesh_points_schemas_dict["visibility"]["rpc"]) def setMeshPointsVisibility(self, params): - print(self.mesh_points_prefix + self.mesh_points_schemas_dict["visibility"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_points_prefix + + self.mesh_points_schemas_dict["visibility"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_points_schemas_dict["visibility"]) id = str(params["id"]) visibility = bool(params["visibility"]) @@ -25,15 +33,27 @@ def setMeshPointsVisibility(self, params): @exportRpc(mesh_points_prefix + mesh_points_schemas_dict["color"]["rpc"]) def setMeshPointsColor(self, params): - print(self.mesh_points_prefix + self.mesh_points_schemas_dict["color"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_points_prefix + self.mesh_points_schemas_dict["color"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_points_schemas_dict["color"]) id = str(params["id"]) - red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"] + red, green, blue = ( + params["color"]["r"], + params["color"]["g"], + params["color"]["b"], + ) self.SetPointsColor(id, red, green, blue) @exportRpc(mesh_points_prefix + mesh_points_schemas_dict["size"]["rpc"]) def setMeshPointsSize(self, params): - print(self.mesh_points_prefix + self.mesh_points_schemas_dict["size"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_points_prefix + self.mesh_points_schemas_dict["size"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_points_schemas_dict["size"]) id = str(params["id"]) size = float(params["size"]) @@ -41,9 +61,13 @@ def setMeshPointsSize(self, params): @exportRpc(mesh_points_prefix + mesh_points_schemas_dict["vertex_attribute"]["rpc"]) def setMeshPointsVertexAttribute(self, params): - print(self.mesh_points_prefix + self.mesh_points_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_points_prefix + + self.mesh_points_schemas_dict["vertex_attribute"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_points_schemas_dict["vertex_attribute"]) id = str(params["id"]) name = str(params["name"]) self.displayAttributeOnVertices(id, name) - \ No newline at end of file diff --git a/src/opengeodeweb_viewer/rpc/mesh/polygons/polygons_protocols.py b/src/opengeodeweb_viewer/rpc/mesh/polygons/polygons_protocols.py index cd64c32..a984f12 100644 --- a/src/opengeodeweb_viewer/rpc/mesh/polygons/polygons_protocols.py +++ b/src/opengeodeweb_viewer/rpc/mesh/polygons/polygons_protocols.py @@ -8,40 +8,70 @@ from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView + class VtkMeshPolygonsView(VtkMeshView): mesh_polygons_prefix = "opengeodeweb_viewer.mesh.polygons." - mesh_polygons_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) + mesh_polygons_schemas_dict = get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") + ) def __init__(self): super().__init__() @exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["visibility"]["rpc"]) def setMeshPolygonsVisibility(self, params): - print(self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["visibility"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polygons_prefix + + self.mesh_polygons_schemas_dict["visibility"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polygons_schemas_dict["visibility"]) id = params["id"] visibility = bool(params["visibility"]) self.SetVisibility(id, visibility) - + @exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["color"]["rpc"]) def setMeshPolygonsColor(self, params): - print(self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["color"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["color"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polygons_schemas_dict["color"]) id = params["id"] - red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"] + red, green, blue = ( + params["color"]["r"], + params["color"]["g"], + params["color"]["b"], + ) self.SetColor(id, red, green, blue) - @exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["vertex_attribute"]["rpc"]) + @exportRpc( + mesh_polygons_prefix + mesh_polygons_schemas_dict["vertex_attribute"]["rpc"] + ) def setMeshPolygonsVertexAttribute(self, params): - print(self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polygons_prefix + + self.mesh_polygons_schemas_dict["vertex_attribute"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polygons_schemas_dict["vertex_attribute"]) id = params["id"] name = str(params["name"]) self.displayAttributeOnVertices(id, name) - @exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["polygon_attribute"]["rpc"]) + @exportRpc( + mesh_polygons_prefix + mesh_polygons_schemas_dict["polygon_attribute"]["rpc"] + ) def setMeshPolygonsPolygonAttribute(self, params): - print(self.mesh_polygons_prefix + self.mesh_polygons_schemas_dict["polygon_attribute"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polygons_prefix + + self.mesh_polygons_schemas_dict["polygon_attribute"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polygons_schemas_dict["polygon_attribute"]) id = params["id"] name = str(params["name"]) diff --git a/src/opengeodeweb_viewer/rpc/mesh/polyhedrons/polyhedrons_protocols.py b/src/opengeodeweb_viewer/rpc/mesh/polyhedrons/polyhedrons_protocols.py index 5cbcbfd..b1d079a 100644 --- a/src/opengeodeweb_viewer/rpc/mesh/polyhedrons/polyhedrons_protocols.py +++ b/src/opengeodeweb_viewer/rpc/mesh/polyhedrons/polyhedrons_protocols.py @@ -8,16 +8,26 @@ from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView + class VtkMeshPolyhedronsView(VtkMeshView): mesh_polyhedrons_prefix = "opengeodeweb_viewer.mesh.polyhedrons." - mesh_polyhedrons_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) + mesh_polyhedrons_schemas_dict = get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") + ) def __init__(self): super().__init__() - @exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["visibility"]["rpc"]) + @exportRpc( + mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["visibility"]["rpc"] + ) def setMeshPolyhedronsVisibility(self, params): - print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["visibility"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polyhedrons_prefix + + self.mesh_polyhedrons_schemas_dict["visibility"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polyhedrons_schemas_dict["visibility"]) id = params["id"] visibility = bool(params["visibility"]) @@ -25,25 +35,49 @@ def setMeshPolyhedronsVisibility(self, params): @exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["color"]["rpc"]) def setMeshPolyhedronsColor(self, params): - print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["color"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polyhedrons_prefix + + self.mesh_polyhedrons_schemas_dict["color"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polyhedrons_schemas_dict["color"]) id = params["id"] - red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"] + red, green, blue = ( + params["color"]["r"], + params["color"]["g"], + params["color"]["b"], + ) self.SetColor(id, red, green, blue) - @exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"]) + @exportRpc( + mesh_polyhedrons_prefix + + mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"] + ) def setMeshPolyhedronsVertexAttribute(self, params): - print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polyhedrons_prefix + + self.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polyhedrons_schemas_dict["vertex_attribute"]) id = params["id"] name = str(params["name"]) self.displayAttributeOnVertices(id, name) - @exportRpc(mesh_polyhedrons_prefix + mesh_polyhedrons_schemas_dict["polyhedron_attribute"]["rpc"]) + @exportRpc( + mesh_polyhedrons_prefix + + mesh_polyhedrons_schemas_dict["polyhedron_attribute"]["rpc"] + ) def setMeshPolyhedronsPolyhedronAttribute(self, params): - print(self.mesh_polyhedrons_prefix + self.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], f"{params=}", flush=True) + print( + self.mesh_polyhedrons_prefix + + self.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.mesh_polyhedrons_schemas_dict["vertex_attribute"]) id = params["id"] name = str(params["name"]) self.displayAttributeOnCells(id, name) - diff --git a/src/opengeodeweb_viewer/rpc/model/model_protocols.py b/src/opengeodeweb_viewer/rpc/model/model_protocols.py index d732cf1..8cbdee7 100644 --- a/src/opengeodeweb_viewer/rpc/model/model_protocols.py +++ b/src/opengeodeweb_viewer/rpc/model/model_protocols.py @@ -9,16 +9,23 @@ from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema from opengeodeweb_viewer.object.object_methods import VtkObjectView + class VtkModelView(VtkObjectView): model_prefix = "opengeodeweb_viewer.model." - model_schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) + model_schemas_dict = get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") + ) def __init__(self): super().__init__() - + @exportRpc(model_prefix + model_schemas_dict["register"]["rpc"]) def registerModel(self, params): - print(self.model_prefix + self.model_schemas_dict["register"]["rpc"], f"{params=}", flush=True) + print( + self.model_prefix + self.model_schemas_dict["register"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.model_schemas_dict["register"]) id = params["id"] file_name = params["file_name"] @@ -34,14 +41,22 @@ def registerModel(self, params): @exportRpc(model_prefix + model_schemas_dict["deregister"]["rpc"]) def deregisterModel(self, params): - print(self.model_prefix + self.model_schemas_dict["deregister"]["rpc"], f"{params=}", flush=True) + print( + self.model_prefix + self.model_schemas_dict["deregister"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.model_schemas_dict["deregister"]) id = params["id"] self.deregisterObject(id) @exportRpc(model_prefix + model_schemas_dict["set_mesh_visibility"]["rpc"]) def setMeshVisibility(self, params): - print(self.model_prefix + self.model_schemas_dict["set_mesh_visibility"]["rpc"], f"{params=}", flush=True) + print( + self.model_prefix + self.model_schemas_dict["set_mesh_visibility"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.model_schemas_dict["set_mesh_visibility"]) id = params["id"] visibility = bool(params["visibility"]) @@ -49,7 +64,12 @@ def setMeshVisibility(self, params): @exportRpc(model_prefix + model_schemas_dict["set_components_visibility"]["rpc"]) def setComponentsVisibility(self, params): - print(self.model_prefix + self.model_schemas_dict["set_components_visibility"]["rpc"], f"{params=}", flush=True) + print( + self.model_prefix + + self.model_schemas_dict["set_components_visibility"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.model_schemas_dict["set_components_visibility"]) id = params["id"] visibility = bool(params["visibility"]) @@ -57,9 +77,16 @@ def setComponentsVisibility(self, params): @exportRpc(model_prefix + model_schemas_dict["set_components_color"]["rpc"]) def setComponentsColor(self, params): - print(self.model_prefix + self.model_schemas_dict["set_components_color"]["rpc"], f"{params=}", flush=True) + print( + self.model_prefix + self.model_schemas_dict["set_components_color"]["rpc"], + f"{params=}", + flush=True, + ) validate_schema(params, self.model_schemas_dict["set_components_color"]) id = params["id"] - red, green, blue = params["color"]["r"], params["color"]["g"], params["color"]["b"] + red, green, blue = ( + params["color"]["r"], + params["color"]["g"], + params["color"]["b"], + ) self.SetColor(id, red, green, blue) - diff --git a/src/opengeodeweb_viewer/utils_functions.py b/src/opengeodeweb_viewer/utils_functions.py index 0f27859..854e28e 100644 --- a/src/opengeodeweb_viewer/utils_functions.py +++ b/src/opengeodeweb_viewer/utils_functions.py @@ -16,7 +16,8 @@ def get_schemas_dict(path): file_content = json.load(file) schemas_dict[filename] = file_content return schemas_dict - + + def validate_schema(params, schema): try: validate(instance=params, schema=schema) diff --git a/src/opengeodeweb_viewer/vtk_override_protocols.py b/src/opengeodeweb_viewer/vtk_override_protocols.py index 9b6e4be..09a8205 100644 --- a/src/opengeodeweb_viewer/vtk_override_protocols.py +++ b/src/opengeodeweb_viewer/vtk_override_protocols.py @@ -14,21 +14,21 @@ # # ============================================================================= + class vtkWebPublishImageDelivery(vtk_protocols.vtkWebProtocol): def __init__(self, decode=True): super(vtkWebPublishImageDelivery, self).__init__() self.trackingViews = {} self.lastStaleTime = 0 self.staleHandlerCount = 0 - self.deltaStaleTimeBeforeRender = 0.5 # 0.5s + self.deltaStaleTimeBeforeRender = 0.5 # 0.5s self.decode = decode self.viewsInAnimations = [] self.targetFrameRate = 30.0 self.minFrameRate = 12.0 self.maxFrameRate = 30.0 - - def pushRender(self, vId, ignoreAnimation = False): + def pushRender(self, vId, ignoreAnimation=False): if vId not in self.trackingViews: return @@ -40,7 +40,7 @@ def pushRender(self, vId, ignoreAnimation = False): if "originalSize" not in self.trackingViews[vId]: view = self.getView(vId) - self.trackingViews[vId]["originalSize"] = list(view.GetSize()); + self.trackingViews[vId]["originalSize"] = list(view.GetSize()) if "ratio" not in self.trackingViews[vId]: self.trackingViews[vId]["ratio"] = 1 @@ -50,7 +50,9 @@ def pushRender(self, vId, ignoreAnimation = False): quality = self.trackingViews[vId]["quality"] size = [int(s * ratio) for s in self.trackingViews[vId]["originalSize"]] - reply = self.stillRender({ "view": vId, "mtime": mtime, "quality": quality, "size": size }) + reply = self.stillRender( + {"view": vId, "mtime": mtime, "quality": quality, "size": size} + ) stale = reply["stale"] if reply["image"]: # depending on whether the app has encoding enabled: @@ -63,33 +65,36 @@ def pushRender(self, vId, ignoreAnimation = False): self.trackingViews[vId]["mtime"] = reply["mtime"] # echo back real ID, instead of -1 for 'active' reply["id"] = vId - self.publish('viewport.image.push.subscription', reply) + self.publish("viewport.image.push.subscription", reply) if stale: self.lastStaleTime = time.time() if self.staleHandlerCount == 0: self.staleHandlerCount += 1 - reactor.callLater(self.deltaStaleTimeBeforeRender, lambda: self.renderStaleImage(vId)) + reactor.callLater( + self.deltaStaleTimeBeforeRender, lambda: self.renderStaleImage(vId) + ) else: self.lastStaleTime = 0 - def renderStaleImage(self, vId): self.staleHandlerCount -= 1 if self.lastStaleTime != 0: - delta = (time.time() - self.lastStaleTime) + delta = time.time() - self.lastStaleTime if delta >= self.deltaStaleTimeBeforeRender: self.pushRender(vId) else: self.staleHandlerCount += 1 - reactor.callLater(self.deltaStaleTimeBeforeRender - delta + 0.001, lambda: self.renderStaleImage(vId)) - + reactor.callLater( + self.deltaStaleTimeBeforeRender - delta + 0.001, + lambda: self.renderStaleImage(vId), + ) def animate(self): if len(self.viewsInAnimations) == 0: return - nextAnimateTime = time.time() + 1.0 / self.targetFrameRate + nextAnimateTime = time.time() + 1.0 / self.targetFrameRate for vId in self.viewsInAnimations: self.pushRender(vId, True) @@ -109,19 +114,16 @@ def animate(self): self.targetFrameRate += 1.0 reactor.callLater(nextAnimateTime, lambda: self.animate()) - @exportRpc("viewport.image.animation.fps.max") - def setMaxFrameRate(self, fps = 30): + def setMaxFrameRate(self, fps=30): self.maxFrameRate = fps - @exportRpc("viewport.image.animation.fps.get") def getCurrentFrameRate(self): return self.targetFrameRate - @exportRpc("viewport.image.animation.start") - def startViewAnimation(self, viewId = '-1'): + def startViewAnimation(self, viewId="-1"): sView = self.getView(viewId) realViewId = str(self.getGlobalId(sView)) @@ -129,21 +131,19 @@ def startViewAnimation(self, viewId = '-1'): if len(self.viewsInAnimations) == 1: self.animate() - @exportRpc("viewport.image.animation.stop") - def stopViewAnimation(self, viewId = '-1'): + def stopViewAnimation(self, viewId="-1"): sView = self.getView(viewId) realViewId = str(self.getGlobalId(sView)) if realViewId in self.viewsInAnimations: self.viewsInAnimations.remove(realViewId) - @exportRpc("viewport.image.push") def imagePush(self, options): sView = self.getView(options["view"]) realViewId = str(self.getGlobalId(sView)) - # Make sure an image is pushed + # Make sure an image is pushed self.getApplication().InvalidateCache(sView) self.pushRender(realViewId) @@ -160,7 +160,7 @@ def stillRender(self, options): if resize: size = options["size"] if size[0] > 10 and size[1] > 10: - view.SetSize(size) + view.SetSize(size) t = 0 if options and "mtime" in options: t = options["mtime"] @@ -183,13 +183,17 @@ def stillRender(self, options): # Check that we are getting image size we have set if not wait until we # do. The render call will set the actual window size. tries = 10 - while resize and list(view.GetSize()) != size \ - and size != [0, 0] and tries > 0: + while resize and list(view.GetSize()) != size and size != [0, 0] and tries > 0: app.InvalidateCache(view) reply_image = stillRender(view, t, quality) tries -= 1 - if not resize and options and ("clearCache" in options) and options["clearCache"]: + if ( + not resize + and options + and ("clearCache" in options) + and options["clearCache"] + ): app.InvalidateCache(view) reply_image = stillRender(view, t, quality) @@ -207,16 +211,15 @@ def stillRender(self, options): reply["image"] = memoryview(reply_image).tobytes() if reply_image else None endTime = int(round(time.time() * 1000)) - reply["workTime"] = (endTime - beginTime) + reply["workTime"] = endTime - beginTime return reply - @exportRpc("viewport.image.push.observer.add") def addRenderObserver(self, viewId): sView = self.getView(viewId) if not sView: - return { 'error': 'Unable to get view with id %s' % viewId } + return {"error": "Unable to get view with id %s" % viewId} realViewId = str(self.getGlobalId(sView)) @@ -224,24 +227,33 @@ def addRenderObserver(self, viewId): observerCallback = lambda *args, **kwargs: self.pushRender(realViewId) startCallback = lambda *args, **kwargs: self.startViewAnimation(realViewId) stopCallback = lambda *args, **kwargs: self.stopViewAnimation(realViewId) - tag = self.getApplication().AddObserver('UpdateEvent', observerCallback) - tagStart = self.getApplication().AddObserver('StartInteractionEvent', startCallback) - tagStop = self.getApplication().AddObserver('EndInteractionEvent', stopCallback) + tag = self.getApplication().AddObserver("UpdateEvent", observerCallback) + tagStart = self.getApplication().AddObserver( + "StartInteractionEvent", startCallback + ) + tagStop = self.getApplication().AddObserver( + "EndInteractionEvent", stopCallback + ) # TODO do we need self.getApplication().AddObserver('ResetActiveView', resetActiveView()) - self.trackingViews[realViewId] = { 'tags': [tag, tagStart, tagStop], 'observerCount': 1, 'mtime': 0, 'enabled': True, 'quality': 100 } + self.trackingViews[realViewId] = { + "tags": [tag, tagStart, tagStop], + "observerCount": 1, + "mtime": 0, + "enabled": True, + "quality": 100, + } else: # There is an observer on this view already - self.trackingViews[realViewId]['observerCount'] += 1 + self.trackingViews[realViewId]["observerCount"] += 1 self.pushRender(realViewId) - return { 'success': True, 'viewId': realViewId } - + return {"success": True, "viewId": realViewId} @exportRpc("viewport.image.push.observer.remove") def removeRenderObserver(self, viewId): sView = self.getView(viewId) if not sView: - return { 'error': 'Unable to get view with id %s' % viewId } + return {"error": "Unable to get view with id %s" % viewId} realViewId = str(self.getGlobalId(sView)) @@ -250,23 +262,22 @@ def removeRenderObserver(self, viewId): observerInfo = self.trackingViews[realViewId] if not observerInfo: - return { 'error': 'Unable to find subscription for view %s' % realViewId } + return {"error": "Unable to find subscription for view %s" % realViewId} - observerInfo['observerCount'] -= 1 + observerInfo["observerCount"] -= 1 - if observerInfo['observerCount'] <= 0: - for tag in observerInfo['tags']: + if observerInfo["observerCount"] <= 0: + for tag in observerInfo["tags"]: self.getApplication().RemoveObserver(tag) del self.trackingViews[realViewId] - return { 'result': 'success' } - + return {"result": "success"} @exportRpc("viewport.image.push.quality") - def setViewQuality(self, viewId, quality, ratio = 1): + def setViewQuality(self, viewId, quality, ratio=1): sView = self.getView(viewId) if not sView: - return { 'error': 'Unable to get view with id %s' % viewId } + return {"error": "Unable to get view with id %s" % viewId} realViewId = str(self.getGlobalId(sView)) observerInfo = None @@ -274,27 +285,28 @@ def setViewQuality(self, viewId, quality, ratio = 1): observerInfo = self.trackingViews[realViewId] if not observerInfo: - return { 'error': 'Unable to find subscription for view %s' % realViewId } + return {"error": "Unable to find subscription for view %s" % realViewId} - observerInfo['quality'] = quality - observerInfo['ratio'] = ratio + observerInfo["quality"] = quality + observerInfo["ratio"] = ratio # Update image size right now! if "originalSize" in self.trackingViews[realViewId]: - size = [int(s * ratio) for s in self.trackingViews[realViewId]["originalSize"]] - if hasattr(sView, 'SetSize'): + size = [ + int(s * ratio) for s in self.trackingViews[realViewId]["originalSize"] + ] + if hasattr(sView, "SetSize"): sView.SetSize(size) else: sView.ViewSize = size - return { 'result': 'success' } - + return {"result": "success"} @exportRpc("viewport.image.push.original.size") def setViewSize(self, viewId, width, height): sView = self.getView(viewId) if not sView: - return { 'error': 'Unable to get view with id %s' % viewId } + return {"error": "Unable to get view with id %s" % viewId} realViewId = str(self.getGlobalId(sView)) observerInfo = None @@ -302,17 +314,17 @@ def setViewSize(self, viewId, width, height): observerInfo = self.trackingViews[realViewId] if not observerInfo: - return { 'error': 'Unable to find subscription for view %s' % realViewId } + return {"error": "Unable to find subscription for view %s" % realViewId} - observerInfo['originalSize'] = [width, height] + observerInfo["originalSize"] = [width, height] - return { 'result': 'success' } + return {"result": "success"} @exportRpc("viewport.image.push.enabled") def enableView(self, viewId, enabled): sView = self.getView(viewId) if not sView: - return { 'error': 'Unable to get view with id %s' % viewId } + return {"error": "Unable to get view with id %s" % viewId} realViewId = str(self.getGlobalId(sView)) observerInfo = None @@ -320,18 +332,18 @@ def enableView(self, viewId, enabled): observerInfo = self.trackingViews[realViewId] if not observerInfo: - return { 'error': 'Unable to find subscription for view %s' % realViewId } + return {"error": "Unable to find subscription for view %s" % realViewId} - observerInfo['enabled'] = enabled + observerInfo["enabled"] = enabled - return { 'result': 'success' } + return {"result": "success"} @exportRpc("viewport.image.push.invalidate.cache") def invalidateCache(self, viewId): sView = self.getView(viewId) if not sView: - return { 'error': 'Unable to get view with id %s' % viewId } + return {"error": "Unable to get view with id %s" % viewId} self.getApplication().InvalidateCache(sView) - self.getApplication().InvokeEvent('UpdateEvent') - return { 'result': 'success' } + self.getApplication().InvokeEvent("UpdateEvent") + return {"result": "success"} diff --git a/src/opengeodeweb_viewer/vtk_protocol.py b/src/opengeodeweb_viewer/vtk_protocol.py index 9ce1efc..292a4ff 100644 --- a/src/opengeodeweb_viewer/vtk_protocol.py +++ b/src/opengeodeweb_viewer/vtk_protocol.py @@ -7,6 +7,7 @@ # Local application imports + class VtkView(vtk_protocols.vtkWebProtocol): def __init__(self): super().__init__() @@ -42,15 +43,3 @@ def register_object(self, id, reader, filter, actor, mapper, textures): def deregister_object(self, id): del self.get_data_base()[id] - - - - - - - - - - - - \ No newline at end of file diff --git a/src/opengeodeweb_viewer/vtkw_server.py b/src/opengeodeweb_viewer/vtkw_server.py index 134a0d9..81918ee 100644 --- a/src/opengeodeweb_viewer/vtkw_server.py +++ b/src/opengeodeweb_viewer/vtkw_server.py @@ -35,7 +35,9 @@ class _Server(vtk_wslink.ServerProtocol): @staticmethod def add_arguments(parser): parser.add_argument( - "--data_folder_path", default=os.environ.get("DATA_FOLDER_PATH"), help="Path to the folder where data is stored" + "--data_folder_path", + default=os.environ.get("DATA_FOLDER_PATH"), + help="Path to the folder where data is stored", ) @staticmethod @@ -64,7 +66,7 @@ def initialize(self): self.registerVtkWebProtocol(VtkMeshPolyhedronsView()) self.registerVtkWebProtocol(model_protocols) self.registerVtkWebProtocol(VtkGenericView(mesh_protocols, model_protocols)) - + # tell the C++ web app to use no encoding. # ParaViewWebPublishImageDelivery must be set to decode=False to match. self.getApplication().SetImageEncoding(0) @@ -112,7 +114,7 @@ def run_server(Server=_Server): Server.add_arguments(parser) args = parser.parse_args() - + if not "host" in args: args.host = os.environ["DEFAULT_HOST"] if not "port" in args or args.port == 8080: diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 43bf870..c89ebe8 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -109,8 +109,7 @@ def compare_image(self, nb_messages, filename): path_image = os.path.join(self.images_dir_path, filename) - return self.images_diff(test_file_path, path_image)==0.0 - + return self.images_diff(test_file_path, path_image) == 0.0 class FixtureHelper: diff --git a/src/tests/mesh/edges/test_edges_protocols.py b/src/tests/mesh/edges/test_edges_protocols.py index f9fb721..8df92d2 100644 --- a/src/tests/mesh/edges/test_edges_protocols.py +++ b/src/tests/mesh/edges/test_edges_protocols.py @@ -6,16 +6,26 @@ # Local application imports from tests.test_mesh_protocols import test_register_mesh + def test_edges_visibility(server): test_register_mesh(server) - server.call(VtkMeshEdgesView.mesh_edges_prefix + VtkMeshEdgesView.mesh_edges_schemas_dict["visibility"]["rpc"], [{"id": "123456789", "visibility": True}]) + server.call( + VtkMeshEdgesView.mesh_edges_prefix + + VtkMeshEdgesView.mesh_edges_schemas_dict["visibility"]["rpc"], + [{"id": "123456789", "visibility": True}], + ) assert server.compare_image(3, "mesh/edges/visibility.jpeg") == True + def test_edges_color(server): test_edges_visibility(server) - server.call(VtkMeshEdgesView.mesh_edges_prefix + VtkMeshEdgesView.mesh_edges_schemas_dict["color"]["rpc"], [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}]) + server.call( + VtkMeshEdgesView.mesh_edges_prefix + + VtkMeshEdgesView.mesh_edges_schemas_dict["color"]["rpc"], + [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}], + ) assert server.compare_image(3, "mesh/edges/color.jpeg") == True diff --git a/src/tests/mesh/points/test_points_protocols.py b/src/tests/mesh/points/test_points_protocols.py index 74ce746..c8b2e1c 100644 --- a/src/tests/mesh/points/test_points_protocols.py +++ b/src/tests/mesh/points/test_points_protocols.py @@ -6,18 +6,28 @@ # Local application imports from tests.test_mesh_protocols import test_register_mesh + def test_points_visibility(server): test_register_mesh(server) - server.call(VtkMeshPointsView.mesh_points_prefix + VtkMeshPointsView.mesh_points_schemas_dict["visibility"]["rpc"], [{"id": "123456789", "visibility": True}]) + server.call( + VtkMeshPointsView.mesh_points_prefix + + VtkMeshPointsView.mesh_points_schemas_dict["visibility"]["rpc"], + [{"id": "123456789", "visibility": True}], + ) assert server.compare_image(3, "mesh/points/visibility.jpeg") == True + def test_points_size(server): test_points_visibility(server) - server.call(VtkMeshPointsView.mesh_points_prefix + VtkMeshPointsView.mesh_points_schemas_dict["size"]["rpc"], [{"id": "123456789", "size": 15}]) + server.call( + VtkMeshPointsView.mesh_points_prefix + + VtkMeshPointsView.mesh_points_schemas_dict["size"]["rpc"], + [{"id": "123456789", "size": 15}], + ) assert server.compare_image(3, "mesh/points/size.jpeg") == True @@ -25,6 +35,9 @@ def test_points_color(server): test_points_size(server) - server.call(VtkMeshPointsView.mesh_points_prefix + VtkMeshPointsView.mesh_points_schemas_dict["color"]["rpc"], [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}]) + server.call( + VtkMeshPointsView.mesh_points_prefix + + VtkMeshPointsView.mesh_points_schemas_dict["color"]["rpc"], + [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}], + ) assert server.compare_image(3, "mesh/points/color.jpeg") == True - diff --git a/src/tests/mesh/polygons/test_polygons_protocols.py b/src/tests/mesh/polygons/test_polygons_protocols.py index a519bcf..200b781 100644 --- a/src/tests/mesh/polygons/test_polygons_protocols.py +++ b/src/tests/mesh/polygons/test_polygons_protocols.py @@ -11,7 +11,11 @@ def test_polygons_color(server): test_register_mesh(server) - server.call(VtkMeshPolygonsView.mesh_polygons_prefix + VtkMeshPolygonsView.mesh_polygons_schemas_dict["color"]["rpc"], [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}]) + server.call( + VtkMeshPolygonsView.mesh_polygons_prefix + + VtkMeshPolygonsView.mesh_polygons_schemas_dict["color"]["rpc"], + [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}], + ) assert server.compare_image(3, "mesh/polygons/color.jpeg") == True @@ -19,5 +23,9 @@ def test_polygons_visibility(server): test_register_mesh(server) - server.call(VtkMeshPolygonsView.mesh_polygons_prefix + VtkMeshPolygonsView.mesh_polygons_schemas_dict["visibility"]["rpc"], [{"id": "123456789", "visibility": False}]) + server.call( + VtkMeshPolygonsView.mesh_polygons_prefix + + VtkMeshPolygonsView.mesh_polygons_schemas_dict["visibility"]["rpc"], + [{"id": "123456789", "visibility": False}], + ) assert server.compare_image(3, "mesh/polygons/visibility.jpeg") == True diff --git a/src/tests/mesh/polyhedrons/test_polyhedrons_protocols.py b/src/tests/mesh/polyhedrons/test_polyhedrons_protocols.py index 65a9111..c96a66e 100644 --- a/src/tests/mesh/polyhedrons/test_polyhedrons_protocols.py +++ b/src/tests/mesh/polyhedrons/test_polyhedrons_protocols.py @@ -2,35 +2,57 @@ # Third party imports from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView -from opengeodeweb_viewer.rpc.mesh.polyhedrons.polyhedrons_protocols import VtkMeshPolyhedronsView +from opengeodeweb_viewer.rpc.mesh.polyhedrons.polyhedrons_protocols import ( + VtkMeshPolyhedronsView, +) # Local application imports def test_register_mesh(server): - server.call(VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["register"]["rpc"], [{"id": "123456789", "file_name": "hybrid_solid.vtu"}]) + server.call( + VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["register"]["rpc"], + [{"id": "123456789", "file_name": "hybrid_solid.vtu"}], + ) assert server.compare_image(3, "mesh/polyhedrons/register.jpeg") == True + def test_polyhedrons_color(server): test_register_mesh(server) - server.call(VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["color"]["rpc"], [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}]) + server.call( + VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["color"]["rpc"], + [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}], + ) assert server.compare_image(3, "mesh/polyhedrons/color.jpeg") == True + def test_polyhedrons_visibility(server): test_register_mesh(server) - server.call(VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["visibility"]["rpc"], [{"id": "123456789", "visibility": False}]) + server.call( + VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["visibility"]["rpc"], + [{"id": "123456789", "visibility": False}], + ) assert server.compare_image(3, "mesh/polyhedrons/visibility.jpeg") == True + def test_vertex_attribute(server): test_register_mesh(server) - server.call(VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["vertex_attribute"]["rpc"], [{"id": "123456789", "name": "toto_on_vertices"}]) + server.call( + VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["vertex_attribute"][ + "rpc" + ], + [{"id": "123456789", "name": "toto_on_vertices"}], + ) assert server.compare_image(3, "mesh/polyhedrons/vertex_attribute.jpeg") == True @@ -38,5 +60,11 @@ def test_polyhedron_attribute(server): test_register_mesh(server) - server.call(VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["polyhedron_attribute"]["rpc"], [{"id": "123456789", "name": "toto_on_polyhedra"}]) - assert server.compare_image(3, "mesh/polyhedrons/polyhedron_attribute.jpeg") == True \ No newline at end of file + server.call( + VtkMeshPolyhedronsView.mesh_polyhedrons_prefix + + VtkMeshPolyhedronsView.mesh_polyhedrons_schemas_dict["polyhedron_attribute"][ + "rpc" + ], + [{"id": "123456789", "name": "toto_on_polyhedra"}], + ) + assert server.compare_image(3, "mesh/polyhedrons/polyhedron_attribute.jpeg") == True diff --git a/src/tests/test_generic_protocols.py b/src/tests/test_generic_protocols.py index a536d7b..1c3df00 100644 --- a/src/tests/test_generic_protocols.py +++ b/src/tests/test_generic_protocols.py @@ -1,21 +1,47 @@ from opengeodeweb_viewer.rpc.generic.generic_protocols import VtkGenericView + def test_register_mesh(server): - server.call(VtkGenericView.generic_prefix + VtkGenericView.generic_schemas_dict["register"]["rpc"], [{"viewer_object": "mesh", "id": "123456789", "file_name": "hat.vtp"}]) + server.call( + VtkGenericView.generic_prefix + + VtkGenericView.generic_schemas_dict["register"]["rpc"], + [{"viewer_object": "mesh", "id": "123456789", "file_name": "hat.vtp"}], + ) assert server.compare_image(3, "mesh/register.jpeg") == True + def test_register_model(server): - server.call(VtkGenericView.generic_prefix + VtkGenericView.generic_schemas_dict["register"]["rpc"], [{"viewer_object": "model", "id": "123456789", "file_name": "CrossSection.vtm"}]) + server.call( + VtkGenericView.generic_prefix + + VtkGenericView.generic_schemas_dict["register"]["rpc"], + [ + { + "viewer_object": "model", + "id": "123456789", + "file_name": "CrossSection.vtm", + } + ], + ) assert server.compare_image(3, "model/register.jpeg") == True + def test_deregister_mesh(server): test_register_mesh(server) - server.call(VtkGenericView.generic_prefix + VtkGenericView.generic_schemas_dict["deregister"]["rpc"], [{"viewer_object": "mesh", "id": "123456789"}]) + server.call( + VtkGenericView.generic_prefix + + VtkGenericView.generic_schemas_dict["deregister"]["rpc"], + [{"viewer_object": "mesh", "id": "123456789"}], + ) assert server.compare_image(3, "mesh/deregister.jpeg") == True + def test_deregister_model(server): test_register_model(server) - server.call(VtkGenericView.generic_prefix + VtkGenericView.generic_schemas_dict["deregister"]["rpc"], [{"viewer_object": "model", "id": "123456789"}]) - assert server.compare_image(3, "model/deregister.jpeg") == True \ No newline at end of file + server.call( + VtkGenericView.generic_prefix + + VtkGenericView.generic_schemas_dict["deregister"]["rpc"], + [{"viewer_object": "model", "id": "123456789"}], + ) + assert server.compare_image(3, "model/deregister.jpeg") == True diff --git a/src/tests/test_mesh_protocols.py b/src/tests/test_mesh_protocols.py index 18c9cfc..d38f41b 100644 --- a/src/tests/test_mesh_protocols.py +++ b/src/tests/test_mesh_protocols.py @@ -1,38 +1,67 @@ - - from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView + def test_register_mesh(server): - server.call(VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["register"]["rpc"], [{"id": "123456789", "file_name": "hat.vtp"}]) + server.call( + VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["register"]["rpc"], + [{"id": "123456789", "file_name": "hat.vtp"}], + ) assert server.compare_image(3, "mesh/register.jpeg") == True + def test_deregister_mesh(server): test_register_mesh(server) - server.call(VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["deregister"]["rpc"], [{"id": "123456789"}]) + server.call( + VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["deregister"]["rpc"], + [{"id": "123456789"}], + ) assert server.compare_image(3, "mesh/deregister.jpeg") == True + def test_opacity(server): test_register_mesh(server) - server.call(VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["opacity"]["rpc"], [{"id": "123456789", "opacity": 0.1}]) + server.call( + VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["opacity"]["rpc"], + [{"id": "123456789", "opacity": 0.1}], + ) assert server.compare_image(3, "mesh/opacity.jpeg") == True + def test_color(server): test_register_mesh(server) - server.call(VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["color"]["rpc"], [{"id": "123456789", "color": {"r": 50, "g": 2, "b": 250}}]) + server.call( + VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["color"]["rpc"], + [{"id": "123456789", "color": {"r": 50, "g": 2, "b": 250}}], + ) assert server.compare_image(3, "mesh/color.jpeg") == True + def test_apply_textures(server): test_register_mesh(server) - server.call(VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["apply_textures"]["rpc"], [{"id": "123456789", "textures": [{"texture_name": "lambert2SG", "texture_file_name": "hat_lambert2SG.vti"}]}]) + server.call( + VtkMeshView.mesh_prefix + + VtkMeshView.mesh_schemas_dict["apply_textures"]["rpc"], + [ + { + "id": "123456789", + "textures": [ + { + "texture_name": "lambert2SG", + "texture_file_name": "hat_lambert2SG.vti", + } + ], + } + ], + ) assert server.compare_image(3, "mesh/apply_textures.jpeg") == True @@ -61,4 +90,4 @@ def test_apply_textures(server): # VtkMeshView.mesh_prefix + VtkMeshView.mesh_schemas_dict["display_polygon_attribute"]["rpc"], # [{"id": "123456789", "name": "implicit_on_polygons"}], # ) -# assert server.compare_image(3, "mesh/display_polygon_attribute_2.jpeg") == True \ No newline at end of file +# assert server.compare_image(3, "mesh/display_polygon_attribute_2.jpeg") == True diff --git a/src/tests/test_model_protocols.py b/src/tests/test_model_protocols.py index 54ca560..de912ac 100644 --- a/src/tests/test_model_protocols.py +++ b/src/tests/test_model_protocols.py @@ -1,35 +1,58 @@ from opengeodeweb_viewer.rpc.model.model_protocols import VtkModelView + def test_register_model(server): - server.call(VtkModelView.model_prefix + VtkModelView.model_schemas_dict["register"]["rpc"], [{"id": "123456789", "file_name": "CrossSection.vtm"}]) + server.call( + VtkModelView.model_prefix + VtkModelView.model_schemas_dict["register"]["rpc"], + [{"id": "123456789", "file_name": "CrossSection.vtm"}], + ) assert server.compare_image(3, "model/register.jpeg") == True + def test_deregister_model(server): test_register_model(server) - server.call(VtkModelView.model_prefix + VtkModelView.model_schemas_dict["deregister"]["rpc"], [{"id": "123456789"}]) + server.call( + VtkModelView.model_prefix + + VtkModelView.model_schemas_dict["deregister"]["rpc"], + [{"id": "123456789"}], + ) assert server.compare_image(3, "model/deregister.jpeg") == True def test_set_mesh_visibility(server): test_register_model(server) - - server.call(VtkModelView.model_prefix + VtkModelView.model_schemas_dict["set_mesh_visibility"]["rpc"], [{"id": "123456789", "visibility": True}]) + + server.call( + VtkModelView.model_prefix + + VtkModelView.model_schemas_dict["set_mesh_visibility"]["rpc"], + [{"id": "123456789", "visibility": True}], + ) assert server.compare_image(3, "model/set_mesh_visibility.jpeg") == True + def test_set_components_visibility(server): test_register_model(server) - server.call(VtkModelView.model_prefix + VtkModelView.model_schemas_dict["set_components_visibility"]["rpc"], [{"id": "123456789", "visibility": False}]) + server.call( + VtkModelView.model_prefix + + VtkModelView.model_schemas_dict["set_components_visibility"]["rpc"], + [{"id": "123456789", "visibility": False}], + ) assert server.compare_image(3, "model/set_components_visibility.jpeg") == True + def test_set_components_color(server): test_register_model(server) - server.call(VtkModelView.model_prefix + VtkModelView.model_schemas_dict["set_components_color"]["rpc"], [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}]) - assert server.compare_image(3, "model/set_components_color.jpeg") == True \ No newline at end of file + server.call( + VtkModelView.model_prefix + + VtkModelView.model_schemas_dict["set_components_color"]["rpc"], + [{"id": "123456789", "color": {"r": 255, "g": 0, "b": 0}}], + ) + assert server.compare_image(3, "model/set_components_color.jpeg") == True