Allow to specify the 3d model for a footprint.

This commit is contained in:
Jan Böhmer 2019-10-03 14:04:09 +02:00
parent d9fe77d0e8
commit 6645ab0b61
8 changed files with 100 additions and 45 deletions

View file

@ -53,16 +53,21 @@ abstract class Attachment extends NamedDBElement
* Based on: https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
* It will be used to determine if a attachment is a picture and therefore will be shown to user as preview.
*/
const PICTURE_EXTS = ['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png',
public const PICTURE_EXTS = ['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png',
'svg', 'webp'];
/**
* A list of extensions that will be treated as a 3D Model that can be shown to user directly in Part-DB.
*/
public const MODEL_EXTS = ['x3d'];
/**
* When the path begins with one of this placeholders
*/
const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%'];
public const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%'];
/** @var array Placeholders for attachments which using built in files. */
const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%'];
public const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%'];
/**
* @var bool
@ -101,7 +106,7 @@ abstract class Attachment extends NamedDBElement
/**
* Check if this attachement is a picture (analyse the file's extension).
* If the link is external, it is assumed that this is false.
* If the link is external, it is assumed that this is true.
*
* @return bool * true if the file extension is a picture extension
* * otherwise false
@ -118,6 +123,23 @@ abstract class Attachment extends NamedDBElement
return in_array(strtolower($extension), static::PICTURE_EXTS, true);
}
/**
* Check if this attachment is a 3D model and therfore can be directly shown to user.
* If the attachment is external, false is returned (3D Models must be internal).
* @return bool
*/
public function is3DModel() : bool
{
//We just assume that 3D Models are internally saved, otherwise we get problems loading them.
if ($this->isExternal()) {
return false;
}
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
return in_array(strtolower($extension), static::MODEL_EXTS, true);
}
/**
* Checks if the attachment file is externally saved (the database saves an URL)
* @return bool true, if the file is saved externally

View file

@ -98,7 +98,7 @@ class Footprint extends PartsContainingDBElement
protected $parts;
/**
* @var FootprintAttachment
* @var FootprintAttachment|null
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\FootprintAttachment")
* @ORM\JoinColumn(name="id_footprint_3d", referencedColumnName="id")
*/
@ -120,24 +120,12 @@ class Footprint extends PartsContainingDBElement
****************************************/
/**
* Get the filename of the picture (absolute path from filesystem root).
*
* @return string the saved filename in the DB
* * an empty string if there is no picture
* Returns the 3D Model associated with this footprint.
* @return FootprintAttachment|null
*/
public function getFilename(): string
public function getFootprint3d() : ?FootprintAttachment
{
return $this->filename;
}
/**
* Get the filename of the 3d model (absolute path from filesystem root).
* @return string * the absolute path to the model (from filesystem root), as a UNIX path (with slashes)
* * an empty string if there is no model
*/
public function get3dFilename(): string
{
return $this->filename_3d;
return $this->footprint_3d;
}
/********************************************************************************
@ -147,27 +135,14 @@ class Footprint extends PartsContainingDBElement
*********************************************************************************/
/**
* Change the filename of this footprint.
* @param string $new_filename The new file name
* @return Footprint
*/
public function setFilename(string $new_filename): self
{
$this->filename = $new_filename;
return $this;
}
/**
* Change the 3d model filename of this footprint.
* @param string $new_filename The new filename
*
* Sets the 3D Model associated with this footprint.
* @param FootprintAttachment|null $new_attachment
* @return Footprint
*/
public function set3dFilename(string $new_filename): self
public function setFootprint3d(?FootprintAttachment $new_attachment) : Footprint
{
$this->filename = $new_filename;
$this->footprint_3d = $new_attachment;
return $this;
}
}