Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Common interface for getting and setting viewpoints

Wieland Lindenthalf7bdb37d9b72
diff --git a/frontend/src/app/modules/bcf/bcf-buttons/bcf-add-viewpoint-button.component.ts b/frontend/src/app/modules/bcf/bcf-buttons/bcf-add-viewpoint-button.component.ts
index e4e3d4145d6..457e749073e 100644
--- a/frontend/src/app/modules/bcf/bcf-buttons/bcf-add-viewpoint-button.component.ts
+++ b/frontend/src/app/modules/bcf/bcf-buttons/bcf-add-viewpoint-button.component.ts
@@ -29,13 +29,9 @@
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
import {CurrentProjectService} from "core-components/projects/current-project.service";
-import {BcfPathHelperService} from "core-app/modules/bcf/helper/bcf-path-helper.service";
-import {RevitBridgeService} from "core-app/modules/bcf/services/revit-bridge.service";
import {HttpClient, HttpHeaders} from "@angular/common/http";
-import {untilComponentDestroyed} from "ng2-rx-componentdestroyed";
-import {distinctUntilChanged, filter} from "rxjs/operators";
-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";
import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";
+import {ModelViewerService} from "core-app/modules/bcf/services/model-viewer.service";
@Component({
template: `
@@ -56,23 +52,13 @@ export class BcfAddViewpointButtonComponent implements OnInit, OnDestroy {
constructor(readonly I18n:I18nService,
readonly currentProject:CurrentProjectService,
- readonly revitBridgeService:RevitBridgeService,
+ readonly modelViewerService:ModelViewerService,
readonly httpClient:HttpClient) {
}
public handleClick() {
console.log("handleClick");
- const trackingId = this.revitBridgeService.newTrackingId();
-
- this.revitBridgeService.sendMessageToRevit('ViewpointGenerationRequest', trackingId, '');
-
- this.revitBridgeService.revitMessageReceived$
- .pipe(
- distinctUntilChanged(),
- filter(message => message.messageType === 'ViewpointData' && message.trackingId === trackingId),
- untilComponentDestroyed(this)
- )
- .subscribe(message => this.saveViewpoint(message));
+ this.modelViewerService.getViewpoint().then((message) => this.saveViewpoint(message));
}
private saveViewpoint(message:any):void {
@@ -96,7 +82,7 @@ export class BcfAddViewpointButtonComponent implements OnInit, OnDestroy {
responseType: 'json'
}
).subscribe((data) => {
- console.log("Response of posting viewpiont", data);
+ console.log("Response of posting viewpoint", data);
});
}
diff --git a/frontend/src/app/modules/bcf/openproject-bcf.module.ts b/frontend/src/app/modules/bcf/openproject-bcf.module.ts
index db6786447d1..14798d00139 100644
--- a/frontend/src/app/modules/bcf/openproject-bcf.module.ts
+++ b/frontend/src/app/modules/bcf/openproject-bcf.module.ts
@@ -40,6 +40,8 @@ import {BcfAddViewpointButtonComponent} from "core-app/modules/bcf/bcf-buttons/b
import {RevitBridgeService} from "core-app/modules/bcf/services/revit-bridge.service";
import {HTTP_INTERCEPTORS, HttpClientModule} from "@angular/common/http";
import {OpenProjectHeaderInterceptor} from "core-app/modules/hal/http/openproject-header-interceptor";
+import {ModelViewerService} from "core-app/modules/bcf/services/model-viewer.service";
+import {XeokitBridgeService} from "core-app/modules/bcf/services/xeokit-bridge.service";
@NgModule({
imports: [
@@ -52,7 +54,9 @@ import {OpenProjectHeaderInterceptor} from "core-app/modules/hal/http/openprojec
{ provide: HTTP_INTERCEPTORS, useClass: OpenProjectHeaderInterceptor, multi: true },
BcfDetectorService,
BcfPathHelperService,
- RevitBridgeService
+ ModelViewerService,
+ RevitBridgeService,
+ XeokitBridgeService
],
declarations: [
BcfWpSingleViewComponent,
diff --git a/frontend/src/app/modules/bcf/services/model-viewer.service.ts b/frontend/src/app/modules/bcf/services/model-viewer.service.ts
new file mode 100644
index 00000000000..27d5f46467e
--- /dev/null
+++ b/frontend/src/app/modules/bcf/services/model-viewer.service.ts
@@ -0,0 +1,27 @@
+import {HostListener, Injectable} from '@angular/core';
+import {ViewerBridgeServiceInterface} from "core-app/modules/bcf/services/viewer-bridge.service";
+import {RevitBridgeService} from "core-app/modules/bcf/services/revit-bridge.service";
+import {XeokitBridgeService} from "core-app/modules/bcf/services/xeokit-bridge.service";
+
+@Injectable()
+export class ModelViewerService {
+
+ public modelViewer:ViewerBridgeServiceInterface;
+
+
+ constructor(private readonly revitBridge:RevitBridgeService,
+ private readonly xeokitBridge:XeokitBridgeService) {
+ this.modelViewer = this.revitBridge;
+ if (window.navigator.userAgent.search('Revit') > -1) {
+ console.log("We are running in the context of a revit add-in");
+ this.modelViewer = this.revitBridge;
+ } else {
+ console.log('We are running in a plain browser');
+ this.modelViewer = this.xeokitBridge;
+ }
+ }
+
+ public getViewpoint():Promise<any> {
+ return this.modelViewer.getViewpoint();
+ }
+}
diff --git a/frontend/src/app/modules/bcf/services/revit-bridge.service.ts b/frontend/src/app/modules/bcf/services/revit-bridge.service.ts
index 0ede922ecff..f1043bf4877 100644
--- a/frontend/src/app/modules/bcf/services/revit-bridge.service.ts
+++ b/frontend/src/app/modules/bcf/services/revit-bridge.service.ts
@@ -1,12 +1,16 @@
+import {ViewerBridgeServiceInterface} from "core-app/modules/bcf/services/viewer-bridge.service";
+
declare global {
interface Window { RevitBridge:any; }
}
-import {HostListener, Injectable} from '@angular/core';
+import {Injectable} from '@angular/core';
import {Subject} from "rxjs";
+import {distinctUntilChanged, filter, first} from "rxjs/operators";
+import {untilComponentDestroyed} from "ng2-rx-componentdestroyed";
@Injectable()
-export class RevitBridgeService {
+export class RevitBridgeService implements ViewerBridgeServiceInterface {
private revitMessageReceivedSource = new Subject<{ messageType:string, trackingId:string, messagePayload:string }>();
public revitMessageReceived$ = this.revitMessageReceivedSource.asObservable();
private _trackingIdNumber = 0;
@@ -29,6 +33,20 @@ export class RevitBridgeService {
}
}
+ public getViewpoint():Promise<any> {
+ const trackingId = this.newTrackingId();
+
+ this.sendMessageToRevit('ViewpointGenerationRequest', trackingId, '');
+
+ return this.revitMessageReceived$
+ .pipe(
+ distinctUntilChanged(),
+ filter(message => message.messageType === 'ViewpointData' && message.trackingId === trackingId),
+ first()
+ )
+ .toPromise();
+ }
+
public sendMessageToRevit(messageType:string, trackingId:string, messagePayload?:any) {
if (!this.ready) {
console.log('The Revit bridge is not ready yet.');
diff --git a/frontend/src/app/modules/bcf/services/viewer-bridge.service.d.ts b/frontend/src/app/modules/bcf/services/viewer-bridge.service.d.ts
new file mode 100644
index 00000000000..ff5d6085733
--- /dev/null
+++ b/frontend/src/app/modules/bcf/services/viewer-bridge.service.d.ts
@@ -0,0 +1,4 @@
+export interface ViewerBridgeServiceInterface {
+ getViewpoint():any;
+ // setViewpoint() {};
+}
diff --git a/frontend/src/app/modules/bcf/services/xeokit-bridge.service.ts b/frontend/src/app/modules/bcf/services/xeokit-bridge.service.ts
new file mode 100644
index 00000000000..f52846b9f3b
--- /dev/null
+++ b/frontend/src/app/modules/bcf/services/xeokit-bridge.service.ts
@@ -0,0 +1,15 @@
+import {ViewerBridgeServiceInterface} from "core-app/modules/bcf/services/viewer-bridge.service";
+
+import {Injectable} from '@angular/core';
+import {IFCViewerService} from "core-app/modules/ifc_models/ifc-viewer/ifc-viewer.service";
+
+@Injectable()
+export class XeokitBridgeService implements ViewerBridgeServiceInterface {
+ constructor(readonly ifcViewerService:IFCViewerService) {
+ }
+
+ public getViewpoint():Promise<any> {
+ // console.log("getViewpoint from XeokitViewerService.getViewer()", this.xeokitViewerService.getViewer());
+ return new Promise((resolve, reject) => {});
+ }
+}
diff --git a/frontend/src/app/modules/ifc_models/ifc-viewer/ifc-viewer.component.ts b/frontend/src/app/modules/ifc_models/ifc-viewer/ifc-viewer.component.ts
index 5a2dd220613..2b0dcfea967 100644
--- a/frontend/src/app/modules/ifc_models/ifc-viewer/ifc-viewer.component.ts
+++ b/frontend/src/app/modules/ifc_models/ifc-viewer/ifc-viewer.component.ts
@@ -27,7 +27,6 @@
// ++
import {Component, ElementRef, OnInit, OnDestroy, ChangeDetectionStrategy} from '@angular/core';
-
import {GonService} from "core-app/modules/common/gon/gon.service";
import {IFCViewerService} from "core-app/modules/ifc_models/ifc-viewer/ifc-viewer.service";