Skip to content

feat: update with delta #1922

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

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b827101
ci: simplify blitz ci
RobPasMue Mar 10, 2025
7039876
fix: translating sketch issues when using a custom default unit (#1808)
RobPasMue Mar 10, 2025
f26f02c
feat: matrix helper methods (#1806)
umutsoysalansys Mar 11, 2025
472f787
new method
umutsoysalansys Mar 11, 2025
6e26772
surface body
umutsoysalansys Mar 13, 2025
ed2c9a5
update with latest tracker for bodies
umutsoysalansys Mar 19, 2025
e224a2f
Merge branch 'main' into feat/update-with-delta
umutsoysalansys Apr 2, 2025
3c376bb
update in tracker
umutsoysalansys Apr 7, 2025
99f00f3
tracker updated
umutsoysalansys Apr 7, 2025
32be1b1
duplicate and inexact faces
umutsoysalansys Apr 8, 2025
3a5d83d
Merge branch 'main' into feat/update-with-delta
umutsoysalansys Apr 17, 2025
b70665c
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 18, 2025
cc05617
chore: adding changelog file 1922.added.md [dependabot-skip]
pyansys-ci-bot Apr 18, 2025
e2a9046
replacing update design inplace
umutsoysalansys Apr 18, 2025
8b94ad8
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 18, 2025
b52d54f
Update problem_areas.py
umutsoysalansys Apr 18, 2025
cc59f6a
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 18, 2025
39f4d38
Merge branch 'main' into feat/update-with-delta
umutsoysalansys Apr 21, 2025
be524f6
fixing function arguments ordre
umutsoysalansys Apr 21, 2025
75f2be0
Update repair_tools.py
umutsoysalansys Apr 21, 2025
4495fdf
fixing function arguments order more
umutsoysalansys Apr 21, 2025
63e7e8c
Merge branch 'main' into feat/update-with-delta
umutsoysalansys Apr 21, 2025
32a042c
remove result
umutsoysalansys Apr 21, 2025
26fa520
Merge branch 'feat/update-with-delta' of https://github.com/ansys/pya…
umutsoysalansys Apr 21, 2025
065921a
test update
umutsoysalansys Apr 21, 2025
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
1 change: 1 addition & 0 deletions doc/changelog.d/1806.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
matrix helper methods
1 change: 1 addition & 0 deletions doc/changelog.d/1808.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
translating sketch issues when using a custom default unit
1 change: 1 addition & 0 deletions doc/changelog.d/1922.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update with delta
134 changes: 134 additions & 0 deletions src/ansys/geometry/core/designer/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,3 +1271,137 @@ def _update_design_inplace(self) -> None:

# Read the existing design
self.__read_existing_design()

def update_from_tracker(self, tracker_response):
"""
Update the design with the changed bodies while preserving unchanged ones.

Parameters
----------
changed_bodies : list[dict]
A list of dictionaries representing changed body information. Each dictionary
should contain 'id', 'name', and 'is_surface' keys.
"""
print("Updating design using the tracker...")

# Function to update a body if it exists
def update_body(existing_body, body_info):
existing_body.name = body_info.name
existing_body._template._is_surface = body_info.is_surface
print(f"Updated body: {body_info.name} (ID: {body_info.id})")

# Function to find and add bodies within components recursively
def find_and_add_body(body_info, component):
for component in components:
if component.id == body_info["parent_id"]:
new_body = MasterBody(
body_info["id"],
body_info["name"],
self._grpc_client,
is_surface=body_info["is_surface"],
)
component.bodies.append(new_body)
print(f"Added new body: {body_info['name']} (ID: {body_info['id']})")
return True # Found and added

# Recursively search in subcomponents
if find_and_add_body(body_info, component.components):
return True

return False # Not found

# Function to find and update bodies within components recursively
def find_and_update_body(body_info, component):
if component == []:
return False
for body in component.bodies:
if body.id == body_info.id:
update_body(body, body_info)
return True # Found and updated

# Recursively search in subcomponents
if find_and_update_body(body_info, component.components):
return True

return False # Not found

# Function to find and remove bodies within components recursively

def find_and_remove_body(body_info, component):
if component == []:
return False
for body in component.bodies:
if body.id == body_info.id:
component.bodies.remove(body)
print(f"Removed body: {body_info.id}")
return True # Found and removed

# Recursively search in subcomponents
if find_and_remove_body(body_info, component.components):
return True

return False # Not found

# Loop through all changed bodies from the tracker
for body_info in tracker_response.modified_bodies:
body_id = body_info.id
body_name = body_info.name
is_surface = body_info.is_surface

updated = False # Track if a body was updated

# First, check bodies at the root level
for body in self.bodies:
if body.id == body_id:
update_body(body, body_info)
updated = True
break

# If not found in root, search within components
if not updated:
for component in self.components:
updated = find_and_update_body(body_info, component)

# Loop through all deleted bodies from the tracker
for body_info in tracker_response.deleted_bodies:
body_id = body_info.id

removed = False # Track if a body was removed

# First, check bodies at the root level
for body in self.bodies:
if body.id == body_id:
self.bodies.remove(body)
print(f"Removed body: {body_id}")
removed = True
break

# If not found in root, search within components
if not removed:
removed = find_and_remove_body(body_info, self.components)

# Loop through all added bodies from the tracker
for body_info in tracker_response.created_bodies:
body_id = body_info["id"]
body_name = body_info["name"]
is_surface = body_info["is_surface"]

added = False # Track if a body was added

# First, check if the body already exists at the root level
for body in self.bodies:
if body.id == body_id:
added = True
break

# If not found in root, search within components
if not added:
added = find_and_add_body(body_info, self.components)

# If still not found, add it as a new body at the root level
if not added:
new_body = MasterBody(body_id, body_name, self._grpc_client, is_surface=is_surface)
self.bodies.append(new_body)
print(f"Added new body: {body_name} (ID: {body_id})")

print("Design update completed.")
10 changes: 5 additions & 5 deletions src/ansys/geometry/core/tools/prepare_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ def enhanced_share_topology(
)

message = RepairToolMessage(
response.get("success"),
response.get("created_bodies_monikers"),
response.get("modified_bodies_monikers"),
response.get("found"),
response.get("repaired"),
success=response.get("success"),
created_bodies=response.get("created_bodies_monikers"),
modified_bodies=response.get("modified_bodies_monikers"),
found=response.get("found"),
repaired=response.get("repaired"),
)
return message

Expand Down
79 changes: 45 additions & 34 deletions src/ansys/geometry/core/tools/problem_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ def fix(self) -> RepairToolMessage:
response = self._repair_stub.FixDuplicateFaces(
FixDuplicateFacesRequest(duplicate_face_problem_area_id=self._grpc_id)
)
parent_design._update_design_inplace()
# parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)

parent_design.update_from_tracker(response.result.complete_command_response)

return message


Expand Down Expand Up @@ -188,10 +190,11 @@ def fix(self) -> RepairToolMessage:
)
parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)
# parent_design.update_from_tracker(response.result.complete_command_response)
return message


Expand Down Expand Up @@ -242,9 +245,9 @@ def fix(self) -> RepairToolMessage:
)
parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)
return message

Expand Down Expand Up @@ -293,12 +296,12 @@ def fix(self) -> RepairToolMessage:
parent_design = get_design_from_edge(self.edges[0])
request = FixExtraEdgesRequest(extra_edge_problem_area_id=self._grpc_id)
response = self._repair_stub.FixExtraEdges(request)
parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)
parent_design.update_from_tracker(response.result.complete_command_response)

return message

Expand Down Expand Up @@ -348,12 +351,13 @@ def fix(self) -> RepairToolMessage:
response = self._repair_stub.FixShortEdges(
FixShortEdgesRequest(short_edge_problem_area_id=self._grpc_id)
)
parent_design._update_design_inplace()
# parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)
parent_design.update_from_tracker(response.result.complete_command_response)

return message

Expand Down Expand Up @@ -403,12 +407,15 @@ def fix(self) -> RepairToolMessage:
response = self._repair_stub.FixSmallFaces(
FixSmallFacesRequest(small_face_problem_area_id=self._grpc_id)
)
parent_design._update_design_inplace()
# parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)

parent_design.update_from_tracker(response.result.complete_command_response)

return message


Expand Down Expand Up @@ -457,12 +464,14 @@ def fix(self) -> RepairToolMessage:
response = self._repair_stub.FixSplitEdges(
FixSplitEdgesRequest(split_edge_problem_area_id=self._grpc_id)
)
parent_design._update_design_inplace()
# parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)
parent_design.update_from_tracker(response.result.complete_command_response)

return message


Expand Down Expand Up @@ -511,12 +520,13 @@ def fix(self) -> RepairToolMessage:
response = self._repair_stub.FixStitchFaces(
FixStitchFacesRequest(stitch_face_problem_area_id=self._grpc_id)
)
parent_design._update_design_inplace()
# parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)
parent_design.update_from_tracker(response.result.complete_command_response)
return message


Expand Down Expand Up @@ -560,12 +570,13 @@ def fix(self) -> RepairToolMessage:
response = self._repair_stub.FixAdjustSimplify(
FixAdjustSimplifyRequest(adjust_simplify_problem_area_id=self._grpc_id)
)
parent_design._update_design_inplace()
# parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
success=response.result.success,
created_bodies=response.result.created_bodies_monikers,
modified_bodies=response.result.modified_bodies_monikers,
)
parent_design.update_from_tracker(response.result.complete_command_response)
return message


Expand Down
4 changes: 4 additions & 0 deletions src/ansys/geometry/core/tools/repair_tool_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def __init__(
success: bool,
created_bodies: list[str],
modified_bodies: list[str],
deleted_bodies: list[str] = None,
craeted_components: list[str] = None,
modified_components: list[str] = None,
deleted_components: list[str] = None,
found: int = -1,
repaired: int = -1,
):
Expand Down
Loading
Loading