1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.vtk.utils;
\r
14 import java.util.ArrayList;
\r
15 import java.util.List;
\r
17 import org.simantics.g3d.vtk.Activator;
\r
18 import org.simantics.g3d.vtk.preferences.CloseMethod;
\r
19 import org.simantics.g3d.vtk.preferences.PreferenceConstants;
\r
20 import org.simantics.utils.threads.AWTThread;
\r
22 import vtk.vtkCamera;
\r
23 import vtk.vtkObject;
\r
24 import vtk.vtkPanel;
\r
25 import vtk.vtkReferenceInformation;
\r
26 import vtk.vtkRenderWindow;
\r
27 import vtk.vtkRenderer;
\r
29 public class vtkPanelUtil {
\r
31 private static List<vtkPanel> activePanels = new ArrayList<vtkPanel>();
\r
32 private static List<vtkPanel> waitingToDeletePanels = new ArrayList<vtkPanel>();
\r
34 public static void registerPanel(vtkPanel panel) {
\r
35 activePanels.add(panel);
\r
38 public static void unregisterPanel(vtkPanel panel) {
\r
39 assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
\r
40 if (!activePanels.remove(panel))
\r
42 CloseMethod method = getCloseMethod();
\r
43 if (method == CloseMethod.ON_LAST_CLOSE) {
\r
44 waitingToDeletePanels.add(panel);
\r
46 if (activePanels.size() == 0) {
\r
49 } else if (method == CloseMethod.ON_CLOSE) {
\r
52 } else if (method == CloseMethod.NO_CLOSE) {
\r
53 waitingToDeletePanels.add(panel);
\r
57 public static CloseMethod getCloseMethod() {
\r
58 return CloseMethod.valueOf(Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CLOSE_METHOD));
\r
61 private static void cleanup() {
\r
63 for (vtkPanel p : waitingToDeletePanels) {
\r
66 waitingToDeletePanels.clear();
\r
70 private static void vtkGC() {
\r
71 vtkReferenceInformation info = vtkObject.JAVA_OBJECT_MANAGER.gc(true);
\r
72 System.out.println("Referenced objects when closing editor: " + info.getTotalNumberOfObjects() + "\n");
\r
73 System.out.println(info.listRemovedReferenceToString());
\r
74 System.out.println(info.listKeptReferenceToString());
\r
78 private static void dPanel(vtkPanel panel) {
\r
80 vtkCamera camera = panel.GetRenderer().GetActiveCamera();
\r
81 vtkRenderer ren = panel.GetRenderer();
\r
82 vtkRenderWindow win = panel.GetRenderWindow();
\r
83 win.SetForceMakeCurrent();
\r