
from ashapi import Config, SimcomplexTask, local_server


class SceneRoutesTask(SimcomplexTask):

    def init(self, path):
        self.scene_path = path

    def setup(self):
        self.done = False
        print(f"Opening scene '{self.scene_path}'")
        self.scene.open(
            self.scene_path,
            self.on_scene_opened
        )

    def on_scene_opened(self, response):
        print(f"Opened scene: '{self.scene_path}'")
        print(f"Opened scene contains {len(self.scene.routes)} route(s)")
        if self.scene.routes:
            print("Routes:")
            for r in self.scene.routes:
                print(f'    "{r.name}", {len(r)} points, uid={r.uid}')
        self.done = self.scene.path == self.scene_path
        self.complete()

    def result(self):
        return self.done



if __name__ == '__main__':

    config = Config.localhost()

    with local_server(config):

        task = SceneRoutesTask(config, "api/all_models_nv.stexc")

        result = task.run()

