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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
(Not) Integration of XeokitSDK and Viewer
Wieland Lindenthal4e189a705527
diff --git a/frontend/package.json b/frontend/package.jsonindex 86e5c59bb5c..fecdcb229d0 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -89,6 +89,8 @@"glob": "^7.1.4","hammerjs": "^2.0.8","happypack": "^5.0.1",+ "inspire-tree": "^5.0.1",+ "inspire-tree-dom": "^4.0.4","jquery": "^3.4.1","jquery-ui": "git+https://github.com/jquery/jquery-ui.git#74f8a0ac952f6f45f773312292baef1c26d81300","jquery-ujs": "^1.2.2",diff --git a/frontend/src/app/angular4-modules.ts b/frontend/src/app/angular4-modules.tsindex eee0aa80c4f..e9b8f739e9c 100644--- a/frontend/src/app/angular4-modules.ts+++ b/frontend/src/app/angular4-modules.ts@@ -94,6 +94,7 @@ import {PreviewTriggerService} from "core-app/globals/global-listeners/preview-timport {OpenprojectOverviewModule} from "core-app/modules/overview/openproject-overview.module";import {OpenprojectMyPageModule} from "core-app/modules/my-page/openproject-my-page.module";import {OpenprojectProjectsModule} from "core-app/modules/projects/openproject-projects.module";+import {OpenprojectIFCModelsModule} from "core-app/modules/ifc_models/openproject-ifc-models.module";@NgModule({imports: [@@ -141,6 +142,9 @@ import {OpenprojectProjectsModule} from "core-app/modules/projects/openproject-p// Global SearchOpenprojectGlobalSearchModule,+ // IFC Models+ OpenprojectIFCModelsModule,+// Admin moduleOpenprojectAdminModule,diff --git a/frontend/src/app/modules/ifc_models/ifc-viewer-entry.component.ts b/frontend/src/app/modules/ifc_models/ifc-viewer-entry.component.tsnew file mode 100644index 00000000000..a51c0c30c79--- /dev/null+++ b/frontend/src/app/modules/ifc_models/ifc-viewer-entry.component.ts@@ -0,0 +1,28 @@+import {Component, ElementRef, Input, OnInit} from '@angular/core';+import {DynamicBootstrapper} from "core-app/globals/dynamic-bootstrapper";++@Component({+ selector: 'ifc-viewer-entry',+ template: `+ <ifc-viewer [ifcModelId]="ifcModelId"+ [xktFileUrl]="xktFileUrl"+ [metadataFileUrl]="metadataFileUrl"></ifc-viewer>+ `+})+export class IFCViewerEntryComponent implements OnInit {+ constructor(readonly elementRef:ElementRef) {+ }++ public ifcModelId:string;+ public xktFileUrl:string;+ public metadataFileUrl:string;++ ngOnInit() {+ const element = this.elementRef.nativeElement;+ this.ifcModelId = element.dataset.ifcModelId;+ this.xktFileUrl = element.dataset.xktFileUrl;+ this.metadataFileUrl = element.dataset.metadataFileUrl;+ }+}++DynamicBootstrapper.register({ selector: 'ifc-viewer-entry', cls: IFCViewerEntryComponent });diff --git a/frontend/src/app/modules/ifc_models/ifc-viewer.component.ts b/frontend/src/app/modules/ifc_models/ifc-viewer.component.tsnew file mode 100644index 00000000000..2f8b0dc8076--- /dev/null+++ b/frontend/src/app/modules/ifc_models/ifc-viewer.component.ts@@ -0,0 +1,59 @@+// -- copyright+// OpenProject is a project management system.+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)+//+// 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 doc/COPYRIGHT.rdoc for more details.+// ++++import {Component, Input, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core';+import {DynamicBootstrapper} from "app/globals/dynamic-bootstrapper";++@Component({+ selector: 'ifc-viewer',+ template: `+ <canvas [id]="'xeokit-model-canvas-' + ifcModelId" class="xeokit-model-canvas"></canvas>+ <div [id]="'xeokit-tree-panel-' + ifcModelId" class="treePanel" class="xeokit-tree-panel"></div>+`,+ styleUrls: [+ '../../../../node_modules/inspire-tree-dom/dist/inspire-tree-light.css'+ ],+ encapsulation: ViewEncapsulation.None+})+export class IFCViewerComponent implements OnInit, OnDestroy {+ @Input() public ifcModelId:string;+ @Input() public xktFileUrl:string;+ @Input() public metadataFileUrl:string;++ ngOnInit():void {+ import('./xeokit-viewer').then((XeokitViewerModule:any) => {+ let viewer = new XeokitViewerModule.XeokitViewer(this.ifcModelId, this.xktFileUrl, this.metadataFileUrl);+ });+ }++ ngOnDestroy():void {+ }+}+DynamicBootstrapper.register({+ selector: 'ifc-viewer', cls: IFCViewerComponent+});\ No newline at end of filediff --git a/frontend/src/app/modules/ifc_models/openproject-ifc-models.module.ts b/frontend/src/app/modules/ifc_models/openproject-ifc-models.module.tsnew file mode 100644index 00000000000..2ec2c33ef68--- /dev/null+++ b/frontend/src/app/modules/ifc_models/openproject-ifc-models.module.ts@@ -0,0 +1,51 @@+// -- copyright+// OpenProject is a project management system.+// Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+//+// 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 doc/COPYRIGHT.rdoc for more details.+// ++++import {NgModule} from "@angular/core";+import {IFCViewerComponent} from "core-app/modules/ifc_models/ifc-viewer.component";+import {IFCViewerEntryComponent} from "core-app/modules/ifc_models/ifc-viewer-entry.component";++@NgModule({+ providers: [+ ],+ declarations: [+ IFCViewerEntryComponent,+ IFCViewerComponent+ ],+ exports: [+ IFCViewerEntryComponent,+ IFCViewerComponent+ ],+ entryComponents: [+ IFCViewerEntryComponent,+ IFCViewerComponent+ ]+})+export class OpenprojectIFCModelsModule {+}+diff --git a/frontend/src/app/modules/ifc_models/xeokit-viewer.d.ts b/frontend/src/app/modules/ifc_models/xeokit-viewer.d.tsnew file mode 100644index 00000000000..324170fab26--- /dev/null+++ b/frontend/src/app/modules/ifc_models/xeokit-viewer.d.ts@@ -0,0 +1,2 @@+export default class XeokitViewer {+}\ No newline at end of filediff --git a/frontend/src/app/modules/ifc_models/xeokit-viewer.js b/frontend/src/app/modules/ifc_models/xeokit-viewer.jsnew file mode 100644index 00000000000..0c01a7337e8--- /dev/null+++ b/frontend/src/app/modules/ifc_models/xeokit-viewer.js@@ -0,0 +1,155 @@+//------------------------------------------------------------------------------------------------------------------+// Import the modules we need for this example+//------------------------------------------------------------------------------------------------------------------+import {Viewer} from "../../../../vendor/xeokit-sdk/src/viewer/Viewer.js";+import {XKTLoaderPlugin} from "../../../../vendor/xeokit-sdk/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js";+import InspireTree from "inspire-tree";+import InspireTreeDOM from "inspire-tree-dom";+// import {NavCubePlugin} from "../src/plugins/NavCubePlugin/NavCubePlugin.js";+//------------------------------------------------------------------------------------------------------------------+// Create a Viewer, arrange the camera, tweak xraying and highlight materials+//------------------------------------------------------------------------------------------------------------------++export class XeokitViewer {+ constructor(ifcModelId, xktFileUrl, metadataFileUrl) {+ const viewer = new Viewer({+ canvasId: 'xeokit-model-canvas-' + ifcModelId,+ transparent: true+ });+ const cameraControl = viewer.cameraControl;+ const scene = viewer.scene;+ const cameraFlight = viewer.cameraFlight;+ cameraControl.panToPointer = true;+ cameraControl.doublePickFlyTo = true;+ cameraFlight.duration = 1.0;+ cameraFlight.fitFOV = 25;+ viewer.camera.eye = [-2.56, 8.38, 8.27];+ viewer.camera.look = [13.44, 3.31, -14.83];+ viewer.camera.up = [0.10, 0.98, -0.14];+ viewer.scene.xrayMaterial.fillAlpha = 0.1;+ viewer.scene.xrayMaterial.fillColor = [0, 0, 0];+ viewer.scene.xrayMaterial.edgeAlpha = 0.4;+ viewer.scene.xrayMaterial.edgeColor = [0, 0, 0];+ viewer.scene.highlightMaterial.fill = false;+ viewer.scene.highlightMaterial.fillAlpha = 0.3;+ viewer.scene.highlightMaterial.edgeColor = [1, 1, 0];++ const xktLoader = new XKTLoaderPlugin(viewer);+ const model = xktLoader.load({+ id: "xeokit-model-" + ifcModelId,+ src: xktFileUrl,+ metaModelSrc: metadataFileUrl,+ edges: true+ });+ //------------------------------------------------------------------------------------------------------------------+ // Mouse over entities to highlight them+ //------------------------------------------------------------------------------------------------------------------+ var lastEntity = null;+ viewer.scene.input.on("mousemove", function (coords) {+ var hit = viewer.scene.pick({+ canvasPos: coords+ });+ if (hit) {+ if (!lastEntity || hit.entity.id !== lastEntity.id) {+ if (lastEntity) {+ lastEntity.highlighted = false;+ }+ lastEntity = hit.entity;+ hit.entity.highlighted = true;+ }+ } else {+ if (lastEntity) {+ lastEntity.highlighted = false;+ lastEntity = null;+ }+ }+ });+ //------------------------------------------------------------------------------------------------------------------+ // When model loaded, create a tree view that toggles object xraying+ //------------------------------------------------------------------------------------------------------------------+ const t0 = performance.now();+ model.on("loaded", function () {+ const t1 = performance.now();+ // Builds tree view data from MetaModel+ var createData = function (metaModel) {+ const data = [];+ function visit(expand, data, metaObject) {+ if (!metaObject) {+ return;+ }+ var child = {+ id: metaObject.id,+ text: metaObject.name+ };+ data.push(child);+ const children = metaObject.children;+ if (children) {+ child.children = [];+ for (var i = 0, len = children.length; i < len; i++) {+ visit(true, child.children, children[i]);+ }+ }+ }+ visit(true, data, metaModel.rootMetaObject);+ return data;+ };+ // Get MetaModel we loaded for our model+ const modelId = model.id;+ const metaModel = viewer.metaScene.metaModels[modelId];+ // Create the tree view+ var treeView = new InspireTree({+ selection: {+ autoSelectChildren: true,+ autoDeselect: true,+ mode: 'checkbox'+ },+ checkbox: {+ autoCheckChildren: true+ },+ data: createData(metaModel)+ });+ new InspireTreeDOM(treeView, {+ target: document.getElementById("xeokit-tree-panel-12")+ });+ // Initialize the tree view once loaded+ treeView.on('model.loaded', function () {+ treeView.select();+ treeView.model.expand();+ treeView.model[0].children[0].expand();+ treeView.model[0].children[0].children[0].expand();+ treeView.on('node.selected', function (event, node) {+ const objectId = event.id;+ viewer.scene.setObjectsXRayed(objectId, false);+ viewer.scene.setObjectsPickable(objectId, true);+ });+ treeView.on('node.deselected', function (event, node) {+ const objectId = event.id;+ viewer.scene.setObjectsXRayed(objectId, true);+ viewer.scene.setObjectsPickable(objectId, false);+ });+ });+ });+ scene.input.on("mouseclicked", function (coords) {+ var hit = scene.pick({+ canvasPos: coords+ });+ if (hit) {+ var entity = hit.entity;+ var metaObject = viewer.metaScene.metaObjects[entity.id];+ if (metaObject) {+ console.log(JSON.stringify(metaObject.getJSON(), null, "\t"));+ } else {+ const parent = entity.parent;+ if (parent) {+ metaObject = viewer.metaScene.metaObjects[parent.id];+ if (metaObject) {+ console.log(JSON.stringify(metaObject.getJSON(), null, "\t"));+ }+ }+ }+ }+ });+ return viewer;+ }+}+diff --git a/modules/ifc_models/app/assets/stylesheets/ifc_models/ifc_models.sass b/modules/ifc_models/app/assets/stylesheets/ifc_models/ifc_models.sassnew file mode 100644index 00000000000..cf7d5e93e31--- /dev/null+++ b/modules/ifc_models/app/assets/stylesheets/ifc_models/ifc_models.sass@@ -0,0 +1,30 @@+.xeokit-tree-panel+ padding-top: 25px+ pointer-events: all+ height: 100%+ overflow-y: scroll+ position: absolute+ background-color: rgba(0, 0, 0, 0.1)+ color: black+ top: 0+ z-index: 200000+ float: left+ left: 0+ font-family: 'Roboto', sans-serif+ font-size: 15px+ user-select: none+ -ms-user-select: none+ -moz-user-select: none+ -webkit-user-select: none+ width: 350px++.xeokit-model-canvas+ width: 100%+ height: 100%++.ifc-model-viewer-container+ position: relative+ width: 100%+ height: 70vH+ border-top: 1px solid gray+ border-bottom: 1px solid gray\ No newline at end of filediff --git a/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb b/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rbindex f28a20f124f..1d6c3494c30 100644--- a/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb+++ b/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb@@ -30,6 +30,8 @@module ::IFCModelsclass IFCModelsController < BaseController+ include IFCModelsHelper+before_action :find_project_by_project_id, only: %i[index new create show edit update destroy]before_action :find_ifc_model_object, except: %i[index new create]@@ -49,6 +51,7 @@ module ::IFCModelsenddef edit; end+def show; enddef creatediff --git a/modules/ifc_models/app/helpers/ifc_models_helper.rb b/modules/ifc_models/app/helpers/ifc_models_helper.rbnew file mode 100644index 00000000000..33d80722eb9--- /dev/null+++ b/modules/ifc_models/app/helpers/ifc_models_helper.rb@@ -0,0 +1,9 @@+module IFCModelsHelper+ def attachment_content_url(attachment)+ if attachment.external_storage?+ attachment.external_url+ else+ API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(attachment.id)+ end+ end+end\ No newline at end of filediff --git a/modules/ifc_models/app/models/ifc_models/ifc_model.rb b/modules/ifc_models/app/models/ifc_models/ifc_model.rbindex 6e75886828b..2bcf02c8e0b 100644--- a/modules/ifc_models/app/models/ifc_models/ifc_model.rb+++ b/modules/ifc_models/app/models/ifc_models/ifc_model.rb@@ -1,6 +1,6 @@module IFCModelsclass IFCModel < ActiveRecord::Base- acts_as_attachable delete_permission: :manage_ifc_models+ acts_as_attachable delete_permission: :manage_ifc_models, view_permission: :view_ifc_modelsbelongs_to :projectbelongs_to :uploader, class_name: 'User', foreign_key: 'uploader_id'diff --git a/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erb b/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erbindex 984e6fde467..c8d29b391a5 100644--- a/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erb+++ b/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erb@@ -31,6 +31,12 @@ See doc/COPYRIGHT.rdoc for more details.++#%><% html_title h(@ifc_model.title) -%>++<% content_for :header_tags do %>+ <%= stylesheet_link_tag "ifc_models/ifc_models", media: 'all' %>+<% end %>++<%= toolbar title: @ifc_model.title do %><% if authorize_for('ifc_models/ifc_models', :edit) %><li class="toolbar-item">@@ -48,3 +54,9 @@ See doc/COPYRIGHT.rdoc for more details.<% end %><% end %>+<div class="ifc-model-viewer-container">+ <ifc-viewer-entry data-ifc-model-id="<%= @ifc_model.id %>"+ data-xkt-file-url="<%= attachment_content_url(@ifc_model.xkt_attachment) %>"+ data-metadata-file-url="<%= attachment_content_url(@ifc_model.metadata_attachment) %>"></ifc-viewer-entry>+</div>+diff --git a/modules/ifc_models/lib/open_project/ifc_models/engine.rb b/modules/ifc_models/lib/open_project/ifc_models/engine.rbindex 852b61c3d18..6dcc69788e7 100644--- a/modules/ifc_models/lib/open_project/ifc_models/engine.rb+++ b/modules/ifc_models/lib/open_project/ifc_models/engine.rb@@ -52,6 +52,8 @@ module OpenProject::IFCModelsendend+ assets %w(ifc_models/ifc_models.css)+initializer 'ifc_models.menu' do::Redmine::MenuManager.map(:project_menu) do |menu|menu.push(:ifc_models,