File size: 5,363 Bytes
71174bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | <template>
<PluginComponent
v-model="open"
:infoPayload="infoPayload"
cancelBtnTxt="Cancel"
actionBtnTxt="Move"
@onPopupDone="onPopupDone"
@onUserArgChanged="onUserArgChanged"
@onMolCountsChanged="onMolCountsChanged"
>
<ul>
<li v-for="title of selectedRegionsTitles" :key="title">
{{ title }}
</li>
</ul>
<Alert type="info">
You can also change a region's position and other properties (e.g.,
size) by selecting it in the Navigator panel and editing in the
Styles panel.
</Alert>
</PluginComponent>
</template>
<script lang="ts">
import { Options } from "vue-class-component";
import { IContributorCredit, ISoftwareCredit } from "../PluginInterfaces";
import PluginComponent from "../Parents/PluginComponent/PluginComponent.vue";
import { PluginParentClass } from "../Parents/PluginParentClass/PluginParentClass";
import { UserArg } from "@/UI/Forms/FormFull/FormFullInterfaces";
import { IRegion } from "@/UI/Navigation/TreeView/TreeInterfaces";
import Alert from "@/UI/Layout/Alert.vue";
import { TreeNode } from "@/TreeNodes/TreeNode/TreeNode";
import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList";
import { ITest } from "@/Testing/TestInterfaces";
import * as api from "@/Api";
import { Tag } from "./ActivityFocus/ActivityFocusUtils";
/** AboutPlugin */
@Options({
components: {
PluginComponent,
Alert,
},
})
export default class MoveRegionsOnClickPlugin extends PluginParentClass {
menuPath = null; // Not available through menu system
title = "Move regions?";
softwareCredits: ISoftwareCredit[] = [];
contributorCredits: IContributorCredit[] = [
// {
// name: "Jacob D. Durrant",
// url: "http://durrantlab.com/",
// },
];
pluginId = "moveregionsonclick";
intro = `Move all selected regions to this atom's position:`;
details = "This plugin allows for precise repositioning of docking boxes or other regions by clicking on an atom in the 3D viewer.";
tags = [Tag.All];
userArgDefaults: UserArg[] = [];
logJob = false;
logAnalytics = false;
newCenter: [number, number, number] = [0, 0, 0];
/**
* Checks if the plugin is allowed to run. Returns true if allowed, false if
* not allowed, or a string if not allowed and there's a user message.
*
* @returns {string | null} Null if allowed, or a message if not allowed.
*/
checkPluginAllowed(): string | null {
if (this.selectedRegionsTitles.length === 0) {
return "No regions selected.";
}
return null;
}
/**
* Called right before the plugin popup opens.
*
* @param {number[]} payload The payload from the event (new box center).
* @return {boolean | void} If false, the popup will not open (abort).
* Anything else, and the popup will open.
*/
async onBeforePopupOpen(payload: [number, number, number]) {
// Save new center.
this.newCenter = payload;
return;
}
/**
* Get the selected regions.
*
* @returns {TreeNodeList} The selected regions.
*/
get selectedRegions(): TreeNodeList {
// Get terminal nodes
let terminalNodes = (this.$store.state.molecules as TreeNodeList)
.filters.onlyTerminal;
// Get the ones that are selected and regions
terminalNodes = terminalNodes.filters.keepSelected();
terminalNodes = terminalNodes.filters.keepRegions();
return terminalNodes;
}
/**
* Get the titles of the selected regions.
*
* @returns {string[]} The titles of the selected regions.
*/
get selectedRegionsTitles(): string[] {
const selectedRegions = this.selectedRegions;
return selectedRegions.map((node) =>
node.descriptions.pathName(" > ", 0)
);
}
/**
* Runs when the popup closes via done button. Here, does nothing.
*/
onPopupDone() {
this.submitJobs(this.selectedRegions.toArray() as TreeNode[]);
}
/**
* Every plugin runs some job. This is the function that does the job
* running.
*
* @param {TreeNode} treeNode The molecule container associated with the
* region.
* @returns {Promise<void>} Resolves when the job is done.
*/
runJobInBrowser(treeNode: TreeNode): Promise<void> {
const newRegion = {
...treeNode.region,
center: this.newCenter,
} as IRegion;
treeNode.region = newRegion;
treeNode.viewerDirty = true;
return Promise.resolve();
}
/**
* Gets the test commands for the plugin. For advanced use.
*
* @gooddefault
* @document
* @returns {ITest[]} The selenium test commands.
*/
async getTests(): Promise<ITest[]> {
// Not going to test closing, etc. (Too much work.) But at least opens
// to see if an error occurs.
api.plugins.runPlugin(this.pluginId, [0, 0, 0]);
return [];
}
}
</script>
<style scoped lang="scss">
.inverse-indent {
text-indent: -1em;
padding-left: 1em;
}
</style>
|