Export: driver change could close the current graphic window 40/14140/2
Calixte DENIZET [Wed, 26 Mar 2014 13:53:47 +0000 (14:53 +0100)]
Change-Id: I188cefa64e6af115d29d06fe1e1809d1272e4f8e

scilab/modules/graphic_export/sci_gateway/cpp/sci_driver.cpp
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/Export.java

index 9a7930a..6bd206c 100644 (file)
@@ -85,16 +85,6 @@ int sci_driver(char * fname, unsigned long fname_len )
         else if (org_scilab_modules_gui::SwingView::isHeadless(getScilabJavaVM()))
         {
             org_scilab_modules_gui::SwingView::setHeadless(getScilabJavaVM(), false);
-            int CurrentFigureReference = ScilabView::getCurrentFigure();
-            if (CurrentFigureReference != 0)
-            {
-                int uid = CurrentFigureReference;
-
-                if (uid)
-                {
-                    deleteGraphicObject(uid);
-                }
-            }
         }
 
         freeAllocatedSingleString(driver);
index 01bc640..59afb85 100644 (file)
@@ -246,31 +246,33 @@ public class Export {
             }
         } else {
             DrawerVisitor visitor = DrawerVisitor.getVisitor(uid);
-            G2DCanvas canvas = (G2DCanvas) visitor.getCanvas();
-            canvas.enableDraw();
-            Exporter exporter = null;
-            try {
-                canvas.redraw();
-                exporter = visitorsToExp.get(visitor);
-                if (exporter != null) {
-                    exporter.file = file;
-                    exporter.write();
-                }
-            } catch (OutOfMemoryError e) {
-                return MEMORY_ERROR;
-            } catch (IOException e) {
-                throw e;
-            } catch (Throwable e) {
-                return UNKNOWN_ERROR;
-            } finally {
-                if (exporter != null) {
-                    exporter.dispose();
-                    exporter = null;
-                    visitorsToExp.remove(visitor);
+            if (visitor.getCanvas() instanceof G2DCanvas) {
+                G2DCanvas canvas = (G2DCanvas) visitor.getCanvas();
+                canvas.enableDraw();
+                Exporter exporter = null;
+                try {
+                    canvas.redraw();
+                    exporter = visitorsToExp.get(visitor);
+                    if (exporter != null) {
+                        exporter.file = file;
+                        exporter.write();
+                    }
+                } catch (OutOfMemoryError e) {
+                    return MEMORY_ERROR;
+                } catch (IOException e) {
+                    throw e;
+                } catch (Throwable e) {
+                    return UNKNOWN_ERROR;
+                } finally {
+                    if (exporter != null) {
+                        exporter.dispose();
+                        exporter = null;
+                        visitorsToExp.remove(visitor);
+                    }
+                    DrawerVisitor.changeVisitor(figure, null);
+                    GraphicController.getController().unregister(visitor);
+                    canvas.destroy();
                 }
-                DrawerVisitor.changeVisitor(figure, null);
-                GraphicController.getController().unregister(visitor);
-                canvas.destroy();
             }
         }