Skip to content

Commit 4087843

Browse files
committed
import + elements instead of blocks
1 parent 6ec00a9 commit 4087843

File tree

5 files changed

+129
-8
lines changed

5 files changed

+129
-8
lines changed

COMPAS-Masonry.rhproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"id": "4384e04f-2997-429b-b3fc-53e7fe78703e",
99
"identity": {
1010
"name": "COMPAS-Masonry",
11-
"version": "0.1.50-beta",
11+
"version": "0.1.53-beta",
1212
"publisher": {
1313
"email": "[email protected]",
1414
"name": "Tom Van Mele",

commands/DEA_blocks.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
import compas_rhino.layers
1010
from compas_dem.elements import Block
11+
from compas_dem.interactions import FrictionContact
1112
from compas_dem.models import BlockModel
1213
from compas_dem.templates import ArchTemplate
1314
from compas_dem.templates import BarrelVaultTemplate
1415
from compas_dem.templates import DomeTemplate
1516
from compas_masonry.session import MasonrySession as Session
17+
from compas_model.models import InteractionGraph
1618

1719
# =============================================================================
1820
# Command
@@ -27,7 +29,15 @@ def RunCommand():
2729
for obj in session.scene.find_all_by_itemtype(Block):
2830
session.scene.remove(obj)
2931

32+
for obj in session.scene.find_all_by_itemtype(FrictionContact):
33+
session.scene.remove(obj)
34+
35+
for obj in session.scene.find_all_by_itemtype(InteractionGraph):
36+
session.scene.remove(obj)
37+
3038
compas_rhino.layers.clear_layer("Masonry::DEA::Blocks")
39+
compas_rhino.layers.clear_layer("Masonry::DEA::Interactions")
40+
compas_rhino.layers.clear_layer("Masonry::DEA::Contacts")
3141

3242
model = None
3343

@@ -161,7 +171,7 @@ def RunCommand():
161171
# Scene
162172
# =============================================================================
163173

164-
for block in model.blocks():
174+
for block in model.elements():
165175
node = block.graphnode
166176
session.scene.add(
167177
block, # type: ignore

commands/DEA_contacts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import rhinoscriptsyntax as rs # type: ignore
88

9+
import compas_rhino.layers
910
from compas_dem.interactions import FrictionContact
1011
from compas_dem.models import BlockModel
1112
from compas_masonry.session import MasonrySession as Session
@@ -27,6 +28,9 @@ def RunCommand():
2728
for obj in session.scene.find_all_by_itemtype(InteractionGraph):
2829
session.scene.remove(obj)
2930

31+
compas_rhino.layers.clear_layer("Masonry::DEA::Interactions")
32+
compas_rhino.layers.clear_layer("Masonry::DEA::Contacts")
33+
3034
# this should be simplified in the future
3135
# by adding a method model.clear_interactions()
3236
for u, v in list(model.graph.edges()):
@@ -62,7 +66,7 @@ def RunCommand():
6266
session.scene.add(model.graph, layer="Masonry::DEA::Interactions") # type: ignore
6367

6468
for contact in model.contacts():
65-
session.scene.add(contact, layer="Masonry::DEA::Interactions") # type: ignore
69+
session.scene.add(contact, layer="Masonry::DEA::Contacts") # type: ignore
6670

6771
session.scene.redraw()
6872

commands/DEA_import.py

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,94 @@
22
# venv: brg-csd
33
# r: compas_masonry>=0.2.7
44

5-
# import pathlib
5+
import pathlib
66

7-
# from compas_masonry.session import MasonrySession as Session
8-
from compas_rui.feedback import warn
7+
import rhinoscriptsyntax as rs # type: ignore
8+
9+
import compas
10+
import compas_rhino.layers
11+
from compas_dem.elements import Block
12+
from compas_dem.interactions import FrictionContact
13+
from compas_dem.models import BlockModel
14+
from compas_masonry.session import MasonrySession as Session
15+
from compas_model.models import InteractionGraph
16+
from compas_rui import feedback
17+
from compas_rui.forms import FileForm
918

1019

1120
def RunCommand():
12-
# session = Session(basedir=pathlib.Path().home() / ".compas_session", name="COMPAS-Masonry")
21+
session = Session(basedir=pathlib.Path().home() / ".compas_session", name="COMPAS-Masonry")
22+
23+
path = rs.DocumentPath() # to make sure the document has a path
24+
if path:
25+
basedir = pathlib.Path(path).parent
26+
else:
27+
basedir = pathlib.Path().home()
28+
29+
filepath = FileForm.open(str(basedir))
30+
if not filepath:
31+
return
32+
33+
try:
34+
result = compas.json_load(filepath)
35+
except Exception as e:
36+
feedback.warn(f"Failed to load datafrom {filepath}: {e}")
37+
return
38+
39+
if not isinstance(result, BlockModel):
40+
feedback.warn(f"The data in the file is not a BlockModel: {type(result)}")
41+
return
42+
43+
# =============================================================================
44+
# Clear existing model
45+
# =============================================================================
46+
47+
session.delete("blockmodel")
48+
49+
for obj in session.scene.find_all_by_itemtype(Block):
50+
session.scene.remove(obj)
51+
52+
for obj in session.scene.find_all_by_itemtype(FrictionContact):
53+
session.scene.remove(obj)
54+
55+
for obj in session.scene.find_all_by_itemtype(InteractionGraph):
56+
session.scene.remove(obj)
57+
58+
compas_rhino.layers.clear_layer("Masonry::DEA::Blocks")
59+
compas_rhino.layers.clear_layer("Masonry::DEA::Interactions")
60+
compas_rhino.layers.clear_layer("Masonry::DEA::Contacts")
61+
62+
# =============================================================================
63+
# Add new model
64+
# =============================================================================
65+
66+
model: BlockModel = result
67+
session["blockmodel"] = model
68+
69+
# =============================================================================
70+
# Update scene
71+
# =============================================================================
72+
73+
# this should be simplifed by adding a helper method to the session
74+
75+
for block in model.elements():
76+
node = block.graphnode
77+
session.scene.add(
78+
block, # type: ignore
79+
name=f"Block_{node}", # type: ignore
80+
group=f"Masonry::DEA::Blocks::{node}", # type: ignore
81+
layer="Masonry::DEA::Blocks", # type: ignore
82+
)
83+
84+
if model.graph.number_of_edges() > 0:
85+
session.scene.add(model.graph, layer="Masonry::DEA::Interactions") # type: ignore
86+
87+
for contact in model.contacts():
88+
session.scene.add(contact, layer="Masonry::DEA::Contacts") # type: ignore
89+
90+
session.scene.redraw()
1391

14-
warn("Not available yet.")
92+
rs.Redraw()
1593

1694

1795
# =============================================================================
Lines changed: 29 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)