Skip to content

Commit

Permalink
Improve handling over-writing already existing views
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 13, 2024
1 parent 2da154a commit 71c6cee
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>org.embl.mobie</groupId>
<artifactId>mobie-viewer-fiji</artifactId>
<version>5.0.3</version>
<version>5.0.4</version>

<!-- force javadoc generation to fetch errors: -->
<!-- mvn javadoc:javadoc | grep error -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ protected void createAndSaveAffineTransformedImages(
affineTransformation,
movingImage.getName() + ", " + suffix );

MoBIE.getInstance().getViewManager().getViewsSaver().saveViewDialog( view );
MoBIE.getInstance().getViewManager().show( view );
if ( MoBIE.getInstance().getViewManager().getViewsSaver().saveViewDialog( view ) )
{
MoBIE.getInstance().getViewManager().show( view );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.scijava.command.BdvPlaygroundActionCommand;

@Plugin( type = BdvPlaygroundActionCommand.class, name = ViewerTransformLoggerCommand.NAME, menuPath = CommandConstants.CONTEXT_MENU_ITEMS_ROOT + ViewerTransformLoggerCommand.NAME )
public class ViewerTransformLoggerCommand implements BdvPlaygroundActionCommand
@Plugin( type = BdvPlaygroundActionCommand.class, name = CurrentLocationLoggerCommand.NAME, menuPath = CommandConstants.CONTEXT_MENU_ITEMS_ROOT + CurrentLocationLoggerCommand.NAME )
public class CurrentLocationLoggerCommand implements BdvPlaygroundActionCommand
{
static { net.imagej.patcher.LegacyInjector.preinit(); }

Expand Down Expand Up @@ -79,10 +79,13 @@ public void run()

// print
final Gson gson = JsonHelper.buildGson( false );
Logger.log( "# Current location " );
Logger.log( "To restore the view, any of below lines can be pasted into the \'location\' text field." );
Logger.log( "To share views with other people we recommend \'normalizedAffine\'." );

Logger.log( "" );
Logger.log( "# Current location" );
Logger.log( "" );
Logger.log( "- To restore the current location, any of below lines can be pasted into MoBIE's \"location\" field." );
Logger.log( "- To share views with other people we recommend \"normalizedAffine\"." );
Logger.log( "- Note that below \"position\" is the position of the window center (not of the mouse pointer)." );
Logger.log( "" );
Logger.log( gson.toJson( positionViewerTransform ) );
Logger.log( gson.toJson( affineViewerTransform ) );
Logger.log( gson.toJson( normalizedAffineViewerTransform ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import ij.ImagePlus;
import ij.io.FileSaver;
import net.imglib2.realtransform.AffineTransform3D;
import org.embl.mobie.command.context.AutomaticRegistrationCommand;
import org.embl.mobie.lib.transform.Transform;

import java.lang.reflect.Method;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/embl/mobie/lib/bdv/view/SliceViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
*/
package org.embl.mobie.lib.bdv.view;

import IceInternal.Ex;
import bdv.util.BdvHandle;
import bdv.viewer.SourceAndConverter;
import net.imglib2.realtransform.AffineTransform3D;
import org.embl.mobie.DataStore;
import org.embl.mobie.command.context.*;
import org.embl.mobie.command.view.ViewerTransformLoggerCommand;
import org.embl.mobie.command.view.CurrentLocationLoggerCommand;
import org.embl.mobie.MoBIE;
import org.embl.mobie.lib.annotation.SliceViewAnnotationSelector;
import org.embl.mobie.lib.bdv.MobieBdvSupplier;
Expand Down Expand Up @@ -126,7 +125,8 @@ public synchronized BdvHandle getBdvHandle()

private void installContextMenuAndKeyboardShortCuts( )
{
final SliceViewAnnotationSelector sliceViewAnnotationSelector = new SliceViewAnnotationSelector( bdvHandle, is2D, () -> moBIE.getViewManager().getAnnotationDisplays() );
final SliceViewAnnotationSelector sliceViewAnnotationSelector =
new SliceViewAnnotationSelector( bdvHandle, is2D, () -> moBIE.getViewManager().getAnnotationDisplays() );

sacService.registerAction( UNDO_SEGMENT_SELECTIONS, sourceAndConverters -> {
// TODO: Maybe only do this for the sacs at the mouse position
Expand All @@ -148,7 +148,8 @@ private void installContextMenuAndKeyboardShortCuts( )
actions.add( SourceAndConverterService.getCommandName( SourcesInfoCommand.class ) );
actions.add( SourceAndConverterService.getCommandName( ShowRasterImagesCommand.class ) );
actions.add( SourceAndConverterService.getCommandName( ScreenShotMakerCommand.class ) );
actions.add( SourceAndConverterService.getCommandName( ViewerTransformLoggerCommand.class ) );
// TODO https://github.com/mobie/mobie-viewer-fiji/issues/1152
actions.add( SourceAndConverterService.getCommandName( CurrentLocationLoggerCommand.class ) );
actions.add( SourceAndConverterService.getCommandName( BigWarpRegistrationCommand.class ) );
//actions.add( SourceAndConverterService.getCommandName( AutomaticRegistrationCommand.class ) );
actions.add( SourceAndConverterService.getCommandName( ManualTransformationCommand.class ) );
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/org/embl/mobie/lib/view/save/ViewSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ public ViewSaver( MoBIE moBIE) {
this.moBIE = moBIE;
}

public void saveViewDialog( View view )
public boolean saveViewDialog( View view )
{
final GenericDialog gd = new GenericDialog("Save view");
final GenericDialog gd = new GenericDialog("Save view " + ( view.getName() == null ? "" : view.getName()) );

gd.addChoice("Save to", new String[]{ FileLocation.CurrentProject.toString(), FileLocation.ExternalJSONFile.toString() }, saveToProjectOrFile );
gd.addFileField( "External JSON file", externalJsonPath, 70 );
gd.addMessage( "" );
gd.addStringField("View name", view.getName() != null ? view.getName() : "", 70 );
gd.addStringField( "View description", view.getDescription() != null ? view.getDescription() : "", 70 );
if ( view.getName() == null )
gd.addStringField("View name", "my-new-view-name", 35 );
gd.addStringField( "View description", view.getDescription() != null ? view.getDescription() : "My view description....", 70 );
gd.addCheckbox("Make view exclusive", view.isExclusive() != null ? view.isExclusive() : false );
gd.addMessage( "" );
gd.addChoice("Selection group", getSelectionGroupChoices(), uiSelectionChoice );
Expand All @@ -103,18 +104,27 @@ public void saveViewDialog( View view )
// fetch primary user input
saveToProjectOrFile = gd.getNextChoice();
externalJsonPath = gd.getNextString();
view.setName( UserInterfaceHelper.tidyString( gd.getNextString() ) );
if ( view.getName() == null )
view.setName( UserInterfaceHelper.tidyString( gd.getNextString() ) );
view.setDescription( gd.getNextString() );
view.setExclusive( gd.getNextBoolean() );
uiSelectionChoice = gd.getNextChoice();
String newSelectionGroupName = gd.getNextString();

if ( moBIE.getViews().containsKey( view.getName() ) )
{
GenericDialog dialog = new GenericDialog( "Overwrite view?" );
dialog.addMessage( view.getName() + " exists already; are you sure you want to overwrite it?" );
dialog.showDialog();
if ( ! dialog.wasOKed() ) {
return false;
}
}

// compute derived parameters
FileLocation fileLocation = FileLocation.valueOf( saveToProjectOrFile );
if ( view.isExclusive() )
view.setViewerTransform( new NormalizedAffineViewerTransform( moBIE.getViewManager().getSliceViewer().getBdvHandle() ) );
//else
// view.setViewerTransform( new NoViewerTransform() );

if ( uiSelectionChoice.equals( CREATE_SELECTION_GROUP ) )
view.setUiSelectionGroup( newSelectionGroupName );
Expand Down Expand Up @@ -145,6 +155,8 @@ public void saveViewDialog( View view )
saveNewViewToProject( view, "dataset.json" );
else if ( fileLocation == FileLocation.ExternalJSONFile )
saveNewViewToFileSystem( view, externalJsonPath );

return true;
}

@NotNull
Expand Down Expand Up @@ -230,7 +242,8 @@ private void saveNewViewToProject( View view, String viewJson ) {
// }
// }

private void addViewToUi( View view ) {
private void addViewToUi( View view )
{
moBIE.getViews().put( view.getName(), view );
Map<String, View > views = new HashMap<>();
views.put( view.getName(), view );
Expand Down Expand Up @@ -292,15 +305,11 @@ private boolean jsonExists( String jsonPath ) {
// }
// }

private void saveNewViewToAdditionalViewsJson( View view, String jsonPath ) throws IOException {

private void saveNewViewToAdditionalViewsJson( View view, String jsonPath ) throws IOException
{
AdditionalViews additionalViews;
if ( jsonExists( jsonPath ) ) {
additionalViews = new AdditionalViewsJsonParser().getViews( jsonPath );
if ( additionalViews.views.containsKey( view.getName() ) ) {
IJ.log( "View saving aborted - this view name already exists!" );
return;
}
} else {
additionalViews = new AdditionalViews();
additionalViews.views = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void writeDatasetJson( Dataset dataset, View view, String datasetJ

public static void writeAdditionalViewsJson( AdditionalViews additionalViews, View view, String jsonPath ) throws IOException
{
additionalViews.views.put(view.getName(), view);
additionalViews.views.put( view.getName(), view );

if (isGithub( jsonPath )) {
new ViewsGithubWriter( GitHubUtils.rawUrlToGitLocation( jsonPath ) ).writeViewToViewsJson( view );
Expand Down

0 comments on commit 71c6cee

Please sign in to comment.