Skip to content

Commit

Permalink
Insert multiple picks for structureless too
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Jan 10, 2025
1 parent b221dfa commit bd370bb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 54 deletions.
60 changes: 50 additions & 10 deletions hexrdgui/tree_views/generic_picks_tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,8 @@ def insert_item():
else:
raise NotImplementedError

new_item = TreeItem([position, 0., 0.])
model.insert_items([new_item], parent_item, position)

# Select the new item
index = model.createIndex(new_item.row(), 0, new_item)
self.setCurrentIndex(index)

if is_hand_pickable:
# Go ahead and get the user to hand pick the point...
self.hand_pick_point(new_item, line_name)
pick_label = f'Inserting points into: {line_name}'
return self._insert_picks(parent_item, position, pick_label)

def hand_pick_item():
self.hand_pick_point(item, line_name)
Expand Down Expand Up @@ -475,6 +467,54 @@ def hand_pick_item():
# Run the function for the action that was chosen
actions[action_chosen]()

def _insert_picks(self, parent_item, position, pick_label):
model = self.model()

if not self.is_hand_pickable:
new_item = TreeItem([position, 0., 0.])
model.insert_items([new_item], parent_item, position)

# Select the new item
index = model.createIndex(new_item.row(), 0, new_item)
self.setCurrentIndex(index)
return

kwargs = {
'canvas': self.canvas,
'parent': self,
}

picker = LinePickerDialog(**kwargs)
picker.current_pick_label = pick_label
picker.ui.setWindowTitle(pick_label)
picker.ui.view_picks.setVisible(False)
picker.start()

def on_line_completed():
# Just accept it
picker.ui.accept()

def on_accepted():
nonlocal position
original_position = position
new_line = picker.line_data[0]
new_items = []
for x, y in new_line.tolist():
new_items.append(TreeItem([position, x, y]))
position += 1

model.insert_items(new_items, parent_item, original_position)

# Select the last new item
last_item = new_items[-1]
index = model.createIndex(last_item.row(), 0, last_item)
self.setCurrentIndex(index)

picker.accepted.connect(on_accepted)
picker.line_completed.connect(on_line_completed)

self._current_picker = picker

@property
def has_canvas(self):
return self.canvas is not None
Expand Down
45 changes: 1 addition & 44 deletions hexrdgui/tree_views/hkl_picks_tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,51 +121,8 @@ def insert_item():
else:
raise NotImplementedError

if not is_hand_pickable:
new_item = TreeItem([position, 0., 0.])
model.insert_items([new_item], parent_item, position)

# Select the new item
index = model.createIndex(new_item.row(), 0, new_item)
self.setCurrentIndex(index)
return

pick_label = f'Inserting points into: {hkl_str}'
kwargs = {
'canvas': self.canvas,
'parent': self,
}

picker = LinePickerDialog(**kwargs)
picker.current_pick_label = pick_label
picker.ui.setWindowTitle(pick_label)
picker.ui.view_picks.setVisible(False)
picker.start()

def on_line_completed():
# Just accept it
picker.ui.accept()

def on_accepted():
nonlocal position
original_position = position
new_line = picker.line_data[0]
new_items = []
for x, y in new_line.tolist():
new_items.append(TreeItem([position, x, y]))
position += 1

model.insert_items(new_items, parent_item, original_position)

# Select the last new item
last_item = new_items[-1]
index = model.createIndex(last_item.row(), 0, last_item)
self.setCurrentIndex(index)

picker.accepted.connect(on_accepted)
picker.line_completed.connect(on_line_completed)

self._current_picker = picker
return self._insert_picks(parent_item, position, pick_label)

def hand_pick_item():
self.hand_pick_point(item, hkl_str)
Expand Down

0 comments on commit bd370bb

Please sign in to comment.