Skip to content

Commit

Permalink
gui: store module coordinates directly in cfg
Browse files Browse the repository at this point in the history
to convert the old ones in ~/.config/vkdt/nodes/*, go through all these files and
for instance use
`head -1 ~/.config/vkdt/nodes/972458d7acb92286.dat` to find their file name
and then append the rest, i.e.
`tail --lines=+2 ~/.config/vkdt/nodes/972458d7acb92286.dat >> $(head -1 ~/.config/vkdt/nodes/972458d7acb92286.dat)`

full script (caution if you have a default.something.dat):
```
for i in $(ls ~/.config/vkdt/nodes/*dat)
do
  tail --lines=+2 $i >> "$(head -1 $i)"
done
```
  • Loading branch information
hanatos committed Apr 24, 2023
1 parent 6e6b529 commit d703743
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 89 deletions.
29 changes: 14 additions & 15 deletions bin/default-darkroom.i-raw
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
module:i-raw:main
module:denoise:01
module:hilite:01
module:demosaic:01
module:colour:01
module:filmcurv:01
module:llap:01
module:hist:01
module:zones:01
module:crop:01
module:lens:01
module:pick:01
module:display:hist
# last display is the one determining the ROI:
module:display:main
module:i-raw:main:43:400
module:denoise:01:218:400
module:hilite:01:393:400
module:demosaic:01:568:400
module:colour:01:931:400
module:filmcurv:01:1094:400
module:llap:01:1269:400
module:hist:01:1418:634
module:zones:01:219:800
module:crop:01:743:400
module:lens:01:568:800
module:pick:01:43:800
module:display:hist:1600:634
module:display:main:1545:400
connect:i-raw:main:output:denoise:01:input
connect:denoise:01:output:hilite:01:input
connect:hilite:01:output:demosaic:01:input
Expand Down
95 changes: 23 additions & 72 deletions src/gui/render_nodes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ enum hotkey_names_t

typedef struct gui_nodes_t
{
int do_layout; // got nothing, do initial auto layout
ImVec2 mod_pos[100]; // read manual positions from file
int do_layout; // do initial auto layout
int hotkey;
int node_hovered_link;
int dual_monitor;
Expand Down Expand Up @@ -398,20 +397,26 @@ void render_nodes()
mod_id[pos2] = tmp;
render_nodes_module(g, curr);
if(!g->module[curr].name) continue;
if(nodes.do_layout == 1)
ImNodes::SetNodeEditorSpacePos(curr, ImVec2(nodew*(m+0.25), nodey));
else if(nodes.do_layout == 2)
ImNodes::SetNodeEditorSpacePos(curr, nodes.mod_pos[curr]);
if(nodes.do_layout)
{
if(g->module[curr].gui_x == 0 && g->module[curr].gui_y == 0)
ImNodes::SetNodeEditorSpacePos(curr, ImVec2(nodew*(m+0.25), nodey));
else
ImNodes::SetNodeEditorSpacePos(curr, ImVec2(g->module[curr].gui_x, g->module[curr].gui_y));
}
}

for(int m=pos;m<arr_cnt;m++)
{ // draw disconnected modules
render_nodes_module(g, mod_id[m]);
if(!g->module[mod_id[m]].name) continue;
if(nodes.do_layout == 1)
ImNodes::SetNodeEditorSpacePos(mod_id[m], ImVec2(nodew*(m+0.25-pos), 2*nodey));
else if(nodes.do_layout == 2)
ImNodes::SetNodeEditorSpacePos(mod_id[m], nodes.mod_pos[mod_id[m]]);
if(nodes.do_layout)
{
if(g->module[mod_id[m]].gui_x == 0 && g->module[mod_id[m]].gui_y == 0)
ImNodes::SetNodeEditorSpacePos(mod_id[m], ImVec2(nodew*(m+0.25-pos), 2*nodey));
else
ImNodes::SetNodeEditorSpacePos(mod_id[m], ImVec2(g->module[mod_id[m]].gui_x, g->module[mod_id[m]].gui_y));
}
}
ImNodes::PopAttributeFlag();

Expand Down Expand Up @@ -532,75 +537,21 @@ extern "C" int nodes_enter()
nodes.hotkey = -1;
nodes.do_layout = 1; // assume bad initial auto layout
nodes.node_hovered_link = -1;
dt_graph_t *g = &vkdt.graph_dev;
char filename[PATH_MAX], datname[PATH_MAX];
dt_db_image_path(&vkdt.db, vkdt.db.current_imgid, filename, sizeof(filename));
uint64_t hash = hash64(filename);
int loaded_default = 0;
if(snprintf(datname, sizeof(datname), "%s/nodes/%lx.dat", dt_pipe.homedir, hash) < int(sizeof(datname)))
{ // read from ~/.config/vkdt/nodes/<hash>.dat
FILE *f = fopen(datname, "rb");
if(!f)
{ // try initial config for default input module
dt_token_t mod = dt_graph_default_input_module(filename);
if(snprintf(datname, sizeof(datname), "%s/nodes/default.%" PRItkn ".dat", dt_pipe.homedir, dt_token_str(mod)) < int(sizeof(datname)))
f = fopen(datname, "rb");
loaded_default = 1;
}
if(f)
{
char line[300];
fscanf(f, "%299[^\n]", line);
if(loaded_default || !strcmp(line, filename))
{ // only use hashed positions if filename actually matches
while(!feof(f))
{
fscanf(f, "%299[^\n]", line);
char *l = line;
if(fgetc(f) == EOF) break; // read \n
dt_token_t name = dt_read_token(l, &l);
dt_token_t inst = dt_read_token(l, &l);
const float px = dt_read_float(l, &l);
const float py = dt_read_float(l, &l);
for(uint32_t m=0;m<MIN(sizeof(nodes.mod_pos)/sizeof(nodes.mod_pos[0]), g->num_modules);m++)
if(g->module[m].name == name && g->module[m].inst == inst)
nodes.mod_pos[m] = ImVec2(px, py);
}
nodes.do_layout = 2; // ask to read positions
}
fclose(f);
}
}
nodes.do_layout = 2; // ask to read positions
// make sure we process once:
vkdt.graph_dev.runflags = s_graph_run_record_cmd_buf;
return 0;
}

extern "C" int nodes_leave()
{
// serialise node positions to hidden/hashed file in ~/.config
char filename[PATH_MAX], datname[PATH_MAX];
dt_db_image_path(&vkdt.db, vkdt.db.current_imgid, filename, sizeof(filename));
uint64_t hash = hash64(filename);
if(snprintf(datname, sizeof(datname), "%s/nodes", dt_pipe.homedir) < int(sizeof(datname)))
fs_mkdir(datname, 0755);
if(snprintf(datname, sizeof(datname), "%s/nodes/%lx.dat", dt_pipe.homedir, hash) < int(sizeof(datname)))
{ // write to ~/.config/vkdt/nodes/<hash>.dat
FILE *f = fopen(datname, "wb");
if(f)
{
fprintf(f, "%s\n", filename);
dt_graph_t *g = &vkdt.graph_dev;
for(uint32_t m=0;m<g->num_modules;m++)
{
if(g->module[m].name == 0) continue; // don't write removed ones
ImVec2 pos = ImNodes::GetNodeEditorSpacePos(m);
fprintf(f, "%" PRItkn ":%" PRItkn ":%g:%g\n",
dt_token_str(g->module[m].name), dt_token_str(g->module[m].inst),
pos.x, pos.y);
}
fclose(f);
}
dt_graph_t *g = &vkdt.graph_dev;
for(uint32_t m=0;m<g->num_modules;m++)
{ // set gui positions on modules
if(g->module[m].name == 0) continue; // don't write removed ones
ImVec2 pos = ImNodes::GetNodeEditorSpacePos(m);
g->module[m].gui_x = pos.x;
g->module[m].gui_y = pos.y;
}
return 0;
}
Expand Down
9 changes: 7 additions & 2 deletions src/pipe/graph-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ read_module_ascii(
{
dt_token_t name = dt_read_token(line, &line);
dt_token_t inst = dt_read_token(line, &line);
float x = dt_read_float(line, &line);
float y = dt_read_float(line, &line);
// in case of failure:
// discard module id, but remember error state (returns modid=-1)
int modid = dt_module_add(graph, name, inst);
Expand All @@ -199,6 +201,8 @@ read_module_ascii(
dt_token_str(name), dt_token_str(inst));
return 1;
}
graph->module[modid].gui_x = x;
graph->module[modid].gui_y = y;
return 0;
}

Expand Down Expand Up @@ -302,9 +306,10 @@ dt_graph_write_module_ascii(
size_t size)
{
if(graph->module[m].name == 0) return line; // don't write removed modules
WRITE("module:%"PRItkn":%"PRItkn"\n",
WRITE("module:%"PRItkn":%"PRItkn":%g:%g\n",
dt_token_str(graph->module[m].name),
dt_token_str(graph->module[m].inst));
dt_token_str(graph->module[m].inst),
graph->module[m].gui_x, graph->module[m].gui_y);
return line;
}

Expand Down
3 changes: 3 additions & 0 deletions src/pipe/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ typedef struct dt_module_t
// this is useful for instance for a cpu caching of
// input data decoded from disk inside a module:
void *data; // if you indeed must store your own data.

// gui stuff. for convenience referenced here directly, but not crucial for cli operation and may be left 0.
float gui_x, gui_y; // position in graph editor
}
dt_module_t;

Expand Down

0 comments on commit d703743

Please sign in to comment.