Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] 3D viewer selection #1395

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 78 additions & 8 deletions Classes/Controller/ToolboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@

use Kitodo\Dlf\Common\AbstractDocument;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Middleware\Embedded3dViewer;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;

/**
* Controller class for plugin 'Toolbox'.
Expand Down Expand Up @@ -108,6 +113,10 @@ private function renderTools(): void
case 'scoretool':
$this->renderToolByName('renderScoreTool');
break;
case 'tx_dlf_viewerselectiontool':
case 'viewerselectiontool':
$this->renderToolByName('renderViewerSelectionTool');
break;
default:
$this->logger->warning('Incorrect tool configuration: "' . $this->settings['tools'] . '". Tool "' . $tool . '" does not exist.');
}
Expand All @@ -130,6 +139,30 @@ private function renderToolByName(string $tool): void
$this->view->assign($tool, true);
}

/**
* Get the URL of the model.
*
* Gets the URL of the model by parameter or from the configured file group of the document.
*
* @access private
*
* @return string
*/
private function getModelUrl(): string
{
$modelUrl = '';
if (!empty($this->requestData['model'])) {
$modelUrl = $this->requestData['model'];
} elseif (!($this->isDocMissingOrEmpty() || empty($this->settings['fileGrpsModelDownload']))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to properties from ext_conf_template.txt:
Example: GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpThumbs']);

$this->setPage();
if (isset($this->requestData['page'])) {
$file = $this->getFile($this->requestData['page'], GeneralUtility::trimExplode(',', $this->settings['fileGrpsModelDownload']));
$modelUrl = $file['url'] ?? '';
}
}
return $modelUrl;
}

/**
* Get image's URL and MIME type information's.
*
Expand Down Expand Up @@ -362,18 +395,55 @@ private function renderImageManipulationTool(): void
*/
private function renderModelDownloadTool(): void
{
if (
$this->isDocMissingOrEmpty()
|| empty($this->settings['fileGrpsModelDownload'])
) {
// Quit without doing anything if required variables are not set.
$modelUrl = $this->getModelUrl();
if ($modelUrl === '') {
$this->logger->debug("Model URL could not be determined");
return;
}
$this->view->assign('modelUrl', $modelUrl);
}

$this->setPage();

if (isset($this->requestData['page'])) {
$this->view->assign('modelDownload', $this->getFile($this->requestData['page'], GeneralUtility::trimExplode(',', $this->settings['fileGrpsModelDownload'])));
/**
* Renders the viewer selection tool
* Renders the viewer selection tool (used in template)
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*
* @access private
*
* @return void
* @throws InsufficientFolderAccessPermissionsException
*/
private function renderViewerSelectionTool(): void
{
$model = $this->getModelUrl();
if (!$model) {
$this->logger->debug("Model URL could not be determined");
return;
}

$pathInfo = PathUtility::pathinfo($model);
$modelFormat = strtolower($pathInfo["extension"]);
$viewers = [];
/** @var StorageRepository $storageRepository */
$storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
$defaultStorage = $storageRepository->getDefaultStorage();
if ($defaultStorage->hasFolder(Embedded3dViewer::VIEWER_FOLDER)) {
$viewerFolders = $defaultStorage->getFoldersInFolder($defaultStorage->getFolder(Embedded3dViewer::VIEWER_FOLDER));
if (count($viewerFolders) > 0) {
/** @var YamlFileLoader $yamlFileLoader */
$yamlFileLoader = GeneralUtility::makeInstance(YamlFileLoader::class);
foreach ($viewerFolders as $viewerFolder) {
if ($viewerFolder->hasFile(Embedded3dViewer::VIEWER_CONFIG_YML)) {
$fileIdentifier = $viewerFolder->getFile(Embedded3dViewer::VIEWER_CONFIG_YML)->getIdentifier();
$viewerConfig = $yamlFileLoader->load($defaultStorage->getName() . $fileIdentifier)["viewer"];
if (!empty($viewerConfig["supportedModelFormats"]) && in_array($modelFormat, array_map('strtolower', $viewerConfig["supportedModelFormats"]))) {
$viewers[] = (object) ['id' => $viewerFolder->getName(), 'name' => $viewerConfig["name"] ?? $viewerFolder->getName()];
}
}
}
$this->view->assign('viewers', $viewers);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion Documentation/Developers/Embedded3DViewer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The `model-viewer <https://modelviewer.dev>`_ is installed as the build-in stand
:local:
:depth: 2

.. _Embedded 3D Viewer Setup:

Setup
=======

Expand All @@ -25,11 +27,13 @@ Configuration

By default, the viewers from the folder ``dlf_3d_viewers`` are all active and can be accessed and tested via URL.

For this, only the parameter ``tx_dlf[viewer]`` with the name of the viewer and the encoded URL to the model via the parameter ``tx_dlf[model]`` need to be passed to the URL under which the plugin ``plugin.tx_dlf_embedded3dViewer`` is rendered.
For this, only the parameter ``tx_dlf[viewer]`` with the encoded subfolder name of the viewer needs to be passed to the URL where the plugin ``plugin.tx_dlf_embedded3dViewer`` is rendered.

.. note::
For example in the DFG Viewer, this is the page whose ID is set via the constant ``config.kitodoPageView``.

To render the model, the encoded URL to the METS document should be set using the parameter ``tx_dlf[id]``. Alternatively, it is possible to define the model directly with an encoded URL via the parameter ``tx_dlf[model]``.

Automatic selection of the viewer
-------

Expand Down
54 changes: 54 additions & 0 deletions Documentation/Plugins/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,60 @@ The fulltext is fetched and rendered by JavaScript into the `<div id="tx-dlf-ful

**Please note**: To allow JavaScript fetching the fulltext, the `CORS headers <https://en.wikipedia.org/wiki/Cross-origin_resource_sharing>`_ must be configured appropriate on the providing webserver.

Model download tool
^^^^^^^^^^^^^

This tool makes it possible to extract the model URL from the METS file or use the provided model parameter to provide a download URL.

:typoscript:`plugin.tx_dlf_modeldownloadtool.`

.. t3-field-list-table::
:header-rows: 1

- :Property:
Property
:Data Type:
Data type
:Values:
Values

- :Property:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you set up this property here?

fileGrps... config is configured in ext_conf_template.txt (

files.fileGrpImages = DEFAULT,MAX
)

Please move it there.

fileGrpsModelDownload
:Data Type:
:ref:`t3tsref:data-type-string`
:Values:
DEFAULT - single filegroup

MIN,DEFAULT,MAX - comma separated list of filegroups


Viewer selection tool
^^^^^^^^^^^^^

This tool can display a selection list of configured 3D viewers (from the "dlf_3d_viewers" directory see :ref:`Embedded 3D Viewer Setup`) that support the current model.

The model URL is extracted from the METS file or taken from the provided model parameter. The extension of the model is extracted from this URL and compared with the supported model formats specified in the respective viewer configuration.

:typoscript:`plugin.tx_dlf_viewerselectiontool.`

.. t3-field-list-table::
:header-rows: 1

- :Property:
Property
:Data Type:
Data type
:Values:
Values

- :Property:
fileGrpsModelDownload
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above.

:Data Type:
:ref:`t3tsref:data-type-string`
:Values:
DEFAULT - single filegroup

MIN,DEFAULT,MAX - comma separated list of filegroups

Search in Document Tool
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@
<source><![CDATA[Search in document]]></source>
<target><![CDATA[Im Dokument suchen]]></target>
</trans-unit>
<trans-unit id="tools.viewerselection.default" approved="yes">
<source><![CDATA[Default]]></source>
<target><![CDATA[Standard]]></target>
</trans-unit>
<trans-unit id="volume" approved="yes">
<source><![CDATA[volume]]></source>
<target><![CDATA[Band]]></target>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@
<trans-unit id="tools.searchindocument.loading">
<source><![CDATA[Loading...]]></source>
</trans-unit>
<trans-unit id="tools.viewerselection.default">
<source><![CDATA[Default]]></source>
</trans-unit>
<trans-unit id="search.logicalPage">
<source><![CDATA[Page]]></source>
</trans-unit>
Expand Down
33 changes: 27 additions & 6 deletions Resources/Private/Templates/Toolbox/Main.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,39 @@
</f:then>
</f:if>

<f:if condition="{renderModelDownloadTool} && {modelDownload}">
<f:if condition="{renderModelDownloadTool} && {modelUrl}">
<f:then>
<li>
<span class="tx-dlf-tools-modeldownload">
<f:link.external uri="{modelDownload.url}">
<f:translate key="downloadModel" />
</f:link.external>
</span>
<span class="tx-dlf-tools-modeldownload">
<f:link.external uri="{modelUrl}">
<f:translate key="downloadModel"/>
</f:link.external>
</span>
</li>
</f:then>
</f:if>

<f:if condition="{renderViewerSelectionTool} && {viewers}">
<f:then>
<form method="get" action="{f:uri.page(pageUid='{viewData.requestData.pageUid}')}">
<f:if condition="{viewData.requestData.id}">
<f:form.hidden name="tx_dlf[id]" value="{viewData.requestData.id}"/>
</f:if>
<f:if condition="{viewData.requestData.model}">
<f:form.hidden name="tx_dlf[model]" value="{viewData.requestData.model}"/>
</f:if>
<f:form.select id="tx-dlf-viewer-{viewData.uniqueId}" name="tx_dlf[viewer]"
options="{viewers}"
optionValueField="id"
optionLabelField="name"
value="{viewData.requestData.viewer}"
additionalAttributes="{'onchange': 'javascript:this.form.submit();'}"
prependOptionLabel="{f:translate(key: 'tools.viewerselection.default', extensionName: 'dlf')}">
</f:form.select>
<form>
</f:then>
</f:if>

<f:if condition="{renderFulltextTool}">
<f:then>
<li>
Expand Down
Loading