Skip to content

Commit

Permalink
Dimension feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zecruel authored Jan 24, 2022
1 parent 40dc9e7 commit 843a064
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/draw_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,8 @@ int graph_draw_gl(graph_obj * master, struct ogl *gl_ctx, struct draw_param para
gl_ctx->fg[2] = color.b;
gl_ctx->fg[3] = color.a;

/* check if graph is legible (greater then 5 pixels) */
if (xd1 - xd0 < 5 && yd1 - yd0 < 5 && zd1 - zd0 < 5 && current->next != NULL){
/* check if graph is legible (greater then 3 pixels) */
if (xd1 - xd0 < 3 && yd1 - yd0 < 3 && zd1 - zd0 < 3 && current->next != NULL){
/* draw a single triangle if not legible */
draw_gl_triang (gl_ctx, (int[]){xd0, yd0, zd0}, (int[]){xd0, yd1, zd0}, (int[]){xd1, yd0, zd0});
return 0;
Expand Down
14 changes: 14 additions & 0 deletions src/dxf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,8 @@ int dxf_read (dxf_drawing *drawing, char *buf, long fsize, int *prog){
drawing->dimscale = 1.0;
drawing->dimlfac = 1.0;
drawing->dimpost[0] = '<'; drawing->dimpost[1] = '>'; drawing->dimpost[2] = 0;
strncpy(drawing->dimtxsty, "Standard", DXF_MAX_CHARS);
strncpy(drawing->dimblk, "Open", DXF_MAX_CHARS);

if(dxf_find_head_var(drawing->head, "$DIMSCALE", &start, &end)){
part = dxf_find_attr_i2(start, end, 40, 0);
Expand All @@ -1703,6 +1705,18 @@ int dxf_read (dxf_drawing *drawing, char *buf, long fsize, int *prog){
strncpy (drawing->dimpost, part->value.s_data, DXF_MAX_CHARS);
}
}
if(dxf_find_head_var(drawing->head, "$DIMTXSTY", &start, &end)){
part = dxf_find_attr_i2(start, end, 7, 0);
if (part != NULL){
strncpy (drawing->dimtxsty, part->value.s_data, DXF_MAX_CHARS);
}
}
if(dxf_find_head_var(drawing->head, "$DIMBLK", &start, &end)){
part = dxf_find_attr_i2(start, end, 1, 0);
if (part != NULL){
strncpy (drawing->dimblk, part->value.s_data, DXF_MAX_CHARS);
}
}

//return drawing;
state = INIT;
Expand Down
2 changes: 2 additions & 0 deletions src/dxf.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ struct Dxf_drawing{
double dimlfac;
double dimscale;
char dimpost [DXF_MAX_CHARS + 1];
char dimtxsty [DXF_MAX_CHARS + 1];
char dimblk [DXF_MAX_CHARS + 1];

};
typedef struct Dxf_drawing dxf_drawing;
Expand Down
2 changes: 1 addition & 1 deletion src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct gui_glyph * gui_new_glyph (struct gui_font *gfont, int code_p){
glyph->y = y0;
glyph->w = w;
glyph->h = h;
glyph->adv = curr_glyph->adv * gfont->font->height;
glyph->adv = (double)curr_glyph->adv * (double)gfont->font->height;

}
}
Expand Down
5 changes: 4 additions & 1 deletion src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ enum Modal {
PROP,
TXT_PROP,
VERTEX,
DIMENSION
DIM_LINEAR,
DIM_ANGULAR,
DIM_RADIUS,
DIM_ORDINATE
};

enum Gui_ev {
Expand Down
56 changes: 54 additions & 2 deletions src/gui_dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

int gui_dim_interactive(gui_obj *gui){

if (gui->modal != DIMENSION) return 0;
if (gui->modal != DIM_LINEAR) return 0;

if (gui->step == 0){

Expand All @@ -19,7 +19,7 @@ int gui_dim_interactive(gui_obj *gui){
}

int gui_dim_info (gui_obj *gui){
if (gui->modal != DIMENSION) return 0;
if (gui->modal != DIM_LINEAR) return 0;
static int fix_angle = 0;
static double angle_fixed = 0.0;
static double dist_fixed = 3.0;
Expand Down Expand Up @@ -245,6 +245,58 @@ int gui_dim_mng (gui_obj *gui){
}
}

nk_label(gui->ctx, "Annotation text style:", NK_TEXT_LEFT);
/* text style combo selection */
int num_tstyles = gui->drawing->num_tstyles;
dxf_tstyle *t_sty = gui->drawing->text_styles;
int h = num_tstyles * 25 + 5;
h = (h < 200)? h : 200;
if (nk_combo_begin_label(gui->ctx, gui->drawing->dimtxsty, nk_vec2(220, h))){
nk_layout_row_dynamic(gui->ctx, 20, 1);
int j = 0;
for (j = 0; j < num_tstyles; j++){
if (nk_button_label(gui->ctx, t_sty[j].name)){
strncpy(gui->drawing->dimtxsty, t_sty[j].name, DXF_MAX_CHARS); /* select current style */
/* change in DXF main struct */
dxf_node *start = NULL, *end = NULL, *part = NULL;
if(dxf_find_head_var(gui->drawing->head, "$DIMTXSTY", &start, &end)){
/* variable exists */
part = dxf_find_attr_i2(start, end, 7, 0);
if (part != NULL){
strncpy(part->value.s_data, gui->drawing->dimtxsty, DXF_MAX_CHARS);
}
}
else{
dxf_attr_append(gui->drawing->head, 9, "$DIMTXSTY", DWG_LIFE);
dxf_attr_append(gui->drawing->head, 7, &gui->drawing->dimtxsty, DWG_LIFE);
}

nk_combo_close(gui->ctx);
break;
}
}
nk_combo_end(gui->ctx);
}

nk_label(gui->ctx, "Terminator:", NK_TEXT_LEFT);
res = nk_edit_string_zero_terminated(gui->ctx, NK_EDIT_SIMPLE|NK_EDIT_SIG_ENTER|NK_EDIT_SELECTABLE|NK_EDIT_AUTO_SELECT, gui->drawing->dimblk, DXF_MAX_CHARS, nk_filter_default);
if ((res & NK_EDIT_DEACTIVATED) || (res & NK_EDIT_COMMITED)){ /* probably, user change parameter string */
nk_edit_unfocus(gui->ctx);
/* change in DXF main struct */
dxf_node *start = NULL, *end = NULL, *part = NULL;
if(dxf_find_head_var(gui->drawing->head, "$DIMBLK", &start, &end)){
/* variable exists */
part = dxf_find_attr_i2(start, end, 1, 0);
if (part != NULL){
strncpy(part->value.s_data, gui->drawing->dimblk, DXF_MAX_CHARS);
}
}
else{
dxf_attr_append(gui->drawing->head, 9, "$DIMBLK", DWG_LIFE);
dxf_attr_append(gui->drawing->head, 1, &gui->drawing->dimblk, DWG_LIFE);
}
}

} else show_config = 0;
nk_end(gui->ctx);

Expand Down
9 changes: 2 additions & 7 deletions src/gui_toolbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,12 @@ int gui_tools_win (gui_obj *gui){
nk_layout_row_static(gui->ctx, 28, 28, 6);

if (nk_button_image_styled(gui->ctx, &gui->b_icon, nk_image_ptr(gui->svg_bmp[SVG_DIM_LINEAR]))){
gui->modal = DIMENSION;
gui->modal = DIM_LINEAR;
gui->step = 0;
}

/* another line --- temporay */
nk_layout_row_static(gui->ctx, 28, 28, 6);

if (nk_button_image_styled(gui->ctx, &gui->b_icon, nk_image_ptr(gui->svg_bmp[SVG_DIM_LINEAR]))){
gui->modal = DIMENSION;
gui->step = 0;
}
nk_layout_row_dynamic(gui->ctx, 28, 1); /*space*/
}

nk_layout_row_dynamic(gui->ctx, 10, 1); /*space*/
Expand Down

0 comments on commit 843a064

Please sign in to comment.