mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 04:40:08 -07:00
Add LDViewService
Add service for converting LDRaw model files to stl format
This commit is contained in:
parent
0b589ba2ca
commit
a2a87fc8dc
@ -22,4 +22,7 @@ parameters:
|
|||||||
brickset_apikey: ~
|
brickset_apikey: ~
|
||||||
|
|
||||||
# Rebrickable API key obtainable at http://rebrickable.com/api/
|
# Rebrickable API key obtainable at http://rebrickable.com/api/
|
||||||
rebrickable_apikey: ~
|
rebrickable_apikey: ~
|
||||||
|
|
||||||
|
# Absolute path to OSMesa port of LDView
|
||||||
|
ldview_bin: /usr/bin/ldview
|
@ -17,6 +17,10 @@ services:
|
|||||||
class: AppBundle\Service\CollectionService
|
class: AppBundle\Service\CollectionService
|
||||||
arguments: ['@doctrine.orm.entity_manager', '@manager.brickset','@manager.rebrickable']
|
arguments: ['@doctrine.orm.entity_manager', '@manager.brickset','@manager.rebrickable']
|
||||||
|
|
||||||
|
service.ldview:
|
||||||
|
class: AppBundle\Service\LDViewService
|
||||||
|
arguments: ['%ldview_bin%', '@oneup_flysystem.ldraw_filesystem']
|
||||||
|
|
||||||
loader.rebrickable:
|
loader.rebrickable:
|
||||||
class: AppBundle\Command\Loader\RebrickableLoader
|
class: AppBundle\Command\Loader\RebrickableLoader
|
||||||
arguments: ['@doctrine.orm.entity_manager', '@manager.rebrickable', '%rebrickable_url%' ]
|
arguments: ['@doctrine.orm.entity_manager', '@manager.rebrickable', '%rebrickable_url%' ]
|
||||||
|
68
src/AppBundle/Service/LDViewService.php
Normal file
68
src/AppBundle/Service/LDViewService.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AppBundle\Service;
|
||||||
|
|
||||||
|
use League\Flysystem\File;
|
||||||
|
use League\Flysystem\Filesystem;
|
||||||
|
use Symfony\Component\Asset\Exception\LogicException;
|
||||||
|
use Symfony\Component\Process\ProcessBuilder;
|
||||||
|
|
||||||
|
class LDViewService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string LDView binary file path
|
||||||
|
*/
|
||||||
|
private $ldview;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \League\Flysystem\Filesystem
|
||||||
|
*/
|
||||||
|
private $stlStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LDViewService constructor.
|
||||||
|
*
|
||||||
|
* @param string $ldview Path to LDView OSMesa binary file
|
||||||
|
* @param Filesystem $stlStorage Filesystem for generated stl model files
|
||||||
|
*/
|
||||||
|
public function __construct($ldview, $stlStorage)
|
||||||
|
{
|
||||||
|
$this->ldview = $ldview;
|
||||||
|
$this->stlStorage = $stlStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert LDraw model from .dat format to .stl by using LDView
|
||||||
|
* stores created file to $stlStorage filesystem
|
||||||
|
*
|
||||||
|
* @param Filesystem $LDrawDir
|
||||||
|
*
|
||||||
|
* @return File
|
||||||
|
*/
|
||||||
|
public function datToStl($file, $LDrawDir)
|
||||||
|
{
|
||||||
|
$stlFilename = $file['filename'].'.stl';
|
||||||
|
|
||||||
|
if (!$this->stlStorage->has($stlFilename)) {
|
||||||
|
$builder = new ProcessBuilder();
|
||||||
|
$process = $builder
|
||||||
|
->setPrefix($this->ldview)
|
||||||
|
->setArguments([
|
||||||
|
$LDrawDir->getAdapter()->getPathPrefix().$file['path'],
|
||||||
|
'-LDrawDir='.$LDrawDir->getAdapter()->getPathPrefix(),
|
||||||
|
'-ExportFile='.$this->stlStorage->getAdapter()->getPathPrefix().$stlFilename,
|
||||||
|
])
|
||||||
|
->getProcess();
|
||||||
|
|
||||||
|
$process->run();
|
||||||
|
|
||||||
|
if (!$this->stlStorage->has($stlFilename)) {
|
||||||
|
throw new LogicException($file['basename'].': new file not found'); //TODO
|
||||||
|
} elseif (!$process->isSuccessful()) {
|
||||||
|
throw new LogicException($file['basename'].' : '.$process->getOutput()); //TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->stlStorage->get($stlFilename);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user