Skip to content

Commit

Permalink
refine addSurface promise api
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoes committed Sep 12, 2017
1 parent dd6e291 commit f476455
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions 3Dmol/glviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,7 @@ $3Dmol.GLViewer = (function() {
* @param {AtomSelectionSpec} allsel - Use atoms in this selection to calculate surface; may be larger group than 'atomsel'
* @param {AtomSelectionSpec} focus - Optionally begin rendering surface specified atoms
* @param {function} surfacecallback - function to be called after setting the surface
* @return {number} surfid - Identifying number for this surface, else promise if no surfacecallback is specified
* @return {Promise} promise - Returns a promise that ultimately resovles to the surfid. Returns surfid immediately if surfacecallback is specified. Returned promise has a surfid field for immediate access.
*/
this.addSurface = function(type, style, atomsel, allsel, focus, surfacecallback) {
// type 1: VDW 3: SAS 4: MS 2: SES
Expand Down Expand Up @@ -3418,7 +3418,7 @@ $3Dmol.GLViewer = (function() {
style = style || {};
var mat = getMatWithStyle(style);
var surfobj = [];

var promise = null;
if (symmetries) { //do preprocessing
var modelsAtomList = {};
var modelsAtomsToShow = {};
Expand All @@ -3432,6 +3432,7 @@ $3Dmol.GLViewer = (function() {
for (n = 0; n < atomsToShow.length; n++) {
modelsAtomsToShow[atomsToShow[n].model].push(atomsToShow[n]);
}
var promises = [];
for (n = 0; n < models.length; n++) {
if(modelsAtomsToShow[n].length > 0) {
surfobj.push({
Expand All @@ -3442,9 +3443,10 @@ $3Dmol.GLViewer = (function() {
symmetries : models[n].getSymmetries()
// also webgl initialized
});
var promise = addSurfaceHelper(surfobj[n], modelsAtomList[n], modelsAtomsToShow[n])
promises.append(addSurfaceHelper(surfobj[n], modelsAtomList[n], modelsAtomsToShow[n]))
}
}
promise = Promise.all(promises);
}
else {
surfobj.push({
Expand All @@ -3454,9 +3456,10 @@ $3Dmol.GLViewer = (function() {
finished : false,
symmetries : [new $3Dmol.Matrix4()]
});
var promise = addSurfaceHelper(surfobj[surfobj.length-1], atomlist, atomsToShow)
promise = addSurfaceHelper(surfobj[surfobj.length-1], atomlist, atomsToShow)
}
surfaces[surfid] = surfobj;
promise.surfid = surfid;
if(surfacecallback && typeof(surfacecallback) == "function") {
promise.then(function(surfid) {
surfacecallback(surfid);
Expand Down

0 comments on commit f476455

Please sign in to comment.