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

Rhino compatibility #31

Merged
merged 19 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `compas_model.rhino.scene.RhinoBlockObject`.
* Added `compas_model.notebook.scene.ThreeBlockObject`.
* Added `compas_model.elements_connected_by`.
* Added plugin for `installable_rhino_package`.
* Added `PlateElement` and `PlateFeature` to 2nd level imports.

### Changed

* Fixed cannot import `compas_model.elements` in Rhino.

### Removed
1 change: 1 addition & 0 deletions src/compas_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

__all_plugins__ = [
"compas_model.scene",
"compas_model.rhino",
"compas_model.rhino.scene",
"compas_model.notebook.scene",
]
4 changes: 4 additions & 0 deletions src/compas_model/elements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from .block import BlockFeature
from .interface import InterfaceElement
from .interface import InterfaceFeature
from .plate import PlateElement
from .plate import PlateFeature


__all__ = [
Expand All @@ -13,4 +15,6 @@
"BlockFeature",
"InterfaceElement",
"InterfaceFeature",
"PlateElement",
"PlateFeature",
]
3 changes: 2 additions & 1 deletion src/compas_model/elements/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from compas.datastructures import Mesh
from compas.geometry import Box
from compas.geometry import bounding_box
from compas.geometry import convex_hull_numpy
from compas.geometry import oriented_bounding_box

from compas_model.elements import Element
Expand Down Expand Up @@ -99,6 +98,8 @@ def compute_obb(self, inflate=0.0):
return box

def compute_collision_mesh(self):
from compas.geometry import convex_hull_numpy
chenkasirer marked this conversation as resolved.
Show resolved Hide resolved

points = self.geometry.vertices_attributes("xyz") # type: ignore
vertices, faces = convex_hull_numpy(points)
vertices = [points[index] for index in vertices] # type: ignore
Expand Down
3 changes: 2 additions & 1 deletion src/compas_model/elements/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from compas.datastructures import Mesh
from compas.geometry import Box
from compas.geometry import bounding_box
from compas.geometry import convex_hull_numpy
from compas.geometry import oriented_bounding_box

from compas_model.elements import Element
Expand Down Expand Up @@ -93,6 +92,8 @@ def compute_obb(self, inflate=0.0):
return box

def compute_collision_mesh(self):
from compas.geometry import convex_hull_numpy
chenkasirer marked this conversation as resolved.
Show resolved Hide resolved

points = self.geometry.vertices_attributes("xyz") # type: ignore
vertices, faces = convex_hull_numpy(points)
vertices = [points[index] for index in vertices] # type: ignore
Expand Down
3 changes: 2 additions & 1 deletion src/compas_model/elements/plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from compas.datastructures import Mesh
from compas.geometry import Box
from compas.geometry import bounding_box
from compas.geometry import convex_hull_numpy
from compas.geometry import oriented_bounding_box
from compas.itertools import pairwise

Expand Down Expand Up @@ -114,6 +113,8 @@ def compute_obb(self, inflate=0.0):
return box

def compute_collision_mesh(self):
from compas.geometry import convex_hull_numpy

points = self.geometry.vertices_attributes("xyz") # type: ignore
vertices, faces = convex_hull_numpy(points)
vertices = [points[index] for index in vertices] # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion src/compas_model/model/elementtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __from_data__(cls, data):

def __init__(self, model, name=None):
# type: (compas_model.model.Model, str | None) -> None
super().__init__(name=name)
super(ElementTree, self).__init__(name=name)
root = GroupNode(name="root")
self.add(root)
self.model = model
Expand Down
2 changes: 1 addition & 1 deletion src/compas_model/model/interactiongraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __from_data__(cls, data, guid_element):

def __init__(self, default_node_attributes=None, default_edge_attributes=None, name=None, **kwargs):
# type: (dict | None, dict | None, str | None, dict) -> None
super().__init__(
super(InteractionGraph, self).__init__(
default_node_attributes=default_node_attributes,
default_edge_attributes=default_edge_attributes,
name=name,
Expand Down
3 changes: 1 addition & 2 deletions src/compas_model/model/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import OrderedDict
from collections import deque
from typing import Type # noqa: F401

import compas
import compas.datastructures # noqa: F401
Expand Down Expand Up @@ -117,7 +116,7 @@ def __getitem__(self, index):
# Info
# ==========================================================================

def print(self):
def print_model(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should just switch to using __str__ and print with print(model)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me but would have to make changes in Tree.print_hierarchy and InteractionGraph.print_interactions as they internally call print

Copy link
Collaborator Author

@chenkasirer chenkasirer Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw I think we should generally avoid calls to print in COMPAS, especially the parts that are more library-ish.

Copy link
Collaborator

@petrasvestartas petrasvestartas Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change to __str__ and then additional change will be needed for the tree in compas and merge this pull request. Due to multiple other packages, still ironpython needs to be supported for some time.

print("=" * 80)
print("Spatial Hierarchy")
print("=" * 80)
Expand Down
6 changes: 6 additions & 0 deletions src/compas_model/rhino/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import compas.plugins


@compas.plugins.plugin(category="install")
def installable_rhino_packages():
return ["compas_model"] # add all other dependencies that are needed and work in rhino
1 change: 0 additions & 1 deletion src/compas_model/scene/modelobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class ModelObject(SceneObject):

def __init__(
self,
model,
Expand Down
Loading