import { Parser } from "./parser";
import { FilePusher } from "../gocadpusher/filepusher";
declare var proj4;

/**
 * Uses the block reading parser in the current UI thread. in
 * other words single threading. Mainly for debugging as its
 * easier to debug.
 */
export class LocalGocadPusherParser extends Parser {
   // Easier to debug when running local.
   public parse(data: any): Promise<any> {
      return new Promise<any>(resolve => {
         new FilePusher(data.file, data.options, proj4).start().then(document => {
            resolve(document);
         });
      });
   }
}
import { Parser } from "./parser";
import { Event } from "../domain/event";
import { PipeToThreedObj } from "../push3js/pipetothreedobj";
import { DocumentPusher } from "../gocadpusher/documentpusher";
import { LinesToLinePusher } from "../util/linestolinepusher";
import { LinesPagedPusher } from "../util/linespagedpusher";

declare var proj4;

let eventList = [
   "start",
   "complete",
   "bstones",
   "borders",
   "header",
   "vertices",
   "faces",
   "lines",
   "properties"
];

/**
 * Uses the block reading parser in the current UI thread. in
 * other words single threading. Mainly for debugging as its
 * easier to debug.
 */
export class LocalGocadPusherParser extends Parser {
   constructor(public options: any = {}) {
      super();
   }

   public parse(data: any): Promise<any> {
      let file = data.file;
      let options = data.options;

      return new Promise<any>((resolve, reject) => {
         let pusher = new DocumentPusher(this.options, proj4);

         // Turn blocks of lines into lines
         let linesToLinePusher = new LinesToLinePusher(function (line) {
            pusher.push(line);
         });

         let pipe = new PipeToThreedObj();
         pipe.addEventListener("complete", (event) => {
            resolve(event.data);
         });

         pipe.addEventListener("error", (event) => {
            console.log("There is an error with your pipes!");
            reject(event.data);
         });

         new LinesPagedPusher(file, options, function (lines) {
            linesToLinePusher.receiver(lines);
         }).start().then(function () {
            console.log("******************* Local Kaput ****************************");
         });

         eventList.forEach(function (name) {
            // console.log("Adding listener: " + name);
            pusher.addEventListener(name,
               function defaultHandler(event) {
                  console.log("GPW: " + event.type);
                  pipe.pipe({
                     eventName: event.type,
                     data: event.data
                  });
               });
         });
      });
   }
}

Convert local pusher to use new style
Convert local pusher to use new style
