Skip to content

Commit

Permalink
Save and load VPORT params
Browse files Browse the repository at this point in the history
  • Loading branch information
zecruel authored May 2, 2024
1 parent 4254e0d commit f4a7589
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/dxf_seed.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ const char *dxf_seed_2007 =
"21\n"
"1.0\n"
"12\n"
"20.0\n"
"0.5\n"
"22\n"
"320.0\n"
"0.5\n"
"13\n"
"0.0\n"
"23\n"
Expand All @@ -174,15 +174,15 @@ const char *dxf_seed_2007 =
"36\n"
"1.0\n"
"17\n"
"0.0\n"
"7.75\n"
"27\n"
"0.0\n"
"15.0\n"
"37\n"
"0.0\n"
"40\n"
"25.0\n"
"40.0\n"
"41\n"
"1.8\n"
"0.99\n"
"42\n"
"50.0\n"
"43\n"
Expand Down
89 changes: 88 additions & 1 deletion src/gui_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,38 @@ int gui_main_loop (gui_obj *gui) {
}
}

/* get active viewport */
start = dxf_find_obj_descr2(gui->drawing->t_vport, "VPORT", "*ACTIVE");
if (start) {
double x = 0.0, y = 0.0, z = 0.0, h = 1.0, ar = 1.0;
part = dxf_find_attr2(start, 17);
if (part != NULL){
x = part->value.d_data;
}
part = dxf_find_attr2(start, 27);
if (part != NULL){
y = part->value.d_data;
}
part = dxf_find_attr2(start, 37);
if (part != NULL){
z = part->value.d_data;
}
part = dxf_find_attr2(start, 40);
if (part != NULL){
h = part->value.d_data;
}
part = dxf_find_attr2(start, 41);
if (part != NULL){
ar = part->value.d_data;
}
/* convert and apply vport params to display */
gui->zoom = 800.0 / h;
gui->ofs_x = x - (gui->win_w - 800 * ar)/(2.0 * gui->zoom);
gui->ofs_y = y - h / 2.0;
}
else gui->action = VIEW_ZOOM_EXT;

dxf_ents_parse(gui->drawing);
gui->action = VIEW_ZOOM_EXT;
gui->layer_idx = dxf_lay_idx (gui->drawing,
strpool_inject( &name_pool, "0", 1));
gui->ltypes_idx = dxf_ltype_idx (gui->drawing,
Expand Down Expand Up @@ -786,6 +816,37 @@ int gui_main_loop (gui_obj *gui) {

update_title = 1;

/* get active viewport */
start = dxf_find_obj_descr2(gui->drawing->t_vport, "VPORT", "*ACTIVE");
if (start) {
double x = 0.0, y = 0.0, z = 0.0, h = 1.0, ar = 1.0;
part = dxf_find_attr2(start, 17);
if (part != NULL){
x = part->value.d_data;
}
part = dxf_find_attr2(start, 27);
if (part != NULL){
y = part->value.d_data;
}
part = dxf_find_attr2(start, 37);
if (part != NULL){
z = part->value.d_data;
}
part = dxf_find_attr2(start, 40);
if (part != NULL){
h = part->value.d_data;
}
part = dxf_find_attr2(start, 41);
if (part != NULL){
ar = part->value.d_data;
}
/* convert and apply vport params to display */
gui->zoom = 800.0 / h;
gui->ofs_x = x - (gui->win_w - 800 * ar)/(2.0 * gui->zoom);
gui->ofs_y = y - h / 2.0;
}
else gui->action = VIEW_ZOOM_EXT;

if (gui->script_resume_reason == YIELD_DRWG_NEW){
gui->script_resume_reason = YIELD_NONE;
gui->script_resume = 1;
Expand Down Expand Up @@ -909,6 +970,32 @@ int gui_main_loop (gui_obj *gui) {
dxf_attr_append(gui->drawing->head, 2, gui->list_do.current->uuid, DWG_LIFE);
}

/* get active viewport */
start = dxf_find_obj_descr2(gui->drawing->t_vport, "VPORT", "*ACTIVE");
if (start) {
/* convert and apply display params to vport object to store */
double x = 0.0, y = 0.0, z = 0.0, h = 1.0, ar = 0.99;

h = 800.0 / gui->zoom;
x = gui->ofs_x + (gui->win_w - 800 * ar)/(2.0 * gui->zoom);
y = gui->ofs_y + h / 2.0;

dxf_attr_change(start, 10, (void *) (double[]){0.0});
dxf_attr_change(start, 20, (void *) (double[]){0.0});
dxf_attr_change(start, 11, (void *) (double[]){1.0});
dxf_attr_change(start, 21, (void *) (double[]){1.0});
dxf_attr_change(start, 12, (void *) (double[]){0.5});
dxf_attr_change(start, 22, (void *) (double[]){0.5});
dxf_attr_change(start, 16, (void *) (double[]){0.0});
dxf_attr_change(start, 26, (void *) (double[]){0.0});
dxf_attr_change(start, 36, (void *) (double[]){1.0});
dxf_attr_change(start, 17, (void *) &x);
dxf_attr_change(start, 27, (void *) &y);
dxf_attr_change(start, 37, (void *) &z);
dxf_attr_change(start, 40, (void *) &h);
dxf_attr_change(start, 41, (void *) &ar);
}

if (dxf_save (gui->curr_path, gui->drawing)){
if (strncmp (gui->dwg_dir, get_dir(gui->curr_path) , PATH_MAX_CHARS) == 0 &&
strncmp (gui->dwg_file, get_filename(gui->curr_path) , DXF_MAX_CHARS) == 0 )
Expand Down
31 changes: 31 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,37 @@ int main(int argc, char** argv){
dxf_attr_append(gui->drawing->head, 2, uuid_str, DWG_LIFE);
}

/* get active viewport */
start = dxf_find_obj_descr2(gui->drawing->t_vport, "VPORT", "*ACTIVE");
if (start) {
double x = 0.0, y = 0.0, z = 0.0, h = 1.0, ar = 1.0;
part = dxf_find_attr2(start, 17);
if (part != NULL){
x = part->value.d_data;
}
part = dxf_find_attr2(start, 27);
if (part != NULL){
y = part->value.d_data;
}
part = dxf_find_attr2(start, 37);
if (part != NULL){
z = part->value.d_data;
}
part = dxf_find_attr2(start, 40);
if (part != NULL){
h = part->value.d_data;
}
part = dxf_find_attr2(start, 41);
if (part != NULL){
ar = part->value.d_data;
}
/* convert and apply vport params to display */
gui->zoom = 800.0 / h;
gui->ofs_x = x - (gui->win_w - 800 * ar)/(2.0 * gui->zoom);
gui->ofs_y = y - h / 2.0;
}
else gui->action = VIEW_ZOOM_EXT;

strncpy (gui->list_do.current->uuid, uuid_str, ACT_CHARS - 1);
gui->list_do.current->time = curr_time;

Expand Down

0 comments on commit f4a7589

Please sign in to comment.