Skip to content

Commit

Permalink
Merge pull request #169 from specklesystems/jrm/deps/specklepy216
Browse files Browse the repository at this point in the history
Jrm/deps/specklepy216
  • Loading branch information
JR-Morgan committed Sep 8, 2023
2 parents 201ca5f + 319cbf8 commit 2688a69
Show file tree
Hide file tree
Showing 14 changed files with 478 additions and 437 deletions.
4 changes: 2 additions & 2 deletions bpy_speckle/blender_commit_object_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bpy.types import Object, Collection, ID
from specklepy.objects.base import Base
from bpy_speckle.functions import _report
from bpy_speckle.specklepy_extras.commit_object_builder import CommitObjectBuilder, ROOT
from specklepy.objects.graph_traversal.commit_object_builder import CommitObjectBuilder, ROOT
from specklepy.objects import Base
from specklepy.objects.other import Collection as SCollection
from attrs import define
Expand Down Expand Up @@ -79,7 +79,7 @@ def build_commit_object(self, root_commit_object: Base) -> None:
# Create all collections
root_col = self.ensure_collection(bpy.context.scene.collection)
root_col.collectionType = "Scene Collection"
for col in bpy.context.scene.collection.children_recursive:
for col in bpy.context.scene.collection.children_recursive: #type: ignore
self.ensure_collection(col)

objects_to_build = set(self.converted.values())
Expand Down
2 changes: 1 addition & 1 deletion bpy_speckle/clients.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Permanent handle on all user clients
"""
from specklepy.api.client import SpeckleClient
from specklepy.core.api.client import SpeckleClient


speckle_clients: list[SpeckleClient] = []
5 changes: 4 additions & 1 deletion bpy_speckle/convert/to_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,15 @@ def view_to_native(speckle_view, name: str, scale: float) -> bpy.types.Object:
native_cam = bpy.data.cameras.new(name=name)
native_cam.lens = 18 # 90° horizontal fov

if not hasattr(speckle_view, "origin"):
raise ConversionSkippedException("2D views not supported")

cam_obj = create_new_object(native_cam, name)

scale_factor = get_scale_factor(speckle_view, scale)
tx = (speckle_view.origin.x * scale_factor)
ty = (speckle_view.origin.y * scale_factor)
tz = (speckle_view.origin.z * scale_factor) #TODO: do these need to be scaled?
tz = (speckle_view.origin.z * scale_factor)

forward = MVector((speckle_view.forwardDirection.x, speckle_view.forwardDirection.y, speckle_view.forwardDirection.z))
up = MVector((speckle_view.upDirection.x, speckle_view.upDirection.y, speckle_view.upDirection.z))
Expand Down
2 changes: 1 addition & 1 deletion bpy_speckle/convert/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from bpy_speckle.functions import _report
from bpy.types import Material, Object, Collection as BCollection, Node, ShaderNodeVertexColor

from bpy_speckle.specklepy_extras.traversal import TraversalContext
from specklepy.objects.graph_traversal.traversal import TraversalContext

class ConversionSkippedException(Exception):
pass
Expand Down
47 changes: 8 additions & 39 deletions bpy_speckle/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,20 @@
from specklepy.objects.base import Base
from bpy_speckle.convert.constants import ELEMENTS_PROPERTY_ALIASES

from bpy_speckle.specklepy_extras.traversal import GraphTraversal, TraversalRule
from specklepy.objects.graph_traversal.traversal import GraphTraversal, TraversalRule
from specklepy.objects.units import get_scale_factor_to_meters, get_units_from_string

"""
Speckle functions
"""

UNIT_SCALE = {
"meters": 1.0,
"centimeters": 0.01,
"millimeters": 0.001,
"inches": 0.0254,
"feet": 0.3048,
"kilometers": 1000.0,
"mm": 0.001,
"cm": 0.01,
"m": 1.0,
"km": 1000.0,
"in": 0.0254,
"ft": 0.3048,
"yd": 0.9144,
"mi": 1609.340,
}

"""
Utility functions
"""


def _report(msg):
def _report(msg: object) -> None:
"""
Function for printing messages to the console
"""
print("SpeckleBlender: {}".format(msg))


def get_scale_length(units: str) -> float:
if units.lower() in UNIT_SCALE.keys():
return UNIT_SCALE[units]
_report("Units <{}> are not supported.".format(units))
return 1.0


"""
Client, user, and stream functions
"""
"""Returns a scalar to convert distance values from one unit system to meters"""
return get_scale_factor_to_meters(get_units_from_string(units))


def get_default_traversal_func(can_convert_to_native: Callable[[Base], bool]) -> GraphTraversal:
Expand All @@ -56,13 +25,13 @@ def get_default_traversal_func(can_convert_to_native: Callable[[Base], bool]) ->

ignore_rule = TraversalRule(
[
lambda o: "Objects.Structural.Results" in o.speckle_type, #Sadly, this one is nessasary to avoid double conversion...
lambda o: "Objects.Structural.Results" in o.speckle_type, #Sadly, this one is necessary to avoid double conversion...
lambda o: "Objects.BuiltElements.Revit.Parameter" in o.speckle_type, #This one is just for traversal performance of revit commits
],
lambda _: [],
)

convertable_rule = TraversalRule(
convertible_rule = TraversalRule(
[can_convert_to_native],
lambda _: ELEMENTS_PROPERTY_ALIASES,
)
Expand All @@ -73,4 +42,4 @@ def get_default_traversal_func(can_convert_to_native: Callable[[Base], bool]) ->
lambda o: o.get_member_names(), #TODO: avoid deprecated members
)

return GraphTraversal([ignore_rule, convertable_rule, default_rule])
return GraphTraversal([ignore_rule, convertible_rule, default_rule])
10 changes: 10 additions & 0 deletions bpy_speckle/operators/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from bpy.props import BoolProperty
from bpy_speckle.clients import speckle_clients
from bpy_speckle.properties.scene import get_speckle
from specklepy.logging import metrics


class DeleteCommit(bpy.types.Operator):
Expand Down Expand Up @@ -58,6 +59,15 @@ def delete_commit(self, context: bpy.types.Context) -> None:
client = speckle_clients[int(speckle.active_user)]

deleted = client.commit.delete(stream_id=stream.id, commit_id=commit.id)

metrics.track(
"Connector Action",
client.account,
custom_props={
"name": "delete_commit"
},
)

if not deleted:
raise Exception("Delete operation failed")

Expand Down
22 changes: 22 additions & 0 deletions bpy_speckle/operators/misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import bpy
import webbrowser
from specklepy.logging import metrics


class OpenSpeckleGuide(bpy.types.Operator):
Expand All @@ -10,6 +11,13 @@ class OpenSpeckleGuide(bpy.types.Operator):

def execute(self, context):
webbrowser.open("https://speckle.guide/user/blender.html")
metrics.track(
"Connector Action",
None,
custom_props={
"name": "OpenSpeckleGuide"
},
)
return {"FINISHED"}


Expand All @@ -21,6 +29,13 @@ class OpenSpeckleTutorials(bpy.types.Operator):

def execute(self, context):
webbrowser.open("https://speckle.systems/tutorials/")
metrics.track(
"Connector Action",
None,
custom_props={
"name": "OpenSpeckleTutorials"
},
)
return {"FINISHED"}


Expand All @@ -32,4 +47,11 @@ class OpenSpeckleForum(bpy.types.Operator):

def execute(self, context):
webbrowser.open("https://speckle.community/")
metrics.track(
"Connector Action",
None,
custom_props={
"name": "OpenSpeckleForum"
},
)
return {"FINISHED"}
49 changes: 48 additions & 1 deletion bpy_speckle/operators/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from bpy_speckle.functions import get_scale_length, _report
from bpy_speckle.clients import speckle_clients

from specklepy.logging import metrics

class UpdateObject(bpy.types.Operator):
"""
Expand Down Expand Up @@ -56,6 +56,13 @@ def execute(self, context):
_report("Updating object {}".format(sm["_id"]))
client.objects.update(active.speckle.object_id, sm)

metrics.track(
"Connector Action",
None,
custom_props={
"name": "UpdateObject"
},
)
return {"FINISHED"}

return {"CANCELLED"}
Expand All @@ -79,6 +86,14 @@ def execute(self, context):
context.object.speckle.enabled = False
context.view_layer.update()

metrics.track(
"Connector Action",
None,
custom_props={
"name": "ResetObject"
},
)

return {"FINISHED"}


Expand Down Expand Up @@ -125,6 +140,14 @@ def execute(self, context):
active.speckle.enabled = False
context.view_layer.update()

metrics.track(
"Connector Action",
None,
custom_props={
"name": "DeleteObject"
},
)

return {"FINISHED"}

@deprecated
Expand Down Expand Up @@ -197,6 +220,13 @@ def execute(self, context):
context.view_layer.update()
_report("Done.")

metrics.track(
"Connector Action",
None,
custom_props={
"name": "UploadNgonsAsPolylines"
},
)
return {"FINISHED"}

def invoke(self, context, event):
Expand Down Expand Up @@ -267,6 +297,14 @@ def execute(self, context):
else:
obj.select_set(False)

metrics.track(
"Connector Action",
None,
custom_props={
"name": "SelectIfSameCustomProperty"
},
)

return {"FINISHED"}


Expand Down Expand Up @@ -315,4 +353,13 @@ def execute(self, context):
else:
obj.select_set(False)

metrics.track(
"Connector Action",
None,
custom_props={
"name": "SelectIfHasCustomProperty"
},
)


return {"FINISHED"}
Loading

0 comments on commit 2688a69

Please sign in to comment.