delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2019/09/02/09:31:25

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=majenko.co.uk; s=key1;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=mRspYlFDnSGnN5rgXzJ85ftp5RjDaEtbVCjJtW2DP0s=;
b=ntfb89m0Qh2EzKi0GK6B2Us7OHjd43Xay+405gooYMGk3C16AhXmExy4EFmI0aMQ7r
4xPeqkeJpTAAX/njRDCb5284RRz9YBSDUmHWuveoKl1BGXIaEdA8w5Mf2mossSw+2iPs
XpKJray2oW8SyzMOG5uwuU5BbShheZiIO2vO4QF5P1/dwym+wxnxkMe23vfsWbydxvZe
HWVVfT+2jZaIQ+EZ8Qjp9MgyZudlap+sMthLwN7znnkhtPMZvO2eLUKQkTpGh3WY1G2v
wZmEOagMdRu5x4cMp68FjH3pa0vVx+n+ri07SesOmLlGhBzIDgsai6eevsbmxtfIqJrR
I5UA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=mRspYlFDnSGnN5rgXzJ85ftp5RjDaEtbVCjJtW2DP0s=;
b=VRzBwEVOx9+WjfLqivhJqPM0Tmj1fXE9+aQtkFEVSBwYkOaKvnc3YQNw4GKEQaCxHR
hYPHqCbL0W/pGe/T41puOhUUKB4CYcqt4UkGbsrDsy4U59uilKdsxgrBEqcpkpH/7wMJ
S2IbTkMsRfU8uyO5Xd5MrD/ks4sQ/0xg+ovG4MOSohs5ShTOeIqMz8HugOslaj0f/LZC
mOHqkSO+rtTAjHThXFYrLo+VA5itd/DJBBZAs0sLjAKAfucI+aaX7HrPAEZJWk9KTomM
XrSTNdFKeaLeaulmc3pIV+bZ/FumZOzMoIom0c41Bwg5ocHs0UNh9VpL2dn64KfcHJeh
KdUg==
X-Gm-Message-State: APjAAAUsjuuAdNcubvzsvQ5r0ouPa5yLNbkVLgVdt3l7p7+CMPBt1QQJ
cxQ6mi5XZO5fFRzYQrJt0PyyQZDaRtvKWXJUP7cgaJgH0ws=
X-Google-Smtp-Source: APXvYqxRihsB5Cmwfozq9hwer51uaC+MykH8UXX2VixrzjhEh9SpWcpSgDjgDY1X7gng3LZ3Qlvrf6ZIQpdr6EDBcgo=
X-Received: by 2002:a2e:3a13:: with SMTP id h19mr1143731lja.220.1567429806221;
Mon, 02 Sep 2019 06:10:06 -0700 (PDT)
MIME-Version: 1.0
References: <CAPp8_DqaZpOpdKFrUF7HC9sbCG2ag0a2iuWQrSkOY76U1kRQ6g AT mail DOT gmail DOT com>
<alpine DOT DEB DOT 2 DOT 20 DOT 1909021356320 DOT 1863 AT nimbus>
In-Reply-To: <alpine.DEB.2.20.1909021356320.1863@nimbus>
From: "Majenko Technologies (matt AT majenko DOT co DOT uk) [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com>
Date: Mon, 2 Sep 2019 14:09:55 +0100
Message-ID: <CAPp8_DpMmfLQ1MzYkSyXCQ6KiGxf1+TBLz12s0ztRL7qK4sCCw@mail.gmail.com>
Subject: Re: [geda-user] gschem interaction from external processes
To: geda-user AT delorie DOT com
Reply-To: geda-user AT delorie DOT com

--000000000000cf861b059191b0d6
Content-Type: text/plain; charset="UTF-8"

For saving I simply iterate over any open windows (not sure if that's
really needed?) and then call gschem_action_activate (action_file_save_all,
item); on that window.

void saveAllFiles(int sig) {
    GList *elem;

    GschemToplevel *item;

    for(elem = global_window_list; elem; elem = elem->next) {
        item = elem->data;
        gschem_action_activate (action_file_save_all, item);
    }
}

The reverting is harder, and it's there where the rogue untitled_1.sch
comes from.  Reverting involves closing and reopening a file, and if it's
the only one then gschem automatically makes a new untitled_1.sch file when
it closes.  It's made even more complex by the fact that you can't modify
the GList of pages whilst iterating that GList of pages - so I just dump
the page pointers into a temporary array first and work from that instead.
It seems to work.

At the moment, to solve the untitled_1.sch problem, I'm simply doing a
post-process of looking through all the open files looking for one that is
called untitled_1.sch and closing it again.  All a bit hacky...

void refreshAllFiles(int sig) {
    GList *win,*page;
    GschemToplevel *top;
    PAGE *p_current;
    PAGE *newpage;
    gchar *filename;
    TOPLEVEL *toplevel;
    int page_control;
    int up;

    for (win = global_window_list; win; win = win->next) {
        top = win->data;
        toplevel = gschem_toplevel_get_toplevel(top);

        int pagecount = 0;

        for (page = geda_list_get_glist(toplevel->pages); page != NULL;
page = g_list_next(page)) {
            pagecount++;
        }

        PAGE *pages[pagecount];

        pagecount = 0;
        for (page = geda_list_get_glist(toplevel->pages); page != NULL;
page = g_list_next(page)) {
            pages[pagecount++] = page->data;
        }

        int pgno = 0;
        for (pgno = 0; pgno < pagecount; pgno++) {
            p_current = pages[pgno];

            filename = g_strdup (p_current->page_filename);

            if (filename == NULL) {
                printf("Error: got null filename\n");
                continue;
            }

            if (access(filename, R_OK) != 0) {
                printf("File not found: %s\n", filename);
                continue;
            }

            page_control = p_current->page_control;
            up = p_current->up;

            /* delete the page, then re-open the file as a new page */
            x_window_close_page (top, p_current);

            /* Force symbols to be re-loaded from disk */
            s_clib_refresh();

            newpage = x_window_open_page (top, filename);
            if (newpage != NULL) {

                /* make sure we maintain the hierarchy info */
                newpage->page_control = page_control;
                newpage->up = up;

                x_window_set_current_page (top, newpage);
            }
        }

        // When we closed and reopened the files there's a chance we made a
new untitled_1.sch file.
        // Let's close it - we don't want it.
        for (page = geda_list_get_glist(toplevel->pages); page != NULL;
page = g_list_next(page)) {
            PAGE *pg;
            pg = page->data;
            if (strstr(pg->page_filename, "/untitled_1.sch") != NULL) {
                x_window_close_page(top, pg);
                break;
            }
        }

    }
}

Having a file descriptor form of access would be nicer, yes - be that a
named pipe, unix socket, stdin, whatever.  Some way where you can actually
give it some definite commands and instructions rather than just firing a
signal and hoping it does what you want.


On Mon, Sep 2, 2019 at 2:01 PM Roland Lutz <rlutz AT hedmen DOT org> wrote:

> Hi Matt,
>
> On Mon, 2 Sep 2019, Majenko Technologies (matt AT majenko DOT co DOT uk) [via
> geda-user AT delorie DOT com] wrote:
> > I am attempting to build an integrated project management system based
> > around gschem and PCB and associated tools. Something which integrates
> > the tools together into a single workflow.
> >
> > As part of this is an automated (by automated I mean you click one
> > button in the interface) "Save open schematics and PCBs, Run gsch2pcb,
> > Reload open schematics and PCBs from disk, Load new netlist and layout
> > to buffer" operation.
>
> I have already implemented the gschem side of things for Igor2's
> "genxproj" tool as part of the file operation cleanup I'm currently
> working on.
>
> > I have modified the code so that it responds to two signals, USR1 (save
> all
> > pages) and USR2 (close and re-open all pages), and it (kind of) works
>
> I think file-descriptor communication would be more desireable.
>
> > (at the moment it's dumping random "untitled_1.sch" files around the
> > place, but I can fix that...)
>
> Yes, that's one of the (many) non-trivial issues with that. :/
>
> > What would be ideal would be a "--listen" system like PCB has that would
> > allow you to send SCM scripts directly to the running process.
>
> That won't help, either, because the SCM actions internally have the same
> issues.
>
> What's missing is a proper abstraction of file operations in gschem which
> gives you functions like "save all pages" or "revert page" to call when
> signalled to.  That's exactly what I have been working on for the past
> month; I'll try to complete this as soon as possible.
>
> Roland
>
>

-- 
*Matt Jenkins*
Majenko Technologies

--000000000000cf861b059191b0d6
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">For saving I simply iterate over any open windows (not sur=
e if that&#39;s really needed?) and then call=C2=A0gschem_action_activate (=
action_file_save_all, item); on that window.<div><br></div><div><font face=
=3D"monospace">void saveAllFiles(int sig) {<br>=C2=A0 =C2=A0 GList *elem;<b=
r>=C2=A0 =C2=A0<br>=C2=A0 =C2=A0 GschemToplevel *item;<br><br>=C2=A0 =C2=A0=
 for(elem =3D global_window_list; elem; elem =3D elem-&gt;next) {<br>=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 item =3D elem-&gt;data;<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 gschem_action_activate (action_file_save_all, item);<br>=C2=A0 =C2=A0 }=
<br>}</font><br></div><div><br></div><div>The reverting is harder, and it&#=
39;s there where the rogue untitled_1.sch comes from.=C2=A0 Reverting invol=
ves closing and reopening a file, and if it&#39;s the only one then gschem =
automatically makes a new untitled_1.sch file when it closes.=C2=A0 It&#39;=
s made even more complex by the fact that you can&#39;t modify the GList of=
 pages whilst iterating that GList of pages - so I just dump the page point=
ers into a temporary array first and work from that instead. It seems to wo=
rk.</div><div><br></div><div>At the moment, to solve the untitled_1.sch pro=
blem, I&#39;m simply doing a post-process of looking through all the open f=
iles looking for one that is called untitled_1.sch and closing it again.=C2=
=A0 All a bit hacky...</div><div><br></div><div><font face=3D"monospace">vo=
id refreshAllFiles(int sig) {<br>=C2=A0 =C2=A0 GList *win,*page;<br>=C2=A0 =
=C2=A0 GschemToplevel *top;<br>=C2=A0 =C2=A0 PAGE *p_current;<br>=C2=A0 =C2=
=A0 PAGE *newpage;<br>=C2=A0 =C2=A0 gchar *filename;<br>=C2=A0 =C2=A0 TOPLE=
VEL *toplevel;<br>=C2=A0 =C2=A0 int page_control;<br>=C2=A0 =C2=A0 int up;<=
br><br>=C2=A0 =C2=A0 for (win =3D global_window_list; win; win =3D win-&gt;=
next) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 top =3D win-&gt;data;<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 toplevel =3D gschem_toplevel_get_toplevel(top);<br><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 int pagecount =3D 0;<br><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 for (page =3D geda_list_get_glist(toplevel-&gt;pages); page !=3D=
 NULL; page =3D g_list_next(page)) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 pagecount++;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 PAGE *pages[pagecount];<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 pa=
gecount =3D 0;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 for (page =3D geda_list_get_g=
list(toplevel-&gt;pages); page !=3D NULL; page =3D g_list_next(page)) {<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pages[pagecount++] =3D page-&gt;d=
ata;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 in=
t pgno =3D 0;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 for (pgno =3D 0; pgno &lt; pag=
ecount; pgno++) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 p_current =
=3D pages[pgno];<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 filename =
=3D g_strdup (p_current-&gt;page_filename);<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 if (filename =3D=3D NULL) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf(&quot;Error: got null filename\n&quo=
t;);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;<b=
r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 if (access(filename, R_OK) !=3D 0) {<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf(&quot;File not found: %s\n=
&quot;, filename);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 continue;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 page_control =3D p_current-&gt;page_cont=
rol;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 up =3D p_current-&gt;up;<=
br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* delete the page, then r=
e-open the file as a new page */<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 x_window_close_page (top, p_current);<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 /* Force symbols to be re-loaded from disk */<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 s_clib_refresh();<br><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 newpage =3D x_window_open_page (top, filename);=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (newpage !=3D NULL) {<br><=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* make sure we =
maintain the hierarchy info */<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 newpage-&gt;page_control =3D page_control;<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 newpage-&gt;up =3D up;<br><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 x_window_set_current_p=
age (top, newpage);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 }<br><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 // When we cl=
osed and reopened the files there&#39;s a chance we made a new untitled_1.s=
ch file.<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Let&#39;s close it - we don&#39;=
t want it.<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 for (page =3D geda_list_get_glist=
(toplevel-&gt;pages); page !=3D NULL; page =3D g_list_next(page)) {<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 PAGE *pg;<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 pg =3D page-&gt;data;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 if (strstr(pg-&gt;page_filename, &quot;/untitled_1.sch&quot;)=
 !=3D NULL) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 x_=
window_close_page(top, pg);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 break;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 }<br><br>=C2=A0 =C2=A0 }<br>}</font><br></div><div=
><br></div><div>Having a file descriptor form of access would be nicer, yes=
 - be that a named pipe, unix socket, stdin, whatever.=C2=A0 Some way where=
 you can actually give it some definite commands and instructions rather th=
an just firing a signal and hoping it does what you want.</div><div><br></d=
iv></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_att=
r">On Mon, Sep 2, 2019 at 2:01 PM Roland Lutz &lt;<a href=3D"mailto:rlutz AT h=
edmen.org">rlutz AT hedmen DOT org</a>&gt; wrote:<br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex">Hi Matt,<br>
<br>
On Mon, 2 Sep 2019, Majenko Technologies (<a href=3D"mailto:matt AT majenko DOT co=
.uk" target=3D"_blank">matt AT majenko DOT co DOT uk</a>) [via <br>
<a href=3D"mailto:geda-user AT delorie DOT com" target=3D"_blank">geda-user AT delori=
e.com</a>] wrote:<br>
&gt; I am attempting to build an integrated project management system based=
 <br>
&gt; around gschem and PCB and associated tools. Something which integrates=
 <br>
&gt; the tools together into a single workflow.<br>
&gt; <br>
&gt; As part of this is an automated (by automated I mean you click one <br=
>
&gt; button in the interface) &quot;Save open schematics and PCBs, Run gsch=
2pcb, <br>
&gt; Reload open schematics and PCBs from disk, Load new netlist and layout=
 <br>
&gt; to buffer&quot; operation.<br>
<br>
I have already implemented the gschem side of things for Igor2&#39;s <br>
&quot;genxproj&quot; tool as part of the file operation cleanup I&#39;m cur=
rently <br>
working on.<br>
<br>
&gt; I have modified the code so that it responds to two signals, USR1 (sav=
e all<br>
&gt; pages) and USR2 (close and re-open all pages), and it (kind of) works<=
br>
<br>
I think file-descriptor communication would be more desireable.<br>
<br>
&gt; (at the moment it&#39;s dumping random &quot;untitled_1.sch&quot; file=
s around the <br>
&gt; place, but I can fix that...)<br>
<br>
Yes, that&#39;s one of the (many) non-trivial issues with that. :/<br>
<br>
&gt; What would be ideal would be a &quot;--listen&quot; system like PCB ha=
s that would <br>
&gt; allow you to send SCM scripts directly to the running process.<br>
<br>
That won&#39;t help, either, because the SCM actions internally have the sa=
me <br>
issues.<br>
<br>
What&#39;s missing is a proper abstraction of file operations in gschem whi=
ch <br>
gives you functions like &quot;save all pages&quot; or &quot;revert page&qu=
ot; to call when <br>
signalled to.=C2=A0 That&#39;s exactly what I have been working on for the =
past <br>
month; I&#39;ll try to complete this as soon as possible.<br>
<br>
Roland<br>
<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature"><div dir=3D"ltr"><b>Matt Jenkins</b><div>Majenko=
 Technologies</div><div><br></div></div></div>

--000000000000cf861b059191b0d6--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019