Skip to content

Commit f43e666

Browse files
committed
git colourisation fixes
Fix bug where uncommitted changes were not fully colourised in the same way as diffs. Also try and catch more changes, eg. highlight if a Products Type has changed.
1 parent 26b21dd commit f43e666

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

src/bonsai/bonsai/core/ifcgit.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,19 @@ def colourise_revision(ifcgit: tool.IfcGit) -> None:
9999
step_ids = ifcgit.get_revisions_step_ids()
100100
if not step_ids:
101101
return
102-
modified_shape_object_step_ids = ifcgit.get_modified_shape_object_step_ids(step_ids)
103-
final_step_ids = ifcgit.update_step_ids(step_ids, modified_shape_object_step_ids)
102+
modified_step_ids = ifcgit.get_modified_step_ids(step_ids)
103+
final_step_ids = ifcgit.update_step_ids(step_ids, modified_step_ids)
104104
ifcgit.colourise(final_step_ids)
105105

106106

107107
def colourise_uncommitted(ifcgit: tool.IfcGit, ifc: tool.Ifc, repo: git.Repo) -> None:
108108
path_ifc = ifc.get_path()
109109
step_ids = ifcgit.ifc_diff_ids(repo, None, "HEAD", path_ifc)
110-
ifcgit.colourise(step_ids)
110+
if not step_ids:
111+
return
112+
modified_step_ids = ifcgit.get_modified_step_ids(step_ids)
113+
final_step_ids = ifcgit.update_step_ids(step_ids, modified_step_ids)
114+
ifcgit.colourise(final_step_ids)
111115

112116

113117
def switch_revision(ifcgit: tool.IfcGit, ifc: tool.Ifc) -> None:

src/bonsai/bonsai/tool/ifcgit.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,24 +370,36 @@ def get_revisions_step_ids(cls) -> Union[STEP_IDS, None]:
370370
return step_ids
371371

372372
@classmethod
373-
def get_modified_shape_object_step_ids(cls, step_ids: STEP_IDS) -> STEP_IDS:
373+
def get_modified_step_ids(cls, step_ids: STEP_IDS) -> STEP_IDS:
374374
model = tool.Ifc.get()
375-
modified_shape_object_step_ids = {"modified": []}
375+
modified_step_ids = {"modified": set()}
376376

377-
for step_id in step_ids["modified"]:
378-
if model.by_id(step_id).is_a() == "IfcProductDefinitionShape":
379-
product = model.by_id(step_id).ShapeOfProduct[0]
380-
modified_shape_object_step_ids["modified"].append(product.id())
377+
for step_id in step_ids["modified"] | step_ids["added"]:
378+
try:
379+
entity = model.by_id(step_id)
380+
except:
381+
continue
382+
if entity.is_a("IfcProductDefinitionShape"):
383+
for product in entity.ShapeOfProduct:
384+
modified_step_ids["modified"].add(product.id())
385+
elif entity.is_a("IfcObjectPlacement"):
386+
for product in entity.PlacesObject:
387+
modified_step_ids["modified"].add(product.id())
388+
elif entity.is_a("IfcTypeProduct") and entity.Types:
389+
for related_object in entity.Types[0].RelatedObjects:
390+
modified_step_ids["modified"].add(related_object.id())
381391

382-
return modified_shape_object_step_ids
392+
return modified_step_ids
383393

384394
@classmethod
385-
def update_step_ids(cls, step_ids: STEP_IDS, modified_shape_object_step_ids: STEP_IDS) -> STEP_IDS:
395+
def update_step_ids(cls, step_ids: STEP_IDS, modified_step_ids: STEP_IDS) -> STEP_IDS:
386396

387397
final_step_ids = {}
388398
final_step_ids["added"] = step_ids["added"]
389399
final_step_ids["removed"] = step_ids["removed"]
390-
final_step_ids["modified"] = step_ids["modified"].union(modified_shape_object_step_ids["modified"])
400+
final_step_ids["modified"] = (
401+
step_ids["modified"].union(modified_step_ids["modified"]).difference(step_ids["added"])
402+
)
391403
return final_step_ids
392404

393405
@classmethod

0 commit comments

Comments
 (0)