import LoadAction from "../../classes/status/LoadAction" ; import { TreeElement } from "../../classes/TreeElement" ; import { ColorMetrics } from "../../constants/ColorMetrics" ; import { lazyInject } from "../../inversify.config" ; import AppStatusStore from "../../stores/AppStatusStore" ; import SceneStore from "../../stores/SceneStore" ; import VisualizationOptionStore from "../../stores/VisualizationOptionStore" ; import SonarQubeScmService from "../sonarqube/scm/SonarQubeScmService" ; import LayoutProcessor from "./LayoutProcessor" ; import Softvis3dModel from "./Softvis3dModel" ; export default class CityLayoutService { public static BUILD_CITY : LoadAction = new LoadAction ( "BUILD_CITY" , "Create layout" ) ; @ lazyInject ( "SceneStore" ) private readonly sceneStore ! : SceneStore ; @ lazyInject ( "AppStatusStore" ) private readonly appStatusStore ! : AppStatusStore ; @ lazyInject ( "VisualizationOptionStore" ) private readonly visualizationOptions ! : VisualizationOptionStore ; @ lazyInject ( "LayoutProcessor" ) private readonly layoutProcessor ! : LayoutProcessor ; @ lazyInject ( "SonarQubeScmService" ) private readonly scmService ! : SonarQubeScmService ; public createCity ( ) { this . loadRequiredMetricData ( ) . then ( ( ) => { if ( this . sceneStore . projectData !== null ) { this . appStatusStore . load ( CityLayoutService . BUILD_CITY ) ; const model = this . prepareModel ( ) ; this . buildCity ( model ) ; } } ) ; } private loadRequiredMetricData ( ) { if ( ColorMetrics . isScmColorMetric ( this . visualizationOptions . metricColor ) ) { return this . scmService . assertScmInfoAreLoaded ( ) ; } return new Promise < void > ( ( resolve ) => { resolve ( ) ; } ) ; } private prepareModel ( ) { return new Softvis3dModel ( this . sceneStore . projectData as TreeElement , this . visualizationOptions . profile . footprintMetric . id , this . visualizationOptions . profile . heightMetric . id , this . visualizationOptions . metricColor . id , this . visualizationOptions . buildingColorTheme ) ; } private buildCity ( model ) { const options = { layout : this . visualizationOptions . layout . id , layoutOptions : { } , colorMetric : this . visualizationOptions . metricColor . id , scalingMethod : this . visualizationOptions . profile . scale , } ; this . layoutProcessor . getIllustration ( options , model ) . then ( ( illustration ) => { this . sceneStore . shapes = illustration . shapes ; this . appStatusStore . loadComplete ( CityLayoutService . BUILD_CITY ) ; } ) ; } }