diff --git a/src/main/java/org/janelia/saalfeldlab/paintera/meshes/MeshExporterObj.java b/src/main/java/org/janelia/saalfeldlab/paintera/meshes/MeshExporterObj.java index 13fa81dd2..e81d99c68 100644 --- a/src/main/java/org/janelia/saalfeldlab/paintera/meshes/MeshExporterObj.java +++ b/src/main/java/org/janelia/saalfeldlab/paintera/meshes/MeshExporterObj.java @@ -15,12 +15,12 @@ public class MeshExporterObj extends MeshExporter { private long numVertices = 0; - public void exportMaterial(String path, final long[] ids, final Color[] colors) { + public void exportMaterial(String path, final String[] ids, final Color[] colors) { final String materialPath = path + ".mtl"; try (final FileWriter writer = new FileWriter(materialPath, false)) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < ids.length; i++) { - final long id = ids[i]; + final String id = ids[i]; final Color specularColor = colors[i]; final double red = specularColor.getRed(); final double green = specularColor.getGreen(); diff --git a/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/IntersectingSourceStatePreferencePaneNode.kt b/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/IntersectingSourceStatePreferencePaneNode.kt index 5b09c4f9d..e05d39dca 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/IntersectingSourceStatePreferencePaneNode.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/IntersectingSourceStatePreferencePaneNode.kt @@ -1,10 +1,18 @@ package org.janelia.saalfeldlab.paintera.state +import javafx.geometry.Pos import javafx.scene.Node +import javafx.scene.control.Button import javafx.scene.control.ColorPicker +import javafx.scene.layout.HBox +import javafx.scene.layout.VBox import org.janelia.saalfeldlab.fx.extensions.createNullableValueBinding +import org.janelia.saalfeldlab.paintera.meshes.MeshExporterObj +import org.janelia.saalfeldlab.paintera.meshes.MeshInfo +import org.janelia.saalfeldlab.paintera.meshes.managed.MeshManagerWithSingleMesh import org.janelia.saalfeldlab.paintera.meshes.ui.MeshSettingsController import org.janelia.saalfeldlab.paintera.meshes.ui.MeshSettingsController.Companion.addGridOption +import org.janelia.saalfeldlab.paintera.ui.source.mesh.MeshExporterDialog import org.janelia.saalfeldlab.util.Colors class IntersectingSourceStatePreferencePaneNode(private val state: IntersectingSourceState<*, *>) { @@ -12,7 +20,7 @@ class IntersectingSourceStatePreferencePaneNode(private val state: IntersectingS val node: Node get() { val manager = state.meshManager - val settings = manager.settings + val settings = manager.globalSettings return SourceState.defaultPreferencePaneNode(state.compositeProperty()).apply { children += MeshSettingsController(settings, state::refreshMeshes).createTitledPane( @@ -29,7 +37,36 @@ class IntersectingSourceStatePreferencePaneNode(private val state: IntersectingS } addGridOption("Color", colorPicker) + }.also { + it.content = VBox(it.content).apply { + val exportMeshButton = Button("Export all") + exportMeshButton.setOnAction { _ -> + val manager = state.meshManager as MeshManagerWithSingleMesh> + val key = manager.meshKey!! + val exportDialog = MeshExporterDialog(MeshInfo(key, manager)) + val result = exportDialog.showAndWait() + if (result.isPresent) { + result.get().run { + (meshExporter as? MeshExporterObj<*>)?.run { + exportMaterial(filePath, arrayOf(""), arrayOf(Colors.toColor(state.converter().color))) + } + meshExporter.exportMesh( + manager.getBlockListFor, + manager.getMeshFor, + manager.getSettings(key), + key, + scale, + filePath, + false + ) + } + } + } + val buttonBox = HBox(exportMeshButton).also { it.alignment = Pos.BOTTOM_RIGHT } + children += buttonBox + + } } } } -} +} \ No newline at end of file diff --git a/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/ThresholdingSourceStatePreferencePaneNode.kt b/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/ThresholdingSourceStatePreferencePaneNode.kt index a738d015a..baa05392b 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/ThresholdingSourceStatePreferencePaneNode.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/paintera/state/ThresholdingSourceStatePreferencePaneNode.kt @@ -16,8 +16,11 @@ import org.janelia.saalfeldlab.fx.TitledPanes import org.janelia.saalfeldlab.fx.ui.NamedNode import org.janelia.saalfeldlab.fx.ui.NumberField import org.janelia.saalfeldlab.fx.ui.ObjectField +import org.janelia.saalfeldlab.paintera.meshes.MeshExporterObj +import org.janelia.saalfeldlab.paintera.meshes.MeshInfo import org.janelia.saalfeldlab.paintera.meshes.ui.MeshSettingsController import org.janelia.saalfeldlab.paintera.ui.PainteraAlerts +import org.janelia.saalfeldlab.paintera.ui.source.mesh.MeshExporterDialog class ThresholdingSourceStatePreferencePaneNode(private val state: ThresholdingSourceState<*, *>) { @@ -26,6 +29,7 @@ class ThresholdingSourceStatePreferencePaneNode(private val state: ThresholdingS .also { it.children.addAll(createBasicNote(), createMeshesNode()) } private fun createBasicNote(): Node { + val min = NumberField .doubleField(state.minProperty().get(), { true }, ObjectField.SubmitOn.ENTER_PRESSED, ObjectField.SubmitOn.FOCUS_LOST) .also { it.valueProperty().addListener { _, _, new -> state.minProperty().set(new.toDouble()) } } @@ -82,6 +86,33 @@ class ThresholdingSourceStatePreferencePaneNode(private val state: ThresholdingS state.meshManager.managedSettings.meshesEnabledProperty, titledPaneGraphicsSettings = MeshSettingsController.TitledPaneGraphicsSettings("Meshes"), helpDialogSettings = MeshSettingsController.HelpDialogSettings(headerText = "Meshes") - ) + ).also { + it.content = VBox(it.content).apply { + val exportMeshButton = Button("Export all") + exportMeshButton.setOnAction { _ -> + val exportDialog = MeshExporterDialog(MeshInfo(state.meshManager.meshKey, state.meshManager)) + val result = exportDialog.showAndWait() + if (result.isPresent) { + result.get().run { + (meshExporter as? MeshExporterObj<*>)?.run { + exportMaterial(filePath, arrayOf(""), arrayOf(state.colorProperty().get())) + } + meshExporter.exportMesh( + state.meshManager.getBlockListFor, + state.meshManager.getMeshFor, + state.meshSettings, + state.thresholdBounds, + scale, + filePath, + false + ) + } + } + } + val buttonBox = HBox(exportMeshButton).also { it.alignment = Pos.BOTTOM_RIGHT } + children += buttonBox + + } + } }