From 44a52aeb2f3e1050a264cf18eece901794a3fcf2 Mon Sep 17 00:00:00 2001 From: Wieland Lindenthal Date: Fri, 17 Sep 2021 15:32:49 +0200 Subject: [PATCH] Cherry picking PR#9422, PR#9446 "[37894] Amend clipping plane direction" (#9680) * Added configurational flag to bcf viewer - on loading: clipping direction is reversed - on saving: clipping direction is reversed - fixed maxlen of jshint to maxlen of editorconfig - removed duplicate key in eslintrc * cosmetic formatting change Co-authored-by: Eric Schubert --- frontend/.eslintrc.js | 1 - frontend/.jshintrc | 2 +- .../ifc-viewer/ifc-viewer.service.ts | 77 +++++++++++-------- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index 2b4453c7bc..f8292b526e 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -101,7 +101,6 @@ module.exports = { "no-empty": "error", "no-eval": "error", "no-new-wrappers": "error", - "no-redeclare": "error", "no-trailing-spaces": "error", "no-underscore-dangle": "off", "no-unused-labels": "error", diff --git a/frontend/.jshintrc b/frontend/.jshintrc index 91315dac1f..25137b31ba 100644 --- a/frontend/.jshintrc +++ b/frontend/.jshintrc @@ -46,7 +46,7 @@ "noarg": true, "noempty": true, "nonew": true, - "maxlen": 100, + "maxlen": 120, "quotmark": true, "sub": true, "undef": true, diff --git a/frontend/src/app/modules/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts b/frontend/src/app/modules/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts index 65a64598f8..0337c3dd96 100644 --- a/frontend/src/app/modules/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts +++ b/frontend/src/app/modules/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts @@ -1,16 +1,15 @@ -import { Injectable, Inject, Injector } from '@angular/core'; -import { XeokitServer } from "core-app/modules/bim/ifc_models/xeokit/xeokit-server"; -import { BcfViewpointInterface } from "core-app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface"; -import { ViewerBridgeService } from "core-app/modules/bim/bcf/bcf-viewer-bridge/viewer-bridge.service"; -import { BehaviorSubject, Observable, Subject , of } from "rxjs"; -import { WorkPackageResource } from "core-app/modules/hal/resources/work-package-resource"; -import { PathHelperService } from "core-app/modules/common/path-helper/path-helper.service"; -import { BcfApiService } from "core-app/modules/bim/bcf/api/bcf-api.service"; -import { InjectField } from "core-app/helpers/angular/inject-field.decorator"; -import { ViewpointsService } from "core-app/modules/bim/bcf/helper/viewpoints.service"; -import { CurrentProjectService} from "core-app/components/projects/current-project.service"; -import { HttpClient } from "@angular/common/http"; - +import { Injectable, Injector } from '@angular/core'; +import { XeokitServer } from 'core-app/modules/bim/ifc_models/xeokit/xeokit-server'; +import { BcfViewpointInterface } from 'core-app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; +import { ViewerBridgeService } from 'core-app/modules/bim/bcf/bcf-viewer-bridge/viewer-bridge.service'; +import { BehaviorSubject, Observable, of } from 'rxjs'; +import { WorkPackageResource } from 'core-app/modules/hal/resources/work-package-resource'; +import { PathHelperService } from 'core-app/modules/common/path-helper/path-helper.service'; +import { BcfApiService } from 'core-app/modules/bim/bcf/api/bcf-api.service'; +import { InjectField } from 'core-app/helpers/angular/inject-field.decorator'; +import { ViewpointsService } from 'core-app/modules/bim/bcf/helper/viewpoints.service'; +import { CurrentProjectService } from 'core-app/components/projects/current-project.service'; +import { HttpClient } from '@angular/common/http'; export interface XeokitElements { canvasElement:HTMLElement; @@ -21,16 +20,28 @@ export interface XeokitElements { enableEditModels?:boolean; } +/** + * Options for saving current viewpoint in xeokit-bim-viewer. + * See: https://xeokit.github.io/xeokit-bim-viewer/docs/class/src/BIMViewer.js~BIMViewer.html#instance-method-saveBCFViewpoint + */ export interface BCFCreationOptions { spacesVisible?:boolean; spaceBoundariesVisible?:boolean; openingsVisible?:boolean; + defaultInvisible?:boolean; + reverseClippingPlanes?:boolean; } +/** + * Options for loading a viewpoint into xeokit-bim-viewer. + * See: https://xeokit.github.io/xeokit-bim-viewer/docs/class/src/BIMViewer.js~BIMViewer.html#instance-method-loadBCFViewpoint + */ export interface BCFLoadOptions { rayCast?:boolean; immediate?:boolean; duration?:number; + updateCompositeObjects?:boolean; + reverseClippingPlanes?:boolean; } @Injectable() @@ -49,7 +60,7 @@ export class IFCViewerService extends ViewerBridgeService { super(injector); } - public newViewer(elements:XeokitElements, projects:any[]) { + public newViewer(elements:XeokitElements, projects:any[]):void { import('@xeokit/xeokit-bim-viewer/dist/xeokit-bim-viewer.es').then((XeokitViewerModule:any) => { const server = new XeokitServer(this.pathHelper); const viewerUI = new XeokitViewerModule.BIMViewer(server, elements); @@ -62,45 +73,44 @@ export class IFCViewerService extends ViewerBridgeService { viewerUI.loadProject(projects[0]["id"]); - viewerUI.on("addModel", (event:Event) => { // "Add" selected in Models tab's context menu + viewerUI.on("addModel", () => { // "Add" selected in Models tab's context menu window.location.href = this.pathHelper.ifcModelsNewPath(this.currentProjectService.identifier as string); }); viewerUI.on("editModel", (event:{ modelId:number|string }) => { // "Edit" selected in Models tab's context menu - window.location.href = this.pathHelper.ifcModelsEditPath(this.currentProjectService.identifier as string, event.modelId); + window.location.href = this.pathHelper.ifcModelsEditPath( + this.currentProjectService.identifier as string, event.modelId); }); - viewerUI.on("deleteModel", (event:{ modelId:number|string }) => { // "Delete" selected in Models tab's context menu + viewerUI.on("deleteModel", (event:{ modelId:number|string }) => { + // "Delete" selected in Models tab's context menu. // We don't have an API for IFC models yet. We need to use the normal Rails form posts for deletion. const formData = new FormData(); formData.append( 'authenticity_token', - jQuery('meta[name=csrf-token]').attr('content') as string + jQuery('meta[name=csrf-token]').attr('content') as string, ); formData.append( '_method', - 'delete' + 'delete', ); this.httpClient.post( - this.pathHelper.ifcModelsDeletePath( - this.currentProjectService.identifier as string, event.modelId), - formData - ) + this.pathHelper.ifcModelsDeletePath(this.currentProjectService.identifier as string, event.modelId), formData) .subscribe() .add(() => { // Ensure we reload after every request. // We need to reload to get a fresh CSRF token for a successive // model deletion placed as a META element into the HTML HEAD. - window.location.reload() - }) + window.location.reload(); + }); }); this.viewer = viewerUI; }); } - public destroy() { + public destroy():void { this.viewerVisible$.complete(); if (!this.viewer) { @@ -111,7 +121,7 @@ export class IFCViewerService extends ViewerBridgeService { this.viewer = undefined; } - public get viewer() { + public get viewer():any { return this._viewer; } @@ -119,12 +129,13 @@ export class IFCViewerService extends ViewerBridgeService { this._viewer = viewer; } - public setKeyboardEnabled(val:boolean) { + public setKeyboardEnabled(val:boolean):void { this.viewer.setKeyboardEnabled(val); } public getViewpoint$():Observable { - const viewpoint = this.viewer.saveBCFViewpoint({ spacesVisible: true }); + const opts:BCFCreationOptions = { spacesVisible: true, reverseClippingPlanes: true }; + const viewpoint = this.viewer.saveBCFViewpoint(opts); // The backend rejects viewpoints with bitmaps delete viewpoint.bitmaps; @@ -132,15 +143,15 @@ export class IFCViewerService extends ViewerBridgeService { return of(viewpoint); } - public showViewpoint(workPackage:WorkPackageResource, index:number) { + public showViewpoint(workPackage:WorkPackageResource, index:number):void { // Avoid reload the app when there is a place to show the viewer // ('bim.partitioned.split') if (this.routeWithViewer) { if (this.viewer) { - let viewpointOptions = { updateCompositeObjects: true }; + const opts:BCFLoadOptions = { updateCompositeObjects: true, reverseClippingPlanes: true }; this.viewpointsService .getViewPoint$(workPackage, index) - .subscribe(viewpoint => this.viewer.loadBCFViewpoint(viewpoint, viewpointOptions)); + .subscribe(viewpoint => this.viewer.loadBCFViewpoint(viewpoint, opts)); } } else { // Reload the whole app to get the correct menus and GON data @@ -149,7 +160,7 @@ export class IFCViewerService extends ViewerBridgeService { window.location.href = this.pathHelper.bimDetailsPath( workPackage.project.idFromLink, workPackage.id!, - index + index, ); } }