0% found this document useful (0 votes)
1 views1 page

GRASP Python (20)

The document describes a process for selecting nodes in a graphical interface for element creation. It outlines the steps for selecting the first and second nodes based on user clicks, including distance calculations to determine the closest node. If no nodes are selected within a specified threshold, appropriate messages are printed to the user.

Uploaded by

Le Fondateur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

GRASP Python (20)

The document describes a process for selecting nodes in a graphical interface for element creation. It outlines the steps for selecting the first and second nodes based on user clicks, including distance calculations to determine the closest node. If no nodes are selected within a specified threshold, appropriate messages are printed to the user.

Uploaded by

Le Fondateur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

return

print("Select first node (click on it)")


self.fig.canvas.mpl_connect('button_press_event',
self.on_click_select_first_node)

def on_click_select_first_node(self, event):


"""Handle first node selection for element creation"""
if event.inaxes != self.ax:
return

# Find closest node


min_dist = float('inf')
selected_node = None
for node_id, node in self.nodes.items():
dist = np.sqrt((event.xdata - node['x'])**2 + (event.ydata -
node['y'])**2)
if dist < min_dist:
min_dist = dist
selected_node = node_id

if min_dist > 0.5: # Threshold for selection


print("No node selected nearby")

self.fig.canvas.mpl_disconnect(self.fig.canvas.button_press_event)
return

print(f"Selected Node {selected_node}, now select second node")


self.selected_node1 = selected_node
self.fig.canvas.mpl_disconnect(self.fig.canvas.button_press_event)
self.fig.canvas.mpl_connect('button_press_event',
self.on_click_select_second_node)

def on_click_select_second_node(self, event):


"""Handle second node selection for element creation"""
if event.inaxes != self.ax:
return

# Find closest node


min_dist = float('inf')
selected_node = None
for node_id, node in self.nodes.items():
if node_id == self.selected_node1:
continue
dist = np.sqrt((event.xdata - node['x'])**2 + (event.ydata -
node['y'])**2)
if dist < min_dist:
min_dist = dist
selected_node = node_id

if min_dist > 0.5 or selected_node is None: # Threshold for


selection
print("No valid second node selected nearby")

self.fig.canvas.mpl_disconnect(self.fig.canvas.button_press_event)
return

P a g e 6 | 62

You might also like