Skip to content

Commit

Permalink
Message function is now part of the basemodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-wu committed May 15, 2019
1 parent f30d1d2 commit e7a4f6b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 48 deletions.
9 changes: 9 additions & 0 deletions src/modules/BaseModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var BaseModule = function() {
this.typeName = "Base Module";
this.instanceName = "default";
this.onChangedCallbacks = [];
this.messageFunction = undefined;
/** Notifier handle for informing other modules of any changes **/
this.eventNotifiers = [];
}
Expand All @@ -25,6 +26,14 @@ BaseModule.prototype.publishChanges = function(annotations, eventType) {
}
}

BaseModule.prototype.setMessageFunction = function(functionIn) {
this.messageFunction = functionIn;
}

BaseModule.prototype.displayMessage = function(message) {
if (this.messageFunction)
this.messageFunction(message);
}

BaseModule.prototype.getName = function() {
return this.instanceName;
Expand Down
39 changes: 17 additions & 22 deletions src/modules/ScaffoldViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var ScaffoldViewer = function(typeAtStartUp) {
var meshUpdatedCallbacks = new Array();
var meshAllPartsDownloadedCallbacks = new Array();
var availableMeshTypes = undefined;
this.alertFunction = undefined;
this.promptFunction = undefined;
this.confirmFunction = undefined;
var currentMeshType = "3d_heart1";
Expand Down Expand Up @@ -101,7 +100,7 @@ var ScaffoldViewer = function(typeAtStartUp) {
registerLandmarks(coords, datapoint.name, true);
}
} else {
_this.alertFunction(returnedObject['error']);
_this.displayMessage(returnedObject['error']);
}

}
Expand Down Expand Up @@ -207,7 +206,7 @@ var ScaffoldViewer = function(typeAtStartUp) {
//Data include meshtype, options and landmark
var importData = function(data) {
if (data && data.meshtype && data.options) {
_this.alertFunction("Importing data");
_this.displayMessage("Importing data");
currentMeshType = data.meshtype;
currentOptions = data.options;
currentLandmarks = data.landmarks;
Expand Down Expand Up @@ -254,8 +253,8 @@ var ScaffoldViewer = function(typeAtStartUp) {
verifierEntered(verifier);
}
} else {
if (_this.alertFunction)
_this.alertFunction("Loading abort");
if (_this.displayMessage)
_this.displayMessage("Loading abort");
}
}
}
Expand All @@ -268,8 +267,7 @@ var ScaffoldViewer = function(typeAtStartUp) {
if (_this.promptFunction)
_this.promptFunction("Enter your verifier here", "...", verifierEnteredCallback());
} else {
if (_this.alertFunction)
_this.alertFunction("Loading abort");
_this.displayMessage("Loading abort");
}
}
}
Expand All @@ -281,7 +279,7 @@ var ScaffoldViewer = function(typeAtStartUp) {

var parseWorkspaceResponse = function(options) {
if (options.status === 'error')
_this.alertFunction(options.message);
_this.displayMessage(options.message);
else if (options.status === 'success') {
if (options.VerifyURL)
verificationCodePrompt(options.VerifyURL);
Expand All @@ -299,7 +297,7 @@ var ScaffoldViewer = function(typeAtStartUp) {
var options = JSON.parse(xmlhttp.responseText);
parseWorkspaceResponse(options);
} else {
_this.alertFunction("Error reading workspace");
_this.displayMessage("Error reading workspace");
}
}
}
Expand Down Expand Up @@ -354,8 +352,8 @@ var ScaffoldViewer = function(typeAtStartUp) {
var response = JSON.parse(xmlhttp.responseText);
if (response.status == "success")
changesCommitted = true;
if (response.message && _this.alertFunction)
_this.alertFunction(response.message);
if (response.message)
_this.displayMessage(response.message);
}
}
var requestString = "./commitWorkspaceChanges" + "?msg=" + msg;
Expand All @@ -373,8 +371,7 @@ var ScaffoldViewer = function(typeAtStartUp) {
_this.promptFunction("Please enter commit message", msg, commitWorkspaceCallback());
}
else {
if (_this.alertFunction)
_this.alertFunction("Everything is up-to-date");
_this.displayMessage("Everything is up-to-date");
}
}

Expand All @@ -385,8 +382,8 @@ var ScaffoldViewer = function(typeAtStartUp) {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var response = JSON.parse(xmlhttp.responseText);
if (response.message && _this.alertFunction)
_this.alertFunction(response.message);
if (response.message)
_this.displayMessage(response.message);
}
}
var requestString = "./pushWorkspace";
Expand Down Expand Up @@ -461,14 +458,12 @@ var ScaffoldViewer = function(typeAtStartUp) {
console.log(response);
if (response.data) {
importData(response.data);
if (_this.alertFunction)
_this.alertFunction(response.message);
_this.displayMessage(response.message);
}
else if (response.message) {
settingsChanged = true;
_this.updateMesh();
if (_this.alertFunction)
_this.alertFunction(response.message);
_this.displayMessage(response.message);
}
}
}
Expand Down Expand Up @@ -570,10 +565,10 @@ var ScaffoldViewer = function(typeAtStartUp) {
csg.addDatGui(parent);
}

this.setAlertFunction = function(alertFunction) {
this.alertFunction = alertFunction;
this.setMessageFunction = function(functionIn) {
(require('./BaseModule').BaseModule).prototype.setMessageFunction.call( _this, functionIn );
if (csg)
csg.setAlertFunction(alertFunction);
csg.setMessageFunction(functionIn);
}

/**
Expand Down
21 changes: 6 additions & 15 deletions src/modules/bodyRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ var BodyViewer = function(ModelsLoaderIn) {
"Endocrine", "Female Reproductive", "Male Reproductive", "Special sense organs"];
var systemMeta = undefined;
var _this = this;
var alertFunction = undefined;
_this.typeName = "Body Viewer";

this.setAlertFunction = function(alertFunctionIn) {
alertFunction = alertFunctionIn;
}

/**
* This callback is triggered when a body part is clicked.
* @callback
Expand All @@ -48,8 +43,7 @@ var BodyViewer = function(ModelsLoaderIn) {
if (intersects[i] !== undefined && (intersects[ i ].object.name !== undefined)) {
if (!intersects[ i ].object.name.includes("Body")) {
_this.setSelectedByObjects([intersects[ i ].object], true);
if (alertFunction)
alertFunction(intersects[ i ].object.name + " selected.");
_this.displayMessage(intersects[ i ].object.name + " selected.");
return;
} else {
bodyClicked = true;
Expand Down Expand Up @@ -143,12 +137,10 @@ var BodyViewer = function(ModelsLoaderIn) {
geometry.setAlpha(0.5);
geometry.morph.material.side = THREE.FrontSide;
}
if (alertFunction) {
if (partName)
alertFunction(partName + " loaded.");
else
alertFunction("Resource loaded.");
}
if (partName)
_this.displayMessage(partName + " loaded.");
else
_this.displayMessage("Resource loaded.");
var annotation = new (require('../utilities/annotation').annotation)();
annotation.data = {species:currentSpecies, system:systemName, part:partName};
geometry.userData = [annotation];
Expand Down Expand Up @@ -218,8 +210,7 @@ var BodyViewer = function(ModelsLoaderIn) {
var downloadPath = item["BodyURL"];
var scaling = false;
item["loaded"] = ITEM_LOADED.DOWNLOADING;
if (alertFunction)
alertFunction("Downloading data.");
_this.displayMessage("Downloading data.");
if (item["FileFormat"] == "JSON") {
if (systemName == "Musculo-skeletal" || systemName == "Skin (integument)")
scaling = true;
Expand Down
5 changes: 5 additions & 0 deletions src/modules/organsRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ var OrgansViewer = function(ModelsLoaderIn) {
_this.scene.resetView();
}
var annotation = new (require('../utilities/annotation').annotation)();
if (partName)
_this.displayMessage(partName + " loaded.");
else
_this.displayMessage("Resource loaded.");
annotation.data = {species:sceneData.currentSpecies, system:systemName, part:partName};
geometry.userData = [annotation];
}
Expand Down Expand Up @@ -788,6 +792,7 @@ var OrgansViewer = function(ModelsLoaderIn) {
// Exist: Set it as current scene and update the gui.
// Not: Create a new scene
if (organScene == undefined) {
_this.displayMessage("Loading " + name);
_this.changeCompareSpecies("none");
organScene = _this.zincRenderer.createScene(name);
for (var i = 0; i < sceneChangedCallbacks.length;i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/BodyViewerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ var BodyViewerDialog = function(bodyViewerIn, parentIn) {
_myInstance.module.initialiseRenderer(displayArea);
_myInstance.module.addChangedCallback(bodyViewerChangedCallback());
var snackbar = _myInstance.getSnackbar();
_myInstance.module.setAlertFunction(snackbar.showMessage);
_myInstance.module.setMessageFunction(snackbar.showMessage);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/ui/OrgansViewerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ var OrgansViewerDialog = function(organsViewerIn, parentIn) {
_myInstance.module.addOrganPartAddedCallback(organPartAddedCallback());
_myInstance.module.addChangedCallback(organsViewerChangedCallback());
_myInstance.module.addLayoutUpdateRequiredCallback(layoutUpdateRequiredCallback());
var snackbar = _myInstance.getSnackbar();
_myInstance.module.setMessageFunction(snackbar.showMessage);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/ScaffoldDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ var ScaffoldDialog = function(scaffoldViewerIn, parentIn) {
var displayArea = _myInstance.container.find("#scaffoldDisplayArea")[0];
_myInstance.module.initialiseRenderer(displayArea);
initialiseScaffoldControlUI();
_myInstance.module.setAlertFunction(snackbar.showMessage);
_myInstance.module.setMessageFunction(snackbar.showMessage);
_myInstance.module.promptFunction = modal.prompt;
_myInstance.module.confirmFunction = modal.confirm;
var meshTypes = _myInstance.module.getAvailableMeshTypes();
Expand Down
19 changes: 10 additions & 9 deletions src/utilities/csg.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports.csg = function(sceneIn, zincRendererIn) {
var reverseController = undefined;
var plane = undefined;
var planeHelper = undefined;
var alertFunction = undefined;
var messageFunction = undefined;
var guiControls = new function() {
this.distance = 1.0;
this.continuous = false;
Expand Down Expand Up @@ -191,8 +191,7 @@ exports.csg = function(sceneIn, zincRendererIn) {
if (mergedGlyphGeometry === undefined && currentGlyphs) {
mergedGlyphGeometry = csgScene.addZincGeometry(currentGlyphs, 45121, 0xffffff, 1.0);
}
if (alertFunction)
alertFunction("Cutting the surfaces. This may take a few seconds.");
displayMessage("Cutting the surfaces. This may take a few seconds.");
zincCSG.intersect(boxGeometry).then((csg1) => {
var intersect = undefined;
if (glyphsetCSG) {
Expand Down Expand Up @@ -221,16 +220,14 @@ exports.csg = function(sceneIn, zincRendererIn) {
resultCSG.terminateWorker();
}).catch(
(reason) => {
if (alertFunction)
alertFunction(reason);
displayMessage(reason);
}
);
}
csg1.terminateWorker();
}).catch(
(reason) => {
if (alertFunction)
alertFunction(reason);
displayMessage(reason);
}
);
}
Expand Down Expand Up @@ -424,10 +421,14 @@ exports.csg = function(sceneIn, zincRendererIn) {
updatePlane();
}

this.setAlertFunction = function(alertFunctionIn) {
alertFunction = alertFunctionIn;
var displayMessage = function(message) {
if (messageFunction)
messageFunction(message);
}

this.setMessageFunction = function(functionIn) {
messageFunction = functionIn;
}

this.addDatGui = function(parent) {
datGui = new dat.GUI({autoPlace: false});
Expand Down

0 comments on commit e7a4f6b

Please sign in to comment.