* Bug #14582: gettext or _ were applied to broken literal strings
[scilab.git] / scilab / modules / graphics / macros / edit_curv.sci
index 227c098..1443dc1 100644 (file)
@@ -1,13 +1,16 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 1993 - INRIA - Serge Steer
 // Copyright (C) 1993 - INRIA - Habib Jreij
-// This file must be used under the terms of the CeCILL.
-// This source file is licensed as described in the file COPYING, which
-// you should have received as part of this distribution.  The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-
-function [x,y,ok,gc]=edit_curv(x,y,job,tit,gc)
+// Copyright (C) 2012 - 2016 - Scilab Enterprises
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// This file was originally licensed under the terms of the CeCILL v2.1,
+// and continues to be available under such terms.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+
+function [x,y,ok,gc] = edit_curv(x,y,job,tit,gc)
     //   mod_curv  - Edition  de courbe interactive
     //%Syntaxe
     //  [x,y,ok]=mod_curv(xd,yd,job,tit)
@@ -106,27 +109,29 @@ function [x,y,ok,gc]=edit_curv(x,y,job,tit,gc)
     w="menus(3)(";rpar=")"
     Data=w(ones(menu_d))+string(1:size(menu_d,"*"))+rpar(ones(menu_d))
 
-    curwin = max(winsid())+1;
-    scf(curwin) ;
+    curwin = scf().figure_id
 
-    //** Default layout is changed in Scilab 5
-    //** unsetmenu(curwin,'File',1) // clear
-    //** unsetmenu(curwin,'File',2) // select
-    //** unsetmenu(curwin,'File',6) // load
-    //** unsetmenu(curwin,'File',7) // close
-    //** unsetmenu(curwin,'3D Rot.')
+    // Disable the menus and toolbars
+    toolbar(curwin,"off");
+    delmenu(curwin,gettext("File"));
+    delmenu(curwin,gettext("Tools"));
+    delmenu(curwin,gettext("Edit"));;
+    delmenu(curwin,"?");
 
     execstr("Edit_"+string(curwin)+"=Edit");
     execstr("Data_"+string(curwin)+"=Data");
     menubar(curwin,menus)
     //
-    f = gcf(); a = gca();
-    a.data_bounds = [rect(1),rect(2);rect(3),rect(4)]
-    a.axes_visible="on";
-    a.grid=[4 4];
+    edit_curv_figure = gcf();
+    edit_curv_figure.figure_name = "edit_curv";
+
+    edit_curv_axes = gca();
+    edit_curv_axes.data_bounds = [rect(1),rect(2);rect(3),rect(4)]
+    edit_curv_axes.axes_visible="on";
+    edit_curv_axes.grid=[4 4];
     if x<>[] then
         xpolys(x*[1 1],y*[1 1],[1,-1])
-        hdl=a.children.children
+        hdl=edit_curv_axes.children.children
     else
         hdl=[]
     end
@@ -155,15 +160,15 @@ function [x,y,ok,gc]=edit_curv(x,y,job,tit,gc)
             break
 
         case "Ok" then    //    -- ok menu
-            rect = matrix(a.data_bounds',1,4);
+            rect = matrix(edit_curv_axes.data_bounds',1,4);
             gc   = list(rect,axisdata);
-            xdel(curwin);
+            delete(edit_curv_figure)
             return;
 
         case "Abort" then //    -- abort menu
             x = xsav
             y = ysav
-            xdel(curwin)
+            delete(edit_curv_figure)
             ok = %f;
             return
 
@@ -174,9 +179,8 @@ function [x,y,ok,gc]=edit_curv(x,y,job,tit,gc)
             return
 
         case "Undo" then
-            if hdl<>[] then draw(hdl),end //erase
             x=xs;y=ys
-            if x<>[] then hdl.data=[x y];draw(hdl);end
+            if x<>[] then hdl.data=[x y]; end
 
         case "Size" then
             while %t
@@ -196,16 +200,7 @@ function [x,y,ok,gc]=edit_curv(x,y,job,tit,gc)
                 if dx==0 then dx=max(xmx/2,1),xmn=xmn-dx/10;xmx=xmx+dx/10;end
                 if dy==0 then dy=max(ymx/2,1),ymn=ymn-dy/5;ymx=ymx+dy/10;end
                 rect=[xmn,ymn,xmx,ymx];
-                a.data_bounds=[rect(1),rect(2);rect(3),rect(4)]
-            end
-
-        case "Grids" then //no more used
-            rep=x_mdialog("entrez les nouveaux nombres d''intervalles",..
-            ["axe des x";"axe des y"],..
-            string([axisdata(2);axisdata(4)]))
-            if rep<>[] then
-                rep=evstr(rep)
-                axisdata(2)=rep(1);axisdata(4)=rep(2);
+                edit_curv_axes.data_bounds=[rect(1),rect(2);rect(3),rect(4)]
             end
 
         case "Clear" then
@@ -225,7 +220,7 @@ function [x,y,ok,gc]=edit_curv(x,y,job,tit,gc)
                 xmn=0;ymn=0;xmx=1;ymx=1;dx=1;dy=1
             end
             rect=[xmn,ymn,xmx,ymx];
-            a.data_bounds=[rect(1),rect(2);rect(3),rect(4)]
+            edit_curv_axes.data_bounds=[rect(1),rect(2);rect(3),rect(4)]
             if x<>[]&y<>[] then
                 if hdl==[] then
                     xpolys(x(1)*[1 1],y(1)*[1 1],[1,-1])
@@ -241,12 +236,12 @@ function [x,y,ok,gc]=edit_curv(x,y,job,tit,gc)
             savexy(x,y)
 
         case "Replot" then
-            draw(f)
+            // for compatibility only, perform nothing on purpose
 
         case "edit" then
             npt=prod(size(x))
             if npt<>0 then
-                dist=((x-ones(npt,1)*c1(1))/dx)^2+((y-ones(npt,1)*c1(2))/dy)^2
+                dist=((x-ones(npt,1)*c1(1))/dx).^2+((y-ones(npt,1)*c1(2))/dy).^2
                 [m,k]=min(dist);m=sqrt(m)
             else
                 m=3*eps
@@ -308,7 +303,7 @@ function [x,y] = addpt(c1,x,y)
         x = c1(1);
         y = c1(2);
         xpolys(x*[1 1],y*[1 1],[1,-1]);
-        hdl = resume(a.children(1).children)
+        hdl = resume(edit_curv_axes.children(1).children)
     end
     //recherche des intervalles en x contenant l'abscisse designee
     kk=[]
@@ -336,7 +331,7 @@ function [x,y] = addpt(c1,x,y)
                 pp=pp(:,i)
                 x=x([1:k k:npt]);x(k+1)=pp(1);
                 y=y([1:k k:npt]);y(k+1)=pp(2);
-                hdl;drawlater();hdl.data=[x y];draw(hdl)
+                hdl.data=[x y];
                 return
             end
         end
@@ -352,13 +347,12 @@ function [x,y] = addpt(c1,x,y)
         x(npt+1)=c1(1)
         y(npt+1)=c1(2)
     end
-    hdl;drawlater();hdl.data=[x y];draw(hdl)
+    hdl.data=[x y];
 endfunction
 
 function [x,y]=movept(x,y)
     //on bouge un point existant
     hdl;
-    //** f;f.pixmap='on';
     rep(3)=-1
     while rep(3)==-1 do
         rep = xgetmouse();
@@ -367,39 +361,120 @@ function [x,y]=movept(x,y)
         if mody==0 then c2(2)=y(k);end
         x(k)=c2(1);y(k)=c2(2)
         hdl.data=[x,y];
-        //** show_pixmap();
-        drawnow()
     end
-    //** f.pixmap='off';
 endfunction
 
 
 function [x,y] = readxy()
-    fn=uigetfile("*.xy")
-    if fn<>emptystr() then
-        if execstr("load(fn)","errcatch")<>0 then
-            xy=read(fn,-1,2)
-            x=xy(:,1);y=xy(:,2)
+
+    function xy = findPolyline(children)
+        xy = [];
+        for i = 1:length(children)
+            select children(i).type,
+            case "Polyline" then
+                xy = children(i).data;
+                return
+            case "Axes" then
+                xy = findPolyline(children(i).children);
+                return
+            case "Compound" then
+                xy = findPolyline(children(i).children);
+                return
+            end
+        end
+    endfunction
+
+    fn=uigetfile(["*.scg";"*.sod";"*.xy"], "", _("Select a file to load"));
+    if fn <> "" then
+        [pth, fnm, ext] = fileparts(fn);
+        flname = fnm + ext;
+
+        select ext
+        case ".scg" then
+            loaded_figure=figure("visible", "off");
+            if execstr("xload(fn, loaded_figure.figure_id)","errcatch") == 0 then
+                loaded_figure.visible = "off";
+                scf(edit_curv_figure);
+                xy = findPolyline(loaded_figure.children);
+                delete(loaded_figure);
+                if xy <> [] then
+                    x=xy(:,1);y=xy(:,2);
+                else
+                    msg = _("%s: The file "'%s"' does not contains any "'Polyline"' graphic entity.\n")
+                    messagebox(msprintf(msg, "edit_curve", flname));
+                    return
+                end
+            else
+                msg = _("%s: Cannot open file "'%s"' for reading.\n")
+                messagebox(msprintf(msg, "edit_curv", flname), "modal");
+                return
+            end
+        case ".xy" then
+            if execstr("xy = read(fn,-1,2)","errcatch") == 0 then
+                x=xy(:,1);y=xy(:,2);
+            else
+                msg = _("%s: Cannot open file "'%s"' for reading.\n")
+                messagebox(msprintf(msg, "edit_curv", flname), "modal");
+                return
+            end
+        case ".sod" then
+            if execstr("load(fn)","errcatch") == 0 then
+                x=xy(:,1);y=xy(:,2);
+            else
+                msg = _("%s: Cannot open file "'%s"' for reading.\n")
+                messagebox(msprintf(msg, "edit_curv", flname), "modal");
+                return
+            end
         else
-            x=xy(:,1);y=xy(:,2)
+            messagebox(_("Error in file format."), "modal");
+            return
         end
     else
         x=x
         y=y
     end
-
 endfunction
 
 
 function savexy(x,y)
-    fn = uigetfile("*.xy")
-    if fn<>emptystr()  then
+    fn=uiputfile(["*.sod";"*.xy"], "", _("Select a file to write"));
+    if fn <> "" then
+        [pth, fnm, ext] = fileparts(fn);
+        flname = fnm + ext;
         xy = [x y];
-        fil=fn+".xy"
-        if execstr("save(fil,xy)","errcatch")<>0 then
-            messagebox(["Impossible to save in the selected file";
-            "Check file and directory access"],"modal");
-            return
+        fil = fn;
+
+        select ext
+        case "" then
+            fil = fil + ".xy";
+            ext = ".xy";
+        case ".xy" then
+            // empty case fil = fn
+        case ".sod" then
+            // empty case fil = fn
+        else
+            fil = pth + fnm + ".xy";
+            ext = ".xy";
+        end
+
+        select ext
+        case ".sod" then
+            if execstr("save(fil,""xy"")","errcatch")<>0 then
+                msg = _("%s: The file "'%s"' cannot be written.\n")
+                messagebox(msprintf(msg, "edit_curv", flname), "modal");
+                return
+            end
+        case ".xy" then
+            isErr = execstr("write(fil,xy)","errcatch")
+            if isErr == 240 then
+                mdelete(fil); // write cannot overwrite an existing file
+                isErr = execstr("write(fil,xy)","errcatch");
+            end
+            if isErr <> 0 then
+                msg = _("%s: The file "'%s"' cannot be written.\n")
+                messagebox(msprintf(msg, "edit_curv", flname), "modal");
+                return
+            end
         end
     end
 endfunction