# OME/Web/XMLFileExportDTGED.pm #------------------------------------------------------------------------------- # # Copyright (C) 2003 Open Microscopy Environment # Massachusetts Institute of Technology, # National Institutes of Health, # University of Dundee # # # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # # Written by: Ilya G. Goldberg (based on Jean-Marie Burel ) # #------------------------------------------------------------------------------- package OME::Web::XMLFileExportDTGED ; use strict; use vars qw($VERSION); use OME; $VERSION = $OME::VERSION; use CGI; use OME::Web::DBObjTable; use OME::Tasks::OMEXMLImportExport; use OME::Tasks::ImageManager; use OME::Tasks::PixelsManager; use base qw(OME::Web); sub getPageTitle { return "Open Microscopy Environment - Export OME XML to browser" ; } { my $menu_text = "Export Image(s)"; sub getMenuText { return $menu_text } } sub getPageBody { my $self = shift; my $cgi = $self->CGI(); my $session = $self->Session(); my $factory = $session->Factory(); my $action = $cgi->param('action'); my $image_ids = $cgi->param('images_to_export'); my @images; my $body; my $approximate_file_size; foreach my $image_id ( split( m',', $image_ids ) ) { my $image = $factory->loadObject( 'OME::Image', $image_id ) or die "Couldn't load image id='$image_id'"; push @images, $image; foreach my $pixels ( $image->pixels() ) { my ($bytesPerPixel, $isSigned, $isFloat) = OME::Tasks::PixelsManager->getPixelTypeInfo( $pixels->PixelType() ); # size = bytesPerPixel * NumPixels * typical compression of 2/3's $approximate_file_size += $bytesPerPixel * $pixels->SizeX * $pixels->SizeY * $pixels->SizeZ * $pixels->SizeC * $pixels->SizeT * 2 / 3; } } $approximate_file_size /= 1048576; $approximate_file_size = sprintf( '%.2f', $approximate_file_size); if ( $action eq 'Export'){ my $filename = $session->getTemporaryFilename('XMLFileExport','ome') or die "OME::Web::XMLFileExport could not obtain temporary filename\n"; if (@images) { ### my $exporter= OME::Tasks::OMEXMLImportExport->new($session); my $exporter= OME::Web::XMLFileExportDTGED->new($session); $exporter->exportToXMLFile(\@images,$filename); my $downloadFilename = $cgi->param( 'filename' ); if( not defined $downloadFilename || $downloadFilename eq '' ) { if (scalar @images > 1) { $downloadFilename = $session->dataset()->name(); } else { $downloadFilename = $images[0]->name(); } } $downloadFilename =~ s/(\.ome)?$/\.ome/; $self->contentType('application/ome+xml'); return ('FILE',{ filename => $filename, temp => 1, downloadFilename => $downloadFilename}) ; } else { $body .= $cgi->p({class => 'ome_error'}, 'No image(s) selected. Please try again.'); } } $self->contentType('text/html'); my $tmpl_dir = $self->Session()->Configuration()->template_dir(); my $tmpl = HTML::Template->new( filename => 'XMLFileExport.tmpl', path => $tmpl_dir ); if( @images ) { $tmpl->param( selected_images => $self->Renderer()->renderArray( \@images, 'ref_mass', { type => 'OME::Image' } ) ); $tmpl->param( file_size => $approximate_file_size.' MB' ); $tmpl->param( size_warning => $approximate_file_size.' MB' ) if( $approximate_file_size >= 500 ); } $body .= $cgi->startform( -action => $self->pageURL( 'OME::Web::XMLFileExport' ) ). $tmpl->output(). $cgi->hidden( -name => 'images_to_export' ). $cgi->endform(); return ('HTML',$body); } ##################################################### # For each given image, exports all attributes from the # image import MEX to the specified XML file. # export($images,$file) # $images a ref to an array containing the image objects # $file MUST be absolute (path+name) sub exportToXMLFile { my ($self, $images, $file) = @_ ; my $session = OME::Session->instance(); my $factory = $session->Factory() ; # To-do check if can write in file my $exporter = OME::Tasks::OMEExport->new( session => $session ) ; my @exportObjects = () ; my $image_import_module = $session->Configuration()->image_import_module(); my $annotation_module = $session->Configuration()->annotation_module(); ###new my @outputs = $image_import_module->outputs(); foreach my $image (@$images) { push(@exportObjects,$image) ; # Add the image # Get the import mex for this image my $import_MEX = $factory->findObject ("OME::ModuleExecution", image_id => $image->id(), module => $image_import_module, ); ### New code ### # Get the DTGED annotation mex for this image my $dtged_MEX = $factory->findObject ("OME::ModuleExecution", image_id => $image->id(), module => $annotation_module ); ### I guess this selects all annotations for the image; ### how do I restrict additional results to those with Untyped Oputput ### of the form/semantic type defined as "DTGEDImageAnnotation" ? ### # Collect all the attributes produced by the import MEX my @untyped_outputs = $import_MEX->untypedOutputs(); my @dtged_outputs = $dtged_MEX->untypedOutputs(); ### New foreach my $output (@outputs,@untyped_outputs,@dtged_outputs) { ### Changed my $ST = $output->semantic_type(); next unless $ST; # Skip the untyped output itself # Get the output's attributes, and push them on the list my $attributes = OME::Tasks::ModuleExecutionManager-> getAttributesForMEX($import_MEX,$ST); push(@exportObjects,@$attributes); } } $exporter->buildDOM(\@exportObjects, ResolveAllRefs => 1, ExportSTDs => 0) ; $exporter->exportFile($file); return ; } 1;