diff --git a/Sources/controls/FileLoader/index.js b/Sources/controls/FileLoader/index.js index f5d7425c..4c890756 100644 --- a/Sources/controls/FileLoader/index.js +++ b/Sources/controls/FileLoader/index.js @@ -24,38 +24,23 @@ export default class FileLoader extends React.Component { ReaderFactory.openFiles( ['raw'].concat(ReaderFactory.listSupportedExtensions()), (files) => { - ReaderFactory.loadFiles(files).then( - (readers) => { - for (let i = 0; i < readers.length; i++) { - const { reader, sourceType, name, dataset } = readers[i]; - if (reader) { - const source = this.props.proxyManager.createProxy( - 'Sources', - 'TrivialProducer', - { name } - ); - if (dataset && dataset.isA && dataset.isA('vtkDataSet')) { - source.setInputData(dataset, sourceType); - } else { - source.setInputAlgorithm(reader, sourceType); - } - - this.props.proxyManager.createRepresentationInAllViews(source); - this.props.proxyManager.renderAllViews(); - } - } + ReaderFactory.loadFiles(files) + .then((readers) => { + ReaderFactory.registerReadersToProxyManager( + readers, + this.props.proxyManager + ); this.setState({ file: null }); this.props.updateTab('pipeline'); - }, - () => { + }) + .catch(() => { // No reader found if (files.length === 1) { this.setState({ file: files[0] }); } else { this.setState({ file: null }); } - } - ); + }); } ); } diff --git a/Sources/index.js b/Sources/index.js index c0a0a60f..c4fbe81c 100644 --- a/Sources/index.js +++ b/Sources/index.js @@ -16,7 +16,15 @@ import MainView from './MainView'; import * as Controls from './controls'; import ReaderFactory from './io/ReaderFactory'; -export const { registerReader } = ReaderFactory; +import { registerReadersToProxyManager } from './controls/FileLoader'; + +export const { + registerReader, + listReaders, + listSupportedExtensions, + openFiles, + loadFiles, +} = ReaderFactory; export const { registerControlTab, unregisterControlTab } = Controls; export function createViewer(container, proxyConfiguration = defaultConfig) { @@ -50,6 +58,12 @@ export function createViewer(container, proxyConfiguration = defaultConfig) { .catch(console.error); } + function loadAndViewFiles(files) { + return ReaderFactory.loadFiles(files).then((readers) => + registerReadersToProxyManager(readers, proxyManager) + ); + } + function toggleControl() { mainView.onToggleControl(); } @@ -82,6 +96,7 @@ export function createViewer(container, proxyConfiguration = defaultConfig) { return { addDataSet, openRemoteDataset, + loadAndViewFiles, processURLArgs, unbind, toggleControl, diff --git a/Sources/io/ReaderFactory.js b/Sources/io/ReaderFactory.js index 2ea2fb88..d15b5e26 100644 --- a/Sources/io/ReaderFactory.js +++ b/Sources/io/ReaderFactory.js @@ -138,6 +138,27 @@ function downloadDataset(fileName, url, progressCallback) { // ---------------------------------------------------------------------------- +function registerReadersToProxyManager(readers, proxyManager) { + for (let i = 0; i < readers.length; i++) { + const { reader, sourceType, name, dataset } = readers[i]; + if (reader) { + const source = proxyManager.createProxy('Sources', 'TrivialProducer', { + name, + }); + if (dataset && dataset.isA && dataset.isA('vtkDataSet')) { + source.setInputData(dataset, sourceType); + } else { + source.setInputAlgorithm(reader, sourceType); + } + + proxyManager.createRepresentationInAllViews(source); + proxyManager.renderAllViews(); + } + } +} + +// ---------------------------------------------------------------------------- + export default { downloadDataset, openFiles, @@ -145,4 +166,5 @@ export default { registerReader, listReaders, listSupportedExtensions, + registerReadersToProxyManager, };