From 91cc8a7453143c3cdf24a4aff57f4d759c83f154 Mon Sep 17 00:00:00 2001 From: "Philipp M. Fischer" Date: Thu, 10 Oct 2024 09:24:00 +0200 Subject: [PATCH 1/4] Fixed NPE in Update Handler - (Task #1209) - Workbench could not be set up from the eclipse framework, since the AWT Event Queue is not regarded as Display thread. Now getting the workbench synchronously in a display thread. --- Task #1209: Visualization crashes with NPE --- .../ui/vtkClient/VtkClientVisUpdateHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java index dd554240a3..597f9b4c85 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java +++ b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java @@ -14,6 +14,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.emf.ecore.EObject; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPart; @@ -93,8 +94,10 @@ public static synchronized VtkClientVisUpdateHandler getInstance() { if (instance == null) { instance = new VtkClientVisUpdateHandler(); IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow workbenchwindow = workbench.getActiveWorkbenchWindow(); - workbenchwindow.getPartService().addPartListener(instance); + Display.getDefault().syncExec(() -> { + IWorkbenchWindow workbenchwindow = workbench.getActiveWorkbenchWindow(); + workbenchwindow.getPartService().addPartListener(instance); + }); } return instance; } From de67a5e10baa781b2806a1bdd1b7ec10434f8784 Mon Sep 17 00:00:00 2001 From: "Philipp M. Fischer" Date: Thu, 10 Oct 2024 10:03:05 +0200 Subject: [PATCH 2/4] Fixing visualisation updates - (Task #1209) - Due to removing the visualization server, no updates were transmitted to the visualization. Code has been changed to directly send all changes on the model as if they were sent by the communication server as it was done in 4.16 --- Task #1209: Visualization crashes with NPE --- .../extension/visualisation/ui/Activator.java | 3 ++ .../vtkClient/VtkClientVisUpdateHandler.java | 6 ++-- .../visualisation/delta/DeltaShapeHelper.java | 2 -- .../visualisation/shape/ShapeHelper.java | 20 ----------- .../treemanager/IPausableSender.java | 24 -------------- .../treemanager/IVisUpdateHandler.java | 6 ++-- .../treemanager/TreeManager.java | 33 +++++++++++++------ 7 files changed, 32 insertions(+), 62 deletions(-) delete mode 100644 de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IPausableSender.java diff --git a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/Activator.java b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/Activator.java index 835b5ce368..c3c4c85c78 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/Activator.java +++ b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/Activator.java @@ -20,6 +20,7 @@ import org.osgi.framework.BundleContext; import de.dlr.sc.virsat.model.extension.visualisation.treemanager.StartManagers; +import de.dlr.sc.virsat.model.extension.visualisation.ui.vtkClient.VtkClientVisUpdateHandler; import de.dlr.sc.virsat.project.editingDomain.VirSatTransactionalEditingDomain; /** @@ -68,6 +69,8 @@ public void start(BundleContext context) throws Exception { pluginId = getDefault().getBundle().getSymbolicName(); // initialize the communication servers try { + + StartManagers.getTreeManager().setVisUpdateHandler(VtkClientVisUpdateHandler.getInstance()); resourceReloadListener = new ResourceReloadListener(); VirSatTransactionalEditingDomain.addResourceEventListener(resourceReloadListener); diff --git a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java index 597f9b4c85..3d1e959d10 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java +++ b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkClientVisUpdateHandler.java @@ -27,8 +27,8 @@ import de.dlr.sc.virsat.model.extension.visualisation.Activator; import de.dlr.sc.virsat.model.extension.visualisation.treemanager.IVisUpdateHandler; import de.dlr.sc.virsat.uiengine.ui.editor.GenericEditor; +import de.dlr.sc.visproto.VisProto.SceneGraph; import de.dlr.sc.visproto.VisProto.SceneGraphNode; -import de.dlr.sc.visproto.VisProto.VisualisationMessage; import vtk.vtkProp; /** @@ -53,12 +53,12 @@ private VtkClientVisUpdateHandler() { * * @param visualisationMessage */ - public synchronized void updateVisualisationData(VisualisationMessage visualisationMessage) { + public synchronized void updateVisualisationData(SceneGraph sceneGraph) { EventQueue.invokeLater(new Runnable() { @Override public void run() { - mNode = visualisationMessage.getSceneGraph().getNode(); + mNode = sceneGraph.getNode(); VtkTreeManager visMan = VtkTreeManager.getInstance(); visMan.clearInvalidActors(); visMan.forceSceneryUpdate(mNode); diff --git a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/delta/DeltaShapeHelper.java b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/delta/DeltaShapeHelper.java index 6435437674..1cd1b9c167 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/delta/DeltaShapeHelper.java +++ b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/delta/DeltaShapeHelper.java @@ -89,7 +89,6 @@ protected void setShapeParent(String parentShapeId, String shapeId) { public void traverseTreeAndCreateShapes(StructuralElementInstance rootSei) { super.traverseTreeAndCreateShapes(rootSei); - pauseVisTreeManagerUpdateSending(); for (GhostShapeDelta ghostShapeDelta : ghostShapeDeltas) { Shape ghostShape = ghostShapeDelta.shape; ghostShape.id += GHOST_SHAPE_SUFFIX; @@ -106,6 +105,5 @@ public void traverseTreeAndCreateShapes(StructuralElementInstance rootSei) { visualisationTreeManager.setParent(ghostShapeId, ghostShapeParentId); } } - resumeVisTreeManagerUpdateSending(); } } diff --git a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/shape/ShapeHelper.java b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/shape/ShapeHelper.java index 1c678c1429..73dd70388b 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/shape/ShapeHelper.java +++ b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/shape/ShapeHelper.java @@ -19,7 +19,6 @@ import de.dlr.sc.virsat.model.dvlm.structural.StructuralElementInstance; import de.dlr.sc.virsat.model.extension.visualisation.IVisualisationTreeManager; import de.dlr.sc.virsat.model.extension.visualisation.model.Visualisation; -import de.dlr.sc.virsat.model.extension.visualisation.treemanager.IPausableSender; /** * A class for extracting of shape data from a StructuralElementInstance, @@ -48,11 +47,9 @@ public ShapeHelper(IVisualisationTreeManager visualisationTreeManager, ShapeEdit * @param sei The SEI for which to create a shape. */ public void traverseTreeAndCreateShapes(StructuralElementInstance sei) { - pauseVisTreeManagerUpdateSending(); StructuralElementInstance visParent = getVisualisationParent(sei); String visParentId = visParent != null ? visParent.getUuid().toString() : null; traverseTreeAndCreateShapes(sei, visParentId); - resumeVisTreeManagerUpdateSending(); } /** @@ -258,24 +255,7 @@ protected Shape createShapeFromVisualisationBean(Visualisation visBean, String s return createShapeFromBean(visBean, shapeId); } - /** - * tries to pause update sending until all the scenegraph is created - */ - protected void pauseVisTreeManagerUpdateSending() { - if (visualisationTreeManager instanceof IPausableSender) { - ((IPausableSender) visualisationTreeManager).pauseSending(); - } - } - /** - * tries to resume update sending - */ - protected void resumeVisTreeManagerUpdateSending() { - if (visualisationTreeManager instanceof IPausableSender) { - ((IPausableSender) visualisationTreeManager).resumeSending(); - } - } - /** * Creates Shape from Vis Bean * @param visBean The bean from which to use the values diff --git a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IPausableSender.java b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IPausableSender.java deleted file mode 100644 index ac42a685dd..0000000000 --- a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IPausableSender.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2019 German Aerospace Center (DLR), Simulation and Software Technology, Germany. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package de.dlr.sc.virsat.model.extension.visualisation.treemanager; - -/** - * Interface for classes that can send updates on every change, but need to be paused sometimes for performance reasons - */ -public interface IPausableSender { - - /** - */ - void pauseSending(); - - /** - */ - void resumeSending(); -} diff --git a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IVisUpdateHandler.java b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IVisUpdateHandler.java index 740bba9a84..d6caa87ca4 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IVisUpdateHandler.java +++ b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/IVisUpdateHandler.java @@ -9,7 +9,7 @@ *******************************************************************************/ package de.dlr.sc.virsat.model.extension.visualisation.treemanager; -import de.dlr.sc.visproto.VisProto.VisualisationMessage; +import de.dlr.sc.visproto.VisProto.SceneGraph; /** * Calling VisualisationManager to refresh @@ -22,7 +22,7 @@ public interface IVisUpdateHandler { /** * Updates corresponding TreeManagern and Visualisation. * - * @param visualisationMessage contains the SceneGraph message with the updated SceneGraph + * @param sceneGraph contains the SceneGraph message with the updated SceneGraph */ - void updateVisualisationData(VisualisationMessage visualisationMessage); + void updateVisualisationData(SceneGraph sceneGraph); } diff --git a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/TreeManager.java b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/TreeManager.java index 5a74a98d76..3aa7ed033f 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/TreeManager.java +++ b/de.dlr.sc.virsat.model.extension.visualisation/src/de/dlr/sc/virsat/model/extension/visualisation/treemanager/TreeManager.java @@ -40,7 +40,7 @@ /** * This class is responsible for the management of the ProtoBuf-SceneGraph */ -public class TreeManager implements IVisualisationTreeManager, IPausableSender { +public class TreeManager implements IVisualisationTreeManager { //global root node created on initialisation which always exists public static final String VISUALISATION_GLOBAL_ROOT_ID = "0"; @@ -53,6 +53,7 @@ public class TreeManager implements IVisualisationTreeManager, IPausableSender { private Map hashNodeMap = new HashMap(); private IShapeEditObserver observer; + /** * Log root node */ @@ -131,6 +132,8 @@ public void editShape(Shape shape) { if (!protoNodeMap.get(shape.id).hasGeometry() && protoGeometryFileMap.containsKey(shape.id)) { protoGeometryFileMap.remove(shape.id); } + + sendSceneGraph(mSceneGraph.build()); } /** @@ -317,6 +320,8 @@ public void createShape(Shape shape) { shape.rotationX, shape.rotationY, shape.rotationZ, shape.color, shape.transparency); addChildNode(VISUALISATION_GLOBAL_ROOT_ID, shape.id); + + sendSceneGraph(mSceneGraph.build()); } else { activator.getLog().log(new Status(Status.ERROR, Activator.getPluginId(), "ID already exists", null)); throw new RuntimeException("Error at creating new shape. ID already exist"); @@ -470,6 +475,7 @@ private void refreshMapFrom(Builder nodeBuilder) { public void setParent(String idChild, String idParent) { removeFromCurrentParent(idChild); addChildNode(idParent, idChild); + sendSceneGraph(mSceneGraph.build()); } /** @@ -516,6 +522,7 @@ public void removeShape(String id) { addChildNode(mSceneGraph.getNodeBuilder(), child); } + sendSceneGraph(mSceneGraph.build()); } /** @@ -538,6 +545,7 @@ private Builder removeNodeFromMaps(String id) { public void removeShapeWithSubtree(String id) { removeFromCurrentParent(id); removeNodeRecursively(id); + sendSceneGraph(mSceneGraph.build()); } /** @@ -551,7 +559,6 @@ private void removeNodeRecursively(String id) { } } - /** * Checks if there is a registered node with the ide * @param id Id of the node @@ -607,6 +614,7 @@ public void update(VisualisationMessage visualisationMessage) { } protoNodeMap.clear(); this.refreshMapFrom(mSceneGraph.getNodeBuilder()); + sendSceneGraph(mSceneGraph.build()); } else { activator.getLog().log(new Status(Status.WARNING, Activator.getPluginId(), "Received SceneGraph is equal to the current one", null)); } @@ -683,16 +691,21 @@ private Shape convertProtobufNodeToShape(SceneGraphNodeOrBuilder node) { return shape; } - @Override - public void pauseSending() { - } - - @Override - public void resumeSending() { - } - @Override public void reloadGeometryFile(String shapeId) { createGeometryFileBuilder(shapeId); } + + private IVisUpdateHandler visUpdateHandler; + + public void setVisUpdateHandler(IVisUpdateHandler visUpdateHandler) { + this.visUpdateHandler = visUpdateHandler; + } + + public void sendSceneGraph(SceneGraph sceneGraph) { + if (visUpdateHandler != null) { + visUpdateHandler.updateVisualisationData(sceneGraph); + } + } + } From e96504f9f4b74884997755666df36dbd94f527f2 Mon Sep 17 00:00:00 2001 From: "Philipp M. Fischer" Date: Thu, 10 Oct 2024 10:47:34 +0200 Subject: [PATCH 3/4] Fixed NPE in Selection Box - (Task #1209) - Fixed NPE in VTK Visualization when selecting an object to display the bounding box to indicate which object is slected in the Virtual Satellite Navigator --- Task #1209: Visualization crashes with NPE --- .../extension/visualisation/ui/vtkClient/VtkTreeManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkTreeManager.java b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkTreeManager.java index 4cb9723a8a..ed55cecef6 100644 --- a/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkTreeManager.java +++ b/de.dlr.sc.virsat.model.extension.visualisation.ui/src/de/dlr/sc/virsat/model/extension/visualisation/ui/vtkClient/VtkTreeManager.java @@ -420,7 +420,7 @@ private void updateHighlightedObjectIfSelected(SceneGraphNode node, ActorVtk par ActorVtk actor = actorMap.get(node.getID()); if (selectedActor != null) { - if (selectedActor.getId().equals(actor.getId())) { + if (selectedActor.getId().equals(actor.getId()) && selectedActor.GetMapper() != null) { highlightSource.SetBounds(selectedActor.GetMapper().GetBounds()); localAxes.SetUserTransform(parent.GetUserTransform()); highlightActor.SetUserTransform(actor.GetUserTransform()); From 57722b23e0d8fe2688e893300f4aa85ce15b55c0 Mon Sep 17 00:00:00 2001 From: "Philipp M. Fischer" Date: Thu, 10 Oct 2024 11:22:53 +0200 Subject: [PATCH 4/4] Fixing workflow - (Task #1209) - Old upload artifact v2 stopped working --- Task #1209: Visualization crashes with NPE --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 656c7984eb..4e7ce5e5b8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -195,7 +195,7 @@ jobs: # -------------------------------------------- - name: Build and Test - Upload SWTBot Screenshots on Failure if: ${{ failure() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4.3.4 with: name: SWTBot Screenshots path: