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: In-Reply-To: From: "Majenko Technologies (matt AT majenko DOT co DOT uk) [via geda-user AT delorie DOT com]" Date: Mon, 2 Sep 2019 14:09:55 +0100 Message-ID: Subject: Re: [geda-user] gschem interaction from external processes To: geda-user AT delorie DOT com Content-Type: multipart/alternative; boundary="000000000000cf861b059191b0d6" 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 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
For saving I simply iterate over any open windows (not sur= e if that's really needed?) and then call=C2=A0gschem_action_activate (= action_file_save_all, item); on that window.

void saveAllFiles(int sig) {
=C2=A0 =C2=A0 GList *elem;=C2=A0 =C2=A0
=C2=A0 =C2=A0 GschemToplevel *item;

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


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's the only one then gschem = automatically makes a new untitled_1.sch file when it closes.=C2=A0 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 point= ers into a temporary array first and work from that instead. It seems to wo= rk.

At the moment, to solve the untitled_1.sch pro= blem, I'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...

vo= id refreshAllFiles(int sig) {
=C2=A0 =C2=A0 GList *win,*page;
=C2=A0 = =C2=A0 GschemToplevel *top;
=C2=A0 =C2=A0 PAGE *p_current;
=C2=A0 =C2= =A0 PAGE *newpage;
=C2=A0 =C2=A0 gchar *filename;
=C2=A0 =C2=A0 TOPLE= VEL *toplevel;
=C2=A0 =C2=A0 int page_control;
=C2=A0 =C2=A0 int up;<= br>
=C2=A0 =C2=A0 for (win =3D global_window_list; win; win =3D win->= next) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 top =3D win->data;
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 toplevel =3D gschem_toplevel_get_toplevel(top);

= =C2=A0 =C2=A0 =C2=A0 =C2=A0 int pagecount =3D 0;

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

=C2=A0 =C2=A0 = =C2=A0 =C2=A0 PAGE *pages[pagecount];

=C2=A0 =C2=A0 =C2=A0 =C2=A0 pa= gecount =3D 0;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 for (page =3D geda_list_get_g= list(toplevel->pages); page !=3D NULL; page =3D g_list_next(page)) {
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pages[pagecount++] =3D page->d= ata;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 in= t pgno =3D 0;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 for (pgno =3D 0; pgno < pag= ecount; pgno++) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 p_current = =3D pages[pgno];

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 filename = =3D g_strdup (p_current->page_filename);

=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 if (filename =3D=3D NULL) {
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("Error: got null filename\n&quo= t;);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }

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

=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 page_control =3D p_current->page_cont= rol;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 up =3D p_current->up;<= 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 */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 x_window_close_page (top, p_current);

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

=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 newpage =3D x_window_open_page (top, filename);=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (newpage !=3D NULL) {
<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* make sure we = maintain the hierarchy info */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 newpage->page_control =3D page_control;
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 newpage->up =3D up;

=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 x_window_set_current_p= age (top, newpage);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 }

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

=C2=A0 =C2=A0 }
}


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.


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 delori= e.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 gsch= 2pcb,
> 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 cur= rently
working on.

> I have modified the code so that it responds to two signals, USR1 (sav= e all
> pages) and USR2 (close and re-open all pages), and it (kind of) works<= br>
I think file-descriptor communication would be more desireable.

> (at the moment it's dumping random "untitled_1.sch" file= s 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 ha= s 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 sa= me
issues.

What's missing is a proper abstraction of file operations in gschem whi= ch
gives you functions like "save all pages" or "revert page&qu= ot; to call when
signalled to.=C2=A0 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--