Skip to content

Commit

Permalink
[FEATURE] 3D viewer selection (#1395)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
markusweigelt and sebastian-meyer authored Feb 28, 2025
1 parent 1ff16c9 commit 0f55669
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 17 deletions.
15 changes: 14 additions & 1 deletion Classes/Configuration/UseGroupsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ private function __construct()
'useGroupsDownload',
'useGroupsFulltext',
'useGroupsAudio',
'useGroupsScore'
'useGroupsScore',
'useGroupsModel'
];

foreach ($configKeys as $key) {
Expand Down Expand Up @@ -130,6 +131,18 @@ public function getImage(): array
return $this->getByType('Image');
}

/**
* Get the configuration for 'Model' use groups type.
*
* @access public
*
* @return array
*/
public function getModel(): array
{
return $this->getByType('Model');
}

/**
* Get the configuration for 'Score' use groups type.
*
Expand Down
87 changes: 78 additions & 9 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 @@ -113,6 +118,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 @@ -135,6 +144,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->useGroupsConfiguration->getModel()))) {
$this->setPage();
if (isset($this->requestData['page'])) {
$file = $this->getFile($this->requestData['page'], $this->useGroupsConfiguration->getModel());
$modelUrl = $file['url'] ?? '';
}
}
return $modelUrl;
}

/**
* Get the score file.
*
Expand Down Expand Up @@ -370,19 +403,55 @@ private function renderImageManipulationTool(): void
*/
private function renderModelDownloadTool(): void
{
// TODO: missing fileGrpsModelDownload, should be added to ext config as useGroupsModelDownload
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 @@ -10,6 +10,8 @@ On this page, you will find all the information needed to configure and embed an
:local:
:depth: 2

.. _Embedded 3D Viewer Setup:

Setup
=======

Expand All @@ -27,11 +29,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
15 changes: 15 additions & 0 deletions Documentation/Plugins/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,21 @@ 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.`

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.`

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 @@ -477,6 +477,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
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang_labels.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@
<target>Audio Datei Nutzungsgruppen: Komma-getrennte Liste der @USE Attributwerte der Audiodateien nach absteigender Priorität sortiert (Standard ist "AUDIO")</target>
<source>Audio file use groups: comma-separated list of @USE attribute values ordered by decreasing priority (default is "AUDIO")</source>
</trans-unit>
<trans-unit id="config.files.useGroupsModel">
<target>Modell Datei Nutzungsgruppen: Komma-getrennte Liste der @USE Attributwerte der Modelldateien nach absteigender Priorität sortiert (Standard ist "DEFAULT")</target>
<source>Model file use groups: comma-separated list of @USE attribute values ordered by decreasing priority (default is "DEFAULT")</source>
</trans-unit>
<trans-unit id="config.iiif.indexAnnotations">
<target>IIIF-Annotationen mit Motivation "painting" als Volltext behandeln?: Als Volltext behandelte Annotationen werden im Suchid idiert (Standard ist "FALSE")</target>
<source>Handle IIIF annotations with motivation "painting" as fulltext?: Handling annotations as fulltexts means they are ided (default is "FALSE")</source>
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 @@ -269,6 +269,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
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_labels.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@
<trans-unit id="config.files.useGroupsAudio">
<source>Audio file use groups: comma-separated list of @USE attribute values ordered by decreasing priority (default is "AUDIO")</source>
</trans-unit>
<trans-unit id="config.files.useGroupsModel">
<source>Model file use groups: comma-separated list of @USE attribute values ordered by decreasing priority (default is "DEFAULT")</source>
</trans-unit>
<trans-unit id="config.iiif.indexAnnotations">
<source>Handle IIIF annotations with motivation "painting" as fulltext?: Handling annotations as fulltexts means they are ided (default is "FALSE")</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
2 changes: 2 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ files.useGroupsDownload = DOWNLOAD
files.useGroupsFulltext = FULLTEXT
# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsScore
files.useGroupsScore = SCORE
# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsModel
files.useGroupsModel = DEFAULT
# cat=IIIF; type=boolean; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.iiif.indexAnnotations
iiif.indexAnnotations = 0
# cat=IIIF; type=int[1-2000]; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.iiif.thumbnailWidth
Expand Down

0 comments on commit 0f55669

Please sign in to comment.