Commit edfca26f authored by Russ Fish's avatar Russ Fish

Add optional "ghosting" of overlaid nodes from all of the other floors as hollow dots

on the map.  Use a checkbox for control.  Turned at first by default.

Add scale 0 to use the thumbnail (40% reduced) images.  Scale 1 is still the default.

Declutter www by moving the static images into a www/floormap subdirectory.
parent a68e6097
......@@ -12,15 +12,17 @@ use File::Basename;
# TODO: Deal with multiple buildings? Currently defaults to MEB!
#
sub usage {
print STDERR "Usage: floormap [-t] [-T] [-o <prefix>] ";
print STDERR "Usage: floormap [-t] [-T] [-g] [-o <prefix>] ";
print STDERR "[-s <scale>] | [-c <map_x>,<_y>] ";
print STDERR "[-S <last_scale> -C <last_x>,<_y>] -O <last_x_off>,<_y>] ";
print STDERR "[-f <floor>] [<building>]";
print STDERR "\nor\n";
print STDERR "Usage: floormap [-t] [-T] [-o <prefix>] ";
print STDERR "Usage: floormap [-t] [-T] [-g] [-o <prefix>] ";
print STDERR "[-s <scale>] | [-c <map_x>,<_y>] ";
print STDERR "[-S <last_scale> -C <last_x>,<_y>] -O <last_x_off>,<_y>] ";
print STDERR "[-e <pid,eid>] [<building>]\n";
print STDERR "\nor\n";
print STDERR "Usage: floormap [-k] [-o <prefix>] ";
exit(-1);
}
......@@ -33,11 +35,12 @@ sub dprint($) {
if ($debug);
}
my $optlist = "df:o:s:c:S:C:O:e:tTak";
my $optlist = "df:o:s:c:S:C:O:e:tTakg";
my $notitles = 0; # This suppresses titles surrounding the output map.
my $showany = 0; # When showing specific floor, showany is turned on.
my $mereuser = 1;
my $cleanup = 0;
my $ghost = 0; # Overlay ghost nodes from all floors onto each map.
my $building;
my $floor;
......@@ -64,7 +67,7 @@ my $last_x = 0; # The UNZOOMED, and hence un-offset, previous click point.
my $last_y = 0;
my $last_notitles = 0; # This says there were no titles around the previous images.
# The image produced for each floor will be this size.
# The image produced for each floor will be this size, except when using thumbnails.
my $out_width = 792;
my $out_height = 492;
......@@ -146,19 +149,35 @@ if (defined($options{"t"})) {
if (defined($options{"T"})) {
$last_notitles = 1;
}
if (defined($options{"g"})) {
$ghost = 1;
}
if (defined($options{"f"})) {
$floor = $options{"f"};
$showany = 1;
}
if (defined($options{"s"})) {
# Scale by half-integer factors: 1=>1, 2=>1.5, 3=>2, etc.
$scale_arg = $options{"s"};
$scale = ( $scale_arg + 1 ) / 2;
if ($scale_arg > 0) {
# Scale by half-integer factors: 1=>1, 2=>1.5, 3=>2, etc.
$scale = ( $scale_arg + 1 ) / 2;
}
else {
# Scale_arg 0 means to use the 40% size thumbnail images.
$scale = 0.4;
}
dprint "scale arg $scale_arg, scaling factor $scale\n";
}
if (defined($options{"S"})) {
$last_scale_arg = $options{"S"};
$last_scale = ( $last_scale_arg + 1 ) / 2;
if ($last_scale_arg > 0) {
# Scale by half-integer factors: 1=>1, 2=>1.5, 3=>2, etc.
$last_scale = ( $last_scale_arg + 1 ) / 2;
}
else {
# Scale_arg 0 means to use the 40% size thumbnail images.
$last_scale = 0.4;
}
dprint "last_scale arg $last_scale_arg, last scaling factor $last_scale\n";
# Do this now so $scale is defined when reading in images.
......@@ -245,11 +264,14 @@ elsif (@ARGV == 1) {
#
# Gather image data from DB.
#
# Scale_arg 0 means to use the 40% size thumbnail images.
my $path_col = ($scale_arg == 0 ? "thumb_path" : "image_path");
my $db_scale = max($scale_arg, 1);
my $query_result =
DBQueryFatal("select b.building,b.title,f.floor,f.image_path ".
DBQueryFatal("select b.building,b.title,f.floor,f.$path_col ".
" from buildings as b ".
"left join floorimages as f on f.building=b.building ".
"where f.scale=$scale_arg");
"where f.scale=$db_scale");
if (!$query_result->numrows) {
die("*** $0:\n".
......@@ -264,7 +286,7 @@ while (my ($building,$title,$floor,$image) = $query_result->fetchrow_array()) {
$baseimages{$building}->{"floors"} = {};
}
$image = "$TB/www/$image"
$image = "$TB/www/floormap/$image"
if (dirname($image) eq ".");
dprint "image $image\n";
......@@ -354,7 +376,7 @@ else {
writefiles($images->[0], @areamaps);
## Append the component images in the shell, until the Perl function is fixed.
dprint "Last image is $img_n.";
dprint "Last image is $img_n.\n";
if ($img_n > 0) {
my @args = ("convert", "${prefix}.jpg.*", "-append", "${prefix}.jpg");
dprint "@args\n";
......@@ -381,15 +403,22 @@ sub dofloor($$)
# Grab the nodes on this floor in this building. We want to know
# their allocation status so we know what colors to use.
#
my $query_result =
DBQueryFatal("select loc.*,r.pid,r.eid,r.vname ".
" from location_info as loc ".
"left join reserved as r on r.node_id=loc.node_id ".
"where loc.floor='$floor' and loc.building='$building'");
my $query = "select loc.*,r.pid,r.eid,r.vname ".
" from location_info as loc ".
"left join reserved as r on r.node_id=loc.node_id ".
"where loc.building='$building'";
my $query_result = DBQueryFatal($query . " and loc.floor='$floor'");
my $newnodes_query = "select * from new_nodes ".
"where building='$building'";
my $newnodes_result = DBQueryFatal($newnodes_query . " and floor='$floor'");
my $newnodes_result =
DBQueryFatal("select * from new_nodes ".
"where floor='$floor' and building='$building'");
# When ghosting is turned on, get nodes from all floors to be overlaid.
my ($ghost_result, $ghost_newnodes_result);
if ($ghost) {
$ghost_result = DBQueryFatal($query);
$ghost_newnodes_result = DBQueryFatal($newnodes_query);
}
if ($mereuser) {
if (!$query_result->numrows && !$showany) {
......@@ -479,10 +508,10 @@ sub dofloor($$)
next
if ($mereuser);
$table = $newnodes_result;
$table = ($ghost ? $ghost_newnodes_result : $newnodes_result);
}
else {
$table = $query_result;
$table = ($ghost ? $ghost_result : $query_result);
}
while (my $rowref = $table->fetchrow_hashref()) {
......@@ -511,8 +540,14 @@ sub dofloor($$)
$color = 'blue';
}
my $x2 = $x + $DOT_RAD;
$err = $baseimage->Draw(fill=>$color, primitive=>'circle',
points=>"$x,$y $x2,$y");
if ($ghost && $rowref->{"floor"} != $floor) {
$err = $baseimage->Draw(stroke=>$color, strokewidth=>'1.5',
primitive=>'circle', points=>"$x,$y $x2,$y");
}
else {
$err = $baseimage->Draw(fill=>$color,
primitive=>'circle', points=>"$x,$y $x2,$y");
}
warn "$err" if "$err";
$err = $baseimage->Annotate(fill=>'black', x=>$x+$LX, y=>$y+$LY,
text=>"$label");
......@@ -557,7 +592,8 @@ sub dofloor($$)
$err = $baseimage->Border(fill=>'white', width=>0, height=>$head_height);
warn "$err" if "$err";
$err = $baseimage->Annotate(fill=>'black', x=>10, y=>40,
font=>"/usr/testbed/lib/arial.ttf", pointsize=>32,
font=>"/usr/testbed/lib/arial.ttf",
pointsize=>($scale_arg == 0 ? 16 : 32),
text=>"$floor_label");
warn "$err" if "$err";
......@@ -720,6 +756,8 @@ sub writefiles($@)
"value=\"$curr_x\">\n";
print STATE " <input type=\"hidden\" name=\"last_y\" " .
"value=\"$curr_y\">\n";
print STATE " <input type=\"hidden\" name=\"last_ghost\" " .
"value=\"$ghost\">\n";
if ($notitles) {
print STATE " <input type=\"hidden\" name=\"last_notitles\" " .
"value=\"$notitles\">\n";
......
......@@ -43,6 +43,8 @@ FILES += $(SRCDIR)/.htaccess $(SRCDIR)/error.shtml $(SRCDIR)/ssh-mime.pl \
AUTOICONS = $(wildcard $(SRCDIR)/autostatus-icons/*.gif)
AUTOICONS += $(wildcard $(SRCDIR)/autostatus-icons/*.png)
FLOORMAPFILES = $(wildcard $(SRCDIR)/floormap/*.jpg)
PIXFILES = $(wildcard $(SRCDIR)/pix/*.jpg)
PIXFILES += $(wildcard $(SRCDIR)/pix/*.gif)
......@@ -111,6 +113,7 @@ endif
# Kill the directory part of the names. The vpath rule will do the rest.
#
ALLFILES = $(notdir $(FILES))
ALLFLOORMAPS = $(notdir $(FLOORMAPFILES))
ALLPIXES = $(notdir $(PIXFILES))
ALLDOCS = $(notdir $(DOCFILES))
ALLTUTS = $(notdir $(TUTFILES))
......@@ -124,6 +127,7 @@ ALLHY = $(notdir $(HYFILES))
ALLUSRP = $(notdir $(USRPFILES))
install: $(addprefix $(INSTALL_WWWDIR)/, $(ALLFILES)) \
$(addprefix $(INSTALL_WWWDIR)/floormap/, $(ALLFLOORMAPS)) \
$(addprefix $(INSTALL_WWWDIR)/pix/, $(ALLPIXES)) \
$(addprefix $(INSTALL_WWWDIR)/tutorial/, $(ALLTUTS)) \
$(addprefix $(INSTALL_WWWDIR)/doc/, $(ALLDOCS)) \
......
......@@ -67,6 +67,9 @@ else {
# THIS is ugly... Value= is not passed by IE on <input type=image>, so we wrap the
# scale value into the button name. Hence we will see coordinates of scale_1_x
# scale_2_x, etc. when the buttons are pressed. Decode to just a $scale value here.
if (isset($scale_0_x) && $scale_0_x != "") {
$scale = 0;
}
if (isset($scale_1_x) && $scale_1_x != "") {
$scale = 1;
}
......@@ -86,7 +89,7 @@ elseif (isset($scale_5_x) && $scale_5_x != "") {
#
# Verify numeric scale and centering arguments.
#
if (isset($scale) && $scale != "") {
if (isset($scale) && $scale !== "") { # "0" is a valid value for $scale.
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $scale)) {
PAGEARGERROR("Invalid scale argument.");
......@@ -119,7 +122,7 @@ else {
#
# We need the previous scale and click coords, and offsets to interpret new click coords!
#
if (isset($last_scale) && $last_scale != "") {
if (isset($last_scale) && $last_scale !== "") { # "0" is a valid value.
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $last_scale)) {
PAGEARGERROR("Invalid last_scale argument.");
......@@ -232,9 +235,8 @@ while ($row = mysql_fetch_array($query_result)) {
}
#
# Run the script. It will produce three output files; image, areamap, and state.
# We want to embed all of these images into the page we send back. This
# is painful!
# Run the Perl script. It will produce three output files; image, areamap, and state.
# We want to embed all of these images into the page we send back. This is painful!
#
# Need cleanup "handler" to make sure temp files get deleted!
#
......@@ -266,25 +268,34 @@ if (!preg_match("/^\/tmp\/([-\w]+)$/", $prefix, $matches)) {
}
$uniqueid = $matches[1];
$retval = SUEXEC($uid, "nobody", "webfloormap -o $prefix " .
(isset($pid) ? "-e $pid,$eid " : "") .
(isset($floor) ? "-f $floor " : "") .
(isset($building) ? "$building" : "") .
# Default the ghosting checkbox state to checked the first time through.
if (!isset($last_ghost)) {
$ghost = 1;
}
# From clicking on a zoom button.
(isset($scale) ? "-s $scale " : "") .
$perl_args = "-o $prefix " .
# From clicking on a zoom button.
(isset($scale) ? "-s $scale " : "") .
# From clicking on a map image.
(isset($map_x) ? "-c $map_x,$map_y " : "") .
# From clicking on a map image.
(isset($map_x) ? "-c $map_x,$map_y " : "") .
# Previous image state info came from an included .state
# file, previously output by the Perl script along with the map.
(isset($last_scale) ? "-S $last_scale " : "") .
(isset($last_x) ? "-C $last_x,$last_y " : "") .
(isset($last_x_off) ? "-O $last_x_off,$last_y_off " : "") .
(isset($last_notitles) && $last_notitles ? "-T " : ""),
# Previous image state info came from an included .state
# file, previously output by the Perl script along with the map.
(isset($last_scale) ? "-S $last_scale " : "") .
(isset($last_x) ? "-C $last_x,$last_y " : "") .
(isset($last_x_off) ? "-O $last_x_off,$last_y_off " : "") .
(isset($last_notitles) && $last_notitles ? "-T " : "") .
(isset($ghost) ? "-g " : "") .
SUEXEC_ACTION_IGNORE);
(isset($pid) ? "-e $pid,$eid " : "") .
(isset($floor) ? "-f $floor " : "") .
(isset($building) ? "$building" : ""); # Building arg must be last!
if (0) { ### Put the Perl script args into the page when debugging.
echo "\$btfv/floormap -d $perl_args\n";
}
$retval = SUEXEC($uid, "nobody", "webfloormap $perl_args", SUEXEC_ACTION_IGNORE);
if ($retval) {
SUEXECERROR(SUEXEC_ACTION_USERERROR);
......@@ -365,7 +376,7 @@ echo "</td> <td style=\" background-color: transparent\"> &nbsp; &nbsp; </td> <t
# Wrap the image and zoom controls together in an input form.
echo "<form method=\"get\" action=\"floormap.php3#zoom\">\n";
# Zoom controls may be clicked to set a new scale.
# Zoom controls may be clicked to set a new scale. Otherwise, it persists.
$curr_scale = (isset($scale) ? $scale : (isset($last_scale) ? $last_scale : 1));
echo " <a name=zoom></a>\n";
function zoom_btns($curr_scale) {
......@@ -373,15 +384,15 @@ echo " <table align=\"center\" border=\"2\" cellpadding=\"0\" cellspacing=\"2\"
echo " <tbody>\n";
echo " <tr>\n";
# Wrap the scale into the button name. Value= is not passed by IE.
echo " <td><input type=\"image\" src=\"btn_zoom_out.jpg\"\n";
echo " name=\"scale_" . max($curr_scale-1,1) . "\"><br></td>\n";
for ($i = 1; $i <= 5; $i++) {
echo " <td><input type=\"image\" src=\"floormap/btn_zoom_out.jpg\"\n";
echo " name=\"scale_" . max($curr_scale-1,0) . "\"><br></td>\n";
for ($i = 0; $i <= 5; $i++) {
$img = "btn_scale_" . $i . "_" . ($curr_scale==$i?"brt":"dim") . ".jpg";
echo " <td><input type=\"image\" src=\"$img\"\n";
echo " <td><input type=\"image\" src=\"floormap/$img\"\n";
echo " name=\"scale_$i\"><br></td>\n";
}
echo " <td><input type=\"image\" src=\"btn_zoom_in.jpg\"\n";
echo " name=\"scale_" . min($curr_scale+1,6) . "\"><br></td>\n";
echo " <td><input type=\"image\" src=\"floormap/btn_zoom_in.jpg\"\n";
echo " name=\"scale_" . min($curr_scale+1,5) . "\"><br></td>\n";
echo " </tr>\n";
echo " </tbody>\n";
echo " </table>\n";
......@@ -408,12 +419,17 @@ if (count($channels)) {
echo "</td> </tr> </table>\n";
# The image may be clicked to set a new center-point.
# The image may be clicked to get node info or set a new center-point.
echo " Click on the dots below to see information about the node.\n";
echo " <br>\n";
echo " Clicks elsewhere on the map set the center point for a zoomed-in view.\n";
echo " <br>\n";
echo " <input name=\"map\" type=\"image\" style=\"border: 2px solid\" ";
# The checkbox value is sent when the box is checked; nothing is sent otherwise.
echo " <input name=ghost type=checkbox value=\"1\"" .
(isset($ghost) ? " checked" : "") . ">\n"; # Current checkbox state.
echo " Show nodes on other floors as hollow dots.\n";
echo " <br>\n";
echo " <input name=map type=image style=\"border: 2px solid\" ";
echo "src=\"floormap_aux.php3?prefix=$uniqueid\" usemap=\"#floormap\">\n";
echo " <br>\n";
zoom_btns($curr_scale);
......
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