Skip to content

Commit

Permalink
Merge branch '2-extensions-on-end-of-strand' of https://github.com/UC…
Browse files Browse the repository at this point in the history
…-Davis-molecular-computing/scadnano into 2-extensions-on-end-of-strand
  • Loading branch information
dave-doty committed Sep 8, 2022
2 parents 729b25c + acab47c commit da4dff2
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 62 deletions.
3 changes: 2 additions & 1 deletion lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import 'state/grid.dart';

// WARNING: Do not modify line below, except for the version string
// (and also add new version string to scadnano_versions_to_link).
const String CURRENT_VERSION = "0.17.4";
const String CURRENT_VERSION = "0.17.5";
const String INITIAL_VERSION = "0.1.0";

// scadnano versions that we deploy so that older versions can be used.
final scadnano_older_versions_to_link =[
// "0.17.3", // accidentally skipped this version
"0.17.4",
"0.17.2",
"0.17.1",
"0.17.0",
Expand Down
29 changes: 29 additions & 0 deletions lib/src/middleware/helix_idxs_change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ helix_idxs_change_middleware(Store<AppState> store, dynamic action, NextDispatch
Set<int> existing_idxs = store.state.design.helices.keys.toSet();
Set<int> old_idxs = action.idx_replacements.keys.toSet();
Set<int> remaining_idxs = existing_idxs.difference(old_idxs);
var new_indices = action.idx_replacements.values.toSet();

if (new_indices.length != action.idx_replacements.length) {
Map<int, List<int>> key_to_idxs = new Map<int, List<int>>();

for (var old_index in old_idxs) {
var new_index = action.idx_replacements[old_index];
if (key_to_idxs.containsKey(new_index))
key_to_idxs[new_index].add(old_index);
else
key_to_idxs[new_index] = [ old_index ];
}

if (key_to_idxs.length != action.idx_replacements.length) {
var msg = 'You tried to assign existing helices ';

msg += key_to_idxs.entries.where((element) => element.value.length != 1).map((element) {
return element.value.join(', ') + " to " + element.key.toString();
}).join(" and helices ");

msg += ". Each helix must have a unique new index; make sure all the integers you write are distinct from each other and do not appear elsewhere in the design";

window.alert(msg);
return;
}


}

for (int new_idx in action.idx_replacements.values) {
if (remaining_idxs.contains(new_idx)) {
var msg = 'Index ${new_idx} is already taken.';
Expand Down
7 changes: 4 additions & 3 deletions lib/src/reducers/helices_reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ Design helix_idx_change_reducer(Design design, AppState state, actions.HelixIdxs
var strands = design.strands.toList();

Map<String, HelixGroup> new_groups = change_groups(action, helices, design);

var copy_helices = design.helices.toMap();
// change helices

helices.removeWhere((key, _) => action.idx_replacements.containsKey(key));
for (int old_idx in action.idx_replacements.keys) {
int new_idx = action.idx_replacements[old_idx];
var helix = helices[old_idx].rebuild((b) => b..idx = new_idx);
helices.remove(old_idx);
var helix = copy_helices[old_idx].rebuild((b) => b..idx = new_idx);
helices[new_idx] = helix;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ part 'serializers.g.dart';
DialogShow,
DialogHide,
DialogLink,
DialogLabel,
StrandOrder,
StrandColorSet,
StrandColorPickerShow,
Expand Down
29 changes: 29 additions & 0 deletions lib/src/state/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ abstract class DialogLink
..tooltip = tooltip);
}



/************************ end BuiltValue boilerplate ************************/

String get label;
Expand All @@ -314,6 +316,33 @@ abstract class DialogLink
String get value;
}

abstract class DialogLabel
with BuiltJsonSerializable
implements DialogItem, Built<DialogLabel, DialogLabelBuilder> {
DialogLabel._();

factory DialogLabel.from([void Function(DialogLabelBuilder) updates]) = _$DialogLabel;

static Serializer<DialogLabel> get serializer => _$dialogLabelSerializer;

@memoized
int get hashCode;

factory DialogLabel({String label, String tooltip}) {
return DialogLabel.from((b) => b
..label = label
..value = ""
..tooltip = tooltip);
}


/************************ end BuiltValue boilerplate ************************/

String get label;

String get value;
}

// abstract class DialogLink
// with BuiltJsonSerializable
// implements DialogItem, Built<DialogLink, DialogLinkBuilder> {
Expand Down
7 changes: 7 additions & 0 deletions lib/src/view/design_dialog_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ class DesignDialogFormComponent extends UiStatefulComponent2<DesignDialogFormPro
..href = item.link
..target = '_blank')(item.label);
}
else if (item is DialogLabel) {
return (Dom.span()
..title = item.tooltip
)(item.label);
}


return null;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/view/design_main_error_boundary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@ class DesignMainErrorBoundaryComponent<T extends DesignMainErrorBoundaryProps,

send_error(String escaped_error_message) async{
app.dispatch(actions.ErrorMessageSet(escaped_error_message));
app.dispatch(actions.LoadingDialogHide()); // close loading dialog if it's currently being shown
app.view.design_view.render(app.state);
}
35 changes: 35 additions & 0 deletions lib/src/view/menu_side.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class SideMenuComponent extends UiComponent2<SideMenuProps> with RedrawCounterMi
..disabled = props.groups.length == 1
..on_click = ((ev) => app.dispatch(actions.GroupRemove(name: props.displayed_group_name)))
..key = 'remove-current-group')(),
(MenuDropdownItem()
..display = 'adjust helix indices'
..disabled = props.groups[props.displayed_group_name].helices_view_order.length == 0
..on_click = ((ev) => adjust_helix_indices_for_current_group())
..key = 'adjust-helix-indices')(),
]);
return NavDropdown({
'title': 'Group',
Expand Down Expand Up @@ -125,6 +130,9 @@ class SideMenuComponent extends UiComponent2<SideMenuProps> with RedrawCounterMi
set_new_parameters_for_current_group() =>
app.disable_keyboard_shortcuts_while(ask_new_parameters_for_current_group);

adjust_helix_indices_for_current_group() =>
app.disable_keyboard_shortcuts_while(ask_new_helix_indices_for_current_group);

add_new_group(Iterable<String> existing_names) =>
app.disable_keyboard_shortcuts_while(() => ask_about_new_group(existing_names));

Expand Down Expand Up @@ -262,4 +270,31 @@ class SideMenuComponent extends UiComponent2<SideMenuProps> with RedrawCounterMi
app.dispatch(
actions.GroupChange(old_name: props.displayed_group_name, new_name: new_name, new_group: new_group));
}

Future<void> ask_new_helix_indices_for_current_group() async {
var group = props.groups[props.displayed_group_name];
var existing_grid = group.grid;

List<DialogItem> items = [];
items.add(DialogLabel(label: 'current view order: ' + group.helices_view_order.join(' ')));

for (var helix_index in group.helices_view_order) {
items.add(DialogInteger(label: helix_index.toString(), value: helix_index));
}

var dialog =
Dialog(title: 'adjust Helix indices', items: items);
List<DialogItem> results = await util.dialog(dialog);
if (results == null) return;

Map<int, int> new_indices_map = {};
for (int i = 1; i < results.length; i++) {
new_indices_map[group.helices_view_order[i-1]] = (results[i] as DialogInteger).value;
}

app.dispatch(actions.HelixIdxsChange(idx_replacements: new_indices_map));
}

}


Loading

0 comments on commit da4dff2

Please sign in to comment.