Skip to content

Commit

Permalink
Merge pull request #10 from floryst/expose_readerfactory_methods
Browse files Browse the repository at this point in the history
fix(ReaderFactory): Expose useful methods
  • Loading branch information
jourdain authored Feb 8, 2018
2 parents 0f9243d + 378fbdb commit 4815915
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
33 changes: 9 additions & 24 deletions Sources/controls/FileLoader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
);
});
}
);
}
Expand Down
17 changes: 16 additions & 1 deletion Sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -82,6 +96,7 @@ export function createViewer(container, proxyConfiguration = defaultConfig) {
return {
addDataSet,
openRemoteDataset,
loadAndViewFiles,
processURLArgs,
unbind,
toggleControl,
Expand Down
22 changes: 22 additions & 0 deletions Sources/io/ReaderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,33 @@ 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,
loadFiles,
registerReader,
listReaders,
listSupportedExtensions,
registerReadersToProxyManager,
};

0 comments on commit 4815915

Please sign in to comment.