Different vessel shapes

This commit is contained in:
2024-04-11 18:44:04 +02:00
parent eccb68e9a2
commit 806cc407eb
9 changed files with 1097 additions and 98 deletions
+55 -11
View File
@@ -80,6 +80,7 @@ switch ($submit = form_get_action()) {
$p[':ballast'] = gpc_get_int($_POST, 'ballast');
$p[':beltpos_aft'] = gpc_get_float($_POST, 'beltpos_aft');
$p[':beltpos_bow'] = gpc_get_float($_POST, 'beltpos_bow');
$p[':shapefile'] = gpc_get_string($_POST, 'shapefile');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
$fields = join(',', array_map(function($s) { return ltrim($s, ':') . '=' . $s; }, array_keys($p)));
$sth = $pdo->prepare("UPDATE vessel SET $fields WHERE vid=:vid");
@@ -143,22 +144,22 @@ echo "</form>\n";
// Get current vessel data
$sql = "SELECT vesselname, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, beltpos_aft, beltpos_bow, remarks "
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
. " remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$vid]);
$vessel = $sth->fetch();
?>
<?php /* <svg viewbox="0 0 1024 768">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
<rect x="0" y="0" width="1024" height="768" stroke="black" fill="none" />
<text x="0" y="20" font-size="12" fill="#ccc" text-anchor="start">Elizabethan 29</text>
<line x1="0" y1="0" x2="100" y2="100" />
</svg> */ ?>
<br>
// get vessel shape
// TODO predefine base shapes for different vessels
$shapefilepath = dirname(__FILE__).'/'.$g_shapedir.'/'.$vessel['shapefile'];
if (isset($vessel['shapefile']) and file_exists($shapefilepath)) {
$baseshape = file_get_contents($shapefilepath);
} else {
// use internal default shape
$baseshape = <<<EOT
<svg
width="680.8349"
height="205.42085"
@@ -185,6 +186,44 @@ $vessel = $sth->fetch();
transform="matrix(1,0,0,-1,-4.9118388e-8,123.69274)" />
</g>
</svg>
EOT;
}
$shape = new SimpleXMLElement($baseshape);
$g = $shape->addChild('g');
$g->addAttribute('id', 'boxlayout');
// line for belt
$line = $g->addChild('line');
$line->addAttribute('x1', '100');
$line->addAttribute('y1', '0');
$line->addAttribute('x2', '100');
$line->addAttribute('y2', '100');
$line->addAttribute('style', 'stroke:#ff0000;stroke-width:0.25px');
// rectangle for storage
$rect = $g->addChild('rect');
$rect->addAttribute('x', '2');
$rect->addAttribute('y', '14');
$rect->addAttribute('width', '20');
$rect->addAttribute('height', '26');
$rect->addAttribute('stroke', '#000');
$rect->addAttribute('stroke-width', '0.25px');
$rect->addAttribute('fill', '#57E389');
$rect->addAttribute('fill-opacity', '0.4');
// text with link
$link = $g->addChild('a');
$link->addAttribute('xlink:href', 'storage.php?f=view&id=1');
$text = $link->addChild('text', 'Box1');
$text->addAttribute('font-size', '3.5');
$text->addAttribute('x', '4');
$text->addAttribute('y', '18');
?>
<div class="container-fluid my-4">
<?=$shape->asXML()?>
</div>
<div class="container-fluid">
<div class="row my-4">
@@ -331,7 +370,8 @@ elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
$sql = "SELECT vesselname, vtype, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, beltpos_aft, beltpos_bow, remarks "
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
. " remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
@@ -385,6 +425,10 @@ $vessel = $sth->fetch(PDO::FETCH_OBJ);
<label for="beltpos_bow" class="form-label"><?=_('Belt position bow')?></label>
<input type="text" class="form-control" id="beltpos_bow" name="beltpos_bow" value="<?=format_float($vessel->beltpos_bow, 2) ?>">
</div>
<div class="mb-3">
<label for="shapefile" class="form-label"><?=_('Shapefile')?></label>
<input type="text" class="form-control" id="shapefile" name="shapefile" value="<?=$vessel->shapefile ?>">
</div>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$vessel->remarks ?></textarea>