Pārlūkot izejas kodu

loader plugins by name (using configuration)

Raanan Weber 7 gadi atpakaļ
vecāks
revīzija
14b205f1a1

+ 4 - 0
Viewer/src/configuration/configuration.ts

@@ -52,6 +52,10 @@ export interface ViewerConfiguration {
         }
     }
 
+    loaderPlugins?: {
+        [propName: string]: boolean;
+    };
+
     // features that are being tested.
     // those features' syntax will change and move out! 
     // Don't use in production (or be ready to make the changes :) )

+ 15 - 3
Viewer/src/loader/modelLoader.ts

@@ -5,6 +5,7 @@ import { IModelConfiguration } from "../configuration/configuration";
 import { ViewerModel, ModelState } from "../model/viewerModel";
 import { ILoaderPlugin } from './plugins/loaderPlugin';
 import { TelemetryLoaderPlugin } from './plugins/telemetryLoaderPlugin';
+import { getLoaderPluginByName } from './plugins/';
 
 /**
  * An instance of the class is in charge of loading the model correctly.
@@ -30,11 +31,22 @@ export class ModelLoader {
         this._loadId = 0;
         this._plugins = [];
 
-        this.addPlugin(new TelemetryLoaderPlugin());
+        this.addPlugin("telemetry");
     }
 
-    public addPlugin(plugin: ILoaderPlugin) {
-        this._plugins.push(plugin);
+    public addPlugin(plugin: ILoaderPlugin | string) {
+        let actualPlugin: ILoaderPlugin = {};
+        if (typeof plugin === 'string') {
+            let loadedPlugin = getLoaderPluginByName(plugin);
+            if (loadedPlugin) {
+                actualPlugin = loadedPlugin;
+            }
+        } else {
+            actualPlugin = plugin;
+        }
+        if (actualPlugin && this._plugins.indexOf(actualPlugin) === -1) {
+            this._plugins.push(actualPlugin);
+        }
     }
 
     /**

+ 12 - 0
Viewer/src/loader/plugins/index.ts

@@ -0,0 +1,12 @@
+import { TelemetryLoaderPlugin } from "./telemetryLoaderPlugin";
+import { ILoaderPlugin } from "./loaderPlugin";
+
+const pluginCache: { [key: string]: ILoaderPlugin } = {};
+
+export function getLoaderPluginByName(name: string) {
+    switch (name) {
+        case 'telemetry':
+            pluginCache[name] = new TelemetryLoaderPlugin();
+            return pluginCache[name];
+    }
+}

+ 9 - 0
Viewer/src/viewer/viewer.ts

@@ -324,6 +324,15 @@ export abstract class AbstractViewer {
         if (newConfiguration.observers) {
             this._configureObservers(newConfiguration.observers);
         }
+
+        if (newConfiguration.loaderPlugins) {
+            // TODO should plugins be removed?
+            Object.keys(newConfiguration.loaderPlugins).forEach((name => {
+                if (newConfiguration.loaderPlugins && newConfiguration.loaderPlugins[name]) {
+                    this.modelLoader.addPlugin(name);
+                }
+            }))
+        }
     }
 
     /**