From 892cba67fba9c442d77be1d467e2152b188c3a81 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 18 Mar 2019 17:50:59 +0100 Subject: [roomplanner] Implement (auto)rotating SVG, make SVG pretty --- modules-available/roomplanner/api.inc.php | 5 +- .../roomplanner/inc/pvsgenerator.inc.php | 91 ++++++++++++++++++---- .../roomplanner/templates/svg-plan.html | 52 ++++++++++--- 3 files changed, 121 insertions(+), 27 deletions(-) diff --git a/modules-available/roomplanner/api.inc.php b/modules-available/roomplanner/api.inc.php index 1494ba28..055c6b2e 100644 --- a/modules-available/roomplanner/api.inc.php +++ b/modules-available/roomplanner/api.inc.php @@ -1,8 +1,9 @@ $highlightUuid]); + if ($locationId !== false) { + $locationId = $locationId['locationid']; + } + } $machines = self::getMachines($locationId); if (empty($machines)) return false; - PvsGenerator::boundingBox($machines, $minX, $minY, $maxX, $maxY); - $clientSizeX = 4; /* TODO: optimize */ - $clientSizeY = 4; /* TODO: optimize */ - $sizeX = max($maxX - $minX + $clientSizeX, 1); /* never negative */ - $sizeY = max($maxY - $minY + $clientSizeY, 1); /* and != 0 to avoid divide-by-zero in pvsmgr */ + + $ORIENTATION = ['north' => 2, 'east' => 3, 'south' => 0, 'west' => 1]; if (is_string($highlightUuid)) { - $highlightUuid = strtolower($highlightUuid); + $highlightUuid = strtoupper($highlightUuid); + } + // Figure out autorotate + $auto = ($rotate < 0); + if ($auto && $highlightUuid !== false) { + foreach ($machines as &$machine) { + if ($machine['machineuuid'] === $highlightUuid) { + $rotate = $ORIENTATION[$machine['rotation']]; + break; + } + } } + $rotate %= 4; + // Highlight given machine, rotate it's "keyboard" foreach ($machines as &$machine) { - if (strtolower($machine['machineuuid']) === $highlightUuid) { + if ($machine['machineuuid'] === $highlightUuid) { $machine['class'] = 'hl'; } + $machine['rotation'] = $ORIENTATION[$machine['rotation']] * 90; + } + PvsGenerator::boundingBox($machines, $minX, $minY, $maxX, $maxY); + $clientSizeX = 4; /* TODO: optimize */ + $clientSizeY = 4; /* TODO: optimize */ + $minX--; + $minY--; + $maxX++; + $maxY++; + $sizeX = max($maxX - $minX + $clientSizeX, 1); /* never negative */ + $sizeY = max($maxY - $minY + $clientSizeY, 1); /* and != 0 to avoid divide-by-zero in pvsmgr */ + if ($rotate === 0) { + $centerY = $centerX = 0; + } elseif ($rotate === 1) { + $centerX = $minX + min($sizeX, $sizeY) / 2; + $centerY = $minY + min($sizeX, $sizeY) / 2; + self::swap($sizeX, $sizeY); + } elseif ($rotate === 2) { + $centerX = $minX + $sizeX / 2; + $centerY = $minY + $sizeY / 2; + } else { + $centerX = $minX + max($sizeX, $sizeY) / 2; + $centerY = $minY + max($sizeX, $sizeY) / 2; + self::swap($sizeX, $sizeY); } return Render::parse('svg-plan', [ - 'width' => $sizeX + 2, - 'height' => $sizeY + 2, - 'minX' => $minX - 1, - 'minY' => $minY - 1, + 'width' => $sizeX, + 'height' => $sizeY, + 'centerX' => $centerX, + 'centerY' => $centerY, + 'rotate' => $rotate * 90, + 'shiftX' => -$minX, + 'shiftY' => -$minY, 'machines' => $machines, + 'line' => ['x1' => $minX, 'y1' => $maxY + $clientSizeY, + 'x2' => $maxX + $clientSizeX, 'y2' => $maxY + $clientSizeY], ], 'roomplanner'); // FIXME: Needs module param if called from api.inc.php } + private static function swap(&$a, &$b) + { + $tmp = $a; + $a = $b; + $b = $tmp; + } + /** * Get all clients for given room with IP and position. * @@ -197,11 +255,16 @@ class PvsGenerator if ($position === false || !isset($position['gridRow']) || !isset($position['gridCol'])) continue; // TODO: Remove entry/set to NULL? + $rotation = 'north'; + if (preg_match('/(north|east|south|west)/', $position['itemlook'], $out)) { + $rotation = $out[1]; + } $machines[] = array( 'machineuuid' => $row['machineuuid'], 'clientip' => $row['clientip'], 'gridRow' => $position['gridRow'], 'gridCol' => $position['gridCol'], + 'rotation' => $rotation, ); } diff --git a/modules-available/roomplanner/templates/svg-plan.html b/modules-available/roomplanner/templates/svg-plan.html index 1fdb5d1a..5e1e13b2 100644 --- a/modules-available/roomplanner/templates/svg-plan.html +++ b/modules-available/roomplanner/templates/svg-plan.html @@ -7,24 +7,54 @@ height="{{height}}mm"> - + + + + + + + + + + + + {{#machines}} - + + + + {{/machines}} -- cgit v1.2.3-55-g7522