From 695a4196774de72df9ad711e9ac121794a497043 Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Tue, 26 Oct 2021 11:02:45 +0200 Subject: [PATCH] [#39144] Get viewpoint returns too much data - https://community.openproject.org/work_packages/39144 - removed components from get viewpoint payload - fixed linter issues in several bcf services (added types) - added interface models for bcf viewpoint api - fixed parsing of attributes when posting viewpoints - added getter for viewpoint visibility and selection --- .../bim/bcf/api/bcf-api-request.service.ts | 30 ++- .../app/features/bim/bcf/api/bcf-api.model.ts | 103 ++++++++++ .../bim/bcf/api/topics/bcf-topic.paths.ts | 31 ++- .../bim/bcf/api/topics/bcf-topic.resource.ts | 28 +++ .../bcf-viewpoint-collection.paths.ts | 41 +++- .../bcf-viewpoint-item.interface.ts | 32 ++- .../bcf-viewpoint-selection.paths.ts | 41 ++++ .../bcf-viewpoint-visibility.paths.ts | 41 ++++ .../api/viewpoints/bcf-viewpoint.interface.ts | 11 -- .../bcf/api/viewpoints/bcf-viewpoint.paths.ts | 54 ++++- .../viewer-bridge.service.ts | 4 +- .../bcf-new-wp-attribute-group.component.ts | 46 ++++- .../bcf-wp-attribute-group.component.ts | 2 +- .../bim/bcf/helper/viewpoints.service.ts | 68 ++++++- .../ifc-viewer/ifc-viewer.service.ts | 184 ++++++++++++------ .../pages/viewer/ifc-models-data.service.ts | 2 +- .../bim/revit_add_in/revit-bridge.service.ts | 36 +++- .../bim/bcf/api/v2_1/viewpoints/api.rb | 19 +- .../api/v2_1/viewpoints/base_representer.rb | 8 - .../v2_1/viewpoints/coloring_representer.rb | 4 +- .../api/v2_1/viewpoints/full_representer.rb | 9 +- .../v2_1/viewpoints/selection_representer.rb | 4 +- .../api/v2_1/viewpoints/single_representer.rb | 2 - .../v2_1/viewpoints/visibility_representer.rb | 4 +- 24 files changed, 651 insertions(+), 153 deletions(-) create mode 100644 frontend/src/app/features/bim/bcf/api/bcf-api.model.ts create mode 100644 frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-selection.paths.ts create mode 100644 frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-visibility.paths.ts delete mode 100644 frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts diff --git a/frontend/src/app/features/bim/bcf/api/bcf-api-request.service.ts b/frontend/src/app/features/bim/bcf/api/bcf-api-request.service.ts index 81084f69fa..2f4a1ba645 100644 --- a/frontend/src/app/features/bim/bcf/api/bcf-api-request.service.ts +++ b/frontend/src/app/features/bim/bcf/api/bcf-api-request.service.ts @@ -1,3 +1,31 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { HttpClient, HttpErrorResponse, HttpParams } from '@angular/common/http'; import { Injector } from '@angular/core'; import { TypedJSON } from 'typedjson'; @@ -51,7 +79,7 @@ export class BcfApiRequestService { * @param method request method * @param path API path to request * @param data Request payload (URL params for get, JSON payload otherwise) - * @param data Request payload (URL params for get, JSON payload otherwise) + * @param headers Request headers */ public request(method:HTTPSupportedMethods, path:string, data:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}):Observable { // HttpClient requires us to create HttpParams instead of passing data for get diff --git a/frontend/src/app/features/bim/bcf/api/bcf-api.model.ts b/frontend/src/app/features/bim/bcf/api/bcf-api.model.ts new file mode 100644 index 0000000000..3fb169181a --- /dev/null +++ b/frontend/src/app/features/bim/bcf/api/bcf-api.model.ts @@ -0,0 +1,103 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + +export type BcfViewpointData = BcfViewpoint&{ + components:BcfViewpointVisibility&BcfViewpointSelection +}; + +export type CreateBcfViewpointData = BcfViewpointData&{ + snapshot:{ snapshot_type:string, snapshot_data:string } +}; + +export interface BcfViewpoint { + index:number|null + guid:string + orthogonal_camera:BcfOrthogonalCamera|null + perspective_camera:BcfPerspectiveCamera|null + lines:BcfLine[]|null + clipping_planes:BcfClippingPlane[]|null + bitmaps:BcfBitmap[]|null + snapshot:{ snapshot_type:string } +} + +export interface BcfViewpointVisibility { + visibility:{ + default_visibility:boolean + exceptions:BcfComponent[] + view_setup_hints:BcfViewSetupHints|null + } +} + +export interface BcfViewpointSelection { + selection:BcfComponent[] +} + +export interface BcfComponent { + ifc_guid:string|null + originating_system:string|null + authoring_tool_id:string|null +} + +export interface BcfViewSetupHints { + spaces_visible:boolean + space_boundaries_visible:boolean + openings_visible:boolean +} + +export interface BcfOrthogonalCamera { + camera_view_point:{ x:number, y:number, z:number } + camera_direction:{ x:number, y:number, z:number } + camera_up_vector:{ x:number, y:number, z:number } + view_to_world_scale:number +} + +export interface BcfPerspectiveCamera { + camera_view_point:{ x:number, y:number, z:number } + camera_direction:{ x:number, y:number, z:number } + camera_up_vector:{ x:number, y:number, z:number } + field_of_view:number +} + +export interface BcfBitmap { + guid:string + bitmap_type:string + location:{ x:number, y:number, z:number } + normal:{ x:number, y:number, z:number } + up:{ x:number, y:number, z:number } + height:number +} + +export interface BcfClippingPlane { + location:{ x:number, y:number, z:number } + direction:{ x:number, y:number, z:number } +} + +export interface BcfLine { + start_point:{ x:number, y:number, z:number } + end_point:{ x:number, y:number, z:number } +} diff --git a/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.paths.ts b/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.paths.ts index 2cc1b01ce6..6429c9980f 100644 --- a/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.paths.ts +++ b/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.paths.ts @@ -1,9 +1,38 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { BcfResourceCollectionPath, BcfResourcePath } from 'core-app/features/bim/bcf/api/bcf-path-resources'; import { BcfTopicResource } from 'core-app/features/bim/bcf/api/topics/bcf-topic.resource'; import { BcfApiRequestService } from 'core-app/features/bim/bcf/api/bcf-api-request.service'; import { BcfViewpointPaths } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.paths'; import { BcfViewpointCollectionPath } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint-collection.paths'; import { HTTPClientHeaders, HTTPClientParamMap } from 'core-app/features/hal/http/http.interfaces'; +import { Observable } from 'rxjs'; export class BcfTopicPaths extends BcfResourcePath { readonly bcfTopicService = new BcfApiRequestService(this.injector, BcfTopicResource); @@ -14,7 +43,7 @@ export class BcfTopicPaths extends BcfResourcePath { /** /viewpoints */ public readonly viewpoints = new BcfViewpointCollectionPath(this.injector, this.path, 'viewpoints', BcfViewpointPaths); - get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}) { + get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}):Observable { return this.bcfTopicService.get(this.toPath(), params, headers); } } diff --git a/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.resource.ts b/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.resource.ts index 5234ddf2d8..543f125d3a 100644 --- a/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.resource.ts +++ b/frontend/src/app/features/bim/bcf/api/topics/bcf-topic.resource.ts @@ -1,3 +1,31 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { jsonArrayMember, jsonMember, jsonObject } from 'typedjson'; import * as moment from 'moment'; import { Moment } from 'moment'; diff --git a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-collection.paths.ts b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-collection.paths.ts index 21608e48f5..26564ad770 100644 --- a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-collection.paths.ts +++ b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-collection.paths.ts @@ -1,20 +1,43 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { BcfResourceCollectionPath } from 'core-app/features/bim/bcf/api/bcf-path-resources'; import { BcfApiRequestService } from 'core-app/features/bim/bcf/api/bcf-api-request.service'; -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; -import { HTTPClientHeaders, HTTPClientParamMap } from 'core-app/features/hal/http/http.interfaces'; import { Observable } from 'rxjs'; import { BcfViewpointPaths } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.paths'; +import { CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model'; export class BcfViewpointCollectionPath extends BcfResourceCollectionPath { - readonly bcfTopicService = new BcfApiRequestService(this.injector); - - get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}) { - throw new Error('Not implemented'); - } + readonly bcfViewpointService = new BcfApiRequestService(this.injector); - post(viewpoint:BcfViewpointInterface):Observable { + post(viewpoint:CreateBcfViewpointData):Observable { return this - .bcfTopicService + .bcfViewpointService .request( 'post', this.toPath(), diff --git a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-item.interface.ts b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-item.interface.ts index 77caec6151..aa0745875b 100644 --- a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-item.interface.ts +++ b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-item.interface.ts @@ -1,4 +1,32 @@ -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + +import { CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model'; export interface BcfViewpointItem { /** The URL of the viewpoint, if persisted */ @@ -6,5 +34,5 @@ export interface BcfViewpointItem { /** URL (persisted or data) to the snapshot */ snapshotURL:string; /** The loaded snapshot, if exists */ - viewpoint?:BcfViewpointInterface; + viewpoint?:CreateBcfViewpointData; } diff --git a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-selection.paths.ts b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-selection.paths.ts new file mode 100644 index 0000000000..50784980d5 --- /dev/null +++ b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-selection.paths.ts @@ -0,0 +1,41 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + +import { BcfResourcePath } from 'core-app/features/bim/bcf/api/bcf-path-resources'; +import { BcfApiRequestService } from 'core-app/features/bim/bcf/api/bcf-api-request.service'; +import { HTTPClientHeaders, HTTPClientParamMap } from 'core-app/features/hal/http/http.interfaces'; +import { Observable } from 'rxjs'; +import { BcfViewpointSelection } from 'core-app/features/bim/bcf/api/bcf-api.model'; + +export class BcfViewpointSelectionPath extends BcfResourcePath { + readonly bcfViewpointsService = new BcfApiRequestService(this.injector); + + get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}):Observable { + return this.bcfViewpointsService.get(this.toPath(), params, headers); + } +} diff --git a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-visibility.paths.ts b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-visibility.paths.ts new file mode 100644 index 0000000000..7101db9dce --- /dev/null +++ b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint-visibility.paths.ts @@ -0,0 +1,41 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + +import { BcfResourcePath } from 'core-app/features/bim/bcf/api/bcf-path-resources'; +import { BcfApiRequestService } from 'core-app/features/bim/bcf/api/bcf-api-request.service'; +import { HTTPClientHeaders, HTTPClientParamMap } from 'core-app/features/hal/http/http.interfaces'; +import { Observable } from 'rxjs'; +import { BcfViewpointVisibility } from 'core-app/features/bim/bcf/api/bcf-api.model'; + +export class BcfViewpointVisibilityPaths extends BcfResourcePath { + readonly bcfViewpointsService = new BcfApiRequestService(this.injector); + + get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}):Observable { + return this.bcfViewpointsService.get(this.toPath(), params, headers); + } +} diff --git a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts deleted file mode 100644 index 44434d118d..0000000000 --- a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** Viewpoints use an interface to avoid (de)serialization of data we don't need */ -export interface BcfViewpointInterface { - guid:string; - components:unknown; - bitmaps:unknown[]; - snapshot:{ snapshot_type:string, snapshot_data:string }; - orthogonal_camera?:unknown; - perspective_camera?:unknown; - clipping_planes?:unknown[]; - lines?:unknown[]; -} diff --git a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts index 3245fcc895..a7e496b3e5 100644 --- a/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts +++ b/frontend/src/app/features/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts @@ -1,16 +1,58 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { HTTPClientHeaders, HTTPClientParamMap } from 'core-app/features/hal/http/http.interfaces'; import { BcfResourcePath } from 'core-app/features/bim/bcf/api/bcf-path-resources'; import { BcfApiRequestService } from 'core-app/features/bim/bcf/api/bcf-api-request.service'; -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; +import { BcfViewpointSelectionPath } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint-selection.paths'; +import { Observable } from 'rxjs'; +import { BcfViewpointVisibilityPaths } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint-visibility.paths'; +import { BcfViewpoint } from 'core-app/features/bim/bcf/api/bcf-api.model'; +import { map } from 'rxjs/operators'; export class BcfViewpointPaths extends BcfResourcePath { - readonly bcfTopicService = new BcfApiRequestService(this.injector); + readonly bcfViewpointsService = new BcfApiRequestService(this.injector); + + public readonly selection = new BcfViewpointSelectionPath(this.injector, this.path, 'selection'); + + public readonly visibility = new BcfViewpointVisibilityPaths(this.injector, this.path, 'visibility'); - get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}) { - return this.bcfTopicService.get(this.toPath(), params, headers); + get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}):Observable { + return this.bcfViewpointsService.get(this.toPath(), params, headers); } - delete(headers:HTTPClientHeaders = {}) { - return this.bcfTopicService.request('delete', this.toPath(), {}, headers); + delete(headers:HTTPClientHeaders = {}):Observable { + return this.bcfViewpointsService + .request('delete', this.toPath(), {}, headers) + .pipe( + map(() => { + // no expected response payload after delete + }), + ); } } diff --git a/frontend/src/app/features/bim/bcf/bcf-viewer-bridge/viewer-bridge.service.ts b/frontend/src/app/features/bim/bcf/bcf-viewer-bridge/viewer-bridge.service.ts index 4e802cf4ee..7d1974d11e 100644 --- a/frontend/src/app/features/bim/bcf/bcf-viewer-bridge/viewer-bridge.service.ts +++ b/frontend/src/app/features/bim/bcf/bcf-viewer-bridge/viewer-bridge.service.ts @@ -1,9 +1,9 @@ import { Injectable, Injector } from '@angular/core'; -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; import { Observable } from 'rxjs'; import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource'; import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator'; import { StateService } from '@uirouter/core'; +import { CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model'; @Injectable() export abstract class ViewerBridgeService { @@ -28,7 +28,7 @@ export abstract class ViewerBridgeService { /** * Get a viewpoint from the viewer */ - abstract getViewpoint$():Observable; + abstract getViewpoint$():Observable; /** * Show the given viewpoint JSON in the viewer diff --git a/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts b/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts index c16d29bba4..2d2d4c02b3 100644 --- a/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts +++ b/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts @@ -1,9 +1,36 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + +import { AfterViewInit, ChangeDetectionStrategy, Component } from '@angular/core'; import { BcfWpAttributeGroupComponent } from 'core-app/features/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component'; import { switchMap, take } from 'rxjs/operators'; import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource'; import { forkJoin } from 'rxjs'; -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; import { BcfViewpointItem } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint-item.interface'; import isNewResource from 'core-app/features/hal/helpers/is-new-resource'; @@ -12,7 +39,7 @@ import isNewResource from 'core-app/features/hal/helpers/is-new-resource'; styleUrls: ['./bcf-wp-attribute-group.component.sass'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class BcfNewWpAttributeGroupComponent extends BcfWpAttributeGroupComponent { +export class BcfNewWpAttributeGroupComponent extends BcfWpAttributeGroupComponent implements AfterViewInit { galleryViewpoints:BcfViewpointItem[] = []; ngAfterViewInit():void { @@ -46,23 +73,24 @@ export class BcfNewWpAttributeGroupComponent extends BcfWpAttributeGroupComponen return forkJoin(observables); }), ) - .subscribe((viewpoints:BcfViewpointInterface[]) => { + .subscribe(() => { this.showIndex = this.galleryViewpoints.length - 1; }); } // Disable show viewpoint functionality - showViewpoint(workPackage:WorkPackageResource, index:number) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + showViewpoint(workPackage:WorkPackageResource, index:number):void { } - deleteViewpoint(workPackage:WorkPackageResource, index:number) { + deleteViewpoint(workPackage:WorkPackageResource, index:number):void { this.galleryViewpoints = this.galleryViewpoints.filter((_, i) => i !== index); this.setViewpointsOnGallery(this.galleryViewpoints); } - saveViewpoint() { + saveViewpoint():void { this.viewerBridge .getViewpoint$() .subscribe((viewpoint) => { @@ -84,11 +112,11 @@ export class BcfNewWpAttributeGroupComponent extends BcfWpAttributeGroupComponen }); } - shouldShowGroup() { + shouldShowGroup():boolean { return this.createAllowed && this.viewerVisible; } - protected actions() { + protected actions():{ icon:string, onClick:(evt:any, index:number) => void, titleText:string }[] { // Show only delete button return super .actions() diff --git a/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts b/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts index 2ca003ba1c..63b4d0581a 100644 --- a/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts +++ b/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts @@ -188,7 +188,7 @@ export class BcfWpAttributeGroupComponent extends UntilDestroyedMixin implements this.viewpointsService .deleteViewPoint$(workPackage, index) - .subscribe((data) => { + .subscribe(() => { this.notifications.addSuccess(this.text.notice_successful_delete); this.gallery.preview.close(); }); diff --git a/frontend/src/app/features/bim/bcf/helper/viewpoints.service.ts b/frontend/src/app/features/bim/bcf/helper/viewpoints.service.ts index ffa9ce1605..793bd1d86c 100644 --- a/frontend/src/app/features/bim/bcf/helper/viewpoints.service.ts +++ b/frontend/src/app/features/bim/bcf/helper/viewpoints.service.ts @@ -1,3 +1,31 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { Injectable, Injector } from '@angular/core'; import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator'; import { BcfApiService } from 'core-app/features/bim/bcf/api/bcf-api.service'; @@ -6,10 +34,10 @@ import { BcfViewpointPaths } from 'core-app/features/bim/bcf/api/viewpoints/bcf- import { ViewerBridgeService } from 'core-app/features/bim/bcf/bcf-viewer-bridge/viewer-bridge.service'; import { map, switchMap, tap } from 'rxjs/operators'; import { forkJoin, Observable, of } from 'rxjs'; -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; import { BcfTopicResource } from 'core-app/features/bim/bcf/api/topics/bcf-topic.resource'; import { APIV3Service } from 'core-app/core/apiv3/api-v3.service'; import idFromLink from 'core-app/features/hal/helpers/id-from-link'; +import { BcfViewpointData, CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model'; @Injectable() export class ViewpointsService { @@ -21,21 +49,36 @@ export class ViewpointsService { @InjectField() apiV3Service:APIV3Service; - constructor(readonly injector:Injector) {} + constructor(readonly injector:Injector) { + } public getViewPointResource(workPackage:WorkPackageResource, index:number):BcfViewpointPaths { - const viewpointHref = workPackage.bcfViewpoints[index].href; + const viewpointHref = workPackage.bcfViewpoints[index].href as string; return this.bcfApi.parse(viewpointHref); } - public getViewPoint$(workPackage:WorkPackageResource, index:number):Observable { + public getViewPoint$(workPackage:WorkPackageResource, index:number):Observable { const viewpointResource = this.getViewPointResource(workPackage, index); - return viewpointResource.get(); + return forkJoin({ + viewpoint: viewpointResource.get(), + selection: viewpointResource.selection.get(), + visibility: viewpointResource.visibility.get(), + }) + .pipe( + map(({ viewpoint, selection, visibility }) => { + const data = viewpoint as BcfViewpointData; + data.components = { + selection: selection.selection, + visibility: visibility.visibility, + }; + return data; + }), + ); } - public deleteViewPoint$(workPackage:WorkPackageResource, index:number):Observable { + public deleteViewPoint$(workPackage:WorkPackageResource, index:number):Observable { const viewpointResource = this.getViewPointResource(workPackage, index); return viewpointResource @@ -46,7 +89,7 @@ export class ViewpointsService { ); } - public saveViewpoint$(workPackage:WorkPackageResource, viewpoint?:BcfViewpointInterface):Observable { + public saveViewpoint$(workPackage:WorkPackageResource, viewpoint?:CreateBcfViewpointData):Observable { const wpProjectId = idFromLink(workPackage.project.href); const topicUUID$ = this.setBcfTopic$(workPackage); // Default to the current viewer's viewpoint @@ -65,11 +108,11 @@ export class ViewpointsService { .viewpoints .post(results.viewpoint)), // Update the work package to reload the viewpoints - tap((results) => this.apiV3Service.work_packages.id(workPackage).requireAndStream(true)), + tap(() => this.apiV3Service.work_packages.id(workPackage).requireAndStream(true)), ); } - public setBcfTopic$(workPackage:WorkPackageResource) { + public setBcfTopic$(workPackage:WorkPackageResource):Observable { if (this.topicUUID) { return of(this.topicUUID); } @@ -78,7 +121,12 @@ export class ViewpointsService { ? of(this.bcfApi.parse(topicHref)!.id) : this.createBcfTopic$(workPackage); - return topicUUID$.pipe(map((topicUUID) => this.topicUUID = topicUUID)); + return topicUUID$.pipe( + map((topicUUID) => { + this.topicUUID = topicUUID; + return this.topicUUID; + }), + ); } private createBcfTopic$(workPackage:WorkPackageResource):Observable { diff --git a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts index ad562e1cce..8f229d9ce5 100644 --- a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts +++ b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts @@ -1,6 +1,33 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { Injectable, Injector } from '@angular/core'; import { XeokitServer } from 'core-app/features/bim/ifc_models/xeokit/xeokit-server'; -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; import { ViewerBridgeService } from 'core-app/features/bim/bcf/bcf-viewer-bridge/viewer-bridge.service'; import { BehaviorSubject, Observable, of } from 'rxjs'; import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource'; @@ -11,6 +38,9 @@ import { ViewpointsService } from 'core-app/features/bim/bcf/helper/viewpoints.s import { CurrentProjectService } from 'core-app/core/current-project/current-project.service'; import { HttpClient } from '@angular/common/http'; import idFromLink from 'core-app/features/hal/helpers/id-from-link'; +import { IfcProjectDefinition } from 'core-app/features/bim/ifc_models/pages/viewer/ifc-models-data.service'; +import { BIMViewer } from '@xeokit/xeokit-bim-viewer/dist/xeokit-bim-viewer.es'; +import { BcfViewpointData, CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model'; export interface XeokitElements { canvasElement:HTMLElement; @@ -46,6 +76,24 @@ export interface BCFLoadOptions { reverseClippingPlanes?:boolean; } +/** + * Wrapping type from xeokit module. Can be removed after we get a real type package. + */ +type Controller = { + on:(event:string, callback:(event:unknown) => void) => string +}; + +/** + * Wrapping type from xeokit module. Can be removed after we get a real type package. + */ +type BimViewer = Controller&{ + loadProject:(projectId:string) => void, + saveBCFViewpoint:(options:BCFCreationOptions) => CreateBcfViewpointData, + loadBCFViewpoint:(bcfViewpoint:BcfViewpointData, options:BCFLoadOptions) => void, + setKeyboardEnabled:(enabled:boolean) => true, + destroy:() => void +}; + @Injectable() export class IFCViewerService extends ViewerBridgeService { public shouldShowViewer = true; @@ -54,7 +102,7 @@ export class IFCViewerService extends ViewerBridgeService { public inspectorVisible$ = new BehaviorSubject(false); - private _viewer:any; + private bimViewer:BimViewer|undefined; @InjectField() pathHelper:PathHelperService; @@ -70,60 +118,59 @@ export class IFCViewerService extends ViewerBridgeService { super(injector); } - public newViewer(elements:XeokitElements, projects:any[]):void { - 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); - - viewerUI.on('queryPicked', (event:any) => { - alert(`IFC Name = "${event.objectName}"\nIFC class = "${event.objectType}"\nIFC GUID = ${event.objectId}`); - }); - - viewerUI.on('modelLoaded', () => this.viewerVisible$.next(true)); - - viewerUI.loadProject(projects[0].id); - - viewerUI.on('addModel', (event:Event) => { // "Add" selected in Models tab's context menu - window.location.href = this.pathHelper.ifcModelsNewPath(this.currentProjectService.identifier as string); - }); - - viewerUI.on('openInspector', () => { - this.inspectorVisible$.next(true); - }); - - 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); - }); - - 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, - ); - formData.append( - '_method', - 'delete', - ); - - this.httpClient.post( - 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(); - }); - }); - - this.viewer = viewerUI; + public newViewer(elements:XeokitElements, projects:IfcProjectDefinition[]):void { + const server = new XeokitServer(this.pathHelper); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + const viewerUI = new BIMViewer(server, elements) as BimViewer; + + viewerUI.on('queryPicked', (event:{ objectName:string, objectType:string, objectId:string }) => { + alert(`IFC Name = "${event.objectName}"\nIFC class = "${event.objectType}"\nIFC GUID = ${event.objectId}`); + }); + + viewerUI.on('modelLoaded', () => this.viewerVisible$.next(true)); + + viewerUI.loadProject(projects[0].id); + + viewerUI.on('addModel', () => { // "Add" selected in Models tab's context menu + window.location.href = this.pathHelper.ifcModelsNewPath(this.currentProjectService.identifier as string); + }); + + viewerUI.on('openInspector', () => { + this.inspectorVisible$.next(true); }); + + 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); + }); + + 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, + ); + formData.append( + '_method', + 'delete', + ); + + this.httpClient.post( + 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(); + }); + }); + + this.viewer = viewerUI; } public destroy():void { @@ -137,24 +184,28 @@ export class IFCViewerService extends ViewerBridgeService { this.viewer = undefined; } - public get viewer():any { - return this._viewer; + public get viewer():BimViewer|undefined { + return this.bimViewer; } - public set viewer(viewer:any) { - this._viewer = viewer; + public set viewer(viewer:BimViewer|undefined) { + this.bimViewer = viewer; } public setKeyboardEnabled(val:boolean):void { - this.viewer.setKeyboardEnabled(val); + this.viewer?.setKeyboardEnabled(val); } - public getViewpoint$():Observable { + public getViewpoint$():Observable { + if (!this.viewer) { + return of(); + } + const opts:BCFCreationOptions = { spacesVisible: true, reverseClippingPlanes: true }; const viewpoint = this.viewer.saveBCFViewpoint(opts); // The backend rejects viewpoints with bitmaps - delete viewpoint.bitmaps; + viewpoint.bitmaps = null; return of(viewpoint); } @@ -167,15 +218,20 @@ export class IFCViewerService extends ViewerBridgeService { const opts:BCFLoadOptions = { updateCompositeObjects: true, reverseClippingPlanes: true }; this.viewpointsService .getViewPoint$(workPackage, index) - .subscribe(viewpoint => this.viewer.loadBCFViewpoint(viewpoint, opts)); + .subscribe((viewpoint) => this.viewer?.loadBCFViewpoint(viewpoint, opts)); } } else { + if (!workPackage.id) { + return; + } + // Reload the whole app to get the correct menus and GON data // and redirect to a route with a place to show viewer // ('bim.partitioned.split') window.location.href = this.pathHelper.bimDetailsPath( + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access idFromLink(workPackage.project.href), - workPackage.id!, + workPackage.id, index, ); } diff --git a/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.ts b/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.ts index e7435aea97..9504d4831c 100644 --- a/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.ts +++ b/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.ts @@ -18,7 +18,7 @@ export interface IFCGonDefinition { export interface IfcProjectDefinition { name:string; - id:number; + id:string; } export interface IfcModelDefinition { diff --git a/frontend/src/app/features/bim/revit_add_in/revit-bridge.service.ts b/frontend/src/app/features/bim/revit_add_in/revit-bridge.service.ts index 4d540dda53..7bbd0c428a 100644 --- a/frontend/src/app/features/bim/revit_add_in/revit-bridge.service.ts +++ b/frontend/src/app/features/bim/revit_add_in/revit-bridge.service.ts @@ -1,13 +1,41 @@ +// -- copyright +// OpenProject is an open source project management software. +// Copyright (C) 2012-2021 the OpenProject GmbH +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See COPYRIGHT and LICENSE files for more details. +//++ + import { Injectable, Injector } from '@angular/core'; import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { distinctUntilChanged, filter, first, map, } from 'rxjs/operators'; -import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface'; import { ViewerBridgeService } from 'core-app/features/bim/bcf/bcf-viewer-bridge/viewer-bridge.service'; import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource'; import { ViewpointsService } from 'core-app/features/bim/bcf/helper/viewpoints.service'; import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator'; +import { BcfViewpointData, CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model'; declare global { interface Window { @@ -45,7 +73,7 @@ export class RevitBridgeService extends ViewerBridgeService { return this.viewerVisible$.getValue(); } - public getViewpoint$():Observable { + public getViewpoint$():Observable { const trackingId = this.newTrackingId(); this.sendMessageToRevit('ViewpointGenerationRequest', trackingId, ''); @@ -73,11 +101,11 @@ export class RevitBridgeService extends ViewerBridgeService { public showViewpoint(workPackage:WorkPackageResource, index:number) { this.viewpointsService .getViewPoint$(workPackage, index) - .subscribe((viewpoint:BcfViewpointInterface) => + .subscribe((viewpoint:BcfViewpointData) => this.sendMessageToRevit( 'ShowViewpoint', this.newTrackingId(), - JSON.stringify(viewpoint) + JSON.stringify(viewpoint), ) ); } diff --git a/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb b/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb index 9da81b6b30..9020fcd17e 100644 --- a/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb +++ b/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb @@ -36,7 +36,8 @@ module Bim::Bcf::API::V2_1 get do @issue .viewpoints - .pluck(:json_viewpoint) + .select(::Bim::Bcf::API::V2_1::Viewpoints::FullRepresenter.selector) + .map(&:json_viewpoint) end post &::Bim::Bcf::API::V2_1::Endpoints::Create @@ -54,18 +55,16 @@ module Bim::Bcf::API::V2_1 namespace = key == :/ ? :Full : key.to_s.camelize get key, &::Bim::Bcf::API::V2_1::Endpoints::Show - .new(model: Bim::Bcf::Viewpoint, - api_name: 'Viewpoints', - render_representer: "::Bim::Bcf::API::V2_1::Viewpoints::#{namespace}Representer".constantize, - instance_generator: ->(*) { @issue.viewpoints.where(uuid: params[:viewpoint_uuid]) }) - .mount + .new(model: Bim::Bcf::Viewpoint, + render_representer: "::Bim::Bcf::API::V2_1::Viewpoints::#{namespace}Representer".constantize, + instance_generator: ->(*) { @issue.viewpoints.where(uuid: params[:viewpoint_uuid]) }) + .mount end delete &::Bim::Bcf::API::V2_1::Endpoints::Delete - .new(model: Bim::Bcf::Viewpoint, - api_name: 'Viewpoints', - instance_generator: ->(*) { @issue.viewpoints.find_by!(uuid: params[:viewpoint_uuid]) }) - .mount + .new(model: Bim::Bcf::Viewpoint, + instance_generator: ->(*) { @issue.viewpoints.find_by!(uuid: params[:viewpoint_uuid]) }) + .mount get :bitmaps do raise NotImplementedError, 'Bitmaps are not yet implemented.' diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb index 2b755c3d47..0c29507f7a 100644 --- a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb +++ b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb @@ -1,5 +1,3 @@ -#-- encoding: UTF-8 - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,12 +28,6 @@ module Bim::Bcf::API::V2_1 class Viewpoints::BaseRepresenter < BaseRepresenter - attr_reader :base_scope - - def initialize(base_scope) - @base_scope = base_scope - end - def to_json(*_args) row = scope.first raise ::ActiveRecord::RecordNotFound unless row diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/coloring_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/coloring_representer.rb index 043a0404b1..129cf626de 100644 --- a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/coloring_representer.rb +++ b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/coloring_representer.rb @@ -1,5 +1,3 @@ -#-- encoding: UTF-8 - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,7 +33,7 @@ module Bim::Bcf::API::V2_1::Viewpoints protected def scope - base_scope + represented .select "jsonb_build_object('coloring', json_viewpoint #> '{components, coloring}') as json_viewpoint" end end diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/full_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/full_representer.rb index 01c21a65a0..4756f2c743 100644 --- a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/full_representer.rb +++ b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/full_representer.rb @@ -1,5 +1,3 @@ -#-- encoding: UTF-8 - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -31,10 +29,15 @@ require_relative 'base_representer' module Bim::Bcf::API::V2_1::Viewpoints class FullRepresenter < BaseRepresenter + + def self.selector + "json_viewpoint - 'components' as json_viewpoint" + end + protected def scope - base_scope.select(:json_viewpoint) + represented.select(self.class.selector) end end end diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/selection_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/selection_representer.rb index 55a052a510..5ee644a0a3 100644 --- a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/selection_representer.rb +++ b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/selection_representer.rb @@ -1,5 +1,3 @@ -#-- encoding: UTF-8 - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,7 +33,7 @@ module Bim::Bcf::API::V2_1::Viewpoints protected def scope - base_scope + represented .select "jsonb_build_object('selection', json_viewpoint #> '{components, selection}') as json_viewpoint" end end diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/single_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/single_representer.rb index 2256cd1d35..ac90e6ca44 100644 --- a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/single_representer.rb +++ b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/single_representer.rb @@ -1,5 +1,3 @@ -#-- encoding: UTF-8 - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/visibility_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/visibility_representer.rb index 8f7c6272cc..e228565009 100644 --- a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/visibility_representer.rb +++ b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/visibility_representer.rb @@ -1,5 +1,3 @@ -#-- encoding: UTF-8 - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,7 +33,7 @@ module Bim::Bcf::API::V2_1::Viewpoints protected def scope - base_scope + represented .select "jsonb_build_object('visibility', json_viewpoint #> '{components, visibility}') as json_viewpoint" end end