From 124f935876e414cba26a1f573b47b53278d381ba Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Wed, 7 Feb 2018 17:16:05 -0500 Subject: [PATCH 1/3] fix(ReaderFactory): Expose useful methods --- Sources/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/index.js b/Sources/index.js index c0a0a60f..7a76b3c2 100644 --- a/Sources/index.js +++ b/Sources/index.js @@ -16,7 +16,13 @@ import MainView from './MainView'; import * as Controls from './controls'; import ReaderFactory from './io/ReaderFactory'; -export const { registerReader } = ReaderFactory; +export const { + registerReader, + listReaders, + listSupportedExtensions, + openFiles, + loadFiles, +} = ReaderFactory; export const { registerControlTab, unregisterControlTab } = Controls; export function createViewer(container, proxyConfiguration = defaultConfig) { From 5cc06f8a668657f78576d7ee377d129e60a2f410 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Wed, 7 Feb 2018 18:02:43 -0500 Subject: [PATCH 2/3] fix(Glance): Expose loadAndViewFiles on viewer --- Sources/controls/FileLoader/index.js | 49 ++++++++++++++-------------- Sources/index.js | 9 +++++ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Sources/controls/FileLoader/index.js b/Sources/controls/FileLoader/index.js index f5d7425c..6c958156 100644 --- a/Sources/controls/FileLoader/index.js +++ b/Sources/controls/FileLoader/index.js @@ -7,6 +7,25 @@ import ReaderFactory from '../../io/ReaderFactory'; import RawReader from './RawReader'; import style from './FileLoader.mcss'; +export 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 class FileLoader extends React.Component { constructor(props) { super(props); @@ -24,38 +43,20 @@ 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) => { + 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 7a76b3c2..c4fbe81c 100644 --- a/Sources/index.js +++ b/Sources/index.js @@ -16,6 +16,8 @@ import MainView from './MainView'; import * as Controls from './controls'; import ReaderFactory from './io/ReaderFactory'; +import { registerReadersToProxyManager } from './controls/FileLoader'; + export const { registerReader, listReaders, @@ -56,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(); } @@ -88,6 +96,7 @@ export function createViewer(container, proxyConfiguration = defaultConfig) { return { addDataSet, openRemoteDataset, + loadAndViewFiles, processURLArgs, unbind, toggleControl, From 378fbdb5982c999a2891687423c69b16ac2d4778 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Wed, 7 Feb 2018 18:15:32 -0500 Subject: [PATCH 3/3] fix(ReaderFactory): Move registerReadersToProxyManager to ReaderFactory --- Sources/controls/FileLoader/index.js | 24 ++++-------------------- Sources/io/ReaderFactory.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Sources/controls/FileLoader/index.js b/Sources/controls/FileLoader/index.js index 6c958156..4c890756 100644 --- a/Sources/controls/FileLoader/index.js +++ b/Sources/controls/FileLoader/index.js @@ -7,25 +7,6 @@ import ReaderFactory from '../../io/ReaderFactory'; import RawReader from './RawReader'; import style from './FileLoader.mcss'; -export 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 class FileLoader extends React.Component { constructor(props) { super(props); @@ -45,7 +26,10 @@ export default class FileLoader extends React.Component { (files) => { ReaderFactory.loadFiles(files) .then((readers) => { - registerReadersToProxyManager(readers, this.props.proxyManager); + ReaderFactory.registerReadersToProxyManager( + readers, + this.props.proxyManager + ); this.setState({ file: null }); this.props.updateTab('pipeline'); }) 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, };