Commit b32d1950 authored by claes's avatar claes

Select next object function improved

parent 26bbbab0
/* /*
* Proview $Id: wb_gre.cpp,v 1.4 2007-07-17 12:44:44 claes Exp $ * Proview $Id: wb_gre.cpp,v 1.5 2007-07-18 09:27:16 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -3032,19 +3032,34 @@ void WGre::select_nextobject( flow_eDirection dir) ...@@ -3032,19 +3032,34 @@ void WGre::select_nextobject( flow_eDirection dir)
int sts; int sts;
flow_GetSelectedNodes( flow_ctx, &fnode_list, &fnode_count); flow_GetSelectedNodes( flow_ctx, &fnode_list, &fnode_count);
if ( fnode_count != 1) { if ( fnode_count == 0)
message( "Select one object"); sel = 0;
return; else
} sel = fnode_list[0];
sel = fnode_list[0];
sts = flow_GetNextObject( flow_ctx, sel, dir, &next); if ( !sel || !flow_IsVisible( flow_ctx, sel, flow_eVisible_Partial)) {
if ( EVEN(sts)) { sts = flow_GetNextObject( flow_ctx, 0, dir, &next);
message( "Unable to find next object"); if ( EVEN(sts)) {
return; message( "Unable to find a visible object");
return;
}
flow_SelectClear( flow_ctx);
flow_SetHighlight( next, 1);
flow_SelectInsert( flow_ctx, next);
} }
else {
sts = flow_GetNextObject( flow_ctx, sel, dir, &next);
if ( EVEN(sts)) {
message( "Unable to find next object");
return;
}
flow_SelectClear( flow_ctx); flow_SelectClear( flow_ctx);
flow_SetHighlight( next, 1); flow_SetHighlight( next, 1);
flow_SelectInsert( flow_ctx, next); flow_SelectInsert( flow_ctx, next);
if ( !flow_IsVisible( flow_ctx, next, flow_eVisible_Full))
flow_CenterObject( flow_ctx, next);
}
} }
/* /*
* Proview $Id: flow.h,v 1.12 2007-05-11 15:07:21 claes Exp $ * Proview $Id: flow.h,v 1.13 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -73,7 +73,9 @@ typedef enum { ...@@ -73,7 +73,9 @@ typedef enum {
flow_eVisible_Full, flow_eVisible_Full,
flow_eVisible_Partial, flow_eVisible_Partial,
flow_eVisible_Top, flow_eVisible_Top,
flow_eVisible_Bottom flow_eVisible_Bottom,
flow_eVisible_Right,
flow_eVisible_Left
} flow_eVisible; } flow_eVisible;
typedef enum { typedef enum {
......
/* /*
* Proview $Id: flow_api.cpp,v 1.9 2007-07-17 12:40:50 claes Exp $ * Proview $Id: flow_api.cpp,v 1.10 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -698,3 +698,8 @@ int flow_GetNextObject( flow_tCtx ctx, flow_tNode object, flow_eDirection dir, ...@@ -698,3 +698,8 @@ int flow_GetNextObject( flow_tCtx ctx, flow_tNode object, flow_eDirection dir,
return ctx->get_next_object( (FlowArrayElem *)object, dir, return ctx->get_next_object( (FlowArrayElem *)object, dir,
(FlowArrayElem **)next); (FlowArrayElem **)next);
} }
int flow_IsVisible( flow_tCtx ctx, flow_tObject object, flow_eVisible type)
{
return ctx->is_visible( (FlowArrayElem *)object, type);
}
/* /*
* Proview $Id: flow_api.h,v 1.9 2007-07-17 12:40:50 claes Exp $ * Proview $Id: flow_api.h,v 1.10 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -237,6 +237,7 @@ void flow_SetClickSensitivity( flow_tCtx ctx, int value); ...@@ -237,6 +237,7 @@ void flow_SetClickSensitivity( flow_tCtx ctx, int value);
void flow_SetNoConObstacle( flow_tNodeClass nc, int no_obstacle); void flow_SetNoConObstacle( flow_tNodeClass nc, int no_obstacle);
int flow_GetNextObject( flow_tCtx ctx, flow_tNode object, flow_eDirection dir, int flow_GetNextObject( flow_tCtx ctx, flow_tNode object, flow_eDirection dir,
flow_tNode *next); flow_tNode *next);
int flow_IsVisible( flow_tCtx ctx, flow_tObject object, flow_eVisible type);
#if defined __cplusplus #if defined __cplusplus
} }
......
/* /*
* Proview $Id: flow_ctx.cpp,v 1.10 2007-07-17 12:40:50 claes Exp $ * Proview $Id: flow_ctx.cpp,v 1.11 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -1661,77 +1661,156 @@ int FlowCtx::radiobutton_cb( FlowArrayElem *object, int number, ...@@ -1661,77 +1661,156 @@ int FlowCtx::radiobutton_cb( FlowArrayElem *object, int number,
int FlowCtx::get_next_object( FlowArrayElem *object, flow_eDirection dir, int FlowCtx::get_next_object( FlowArrayElem *object, flow_eDirection dir,
FlowArrayElem **next) FlowArrayElem **next)
{ {
if ( object->type() != flow_eObjectType_Node) if ( object && object->type() != flow_eObjectType_Node)
return 0; return 0;
double ll_x, ll_y, ur_x, ur_y; double ll_x, ll_y, ur_x, ur_y;
double a_ll_x, a_ll_y, a_ur_x, a_ur_y; double a_ll_x, a_ll_y, a_ur_x, a_ur_y;
double x, y, a_x, a_y; double x, y, a_x, a_y;
double dir_angle; double dir_angle;
vector<NextElem> a0;
((FlowNode *)object)->measure( &ll_x, &ll_y, &ur_x, &ur_y); if ( !object) {
x = (ll_x + ur_x) / 2; // Chose a visible object
y = (ll_y + ur_y) / 2; double window_x_low, window_x_high;
double window_y_low, window_y_high;
switch ( dir) {
case flow_eDirection_Left: window_x_low = double(offset_x) / zoom_factor;
dir_angle = M_PI; window_x_high = double(offset_x + window_width) / zoom_factor;
break; window_y_low = double(offset_y) / zoom_factor;
case flow_eDirection_Right: window_y_high = double(offset_y + window_height) / zoom_factor;
dir_angle = 0;
break; for ( int i = 0; i < a.size(); i++) {
case flow_eDirection_Up:
dir_angle = -M_PI/2; if ( a[i]->type() == flow_eObjectType_Node) {
break; NextElem n;
case flow_eDirection_Down:
dir_angle = M_PI/2; ((FlowNode *)a[i])->measure( &a_ll_x, &a_ll_y, &a_ur_x, &a_ur_y);
break;
default: ; if ( a_ll_x >= window_x_low && a_ur_x <= window_x_high &&
a_ll_y >= window_y_low && a_ur_y <= window_y_high ) {
// Fully visible
switch ( dir) {
case flow_eDirection_Left:
n.rank = (window_x_high - a_ur_x)/
(window_x_high - window_x_low);
break;
case flow_eDirection_Right:
n.rank = (a_ll_x - window_x_low)/
(window_x_high - window_x_low);
break;
case flow_eDirection_Up:
n.rank = (window_y_high - a_ur_y)/
(window_y_high - window_y_low);
break;
case flow_eDirection_Down:
n.rank = (a_ll_y - window_y_low)/
(window_y_high - window_y_low);
break;
default: ;
}
n.elem = a[i];
a0.push_back( n);
}
else if ( ((a_ll_y >= window_y_low && a_ll_y <= window_y_high) ||
(a_ur_y >= window_y_low && a_ur_y <= window_y_high) ||
(a_ll_y <= window_y_low && a_ur_y >= window_y_high)) &&
((a_ll_x >= window_x_low && a_ll_x <= window_x_high) ||
(a_ur_x >= window_x_low && a_ur_x <= window_x_high) ||
(a_ll_x <= window_x_low && a_ur_x >= window_x_high))) {
// Partially visible
switch ( dir) {
case flow_eDirection_Left:
n.rank = (window_x_high - a_ur_x)/
(window_x_high - window_x_low) + 10;
break;
case flow_eDirection_Right:
n.rank = (a_ll_x - window_x_low)/
(window_x_high - window_x_low) + 10;
break;
case flow_eDirection_Up:
n.rank = (window_y_high - a_ur_y)/
(window_y_high - window_y_low) + 10;
break;
case flow_eDirection_Down:
n.rank = (a_ll_y - window_y_low)/
(window_y_high - window_y_low) + 10;
break;
default: ;
}
n.elem = a[i];
a0.push_back( n);
}
}
}
if ( a0.size() == 0)
return 0;
} }
else {
((FlowNode *)object)->measure( &ll_x, &ll_y, &ur_x, &ur_y);
x = ll_x;
y = ll_y;
switch ( dir) {
case flow_eDirection_Left:
dir_angle = M_PI;
break;
case flow_eDirection_Right:
dir_angle = 0;
break;
case flow_eDirection_Up:
dir_angle = -M_PI/2;
break;
case flow_eDirection_Down:
dir_angle = M_PI/2;
break;
default: ;
}
for ( int i = 0; i < a.size(); i++) {
if ( a[i] == object)
continue;
vector<NextElem> a0; if ( a[i]->type() == flow_eObjectType_Node) {
for ( int i = 0; i < a.size(); i++) {
if ( a[i] == object)
continue;
if ( a[i]->type() == flow_eObjectType_Node) {
((FlowNode *)a[i])->measure( &a_ll_x, &a_ll_y, &a_ur_x, &a_ur_y); ((FlowNode *)a[i])->measure( &a_ll_x, &a_ll_y, &a_ur_x, &a_ur_y);
if ( ll_x >= a_ll_x && ur_x <= a_ur_x && if ( ll_x >= a_ll_x && ur_x <= a_ur_x &&
ll_y >= a_ll_y && ur_y <= a_ur_y) ll_y >= a_ll_y && ur_y <= a_ur_y)
continue; continue;
a_x = (a_ll_x + a_ur_x) / 2; a_x = a_ll_x;
a_y = (a_ll_y + a_ur_y) / 2; a_y = a_ll_y;
NextElem n; NextElem n;
n.elem = a[i]; n.elem = a[i];
n.distance = sqrt((a_x - x)*(a_x - x) + (a_y - y)*(a_y - y)); n.distance = sqrt((a_x - x)*(a_x - x) + (a_y - y)*(a_y - y));
if ( fabs( a_y - y) < DBL_EPSILON) { if ( fabs( a_y - y) < DBL_EPSILON) {
if ( a_x > x) if ( a_x > x)
n.angle = 0; n.angle = 0;
else else
n.angle = M_PI; n.angle = M_PI;
} }
else { else {
n.angle = atan((a_x - x)/(a_y - y)) + M_PI / 2; n.angle = atan((a_x - x)/(a_y - y)) + M_PI / 2;
if ( (a_y - y) > 0) if ( (a_y - y) > 0)
n.angle -= M_PI; n.angle -= M_PI;
}
double rank_angel = n.angle + dir_angle;
double rank_distance = n.distance / (x_right - x_left);
if ( rank_angel > M_PI)
rank_angel -= 2 * M_PI;
rank_angel = fabs( rank_angel) / M_PI;
if ( rank_angel > 0.5)
continue;
n.rank = rank_angel + ( 0.3 + rank_distance);
a0.push_back( n);
} }
double rank_angel = n.angle + dir_angle;
double rank_distance = n.distance / (x_right - x_left);
if ( rank_angel > M_PI)
rank_angel -= 2 * M_PI;
rank_angel = fabs( rank_angel) / M_PI;
if ( rank_angel > 0.5)
continue;
n.rank = rank_angel + ( 0.3 + rank_distance);
a0.push_back( n);
} }
} }
if ( a0.size() == 0) if ( a0.size() == 0)
return 0; return 0;
// Find best object
double rank_min = 1E37; double rank_min = 1E37;
FlowArrayElem *rank_elem = 0; FlowArrayElem *rank_elem = 0;
for ( int i = 0; i < (int)a0.size(); i++) { for ( int i = 0; i < (int)a0.size(); i++) {
...@@ -1747,6 +1826,73 @@ int FlowCtx::get_next_object( FlowArrayElem *object, flow_eDirection dir, ...@@ -1747,6 +1826,73 @@ int FlowCtx::get_next_object( FlowArrayElem *object, flow_eDirection dir,
return 1; return 1;
} }
int FlowCtx::is_visible( FlowArrayElem *element, flow_eVisible type)
{
double ll_x, ll_y, ur_x, ur_y;
double window_x_low, window_x_high;
double window_y_low, window_y_high;
if ( element->type() != flow_eObjectType_Node)
return 0;
((FlowNode *)element)->measure( &ll_x, &ll_y, &ur_x, &ur_y);
window_x_low = double(offset_x) / zoom_factor;
window_x_high = double(offset_x + window_width) / zoom_factor;
window_y_low = double(offset_y) / zoom_factor;
window_y_high = double(offset_y + window_height) / zoom_factor;
switch ( type) {
case flow_eVisible_Full:
if ( ll_x >= window_x_low && ur_x <= window_x_high &&
ll_y >= window_y_low && ur_y <= window_y_high )
return 1;
else
return 0;
case flow_eVisible_Partial:
if ( ((ll_y >= window_y_low && ll_y <= window_y_high) ||
(ur_y >= window_y_low && ur_y <= window_y_high) ||
(ll_y <= window_y_low && ur_y >= window_y_high)) &&
((ll_x >= window_x_low && ll_x <= window_x_high) ||
(ur_x >= window_x_low && ur_x <= window_x_high) ||
(ll_x <= window_x_low && ur_x >= window_x_high)))
return 1;
else
return 0;
case flow_eVisible_Top:
if ( ur_y >= window_y_low && ur_y <= window_y_high &&
((ll_x >= window_x_low && ll_x <= window_x_high) ||
(ur_x >= window_x_low && ur_x <= window_x_high) ||
(ll_x <= window_x_low && ur_x >= window_x_high)))
return 1;
else
return 0;
case flow_eVisible_Bottom:
if ( ll_y >= window_y_low && ll_y <= window_y_high &&
((ll_x >= window_x_low && ll_x <= window_x_high) ||
(ur_x >= window_x_low && ur_x <= window_x_high) ||
(ll_x <= window_x_low && ur_x >= window_x_high)))
return 1;
else
return 0;
case flow_eVisible_Right:
if ( ur_x >= window_x_low && ur_y <= window_x_high &&
((ll_y >= window_y_low && ll_y <= window_y_high) ||
(ur_y >= window_y_low && ur_y <= window_y_high) ||
(ll_y <= window_y_low && ur_y >= window_y_high)))
return 1;
else
return 0;
case flow_eVisible_Left:
if ( ll_x >= window_x_low && ll_x <= window_x_high &&
((ll_y >= window_y_low && ll_y <= window_y_high) ||
(ur_y >= window_y_low && ur_y <= window_y_high) ||
(ll_y <= window_y_low && ur_y >= window_y_high)))
return 1;
else
return 0;
default: ;
}
return 0;
}
void FlowCtx::change_scrollbar() void FlowCtx::change_scrollbar()
{ {
......
/* /*
* Proview $Id: flow_ctx.h,v 1.6 2007-07-17 12:40:50 claes Exp $ * Proview $Id: flow_ctx.h,v 1.7 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -323,8 +323,9 @@ class FlowCtx { ...@@ -323,8 +323,9 @@ class FlowCtx {
int find_by_name_no_case( char *name, FlowArrayElem **element) int find_by_name_no_case( char *name, FlowArrayElem **element)
{ return a.find_by_name_no_case( name, element);}; { return a.find_by_name_no_case( name, element);};
void get_zoom( double *zoom) { *zoom = zoom_factor;}; void get_zoom( double *zoom) { *zoom = zoom_factor;};
int FlowCtx::get_next_object( FlowArrayElem *object, flow_eDirection dir, int get_next_object( FlowArrayElem *object, flow_eDirection dir,
FlowArrayElem **next); FlowArrayElem **next);
int is_visible( FlowArrayElem *element, flow_eVisible type);
~FlowCtx(); ~FlowCtx();
}; };
......
/* /*
* Proview $Id: ge_graph.cpp,v 1.41 2007-07-17 12:40:50 claes Exp $ * Proview $Id: ge_graph.cpp,v 1.42 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -1059,24 +1059,38 @@ void Graph::select_nextobject( glow_eDirection dir) ...@@ -1059,24 +1059,38 @@ void Graph::select_nextobject( glow_eDirection dir)
int sts; int sts;
sts = get_selected_object( &sel); sts = get_selected_object( &sel);
if ( EVEN(sts)) { if ( EVEN(sts))
message( 'E', "No object is selected"); sel = 0;
return; else {
} if ( grow_GetObjectType( sel) == glow_eObjectType_Con) {
if ( grow_GetObjectType( sel) == glow_eObjectType_Con) { message( 'E', "Select an object");
message( 'E', "Select an object"); return;
return; }
} }
sts = grow_GetNextObject( grow->ctx, sel, dir, &next); if ( !sel || !grow_IsVisible( grow->ctx, sel, glow_eVisible_Partial)) {
if ( EVEN(sts)) { sts = grow_GetNextObject( grow->ctx, 0, dir, &next);
message( 'E', "Unable to find next object"); if ( EVEN(sts)) {
return; message( 'E', "Unable to find visible object");
return;
}
grow_SelectClear( grow->ctx);
grow_SetHighlight( next, 1);
grow_SelectInsert( grow->ctx, next);
} }
else {
sts = grow_GetNextObject( grow->ctx, sel, dir, &next);
if ( EVEN(sts)) {
message( 'E', "Unable to find next object");
return;
}
grow_SelectClear( grow->ctx); grow_SelectClear( grow->ctx);
grow_SetHighlight( next, 1); grow_SetHighlight( next, 1);
grow_SelectInsert( grow->ctx, next); grow_SelectInsert( grow->ctx, next);
if ( !grow_IsVisible( grow->ctx, next, glow_eVisible_Partial))
grow_CenterObject( grow->ctx, next);
}
} }
int Graph::get_selected_object( grow_tObject *object) int Graph::get_selected_object( grow_tObject *object)
......
/* /*
* Proview $Id: glow.h,v 1.21 2007-07-04 13:28:05 claes Exp $ * Proview $Id: glow.h,v 1.22 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -312,6 +312,15 @@ typedef enum { ...@@ -312,6 +312,15 @@ typedef enum {
glow_eCorner_Right //!< Right corners glow_eCorner_Right //!< Right corners
} glow_eCorner; } glow_eCorner;
typedef enum {
glow_eVisible_Full,
glow_eVisible_Partial,
glow_eVisible_Top,
glow_eVisible_Bottom,
glow_eVisible_Left,
glow_eVisible_Right
} glow_eVisible;
//! Text Fonts //! Text Fonts
typedef enum { typedef enum {
glow_eFont_Helvetica, //!< Font Helvetica glow_eFont_Helvetica, //!< Font Helvetica
...@@ -322,10 +331,10 @@ typedef enum { ...@@ -322,10 +331,10 @@ typedef enum {
} glow_eFont; } glow_eFont;
typedef enum { typedef enum {
glow_eDynamicType_Object, glow_eDynamicType_Object,
glow_eDynamicType_SubGraph, glow_eDynamicType_SubGraph,
glow_eDynamicType_SubGraphEnd glow_eDynamicType_SubGraphEnd
} glow_eDynamicType; } glow_eDynamicType;
//! Type of shadow drawn for an object //! Type of shadow drawn for an object
typedef enum { typedef enum {
......
/* /*
* Proview $Id: glow_growapi.cpp,v 1.31 2007-07-17 12:43:54 claes Exp $ * Proview $Id: glow_growapi.cpp,v 1.32 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -4410,6 +4410,11 @@ int grow_GetNextObject( grow_tCtx ctx, grow_tObject object, glow_eDirection dir, ...@@ -4410,6 +4410,11 @@ int grow_GetNextObject( grow_tCtx ctx, grow_tObject object, glow_eDirection dir,
return ctx->get_next_object( (GlowArrayElem *)object, dir, (GlowArrayElem **)next); return ctx->get_next_object( (GlowArrayElem *)object, dir, (GlowArrayElem **)next);
} }
int grow_IsVisible( grow_tCtx ctx, grow_tObject object, glow_eVisible type)
{
return ctx->is_visible( (GlowArrayElem *)object, type);
}
/*@}*/ /*@}*/
......
/* /*
* Proview $Id: glow_growapi.h,v 1.26 2007-07-17 12:43:54 claes Exp $ * Proview $Id: glow_growapi.h,v 1.27 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -2846,6 +2846,7 @@ extern "C" { ...@@ -2846,6 +2846,7 @@ extern "C" {
glow_eScaleType type); glow_eScaleType type);
int grow_GetNextObject( grow_tCtx ctx, grow_tObject object, glow_eDirection dir, int grow_GetNextObject( grow_tCtx ctx, grow_tObject object, glow_eDirection dir,
grow_tObject *next); grow_tObject *next);
int grow_IsVisible( grow_tCtx ctx, grow_tObject object, glow_eVisible type);
/*@}*/ /*@}*/
#if defined __cplusplus #if defined __cplusplus
......
/* /*
* Proview $Id: glow_growctx.cpp,v 1.25 2007-07-17 12:43:54 claes Exp $ * Proview $Id: glow_growctx.cpp,v 1.26 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -3896,11 +3896,13 @@ void GrowCtx::delete_menu_child( GlowArrayElem *parent) ...@@ -3896,11 +3896,13 @@ void GrowCtx::delete_menu_child( GlowArrayElem *parent)
int GrowCtx::get_next_object( GlowArrayElem *object, glow_eDirection dir, int GrowCtx::get_next_object( GlowArrayElem *object, glow_eDirection dir,
GlowArrayElem **next) GlowArrayElem **next)
{ {
if ( !(object->type() == glow_eObjectType_GrowNode || if ( object &&
!(object->type() == glow_eObjectType_GrowNode ||
object->type() == glow_eObjectType_GrowSlider || object->type() == glow_eObjectType_GrowSlider ||
object->type() == glow_eObjectType_GrowGroup || object->type() == glow_eObjectType_GrowGroup ||
object->type() == glow_eObjectType_GrowTrend || object->type() == glow_eObjectType_GrowTrend ||
object->type() == glow_eObjectType_GrowBar)) { object->type() == glow_eObjectType_GrowBar ||
object->type() == glow_eObjectType_GrowText)) {
return 0; return 0;
} }
...@@ -3908,73 +3910,158 @@ int GrowCtx::get_next_object( GlowArrayElem *object, glow_eDirection dir, ...@@ -3908,73 +3910,158 @@ int GrowCtx::get_next_object( GlowArrayElem *object, glow_eDirection dir,
double a_ll_x, a_ll_y, a_ur_x, a_ur_y; double a_ll_x, a_ll_y, a_ur_x, a_ur_y;
double x, y, a_x, a_y; double x, y, a_x, a_y;
double dir_angle; double dir_angle;
vector<NextElem> a0;
object->measure( &ll_x, &ll_y, &ur_x, &ur_y); if ( !object) {
x = (ll_x + ur_x) / 2; // Chose a visible object
y = (ll_y + ur_y) / 2; double window_x_low, window_x_high;
double window_y_low, window_y_high;
switch ( dir) {
case glow_eDirection_Left: window_x_low = double(mw.offset_x) / mw.zoom_factor_x;
dir_angle = M_PI; window_x_high = double(mw.offset_x + mw.window_width) / mw.zoom_factor_x;
break; window_y_low = double(mw.offset_y) / mw.zoom_factor_y;
case glow_eDirection_Right: window_y_high = double(mw.offset_y + mw.window_height) / mw.zoom_factor_y;
dir_angle = 0;
break; for ( int i = 0; i < a.size(); i++) {
case glow_eDirection_Up:
dir_angle = -M_PI/2; if ( a[i]->type() == glow_eObjectType_GrowNode ||
break; a[i]->type() == glow_eObjectType_GrowSlider ||
case glow_eDirection_Down: a[i]->type() == glow_eObjectType_GrowGroup ||
dir_angle = M_PI/2; a[i]->type() == glow_eObjectType_GrowTrend ||
break; a[i]->type() == glow_eObjectType_GrowBar ||
default: ; a[i]->type() == glow_eObjectType_GrowText) {
NextElem n;
a[i]->measure( &a_ll_x, &a_ll_y, &a_ur_x, &a_ur_y);
if ( a_ll_x >= window_x_low && a_ur_x <= window_x_high &&
a_ll_y >= window_y_low && a_ur_y <= window_y_high ) {
// Fully visible
switch ( dir) {
case glow_eDirection_Left:
n.rank = (window_x_high - a_ur_x)/
(window_x_high - window_x_low);
break;
case glow_eDirection_Right:
n.rank = (a_ll_x - window_x_low)/
(window_x_high - window_x_low);
break;
case glow_eDirection_Up:
n.rank = (window_y_high - a_ur_y)/
(window_y_high - window_y_low);
break;
case glow_eDirection_Down:
n.rank = (a_ll_y - window_y_low)/
(window_y_high - window_y_low);
break;
default: ;
}
n.elem = a[i];
a0.push_back( n);
}
else if ( ((a_ll_y >= window_y_low && a_ll_y <= window_y_high) ||
(a_ur_y >= window_y_low && a_ur_y <= window_y_high) ||
(a_ll_y <= window_y_low && a_ur_y >= window_y_high)) &&
((a_ll_x >= window_x_low && a_ll_x <= window_x_high) ||
(a_ur_x >= window_x_low && a_ur_x <= window_x_high) ||
(a_ll_x <= window_x_low && a_ur_x >= window_x_high))) {
// Partially visible
switch ( dir) {
case glow_eDirection_Left:
n.rank = (window_x_high - a_ur_x)/
(window_x_high - window_x_low) + 10;
break;
case glow_eDirection_Right:
n.rank = (a_ll_x - window_x_low)/
(window_x_high - window_x_low) + 10;
break;
case glow_eDirection_Up:
n.rank = (window_y_high - a_ur_y)/
(window_y_high - window_y_low) + 10;
break;
case glow_eDirection_Down:
n.rank = (a_ll_y - window_y_low)/
(window_y_high - window_y_low) + 10;
break;
default: ;
}
n.elem = a[i];
a0.push_back( n);
}
}
}
if ( a0.size() == 0)
return 0;
} }
else {
vector<NextElem> a0; object->measure( &ll_x, &ll_y, &ur_x, &ur_y);
for ( int i = 0; i < a.size(); i++) { x = (ll_x + ur_x) / 2;
if ( a[i] == object) y = (ll_y + ur_y) / 2;
continue;
switch ( dir) {
if ( a[i]->type() == glow_eObjectType_GrowNode || case glow_eDirection_Left:
a[i]->type() == glow_eObjectType_GrowSlider || dir_angle = M_PI;
a[i]->type() == glow_eObjectType_GrowGroup || break;
a[i]->type() == glow_eObjectType_GrowTrend || case glow_eDirection_Right:
a[i]->type() == glow_eObjectType_GrowBar) { dir_angle = 0;
break;
a[i]->measure( &a_ll_x, &a_ll_y, &a_ur_x, &a_ur_y); case glow_eDirection_Up:
if ( ll_x >= a_ll_x && ur_x <= a_ur_x && dir_angle = -M_PI/2;
ll_y >= a_ll_y && ur_y <= a_ur_y) break;
case glow_eDirection_Down:
dir_angle = M_PI/2;
break;
default: ;
}
for ( int i = 0; i < a.size(); i++) {
if ( a[i] == object)
continue; continue;
a_x = (a_ll_x + a_ur_x) / 2;
a_y = (a_ll_y + a_ur_y) / 2; if ( a[i]->type() == glow_eObjectType_GrowNode ||
a[i]->type() == glow_eObjectType_GrowSlider ||
a[i]->type() == glow_eObjectType_GrowGroup ||
a[i]->type() == glow_eObjectType_GrowTrend ||
a[i]->type() == glow_eObjectType_GrowBar ||
a[i]->type() == glow_eObjectType_GrowText) {
a[i]->measure( &a_ll_x, &a_ll_y, &a_ur_x, &a_ur_y);
if ( ll_x >= a_ll_x && ur_x <= a_ur_x &&
ll_y >= a_ll_y && ur_y <= a_ur_y)
continue;
a_x = (a_ll_x + a_ur_x) / 2;
a_y = (a_ll_y + a_ur_y) / 2;
NextElem n; NextElem n;
n.elem = a[i]; n.elem = a[i];
n.distance = sqrt((a_x - x)*(a_x - x) + (a_y - y)*(a_y - y)); n.distance = sqrt((a_x - x)*(a_x - x) + (a_y - y)*(a_y - y));
if ( fabs( a_y - y) < DBL_EPSILON) { if ( fabs( a_y - y) < DBL_EPSILON) {
if ( a_x > x) if ( a_x > x)
n.angle = 0; n.angle = 0;
else else
n.angle = M_PI; n.angle = M_PI;
} }
else { else {
n.angle = atan((a_x - x)/(a_y - y)) + M_PI / 2; n.angle = atan((a_x - x)/(a_y - y)) + M_PI / 2;
if ( (a_y - y) > 0) if ( (a_y - y) > 0)
n.angle -= M_PI; n.angle -= M_PI;
}
double rank_angel = n.angle + dir_angle;
double rank_distance = n.distance / (x_right - x_left);
if ( rank_angel > M_PI)
rank_angel -= 2 * M_PI;
rank_angel = fabs( rank_angel) / M_PI;
if ( rank_angel > 0.5)
continue;
n.rank = rank_angel + ( 0.3 + rank_distance);
a0.push_back( n);
} }
double rank_angel = n.angle + dir_angle;
double rank_distance = n.distance / (x_right - x_left);
if ( rank_angel > M_PI)
rank_angel -= 2 * M_PI;
rank_angel = fabs( rank_angel) / M_PI;
if ( rank_angel > 0.5)
continue;
n.rank = rank_angel + ( 0.3 + rank_distance);
a0.push_back( n);
} }
if ( a0.size() == 0)
return 0;
} }
if ( a0.size() == 0)
return 0;
double rank_min = 1E37; double rank_min = 1E37;
GlowArrayElem *rank_elem = 0; GlowArrayElem *rank_elem = 0;
...@@ -3990,3 +4077,68 @@ int GrowCtx::get_next_object( GlowArrayElem *object, glow_eDirection dir, ...@@ -3990,3 +4077,68 @@ int GrowCtx::get_next_object( GlowArrayElem *object, glow_eDirection dir,
*next = rank_elem; *next = rank_elem;
return 1; return 1;
} }
int GrowCtx::is_visible( GlowArrayElem *element, glow_eVisible type)
{
double ll_x, ll_y, ur_x, ur_y;
double window_x_low, window_x_high;
double window_y_low, window_y_high;
element->measure( &ll_x, &ll_y, &ur_x, &ur_y);
window_x_low = double(mw.offset_x) / mw.zoom_factor_x;
window_x_high = double(mw.offset_x + mw.window_width) / mw.zoom_factor_x;
window_y_low = double(mw.offset_y) / mw.zoom_factor_y;
window_y_high = double(mw.offset_y + mw.window_height) / mw.zoom_factor_y;
switch ( type) {
case glow_eVisible_Full:
if ( ll_x >= window_x_low && ur_x <= window_x_high &&
ll_y >= window_y_low && ur_y <= window_y_high )
return 1;
else
return 0;
case glow_eVisible_Partial:
if ( ((ll_y >= window_y_low && ll_y <= window_y_high) ||
(ur_y >= window_y_low && ur_y <= window_y_high) ||
(ll_y <= window_y_low && ur_y >= window_y_high)) &&
((ll_x >= window_x_low && ll_x <= window_x_high) ||
(ur_x >= window_x_low && ur_x <= window_x_high) ||
(ll_x <= window_x_low && ur_x >= window_x_high)))
return 1;
else
return 0;
case glow_eVisible_Top:
if ( ur_y >= window_y_low && ur_y <= window_y_high &&
((ll_x >= window_x_low && ll_x <= window_x_high) ||
(ur_x >= window_x_low && ur_x <= window_x_high) ||
(ll_x <= window_x_low && ur_x >= window_x_high)))
return 1;
else
return 0;
case glow_eVisible_Bottom:
if ( ll_y >= window_y_low && ll_y <= window_y_high &&
((ll_x >= window_x_low && ll_x <= window_x_high) ||
(ur_x >= window_x_low && ur_x <= window_x_high) ||
(ll_x <= window_x_low && ur_x >= window_x_high)))
return 1;
else
return 0;
case glow_eVisible_Right:
if ( ur_x >= window_x_low && ur_y <= window_x_high &&
((ll_y >= window_y_low && ll_y <= window_y_high) ||
(ur_y >= window_y_low && ur_y <= window_y_high) ||
(ll_y <= window_y_low && ur_y >= window_y_high)))
return 1;
else
return 0;
case glow_eVisible_Left:
if ( ll_x >= window_x_low && ll_x <= window_x_high &&
((ll_y >= window_y_low && ll_y <= window_y_high) ||
(ur_y >= window_y_low && ur_y <= window_y_high) ||
(ll_y <= window_y_low && ur_y >= window_y_high)))
return 1;
else
return 0;
default: ;
}
return 0;
}
/* /*
* Proview $Id: glow_growctx.h,v 1.12 2007-07-17 12:43:54 claes Exp $ * Proview $Id: glow_growctx.h,v 1.13 2007-07-18 09:26:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -780,6 +780,9 @@ class GrowCtx : public GlowCtx { ...@@ -780,6 +780,9 @@ class GrowCtx : public GlowCtx {
int get_next_object( GlowArrayElem *object, glow_eDirection dir, int get_next_object( GlowArrayElem *object, glow_eDirection dir,
GlowArrayElem **next); GlowArrayElem **next);
//! Check if object is visible. */
int GrowCtx::is_visible( GlowArrayElem *element, glow_eVisible type);
char name[40]; //!< Name of the context. char name[40]; //!< Name of the context.
grow_eMode edit_mode; //!< Current edit mode. grow_eMode edit_mode; //!< Current edit mode.
int conpoint_num_cnt; //!< Counter to get next number for when creating conpoints in a subgraph. int conpoint_num_cnt; //!< Counter to get next number for when creating conpoints in a subgraph.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment