Skip to content

Commit

Permalink
Remove tools gui. Revise tool controller role and tool api. Remove un…
Browse files Browse the repository at this point in the history
…do and loader gui.
  • Loading branch information
ivmartel committed Sep 5, 2019
1 parent e87ce7e commit 73463c3
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 2,492 deletions.
48 changes: 33 additions & 15 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,31 @@ dwv.App = function ()
this.getImageData = function () { return imageData; };
/**
* Is the data mono-slice?
* @return {Boolean} True if the data is mono-slice.
* @return {Boolean} True if the data only contains one slice.
*/
this.isMonoSliceData = function () { return isMonoSliceData; };
/**
* Is the data mono-frame?
* @return {Boolean} True if the data only contains one frame.
*/
this.isMonoFrameData = function () {
return this.getImage().getNumberOfFrames() === 1;
};
/**
* Can the data be scrolled?
* @return {Boolean} True if the data has more than one slice or frame.
*/
this.canScroll = function () {
return !this.isMonoSliceData() || !this.isMonoFrameData();
}

/**
* Can window and level be applied to the data?
* @return {Boolean} True if the data is monochrome.
*/
this.canWindowLevel = function () {
return this.getImage().getPhotometricInterpretation().match(/MONOCHROME/) !== null;
}

/**
* Get the main scale.
Expand Down Expand Up @@ -199,18 +221,18 @@ dwv.App = function ()
if ( toolName === "Draw" ) {
if ( typeof config.shapes !== "undefined" && config.shapes.length !== 0 ) {
// setup the shape list
var shapeList = {};
var shapeFactoryList = {};
for ( var s = 0; s < config.shapes.length; ++s ) {
var shapeName = config.shapes[s];
var shapeFactoryClass = shapeName+"Factory";
if (typeof dwv.tool[shapeFactoryClass] !== "undefined") {
shapeList[shapeName] = dwv.tool[shapeFactoryClass];
shapeFactoryList[shapeName] = dwv.tool[shapeFactoryClass];
}
else {
console.warn("Could not initialise unknown shape: "+shapeName);
}
}
toolList.Draw = new dwv.tool.Draw(this, shapeList);
toolList.Draw = new dwv.tool.Draw(this, shapeFactoryList);
toolList.Draw.addEventListener("draw-create", fireEvent);
toolList.Draw.addEventListener("draw-change", fireEvent);
toolList.Draw.addEventListener("draw-move", fireEvent);
Expand Down Expand Up @@ -253,15 +275,10 @@ dwv.App = function ()
}
}
}
toolboxController = new dwv.ToolboxController();
toolboxController.create(toolList, this);
toolboxController = new dwv.ToolboxController(toolList);
}
// gui
if ( config.gui ) {
// tools
if ( config.gui.indexOf("tool") !== -1 && toolboxController) {
toolboxController.setup();
}
// load
if ( config.gui.indexOf("load") !== -1 ) {
var loaderList = {};
Expand Down Expand Up @@ -395,10 +412,6 @@ dwv.App = function ()
*/
this.reset = function ()
{
// clear tools
if ( toolboxController ) {
toolboxController.reset();
}
// clear draw
if ( drawController ) {
drawController.reset();
Expand Down Expand Up @@ -720,6 +733,7 @@ dwv.App = function ()
{
// toggle html
var infoLayer = self.getElement("infoLayer");
// TODO remove
dwv.html.toggleDisplay(infoLayer);
// toggle listeners
infoController.toggleListeners(self, view);
Expand Down Expand Up @@ -1177,6 +1191,7 @@ dwv.App = function ()
var select = self.getElement("presetSelect");
if (select) {
select.selectedIndex = 0;
// TODO remove
dwv.gui.refreshElement(select);
}
};
Expand Down Expand Up @@ -1397,6 +1412,7 @@ dwv.App = function ()

// append the DICOM tags table
tags = data.info;
// TODO remove
if ( tagsGui ) {
tagsGui.update(data.info);
}
Expand Down Expand Up @@ -1424,6 +1440,7 @@ dwv.App = function ()
// connect with local listeners
view.addEventListener("wl-width-change", fireEvent);
view.addEventListener("wl-center-change", fireEvent);
view.addEventListener("wl-preset-add", fireEvent);
view.addEventListener("colour-change", fireEvent);
view.addEventListener("position-change", fireEvent);
view.addEventListener("slice-change", fireEvent);
Expand All @@ -1436,7 +1453,7 @@ dwv.App = function ()

// initialise the toolbox
if ( toolboxController ) {
toolboxController.initAndDisplay( imageLayer );
toolboxController.init( imageLayer );
}

// stop box listening to drag (after first drag)
Expand All @@ -1445,6 +1462,7 @@ dwv.App = function ()
box.removeEventListener("dragover", onDragOver);
box.removeEventListener("dragleave", onDragLeave);
box.removeEventListener("drop", onDrop);
// TODO remove
dwv.html.removeNode(box);
// switch listening to layerContainer
var div = self.getElement("layerContainer");
Expand Down
90 changes: 50 additions & 40 deletions src/app/toolboxController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,27 @@ var dwv = dwv || {};

/**
* Toolbox controller.
* @param {Array} toolList The list of tool objects.
* @constructor
*/
dwv.ToolboxController = function ()
dwv.ToolboxController = function (toolList)
{
// internal toolbox
var toolbox = null;
// point converter function
var displayToIndexConverter = null;

/**
* Create the internal toolbox.
* @param {Array} toolList The list of tools instances.
* @param {Object} app The associated app.
* Selected tool.
* @type Object
*/
this.create = function (toolList, app) {
toolbox = new dwv.tool.Toolbox(toolList, app);
};

/**
* Setup the internal toolbox.
*/
this.setup = function () {
toolbox.setup();
};
var selectedTool = null;

/**
* Reset the internal toolbox.
* Initialise.
*/
this.reset = function () {
toolbox.reset();
};

/**
* Initialise and display the internal toolbox.
*/
this.initAndDisplay = function (layer) {
// initialise
toolbox.init();
// display
toolbox.display(true);
this.init = function (layer) {
for( var key in toolList ) {
toolList[key].init();
}
// TODO Would prefer to have this done in the addLayerListeners
displayToIndexConverter = layer.displayToIndex;
// add layer listeners
Expand All @@ -53,9 +34,27 @@ dwv.ToolboxController = function ()

/**
* Get the tool list.
* @return {Array} The list of tool objects.
*/
this.getToolList = function () {
return toolbox.getToolList();
return toolList;
};

/**
* Check if a tool is in the tool list.
* @param {String} name The name to check.
* @return {String} The tool list element for the given name.
*/
this.hasTool = function (name) {
return this.getToolList()[name];
};

/**
* Get the selected tool.
* @return {Object} The selected tool.
*/
this.getSelectedTool = function () {
return selectedTool;
};

/**
Expand All @@ -64,7 +63,7 @@ dwv.ToolboxController = function ()
*/
this.getSelectedToolEventHandler = function (eventType)
{
return toolbox.getSelectedTool()[eventType];
return this.getSelectedTool()[eventType];
};

/**
Expand All @@ -73,7 +72,18 @@ dwv.ToolboxController = function ()
*/
this.setSelectedTool = function (name)
{
toolbox.setSelectedTool(name);
// check if we have it
if (!this.hasTool(name)) {
throw new Error("Unknown tool: '" + name + "'");
}
// de-activate previous
if (selectedTool) {
selectedTool.activate(false);
}
// set internal var
selectedTool = toolList[name];
// activate new tool
selectedTool.activate(true);
};

/**
Expand All @@ -82,7 +92,7 @@ dwv.ToolboxController = function ()
*/
this.setSelectedShape = function (name)
{
toolbox.getSelectedTool().setShapeName(name);
this.getSelectedTool().setShapeName(name);
};

/**
Expand All @@ -91,15 +101,15 @@ dwv.ToolboxController = function ()
*/
this.setSelectedFilter = function (name)
{
toolbox.getSelectedTool().setSelectedFilter(name);
this.getSelectedTool().setSelectedFilter(name);
};

/**
* Run the selected filter.
*/
this.runSelectedFilter = function ()
{
toolbox.getSelectedTool().getSelectedFilter().run();
this.getSelectedTool().getSelectedFilter().run();
};

/**
Expand All @@ -108,7 +118,7 @@ dwv.ToolboxController = function ()
*/
this.setLineColour = function (colour)
{
toolbox.getSelectedTool().setLineColour(colour);
this.getSelectedTool().setLineColour(colour);
};

/**
Expand All @@ -119,9 +129,9 @@ dwv.ToolboxController = function ()
{
// seems like jquery is checking if the method exists before it
// is used...
if ( toolbox && toolbox.getSelectedTool() &&
toolbox.getSelectedTool().getSelectedFilter() ) {
toolbox.getSelectedTool().getSelectedFilter().run(range);
if ( this.getSelectedTool() &&
this.getSelectedTool().getSelectedFilter() ) {
this.getSelectedTool().getSelectedFilter().run(range);
}
};

Expand Down Expand Up @@ -235,7 +245,7 @@ dwv.ToolboxController = function ()
if ( event.type !== "keydown" ) {
event.preventDefault();
}
var func = toolbox.getSelectedTool()[event.type];
var func = selectedTool[event.type];
if ( func )
{
func(event);
Expand Down
Loading

0 comments on commit 73463c3

Please sign in to comment.